Advertisement
tezuka777

Untitled

Jun 29th, 2016
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1. try
  2. {
  3.     XmlDocument invoiceXML = currentXML;
  4.     XmlNodeList invoiceList = invoiceXML.GetElementsByTagName("Invoice");
  5.     XmlNodeList productList = invoiceXML.GetElementsByTagName("Product");
  6.     XmlNodeList itemList = invoiceXML.GetElementsByTagName("InvoiceItem");
  7.     ArrayList invoiceItems = new ArrayList();
  8.     InvoiceItem invoiceItem = new InvoiceItem();
  9.     //order arraylist
  10.     foreach (XmlNode node in invoiceList)    //for each invoice tag in xml, by right 1 for each xml
  11.     {
  12.         foreach (XmlNode node1 in itemList)// for each invoiceItem tag, which has 2 in this case.
  13.         {
  14.             invoiceItem = new InvoiceItem();
  15.             invoiceItem.InvoiceID = node.Attributes[0].Value;
  16.             string prodID = "";
  17.             string description = "";
  18.             string capacity = "";
  19.             int qty = 0;
  20.             decimal unitpx = 0;
  21.             foreach (XmlNode node2 in productList) //grabbing the details inside the Product tag.
  22.             {
  23.                 prodID = node2.Attributes[0].Value;
  24.                 description = node2.ChildNodes[1].InnerText;
  25.                 capacity = node2.ChildNodes[2].InnerText;
  26.                 qty = Convert.ToInt32(node2.ChildNodes[3].InnerText);
  27.                 unitpx = Convert.ToDecimal(node2.ChildNodes[4].InnerText);
  28.             }
  29.             invoiceItem.ProductID = prodID;
  30.             invoiceItem.Description = description;
  31.             invoiceItem.Capacity = capacity;
  32.             invoiceItem.Quantity = qty;
  33.             invoiceItem.UnitPrice = unitpx;
  34.             invoiceItem.TotalPrice = (qty * unitpx);
  35.  
  36.             invoiceItems.Add(invoiceItem);                                              
  37.         }                    
  38.     }
  39.     //storing this arraylist to currently loaded memory
  40.     currentInvoiceItem = invoiceItems;
  41.  
  42.     string display = "";
  43.     foreach (InvoiceItem ii in currentInvoiceItem)
  44.     {
  45.         display += ii.ToString() + "\r\n";
  46.         display += "---------------";
  47.     }
  48.     richTextBox2.Text = display;
  49. }
  50. catch(Exception)
  51. {
  52.     DialogResult dr = MessageBox.Show("No XML file(s) are currently loaded. Please browse for an XML file before checking it.");
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement