private void buttonDelete_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete " + section.SectionName + "? Student list, classes and attendance data of this section will be permanently deleted", "Confirmation", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { SectionController scontroller = new SectionController(); SectionTimeController stcontroller = new SectionTimeController(); SectionStudentController sscontroller = new SectionStudentController(); try { ClassController ccontroller = new ClassController(); List <ClassModel> classList = ccontroller.GetBySectionId(section.Id); AttendanceController acontroller = new AttendanceController(); foreach (ClassModel Class in classList) { acontroller.DeleteAllByClass(Class.Id); } ccontroller.DeleteAllBySection(section.Id); sscontroller.RemoveAllBySection(section.Id); stcontroller.RemoveAllBySection(section.Id); scontroller.Delete(section); MessageBox.Show("Deleted!"); buttonBack.PerformClick(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public FormYourSections(FacultyUserModel gotFaculty) { InitializeComponent(); faculty = gotFaculty; labelWelcome.Text = faculty.FullName; SectionController controller = new SectionController(); try { List <SectionModel> sectionList = controller.GetByFaculty(faculty); //Console.WriteLine("Sections: "); foreach (SectionModel model in sectionList) { //Console.WriteLine("Name: " + model.SectionName); Panel sectionPanel = new Panel(); sectionPanel.Width = 194; sectionPanel.Height = 102; sectionPanel.BorderStyle = BorderStyle.None; sectionPanel.Margin = new Padding(0, 3, 7, 5); sectionPanel.BackColor = Color.FromArgb(38, 143, 164); flowLayoutPanelSections.Controls.Add(sectionPanel); Label labelSectionName = new Label(); labelSectionName.Text = model.SectionName; labelSectionName.Font = new Font("Arial", 10, FontStyle.Regular); labelSectionName.ForeColor = Color.FromArgb(217, 217, 217); labelSectionName.Location = new Point(8, 8); labelSectionName.Size = new Size(186, 100); SectionTimeController timeController = new SectionTimeController(); List <SectionTimeModel> sectionTimes = timeController.GetBySection(model); sectionPanel.Controls.Add(labelSectionName); } }catch (Exception ex) { MessageBox.Show(ex.Message); } }
public YourSectionsForm(FacultyUserModel gotFaculty) { InitializeComponent(); faculty = gotFaculty; labelWelcome.Text = faculty.FullName; SectionController controller = new SectionController(); try { List <SectionModel> sectionList = controller.GetByFaculty(faculty); if (sectionList.Count == 0) { Label noSections = new Label(); noSections.Text = "You have no sections added. To add a section,"; noSections.Font = new Font("Arial", 12, FontStyle.Regular); noSections.TextAlign = ContentAlignment.MiddleCenter; noSections.ForeColor = Color.FromArgb(217, 217, 217); noSections.AutoSize = true; noSections.Margin = new Padding(3, 3, 0, 3); flowLayoutPanelSections.Controls.Add(noSections); Label clickHere = new Label(); clickHere.Text = "click here"; clickHere.Font = new Font("Arial", 12, FontStyle.Underline); clickHere.ForeColor = Color.FromArgb(217, 217, 217); clickHere.Margin = new Padding(0, 3, 3, 3); clickHere.Cursor = Cursors.Hand; clickHere.Click += new System.EventHandler(this.ClickHere_Click);; flowLayoutPanelSections.Controls.Add(clickHere); } int r = 28; int g = 124; int b = 143; int i = 1; foreach (SectionModel model in sectionList) { //Console.WriteLine("Name: " + model.SectionName); FlowLayoutPanel sectionPanel = new FlowLayoutPanel(); sectionPanel.Width = 188; sectionPanel.Height = 110; sectionPanel.BorderStyle = BorderStyle.None; sectionPanel.Margin = new Padding(0, 3, 7, 5); sectionPanel.BackColor = Color.FromArgb(r, g, b); sectionPanel.FlowDirection = FlowDirection.LeftToRight; sectionPanel.WrapContents = true; sectionPanel.AutoScroll = false; sectionPanel.VerticalScroll.Visible = false; sectionPanel.HorizontalScroll.Enabled = false; flowLayoutPanelSections.Controls.Add(sectionPanel); Label labelSectionName = new Label(); labelSectionName.Text = model.SectionName; labelSectionName.Font = new Font("Arial", 10, FontStyle.Regular); labelSectionName.ForeColor = Color.FromArgb(217, 217, 217); labelSectionName.AutoSize = false; labelSectionName.Size = new Size(sectionPanel.Width - 4, 32); labelSectionName.Margin = new Padding(5, 8, 0, 3); labelSectionName.UseMnemonic = false; sectionPanel.Controls.Add(labelSectionName); SectionTimeController timeController = new SectionTimeController(); List <SectionTimeModel> sectionTimes = timeController.GetBySection(model); foreach (SectionTimeModel timeModel in sectionTimes) { WeekDayController dayCon = new WeekDayController(); ClassTimeController classCon = new ClassTimeController(); Label sectionTimeText1 = new Label(); sectionTimeText1.Text = timeModel.ClassType + ": " + dayCon.Get(timeModel.WeekDayId).WeekDayText.Substring(0, 3) + " " + classCon.Get(timeModel.StartTimeId).ClassTimeText + " - " + classCon.Get(timeModel.EndTimeId).ClassTimeText + " [" + timeModel.RoomNo + "]"; if (sectionTimes.Count == 2) { sectionTimeText1.AutoSize = true; } else { sectionTimeText1.Size = new Size(sectionPanel.Width - 4, 32); } sectionTimeText1.Font = new Font("Arial", 8, FontStyle.Italic); sectionTimeText1.ForeColor = Color.FromArgb(217, 217, 217); if (timeModel == sectionTimes[0]) { sectionTimeText1.Margin = new Padding(4, 0, 0, 0); } else { sectionTimeText1.Margin = new Padding(4, 0, 0, 4); } sectionPanel.Controls.Add(sectionTimeText1); } Button studentsButton = new Button(); studentsButton.Text = "Students"; studentsButton.BackColor = Color.FromArgb(38, 143, 164); studentsButton.Cursor = Cursors.Hand; studentsButton.FlatAppearance.BorderSize = 0; studentsButton.FlatStyle = FlatStyle.Flat; studentsButton.Font = new Font("Arial", 10F); studentsButton.ForeColor = Color.FromArgb(((int)(((byte)(217)))), ((int)(((byte)(217)))), ((int)(((byte)(217))))); studentsButton.AutoSize = false; studentsButton.Size = new Size(75, 25); studentsButton.Margin = new Padding(12, 2, 6, 0); studentsButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; studentsButton.Dock = DockStyle.Bottom | DockStyle.Left; studentsButton.Click += delegate(object sender, EventArgs e) { studentsButton_Click(sender, e, model); }; sectionPanel.Controls.Add(studentsButton); Button editButton = new Button(); editButton.Text = "Edit"; editButton.BackColor = Color.FromArgb(38, 143, 164); editButton.Cursor = Cursors.Hand; editButton.FlatAppearance.BorderSize = 0; editButton.FlatStyle = FlatStyle.Flat; editButton.Font = new Font("Arial", 10F); editButton.ForeColor = Color.FromArgb(((int)(((byte)(217)))), ((int)(((byte)(217)))), ((int)(((byte)(217))))); editButton.AutoSize = false; editButton.Size = new Size(75, 25); editButton.Margin = new Padding(6, 2, 12, 0); editButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; editButton.Click += delegate(object sender, EventArgs e) { editButton_Click(sender, e, model, sectionTimes); }; sectionPanel.Controls.Add(editButton); if (i % 3 == 0) { r -= 5; g -= 5; b -= 5; } i++; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void ButtonSave_Click(object sender, EventArgs e) { SectionModel editedSection = section; editedSection.SectionName = textBoxSectionName.Text.Trim(); editedSection.FacultyId = faculty.Id; SectionTimeController stcontroller = new SectionTimeController(); List <SectionTimeModel> allSectionTimes = stcontroller.GetByFaculty(faculty.Id); try { editedSection.IsValid(); //Console.WriteLine("Section name: " + section.SectionName); //Console.WriteLine("Section facultyID: " + section.FacultyId); SectionTimeModel editedSectionTime1 = sectionTimes[0]; if (comboBoxClassType1.SelectedIndex == 0) { editedSectionTime1.ClassType = ClassTypes.Lab; } else if (comboBoxClassType1.SelectedIndex == 1) { editedSectionTime1.ClassType = ClassTypes.Theory; } editedSectionTime1.RoomNo = textBoxRoomNo1.Text; editedSectionTime1.StartTimeId = comboBoxStartTime1.SelectedIndex + 1; editedSectionTime1.EndTimeId = comboBoxEndTime1.SelectedIndex + 1; editedSectionTime1.WeekDayId = comboBoxWeekDay1.SelectedIndex + 1; //Console.WriteLine("Section Time 1 info:"); //Console.WriteLine("Start Id: " + editedSectionTime1.StartTimeId); //Console.WriteLine("End Id: " + editedSectionTime1.EndTimeId); //Console.WriteLine("Day Id: " + editedSectionTime1.WeekDayID); //Console.WriteLine("Room no: " + editedSectionTime1.RoomNo); //Console.WriteLine("Class type: " + editedSectionTime1.ClassType.ToString()); //Console.WriteLine("Class length: " + (editedSectionTime1.EndTimeId - editedSectionTime1.StartTimeId).ToString()); try { editedSectionTime1.IsValid(); foreach (SectionTimeModel model in allSectionTimes) { if (model.Id != editedSectionTime1.Id) { if (model.WeekDayId == editedSectionTime1.WeekDayId) { if (editedSectionTime1.StartTimeId < model.EndTimeId && editedSectionTime1.StartTimeId >= model.StartTimeId) { //Console.WriteLine("Clash with\nstart id: " + model.StartTimeId + "\nend id: " + model.EndTimeId); throw new Exception("Section 1 time clashes with another section. Please choose a different time"); } if (editedSectionTime1.EndTimeId <= model.EndTimeId && editedSectionTime1.EndTimeId > model.StartTimeId) { //Console.WriteLine("Clash with\nstart id: " + model.StartTimeId + "\nend id: " + model.EndTimeId); throw new Exception("Section 1 time clashes with another section. Please choose a different time"); } if (editedSectionTime1.StartTimeId < model.StartTimeId && editedSectionTime1.EndTimeId > model.EndTimeId) { //Console.WriteLine("Clash with\nstart id: " + model.StartTimeId + "\nend id: " + model.EndTimeId); throw new Exception("Section 1 time clashes with another section. Please choose a different time"); } } } } SectionTimeModel editedSectionTime2 = new SectionTimeModel(); if (!(sectionTimes.Count == 1)) { editedSectionTime2 = sectionTimes[1]; } if (comboBoxClassType2.SelectedIndex == 0) { editedSectionTime2.ClassType = ClassTypes.Lab; } else if (comboBoxClassType2.SelectedIndex == 1) { editedSectionTime2.ClassType = ClassTypes.Theory; } editedSectionTime2.RoomNo = textBoxRoomNo2.Text; editedSectionTime2.StartTimeId = comboBoxStartTime2.SelectedIndex + 1; editedSectionTime2.EndTimeId = comboBoxEndTime2.SelectedIndex + 1; editedSectionTime2.WeekDayId = comboBoxWeekDay2.SelectedIndex + 1; //Console.WriteLine("Section Time 2 info:"); //Console.WriteLine("Start Id: " + editedSectionTime2.StartTimeId); //Console.WriteLine("End Id: " + editedSectionTime2.EndTimeId); //Console.WriteLine("Day Id: " + editedSectionTime2.WeekDayID); //Console.WriteLine("Room no: " + editedSectionTime2.RoomNo); //Console.WriteLine("Class type: " + editedSectionTime2.ClassType.ToString()); //Console.WriteLine("Class length: " + (editedSectionTime2.EndTimeId - editedSectionTime2.StartTimeId).ToString()); SectionModel editedSectionRetured = new SectionModel(); try { if (!checkBoxIgnore.Checked) { editedSectionTime2.IsValid(); foreach (SectionTimeModel model in allSectionTimes) { if (model.Id != editedSectionTime2.Id) { if (model.WeekDayId == editedSectionTime2.WeekDayId) { if (editedSectionTime2.StartTimeId < model.EndTimeId && editedSectionTime2.StartTimeId >= model.StartTimeId) { throw new Exception("Section 2 time clashes with another section. Please choose a different time"); } if (editedSectionTime2.EndTimeId <= model.EndTimeId && editedSectionTime2.EndTimeId > model.StartTimeId) { throw new Exception("Section 2 time clashes with another section. Please choose a different time"); } if (editedSectionTime2.StartTimeId < model.StartTimeId && editedSectionTime2.EndTimeId > model.EndTimeId) { //Console.WriteLine("Clash with\nstart id: " + model.StartTimeId + "\nend id: " + model.EndTimeId); throw new Exception("Section 2 time clashes with another section. Please choose a different time"); } } } } } SectionController controller = new SectionController(); try { //Console.WriteLine("Updating with name and id: " + editedSection.SectionName + " " + editedSection.Id); editedSectionRetured = controller.Update(section); //Console.WriteLine("Edited section id: " + editedSection.Id); editedSectionTime1.SectionId = editedSectionRetured.Id; if (!checkBoxIgnore.Checked) { editedSectionTime2.SectionId = editedSectionRetured.Id; } SectionTimeController controller2 = new SectionTimeController(); try { controller2.Update(editedSectionTime1); if (!checkBoxIgnore.Checked) { controller2.Update(editedSectionTime2); } MessageBox.Show(editedSectionRetured.SectionName + " edited!"); buttonBack.PerformClick(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void ButtonCreate_Click(object sender, EventArgs e) { SectionModel section = new SectionModel(); section.SectionName = textBoxSectionName.Text; section.FacultyId = faculty.Id; try { section.IsValid(); Console.WriteLine("Section name: " + section.SectionName); Console.WriteLine("Section facultyID: " + section.FacultyId); SectionTimeModel sectionTime1 = new SectionTimeModel(); if (comboBoxClassType1.SelectedIndex == 0) { sectionTime1.ClassType = ClassTypes.Lab; } else if (comboBoxClassType1.SelectedIndex == 1) { sectionTime1.ClassType = ClassTypes.Theory; } sectionTime1.RoomNo = textBoxRoomNo1.Text; sectionTime1.StartTimeId = comboBoxStartTime1.SelectedIndex + 1; sectionTime1.EndTimeId = comboBoxEndTime1.SelectedIndex + 1; sectionTime1.WeekDayID = comboBoxWeekDay1.SelectedIndex + 1; Console.WriteLine("Section Time 1 info:"); Console.WriteLine("Start Id: " + sectionTime1.StartTimeId); Console.WriteLine("End Id: " + sectionTime1.EndTimeId); Console.WriteLine("Day Id: " + sectionTime1.WeekDayID); Console.WriteLine("Room no: " + sectionTime1.RoomNo); Console.WriteLine("Class type: " + sectionTime1.ClassType.ToString()); Console.WriteLine("Class length: " + (sectionTime1.EndTimeId - sectionTime1.StartTimeId).ToString()); try { sectionTime1.IsValid(); SectionTimeModel sectionTime2 = new SectionTimeModel(); if (comboBoxClassType2.SelectedIndex == 0) { sectionTime2.ClassType = ClassTypes.Lab; } else if (comboBoxClassType2.SelectedIndex == 1) { sectionTime2.ClassType = ClassTypes.Theory; } sectionTime2.RoomNo = textBoxRoomNo2.Text; sectionTime2.StartTimeId = comboBoxStartTime2.SelectedIndex + 1; sectionTime2.EndTimeId = comboBoxEndTime2.SelectedIndex + 1; sectionTime2.WeekDayID = comboBoxWeekDay2.SelectedIndex + 1; Console.WriteLine("Section Time 2 info:"); Console.WriteLine("Start Id: " + sectionTime2.StartTimeId); Console.WriteLine("End Id: " + sectionTime2.EndTimeId); Console.WriteLine("Day Id: " + sectionTime2.WeekDayID); Console.WriteLine("Room no: " + sectionTime2.RoomNo); Console.WriteLine("Class type: " + sectionTime2.ClassType.ToString()); Console.WriteLine("Class length: " + (sectionTime2.EndTimeId - sectionTime2.StartTimeId).ToString()); SectionModel createdSection = new SectionModel(); try { sectionTime2.IsValid(); SectionController controller = new SectionController(); try { createdSection = controller.Create(section); Console.WriteLine("Created section id: " + createdSection.Id); sectionTime1.SectionId = createdSection.Id; sectionTime2.SectionId = createdSection.Id; SectionTimeController controller2 = new SectionTimeController(); try { controller2.Create(sectionTime1); controller2.Create(sectionTime2); MessageBox.Show(createdSection.SectionName + " created!"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void ButtonCreate_Click(object sender, EventArgs e) { SectionModel section = new SectionModel(); section.SectionName = textBoxSectionName.Text.Trim(); section.FacultyId = faculty.Id; SectionTimeController stcontroller = new SectionTimeController(); List <SectionTimeModel> sectionTimes = stcontroller.GetByFaculty(faculty.Id); try { section.IsValid(); //Console.WriteLine("Section name: " + section.SectionName); //Console.WriteLine("Section facultyID: " + section.FacultyId); SectionTimeModel sectionTime1 = new SectionTimeModel(); if (comboBoxClassType1.SelectedIndex == 0) { sectionTime1.ClassType = ClassTypes.Lab; } else if (comboBoxClassType1.SelectedIndex == 1) { sectionTime1.ClassType = ClassTypes.Theory; } sectionTime1.RoomNo = textBoxRoomNo1.Text; sectionTime1.StartTimeId = comboBoxStartTime1.SelectedIndex + 1; sectionTime1.EndTimeId = comboBoxEndTime1.SelectedIndex + 1; sectionTime1.WeekDayId = comboBoxWeekDay1.SelectedIndex + 1; //Console.WriteLine("Section Time 1 info:"); //Console.WriteLine("Start Id: " + sectionTime1.StartTimeId); //Console.WriteLine("End Id: " + sectionTime1.EndTimeId); //Console.WriteLine("Day Id: " + sectionTime1.WeekDayID); //Console.WriteLine("Room no: " + sectionTime1.RoomNo); //Console.WriteLine("Class type: " + sectionTime1.ClassType.ToString()); //Console.WriteLine("Class length: " + (sectionTime1.EndTimeId - sectionTime1.StartTimeId).ToString()); try { sectionTime1.IsValid(); foreach (SectionTimeModel model in sectionTimes) { if (model.WeekDayId == sectionTime1.WeekDayId) { if (sectionTime1.StartTimeId < model.EndTimeId && sectionTime1.StartTimeId >= model.StartTimeId) { //Console.WriteLine("Clash 1 with\nstart id: " + model.StartTimeId + "\nend id: " + model.EndTimeId); throw new Exception("Section 1 time clashes with another section. Please choose a different time"); } if (sectionTime1.EndTimeId <= model.EndTimeId && sectionTime1.EndTimeId > model.StartTimeId) { //Console.WriteLine("Clash 2 with\nstart id: " + model.StartTimeId + "\nend id: " + model.EndTimeId); throw new Exception("Section 1 time clashes with another section. Please choose a different time"); } if (sectionTime1.StartTimeId < model.StartTimeId && sectionTime1.EndTimeId > model.EndTimeId) { //Console.WriteLine("Clash 3 with\nstart id: " + model.StartTimeId + "\nend id: " + model.EndTimeId); throw new Exception("Section 1 time clashes with another section. Please choose a different time"); } } } SectionTimeModel sectionTime2 = new SectionTimeModel(); if (!checkBoxIgnore.Checked) { if (comboBoxClassType2.SelectedIndex == 0) { sectionTime2.ClassType = ClassTypes.Lab; } else if (comboBoxClassType2.SelectedIndex == 1) { sectionTime2.ClassType = ClassTypes.Theory; } sectionTime2.RoomNo = textBoxRoomNo2.Text; sectionTime2.StartTimeId = comboBoxStartTime2.SelectedIndex + 1; sectionTime2.EndTimeId = comboBoxEndTime2.SelectedIndex + 1; sectionTime2.WeekDayId = comboBoxWeekDay2.SelectedIndex + 1; //Console.WriteLine("Section Time 2 info:"); //Console.WriteLine("Start Id: " + sectionTime2.StartTimeId); //Console.WriteLine("End Id: " + sectionTime2.EndTimeId); //Console.WriteLine("Day Id: " + sectionTime2.WeekDayID); //Console.WriteLine("Room no: " + sectionTime2.RoomNo); //Console.WriteLine("Class type: " + sectionTime2.ClassType.ToString()); //Console.WriteLine("Class length: " + (sectionTime2.EndTimeId - sectionTime2.StartTimeId).ToString()); } SectionModel createdSection = new SectionModel(); try { if (!checkBoxIgnore.Checked) { sectionTime2.IsValid(); foreach (SectionTimeModel model in sectionTimes) { if (model.WeekDayId == sectionTime2.WeekDayId) { if (sectionTime2.StartTimeId < model.EndTimeId && sectionTime2.StartTimeId >= model.StartTimeId) { throw new Exception("Section 2 time clashes with another section. Please choose a different time"); } if (sectionTime2.EndTimeId <= model.EndTimeId && sectionTime2.EndTimeId > model.StartTimeId) { throw new Exception("Section 2 time clashes with another section. Please choose a different time"); } if (sectionTime2.StartTimeId < model.StartTimeId && sectionTime2.EndTimeId > model.EndTimeId) { //Console.WriteLine("Clash 3 with\nstart id: " + model.StartTimeId + "\nend id: " + model.EndTimeId); throw new Exception("Section 2 time clashes with another section. Please choose a different time"); } } } } SectionController controller = new SectionController(); try { createdSection = controller.Create(section); //Console.WriteLine("Created section id: " + createdSection.Id); sectionTime1.SectionId = createdSection.Id; if (!checkBoxIgnore.Checked) { sectionTime2.SectionId = createdSection.Id; } SectionTimeController controller2 = new SectionTimeController(); try { controller2.Create(sectionTime1); if (!checkBoxIgnore.Checked) { controller2.Create(sectionTime2); } MessageBox.Show(createdSection.SectionName + " created!"); LoadingForm loadingForm = new LoadingForm(); if (studentList.Count != 0) { UserController ucontroller = new UserController(); //loading screen loadingForm.Show(); //Console.WriteLine("Starting loop"); foreach (StudentUserModel student in studentList) { try { var createdStudent = ucontroller.Create(student); try { SectionStudentController sscontroller = new SectionStudentController(); sscontroller.Create(createdSection.Id, student.Id); } catch (SQLiteException exc) { if (exc.ErrorCode == 19) { MessageBox.Show("Error: Student already exists in this section"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } catch (SQLiteException ex) { var existingStudent = ucontroller.GetByAcademicId(student.AcademicId); try { SectionStudentController sscontroller = new SectionStudentController(); sscontroller.Create(createdSection.Id, existingStudent.Id); } catch (SQLiteException exc) { if (exc.ErrorCode == 19) { MessageBox.Show("Error: Student already exists in this section"); } } catch (Exception exc) { MessageBox.Show(exc.Message); } } loadingForm.Step(1); } //Console.WriteLine("Ending loop"); } loadingForm.Close(); buttonBack.PerformClick(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }