private void btn_Luu_Click(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(txt_ChucVu.Text)) { #region thao tac them if (bAddFlag) { if (MessageBox.Show("Bạn thực sự muốn thêm chức vụ này ?", "Hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { oChucVu.TenChucVu = txt_ChucVu.Text.Trim(); try { if (oChucVu.Add()) { MessageBox.Show("Thêm thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } RefreshDataSource(); ResetInterface(true); } catch (Exception ex) { MessageBox.Show("Thao tác thêm thất bại.\n" + ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } #endregion #region thao tac sua else { if (MessageBox.Show("Bạn thực sự muốn sửa chức vụ này ?", "Hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { oChucVu.ID = Convert.ToInt16(dtgv_DSChucVu.CurrentRow.Cells[0].Value.ToString()); oChucVu.TenChucVu = txt_ChucVu.Text.Trim(); try { if (oChucVu.Update()) { MessageBox.Show("Cập nhật thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } RefreshDataSource(); ResetInterface(true); } catch (Exception ex) { MessageBox.Show("Thao tác sửa thất bại.\n" + ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } #endregion } else { MessageBox.Show("Tên chức vụ không được rỗng, xin vui lòng cung cấp tên mô hình", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }