private int CheckTimerInterval(bool isACON, int decDelayTime) { if (isACON == false) { SendDataTimer.Interval = Convert.ToInt32(TBox_DelayTime.Text) * 1000; } else { if ((normalDelayTime > (decDelayTime * timeIntervalCounter)) && (isTimerInvalid == false)) { SendDataTimer.Interval = normalDelayTime - (decDelayTime * timeIntervalCounter); } else { isTimerInvalid = true; if (thd.IsAlive) { Btn_Start.Invoke(new Action(() => { Btn_All_Lock(false); StopDataReceivedEvent(); })); //unlocked all button and stop data recervied event thd.Abort(); thd.Join(); } } } return(SendDataTimer.Interval + 3); }
// ID, Code, Description, supplierCode, additionalInfo, imageURL, Unit, BulkPrice, // StandardPrice, stockNSW, stockQLD, stockVIC, stockWA, barcode, barcodeInner, brand, categories private void GetInformation(IWebDriver driver, string ID, string ca) { try { var details = driver.FindElement(By.Id("ctl00_lblHeaderMain")); } catch (Exception) { // MessageBox.Show("You have a problem, Please restart !!!"); Stop(); Thread.Sleep(1000); Btn_Start.PerformClick(); } try { Employee emp = new Employee(); Thread.Sleep(1000); emp.ID = ID; // ID emp.Code = driver.FindElement(By.Id("ctl00_contentMain_lblCode")).Text; // Code emp.Description = driver.FindElement(By.Id("ctl00_contentMain_lblProductHeader")).Text; // Description emp.supplierCode = driver.FindElement(By.Id("ctl00_contentMain_lblSupplierCode")).Text; // supplierCode string info = ""; try { info = driver.FindElement(By.Id("ctl00_contentMain_LoginView2_lblAdditionalDescription1")).Text; } catch (Exception) { } emp.additionalInfo = info; // additionalInfo emp.imageURL = driver.FindElement(By.Id("ctl00_contentMain_imgProduct")).GetAttribute("href"); // imageURL emp.Unit = driver.FindElement(By.Id("ctl00_contentMain_lblUnit")).Text; // Unit emp.BulkPrice = driver.FindElement(By.Id("ctl00_contentMain_lblPickupPrice")).Text.Split(' ')[0]; // BulkPrice emp.StandardPrice = driver.FindElement(By.Id("ctl00_contentMain_lblDeliveredPrice")).Text.Split(' ')[0]; // StandardPrice emp.stockNSW = driver.FindElement(By.Id("ctl00_contentMain_lblRealtimeStockNSW")).Text.Split(' ')[0]; // stockNSW emp.stockQLD = driver.FindElement(By.Id("ctl00_contentMain_lblRealtimeStockQLD")).Text.Split(' ')[0]; // stockQLD emp.stockVIC = driver.FindElement(By.Id("ctl00_contentMain_lblRealtimeStockVIC")).Text.Split(' ')[0]; // stockVIC emp.stockWA = driver.FindElement(By.Id("ctl00_contentMain_lblRealtimeStockWA")).Text.Split(' ')[0]; // stockWA emp.barcode = driver.FindElement(By.Id("ctl00_contentMain_lblBarcode")).Text; // barcode emp.barcodeInner = driver.FindElement(By.Id("ctl00_contentMain_lblbarcodeInner")).Text; // barcodeInner emp.brand = driver.FindElement(By.Id("ctl00_contentMain_lblBrand")).Text; // brand emp.categories = ca; // categories List <Employee> list = new List <Employee>(); try { using (var textReader = File.OpenText(SAVEPATH)) { var csv = new CsvReader(textReader); while (csv.Read()) { var record = csv.GetRecord <Employee>(); list.Add(record); } textReader.Close(); } } catch (Exception) { } list.Add(emp); using (StreamWriter sw = new StreamWriter(SAVEPATH)) using (CsvWriter cw = new CsvWriter(sw)) { cw.WriteHeader <Employee>(); foreach (Employee item in list) { cw.WriteRecord <Employee>(item); } } Thread.Sleep(500); } catch (Exception e) { Console.Write(e.ToString()); } }