public bool updateProType(DTO_ProductType proType) { string sql = string.Format("Update ProductTypes set IDProductlines = (select IDProductlines from Productlines where NameProductlines = '{0}') , NameProductType = '{1}' where IDProductType = '{2}'", proType.IDProductlines, proType.NameProductType, proType.IDProductType); cnn = DataProvider.ConnectData(); SqlCommand command = new SqlCommand(sql, cnn); int row = command.ExecuteNonQuery(); cnn.Close(); if (row > 0) { return(true); } return(false); }
public bool addProType(DTO_ProductType proType) { string sql = string.Format("Insert into ProductTypes values('{0}', (select IDProductlines from Productlines where NameProductlines = '{1}' ), '{2}', '{3}', 'On')", proType.IDProductType, proType.IDProductlines, proType.NameProductType, proType.Quantity); cnn = DataProvider.ConnectData(); SqlCommand command = new SqlCommand(sql, cnn); int row = command.ExecuteNonQuery(); cnn.Close(); if (row > 0) { return(true); } return(false); }
private void btnUpdate_Click(object sender, EventArgs e) { if (btnUpdate.Text.Equals("EDIT")) { btnUpdate.Text = "UPDATE"; btnAdd.Enabled = false; btnDelete.Enabled = false; Action <Control.ControlCollection> blockTextBox = null; blockTextBox = (controls) => { foreach (Control control in controls) { if (control is TextBox) { (control as TextBox).ReadOnly = false; } else { blockTextBox(control.Controls); } } }; blockTextBox(Controls); txtProID.ReadOnly = true; } else { var rs = MessageBox.Show("Do you want to update ???", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (rs == DialogResult.Yes) { if (tabControl2.SelectedIndex == 0)//Update product { BUS_Product bus = new BUS_Product(); string check = checkUpdate(); if (check.Equals("")) { string idPro = txtProID.Text; string idProType = cbProType.Text; float size = float.Parse(txtProSize.Text); string name = txtProName.Text; int price = int.Parse(txtProPrice.Text); int quantity = int.Parse(txtProQuantity.Text); string discount = txtProDiscount.Text; DTO_Product x = new DTO_Product(idPro, idProType, name, size, price, quantity, discount); bool update = bus.updateProduct(x); if (update) { MessageBox.Show("Update succesfully"); Clear(); } } else { MessageBox.Show(check); } } else if (tabControl2.SelectedIndex == 1)//Update Type { BUS_ProductType bus = new BUS_ProductType(); string check = checkUpdate(); if (check.Equals("")) { txtMnIDProType.ReadOnly = true; string idProtype = txtMnIDProType.Text; string idProLine = cbMnProLine.SelectedItem.ToString(); string nameProType = txtMnNametype.Text; int quantity = int.Parse(txtMnQuantityType.Text); DTO_ProductType x = new DTO_ProductType(idProtype, idProLine, nameProType, quantity); bool update = bus.updateProType(x); if (update) { MessageBox.Show("Update succesfully"); Clear(); } } else { MessageBox.Show(check); } } else //Update Employee { BUS_Employee bus = new BUS_Employee(); string check = checkUpdate(); if (check.Equals("")) { txtEmpID.ReadOnly = true; string id = txtEmpID.Text; string pass = txtEmpPass.Text; string name = txtEmpName.Text; string idShop = cbEmpShop.Text.ToString(); string address = txtEmpAddress.Text; string supervisor = txtEmpSupervisor.Text; string phone = txtEmpPhone.Text; string role = cbEmpRole.SelectedItem.ToString(); string status = "On"; if (rdOff.Checked == true) { status = "Off"; } if (txtEmpSupervisor.Text.Equals("")) { txtEmpSupervisor.Text = "null"; } DTO_Employee x = new DTO_Employee(id, pass, name, phone, address, idShop, supervisor, role, status); bool update = bus.updateEmployee(x); if (update) { MessageBox.Show("Update succesfully"); Clear(); } } else { MessageBox.Show(check); } } btnUpdate.Text = "EDIT"; } Clear(); } }
private void btnAdd_Click(object sender, EventArgs e) { string check = checkAdd(); if (btnAdd.Text.Equals("ADD NEW")) { btnAdd.Text = "ADD"; btnUpdate.Enabled = false; btnDelete.Enabled = false; EditText(); txtProID.Text = "ID product is added automatic"; } else { if (check.Equals("")) { if (tabControl2.SelectedIndex == 0)//Add product { BUS_Product bus = new BUS_Product(); string idPro = txtProID.Text; bool checkIDProduct = bus.checkID(idPro); if (checkIDProduct) { var rs = MessageBox.Show("Do you want to update quantity of product ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (rs == DialogResult.Yes) { fmAddQuanity f = new fmAddQuanity(idPro); f.ShowDialog(); Clear(); } } else { string idProType = cbProType.Text; MessageBox.Show(idProType); float size = float.Parse(txtProSize.Text); string name = txtProName.Text; int price = int.Parse(txtProPrice.Text); int quantity = int.Parse(txtProQuantity.Text); string discount = txtProDiscount.Text; DTO_Product x = new DTO_Product(idProType, name, size, price, quantity, discount); bus.addProduct(x); MessageBox.Show("Add new product succesfully"); loadAllData(); Clear(); } } else if (tabControl2.SelectedIndex == 1)//Add Type { EditText(); try { BUS_ProductType bus = new BUS_ProductType(); string idProtype = txtMnIDProType.Text; string idProLine = cbMnProLine.Text; string nameProType = txtMnIDProType.Text; int quantity = 0; DTO_ProductType x = new DTO_ProductType(idProtype, idProLine, nameProType, quantity); bus.addProType(x); MessageBox.Show("Create product type succesfully"); loadAllData(); Clear(); } catch (Exception) { MessageBox.Show("ID product type is duplicate!!!"); } } else //Add Employee { EditText(); try { BUS_Employee bus = new BUS_Employee(); string id = txtEmpID.Text; string pass = txtEmpPass.Text; string name = txtEmpName.Text; string idShop = cbEmpShop.Text.ToString(); string address = txtEmpAddress.Text; string supervisor = txtEmpSupervisor.Text; string phone = txtEmpPhone.Text; string role = cbEmpRole.Text; DTO_Employee x = new DTO_Employee(id, pass, name, phone, address, idShop, supervisor, role, "On"); bus.addEmployee(x); MessageBox.Show("Create succesfully"); } catch (Exception) { MessageBox.Show("ID employee is duplicate!!!"); } loadAllData(); Clear(); } } else { MessageBox.Show(check); } } }
public bool updateProType(DTO_ProductType proType) { return(dao.updateProType(proType)); }
public bool addProType(DTO_ProductType proType) { return(dao.addProType(proType)); }