private void delete_day_Click(object sender, RoutedEventArgs e) { Scheduling3ViewModel scheduling3ViewModel = Periods2.SelectedItem as Scheduling3ViewModel; SecondDataGramData.Remove(scheduling3ViewModel); List <Watch> wachList = new List <Watch>(); wachList = db.Watches.Where(x => x.ExamId == ExamInit.examID).ToList <Watch>(); foreach (Watch w in wachList) { if (w.WatchDate == scheduling3ViewModel.day && w.PeriodId == scheduling3ViewModel.periodID && w.StartTime == scheduling3ViewModel.startTime && w.Duration == scheduling3ViewModel.PD) { db.Watches.Remove(w); db.SaveChanges(); } } foreach (Scheduling3ViewModel scheduling3ViewModel1 in BaseList.ToList()) { if (scheduling3ViewModel.day == scheduling3ViewModel1.day && scheduling3ViewModel.periodID == scheduling3ViewModel1.periodID && scheduling3ViewModel.PD == scheduling3ViewModel1.PD && scheduling3ViewModel.startTime == scheduling3ViewModel1.startTime) { BaseList.Remove(scheduling3ViewModel); MessageBox.Show(BaseList.Count().ToString()); } } }
private void Button_Click(object sender, RoutedEventArgs e) { foreach (fillFirstDataGridmodel fm in FirstDataGramData) { exist = false; for (short i = 1; i <= fm.SelectedNum; i++) { exist = false; Scheduling3ViewModel SV = new Scheduling3ViewModel(); foreach (Scheduling3ViewModel second in SecondDataGramData) { if (second.day == fm.dayDate && second.periodID == i) { exist = true; } } if (exist == false) { SV.day = fm.dayDate; SV.periodID = i; MessageBox.Show(fm.SelectedNum.ToString()); SV.startTime = TimeSpan.Parse(DefaultStartTime.Text); SV.PD = decimal.Parse(DefaultDuration.Text); SV.periodDuration = periodDurationList; SecondDataGramData.Add(SV); BaseList.Add(SV); } else { MessageBox.Show(" التاريخ " + fm.dayDate.ToString("dd/MM/yyyy") + " و الفترة " + i + "تمت اضافتهم مسبقاَ"); } } } }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { SecondDataGramData.Clear(); List <Watch> wachList = new List <Watch>(); wachList = db.Watches.Where(x => x.ExamId == ExamInit.examID).ToList <Watch>(); MessageBox.Show(wachList.Count().ToString()); foreach (Watch w in wachList) { Scheduling3ViewModel model = new Scheduling3ViewModel(); model.day = (DateTime)w.WatchDate; model.periodID = (short)w.PeriodId; model.startTime = (TimeSpan)w.StartTime; model.periodDuration = periodDurationList; model.PD = (decimal)w.Duration; SecondDataGramData.Add(model); } }