private void bt_MALuu_Click(object sender, EventArgs e) { if (isAdd == true) { if (tb_MATen.Text != "") { var monAn = new MonAn(); var sql = new GetDataFromSQL(); monAn.TenMonAn = tb_MATen.Text; monAn.DonViTinh = tb_MADonViTinh.Text; monAn.DonGia = Convert.ToDouble(tb_MADonGia.Text); monAn.GhiChu = tb_MAGhiChu.Text; monAn.DanhMuc = sql.timMaDanhMuc(cb_MADanhMuc.Text); if (sql.themMonAn(monAn)) { MessageBox.Show("Thêm thành công"); isAdd = false; } } else { MessageBox.Show("Vui lòng nhập đầy đủ thông tin!"); return; } } if (isEdit == true) { if (tb_MATen.Text != "") { var ma = new MonAn(); var sql = new GetDataFromSQL(); ma.DanhMuc = sql.timMaDanhMuc(cb_MADanhMuc.Text); ma.DonGia = Convert.ToDouble(tb_MADonGia.Text); ma.DonViTinh = tb_MADonViTinh.Text; ma.GhiChu = tb_MAGhiChu.Text; ma.TenMonAn = tb_MATen.Text; int currentIndex = dataGridView2.CurrentRow.Index; int maMA = int.Parse(dataGridView2.Rows[currentIndex].Cells[0].Value.ToString()); if (sql.capNhatMonAn(ma, maMA)) { MessageBox.Show("Sửa thành công!"); isEdit = false; } } else { MessageBox.Show("Không thể sửa thành NULL!"); return; } } LoadDGVMonAn(); }