private void updateDB(bool isNewQT) { QuyTrinhXLSC quytrinh = new QuyTrinhXLSC(); quytrinh.maQTXLSC = txtMaQT.Text; quytrinh.tenQTXLSC = txtTenQT.Text; quytrinh.noidungQTXLSC = rtbNoidung.Text; quytrinh.tennguoiviet = cbNguoiViet.GetItemText(cbNguoiViet.SelectedItem); if ((txtMaQT.Text == "") || (txtTenQT.Text == "") || (cbNguoiViet.Text == "")) { MessageBox.Show(this, "Vui Long Dien Ma, TenQT Va Ten Nguoi Viet", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } DBQuyTrinhXLSC dbquytrinh = new DBQuyTrinhXLSC(); if (isNewQT) { dbquytrinh.addnewQuyTrinh(quytrinh, false); } else { dbquytrinh.addnewQuyTrinh(quytrinh, true); } dbquytrinh.updateGridData(dataGridQuyTrinh); }
public int addnewQuyTrinh(QuyTrinhXLSC quytrinh, bool isUpdate) { DataBaseManager.initializeInstance(); DataBaseManager dbmg = DataBaseManager.getInstance(); SqlConnection con = dbmg.openDatabase(); string insertNewCmd = "INSERT QUYTRINHXULYSUCO (Id, TenQuyTrinh, NguoiVietQuyTrinh, NoiDungQTXLSC) " + " VALUES (@Id,@TenQuyTrinh,@NguoiVietQuyTrinh,@NoiDungQTXLSC)"; string updateCmd = "UPDATE QUYTRINHXULYSUCO SET Id = @Id, TenQuyTrinh = @TenQuyTrinh, NguoiVietQuyTrinh = @NguoiVietQuyTrinh," + " NoiDungQTXLSC = @NoiDungQTXLSC"; SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = CommandType.Text; if (!isUpdate) { cmd.CommandText = insertNewCmd; } else { cmd.CommandText = updateCmd; } //cmd.CommandText = "INSERT QUYTRINHBAOTRI (Id, TenQuyTrinh) VALUES (@maQTBT,@tenQTBT,@tennguoiviet)"; cmd.Parameters.AddWithValue("@ID", quytrinh.maQTXLSC); cmd.Parameters.AddWithValue("@TenQuyTrinh", quytrinh.tenQTXLSC); cmd.Parameters.AddWithValue("@NguoiVietQuyTrinh", quytrinh.tennguoiviet); cmd.Parameters.AddWithValue("@NoiDungQTXLSC", quytrinh.noidungQTXLSC); int ret = -1; try { ret = cmd.ExecuteNonQuery(); } catch (Exception e) { Debug.WriteLine("The product name is " + e.Message); } dbmg.closeDatabase(); return((ret > 0) ? ret : -1); }