private void btnAdd_Click(object sender, EventArgs e) { String id = txtProductID.Text; String name = txtProductName.Text; String price = txtUnitPrice.Text; String quantity = txtQuantity.Text; string error = valid(id, name, price, quantity); if (error.Equals("")) { Product p = new Product(int.Parse(id), name, float.Parse(price), int.Parse(quantity)); bool check = db.AddNewProduct(p); if (check) { LoadProduct(); MessageBox.Show("Add success!"); } else { MessageBox.Show("Id is exist"); } } else { MessageBox.Show(error); } }
private void insertBtn_Click(object sender, EventArgs e) { Product product = fromTxt(); db.AddNewProduct(product); loadList(); }
private void button1_Click(object sender, EventArgs e) { string mes = validData(); if (mes.Length != 0) { MessageBox.Show(mes); return; } Product p = new Product() { ProductID = int.Parse(txtID.Text), ProductName = txtName.Text, UnitPrice = float.Parse(txtPrice.Text), Quantity = int.Parse(txtQuantity.Text) }; if (db.AddNewProduct(p)) { MessageBox.Show("Insert succeed"); } else { MessageBox.Show("Insert fail"); } this.Close(); }
private void btnSave_Click(object sender, EventArgs e) { bool flag = false; Product.ProductID = int.Parse(txtProductID.Text); Product.ProductName = txtProductName.Text; Product.UnitPrice = float.Parse(txtUnitPrice.Text); Product.Quantity = int.Parse(txtQuantity.Text); ProductDB dB = new ProductDB(); if (addOrEdit == true) { flag = dB.AddNewProduct(Product); } else if (addOrEdit == false) { flag = dB.UpdateProduct(Product); } if (flag == false) { MessageBox.Show("Save fail"); } else { MessageBox.Show("Save Successful."); } }
private void btnSave_Click(object sender, EventArgs e) { ClearErrorProvider(); int ID = 0; int.TryParse(txtProductID.Text, out ID); string Name = txtProductName.Text; int Quantity = 0; decimal Price = 0; try { Quantity = int.Parse(txtQuantity.Text); } catch (Exception) { errQuantity.SetError(txtQuantity, "Quantity must be an integer"); return; } try { Price = decimal.Parse(txtUnitPrice.Text); } catch (Exception) { errPrice.SetError(txtUnitPrice, "Price must be an float"); return; } var p = new Product(ID, Name, Quantity, Price); if (isAddNew) { if (db.AddNewProduct(p)) { MessageBox.Show("Successfully"); } else { MessageBox.Show("Fail"); } } else { if (db.UpdateProduct(p)) { MessageBox.Show("Successfully"); } else { MessageBox.Show("Fail"); } } btnRefresh_Click(null, null); }
private void btnAdd_Click(object sender, EventArgs e) { try { int id = 0; string name = string.Empty; float price = 0; int quantity = 0; if (getAndCheckValues(ref id, ref name, ref price, ref quantity)) { Product p = new Product { ProductID = id, ProductName = name, Quantity = quantity, UnitPrice = price }; bool result = pd.AddNewProduct(p); string message = (result ? "successfull" : "fail"); MessageBox.Show("Add " + message); Form1_Load(sender, e); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnAdd_Click(object sender, EventArgs e) { if (btnAdd.Text.Equals("New")) { btnAdd.Text = "Add"; btnCancel.Visible = true; //clear binding txtProductID.DataBindings.Clear(); txtProductName.DataBindings.Clear(); txtQuantity.DataBindings.Clear(); txtUnitPrice.DataBindings.Clear(); txtProductID.ReadOnly = false; txtProductID.Text = ""; txtProductName.Text = ""; txtQuantity.Text = ""; txtUnitPrice.Text = ""; btnDelete.Enabled = false; btnUpdate.Enabled = false; } else { try { int productID = int.Parse(txtProductID.Text); if (productID > 0) { Product result = productDB.FindProduct(productID); if (result == null) { string productName = txtProductName.Text; float unitPrice = float.Parse(txtUnitPrice.Text); int quantity = int.Parse(txtQuantity.Text); bool isValidInput = CheckTextBoxInput(productName, unitPrice, quantity); if (isValidInput) { Product product = new Product(productID, productName, quantity, unitPrice); productDB.AddNewProduct(product); txtProductID.ReadOnly = true; btnAdd.Text = "New"; btnDelete.Enabled = true; btnUpdate.Enabled = true; LoadBook(); } } else { MessageBox.Show("Duplicate ProductID", "Error"); } } else { MessageBox.Show("ProductID must be positive", "Error"); } } catch (FormatException ex) { MessageBox.Show("ProductID, Quantity and Price must be number", "Error"); } } }