private void btn_Luu_Click(object sender, EventArgs e) { if (txt_Ten.Text != "") { #region thao tac them if (AddFlag) { if (MessageBox.Show("Bạn thực sự muốn thêm loại đơn vị này ?", "Hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string tendv = txt_Ten.Text; LoaiDonVi.TenLoai = tendv; try { LoaiDonVi.Add(); MessageBox.Show("Thêm thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); ResetInterface(true); RefreshDataSource(); return; } catch { MessageBox.Show("Thao tác thêm thất bại.", "Lỗi", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } } } #endregion #region thao tac sua else // thao tac sua { if (MessageBox.Show("Bạn thực sự muốn sửa loại đơn vị này ?", "Hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int id = Convert.ToInt16(dtgv_DSLoaiDonVi.CurrentRow.Cells[0].Value.ToString()); string tendv = txt_Ten.Text; LoaiDonVi.ID = id; LoaiDonVi.TenLoai = tendv; try { LoaiDonVi.Update(); MessageBox.Show("Sửa thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); ResetInterface(true); RefreshDataSource(); return; } catch { MessageBox.Show("Thao tác sửa thất bại.", "Lỗi", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } } } #endregion } else { MessageBox.Show("Tên loại đơn vị không được rỗng, xin vui lòng cung cấp tên loại đơn vị", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }