lunedì 13 settembre 2010

Visual C-Sharp add and search a double on x

If you want add double(0.0) and/or search by date on a file.xml this is it one way that I study.
I take for example a file.xml:
author: Muratore Alessandro
e.Mail: muratore.ale@gmail.com

******************** file.xml *******
<root>
  <books>
    <data>20101223</data>
    <amount>12,92</amount>
  </books>
  <papers>
    <date>20010101</date>
    <amount>22,85</amount>
  </papers>
</root>
******************* /file.xml *******
In the TextBox that have to be created the date will be put in the way dd/mm/yy, in the following code you may notice how the date becomes yyy/mm/dd in order to be registered in file.xml. This method is used to make researches from major date to minor date or viceversa:
// author: Muratore Alessandro
// e.Mail: muratore.ale@gmail.com

XmlDocument ccXml;      // function to charge a file XML
DateTime date_1_cc;      // function to search date ONE
DateTime date_2_cc;      // function to search date TWO
Label lblCalc_Search;      // label for calculation/research

// file.xml path
private const string path_xml = @"C:\Users\muratore.ale\file.xml";

// calculator from date to date:
void calc_cc(object sender, EventArgs e)
{
 // work on date
        date_1_cc = new DateTime();
 date_2_cc = new DateTime();
 date_1_cc = DateTime.Parse(txtBDate_1.Text);
 date_2_cc = DateTime.Parse(txtBDate_2.Text);
 string sDate_1= date_1_cc.ToString("yyyyMMdd");
 string sDate_2= date_2_cc.ToString("yyyyMMdd");

 // charge the file xml
 ccXml = new XmlDocument();
 ccXml.Load(path_xml);

 // search - print - add from date to datae
        XmlNodeList list_nodes = ccXml.SelectNodes("/root/books[date>="+sDate_1+" and date<="+sDate_2+"]/imports");   

 double summ = 0.0;

 foreach (XmlNode node in list_nodes)
 {
  /*
  // print number by number
                MessageBox.Show(node.InnerText);
  */

  double inner = double.Parse(node.InnerText);
  summ += inner;

  //print total on MessageBox
  //MessageBox.Show((inner+summ).ToString());

  // print total on label
  lblCalc_Search.Text = ("$ "+(summ).ToString());
 }
}

Nessun commento:

Posta un commento