public int addNewDeviceGroup(NhomThietBi nhomThietBi, bool isNewNhom) { DataBaseManager.initializeInstance(); DataBaseManager dbmg = DataBaseManager.getInstance(); SqlConnection con = dbmg.openDatabase(); string newNhomCMD = "INSERT NHOMTB (Id, Ten, He) " + " VALUES (@Id,@Ten,@He)"; string updateNhomCMD = "UPDATE NHOMTB SET Id = @Id, Ten = @Ten, He = @He WHERE Id = @Id"; SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = CommandType.Text; if (isNewNhom) { cmd.CommandText = newNhomCMD; } else { cmd.CommandText = updateNhomCMD; } cmd.Parameters.AddWithValue("@Id", nhomThietBi.groupID); cmd.Parameters.AddWithValue("@Ten", nhomThietBi.groupName); cmd.Parameters.AddWithValue("@He", nhomThietBi.groupSection); int ret = -1; try { ret = cmd.ExecuteNonQuery(); } catch (Exception e) { Debug.WriteLine("The product name is " + e.Message); } dbmg.closeDatabase(); Debug.WriteLine("DEVICE IS REGISTERED " + ret); return((ret > 0) ? ret : -1); }
private void updateDB(bool isNewNhom) { NhomThietBi nhom = new NhomThietBi(); nhom.groupID = txtMaNhom.Text; nhom.groupName = txtTenNhom.Text; nhom.groupSection = txtHe.Text; if (nhom.groupID.Equals("") || nhom.groupName.Equals("")) { MessageBox.Show(this, "Vui Long Dien Ma Nhom Ten Nhom", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } DBNhomThietBi ntbDB = new DBNhomThietBi(); ntbDB.addNewDeviceGroup(nhom, isNewNhom); ntbDB.updateGridData(dataGridNhom); }