private void btnAdd_Click(object sender, EventArgs e) { Products newProduct = new Products(); //Validations //name if (Validation.ProductNotNull(txtName)) //&& ProductDB.IsProdNameUnique(txtName.Text)) { //if (Validation.UniqueName(txtName)) //if(txtName.Text == newProduct.ProdName) //{ // MessageBox.Show("Product Name already exists, it has to be unique", "Input Error"); // txtName.Focus(); //} newProduct.ProdName = txtName.Text; } try { newProduct.ProductId = ProductDB.AddProduct(newProduct); this.DialogResult = DialogResult.OK; // OK if Insert was successful } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } Refresh(); }
private static void GenProducts(int amount) { for (int o = 0; o < amount; o++) { try { string[] _typeList = { "tea", "coffe", "cookies", "stuff" }; string[] _nameList = { "Schwarzer Tee", "Ingwer Tee", "Rooibos", "Kreauter tee" }; string[] _tagList = TagFileReader.tagList.ToArray(); double[] _MWSTList = { 14, 19 }; string genID = ""; Random rnd = new Random(); for (int i = 0; i < 13; i++) { genID += rnd.Next(0, 9); } string genTags = ""; for (int i = 0; i < rnd.Next(1, 3); i++) { genTags += _tagList[rnd.Next(0, _tagList.Length)]; } ProductDB.AddProduct(genID, _typeList[rnd.Next(0, _typeList.Length)], _nameList[rnd.Next(0, _nameList.Length)], rnd.Next(0, 20), rnd.Next(0, rnd.Next(1, 50)), rnd.Next(0, rnd.Next(1, 50)), double.Parse("" + rnd.Next(0, 20) + "," + rnd.Next(0, 99)), "sampleTag;" + genTags, _MWSTList[rnd.Next(0, _MWSTList.Length)], DateTime.Parse(rnd.Next(1, 31) + "." + rnd.Next(1, 12) + "." + rnd.Next(2000, 2022))); } catch (Exception ex_gen) { Console.WriteLine("Error while Generating"); Console.WriteLine(ex_gen); } } }
public void TestUpdateProduct() { /*Create the test variables.*/ Product oldProduct = new Product(); oldProduct.ProductCode = "AAAA"; oldProduct.ProductDescription = "A product for the purposes of testing."; oldProduct.ProductUnitPrice = 99; oldProduct.ProductOnHandQuantity = 10; ProductDB.AddProduct(oldProduct); oldProduct = ProductDB.GetProduct(oldProduct.ProductCode); Product newProduct = new Product(); newProduct.ProductDescription = "Another product for the purposes of testing."; newProduct.ProductUnitPrice = 49; newProduct.ProductOnHandQuantity = 20; /* Test the command.*/ bool isProductUpdated = ProductDB.UpdateProduct(oldProduct, newProduct); /* If it affected the database in some way, the test was successful. */ Assert.AreEqual(true, isProductUpdated); /* Clean up the test.*/ newProduct = ProductDB.GetProduct(newProduct.ProductCode); ProductDB.DeleteProduct(newProduct); }
private void btnAddNew_Click(object sender, EventArgs e) { if (txtProductID.ReadOnly) { txtProductID.ReadOnly = false; txtProductName.Clear(); txtQuantity.Clear(); txtPrice.Clear(); } else { string mes = validData(true); if (mes.Length != 0) { MessageBox.Show(mes); return; } Product p = new Product() { ProductID = int.Parse(txtProductID.Text), ProductName = txtProductName.Text, UnitPrice = float.Parse(txtPrice.Text), Quantity = int.Parse(txtQuantity.Text) }; if (db.AddProduct(p)) { MessageBox.Show("Insert sucessfull."); } else { MessageBox.Show("Insert Failed..."); } LoadProduct(); } }
public ActionResult Create(Product p, HttpPostedFileBase prodPhoto) { if (ModelState.IsValid) { if (prodPhoto != null && prodPhoto.ContentLength > 0) { //check MIME type //create filename //string fileName = Path.GetFileName(prodPhoto.FileName); //generate a unique filename to prevent being overwritten string fileName = Guid.NewGuid().ToString() + Path.GetExtension(prodPhoto.FileName); //generate path w/ filename string path = Path.Combine(Server.MapPath("~/Images"), fileName); //save file prodPhoto.SaveAs(path); p.PhotoLocation = fileName; } ProductDB.AddProduct(p); return(RedirectToAction("Index", "Product")); //redirect to index of product controller } // Return view with model errors return(View(p)); }
private void btnAddProduct_Click(object sender, EventArgs e) { string message = ""; string messageBoxTitle = ""; if (validaterClass.isProvided(txtAddProductName, "Product Name needs to be provided")) { string addProductName = txtAddProductName.Text; DialogResult dialogResult = MessageBox.Show("Are you sure to create the product with Name - \"" + txtAddProductName.Text + "\"?", "Create/ Update Confirmation", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { SupplierDB ado = new SupplierDB(); try { //Insert Product Name perProduct.AddProduct(addProductName); txtAddProductName.Text = ""; } catch (Exception ex) { message = ex.Message; messageBoxTitle = "Update Supplier Error"; } } } }
public void AddProduct(Product p) { if (p.Validate()) { ProductDB productDB = new ProductDB(); productDB.AddProduct(p); } }
public void InitTest() { _testProduct = new Product { Code = "HAMS", Description = "Hamster food", Price = 9.99m }; ProductDB.DeleteProduct(_testProduct); ProductDB.AddProduct(_testProduct); }
public async Task <IList <Product> > PostProduct(Product product) { //products.Add(product); ProductDB.AddProduct(product); return(await Task.FromResult(products)); //CreatedAtAction(nameof(GetAll), products); //var result = products.Where(p => p.ProductKindId == product.ProductKindId).ToList(); //return await Task.FromResult(result); }
/// <summary> /// Checks user input and adds product to the database /// </summary> private void AddButton_Click(object sender, RoutedEventArgs e) { try { if (string.IsNullOrWhiteSpace(productName) || string.IsNullOrWhiteSpace(strProductAmount)) { throw new EmptyFieldException(); } if (!GetProductAmount()) { throw new WrongDataFieldException(); } if (productAmount == 0) { throw new WrongDataFieldException(); } if (!productDB.CheckProductName(productName)) { MessageBoxResult result = MessageBox.Show("Продукция с таким наименованием уже существует.\n" + "Хотите изменить добавить к количеству у существущего?", "Подтверждение", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { if (productDB.ChangeProductAmount(productName, productAmount)) { MessageBox.Show("Продукция успешно добавлена", "Выполнено"); this.DialogResult = true; } } } else { if (productDB.AddProduct(productName, productAmount)) { MessageBox.Show("Продукция успешно добавлена", "Выполнено"); this.DialogResult = true; } else { MessageBox.Show("Неопознанная ошибка добавления продукции", "Ошибка"); this.DialogResult = true; } } } catch (WrongDataFieldException exception) { MessageBox.Show(exception.ErrorMessage, exception.Error); ProductAmountTextBox.Clear(); } catch (EmptyFieldException exception) { MessageBox.Show(exception.ErrorMessage, exception.Error); } }
public IActionResult Create(Product pro) { if (ModelState.IsValid) { ProductDB.AddProduct(pro, context); ViewData["Massage"] = pro.Name + " was added!"; return(View()); } return(View(pro)); }
public ActionResult Create(Product p) { if (ModelState.IsValid) { ProductDB.AddProduct(p); return(RedirectToAction("Index")); } //if not valid valid return same view with with model and //invalid model state. return(View(p)); }
public ActionResult Create(Product product) { //runs validation code (from data annotations in the Model) if (ModelState.IsValid) { ProductDB.AddProduct(product); return(RedirectToAction("Index")); //sends you back to the index page } //showing the user the same web page with error messages //return view with model and invalid ModelState return(View(product)); }
public ActionResult Create(Product product) { //run validation code if (ModelState.IsValid) { ProductDB.AddProduct(product); return(RedirectToAction("Index")); } //showing the user the same web page //with error messages //return view with model and invalid ModelState return(View(product)); }
private void btnAdd_Click(object sender, EventArgs e) { product = new Product(); //creates new product object this.PutProductData(product); //puts user data into the product object try { product.ProdName = ProductDB.AddProduct(product).ToString(); //adds product to the DB this.ClearControls(); // clears the textboxes to add another product } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); //catches exception } }
private void btnAdd_Click(object sender, EventArgs e) { product = new Product(); this.PutProductData(product); try { product.ProdName = ProductDB.AddProduct(product).ToString(); //this.DialogResult = DialogResult.OK; this.ClearControls(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }
//private void cmbProductId_SelectedIndexChanged_1(object sender, EventArgs e) //{ // var pro = from prod in products // where prod.ProductId == (int)txtProductId.SelectedItem // select new // { // prod.ProductId, // prod.ProdName // }; // int i = 0; // foreach (var ps in pro) // { // txtProdName.Text = ps.ProdName.ToString(); // i++; // } // product = new Product(); // product.ProductId = Convert.ToInt32(txtProductId.SelectedItem); // product.ProdName = txtProdName.Text; //} private void btnAccept_Click(object sender, EventArgs e) { if (IsValidData()) { if (addProduct) { product = new Product(); this.PutProductData(product); try { product.ProductId = ProductDB.AddProduct(product); this.DialogResult = DialogResult.OK; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } MessageBox.Show("Product Added Successfully!"); //Form1.LoadProductList(); } else { Product newProduct = new Product(); newProduct.ProductId = product.ProductId; this.PutProductData(newProduct); try { if (!ProductDB.UpdateProduct(product, newProduct)) { MessageBox.Show("Another user has updated or " + "deleted that product.", "Database Error"); this.DialogResult = DialogResult.Retry; } else { product = newProduct; this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } }
private void btn_Add_product_Click(object sender, EventArgs e) { this.productsTest.Text = " "; Product product = new Product(); product.Product_name = txbx_productName.Text; product.Product_price = Convert.ToInt32(txbx_productPrice.Text); ProductDB.AddProduct(product); foreach (Product item in ProductDB.products) { this.productsTest.Text += item.Product_name + " " + item.Product_price + "\n"; } }
private void btnAdd_Click_1(object sender, EventArgs e) { if (loggedInAgt == null) { mainForm.btnSignIn_Click(null, null); } else { // declare suppliers List variable and instantiate new List<Supplier> object List <Product> products = new List <Product>(); // assign suppliers to return of GetSuppliers method call products = ProductDB.GetProducts(); // validate input if (Validator.IsPresent(txtProductName)) { if ((txtProductName.Text.Length > 50)) { MessageBox.Show("The Supplier Name is too long (>50). Please adjust."); return; } // text boxes validated // now check that the entered Product Name does not already exist in the database foreach (Product prod in products) { if (txtProductName.Text != "" && prod.ProdName == txtProductName.Text) { MessageBox.Show("This Product Name already exists in the database."); return; } } // create Product object to be added Product product = new Product(); product.ProdName = txtProductName.Text; int newProductId = ProductDB.AddProduct(product); // retrieve auto-generated ProductId products = ProductDB.GetProducts(); // find the List index of the newly created entry int addIndex = ProductDB.FindIndexofId(products, newProductId); // what is the list index of the newly added product DisplayProducts(addIndex); } } }
public void TestAddProduct() { /*Create the test variables.*/ Product p = new Product(); p.ProductCode = "AAAA"; p.ProductDescription = "A product for testing. Not intended to be removed"; p.ProductUnitPrice = 99; p.ProductOnHandQuantity = 10; /* Test the command.*/ Boolean isProductAdded = ProductDB.AddProduct(p); /* If the test subject has a name within the database, the test was successful. */ Assert.IsTrue(isProductAdded); /*Clean up the test*/ p = ProductDB.GetProduct(p.ProductCode); ProductDB.DeleteProduct(p); }
//when accept button has been clicked private void btnAccept_Click(object sender, EventArgs e) { if (ValidData()) { if (addProdcut) //if add button was picked from main form { product = new Product(); this.ProductData(product); //setting new product name to the name typed by user try { //calling method used to add product to database returing the auto incremented ProdcutID product.ProductID = ProductDB.AddProduct(product); this.DialogResult = DialogResult.OK; //setting dialog result to OK } catch (Exception ex) { throw ex; } } else // if modify button was selected from main form { Product newProduct = new Product(); newProduct.ProductID = product.ProductID; this.ProductData(newProduct); try { if (!ProductDB.UpdateProduct(product, newProduct)) { MessageBox.Show("Another user has updated or deleted " + product.ProdName, "Database Error"); this.DialogResult = DialogResult.Retry; } else { this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } }
public ActionResult Index(ProductViewModel prod) { if (ModelState.IsValid) { Product p = new Product() { ProductName = prod.ProductName, PhoneNumber = prod.PhoneNumber, Price = prod.Price, Owner = prod.Owner, Category = prod.Category, Description = prod.Description, EmailAddress = prod.EmailAddress }; ProductDB.AddProduct(p); return(RedirectToAction("Index", "Home")); } return(View(prod)); }
private void ProdSaveButton_Click(object sender, EventArgs e) { // check if valid before accepting changes -Katrina if (Validator.IsPresent(prodNameTextBox)) { if (addProduct) // if Add { this.PutProductData(); try { product.ProductId = ProductDB.AddProduct(product); this.DialogResult = DialogResult.OK; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } else // if Modify { product.ProductId = currentProd.ProductId; this.PutProductData(); try // try to update { if (!ProductDB.UpdateProduct(currentProd, product)) // failed { MessageBox.Show("Another user has updated or deleted current product", "Concurrency Error"); this.DialogResult = DialogResult.Retry; } else { currentProd = product; this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show("Error while updating: " + ex.Message, ex.GetType().ToString()); } } } }
//SAVE CHANGES private void btnAccept_Click(object sender, EventArgs e) { if (IsValidData()) { if (addProduct) { product = new Product(); //product being added this.SaveToProduct(product); try { ProductDB.AddProduct(product); //save product to DB this.DialogResult = DialogResult.OK; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } else //edit product { Product newProduct = new Product(); //updated product this.SaveToProduct(newProduct); try { if (!ProductDB.UpdateProduct(product, newProduct)) //if bool is false (concurrency error) { MessageBox.Show("Another user has updated or deleted that product.", "Database Error"); this.DialogResult = DialogResult.Retry; } else //bool is true, no concurrency issue { product = newProduct; this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } }
public ActionResult Create(Product pro) { ProductDB pd = new ProductDB(); fn = Path.GetFileNameWithoutExtension(pro.ImageFile.FileName); ext = Path.GetExtension(pro.ImageFile.FileName); fn = fn + DateTime.Now.ToString("yymmssfff") + ext; pro.path = "~/images/" + fn; fn = Path.Combine(Server.MapPath("~/images/"), fn); pro.ImageFile.SaveAs(fn); //ImageFile1.SaveAs(fn); pro.picture = fn.ToString(); try { if (ModelState.IsValid) { { if (pd.AddProduct(pro)) { ViewBag.Message = "Product Added Successfully"; } ModelState.Clear(); CategoryDB Cdb = new CategoryDB(); var li = Cdb.GetCategory(); ViewBag.list = li; } } return(View()); } catch { return(View()); } }
//add new product to database private void btnProductAdd_Click_1(object sender, EventArgs e) { if (Validator.IsPresent(txtProdAddEdit)) { Product newProduct = new Product(); newProduct = currentProduct; newProduct.ProdName = txtProdAddEdit.Text; int newId = -1; newId = ProductDB.AddProduct(newProduct); //MessageBox.Show(newId.ToString()); if (newId != -1) { //refresh form LoadProducts(); SetUpFrmControls(); lstProducts.SelectedValue = newId; currentProduct = ProductDB.getProductById(newId); } else { MessageBox.Show("An error occurred updating the database. Please try again."); } } }
public int AddProduct(Product product) { ProductDB productDB = new ProductDB(); return(productDB.AddProduct(product)); }