private void btnMultiply_Click(object sender, EventArgs e) { int index; try { bool b = int.TryParse(lvProduct.SelectedIndices[0].ToString(), out index); if (b) { var cost = lvProduct.Items[index].SubItems[2].Text; var quantity = lvProduct.Items[index].SubItems[3].Text; var sku = lvProduct.Items[index].SubItems[5].Text; UpdateQuantity updateQuantity = new UpdateQuantity(Double.Parse(quantity), Double.Parse(cost), sku, index, lvProduct, lblTotal, txtSearch); updateQuantity.Show(); } } catch (Exception) { index = 0; MessageBox.Show("Please select an item to update."); } }
private void search(string productName) { try { bool isOutOfStock = ProductRepo.checkProductQuantity(productName); if (isOutOfStock) { MessageBox.Show("This product is out of stock."); txtSearch.Clear(); } else { var product = ProductRepo.retrieve(productName); if (product.Count > 0) { lblDescription.Text = product[0].ProductDescription; lblQuantity.Text = product[0].ProductQuantity.ToString(); lblBarcode.Text = product[0].ProductBarcode.ToString(); lblCategory.Text = product[0].ProductCategories; string productImagePath = AssemblyDirectory + @"\Image\ProductImages\" + product[0].ProductImage; string barcodeImagePath = AssemblyDirectory + @"\Image\BarcodeImages\" + product[0].ProductBarcodeImage; if (File.Exists(productImagePath)) { pbProductImage.Image = Image.FromFile(productImagePath); } if (File.Exists(barcodeImagePath)) { pbProductBarcode.Image = Image.FromFile(barcodeImagePath); } lblName.Text = product[0].ProductName.ToString(); lblQuantity.Text = product[0].ProductQuantity.ToString(); lblSKU.Text = product[0].ProductSku.ToString(); lblSubCategory.Text = product[0].ProductSubCategories; lblUnitCost.Text = product[0].ProductUnitCost.ToString(); lblMeasurement.Text = product[0].ProductUnitOfMeasurement; lblAttribute.Text = ""; foreach (var item in product[0].ProductAttributes) { lblAttribute.Text = lblAttribute.Text + item.AttributeName + ": " + item.AttributeValue + "\n"; }//shows product attributes bool productExistOnList = false; if (lvProduct.Items.Count > 0) { for (int i = 0; i < lvProduct.Items.Count; i++)//loops through each product on the list { var name = lvProduct.Items[i].SubItems[0].Text; var desc = lvProduct.Items[i].SubItems[1].Text; var sku = lvProduct.Items[i].SubItems[6].Text; var quantity = lvProduct.Items[i].SubItems[3].Text; var cost = lvProduct.Items[i].SubItems[2].Text; if (name == product[0].ProductName && desc == product[0].ProductDescription && sku == product[0].ProductSku)//if product is found update quantity { DialogResult result = MessageBox.Show("Product with name " + product[0].ProductName + " already exist on the list, \n do you wish to update quantity?", "Product Exist on the List", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { productExistOnList = true; lblTotal.Text = "0.00"; UpdateQuantity multiplyQuantity = new UpdateQuantity(Double.Parse(quantity), Double.Parse(cost), sku, i, lvProduct, lblTotal, txtSearch); multiplyQuantity.Show(); } else { productExistOnList = true; } } } //end of for loop if (productExistOnList == false) { var quantity1 = 1; var unitCost = product[0].ProductUnitCost; var subTotal = quantity1 * unitCost; ListViewItem item1 = new ListViewItem(product[0].ProductName); item1.SubItems.Add(product[0].ProductDescription); item1.SubItems.Add((unitCost).ToString()); item1.SubItems.Add((quantity1).ToString()); item1.SubItems.Add(product[0].ProductUnitOfMeasurement); item1.SubItems.Add((subTotal).ToString()); item1.SubItems.Add((product[0].ProductSku).ToString()); item1.SubItems.Add((product[0].ProductBarcode).ToString()); item1.SubItems.Add((product[0].ProductCategories)); item1.SubItems.Add((product[0].ProductSubCategories).ToString()); item1.SubItems.Add((product[0].ProductAttributes).ToString()); item1.SubItems.Add((product[0].ProductImage).ToString()); item1.SubItems.Add((product[0].ProductBarcodeImage).ToString()); item1.SubItems.Add(product[0].ProductId.ToString()); item1.SubItems.Add(product[0].ProductQuantity.ToString()); lvProduct.Items.Add(item1); lblTotal.Text = "0.00"; int count = lvProduct.Items.Count; for (int indexTotal = 0; indexTotal < count; indexTotal++)//updates subTotal { lblTotal.Text = (double.Parse(lblTotal.Text) + double.Parse(lvProduct.Items[indexTotal].SubItems[5].Text)).ToString(); } txtSearch.Clear(); } txtSearch.Clear(); } else { var quantity = 1; var unitCost = product[0].ProductUnitCost; var subTotal = quantity * unitCost; ListViewItem item1 = new ListViewItem(product[0].ProductName); item1.SubItems.Add(product[0].ProductDescription); item1.SubItems.Add((unitCost).ToString()); item1.SubItems.Add((quantity).ToString()); item1.SubItems.Add(product[0].ProductUnitOfMeasurement); item1.SubItems.Add((subTotal).ToString()); item1.SubItems.Add((product[0].ProductSku).ToString()); item1.SubItems.Add((product[0].ProductBarcode).ToString()); item1.SubItems.Add((product[0].ProductCategories)); item1.SubItems.Add((product[0].ProductSubCategories).ToString()); item1.SubItems.Add((product[0].ProductAttributes).ToString()); item1.SubItems.Add((product[0].ProductImage).ToString()); item1.SubItems.Add((product[0].ProductBarcodeImage).ToString()); item1.SubItems.Add(product[0].ProductId.ToString()); item1.SubItems.Add(product[0].ProductQuantity.ToString()); lvProduct.Items.Add(item1); lblTotal.Text = "0.00"; int count = lvProduct.Items.Count; for (int indexTotal = 0; indexTotal < count; indexTotal++)//updates subTotal { lblTotal.Text = (double.Parse(lblTotal.Text) + double.Parse(lvProduct.Items[indexTotal].SubItems[5].Text)).ToString(); } txtSearch.Clear(); } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }