25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PDAImport.cs 4.1 KiB

3 년 전
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using System;
  2. using System.Text;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5. using importer.RestObjects;
  6. using importer.ImportObjects;
  7. using System.IO;
  8. using ExcelDataReader;
  9. using System.Data;
  10. namespace importer
  11. {
  12. public class PDAImport
  13. {
  14. private static string _serviceUrl;
  15. private static RESTService _rservice;
  16. private static List<Customer> _customers;
  17. private static List<Make> _makes;
  18. private static List<Product> _products;
  19. private static List<Model> _models;
  20. private static List<InspectionType> _inspectionTypes;
  21. private static List<Template> _templates;
  22. private static List<User> _users;
  23. private static Status _status;
  24. private static Priority _priority;
  25. private static Reason _reason;
  26. public static string ServiceUrl { get { return _serviceUrl; } set { _serviceUrl = value; } }
  27. public static Dictionary<string, int> InspectionType;
  28. public static DataTable ReadFile()
  29. {
  30. string filePath = Path.Combine(Global.StorageDir, "PDAFILE.XLS");
  31. System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
  32. using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read))
  33. {
  34. IExcelDataReader reader;
  35. if (Path.GetExtension(filePath).ToUpper() == ".XLS")
  36. {
  37. //1.1 Reading from a binary Excel file ('97-2003 format; *.xls)
  38. reader = ExcelReaderFactory.CreateBinaryReader(stream);
  39. }
  40. else
  41. {
  42. //1.2 Reading from a OpenXml Excel file (2007 format; *.xlsx)
  43. reader = ExcelReaderFactory.CreateOpenXmlReader(stream);
  44. }
  45. //reader = ExcelDataReader.ExcelReaderFactory.CreateReader(stream);
  46. var conf = new ExcelDataSetConfiguration
  47. {
  48. ConfigureDataTable = _ => new ExcelDataTableConfiguration
  49. {
  50. UseHeaderRow = true
  51. }
  52. };
  53. var dataSet = reader.AsDataSet(conf);
  54. return dataSet.Tables[0];
  55. }
  56. }
  57. //Test Comment
  58. public static List<string> DistinctWorkOrders(DataTable data)
  59. {
  60. List<string> list = new List<string>();
  61. var info = (from row in data.AsEnumerable()
  62. where (row.Field<string>("Segment Number") == "02" ||
  63. row.Field<string>("Segment Number") == "03") &&
  64. !string.IsNullOrEmpty(row.Field<string>("Service Tech"))
  65. select row.Field<string>("DBS Workorder Number")).Distinct();
  66. list.AddRange(info);
  67. return list;
  68. }
  69. public static void BuildDefaults()
  70. {
  71. if (Global.Settings.Remote)
  72. _serviceUrl = Global.Settings.Prelub.RemoteService;
  73. else _serviceUrl = Global.Settings.Prelub.LocalService;
  74. _rservice = new RESTService();
  75. _customers = _rservice.RestGet<Customer>("customers.svc");
  76. _makes = _rservice.RestGet<Make>("makes.svc");
  77. _products = _rservice.RestGet<Product>("products.svc");
  78. _models = _rservice.RestGet<Model>("models.svc");
  79. _inspectionTypes = _rservice.RestGet<InspectionType>("inspectionTypes.svc");
  80. _templates = _rservice.RestGet<Template>("templates.svc");
  81. _users = _rservice.RestGet<User>("users.svc");
  82. _status = new Status();
  83. _status.ID = 1;
  84. _status.Name = "Open";
  85. _priority = new Priority();
  86. _priority.ID = 3;
  87. _priority.Name = "Medium";
  88. _reason = new Reason();
  89. _reason.ID = 9;
  90. _reason.Name = "Cust. Request";
  91. _reason.IsActive = true;
  92. _reason.CreateDate = new DateTime(2013, 10, 1, 9, 23, 7);
  93. _reason.CreateUserID = -1;
  94. _reason.UpdateDate = new DateTime(2013, 10, 1, 9, 23, 7);
  95. _reason.UpdateUserID = -1;
  96. }
  97. }
  98. }