private void btnCancelChanges_Click(object sender, EventArgs e) { btnSave.Enabled = false; btnCancelChanges.Enabled = false; QuanLy.addedRows.Clear(); QuanLy.modifiedRows.Clear(); QuanLy.removedRows.Clear(); QuanLy.LoadDataToDataGridView(dataGridView1); }
private void Form1_Load(object sender, EventArgs e) { QuanLy.LoadDataToDataGridView(dataGridView1); }
private void btnSave_Click(object sender, EventArgs e) { btnSave.Enabled = false; if (!QuanLy.CheckAffectedRows(dataGridView1)) { /* Show error(s) to the user */ MessageBox.Show("Có lỗi khi cập nhật dữ liệu vào CDSL. Vui lòng kiểm tra lại các thay đổi của bạn.", "Cập nhật không thành công"); QuanLy.ShowErrorText(lblUpdateStatus); QuanLy.errors.Clear(); } else { /* Save the changes */ btnCancelChanges.Enabled = false; foreach (DataGridViewRow row in QuanLy.addedRows) { using (SqlConnection connection = new SqlConnection(Properties.Resources.localConnectionString_HoangAn)) { connection.Open(); SqlCommand command = new SqlCommand("ThemCB", connection) { CommandType = CommandType.StoredProcedure }; QuanLy.AddParametersToCommand(command, row); command.ExecuteNonQuery(); } } foreach (DataGridViewRow row in QuanLy.modifiedRows) { using (SqlConnection connection = new SqlConnection(Properties.Resources.localConnectionString_HoangAn)) { connection.Open(); SqlCommand command = new SqlCommand("SuaCB", connection) { CommandType = CommandType.StoredProcedure }; QuanLy.AddParametersToCommand(command, row); command.ExecuteNonQuery(); } } foreach (DataGridViewRow row in QuanLy.removedRows) { using (SqlConnection connection = new SqlConnection(Properties.Resources.localConnectionString_HoangAn)) { connection.Open(); SqlCommand command = new SqlCommand("XoaCB", connection) { CommandType = CommandType.StoredProcedure }; QuanLy.AddParametersToCommand(command, row); command.ExecuteNonQuery(); } } QuanLy.ShowChangeLog(lblUpdateStatus); QuanLy.addedRows.Clear(); QuanLy.modifiedRows.Clear(); QuanLy.removedRows.Clear(); QuanLy.LoadDataToDataGridView(dataGridView1); } }