Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try
- {
- XmlDocument invoiceXML = currentXML;
- XmlNodeList invoiceList = invoiceXML.GetElementsByTagName("Invoice");
- XmlNodeList productList = invoiceXML.GetElementsByTagName("Product");
- XmlNodeList itemList = invoiceXML.GetElementsByTagName("InvoiceItem");
- ArrayList invoiceItems = new ArrayList();
- InvoiceItem invoiceItem = new InvoiceItem();
- //order arraylist
- foreach (XmlNode node in invoiceList) //for each invoice tag in xml, by right 1 for each xml
- {
- foreach (XmlNode node1 in itemList)// for each invoiceItem tag, which has 2 in this case.
- {
- invoiceItem = new InvoiceItem();
- invoiceItem.InvoiceID = node.Attributes[0].Value;
- string prodID = "";
- string description = "";
- string capacity = "";
- int qty = 0;
- decimal unitpx = 0;
- foreach (XmlNode node2 in productList) //grabbing the details inside the Product tag.
- {
- prodID = node2.Attributes[0].Value;
- description = node2.ChildNodes[1].InnerText;
- capacity = node2.ChildNodes[2].InnerText;
- qty = Convert.ToInt32(node2.ChildNodes[3].InnerText);
- unitpx = Convert.ToDecimal(node2.ChildNodes[4].InnerText);
- }
- invoiceItem.ProductID = prodID;
- invoiceItem.Description = description;
- invoiceItem.Capacity = capacity;
- invoiceItem.Quantity = qty;
- invoiceItem.UnitPrice = unitpx;
- invoiceItem.TotalPrice = (qty * unitpx);
- invoiceItems.Add(invoiceItem);
- }
- }
- //storing this arraylist to currently loaded memory
- currentInvoiceItem = invoiceItems;
- string display = "";
- foreach (InvoiceItem ii in currentInvoiceItem)
- {
- display += ii.ToString() + "\r\n";
- display += "---------------";
- }
- richTextBox2.Text = display;
- }
- catch(Exception)
- {
- DialogResult dr = MessageBox.Show("No XML file(s) are currently loaded. Please browse for an XML file before checking it.");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement