private void button1_Click(object sender, EventArgs e) { int type; if (radioButton1.Checked) type = 0; else if (radioButton2.Checked) type = 1; else type = 2; Lesson les = new Lesson(); try { les.Type = type; les.Number = listBox6.SelectedIndex; les.DayOfWeek = listBox9.SelectedIndex; les.Subject = (listBox5.SelectedItem as Subject); les.AddGroups(listBox3.SelectedItems.Cast<Group>().ToList()); les.AddTeachers(listBox4.SelectedItems.Cast<Teacher>().ToList()); les.AddClassrooms(listBox11.Items.Cast<Classroom>().ToList()); Program.schedule.AddLesson(les); } catch (Exception ex) { MessageBox.Show(ex.Message); } UpDate(); }
public int CountOfHours(Lesson L, Group G) { int count = 0; foreach (Lesson l in this.Lessons.Where(les => les.Semester == L.Semester).Where(les => les.Subject == L.Subject).Where(les => les.Groups.IndexOf(G) > -1).ToList()) { if (l.Type == 0) count += 2; else count++; } return count; }
public void AddLesson(Lesson L) { L.Semester = Semester; if (!L.IsNormal()) { L.RollBack(); throw new Exception("Дані не реальні"); } if (!Check(L)) { L.RollBack(); throw new Exception("Перевищення годин в навантаженні"); } if (L.Message() != "") if (MessageBox.Show(L.Message(), "Додати?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { L.RollBack(); return; } Lessons.Add(L); }
public void AddLesson(Lesson L) { LessonButton btn = new LessonButton(); panel1.Controls.Add(btn); btn.Lesson = L; }
public void Union(Lesson L) { AddGroups(L.Groups); AddClassrooms(L.Classrooms); AddTeachers(L.Teachers); foreach (Group g in groups) g.Lessons.Remove(L); foreach (Teacher t in teachers) t.Lessons.Remove(L); foreach (Classroom c in classrooms) c.Lessons.Remove(L); message = ""; }
public bool Conflict(Lesson L) { if ((this.day == L.day) && (this.number == L.number) && (this.semester == L.semester)) return true; else return false; }
public bool Compare(Lesson L) { if ((this.day == L.day) && (this.number == L.number) && (this.subject == L.subject) && (this.semester == L.semester)) return true; else return false; }
private bool Check(Lesson L) { foreach (Teacher t in L.Teachers) { foreach (Group g in L.Groups) if (t.CountOfHours(L, g) > LoadHours(t,g)) return false; } return true; }
private Lesson LessonFromAtom(AtomLesson atom) { Lesson l = new Lesson(); l.Day = atom.Day; l.Type = atom.Type; l.Number = atom.Number; l.Semester = atom.Semester; l.AddGroup(Program.Groups.Where(g => g.ID == atom.GroupID).ToList().First()); l.AddTeacher(Program.Teachers.Where(t => t.ID == atom.TeacherID).ToList().First()); l.AddClassroom(Program.Classrooms.Where(c => c.ID == atom.ClassroomID).ToList().First()); l.Subject = (Program.Subjects.Where(s => s.ID == atom.SubjectID)).ToList<Subject>().First(); return l; }
public void RemoveLessons(Lesson L) { Lessons.Remove(L); foreach (Group g in L.Groups) g.Lessons.Remove(L); foreach (Classroom c in L.Classrooms) c.Lessons.Remove(L); foreach (Teacher t in L.Teachers) t.Lessons.Remove(L); lessonBind.Remove(L); }
List<Lesson> MakeReplacement() { if (AtomReplacements.Count() == 0) return new List<Lesson>(); List<Lesson> lessons = new List<Lesson>(); List<Boolean> flags = new List<bool>(); List<Lesson> outlist = new List<Lesson>(); foreach (AtomLesson a in AtomReplacements) { Lesson l = new Lesson(); l.Type = a.Type; l.Number = a.Number; l.Groups = Program.Groups.Where(g => g.ID == a.GroupID).ToList<Group>(); l.Teachers = Program.Teachers.Where(t => t.ID == a.TeacherID).ToList<Teacher>(); l.Classrooms = Program.Classrooms.Where(c => c.ID == a.ClassroomID).ToList<Classroom>(); var su = Program.Subjects.Where(s => s.ID == a.SubjectID).ToList<Subject>(); l.Subject = su[0]; l.Day = a.Day; l.Semester = a.Semester; var query = schedule. Where(s => s.Groups.IndexOf(l.Groups[0]) != -1). Where(s => s.Day == l.Day). Where(s => s.Type == l.Type). Where(s => s.Number == l.Number). ToList<Lesson>(); haveReplacement.AddRange(query); lessons.Add(l); flags.Add(true); } List<Lesson> less = new List<Lesson>(); for (int i = 0; i < lessons.Count(); i++) { if (!flags[i]) continue; for (int j = 0; j < lessons.Count(); j++) if ((lessons[i] != lessons[j]) && lessons[i].Compare(lessons[j]) && ( (lessons[i].Teachers[0] == lessons[j].Teachers[0]) || (lessons[i].Groups[0] == lessons[j].Groups[0]))) { if (lessons[i].Groups[0] != lessons[j].Groups[0]) { var tmp = lessons[i].Groups; tmp.Add(lessons[j].Groups[0]); lessons[i].Groups = tmp; } if (lessons[i].Teachers[0] != lessons[j].Teachers[0]) { var tmp = lessons[i].Teachers; tmp.Add(lessons[j].Teachers[0]); lessons[i].Teachers = tmp; var tmp2 = lessons[i].Classrooms; tmp2.Add(lessons[j].Classrooms[0]); lessons[i].Classrooms = tmp2; } flags[j] = false; } less.Add(lessons[i]); } return less; }
public void RemoveReplacemant(Lesson L) { replacements.Remove(L); EntitySet<Lesson> query = new EntitySet<Lesson>(); foreach (Group g in L.Groups) query.AddRange( haveReplacement. Where(r => r.Day == L.Day). Where(r => r.Number == L.Number). Where(r => r.Groups.Contains(g)) ); foreach (Lesson l in query) haveReplacement.Remove(l); RefreshFact(); }
public bool IsReplacement(Lesson L) { return schedule.IndexOf(L) == -1; }
public bool AddReplacemant(List<Group> G, List<Teacher> T, List<Classroom> C, Subject S) { if (selectedLesson == null) { throw new Exception("Немає заняття, що замінюється"); } haveReplacement.Add(selectedLesson); Lesson les = new Lesson{ Day = this.day, Number = this.selectedLesson.Number, Type = this.selectedLesson.Type}; les.Subject = S; message = ""; RefreshFact(); foreach (Group g in G) { var query = fact. Where(l => l.Groups.IndexOf(g) != -1). Where(l => l.Number == les.Number); if (query.Count() > 0) message += g.Title + " "; } foreach (Teacher t in T) { var query = fact. Where(l => l.Teachers.IndexOf(t) != -1). Where(l => l.Number == les.Number); if (query.Count() > 0) message += t.FullName() + " "; } foreach (Classroom c in C) { var query = fact. Where(l => l.Classrooms.IndexOf(c) != -1). Where(l => l.Number == les.Number); if (query.Count() > 0) message += c.Title + " "; } if (message != "") { message = "Зайняті: " + message; return false; } les.Groups = G; les.Teachers = T; les.Classrooms = C; if (!les.IsNormal()) { message = "Помилка"; return false; } replacements.Add(les); currentReplacements.Add(les); return true; }