private void SaveChanges() { if (IsNew && Valid() && !HasErrors) { App.Model.course.Add(Course); DateTime Occurence = StartDate; while ((int)Occurence.DayOfWeek != DaysOfWeek + 1) { Occurence = Occurence.AddDays(+1); } do { CourseOccurrence c = new CourseOccurrence(Occurence, Course); App.Model.courseoccurrence.Add(c); Occurence = Occurence.AddDays(+7); } while (Occurence.CompareTo(FinishDate) <= 0); IsNew = false; } else if (!IsNew && Valid() && !HasErrors) { Occurences(); } if (Stud.Count() < Course.Student.Count()) { foreach (var m in Course.Student) { var presences = App.Model.presence.Where(p => p.Student == m.Id && p.CourseOccurrence.Course.Code == Course.Code).Include("CourseOccurrence.Presence").Include("Students"); App.Model.presence.RemoveRange(presences); } Course.Student.Clear(); } while (Stud.Count != 0) { Course.Student.Add(Stud.First()); Stud.Remove(Stud.First()); } App.Model.SaveChanges(); App.Messenger.NotifyColleagues(App.MSG_COURSE_CHANGED, Course); CoursesOccurrence.RefreshFromModel(App.Model.courseoccurrence.Where(c => c.Course.Code == Course.Code)); HistoriquePrésences(); Stud = new ObservableCollection <Student>(Course.Student); }
private void HistoriquePrésences() { var table = new DataTable(); var columns = new Dictionary <int, CourseOccurrence>(); table = new DataTable(); table.Columns.Add("Etudiant"); int i = 1; foreach (CourseOccurrence p in CoursesOccurrence) { table.Columns.Add(p.Date.ToShortDateString()); columns[i] = p; ++i; } foreach (Student s in Students) { var row = table.NewRow(); row[0] = s.LastName + ", " + s.FirstName; for (int j = 1; j < table.Columns.Count; ++j) { CourseOccurrence idL = columns[j]; var idp = from p in s.Presence where s.Id == p.Student && p.Present == 1 select p.CourseOccurrence; var ida = from a in s.Presence where s.Id == a.Student && a.Present == 0 select a.CourseOccurrence; string txt = ""; if (idp.Contains(idL)) { txt = "P"; } else if (ida.Contains(idL)) { txt = "A"; } else { txt = "?"; } row[j] = txt; } table.Rows.Add(row); } Presence = table.DefaultView; }
public EncodageView(CourseOccurrence courseoccurence) { DataContext = this; CourseOccurence = courseoccurence; Courses = new ObservableCollection <Course>(App.CurrentUser.Course); Students = new ObservableCollection <Student>(CourseOccurence.Course.Student); Presence = new ObservableCollection <Presence>(App.Model.presence); Users = new ObservableCollection <User>(App.Model.user); CoursesOccurrence = new ObservableCollection <CourseOccurrence>(App.Model.courseoccurrence); Pres = new ObservableCollection <Presence>(CourseOccurence.Presence); Presences = new ObservableCollection <Presence>(Pres); App.Messenger.Register <Course>(App.MSG_SAVE, Course => { App.Model.SaveChanges(); App.Messenger.NotifyColleagues(App.MSG_COURSE_CHANGED, Course); }); App.Messenger.Register <Course>(App.MSG_CANCEL, Course => { CancelChanges(); }); InitializeComponent(); }
public void Occurences() { if (!IsNew && Course.CourseOccurrence.First().Date.CompareTo(StartDate) != 0 || Course.CourseOccurrence.Last().Date.CompareTo(FinishDate) != 0) { var occ = App.Model.courseoccurrence.Where(p => p.Course.Code == Course.Code).Include("Presence").Include("Course.CourseOccurrence"); App.Model.courseoccurrence.RemoveRange(occ); var presence = App.Model.presence.Where(p => p.CourseOccurrence.Course.Code == Course.Code).Include("CourseOccurrence.Presence").Include("Students"); App.Model.presence.RemoveRange(presence); DateTime Occurence = StartDate; while ((int)Occurence.DayOfWeek != DaysOfWeek + 1) { Occurence = Occurence.AddDays(+1); } do { CourseOccurrence c = new CourseOccurrence(Occurence, Course); App.Model.courseoccurrence.Add(c); Occurence = Occurence.AddDays(+7); } while (Occurence.CompareTo(FinishDate) <= 0); } }