|
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?
|
|
|
|
|
What is your timer interval set to? If it is too small, they tick events may be happening too often depending on the time it takes to perform the actions in each one.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
and how many SMS (and hence lblTimer updates) is that?
I am not sending anything now because I am just testing but I am looping through about 100records only
Is the CPU being used by your application or the SQL Server?
I am using MySQL not Sql Server
What is your timer interval set to?
It's set to 15minutes but even if I set to 24hours CPU will jump to 78% from the time the timer runs
|
|
|
|
|
please give me idea about effect. in android or windows vista a effect is used when any application window is open or closed. effect is like grow and shrink. very similar like jquery transfer effect. i can generate that effect like window size increment or decrement with in time but it flicker and not smooth like professional. so please guide how to generate that effect in windows application which look very professional. also tell me is there any free open source library to generate that kind of effect. please me with sample code.
thanks
tbhattacharjee
|
|
|
|
|
Is that what your users want? I wouldn't.
|
|
|
|
|
no rather i want to design in such way for users eye's satisfaction. can u help me.
tbhattacharjee
|
|
|
|
|
Why don't you just concentrate on creating a well design/well written application. These bells and whistles are a waste of time.
|
|
|
|
|
Hello:
i use vs2005(C#) and the OS is WinXP.
Now i want to get the local pc's monitor's status,
include [on] [off] [standby] three status.
what should i do.....
Thanks
|
|
|
|
|
|
|
Ask the user to click a button.
|
|
|
|
|