private void btn_Luu_Click(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(txt_Ten.Text)) { #region thao tac them if (bAddFlag) { if (MessageBox.Show("Bạn thực sự muốn thêm mô hình này ?", "Hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { oMoHinhDaoTao.TenMoHinh = txt_Ten.Text.Trim(); oMoHinhDaoTao.MoTa = rtb_MoTa.Text.Trim(); try { if (oMoHinhDaoTao.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 mô hình này ?", "Hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { oMoHinhDaoTao.ID = Convert.ToInt16(dtgv_DSMoHinh.CurrentRow.Cells[0].Value.ToString()); oMoHinhDaoTao.TenMoHinh = txt_Ten.Text.Trim(); oMoHinhDaoTao.MoTa = rtb_MoTa.Text.Trim(); try { if (oMoHinhDaoTao.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 mô hình không được rỗng, xin vui lòng cung cấp tên mô hình", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }