private void RemoveButton_Click(object sender, EventArgs e) { int ID; if (int.TryParse(ProductID.Text, out ID)) { if (_PHPRepo.VerifyProductID(ID)) { _PHPRepo.GetProductbyId(ID); Product _Product = _PHPRepo.GetProductbyId(ID); _PHPRepo.deleteProduct(_Product); MessageBox.Show("Product has been deleted ", "Sucessful", MessageBoxButtons.OK, MessageBoxIcon.None); StockList.Items.Clear(); List <Product> _NewList = _PHPRepo.GetProducts(); foreach (Product p in _NewList) { string[] row = { p.ProductId.ToString(), p.Product_Name.ToString(), p.Price.ToString(), p.Stock_Level.ToString() }; var listViewItem = new ListViewItem(row); StockList.Items.Add(listViewItem); } ; ProductID.Clear(); } else { MessageBox.Show("Could not find item: " + ID); } } else { MessageBox.Show("Please enter a valid ID"); } }
private void SearchButton_Click(object sender, EventArgs e) { ProductTable.Items.Clear(); if (_PHPRepo.GetProductbyId(prodID) == null) { MessageBox.Show("Could not find sale", "Search Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); DisplayProducts(); } else { _product = _PHPRepo.GetProductbyId(prodID); AddProductToTable(_product); } }
public void AddSale() { Sale sale = new Sale(); bool addProduct = true; sale.Sale_Date = DateTime.Now; Console.WriteLine("new Sale entry"); Console.WriteLine("AddProducts from list or enter to exit :"); Console.WriteLine("Avaliable Products : "); Console.WriteLine(JsonConvert.SerializeObject(_phpRepo.GetProducts())); double cost = 0; while (addProduct) { string input = Console.ReadLine(); if (string.IsNullOrEmpty(input)) { addProduct = false; break; } Product product = _phpRepo.GetProductbyId(int.Parse(input)); if (!(product == default)) { ProductSale productSale = new ProductSale(); productSale.Product = product; cost = cost + product.Price; sale.ProductSales.Add(productSale); }
public void DeleteProduct() { Console.WriteLine("Select product to delete : "); ListProducts(); int id = int.Parse(Console.ReadLine()); var productToDelete = _phpRepo.GetProductbyId(id); _phpRepo.deleteProduct(productToDelete); }
private void SearchButton_Click(object sender, EventArgs e) { LowStockTable.Items.Clear(); if (_PHPRepo.GetProductbyId(prodID) == null || textBox1.Text == "") { MessageBox.Show("Please enter a valid product ID.", "Search Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); DisplayLowStock(); textBox1.Text = ""; } else { _product = _PHPRepo.GetProductbyId(prodID); if (_lowStockList.Contains(_product)) { AddProductToTable(_product); } else { MessageBox.Show("This product has not been flagged for low stock.", "Search Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); DisplayLowStock(); textBox1.Text = ""; } } }
private void SearchButton_Click(object sender, EventArgs e) { int Id; if (int.TryParse(ID.Text, out Id)) { if (_PHPRepo.GetProductbyId(Id) == null) { MessageBox.Show("Could not find Product", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { StockList.Items.Clear(); Product_Name.Enabled = true; Product_Stock.Enabled = true; Product_Price.Enabled = true; _Product = _PHPRepo.GetProductbyId(Id); StockList.Items.Clear(); string[] row = { _Product.ProductId.ToString(), _Product.Product_Name.ToString(), _Product.Price.ToString(), _Product.Stock_Level.ToString() }; var listViewItem = new ListViewItem(row); StockList.Items.Add(listViewItem); Product_ID.Text = _Product.ProductId.ToString(); Product_Name.Text = _Product.Product_Name.ToString(); Product_Stock.Text = _Product.Stock_Level.ToString(); Product_Price.Text = _Product.Price.ToString(); } ID.Clear(); } else { MessageBox.Show("Please inter a valid ID"); } }
/// <summary> /// Validates that all fields have been completed successfully before saving and /// continuing. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveButton_Click_1(object sender, EventArgs e) { //checks if all fields are completed if (!string.IsNullOrEmpty(CustomerNameInput.Text) && row1Complete()) { _sale.SaleId = SaleID; _sale.Sale_Date = DateTime.Now; _sale.Customer_Name = CustomerNameInput.Text; _sale.Total_Cost = saleTotal; //generate row1 product Product product1 = _PHPRepo.GetProductbyId(Int32.Parse(prodIDinput1.Text)); if (product1 != null) { _sale.ProductSales.Add(new ProductSale() { Product = product1, Quantity = Int32.Parse(QtyInput1.Text) }); } //TODO: pass this product to relevant db, reduce stock count if (row2Complete()) { //generate row2 product Product product2 = _PHPRepo.GetProductbyId(Int32.Parse(prodIDinput2.Text)); if (product2 != null) { _sale.ProductSales.Add(new ProductSale() { Product = product2, Quantity = Int32.Parse(QtyInput2.Text) }); } } if (row3Complete()) { //generate row3 product Product product3 = _PHPRepo.GetProductbyId(Int32.Parse(prodIDinput3.Text)); if (product3 != null) { _sale.ProductSales.Add(new ProductSale() { Product = product1, Quantity = Int32.Parse(QtyInput3.Text) }); } } if (row4Complete()) { //generate row4 product Product product4 = _PHPRepo.GetProductbyId(Int32.Parse(prodIDinput4.Text)); if (product4 != null) { _sale.ProductSales.Add(new ProductSale() { Product = product4, Quantity = Int32.Parse(QtyInput4.Text) }); } } if (row5Complete()) { //generate row5 product Product product5 = _PHPRepo.GetProductbyId(Int32.Parse(prodIDinput5.Text)); if (product5 != null) { _sale.ProductSales.Add(new ProductSale() { Product = product5, Quantity = Int32.Parse(QtyInput5.Text) }); } } _PHPRepo.AddSalesRecord(_sale); MessageBox.Show("Transaction recorded successfully."); } else { MessageBox.Show("Please complete all fields before trying to save."); //TODO: Highlight or pinpoint which field is incomplete } }