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); } } }
private void ButtonAdd_Click(object sender, EventArgs e) { StudentUserModel student = new StudentUserModel(); student.FirstName = textBoxStudentFirstName.Text.Trim(); student.LastName = textBoxStudentLastName.Text.Trim(); student.AcademicId = textBoxStudentId.Text; try { student.IsValid(); UserController controller = new UserController(); try { BaseUserModel createdStudent = controller.Create(student); SectionStudentController controller1 = new SectionStudentController(); controller1.Create(section.Id, createdStudent.Id); ClassController ccontroller = new ClassController(); List <ClassModel> classList = ccontroller.GetBySectionId(section.Id); AttendanceController acontroller = new AttendanceController(); foreach (ClassModel Class in classList) { AttendanceModel attendance = new AttendanceModel(); attendance.StudentId = createdStudent.Id; attendance.ClassId = Class.Id; try { acontroller.Create(attendance); } catch (Exception ex) { MessageBox.Show(ex.Message); } } MessageBox.Show(student.FullName + " added in " + section.SectionName); var students = new FormStudentList(faculty, section); students.FormClosed += new FormClosedEventHandler(dash_FormClosed); students.Show(); this.Hide(); } catch (NullReferenceException ex) { MessageBox.Show(ex.Message); } } catch (SQLiteException ex) { try { UserController controller = new UserController(); var gotStudent = controller.GetByAcademicId(student.AcademicId); string message = "Student already exists in our database. Are you sure you want to add " + gotStudent.FullName + "(" + gotStudent.AcademicId + ")?"; DialogResult dialogResult = MessageBox.Show(message, "Confirm", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { try { SectionStudentController controller1 = new SectionStudentController(); controller1.Create(section.Id, gotStudent.Id); MessageBox.Show(gotStudent.FullName + " added in " + section.SectionName); var students = new FormStudentList(faculty, section); students.FormClosed += new FormClosedEventHandler(dash_FormClosed); students.Show(); this.Hide(); } catch (SQLiteException exc) { if (exc.ErrorCode == 19) { MessageBox.Show("Error: Student already exists in this section"); } } catch (Exception exv) { MessageBox.Show(exv.Message); } } else if (dialogResult == DialogResult.No) { this.Hide(); } } catch (Exception exc) { MessageBox.Show(exc.Message); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public FormStudentList(FacultyUserModel gotFaculty, SectionModel gotSection) { InitializeComponent(); faculty = gotFaculty; section = gotSection; labelWelcome.Text = faculty.FullName; labelStudents.Text = "Students of " + section.SectionName; //try //{ UserController controller = new UserController(); studentList = controller.GetBySection(section); ClassController ccontroller = new ClassController(); classList = ccontroller.GetBySectionId(section.Id); AttendanceController acontroller = new AttendanceController(); attendanceList = acontroller.GetAllBySection(section.Id); Console.WriteLine("Found student: " + studentList.Count); Console.WriteLine("Found classes: " + classList.Count); Console.WriteLine("Found attendances: " + attendanceList.Count); List <StudentView> mainList = new List <StudentView>(); int i = 0; foreach (StudentUserModel student in studentList) { Console.WriteLine("doing student no. " + i); StudentView view = new StudentView(); view.AcademicId = student.AcademicId; view.FullName = student.FullName; int c = 0; foreach (ClassModel Class in classList) { AttendanceModel att = attendanceList.Find(x => (x.ClassId == Class.Id) && (x.StudentId == student.Id)); Console.WriteLine("Found attendance id: " + att.Id + " for: " + student.Id + " on: " + Class.Id + " entry: " + att.Entry); view.attendances.Add(att.Entry); DataGridViewColumn col = new DataGridViewTextBoxColumn(); col.HeaderText = Class.ClassDate; int colIndex = dataGridViewStudentList.Columns.Add(col); //dataGridViewStudentList.Rows[i].Cells[c+2].Value = att.Entry.ToString(); c++; } mainList.Add(view); i++; } Console.WriteLine("Main list count: " + mainList.Count); MySortableBindingList <StudentView> mainListBinding = new MySortableBindingList <StudentView>(mainList); dataGridViewStudentList.AutoGenerateColumns = false; dataGridViewStudentList.DataSource = mainListBinding; dataGridViewSerial.AutoGenerateColumns = false; dataGridViewSerial.DataSource = mainListBinding; dataGridViewSerial.Columns[0].DefaultCellStyle.Padding = new Padding(3, 0, 0, 0); dataGridViewStudentList.DataBindingComplete += (o, e) => { foreach (DataGridViewRow row in dataGridViewSerial.Rows) { row.Cells["sln"].Value = (row.Index + 1).ToString(); } foreach (DataGridViewColumn column in dataGridViewStudentList.Columns) { column.SortMode = DataGridViewColumnSortMode.Programmatic; } }; foreach (DataGridViewColumn column in dataGridViewStudentList.Columns) { column.SortMode = DataGridViewColumnSortMode.Automatic; } //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message); //} }
public FormStudentList(FacultyUserModel gotFaculty, SectionModel gotSection) { InitializeComponent(); faculty = gotFaculty; section = gotSection; labelWelcome.Text = faculty.FullName; labelStudents.Text = "Students of " + section.SectionName; try { UserController controller = new UserController(); studentList = controller.GetBySection(section); ClassController ccontroller = new ClassController(); classList = ccontroller.GetBySectionId(section.Id); AttendanceController acontroller = new AttendanceController(); attendanceList = acontroller.GetAllBySection(section.Id); //Console.WriteLine("Found student: " + studentList.Count); //Console.WriteLine("Found classes: " + classList.Count); //Console.WriteLine("Found attendances: " + attendanceList.Count); DataGridViewColumn sln = new DataGridViewTextBoxColumn(); sln.HeaderText = "#"; sln.Width = 30; sln.ReadOnly = true; dataGridViewSln.Columns.Add(sln); DataGridViewColumn IdCol = new DataGridViewTextBoxColumn(); IdCol.HeaderText = "ID"; IdCol.Width = 75; IdCol.ReadOnly = true; dataGridViewStudentList.Columns.Add(IdCol); DataGridViewColumn FullNameCol = new DataGridViewTextBoxColumn(); FullNameCol.HeaderText = "Name"; FullNameCol.Width = 200; FullNameCol.ReadOnly = true; dataGridViewStudentList.Columns.Add(FullNameCol); foreach (ClassModel Class in classList) { DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn(); DateTime date = DateTime.Parse(Class.ClassDate); string dateMod = date.ToString("MMM-dd"); col.HeaderText = dateMod; col.ReadOnly = false; col.Width = 50; col.MaxInputLength = 1; col.ValueType = typeof(string); col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; dataGridViewStudentList.Columns.Add(col); } int i = 0; foreach (StudentUserModel student in studentList) { //Console.WriteLine("doing student no. " + i); StudentView view = new StudentView(); view.AcademicId = student.AcademicId; view.FullName = student.FullName; dataGridViewStudentList.Rows.Add(); dataGridViewSln.Rows.Add(); dataGridViewSln.Rows[i].Cells[0].Value = i + 1; dataGridViewStudentList.Rows[i].Cells[0].Value = student.AcademicId; dataGridViewStudentList.Rows[i].Cells[1].Value = student.FullName; int c = 0; foreach (ClassModel Class in classList) { AttendanceModel att = attendanceList.Find(x => (x.ClassId == Class.Id) && (x.StudentId == student.Id)); //Console.WriteLine("Found attendance id: " + att.Id + " for: " + student.Id + " on: " + Class.Id + " entry: " + att.Entry); if (att.Entry == 2) { dataGridViewStudentList.Rows[i].Cells[c + 2].Value = "L"; } else { dataGridViewStudentList.Rows[i].Cells[c + 2].Value = att.Entry.ToString(); } c++; } i++; } MySortableBindingList <StudentUserModel> studentListSortable = new MySortableBindingList <StudentUserModel>(studentList); dataGridViewStudentList.DataBindingComplete += (o, e) => { foreach (DataGridViewColumn column in dataGridViewStudentList.Columns) { column.SortMode = DataGridViewColumnSortMode.Programmatic; } }; foreach (DataGridViewColumn column in dataGridViewStudentList.Columns) { column.SortMode = DataGridViewColumnSortMode.Automatic; } } catch (Exception ex) { MessageBox.Show(ex.Message); } if (classList.Count != 0) { DataGridViewTextBoxColumn totalCol = new DataGridViewTextBoxColumn(); totalCol.HeaderText = "Total"; totalCol.Width = 38; totalCol.ReadOnly = true; totalCol.Name = "Total"; totalCol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; dataGridViewStudentList.Columns.Add(totalCol); foreach (DataGridViewRow row in dataGridViewStudentList.Rows) { int sum = 0; int classNo = 0; foreach (ClassModel Class in classList) { if (row.Cells[classNo + 2].Value.ToString() == "L" || row.Cells[classNo + 2].Value.ToString() == "l") { sum += 1; } else if (row.Cells[classNo + 2].Value.ToString() == "1") { sum += 1; } classNo++; } row.Cells["Total"].Value = sum.ToString(); } } }