private void buttonYes_Click(object sender, EventArgs e) { bool flag = true; if (dataGridViewThamSo.Rows[Index].Cells["ColTenThamSo"].Value == null) { MessageBox.Show("Tên tham số không được để trống"); dataGridViewThamSo.CurrentCell = dataGridViewThamSo.Rows[Index].Cells["ColTenThamSo"]; dataGridViewThamSo.BeginEdit(true); flag = false; } else if (dataGridViewThamSo.Rows[Index].Cells["ColGiaTri"].Value == null) { MessageBox.Show("Giá trị không được để trống"); dataGridViewThamSo.CurrentCell = dataGridViewThamSo.Rows[Index].Cells["ColGiaTri"]; dataGridViewThamSo.BeginEdit(true); flag = false; } if (flag) { ThamSoDTO thamSoDTO = new ThamSoDTO(); thamSoDTO.TenThamSo = dataGridViewThamSo.Rows[Index].Cells["ColTenThamSo"].Value.ToString(); thamSoDTO.GiaTri = dataGridViewThamSo.Rows[Index].Cells["ColGiaTri"].Value.ToString(); if (Status == 1)//Them tham so { thamSoDTO.MaThamSo = ThamSoBUS.CreateThamSoId(); dataGridViewThamSo.Rows[Index].Cells["ColMaThamSo"].Value = thamSoDTO.MaThamSo; dataGridViewThamSo.Rows[Index].Cells["ColSTT"].Value = (Index + 1).ToString(); if (ThamSoBUS.InsertThamSo(thamSoDTO)) { dataGridViewThamSo.Rows[Index].ReadOnly = true; MessageBox.Show("Thêm thành công"); } else { dataGridViewThamSo.Rows.RemoveAt(Index); MessageBox.Show("Thêm thất bại"); } } else if (Status == 2) { thamSoDTO.MaThamSo = dataGridViewThamSo.Rows[Index].Cells["ColMaThamSo"].Value.ToString(); if (ThamSoBUS.UpdateThamSoById(thamSoDTO)) { dataGridViewThamSo.Rows[Index].ReadOnly = true; MessageBox.Show("Cập nhật thành công"); } else { MessageBox.Show("Cập nhật thất bại"); dataGridViewThamSo.Rows[Index].Cells["ColTenThamSo"].Value = BackupThamSoDTO.TenThamSo; dataGridViewThamSo.Rows[Index].Cells["ColGiaTri"].Value = BackupThamSoDTO.GiaTri; dataGridViewThamSo.Rows[Index].ReadOnly = true; } } Reset(); } }