private void B_Search_Click(object sender, EventArgs e) { // Method that initiates the search for students StudentAccessLayer SAL = new StudentAccessLayer(Session.Database); _searchResults = new List <Student>(); try { switch (CB_SearchBy.SelectedIndex) { case 1: _searchResults = SAL.GetStudentByForename(TB_StudentSearch.Text); break; case 2: _searchResults = SAL.GetStudentBySurname(TB_StudentSearch.Text); break; default: _searchResults.Add(SAL.GetStudentById(Convert.ToInt32(TB_StudentSearch.Text))); break; } } catch (ValidationException vEx) { MessageBox.Show("Record not loaded. There was an error with the student record: " + vEx.Message); } PopulateDT(_searchResults); }
private void B_Enrol_Click(object sender, EventArgs e) { StudentAccessLayer SAL = new StudentAccessLayer(Session.Database); Student result = MakeStudent(); try { if (_existingStudent == null) // If not editing a student { result.Id = SAL.InsertStudent(result); } else // Updates student ID so existing record is updated { result.Id = _existingStudent.Id; SAL.UpdateStudent(result); } } catch (System.Data.SqlClient.SqlException ex) { MessageBox.Show("Student not added/updated. There was an SQL issue: \n" + ex.Message, "SQL ERROR"); return; } F_Enrolment ES = new F_Enrolment(result); ES.Show(); }
private void B_EditStudent_Click(object sender, EventArgs e) { if (DGV_Students.SelectedRows.Count == 1) { StudentAccessLayer SAL = new StudentAccessLayer(Session.Database); F_StudentRegister RS = new F_StudentRegister(SAL.GetStudentById(Convert.ToInt32(DGV_Students.SelectedRows[0].Cells[0].Value.ToString()))); RS.Show(); // Register form doubles up as edit form } else { MessageBox.Show("You have selected more than 1 or 0 students."); } }
// Buttons private void B_EnrolStudent_Click(object sender, EventArgs e) { // Makes sure that only one student is selected if (DGV_Students.SelectedRows.Count == 1) { StudentAccessLayer SAL = new StudentAccessLayer(Session.Database); F_Enrolment ES = new F_Enrolment(SAL.GetStudentById(Convert.ToInt32(DGV_Students.SelectedRows[0].Cells[0].Value.ToString()))); ES.Show(); // Opening enrolment form } else { MessageBox.Show("You have selected more than 1 or less than 1 students."); } }
private void B_DeleteStudent_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("Are you sure you want to delete this student?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dr == DialogResult.Yes) { StudentAccessLayer SAL = new StudentAccessLayer(Session.Database); if (SAL.DeleteStudent(SAL.GetStudentById(Convert.ToInt32(DGV_Students.SelectedRows[0].Cells[0].Value.ToString())))) { MessageBox.Show("Student deleted successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); _dt.Rows.Clear(); } else { MessageBox.Show("Could not delete student.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void B_Search_Click(object sender, EventArgs e) { // Method that initiates the search for students StudentAccessLayer SAL = new StudentAccessLayer(Session.Database); _searchResults = new List <Student>(); switch (CB_SearchBy.SelectedIndex) { case 1: _searchResults = SAL.GetStudentByForename(TB_StudentSearch.Text); break; case 2: _searchResults = SAL.GetStudentBySurname(TB_StudentSearch.Text); break; default: _searchResults.Add(SAL.GetStudentById(Convert.ToInt32(TB_StudentSearch.Text))); break; } PopulateDT(_searchResults); }