Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. public Manufacturer Convert(Manufacturer manufacturer)
  2. {
  3. var pricefileEngine = "";
  4. var pricefileHome = "";
  5.  
  6. List<string> priceFiles = new List<string>();
  7.  
  8.  
  9. foreach (var file in manufacturer.Files)
  10. {
  11. if (file.Contains("BSENG_10"))
  12. {
  13. pricefileEngine = file;
  14. priceFiles.Add(pricefileEngine);
  15. }
  16. if (file.Contains("BS_10"))
  17. {
  18. pricefileHome = file;
  19. priceFiles.Add(pricefileHome);
  20. }
  21. }
  22.  
  23. //PRICE_FILE_ENGINE
  24. var excelData = FileHelper.GetExcelDataSet(pricefileEngine);
  25. foreach (DataRow row in excelData.Tables[0].Rows)
  26. {
  27. var part = new Part();
  28. part.PartNumber = row[1].ToString().Trim();
  29. part.Description = row[2].ToString().Trim();
  30.  
  31. //while (!string.IsNullOrWhiteSpace(row[9].ToString().Trim()))
  32. //{
  33. // part.SubPartNumber = row[9].ToString().Trim();
  34. //}
  35.  
  36. decimal value;
  37. if (decimal.TryParse(row[5].ToString().Trim(), out value))
  38. {
  39. part.ListPrice = value;
  40. }
  41.  
  42. if (decimal.TryParse(row[9].ToString().Trim(), out value))
  43. {
  44. part.DealerPrice = value; // Base
  45. }
  46.  
  47. if (decimal.TryParse(row[13].ToString().Trim(), out value)) part.Weight = value;
  48. if (!string.IsNullOrWhiteSpace(row[14].ToString().Trim())) part.UpcCode = row[14].ToString().Trim();
  49.  
  50. int index = manufacturer.Parts.BinarySearch(part);
  51. if (index < 0) manufacturer.Parts.Insert(~index, part);
  52. else if (part.ListPrice != manufacturer.Parts[index].ListPrice || part.DealerPrice != manufacturer.Parts[index].DealerPrice)
  53. MessageBox.Show("Duplicate P/N: " + part.PartNumber);
  54. }
  55.  
  56. //PRICE_FILE_HOME
  57. var excelData2 = FileHelper.GetExcelDataSet(pricefileHome);
  58. foreach (DataRow row in excelData2.Tables[0].Rows)
  59. {
  60. var part = new Part();
  61. part.PartNumber = row[1].ToString().Trim();
  62. part.Description = row[2].ToString().Trim();
  63.  
  64. if (!string.IsNullOrWhiteSpace(row[4].ToString().Trim()))
  65. {
  66. part.SubPartNumber = row[4].ToString().Trim();
  67. }
  68.  
  69. decimal value;
  70. if (decimal.TryParse(row[5].ToString().Trim(), out value))
  71. {
  72. part.ListPrice = value;
  73. }
  74.  
  75. if (decimal.TryParse(row[9].ToString().Trim(), out value))
  76. {
  77. part.DealerPrice = value; // Base
  78. }
  79.  
  80. if (decimal.TryParse(row[12].ToString().Trim(), out value)) part.Weight = value;
  81. if (!string.IsNullOrWhiteSpace(row[13].ToString().Trim())) part.UpcCode = row[13].ToString().Trim();
  82.  
  83. int index = manufacturer.Parts.BinarySearch(part);
  84. if (index < 0) manufacturer.Parts.Insert(~index, part);
  85. else if (part.ListPrice != manufacturer.Parts[index].ListPrice || part.DealerPrice != manufacturer.Parts[index].DealerPrice)
  86. MessageBox.Show("Duplicate P/N: " + part.PartNumber);
  87. }
  88.  
  89. //MessageBox.Show("Number of files converted: " + count);
  90. return manufacturer;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement