Replacement for JDIS Importer
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

1141 satır
54 KiB

  1. using System.Collections.Generic;
  2. using System;
  3. using System.Text;
  4. using System.Threading.Tasks;
  5. using Microsoft.Identity.Client;
  6. using Microsoft.Exchange.WebServices.Data;
  7. using System.IO;
  8. using System.Data;
  9. using System.Data.SqlClient;
  10. using System.Reflection;
  11. using jdis_import.RESTObjects;
  12. using System.Linq;
  13. /*
  14. Secret Value up-8Q~y46~JyQZjJlsAJ-zpXpglpmuPIJ1Gx3a2O
  15. Secret ID cba04a6c-a233-4646-909b-b50921edbe1c
  16. Client ID 489776b1-ee79-4b14-bc44-9f6bf47332db
  17. Object ID c7647074-edb6-4e8e-8a01-a1ed924fdae9
  18. Tenant ID 1fd06c96-d3a4-45e9-9ed7-bcecb394d277
  19. */
  20. namespace jdis_import
  21. {
  22. class Program
  23. {
  24. private static bool _runAPI = true;
  25. private static RESTService _rservice;
  26. private static List<User> _users;
  27. private static Priority _priority;
  28. private static Reason _reason;
  29. private static Status _status;
  30. private static List<Equipment> _machines;
  31. private static List<Customer> _customers;
  32. private static List<Make> _makes;
  33. private static List<Product> _products;
  34. private static List<Model> _models;
  35. private static List<InspectionType> _inspectionTypes;
  36. private static List<Template> _templates;
  37. private static string _exeDir;
  38. private static bool _log = true;
  39. private static string _connection = "Data Source=192.168.0.7;Initial Catalog=Connexion_Brandt;User ID=mobilepmuser;Password=data4techs;Encrypt=No;TrustServerCertificate=true;Persist Security Info=True;";
  40. private static string _workOrderNumber = string.Empty;
  41. private static List<string> _sqlMessages = new List<string>();
  42. private static bool _newMachine = false;
  43. private static bool _newMake = false;
  44. private static bool _newModel = false;
  45. private static bool _newCustomer = false;
  46. private static bool _quoted = false;
  47. public static string ExeDir { get { return _exeDir; } }
  48. private static Dictionary<string, string> _keys = new Dictionary<string, string>() { { "SecretV", "up-8Q~y46~JyQZjJlsAJ-zpXpglpmuPIJ1Gx3a2O" }, { "SecretID", "cba04a6c-a233-4646-909b-b50921edbe1c" }, { "ObjectId", "c7647074-edb6-4e8e-8a01-a1ed924fdae9" }, { "TenentID", "1fd06c96-d3a4-45e9-9ed7-bcecb394d277" }, { "AppID", "489776b1-ee79-4b14-bc44-9f6bf47332db" } };
  49. public static Dictionary<string, int> InspectionType;
  50. private static Customer CreateNewCustomer(CustomerImport c, ToDo todo)
  51. {
  52. Customer cust = new Customer();
  53. cust.Name = c.Name;
  54. cust.Address = c.Addr1;
  55. cust.Address2 = c.Addr2;
  56. cust.City = c.City;
  57. cust.State = c.State;
  58. cust.CreateDate = DateTime.Now;
  59. cust.CreateUserID = -1;
  60. cust.UpdateDate = DateTime.Now;
  61. cust.UpdateUserID = -1;
  62. cust.IsActive = true;
  63. cust.Number = c.Number;
  64. cust.ZipCode = c.Zip;
  65. string json = Serialize.ToJson<Customer>(cust);
  66. cust = _rservice.PostRest<Customer>(json, "customers.svc");
  67. return cust;
  68. }
  69. private static Model CreateNewModel(Product defaultP, EquipmentImport eq, ToDo todo)
  70. {
  71. Model mdl = new Model();
  72. //Find the Make and assign the default Product
  73. mdl.Name = eq.Model.Trim();
  74. mdl.IsActive = true;
  75. mdl.CreateDate = DateTime.Now;
  76. mdl.CreateUserID = -1;
  77. mdl.UpdateDate = DateTime.Now; ;
  78. mdl.UpdateUserID = -1;
  79. mdl.Product = defaultP;
  80. Make mk = (from x in _makes where x.Name.Trim() == eq.Make.Trim() select x).FirstOrDefault();
  81. if (mk == null)
  82. {
  83. //Create new Make
  84. mk.Name = eq.Make.Trim();
  85. mk.CreateDate = DateTime.Now;
  86. mk.CreateUserID = -1;
  87. mk.UpdateDate = DateTime.Now;
  88. mk.UpdateUserID = -1;
  89. mk.IsActive = true;
  90. mk.Description = eq.Make.Trim();
  91. string mkJson = Serialize.ToJson<Make>(mk);
  92. mk = _rservice.PostRest<Make>(mkJson, "makes.svc");
  93. }
  94. mdl.Make = mk;
  95. string json = Serialize.ToJson<Model>(mdl);
  96. mdl = _rservice.PostRest<Model>(json, "models.svc");
  97. return mdl;
  98. }
  99. private static Equipment CreateNewMachine(EquipmentImport eq, Model mdl, Customer cust, ToDo todo)
  100. {
  101. Equipment newMachine = new Equipment();
  102. newMachine.Model = mdl;
  103. newMachine.Make = mdl.Make;
  104. newMachine.Product = mdl.Product;
  105. newMachine.BarcodeID = null;
  106. newMachine.CreateDate = DateTime.Now;
  107. newMachine.UpdateDate = DateTime.Now;
  108. newMachine.UpateUserID = -1;
  109. newMachine.CreateUserID = -1;
  110. newMachine.Description = eq.SerialNumber;
  111. newMachine.IsActive = true;
  112. newMachine.LastServiceDate = null;
  113. newMachine.Location = null;
  114. newMachine.ManufacturerYear = "2000";
  115. newMachine.MeterReading = eq.MeterReading;
  116. newMachine.Number = eq.EquipmentNumber;
  117. newMachine.Odometer = null;
  118. newMachine.SerialNumber = eq.SerialNumber;
  119. newMachine.Customer = cust;
  120. string eqJson = Serialize.ToJson<Equipment>(newMachine);
  121. newMachine = _rservice.PostRest<Equipment>(eqJson, "Equipments.svc");
  122. return newMachine;
  123. }
  124. public static void APIPush(CustomerImport c, WorkOrderImport wo, List<PartImport> parts, EquipmentImport eq, ToDo todo)
  125. {
  126. Equipment machine = new Equipment();
  127. Model mdl = _models.Find(x => x.Name.Trim() == eq.Model.Trim());
  128. Product defaultP = _products.Find(x => x.ID == 14);
  129. //Customer cust = new Customer();
  130. Customer cust = IsNewCustomer(c.Name);
  131. if (cust == null)
  132. cust = CreateNewCustomer(c, todo);
  133. List<Equipment> equipment = IsNewMachine(eq.SerialNumber);
  134. _newMachine = equipment.Count == 0;
  135. if (_newMachine)
  136. {
  137. bool isNewModel = mdl == null;
  138. if (isNewModel)
  139. {
  140. string sModel = eq.Model.Trim().Substring(0, eq.Model.Length - 1);
  141. mdl = (from x in _models where x.Name.Contains(sModel) orderby x.ID select x).LastOrDefault();
  142. if (mdl == null)
  143. mdl = CreateNewModel(defaultP, eq, todo);
  144. else
  145. machine = CreateNewMachine(eq, mdl, cust, todo);
  146. }
  147. else
  148. {
  149. machine = CreateNewMachine(eq, mdl, cust, todo);
  150. }
  151. }
  152. else
  153. {
  154. machine = equipment.FindAll(x => x.SerialNumber == eq.SerialNumber).LastOrDefault();
  155. machine.Customer = cust;
  156. }
  157. //Find the Template
  158. Template template = _templates.Find(x => x.InspectionLevel.ID == Convert.ToInt32(wo.InspectionLevel) && x.InspectionType.ID == Convert.ToInt32(wo.InspectionType) && x.Name == eq.Model);
  159. if (template == null)
  160. {
  161. //Search by model prefix and get the last one
  162. string prefix = eq.Model.Trim();
  163. prefix = prefix.Substring(0, prefix.Length - 1);
  164. template = (from x in _templates where x.InspectionLevel.ID == Convert.ToInt32(wo.InspectionLevel) && x.InspectionType.ID == Convert.ToInt32(wo.InspectionType) && x.Name.Contains(prefix) orderby x.ID select x).LastOrDefault();
  165. if (template == null || template.ID == 0)
  166. {
  167. todo.Success = false;
  168. todo.Validation = todo.Validation + " No template for this model.";
  169. }
  170. }
  171. User user = _users.Find(x => x.Number == wo.TechnicianUserID.Trim());
  172. WorkOrder workorder = new WorkOrder();
  173. workorder.Number = wo.Number;
  174. workorder.Technician = user;
  175. workorder.Reason = _reason;
  176. workorder.Priority = _priority;
  177. workorder.Status = _status;
  178. workorder.CreateDate = DateTime.Now;
  179. workorder.CreateUserID = -1;
  180. workorder.Equipment = machine;
  181. workorder.Customer = cust;
  182. workorder.MeterReading = Convert.ToDecimal(eq.MeterReading);
  183. workorder.ScheduledStartDate = wo.OpnDt;
  184. workorder.ScheduledEndDate = wo.OpnDt.AddDays(1d);
  185. workorder.UpdateDate = DateTime.Now;
  186. workorder.UpdateUserID = -1;
  187. string woJson = Serialize.ToJson<WorkOrder>(workorder);
  188. Console.WriteLine("WorkOrder Object");
  189. Console.WriteLine();
  190. Console.WriteLine(woJson);
  191. workorder = _rservice.PostRest<WorkOrder>(woJson, "workorders.svc");
  192. if (template == null || template.ID == 0)
  193. {
  194. todo.Validation = todo.Validation + Environment.NewLine + string.Format("Work Order {0} was created but there is no template matching model # {1}", workorder.Number, mdl.Name);
  195. todo.Success = false;
  196. }
  197. else
  198. {
  199. Dictionary<string, string> tps = new Dictionary<string, string>();
  200. tps.Add("create", string.Format("{0}/{1}/{2}", template.ID, workorder.ID, -1));
  201. Inspection i = _rservice.RestGet<Inspection>(true, "inspections.svc", tps);
  202. tps["create"] = string.Format("{0}/{1}/{2}", 1691, workorder.ID, -1);
  203. Inspection sta = _rservice.RestGet<Inspection>(true, "inspections.svc", tps);
  204. if (i != null && i.ID != 0)
  205. {
  206. todo.Success = true;
  207. }
  208. }
  209. }
  210. private static Customer IsNewCustomer(string name)
  211. {
  212. List<Customer> list = _customers.FindAll(x => x.Name.Trim() == name.Trim());
  213. if (list.Count > 1)
  214. return list.LastOrDefault();
  215. else if (list.Count == 1)
  216. return list[0];
  217. else return null;
  218. }
  219. private static List<Equipment> IsNewMachine(string serial)
  220. {
  221. Dictionary<string, string> ps = new Dictionary<string, string>();
  222. ps.Add("search", serial);
  223. _machines = _rservice.RestGet<Equipment>("equipments.svc", ps);
  224. return _machines;
  225. }
  226. private static void ListsAndDefaults()
  227. {
  228. _rservice = new RESTService();
  229. _customers = _rservice.RestGet<Customer>("customers.svc");
  230. _makes = _rservice.RestGet<Make>("makes.svc");
  231. _products = _rservice.RestGet<Product>("products.svc");
  232. _models = _rservice.RestGet<Model>("models.svc");
  233. _inspectionTypes = _rservice.RestGet<InspectionType>("inspectionTypes.svc");
  234. _templates = _rservice.RestGet<Template>("templates.svc");
  235. _users = _rservice.RestGet<User>("users.svc");
  236. _status = new Status();
  237. _status.ID = 1;
  238. _status.Name = "Open";
  239. _priority = new Priority();
  240. _priority.ID = 3;
  241. _priority.Name = "Medium";
  242. _reason = new Reason();
  243. _reason.ID = 9;
  244. _reason.Name = "Cust. Request";
  245. _reason.IsActive = true;
  246. _reason.CreateDate = new DateTime(2013, 10, 1, 9, 23, 7);
  247. _reason.CreateUserID = -1;
  248. _reason.UpdateDate = new DateTime(2013, 10, 1, 9, 23, 7);
  249. _reason.UpdateUserID = -1;
  250. }
  251. static async System.Threading.Tasks.Task Main(string[] args)
  252. {
  253. ListsAndDefaults();
  254. Console.WriteLine("Web APIs have loaded.");
  255. _exeDir = Environment.CurrentDirectory;
  256. SetupDirectories();
  257. List<ToDo> list = new List<ToDo>();
  258. var cca = ConfidentialClientApplicationBuilder
  259. .Create(_keys["AppID"])
  260. .WithClientSecret(_keys["SecretV"])
  261. .WithTenantId(_keys["TenentID"])
  262. .Build();
  263. var ewsScopes = new string[] { "https://outlook.office365.com/.default" };
  264. try
  265. {
  266. Console.WriteLine("Connecting To Exchange.");
  267. var authResult = await cca.AcquireTokenForClient(ewsScopes)
  268. .ExecuteAsync();
  269. // Configure the ExchangeService with the access token
  270. var ewsClient = new ExchangeService();
  271. ewsClient.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
  272. ewsClient.Credentials = new OAuthCredentials(authResult.AccessToken);
  273. ewsClient.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "cmobile@prelub.com");
  274. Mailbox mb = new Mailbox("connexionmobile@rpmindustries.org");
  275. FolderId fid = new FolderId(WellKnownFolderName.Inbox, mb);
  276. List<SearchFilter> searchFilterCollection = new List<SearchFilter>();
  277. string[] filters = "Brandt Import;BRANDT IMPORT;brandt import;TEST Brandt".Split(';');
  278. foreach (string s in filters)
  279. searchFilterCollection.Add(new SearchFilter.ContainsSubstring(ItemSchema.Subject, s));
  280. SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchFilterCollection.ToArray());
  281. ItemView view = new ItemView(100);
  282. view.PropertySet = new PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject, ItemSchema.DateTimeReceived);
  283. view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending);
  284. view.Traversal = ItemTraversal.Shallow;
  285. Console.WriteLine("Line 90: Finding emails.");
  286. FindItemsResults<Item> findResults = ewsClient.FindItems(fid, searchFilter, view);
  287. foreach (EmailMessage msg in findResults.Items)
  288. {
  289. msg.Load();
  290. if (!msg.IsRead)
  291. {
  292. if (msg.HasAttachments)
  293. {
  294. foreach (Attachment attachment in msg.Attachments)
  295. {
  296. attachment.Load();
  297. if (attachment is FileAttachment)
  298. {
  299. ToDo todo = new ToDo();
  300. todo.Sender = msg.Sender.Address;
  301. todo.SenderName = msg.Sender.Name;
  302. todo.FileName = attachment.Name;
  303. list.Add(todo);
  304. //Download File
  305. FileAttachment fAttachment = attachment as FileAttachment;
  306. string fileAttachmentPath = Path.Combine(_exeDir, fAttachment.Name);
  307. File.WriteAllBytes(fileAttachmentPath, fAttachment.Content);
  308. msg.IsRead = true;
  309. msg.Update(ConflictResolutionMode.AlwaysOverwrite);
  310. }
  311. }
  312. }
  313. }
  314. }
  315. Console.WriteLine("Beginning Import.");
  316. foreach (ToDo import in list)
  317. {
  318. BeginImport(import);
  319. GetInspectionTypes();
  320. ReadFile(import);
  321. }
  322. foreach (ToDo sendMsg in list)
  323. {
  324. EmailMessage msgToSend = new EmailMessage(ewsClient);
  325. string body = "JDIS File: {0} Work Order:{1} {2}";
  326. if (sendMsg.Success)
  327. {
  328. body = string.Format(body, sendMsg.FileName.Substring(sendMsg.FileName.LastIndexOf("/") + 1).Trim(), sendMsg.WorkOrderNumber, "Was Imported Successfully");
  329. }
  330. else
  331. {
  332. body = string.Format(body, sendMsg.FileName.Substring(sendMsg.FileName.LastIndexOf("/") + 1).Trim(), sendMsg.WorkOrderNumber, string.Format("Had Errors while importing: {0}", sendMsg.Validation));
  333. msgToSend.Attachments.AddFileAttachment(Path.Combine(_exeDir, sendMsg.FileName));
  334. }
  335. string fileNameOnly = sendMsg.FileName.Substring(sendMsg.FileName.LastIndexOf("/") + 1);
  336. msgToSend.Subject = fileNameOnly;
  337. msgToSend.ToRecipients.Add(new EmailAddress(sendMsg.Sender));
  338. msgToSend.CcRecipients.Add(new EmailAddress("mcarman@rpmindustries.com"));
  339. msgToSend.Body = body;
  340. msgToSend.SendAndSaveCopy();
  341. string pathToFile = Path.Combine(_exeDir, sendMsg.FileName);
  342. if (sendMsg.Success) File.Move(pathToFile, Path.Combine(_exeDir, "Success", fileNameOnly));
  343. else File.Move(sendMsg.FileName, Path.Combine(_exeDir, "Fail", fileNameOnly));
  344. }
  345. }
  346. catch (MsalException ex)
  347. {
  348. Console.WriteLine($"Error acquiring access token: {ex}");
  349. }
  350. catch (Exception ex)
  351. {
  352. Console.WriteLine($"Error: {ex}");
  353. }
  354. if (System.Diagnostics.Debugger.IsAttached)
  355. {
  356. Console.WriteLine("Hit any key to exit...");
  357. Console.ReadKey();
  358. }
  359. }
  360. public static void BeginImport(ToDo todo)
  361. {
  362. XMLData.BuildIntervalLookup();
  363. }
  364. private static void SetupDirectories()
  365. {
  366. string path = Path.Combine(_exeDir, "Success");
  367. if (!Directory.Exists(path))
  368. Directory.CreateDirectory(path);
  369. path = Path.Combine(_exeDir, "Fail");
  370. if (!Directory.Exists(path))
  371. Directory.CreateDirectory(path);
  372. path = Path.Combine(_exeDir, "Log");
  373. if (!Directory.Exists(path))
  374. Directory.CreateDirectory(path);
  375. }
  376. public static void GetInspectionTypes()
  377. {
  378. List<InspectionType> list = _rservice.RestGet<InspectionType>("inspectiontypes.svc");
  379. InspectionType = new Dictionary<string, int>();
  380. foreach (InspectionType t in list)
  381. {
  382. InspectionType.Add(t.Name, t.ID);
  383. }
  384. /*
  385. SqlConnection con = new SqlConnection("Data Source=192.168.0.7;Initial Catalog=Connexion_Brandt;User ID=mobilepmuser;Password=data4techs;Encrypt=No;TrustServerCertificate=true;Persist Security Info=True;");
  386. con.Open();
  387. SqlCommand cmd = con.CreateCommand();
  388. cmd.CommandTimeout = 0;
  389. cmd.Connection = con;
  390. cmd.CommandText = "Select ID, [Name] From InspectionType";
  391. cmd.CommandType = CommandType.Text;
  392. DataSet ds = new DataSet();
  393. SqlDataAdapter da = new SqlDataAdapter(cmd);
  394. da.Fill(ds);
  395. foreach (DataRow row in ds.Tables[0].Rows)
  396. {
  397. InspectionType.Add(row["Name"].ToString(), Convert.ToInt32(row["ID"]));
  398. }
  399. ds.Dispose();
  400. cmd.Dispose();
  401. con.Close();
  402. con.Dispose();
  403. */
  404. }
  405. private static string frmtString
  406. {
  407. get
  408. {
  409. if (_quoted) return "\"{0}\"";
  410. else return "{0}";
  411. }
  412. }
  413. private static List<string> WriteFileToText(string file)
  414. {
  415. List<string> list = new List<string>();
  416. string txt = string.Empty;
  417. using (StreamReader sr = new StreamReader(file))
  418. {
  419. txt = sr.ReadToEnd().Trim();
  420. txt = txt.Replace("\r\r\r", "");
  421. txt = txt.Replace("\r\r", "");
  422. txt = txt.Replace("\r", "");
  423. sr.Close();
  424. }
  425. string[] array = txt.Trim().Split('\n');
  426. list.AddRange(array);
  427. return list;
  428. }
  429. private static DateTime DateFormatter(string d, bool hastime = true)
  430. {
  431. string month, day, year, time;
  432. DateTime dt = new DateTime();
  433. if (d.IndexOf("JAN") != -1)
  434. {
  435. month = "01";
  436. d = d.Replace("JAN", "|");
  437. day = d.Substring(0, d.IndexOf("|"));
  438. year = d.Substring(d.IndexOf("|") + 1, 4);
  439. if (hastime)
  440. time = d.Substring(d.IndexOf(":") - 3 + 2);
  441. else time = "00:00:00.000";
  442. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  443. dt = DateTime.Parse(date);
  444. }
  445. else if (d.IndexOf("FEB") != -1)
  446. {
  447. month = "02";
  448. d = d.Replace("FEB", "|");
  449. day = d.Substring(0, d.IndexOf("|"));
  450. year = d.Substring(d.IndexOf("|") + 1, 4);
  451. if (hastime)
  452. time = d.Substring(d.IndexOf(":") - 3 + 2);
  453. else time = "00:00:00.000";
  454. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  455. dt = DateTime.Parse(date);
  456. }
  457. else if (d.IndexOf("MARCH") != -1)
  458. {
  459. month = "03";
  460. d = d.Replace("MARCH", "|");
  461. day = d.Substring(0, d.IndexOf("|"));
  462. year = d.Substring(d.IndexOf("|") + 1, 4);
  463. if (hastime)
  464. time = d.Substring(d.IndexOf(":") - 3 + 2);
  465. else time = "00:00:00.000";
  466. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  467. dt = DateTime.Parse(date);
  468. }
  469. else if (d.IndexOf("MAR") != -1)
  470. {
  471. month = "03";
  472. d = d.Replace("MAR", "|");
  473. day = d.Substring(0, d.IndexOf("|"));
  474. year = d.Substring(d.IndexOf("|") + 1, 4);
  475. if (hastime)
  476. time = d.Substring(d.IndexOf(":") - 3 + 2);
  477. else time = "00:00:00.000";
  478. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  479. dt = DateTime.Parse(date);
  480. }
  481. else if (d.IndexOf("APRIL") != -1)
  482. {
  483. month = "04";
  484. d = d.Replace("APRIL", "|");
  485. day = d.Substring(0, d.IndexOf("|"));
  486. year = d.Substring(d.IndexOf("|") + 1, 4);
  487. if (hastime)
  488. time = d.Substring(d.IndexOf(":") - 3 + 2);
  489. else time = "00:00:00.000";
  490. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  491. dt = DateTime.Parse(date);
  492. }
  493. else if (d.IndexOf("APR") != -1)
  494. {
  495. month = "04";
  496. d = d.Replace("APR", "|");
  497. day = d.Substring(0, d.IndexOf("|"));
  498. year = d.Substring(d.IndexOf("|") + 1, 4);
  499. if (hastime)
  500. time = d.Substring(d.IndexOf(":") - 3 + 2);
  501. else time = "00:00:00.000";
  502. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  503. dt = DateTime.Parse(date);
  504. }
  505. else if (d.IndexOf("MAY") != -1)
  506. {
  507. month = "05";
  508. d = d.Replace("MAY", "|");
  509. day = d.Substring(0, d.IndexOf("|"));
  510. year = d.Substring(d.IndexOf("|") + 1, 4);
  511. if (hastime)
  512. time = d.Substring(d.IndexOf(":") - 3 + 2);
  513. else time = "00:00:00.000";
  514. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  515. dt = DateTime.Parse(date);
  516. }
  517. else if (d.IndexOf("JUNE") != -1)
  518. {
  519. month = "06";
  520. d = d.Replace("JUNE", "|");
  521. day = d.Substring(0, d.IndexOf("|"));
  522. year = d.Substring(d.IndexOf("|") + 1, 4);
  523. if (hastime)
  524. time = d.Substring(d.IndexOf(":") - 3 + 2);
  525. else time = "00:00:00.000";
  526. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  527. dt = DateTime.Parse(date);
  528. }
  529. else if (d.IndexOf("JUN") != -1)
  530. {
  531. month = "06";
  532. d = d.Replace("JUN", "|");
  533. day = d.Substring(0, d.IndexOf("|"));
  534. year = d.Substring(d.IndexOf("|") + 1, 4);
  535. if (hastime)
  536. time = d.Substring(d.IndexOf(":") - 3 + 2);
  537. else time = "00:00:00.000";
  538. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  539. dt = DateTime.Parse(date);
  540. }
  541. else if (d.IndexOf("JULY") != -1)
  542. {
  543. month = "07";
  544. d = d.Replace("JULY", "|");
  545. day = d.Substring(0, d.IndexOf("|"));
  546. year = d.Substring(d.IndexOf("|") + 1, 4);
  547. if (hastime)
  548. time = d.Substring(d.IndexOf(":") - 3 + 2);
  549. else time = "00:00:00.000";
  550. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  551. dt = DateTime.Parse(date);
  552. }
  553. else if (d.IndexOf("JUL") != -1)
  554. {
  555. month = "07";
  556. d = d.Replace("JUL", "|");
  557. day = d.Substring(0, d.IndexOf("|"));
  558. year = d.Substring(d.IndexOf("|") + 1, 4);
  559. if (hastime)
  560. time = d.Substring(d.IndexOf(":") - 3 + 2);
  561. else time = "00:00:00.000";
  562. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  563. dt = DateTime.Parse(date);
  564. }
  565. else if (d.IndexOf("AUG") != -1)
  566. {
  567. month = "08";
  568. d = d.Replace("AUG", "|");
  569. day = d.Substring(0, d.IndexOf("|"));
  570. year = d.Substring(d.IndexOf("|") + 1, 4);
  571. if (hastime)
  572. time = d.Substring(d.IndexOf(":") - 3 + 2);
  573. else time = "00:00:00.000";
  574. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  575. dt = DateTime.Parse(date);
  576. }
  577. else if (d.IndexOf("SEPT") != -1)
  578. {
  579. month = "09";
  580. d = d.Replace("SEPT", "|");
  581. day = d.Substring(0, d.IndexOf("|"));
  582. year = d.Substring(d.IndexOf("|") + 1, 4);
  583. if (hastime)
  584. time = d.Substring(d.IndexOf(":") - 3 + 2);
  585. else time = "00:00:00.000";
  586. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  587. dt = DateTime.Parse(date);
  588. }
  589. else if (d.IndexOf("SEP") != -1)
  590. {
  591. month = "09";
  592. d = d.Replace("SEP", "|");
  593. day = d.Substring(0, d.IndexOf("|"));
  594. year = d.Substring(d.IndexOf("|") + 1, 4);
  595. if (hastime)
  596. time = d.Substring(d.IndexOf(":") - 3 + 2);
  597. else time = "00:00:00.000";
  598. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  599. dt = DateTime.Parse(date);
  600. }
  601. else if (d.IndexOf("OCT") != -1)
  602. {
  603. month = "10";
  604. d = d.Replace("OCT", "|");
  605. day = d.Substring(0, d.IndexOf("|"));
  606. year = d.Substring(d.IndexOf("|") + 1, 4);
  607. if (hastime)
  608. time = d.Substring(d.IndexOf(":") - 3 + 2);
  609. else time = "00:00:00.000";
  610. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  611. dt = DateTime.Parse(date);
  612. }
  613. else if (d.IndexOf("0CT") != -1)
  614. {
  615. month = "10";
  616. d = d.Replace("0CT", "|");
  617. day = d.Substring(0, d.IndexOf("|"));
  618. year = d.Substring(d.IndexOf("|") + 1, 4);
  619. if (hastime)
  620. time = d.Substring(d.IndexOf(":") - 3 + 2);
  621. else time = "00:00:00.000";
  622. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  623. dt = DateTime.Parse(date);
  624. }
  625. else if (d.IndexOf("NOV") != -1)
  626. {
  627. month = "11";
  628. d = d.Replace("NOV", "|");
  629. day = d.Substring(0, d.IndexOf("|"));
  630. year = d.Substring(d.IndexOf("|") + 1, 4);
  631. if (hastime)
  632. time = d.Substring(d.IndexOf(":") - 3 + 2);
  633. else time = "00:00:00.000";
  634. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  635. dt = DateTime.Parse(date);
  636. }
  637. else
  638. {
  639. month = "12";
  640. d = d.Replace("DEC", "|");
  641. day = d.Substring(0, d.IndexOf("|"));
  642. year = d.Substring(d.IndexOf("|") + 1, 4);
  643. if (hastime)
  644. time = d.Substring(d.IndexOf(":") - 3 + 2);
  645. else time = "00:00:00.000";
  646. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  647. dt = DateTime.Parse(date);
  648. }
  649. return dt;
  650. }
  651. private static void ReadFile(ToDo todo)
  652. {
  653. string file = Path.Combine(_exeDir, todo.FileName);// todo.FileName;
  654. todo.FileName = file;
  655. CustomerImport c = new CustomerImport();
  656. WorkOrderImport wo = new WorkOrderImport();
  657. EquipmentImport eq = new EquipmentImport();
  658. List<PartImport> parts = new List<PartImport>();
  659. Console.WriteLine("Line 306: " + file);
  660. Console.WriteLine("Line 307: " + file);
  661. string filemove = string.Empty;
  662. string filetxt = string.Empty;
  663. string inspectionLevel = string.Empty;
  664. bool isSpecial = false;
  665. StringBuilder specialInstructions = new StringBuilder();
  666. int line = 1;
  667. try
  668. {
  669. List<string> filelines = WriteFileToText(file);
  670. for (int i = filelines.Count - 1; i >= 0; i--)
  671. {
  672. if (string.IsNullOrEmpty(filelines[i])) filelines.RemoveAt(i);
  673. }
  674. string[] lines = filelines.ToArray();
  675. foreach (string s in lines)
  676. {
  677. string currentline = s.Trim().Replace("'", "''");
  678. if (currentline.Contains("Page") && currentline.Substring(78).Trim() != "1")
  679. line = 18;
  680. if (currentline.Contains("Page") && currentline.Substring(78).Trim() == "1")
  681. line = 1;
  682. switch (line)
  683. {
  684. case 1:
  685. string strDate = currentline.Substring(5, currentline.IndexOf("*") - 6);
  686. strDate = strDate.Trim();
  687. strDate.Replace(" ", " ");
  688. wo.CreateDate = DateFormatter(strDate);
  689. break;
  690. case 2:
  691. string strWONum = currentline.Substring(currentline.IndexOf("Work Order") + 10, 12);
  692. strWONum = strWONum.Trim();
  693. wo.Number = strWONum;
  694. todo.WorkOrderNumber = strWONum;
  695. _workOrderNumber = strWONum;
  696. string strSeg = currentline.Substring(currentline.IndexOf("Seg.") + 4, 25);
  697. strSeg = strSeg.Trim();
  698. wo.Segment = strSeg;
  699. string strODate = currentline.Substring(currentline.IndexOf("Opn Dt") + 6);
  700. strODate = strODate.Trim();
  701. wo.OpnDt = DateFormatter(strODate, false);
  702. break;
  703. case 5:
  704. c.Name = currentline.Substring(3, 25);
  705. c.Number = currentline.Substring(38, 10);
  706. break;
  707. case 6:
  708. c.Addr1 = currentline.Substring(3, 25);
  709. break;
  710. case 7:
  711. c.Addr2 = currentline.Substring(3, 25);
  712. break;
  713. case 8:
  714. int comma = currentline.IndexOf(",");
  715. int length = currentline.Length - 3;
  716. c.City = (comma == -1) ? "" : currentline.Substring(3, comma - 3);
  717. c.State = currentline.Substring(currentline.IndexOf(",") + 2, 2);
  718. c.Zip = currentline.Substring(comma + 5, 7);
  719. break;
  720. case 11:
  721. eq.Make = currentline.Substring(0, 8).Trim();
  722. eq.Model = currentline.Substring(8, 14).Trim();
  723. eq.SerialNumber = currentline.Substring(22, 22).Trim();
  724. eq.EquipmentNumber = currentline.Substring(42, 16).Trim();
  725. eq.MeterReading = currentline.Substring(60, 7).Trim();
  726. eq.MID = CSVObject.MachineExists(eq.SerialNumber, _connection);
  727. if (eq.MID == 0) _newMachine = true;
  728. break;
  729. default:
  730. break;
  731. }
  732. if (line > 14)
  733. {
  734. if (currentline.EndsWith(" T"))
  735. {
  736. if (currentline.Contains("PM LEVEL"))
  737. {
  738. isSpecial = false;
  739. }
  740. else if (currentline.Contains("PM INTERVAL"))
  741. {
  742. isSpecial = false;
  743. string pminterval = currentline.Substring(currentline.IndexOf(":") + 2);
  744. pminterval = pminterval.Substring(0, pminterval.IndexOf(" ")).Trim();
  745. if (XMLData.IntervalLookup.ContainsKey(pminterval)) wo.InspectionLevel = XMLData.IntervalLookup[pminterval].ToString();
  746. if (!string.IsNullOrEmpty(wo.InspectionLevel)) wo.InspectionInterval = pminterval;
  747. string strService = currentline.Substring(currentline.IndexOf(":") + 2);
  748. strService = strService.Substring(strService.IndexOf(" ") + 1).Trim();
  749. strService = strService.Substring(0, strService.IndexOf(" ") + 1).Trim();
  750. if (strService.IndexOf(" ") > 0)
  751. strService = strService.Substring(0, strService.IndexOf(" ")).Trim();
  752. if (InspectionType.ContainsKey(strService))
  753. wo.InspectionType = InspectionType[strService].ToString();
  754. else wo.InspectionType = InspectionType["PM"].ToString();
  755. string codeanddescriptionoriginal = currentline.Substring(currentline.IndexOf(":") + 2);
  756. codeanddescriptionoriginal = codeanddescriptionoriginal.Substring(0, codeanddescriptionoriginal.IndexOf(" T") - 3).Trim();
  757. wo.CodeAndDescriptionOriginal = codeanddescriptionoriginal;
  758. }
  759. else if (currentline.Contains("EMPID"))
  760. {
  761. isSpecial = false;
  762. string empid = currentline.Substring(currentline.IndexOf(":") + 2);
  763. empid = empid.Substring(0, empid.IndexOf(" ")).Trim();
  764. wo.TechnicianUserID = empid;
  765. }
  766. else if (currentline.Contains("PROMISE DATE"))
  767. {
  768. isSpecial = false;
  769. string promisedate = currentline.Substring(currentline.IndexOf(":") + 2);
  770. promisedate = promisedate.Substring(0, promisedate.IndexOf(" ")).Trim();
  771. wo.ScheduledStartDate = DateFormatter(promisedate, false);
  772. }
  773. else if (currentline.Contains("SPECIAL INSTRUCTIONS"))
  774. {
  775. isSpecial = true;
  776. string special = currentline.Substring(currentline.IndexOf(":") + 2);
  777. special = special.Substring(0, special.IndexOf(" T") - 1).Trim();
  778. specialInstructions.Append(special);
  779. }
  780. else
  781. {
  782. if (isSpecial)
  783. {
  784. string addspecial = currentline.Substring(0, currentline.IndexOf(" T") - 1).Trim();
  785. specialInstructions.Append(string.Format(" {0}", addspecial));
  786. }
  787. }
  788. }
  789. else
  790. {
  791. isSpecial = false;
  792. int qty = 0;
  793. if (currentline.Length > 0)
  794. {
  795. string input = currentline.Substring(0, (currentline.IndexOf(" ") == -1) ? 1 : currentline.IndexOf(" ")).Trim();
  796. if (int.TryParse(input, out qty))
  797. {
  798. if (qty < 100 && !currentline.Contains("HR"))
  799. {
  800. PartImport pt = new PartImport();
  801. string sline = currentline.Substring(19).Trim();
  802. //pt.Description = currentline.Substring(34, 14);
  803. pt.Number = sline.Substring(0, sline.IndexOf(" "));
  804. sline = sline.Substring(sline.IndexOf(" ")).Trim();
  805. pt.Description = sline.Substring(0, sline.IndexOf(" ")).Trim();
  806. pt.Qty = currentline.Substring(0, currentline.IndexOf(" ")).Trim();
  807. parts.Add(pt);
  808. }
  809. }
  810. }
  811. }
  812. }
  813. line++;
  814. }
  815. if (wo.ScheduledStartDate == DateTime.MinValue) wo.ScheduledStartDate = DateTime.Now;
  816. List<CSVObject> list = new List<CSVObject>();
  817. List<CSVObject> exceptions = new List<CSVObject>();
  818. if (parts.Count == 0)
  819. {
  820. PartImport p = new PartImport();
  821. p.Description = string.Empty;
  822. p.Qty = string.Empty;
  823. p.Number = string.Empty;
  824. parts.Add(p);
  825. }
  826. //Put API Integration here
  827. if (_runAPI)
  828. {
  829. APIPush(c, wo, parts, eq, todo);
  830. }
  831. else
  832. {
  833. static void conn_InfoMsg(object sender, SqlInfoMessageEventArgs e)
  834. {
  835. _sqlMessages.Add(e.Message);
  836. }
  837. foreach (PartImport prt in parts)
  838. {
  839. CSVObject obj = new CSVObject();
  840. obj.Address = string.Format(frmtString, c.Addr1.Trim());
  841. obj.Address2 = string.Format(frmtString, c.Addr2.Trim());
  842. obj.City = string.Format(frmtString, c.City.Trim());
  843. obj.State = string.Format(frmtString, c.State.Trim());
  844. obj.CustomerName = string.Format(frmtString, c.Name.Trim());
  845. obj.CustomerNumber = string.Format(frmtString, c.Number.Trim());
  846. obj.DBSWorkOrderNumber = string.Format(frmtString, wo.Number.Trim());
  847. obj.EquipmentNumber = string.Format(frmtString, eq.EquipmentNumber.Trim());
  848. obj.Make = string.Format(frmtString, eq.Make.Trim());
  849. obj.MeterReading = string.Format(frmtString, eq.MeterReading.Trim());
  850. obj.Model = string.Format(frmtString, eq.Model.Trim());
  851. obj.PartNumber = string.Format(frmtString, prt.Number.Trim());
  852. obj.PartNumberDescription = string.Format(frmtString, prt.Description.Trim());
  853. obj.Quantity = string.Format(frmtString, prt.Qty.Trim());
  854. obj.SegmentNumber = string.Format(frmtString, wo.Segment.Trim());
  855. obj.SerialNumber = string.Format(frmtString, eq.SerialNumber.Trim());
  856. obj.ZipCode = string.Format(frmtString, c.Zip.Trim());
  857. obj.CodeAndDescription = string.Format(frmtString, wo.InspectionLevel.Trim());
  858. obj.SpecialInstructions = specialInstructions.ToString();
  859. obj.CodeAndDescriptionOriginal = string.Format(frmtString, wo.CodeAndDescriptionOriginal);
  860. obj.ContractTypeCode = string.Format(frmtString, "");
  861. obj.DateActualStart = string.Format(frmtString, wo.CreateDate);
  862. obj.FamilyCode = string.Format(frmtString, "");
  863. obj.FamilyDescription = string.Format(frmtString, "");
  864. obj.JobSiteContactName = string.Format(frmtString, "");
  865. obj.JobSiteContactPhone = string.Format(frmtString, "");
  866. obj.LastServiceDate = string.Format(frmtString, "");
  867. obj.PriorityCode = string.Format(frmtString, "");
  868. obj.ReferenceDocNumber = string.Format(frmtString, "");
  869. obj.ServiceTech = string.Format(frmtString, wo.TechnicianUserID);
  870. obj.StoreDescription = string.Format(frmtString, "");
  871. obj.Store = string.Format(frmtString, "");
  872. obj.TechName = string.Format(frmtString, "");
  873. obj.Year = string.Format(frmtString, "");
  874. obj.ScheduledStartDate = string.Format(frmtString, wo.ScheduledStartDate.ToString("yyyy-MM-dd hh:mm:ss"));
  875. obj.InspectionType = string.Format(frmtString, wo.InspectionType.ToString());
  876. obj.Validate();
  877. if (string.IsNullOrEmpty(obj.SerialNumber))
  878. {
  879. exceptions.Add(obj);
  880. //throw new ApplicationException("Serial Number is missing.");
  881. }
  882. else list.Add(obj);
  883. if (list.Count == 0)
  884. {
  885. StringBuilder sbException = new StringBuilder();
  886. foreach (CSVObject csvobj in exceptions)
  887. foreach (PropertyInfo pi in csvobj.GetType().GetProperties())
  888. {
  889. sbException.AppendLine(string.Format("{0}: {1}", pi.Name, pi.GetValue(csvobj, null)));
  890. }
  891. throw new ApplicationException(string.Format("Object Validation Error\r\n{0}", sbException.ToString()));
  892. }
  893. }
  894. filemove = Path.Combine("Success", file);// string.Format("{0}\\{1}\\{2}", _currentDir, _settings["SUCCESSDIR"], file);
  895. try
  896. {
  897. SqlConnection conn = new SqlConnection(_connection);
  898. conn.Open();
  899. string errorstr = CSVObject.WriteToDB(list, conn);
  900. conn.Close();
  901. conn.Dispose();
  902. if (!string.IsNullOrEmpty(errorstr)) throw new ApplicationException(errorstr);
  903. SqlCommand cmd = new SqlCommand("usp_DoImport", new SqlConnection(_connection));
  904. cmd.CommandTimeout = 0;
  905. SqlParameter sqlReturn = cmd.Parameters.Add("@b", SqlDbType.Int);
  906. sqlReturn.Direction = ParameterDirection.ReturnValue;
  907. cmd.Connection.Open();
  908. cmd.Connection.InfoMessage += new SqlInfoMessageEventHandler(conn_InfoMsg);
  909. cmd.Connection.FireInfoMessageEventOnUserErrors = true;
  910. cmd.CommandType = CommandType.StoredProcedure;
  911. cmd.ExecuteNonQuery();
  912. if (Convert.ToInt32(cmd.Parameters["@b"].Value) != 0)
  913. throw new Exception("Error happend in the do import");
  914. cmd.Connection.Close();
  915. cmd.Dispose();
  916. conn.Dispose();
  917. SqlCommand delcmd = new SqlCommand("Delete Results_Brandt", new SqlConnection(_connection));
  918. delcmd.CommandTimeout = 0;
  919. delcmd.Connection.Open();
  920. delcmd.CommandType = CommandType.Text;
  921. try
  922. {
  923. delcmd.ExecuteNonQuery();
  924. }
  925. catch (Exception dex)
  926. {
  927. throw new Exception(dex.Message);
  928. }
  929. delcmd.Connection.Close();
  930. delcmd.Dispose();
  931. }
  932. catch (Exception exSql)
  933. {
  934. string msg = exSql.Message;
  935. string logmsg = string.Format("Date: {0} Error: {1}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt"), exSql.Message);
  936. WriteToLog(logmsg);
  937. todo.Validation = exSql.Message + " " + _workOrderNumber;
  938. filemove = Path.Combine("Fail", todo.FileName);
  939. //File.Move(todo.FileName, filemove);
  940. //MailSvc.SendResponse(msg, _workOrderNumber);
  941. }
  942. Console.WriteLine("Line 584: " + filemove);
  943. if (File.Exists(filemove)) File.Delete(filemove);
  944. //File.Move(file, filemove);
  945. if (_log)
  946. {
  947. string successmsg = string.Format("Success Date: {0} File Name: {1} Work Order #: {2}{3}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt"), file, _workOrderNumber, "********************************");
  948. WriteToLog(successmsg);
  949. if (exceptions.Count > 0)
  950. {
  951. foreach (CSVObject csvobj in exceptions)
  952. {
  953. string csvmsg = string.Format("Null Serial# Exception Date: {0} File Name: {1} Work Order #: {2}{3}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt"), file, _workOrderNumber, "********************************");
  954. WriteToLog(csvmsg);
  955. }
  956. }
  957. if (_sqlMessages.Count > 0)
  958. {
  959. WriteToLog("***********************SQL Messages************************");
  960. foreach (string sqlmessg in _sqlMessages)
  961. WriteToLog(sqlmessg);
  962. WriteToLog("*********************End SQL Messages**********************");
  963. }
  964. }
  965. using (SqlConnection doublecheck = new SqlConnection(_connection))
  966. {
  967. SqlCommand cmddoublecheck = doublecheck.CreateCommand();
  968. cmddoublecheck.Connection.Open();
  969. cmddoublecheck.CommandTimeout = 0;
  970. cmddoublecheck.CommandText = string.Format("Select MAX(ID) from WorkOrder where Number = '{0}'", wo.Number);
  971. cmddoublecheck.CommandType = CommandType.Text;
  972. int rslt = (cmddoublecheck.ExecuteScalar() == DBNull.Value ? 0 : (int)cmddoublecheck.ExecuteScalar());
  973. cmddoublecheck.Dispose();
  974. if (rslt > 0)
  975. {
  976. cmddoublecheck.CommandText = string.Format("Select ID from Inspection where workorderid = {0}", rslt);
  977. rslt = (cmddoublecheck.ExecuteScalar() == DBNull.Value ? 0 : (int)cmddoublecheck.ExecuteScalar());
  978. if (rslt > 0)
  979. {
  980. todo.Success = true;
  981. //MailSvc.SendResponse("Work Order was imported successfully.", wo.Number);
  982. }
  983. else
  984. {
  985. //string noTemplate = string.Format("Work Order was created successfully. However, it appears there is no template for this model: {0}", eq.Model);
  986. todo.Validation = todo.Validation + "\r\n" + string.Format("Work Order was created successfully. However, it appears there is no template for this model: {0}", eq.Model);
  987. todo.Success = false;
  988. }
  989. }
  990. else
  991. {
  992. todo.Validation = todo.Validation + "\r\n" + string.Format("Failed to import work order {0}", wo.Number);//)
  993. }
  994. //MailSvc.SendResponse(string.Format("Failed to import work order {0}.", wo.Number), wo.Number);
  995. }
  996. }
  997. //Console.ReadLine();
  998. }
  999. catch (Exception ex)
  1000. {
  1001. string exMesg = string.Empty;
  1002. try
  1003. {
  1004. exMesg = string.Format("Date: {0} Error: {1}\r\nError occured in line # {2}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt"), ex.Message, line);
  1005. }
  1006. catch (Exception exSend)
  1007. {
  1008. Console.Write(exSend.Message);
  1009. }
  1010. WriteToLog(exMesg);
  1011. filemove = Path.Combine("Fail", file);//, file);
  1012. try
  1013. {
  1014. Console.WriteLine("Line 634: " + file);
  1015. Console.WriteLine("Line 635: " + filemove);
  1016. //File.Move(file, filemove);
  1017. }
  1018. catch (Exception moveExcept)
  1019. {
  1020. Console.WriteLine(moveExcept.Message);
  1021. }
  1022. todo.Success = false;
  1023. todo.Validation = todo.Validation + "\r\n" + string.Format("Failed to import work order {0}. Error: {1}", wo.Number, exMesg);
  1024. //MailSvc.SendResponse(string.Format("Failed to import work order {0}. Error: {1}", wo.Number, exMesg), wo.Number, filemove);
  1025. }
  1026. }
  1027. private static void CreateLogFile(string logfile)
  1028. {
  1029. using (StreamWriter sw = File.CreateText(logfile))
  1030. {
  1031. sw.WriteLine("******************************************");
  1032. sw.WriteLine("****************IMPORT LOG****************");
  1033. sw.WriteLine("******************************************");
  1034. }
  1035. }
  1036. public static void WriteToLog(string message, string sqlmessage = "")
  1037. {
  1038. string logfile = Path.Combine("Log", "log.log");
  1039. if (!File.Exists(logfile))
  1040. {
  1041. CreateLogFile(logfile);
  1042. }
  1043. using (StreamWriter sw = File.AppendText(logfile))
  1044. {
  1045. sw.WriteLine(message);
  1046. if (!string.IsNullOrEmpty(sqlmessage))
  1047. sw.WriteLine(sqlmessage);
  1048. }
  1049. }
  1050. }
  1051. public class ToDo
  1052. {
  1053. private bool _success = false;
  1054. public bool Success { get { return _success; } set { _success = value; } }
  1055. public string Sender { get; set; }
  1056. public string SenderName { get; set; }
  1057. public string FileName { get; set; }
  1058. public string Validation { get; set; }
  1059. public string WorkOrderNumber { get; set; }
  1060. }
  1061. }