private void EditButton_Click(object sender, EventArgs e) { try { List <int> examIds = new List <int>(); examIds.Add(Convert.ToInt32(ExamDataGridView.Rows[ExamDataGridView.SelectedCells[0].RowIndex].Cells[0].Value)); if (examIds.Count == 1) { int examId = examIds.FirstOrDefault(); EditExamForm editExamForm = new EditExamForm(examId); editExamForm.ShowDialog(); } else if (examIds.Count == 0) { //MessageBox.Show("Bạn chưa chọn kỳ thi nào", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); NotificationForm notificationForm = new NotificationForm("Bạn chưa chọn kỳ thi nào", "Cảnh báo", MessageBoxIcon.Warning); notificationForm.ShowDialog(); } else { //MessageBox.Show("Chỉ chọn 1 kỳ thi để sửa", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); NotificationForm notificationForm = new NotificationForm("Chỉ chọn 1 kỳ thi để sửa", "Cảnh báo", MessageBoxIcon.Warning); notificationForm.ShowDialog(); } } catch (Exception ex) { //MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); NotificationForm notificationForm = new NotificationForm(Common.Common.COMMON_ERORR, "Lỗi", MessageBoxIcon.Error); notificationForm.ShowDialog(); } }
private void ExamDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == ExamDataGridView.Columns["Edit"].Index && e.RowIndex >= 0) { int examId = int.Parse(ExamDataGridView.Rows[e.RowIndex].Cells["Id"].Value.ToString()); EditExamForm editExamForm = new EditExamForm(examId); editExamForm.ShowDialog(); } else if (e.ColumnIndex == ExamDataGridView.Columns["Delete"].Index && e.RowIndex >= 0) { DialogResult dialogResult = MessageBox.Show("Đồng ý xóa?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { try { int examId = int.Parse(ExamDataGridView.Rows[e.RowIndex].Cells["Id"].Value.ToString()); int result = managingSchoolService.DeleteExam(examId); if (result > 0) { //MessageBox.Show("Xóa thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); NotificationForm notificationForm = new NotificationForm("Xóa thành công", "Thông báo", MessageBoxIcon.Information); notificationForm.ShowDialog(); LoadExamList(); } else { //MessageBox.Show("Xóa không thành công", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Error); NotificationForm notificationForm = new NotificationForm("Xóa không thành công", "Cảnh báo", MessageBoxIcon.Warning); notificationForm.ShowDialog(); } } catch (Exception ex) { //MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); NotificationForm notificationForm = new NotificationForm(Common.Common.COMMON_ERORR, "Lỗi", MessageBoxIcon.Error); notificationForm.ShowDialog(); } } else if (dialogResult == DialogResult.No) { //no delete } } }