Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. XDocument _document = XDocument.Parse(XMLString);
  2.  
  3. <Line>
  4. <ITEMNMBR>18-4695</ITEMNMBR>
  5. <UNITCOST>2.00000</UNITCOST>
  6. <UNITPRCE>7.00000</UNITPRCE>
  7. <QUANTITY>15.00000</QUANTITY>
  8. </Line>
  9. <Line>
  10. <ITEMNMBR>18-4695</ITEMNMBR>
  11. <UNITCOST>3.00000</UNITCOST>
  12. <UNITPRCE>7.00000</UNITPRCE>
  13. <QUANTITY>22.00000</QUANTITY>
  14. </Line>
  15.  
  16. var lines = _document.Descendants("Line")
  17. .Select(l => l.Elements().ToDictionary(e => e.Name.LocalName, e => e.Value)).ToList();
  18.  
  19. var itemNumbers = lines.Where(dict => dict.ContainsKey("ITEMNMBR"))
  20. .Select(dict => dict["ITEMNMBR"])
  21. .Distinct()
  22. .ToList();
  23.  
  24. foreach (string itemNumber in itemNumbers)
  25. {...
  26.  
  27. var qty = lines.Where(dict => dict.ContainsValue(itemNumber))
  28. .Select(dict => dict["QUANTITY"])
  29. .ToList();
  30.  
  31. int sum = qty.Sum(x => Convert.ToDecimal(x.Value));
  32.  
  33. var qty = lines.Where(dict => dict.ContainsValue(itemNumber))
  34. .Select(dict => dict["QUANTITY"]) // here you are selecting the value
  35. .ToList();
  36.  
  37. int sum = qty.Sum(x => Convert.ToDecimal(x));
  38.  
  39. var sum = lines.Where(dict => dict.ContainsValue(itemNumber))
  40. .Sum(dict => Convert.ToDecimal(dict["QUANTITY"]));
  41.  
  42. decimal sum = qty.Sum(x => !string.IsNullOrEmpty(x) ? Convert.ToDecimal(x) : 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement