private void Bg_DoWork(object sender, DoWorkEventArgs e) { int i = 0; foreach (var item in listRes) { foreach (var item2 in listSchedules) { item2.Restaurant_Id_Fk = item.Restaurant; item2.Res_Cont_Contract_Id_Fk = item.Contract; db.Schedules.Add(item2); db.SaveChanges(); Bg.ReportProgress(i); i = i + 1; } lblDarsad.Invoke(new Action(() => { lblDarsad.Text = "%" + (i * 100 / countTotal).ToString(); })); } }
private void Bg_DoWork(object sender, DoWorkEventArgs e) { int i = 0; bool nimeshab = list.Any(p => p.schedule.Meal_Id_Fk == 3); foreach (var item in list) { db.Trays.Add(item.tray); db.SaveChanges(); item.schedule.Tray_Id_Fk = Convert.ToInt16(item.tray.Id); db.Schedules.Add(item.schedule); foreach (var itemm in item.trayItem) { itemm.Tray_Id_Fk = Convert.ToInt16(item.tray.Id); db.TrayItems.Add(itemm); } if (nimeshab) { Schedule nimeshab2 = new Schedule() { SDate = item.schedule.SDate, Restaurant_Id_Fk = 27, Tray_Id_Fk = item.schedule.Tray_Id_Fk, RegDate = item.schedule.RegDate, Meal_Id_Fk = 3, Res_Cont_Contract_Id_Fk = 2022, PorsNo = 0 }; db.Schedules.Add(nimeshab2); } db.SaveChanges(); i = i + 1; lblDarsad.Invoke(new Action(() => { lblDarsad.Text = "%" + (i * 100 / list.Count()).ToString(); })); Bg.ReportProgress(i); System.Threading.Thread.Sleep(100); } }