|
hi friend it adds the datas now i changed something more after u offered..thanks for help
and one more question; is it too redicilous way to write a method which gets 15 parameters in my process layer and them to call it in my form inside and to assign the parameters here ?
vemedya.com
|
|
|
|
|
That's okey the way you are processing. But Why you have kept a seperate method for InsertData() You should Initialize command there itself. No need for extra garbage. Wrap thing in a function that can be reusable or having something meaning.
You got your problem solved now, I have also found why you were getting error let me tell you if you have found the same or different.
In your event btnEkle_Click you have called h.InsertFirm(firma); directly without setting value for each property, and after finishing a whole operation you are assigning value, I think you're very much newbie with OOPS. try to read some books around will give you better idea on this.
|
|
|
|
|
yeah i am new about it really and try to learn it..i hope it doesnt take much time to improve my skills
thanks for your help again
vemedya.com
|
|
|
|
|
Hi all.
i need to get the ip of a network interface when it is disconnected. i try all the wmi and system.net options afaik, and they give me only when it is a connected network. of course it is a static IP.
thanks for your help.
|
|
|
|
|
Do you know the MAC address of the interface, or can you get it before the interface is disconnected and maintain that information? You might be able to invoke the arp -a command to access the arp cache before it expires to find the lsat known IP address associated with the device. Unfortunately, unless the arp table contains a static entry, the association will be removed within 2 to 10 minutes of going inactive.
Technically speaking, a disconnected device has no IP address, as the address is a network property and it is no longer part of the network. You may configure an interface for a static IP address, but the address is "owned" by the network, and if another device acquires that address while the device is disconnected, it will not operate. While it's disconnected (except for the brief lifetime of the arp cache) it doesn't exist, and no record of it is retained.
Will Rogers never met me.
|
|
|
|
|
Hey all thanks for the help in my last post =^)
Now i got this... seems to be the most simplest project for class but its driving me MAD haha.
All i need to do is read and write the data from a xml file to a listview and also include the names i type into my form.
This is what i was using to test the reading of a xml file, but im only getting the last line of the xml not the whole thing.
private void btnShowAll_Click(object sender, EventArgs e)
{
string sOut;
XmlDocument myDoc = new XmlDocument();
try
{
myDoc.Load("people.xml");
}
catch (Exception xmle)
{
MessageBox.Show(xmle.Message, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
return;
}
txtBox.Text = "";
XmlNodeList nodeList = myDoc.DocumentElement.ChildNodes;
foreach (XmlNode PersonNode in nodeList)
{
foreach (XmlNode PersonTag in PersonNode.ChildNodes)
{
sOut = PersonTag.Name + "\t" + PersonTag.FirstChild.Value;
txtBox.Text = sOut;
}
}
}
|
|
|
|
|
Look at your loop:
foreach (XmlNode PersonTag in PersonNode.ChildNodes)
{
sOut = PersonTag.Name + "\t" + PersonTag.FirstChild.Value;
txtBox.Text = sOut;
}
You replace sOut and txtBox.Text values on each iteration so, when the loop ends you only have the last line... And you are not using any ListView control here, but a TextBox.
|
|
|
|
|
good response.
|
|
|
|
|
Hey _Erik_
thanks for you help on my last post =^)
Yeah this was just to test so i could see the xml, because i was having kinda the same problem with my list view so i just wanted to test it with something simple haha im a newbee cant you tell haha
I dont see it
sOut = PersonTag.Name + "\t" + PersonTag.FirstChild.Value + "\r\n";
Or this
sOut = PersonNode.Name + "\t" + PersonTag.FirstChild.Value + "\r\n";
|
|
|
|
|
I'm afraid none of them. Put a ListBox on your Form instead of a TextBox. This is basically a tree, so you will need a recursive method. This is a very basic sample:
void ShowAll(XmlNodeList nodes)
{
foreach (XmlNode node in nodes)
{
listBox.Add(string.Format("{0}\t{1}", node.Name, node.Value));
if (node.HasChildNodes)
ShowAll(node.ChildNodes);
}
}
Research something about recursion in the Internet if you cannot understand it.
|
|
|
|
|
Yes Erik pointed you what mistake you have done whatever, take a snap of this code. it include a little bit modification and display all lines of XML file
string sOut ="";
XmlDocument myDoc = new XmlDocument();
try
{
myDoc.Load(@"F:\Images.xml");
}
catch (Exception xmle)
{
MessageBox.Show(xmle.Message, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
return;
}
XmlNodeList nodeList = myDoc.DocumentElement.ChildNodes;
foreach (XmlNode PersonNode in nodeList)
{
foreach (XmlNode PersonTag in PersonNode.ChildNodes)
{
sOut += PersonTag.Name + "\t" + PersonTag.FirstChild.Value +"\r\n";
txtBox.Text = sOut;
}
}
|
|
|
|
|
|
|
Haha
Now i got to print the last two lines haha
string sOut = "";
XmlDocument myDoc = new XmlDocument();
try
{
myDoc.Load("people.xml");
}
catch (Exception xmle)
{
MessageBox.Show(xmle.Message, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
return;
}
txtBox.Text = "";
XmlNodeList nodeList = myDoc.DocumentElement.ChildNodes;
foreach (XmlNode PersonNode in nodeList)
{
foreach (XmlNode PersonTag in PersonNode.ChildNodes)
{
sOut += PersonTag.Name + "\t" + PersonTag.FirstChild.Value + "\r\n";
txtBox.Text = sOut;
}
}
|
|
|
|
|
squerley wrote: Now i got to print the last two lines haha
there something wrong.
It display all lines I have checked it and then posted.
|
|
|
|
|
haha craziness
I did it on my other lab and it works fine haha
Anyhow when i run my listview lab im getting this NullReferanceException in my ReadInPeople method
public int ReadInPeople()
{
XmlNodeList nodeList = m_xmlDoc.DocumentElement.ChildNodes;
foreach (XmlNode PersonNode in nodeList)
{
Person addPerson = new Person();
foreach(XmlNode PersonTag in PersonNode.ChildNodes)
{
switch (PersonTag.Name)
{
case "firstName":
addPerson.SetFirstName(PersonTag.FirstChild.Value);
break;
case "lastName":
addPerson.SetLastName(PersonTag.FirstChild.Value);
break;
case "address":
addPerson.SetAddress(PersonTag.FirstChild.Value);
break;
case "city":
addPerson.SetCity(PersonTag.FirstChild.Value);
break;
case "state" :
addPerson.SetState(PersonTag.FirstChild.Value);
break;
case "zip":
addPerson.SetZip(PersonTag.FirstChild.Value);
break;
default:
break;
}
}
this.AddPerson(addPerson);
}
return nodeList.Count;
}
|
|
|
|
|
This is my listView form that im trying to get populated by the xml file
private void frmPersonList_Load(object sender, EventArgs e)
{
try
{
m_xmlDoc.Load("m_person.xml");
}
catch (Exception xmle)
{
MessageBox.Show(xmle.Message, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
}
and i cant see the ReadInPeople method in my main form unless i use public instead of privete and if i use public i get an exception...
myForm.ReadInPeople();
lstPersons.View = View.Details;
lstPersons.Columns.Add("Fist Name", 100, HorizontalAlignment.Center);
lstPersons.Columns.Add("MI", 30, HorizontalAlignment.Center);
lstPersons.Columns.Add("Last Name", 80, HorizontalAlignment.Center);
lstPersons.Columns.Add("Address", 160, HorizontalAlignment.Center);
lstPersons.Columns.Add("City", 150, HorizontalAlignment.Center);
lstPersons.Columns.Add("State", 50, HorizontalAlignment.Center);
lstPersons.Columns.Add("Zip", 50, HorizontalAlignment.Center);
lstPersons.Columns.Add("Date and Time", 150, HorizontalAlignment.Center);
Person p;
for (int i = 0; i < m_PersonReference.Length; i++)
{
p = m_PersonReference[i];
lstPersons.Items.Add(p.FirstName);
lstPersons.Items[i].SubItems.Add(p.MI);
lstPersons.Items[i].SubItems.Add(p.LastName);
lstPersons.Items[i].SubItems.Add(p.Address);
lstPersons.Items[i].SubItems.Add(p.city);
lstPersons.Items[i].SubItems.Add(p.state);
lstPersons.Items[i].SubItems.Add(p.zip);
lstPersons.Items[i].SubItems.Add(p.time);
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void frmPersonList_FormClosing(object sender, FormClosingEventArgs e)
{
this.m_xmlDoc.Save("m_person.xml");
}
|
|
|
|
|
squerley wrote: i cant see the ReadInPeople method in my main form unless i use public instead of privete and if i use public i get an exception...
will you mention exception which is occur?
|
|
|
|
|
What are you trying, please be clear. Fistly your question is you are not getting all lines or something other
|
|
|
|
|
|
Hi,
I have this code which works fine but there is a major issue specially i am going t run this on the server! when the code in the timer start running, the CPU usage of the machine jumps from 16% to 78%? of course after completed it will go back to normal but my question. what's happening in the code? why it take this much from CPU?
MySqlConnection sql_connection = null;
MySqlCommand sql_command = null;
MySqlDataAdapter sql_adapter;
DataTable data_table = null;
MySqlDataReader sql_reader = null;
DataSet data_set = null;
public public_class public_var = new public_class();
const int MF_BYPOSITION = 0x400;
[DllImport("User32.dll")]
private static extern int RemoveMenu(IntPtr hMenu, int nPosition, int wFlagS);
[DllImport("User32.dll")]
private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport("User32.dll")]
private static extern int GetMenuItemCount(IntPtr hWnd);
public delegate void ControlStringConsumer(Control control, string text);
public int result_rows;
public frmMain()
{
InitializeComponent();
}
public void SetText(Control control, string text)
{
control.Invoke(new ControlStringConsumer(SetTextGUI), new object[] { control, text });
}
public void SetTextGUI(Control control, string text)
{
control.Text = text;
}
private void perform()
{
get_statistics_summary();
send_sms();
}
private void get_statistics_summary()
{
sql_connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["SQLdb"].ConnectionString);
sql_connection.Open();
sql_command = new MySqlCommand("SELECT COUNT(*) AS total_files FROM persons", sql_connection);
sql_command.CommandType = CommandType.Text;
sql_reader = sql_command.ExecuteReader();
if (sql_reader.Read())
{
SetText(lblTotalFiles, sql_reader["total_files"].ToString());
}
sql_reader.Close();
sql_command = new MySqlCommand("SELECT COUNT(*) AS total_appointments FROM appointments", sql_connection);
sql_command.CommandType = CommandType.Text;
sql_reader = sql_command.ExecuteReader();
if (sql_reader.Read())
{
SetText(lblTotalAppointments, sql_reader["total_appointments"].ToString());
}
}
private void send_sms()
{
sql_connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["SQLdb"].ConnectionString);
sql_connection.Open();
sql_command = new MySqlCommand("sp_send_pending_sms", sql_connection);
sql_command.CommandType = CommandType.StoredProcedure;
sql_reader = sql_command.ExecuteReader();
while (sql_reader.Read())
{
SetText(lblTimer, sql_reader["sms_queue_id"].ToString());
}
}
private void frmMain_Load(object sender, EventArgs e)
{
this.Cursor = Cursors.WaitCursor;
IntPtr hMenu = GetSystemMenu(this.Handle, false);
int menuItemCount = GetMenuItemCount(hMenu);
RemoveMenu(hMenu, menuItemCount - 1, MF_BYPOSITION);
timerMain.Interval = Convert.ToInt32(ConfigurationManager.AppSettings["ServerTimerInterval"]);
}
private void btnEmailTemplates_Click(object sender, EventArgs e)
{
frmEmailTemplates EmailTemplatesForm = new frmEmailTemplates(public_var);
EmailTemplatesForm.ShowDialog();
}
private void frmMain_Shown(object sender, EventArgs e)
{
this.Cursor = Cursors.WaitCursor;
timerMain.Start();
this.Cursor = Cursors.Default;
}
private void timerMain_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
backgroundWorkerSMS.RunWorkerAsync();
}
private void btnOptions_Click(object sender, EventArgs e)
{
frmOptions OptionsForm = new frmOptions();
DialogResult options_form = OptionsForm.ShowDialog();
if (options_form == DialogResult.OK)
{
timerMain.Stop();
timerMain.Interval = Convert.ToInt32(ConfigurationManager.AppSettings["ServerTimerInterval"]);
timerMain.Start();
}
}
private void backgroundWorkerSMS_DoWork(object sender, DoWorkEventArgs e)
{
perform();
}
private void backgroundWorkerSMS_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
backgroundWorkerSMS.Dispose();
}
</pre>
|
|
|
|
|
is your code and the database running on the same machine?
how many cores are there?
what is inside the stored procedure?
how many different values are you sending to lblTimer per second? (or how long is the SMS table and how long does your code actually run?
if you don't have polling loops, and if you have chosen good algorithms, CPU activity is OK, it just says the processor is working for you.
if the database is elsewhere or the SP is light, then your code is mostly switching threads to update some labels, i.e. your GUI is costing a lot then.
[ADDED]
1. you're not going to have a display with a permanent status update on a server, are you?
2. when update frequency is high, a better approach is to store, not display, the status in some variable(s), and have the GUI update itself (with a Windows.Forms.Timer) a few times a second. When the variable is a 4-byte int or smaller, no need to have synchronization logic (such as locks) at all.
[/ADDED]
|
|
|
|
|
s your code and the database running on the same machine?
Yes both on the same machine.
how many cores are there?
Core Due
what is inside the stored procedure?
Just a select statement only
how many different values are you sending to lblTimer per second? (or how long is the SMS table and how long does your code actually run?
The code runs for about 10seconds
|
|
|
|
|
jrahma wrote: The code runs for about 10second
and how many SMS (and hence lblTimer updates) is that?
|
|
|
|
|
Is the CPU being used by your application or the SQL Server?
|
|
|
|
|