void bg_DoWork(object sender, DoWorkEventArgs e) { string fileName = (string)e.Argument; CSVDataLoader csvDL = new CSVDataLoader(); List <RuntimeData> data = csvDL.getRuntimeDataFromPodCSV(fileName, '"', '\''); double progress = 5; bg.ReportProgress((int)progress); double i = 0; double count = data.Count; BillingDataDataContext db = new BillingDataDataContext(); string errorMessage = ""; foreach (RuntimeData rData in data) { try { Transaction trans = db.Transactions.SingleOrDefault(x => x.ConnsignmentNo == rData.ConsignmentNo); if (trans != null) { trans.DeliveryDate = rData.DeliveryDate; if (rData.DeliveryDate != null) { trans.DeliveryStatus = "Delivered"; } trans.DeliveryTime = rData.DeliveryTime; trans.ReceivedBy = rData.ReceivedBy; trans.Remarks = trans.Remarks; db.Transactions.InsertOnSubmit(trans); db.SubmitChanges(); } else { notFound.Add(rData); } } catch { errorMessage += rData.ConsignmentNo + " "; } i++; int prog = (int)(progress + (i / count * 85)); bg.ReportProgress(prog); } e.Result = errorMessage; bg.ReportProgress(100); }
void bg_DoWork(object sender, DoWorkEventArgs e) { string fileName = (string)e.Argument; CSVDataLoader csvDL = new CSVDataLoader(); List <RuntimeData> data = csvDL.getRuntimeDataFromCSV(fileName, '"', '\''); double progress = 5; bg.ReportProgress((int)progress); double i = 0; double count = data.Count; BillingDataDataContext db = new BillingDataDataContext(); int sheetNo; string errorMessage = ""; try { sheetNo = db.RuntimeDatas.Max(x => x.SheetNo) + 1; } catch (Exception) { sheetNo = 0; } foreach (RuntimeData rData in data) { try { rData.SheetNo = sheetNo; rData.UserId = "System"; db.RuntimeDatas.InsertOnSubmit(rData); db.SubmitChanges(); } catch { errorMessage += rData.ConsignmentNo + " "; } i++; int prog = (int)(progress + (i / count * 85)); bg.ReportProgress(prog); } db.ImportFileData(sheetNo, "System", SecurityModule.currentUserName); e.Result = errorMessage; bg.ReportProgress(100); }