private void placeOrderButton_Click(object sender, EventArgs e) { int count = 0; int cartCount = cartDataGridView.RowCount; if (cartCount != 0) { int quanCount = 0; foreach (double val in totalPrice) { if (val != 0) { quanCount++; } } if (cartCount == quanCount) { EShoppingLibrary.Products aProd = new EShoppingLibrary.Products(); foreach (DataGridViewRow row in cartDataGridView.Rows) { string name = row.Cells[0].Value.ToString(); int noOfItems = Convert.ToInt32(row.Cells[2].Value); //MessageBox.Show(":" + name + ":" + noOfItems.ToString() + ":"); int res = aProd.DecrementStock(name, noOfItems); if (res == 1) { count++; } else { MessageBox.Show(aProd.LastError, "Error"); clearCartButton_Click(sender, e); break; } if (count == cartCount) { MessageBox.Show("Your order has been successfully placed.."); clearCartButton_Click(sender, e); totalLabel.Text = ""; Product.allProducts.Clear(); } } } else { MessageBox.Show("Please select the quantity..."); } } else { MessageBox.Show("Your Cart is empty..."); } }
private void viewProductButton_Click(object sender, EventArgs e) { try { if (productIdTextBox.Text.Trim() != "") { int prodId = Convert.ToInt32(productIdTextBox.Text); EShoppingLibrary.Products aProd = new EShoppingLibrary.Products(); string res = aProd.GetData(prodId); if (res == "") { throw new Exception("Item not found..."); } string[] val = res.Split('%'); //Converting string array to List using LINQ query// var recs = (from data in val select data).ToList(); productNameTextBox.Text = recs[0]; categoryTextBox.Text = recs[1]; itemPriceTextBox.Text = recs[2]; noOfItemsTextBox.Text = recs[3]; productNameTextBox.Enabled = false; categoryTextBox.Enabled = false; imageTextBox.Enabled = false; Image img = aProd.LoadImage(prodId); pictureBox.Image = img; } else { MessageBox.Show("Please enter the Product ID..", "Error"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } }
private void addProductButton_Click(object sender, EventArgs e) { try { EShoppingLibrary.Products aProd = new EShoppingLibrary.Products(); int prodId = Convert.ToInt32(productIdTextBox.Text); string productName = productNameTextBox.Text; string category = categoryTextBox.Text; double itemPrice = Convert.ToDouble(itemPriceTextBox.Text); int noOfItems = Convert.ToInt32(noOfItemsTextBox.Text); Image img = Image.FromFile(imageTextBox.Text); byte[] data; using (MemoryStream ms = new MemoryStream()) { img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); data = ms.ToArray(); } Product aProduct = new Product(prodId, productName, itemPrice, noOfItems, data, category); //Adding to Database int res = aProd.Add(prodId, productName, itemPrice, noOfItems, data, category); if (res == 1) { MessageBox.Show("Added to the database!"); } else { MessageBox.Show(aProd.LastError); } } catch (FormatException fe) { MessageBox.Show("Please enter all the fields..", "Error"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } }
public void frmHomePage_Load(object sender, EventArgs e) { EShoppingLibrary.Products aProduct = new EShoppingLibrary.Products(); int[] allIDs = aProduct.LoadProdIDs(); pictureBox1.Image = aProduct.LoadImage(allIDs[0]); pictureBox2.Image = aProduct.LoadImage(allIDs[1]); pictureBox3.Image = aProduct.LoadImage(allIDs[2]); pictureBox4.Image = aProduct.LoadImage(allIDs[3]); pictureBox5.Image = aProduct.LoadImage(allIDs[4]); pictureBox6.Image = aProduct.LoadImage(allIDs[5]); linkLabel1.Text = aProduct.LoadLabel(allIDs[0]); linkLabel2.Text = aProduct.LoadLabel(allIDs[1]); linkLabel3.Text = aProduct.LoadLabel(allIDs[2]); linkLabel4.Text = aProduct.LoadLabel(allIDs[3]); linkLabel5.Text = aProduct.LoadLabel(allIDs[4]); linkLabel6.Text = aProduct.LoadLabel(allIDs[5]); }
private void updateStockButton_Click(object sender, EventArgs e) { if (productNameTextBox.Enabled == false) { EShoppingLibrary.Products aProd = new EShoppingLibrary.Products(); double newPrice = Convert.ToDouble(itemPriceTextBox.Text); int newStock = Convert.ToInt32(noOfItemsTextBox.Text); int prodID = Convert.ToInt32(productIdTextBox.Text); int res = aProd.UpdateProduct(newPrice, newStock, prodID); if (res == 1) { MessageBox.Show("Update Successful..."); } else { MessageBox.Show(aProd.LastError, "Error"); } } }
private void addProductButton_Click(object sender, EventArgs e) { try { EShoppingLibrary.Products aProd = new EShoppingLibrary.Products(); int prodId = Convert.ToInt32(productIdTextBox.Text); string productName = productNameTextBox.Text; string category = categoryTextBox.Text; double itemPrice = Convert.ToDouble(itemPriceTextBox.Text); int noOfItems = Convert.ToInt32(noOfItemsTextBox.Text); Image img = Image.FromFile(imageTextBox.Text); byte[] data; using (MemoryStream ms = new MemoryStream()) { img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); data = ms.ToArray(); } Product aProduct = new Product(prodId, productName, itemPrice, noOfItems, data, category); //Adding to Database int res = aProd.Add(prodId, productName, itemPrice, noOfItems, data, category); if (res == 1) MessageBox.Show("Added to the database!"); else MessageBox.Show(aProd.LastError); } catch (FormatException fe) { MessageBox.Show("Please enter all the fields..", "Error"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } }
private void placeOrderButton_Click(object sender, EventArgs e) { int count = 0; int cartCount = cartDataGridView.RowCount; if (cartCount != 0) { int quanCount = 0; foreach (double val in totalPrice) if (val != 0) quanCount++; if (cartCount == quanCount) { EShoppingLibrary.Products aProd = new EShoppingLibrary.Products(); foreach (DataGridViewRow row in cartDataGridView.Rows) { string name = row.Cells[0].Value.ToString(); int noOfItems = Convert.ToInt32(row.Cells[2].Value); //MessageBox.Show(":" + name + ":" + noOfItems.ToString() + ":"); int res = aProd.DecrementStock(name, noOfItems); if (res == 1) count++; else { MessageBox.Show(aProd.LastError, "Error"); clearCartButton_Click(sender, e); break; } if (count == cartCount) { MessageBox.Show("Your order has been successfully placed.."); clearCartButton_Click(sender, e); totalLabel.Text = ""; Product.allProducts.Clear(); } } } else MessageBox.Show("Please select the quantity..."); } else MessageBox.Show("Your Cart is empty..."); }
private void updateStockButton_Click(object sender, EventArgs e) { if (productNameTextBox.Enabled == false) { EShoppingLibrary.Products aProd = new EShoppingLibrary.Products(); double newPrice = Convert.ToDouble(itemPriceTextBox.Text); int newStock = Convert.ToInt32(noOfItemsTextBox.Text); int prodID = Convert.ToInt32(productIdTextBox.Text); int res = aProd.UpdateProduct(newPrice, newStock, prodID); if (res == 1) MessageBox.Show("Update Successful..."); else MessageBox.Show(aProd.LastError, "Error"); } }
private void viewProductButton_Click(object sender, EventArgs e) { try { if (productIdTextBox.Text.Trim() != "") { int prodId = Convert.ToInt32(productIdTextBox.Text); EShoppingLibrary.Products aProd = new EShoppingLibrary.Products(); string res = aProd.GetData(prodId); if (res == "") throw new Exception("Item not found..."); string[] val = res.Split('%'); //Converting string array to List using LINQ query// var recs = (from data in val select data).ToList(); productNameTextBox.Text = recs[0]; categoryTextBox.Text = recs[1]; itemPriceTextBox.Text = recs[2]; noOfItemsTextBox.Text = recs[3]; productNameTextBox.Enabled = false; categoryTextBox.Enabled = false; imageTextBox.Enabled = false; Image img = aProd.LoadImage(prodId); pictureBox.Image = img; } else MessageBox.Show("Please enter the Product ID..", "Error"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } }