void InserUpdateData() { if (txtMaMH.Text.Trim().Equals("") || txtTenMH.Text.Trim().Equals("")) { MessageBox.Show("Điền Mã môn học và Tên môn học đầy đủ, sau đó thực hiện lại thao tác", "Thông báo !", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (InsertNew == true) { try { en.MaMH = txtMaMH.Text; en.TenMH = txtTenMH.Text; en.DonVi = txtDonVi.Text; en.SoTC = Int32.Parse(nSoTC.Value.ToString()); en.BieuPhi = Int32.Parse(nBieuPhi.Value.ToString()); en.TrangThai = Int32.Parse(cbTrangThai.SelectedValue.ToString()); en.NgayTao = Convert.ToDateTime(localDate.ToString(formatDH)); en.NgayCapNhat = Convert.ToDateTime(localDate.ToString(formatDH)); bus.insertdata(en); MessageBox.Show("Đã thêm 1 dòng"); } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message.ToString()); } } else { try { int index = dgv.CurrentCell.RowIndex; en.MaMH = dgv.Rows[index].Cells["MaMH"].Value.ToString(); en.TenMH = txtTenMH.Text; en.DonVi = txtDonVi.Text; en.SoTC = Int32.Parse(nSoTC.Value.ToString()); en.BieuPhi = Int32.Parse(nBieuPhi.Value.ToString()); en.TrangThai = Int32.Parse(cbTrangThai.SelectedValue.ToString()); en.NgayCapNhat = Convert.ToDateTime(localDate.ToString(formatDH)); bus.updatedata(en); MessageBox.Show("Đã cập nhật 1 dòng"); } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message.ToString()); } } NapDuLieu(); XoaForm(); EvenButton(0); EnableOrDisable(true); }