Opening a search url in a new C# file - c#

Good sir,
Am having C# file in Xamarin.Forms called WebPage, i wish to open the eSearch Entry in a new Window(in a new C# file) but it isn't working just showing blank page.
Here is the code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HtmlAgilityPack;
using Xamarin.Forms;
using System.Diagnostics;
namespace WList
{
public class WebPage: ContentPage
{
Entry eSearch;
Button bButton;
public WebPage()
{
eSearch = new Entry{Placeholder = "Search and go"};
bButton = new Button { Text = "GO" };
bButton.Clicked += bButton_Clicked;
this.Content = new StackLayout
{
Children = {
eSearch, bButton
}
};
}
void bButton_Clicked(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(eSearch.Text)) { DisplayAlert("Empty", "Search item is empty", "OK"); }
else
{
Navigation.PushModalAsync(new SitePage());
//Debug.WriteLine(eSearch.Text);
}
}
}
}

You need to pass your text value in the constructor to the new page.
For Example
Public class SitePage : ContentPage
{
public SitePage(string text)
{
var entry = new Entry();
entry.Text = text;
this.Content = entry;
}
}
You would then navigate to it like:
Navigation.PushModalAsync(new SitePage(eSearch.Text));

Related

How to Retrieve data inside of the generated key that I just push

I'm trying to retrieve the data inside of the generated key from firebase real time database using C# language and the retrieve data will show in RecyclerViewer. I try everything but still not showing in RecyclerView.
This is my code
how to solve this?
THIS IS THE LISTENER:
using AdamsonsEDApp.Data_Models;
using AdamsonsEDApp.Helpers;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Firebase.Database;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static AdamsonsEDApp.Listeners.StaffListeners;
namespace AdamsonsEDApp.Listeners
{
public class PackageInfoListeners : Java.Lang.Object, IValueEventListener
{
List<PackageInfo> packageinfoList = new List<PackageInfo>();
public event EventHandler<PackageInfoDataEventArgs> PackageInfoRetrieved;
public class PackageInfoDataEventArgs : EventArgs
{
public List<PackageInfo> PackageInfo { get; set; }
}
public void OnCancelled(DatabaseError error)
{
throw new NotImplementedException();
}
public void OnDataChange(DataSnapshot snapshot)
{
if (snapshot.Value != null)
{
var child = snapshot.Children.ToEnumerable<DataSnapshot>();
packageinfoList.Clear();
foreach (DataSnapshot infoData in child)
{
PackageInfo info = new PackageInfo();
info.packageinfoID = infoData.Key;
info.packageinfoName = infoData.Child("infoName").Value.ToString();
info.packageinfoQty = infoData.Child("infoQty").Value.ToString();
packageinfoList.Add(info);
}
PackageInfoRetrieved.Invoke(this, new PackageInfoDataEventArgs { PackageInfo = packageinfoList });
}
}
public void Create()
{
DatabaseReference infoRef = AppDataHelper.GetDatabase().GetReference("packageinfo");
infoRef.AddValueEventListener(this);
}
}
}
This is the Activit
using AdamsonsEDApp.Adapters;
using AdamsonsEDApp.Data_Models;
using AdamsonsEDApp.Fragments;
using AdamsonsEDApp.Listeners;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Support.V7.App;
using Android.Support.V7.Widget;
using Android.Views;
using Android.Widget;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AdamsonsEDApp.Resources.activities
{
[Activity(Label = "#string/app_name", Theme = "#style/AppTheme", MainLauncher = false)]
public class eventpackageinfo_activity : AppCompatActivity
{
string packageinfoname, packageinfoqty;
TextView infonameText, infoqtyText;
ImageView /*removeButton,*/ backpackageButton/*, searchButton*/;
//EditText searchText;
RecyclerView packageinfoRecyclerView;
Button addinclusionsButton;
AddPackageInfoFragment addpackageinfoFragment;
PackageInfoAdapter packageinfoadapter;
List<PackageInfo> packageinfoList;
PackageInfoListeners infoListeners;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
SetContentView(Resource.Layout.eventpackageinfos);
infonameText = (TextView)FindViewById(Resource.Id.infonameText);
infoqtyText = (TextView)FindViewById(Resource.Id.infoqtyText);
addinclusionsButton = (Button)FindViewById(Resource.Id.addinclusionsButton);
backpackageButton = (ImageView)FindViewById(Resource.Id.backpackageButton);
packageinfoRecyclerView = (RecyclerView)FindViewById(Resource.Id.packageinfoRecyclerView);
backpackageButton.Click += BackpackageButton_Click;
addinclusionsButton.Click += AddinclusionsButton_Click;
RetrieveData();
}
private void AddinclusionsButton_Click(object sender, EventArgs e)
{
}
private void BackpackageButton_Click(object sender, EventArgs e)
{
Intent infointent = new Intent(this, typeof(eventpackage_activity));
StartActivity(infointent);
}
private void SetupPackageInfoRecyclerView()
{
packageinfoRecyclerView.SetLayoutManager(new Android.Support.V7.Widget.LinearLayoutManager(packageinfoRecyclerView.Context));
PackageInfoAdapter packageinfoadapter = new PackageInfoAdapter(packageinfoList);
packageinfoRecyclerView.SetAdapter(packageinfoadapter);
}
public void RetrieveData()
{
infoListeners = new PackageInfoListeners();
infoListeners.Create();
infoListeners.PackageInfoRetrieved += InfoListeners_PackageInfoRetrieved;
}
private void InfoListeners_PackageInfoRetrieved(object sender, PackageInfoListeners.PackageInfoDataEventArgs e)
{
packageinfoList = e.PackageInfo;
SetupPackageInfoRecyclerView();
}
}
}
Are you sure you're listening to the correct path in the database? Your code attaches a listener to:
DatabaseReference infoRef = AppDataHelper.GetDatabase().GetReference("packageinfo");
But your screenshot shows a node named eventpackage under the root.

Writing form state to xml C#

My aim is to save the all form data via button click (as opposed to upon closing). To that end, I've used the example given in the following thread. Saving the form state then opening it back up in the same state
I've tried to adapt my code to the best of my ability, but nothing happens, and there are no errors shown. What am I doing wrong?
Here's the relevant parts of my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Serialization;
namespace WindowsFormsApplication1
{
public partial class frmPayroll : Form
{
SaveData sd = new SaveData();
public frmPayroll()
{
InitializeComponent();
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
writeConfig();
}
private void writeConfig()
{
using (StreamWriter sw = new StreamWriter("config.xml"))
{
sd.Married = rdoMarr.Checked;
sd.PayPd = cbPayPd.Text;
sd.Allow = cbAllow.Text;
sd.Gross = txtGross.Text;
sd.Fit = txtFit.Text;
sd.Soc = txtSoc.Text;
sd.Med = txtMed.Text;
sd.NetPay = txtNet.Text;
sd.PayPd = cbPayPd.Text;
XmlSerializer ser = new XmlSerializer(typeof(SaveData));
ser.Serialize(sw, sd);
}
}
private void frmPayroll_Load(object sender, EventArgs e)
{
if (File.Exists("config.xml"))
{
loadConfig();
}
sd.Married = rdoMarr.Checked;
sd.PayPd = cbPayPd.Text;
sd.Allow = cbAllow.Text;
sd.Gross = txtGross.Text;
sd.Fit = txtFit.Text;
sd.Soc = txtSoc.Text;
sd.Med = txtMed.Text;
sd.NetPay = txtNet.Text;
}
private void loadConfig()
{
XmlSerializer ser = new XmlSerializer(typeof(SaveData));
using (FileStream fs = File.OpenRead("config.xml"))
{
sd = (SaveData)ser.Deserialize(fs);
}
}
}
public struct SaveData
{
public bool Married;
public string PayPd;
public string Allow;
public string Gross;
public string Fit;
public string Soc;
public string Med;
public string NetPay;
}
}
You are loading your object by deserializing.
But Where are you assigning the states back to your controls?
look at frmPayroll_Load function.
You are trying to assign the data back to the object again.
You have to assign data back to form controls.
Should be something like this (you may need to apply data conversions if required):
rdoMarr.Checked = sd.Married;
.
.
.
.
txtFit.Text = sd.Fit;
.
.
.
.

How to modify and show a queue in a WPF c#

I'm trying to show in a TextBox in a Windows Presentation Foundation a queue after adding some items, I know it must be something simple, I've checked the code with a breakpoint, the Add Item button works good but once I press it again the queue is empty and I'm always adding just an item and once I add it and I press the same button Add Item button again or the Show Button the queue is empty, I would like to add items and show the queue with the items I added, I made a class named QueueClas. Here below is all the code, thanks beforehand!!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Queue2
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
QueueClas queuec = new QueueClas();
buttonAdd.Click += ButtonAdd_Click;
buttonShow.Click += ButtonShow_Click;
}
private void ButtonShow_Click(object sender, RoutedEventArgs e)
{
QueueClas queuec = new QueueClas();
textBoxShow.Text = queuec.ShowQueue();
}
private void ButtonAdd_Click(object sender, RoutedEventArgs e)
{
QueueClas queuec = new QueueClas();
queuec.AddQueue(int.Parse(textBoxQueue.Text));
textBoxQueue.Clear();
}
public class QueueClas
{
Queue<int> myqueue;
public QueueClas()
{
myqueue = new Queue<int> { };
}
public void AddQueue(int x)
{
myqueue.Enqueue(x);
}
public string ShowQueue()
{
return string.Join(" ", myqueue);
}
public void DeleteItem(int x)
{
myqueue.Dequeue();
}
public string NumberOfItems()
{
int counter = 0;
counter = myqueue.Count();
return "The queue contains " + counter.ToString() + " elements";
}
public string MinQueue()
{
return "The minimun value of the queue is: " + myqueue.Min().ToString();
}
public string MaxQueue()
{
return "The maximum value of the queue is: " + myqueue.Max().ToString();
}
public string FindElement(int x)
{
foreach (int item in myqueue)
{
if (x == item)
{
return "The item is in the queue";
}
}
return "The item is not in the queue";
}
}
}
}
In both the add and show buttons you are initialising your list with QueueClas queuec = new QueueClas();. This is completely erasing the list ans starting fresh. You already initialise it in your MainWindow constructor so there's no need to do it again.

Winforms c# listbox not displaying contents of list

I have a winforms application that I am trying to program using MVC
In the designer.cs for the form I have:
this.listBox_regApps = new System.Windows.Forms.ListBox();
this.listBox_regApps.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.listBox_regApps.FormattingEnabled = true;
this.listBox_regApps.Location = new System.Drawing.Point(62, 115);
this.listBox_regApps.Name = "listBox_regApps";
this.listBox_regApps.Size = new System.Drawing.Size(351, 134);
this.listBox_regApps.TabIndex = 1;
Then later in the normal cs file I try to set the listbox data to be a list (apps). When I debug the list apps does indeed have the data, but it never appears in the form. Not sure why. I've tried adding .update and .refresh but neither of those worked either.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AppCompatDemo1
{
interface IAppView
{
void AddListener(IController controller);
};
public partial class AppCompatApp : Form, IAppView
{
IController controller;
public AppCompatApp()
{
InitializeComponent();
}
public void AddListener(IController controller)
{
this.controller = controller;
}
//Trying to set my listbox to display this list
public void SetApps(List<string> apps)
{
listBox_regApps.DataSource = apps;
}
}
public interface IController
{
void OnTestClick(string currentApp);
}
class AppController : IController
{
AppCompatApp view;
IAppModel model;
public AppController(IAppModel model, AppCompatApp view)
{
this.model = model;
this.view = view;
this.view.AddListener(this);
view.SetApps(model.getApps());
}
}
interface IAppModel
{
List<string> getApps();
}
class AppModel : IAppModel
{
List<string> apps;
public AppModel()
{
apps = new List<string>();
apps.Add("app1");
apps.Add("app2");
apps.Add("app3");
}
public List<string> getApps()
{
return apps;
}
}
}
Something like this.
foreach (string app in apps)
{
listBox_regApps.Items.Add(app);
}

want to access data from text box in the form which is in another solution in visual studio 2013?

I have two solutions TranferService and Sender. TranferService has WCF service and IISHost to host that service. In Sender solution i have windows forms application. In that form i used button to browse and select file, text box to display selected file path, and another button(Send) to transfer that file through WCF service. But i am unable to access textbox value in the transfer solution. it shows"the name does not exist in the current context".
Code for TransferService
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace TransferService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "TransferService" in both code and config file together.
public class TransferService : ITransferService
{
public File DownloadDocument()
{
File file = new File();
String path = txtSelectFilePath.Text;
file.Content = System.IO.File.ReadAllBytes(#path);
//file.Name = "ImagingDevices.exe";
return file;
}
}
}
I am getting error on this line
String path = txtSelectFilePath.Text;
code for form.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Sender
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Browse_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
txtSelectFilePath.Text = openFileDialog1.FileName;
}
}
private void Send_Click(object sender, EventArgs e)
{
TransferService.TransferServiceClient client = new TransferService.TransferServiceClient();
TransferService.File file = client.DownloadDocument();
System.IO.File.WriteAllBytes(#"C:\DownloadedFiles\" + file.Name, file.Content);
MessageBox.Show(file.Name + " is downloaded");
}
}
}
Code for ITransferService.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace TransferService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "ITransferService" in both code and config file together.
[ServiceContract]
public interface ITransferService
{
[OperationContract]
File DownloadDocument();
}
[DataContract]
public class File
{
[DataMember]
public string Name { get; set; }
[DataMember]
public byte[] Content { get; set; }
}
}
Thanx a lot in advance..........
Then create a constructor to your class that receives a path as string something like this:
public class TransferService : ITransferService
{
private string _path;
public TransferService(string path) {
_path = path
}
public File DownloadDocument()
{
File file = new File();
//String path = txtSelectFilePath.Text;
file.Content = System.IO.File.ReadAllBytes(_path);
//file.Name = "ImagingDevices.exe";
return file;
}
}
and then on form.cs
TransferService.TransferServiceClient client = new TransferService.TransferServiceClient(txtSelectFilePath.Text);

Categories

Resources