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 linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { Product aProd = new Product(); string label = linkLabel2.Text; string[] val = label.Split(new string[] { " " }, StringSplitOptions.None); string name = val[0]; double price = Convert.ToDouble(val[1].Substring(1)); int stock = Convert.ToInt32(val[2].Split(' ')[0]); aProd.ItemName = name; aProd.ItemPrice = price; aProd.Stock = stock; if (aProd.Stock == 0) MessageBox.Show("Item not available right now..."); else { Product.allProducts.Add(aProd); MessageBox.Show("Item added to cart..."); } }