private void EditButton_Click(object sender, EventArgs e) { try { List <int> schoolIds = new List <int>(); schoolIds.Add(Convert.ToInt32(SchoolDataGridView.Rows[SchoolDataGridView.SelectedCells[0].RowIndex].Cells[0].Value)); if (schoolIds.Count == 1) { int schoolId = schoolIds.FirstOrDefault(); EditSchoolForm editBlankCertForm = new EditSchoolForm(schoolId); editBlankCertForm.ShowDialog(); } else if (schoolIds.Count == 0) { //MessageBox.Show("Bạn chưa chọn trường nào", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); NotificationForm notificationForm = new NotificationForm("Bạn chưa chọn trường nào", "Cảnh báo", MessageBoxIcon.Warning); notificationForm.ShowDialog(); } else { //MessageBox.Show("Chỉ chọn 1 trường để sửa", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); NotificationForm notificationForm = new NotificationForm("Chỉ chọn 1 trường để 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 SchoolDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == SchoolDataGridView.Columns["Edit"].Index && e.RowIndex >= 0) { int schoolId = int.Parse(SchoolDataGridView.Rows[e.RowIndex].Cells["Id"].Value.ToString()); EditSchoolForm editBlankCertForm = new EditSchoolForm(schoolId); editBlankCertForm.ShowDialog(); } else if (e.ColumnIndex == SchoolDataGridView.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 schoolId = int.Parse(SchoolDataGridView.Rows[e.RowIndex].Cells["Id"].Value.ToString()); int result = managingSchoolService.DeleteSchool(schoolId); 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(); LoadSchool(); } else { //MessageBox.Show("Xóa không thành công", "Lỗi", 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 } } }