private void btn_save_Click(object sender, RoutedEventArgs e) { if (txt_Name.Text == "" || txt_ProductDescription.Text == "" || txt_Price.Text == "" || txt_Stock.Text == "") { MessageBox.Show("Fill all the fields!"); return; } bool created = false; ProductService.ProductB product = new ProductService.ProductB(); product.ProductName = txt_Name.Text; product.ProductDescription = txt_ProductDescription.Text; product.Price = Decimal.Parse(txt_Price.Text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands | NumberStyles.AllowCurrencySymbol); product.Stock = Int32.Parse(txt_Stock.Text); created = prodClient.CreateProduct(product); if (created) { MessageBox.Show("The new product has been created!"); } else { MessageBox.Show("The name of the product already exists!"); return; } txt_Name.Text = ""; txt_ProductDescription.Text = ""; txt_Price.Text = ""; txt_Stock.Text = ""; txt_prodList.Items.Clear(); loadAllProducts(); }
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (listBox.SelectedItem != null) { prodSelect = (string)listBox.SelectedItem; productLine = prodClient.GetProductByName(prodSelect); txt_describtion.Text = productLine.ProductDescription; txt_price.Text = productLine.Price.ToString("0.00"); txt_stock.Text = productLine.Stock.ToString(); // txt_size.Text = prodSelect.Size; } }
private void btn_Remove_Click(object sender, RoutedEventArgs e) { if (removeOrderLine == null) { MessageBox.Show("You have to choose order line!"); return; } if (usernId == 0) { MessageBox.Show("You have to log in before manage order line!"); return; } int returnStock = 0; int idOfProduct = 0; for (int i = 0; i < orderLinesToOrder.Count; i++) { if (orderLinesToOrder[i].OrderLineId == idToRemoveOrderLine) { returnStock = orderLineClient.RemoveOrderLineAndReturnStock(idToRemoveOrderLine); idOfProduct = orderLinesToOrder[i].ProductID; orderLinesToOrder.RemoveAt(i); } } prodClient.ReturnStock(idOfProduct, returnStock); ProductService.ProductB pro = new ProductService.ProductB(); pro = prodClient.GetProduct(idOfProduct); totalPrice = totalPrice - (returnStock * pro.Price); listBox_OrderLines.Items.Clear(); foreach (OrderLineService.OrderLine ol in orderLinesToOrder) { string result = ""; var sb = new StringBuilder(); ProductService.ProductB prod = new ProductService.ProductB(); prod = prodClient.GetProduct(ol.ProductID); sb.Append(ol.OrderLineId + ". " + prod.ProductName + " " + ol.Quantity + "x" + prod.Price); result = sb.ToString(); listBox_OrderLines.Items.Add(result); result = ""; sb.Clear(); } txt_quntity.Text = ""; txt_stock.Text = ""; txt_price.Text = ""; txt_describtion.Text = ""; listBox.SelectedItem = null; }
private void txt_prodList_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (txt_prodList.SelectedItem != null) { prodSelect = (string)txt_prodList.SelectedItem; product = prodClient.GetProductByName(prodSelect); txt_Name.Text = product.ProductName; txt_Price.Text = product.Price.ToString(); txt_ProductDescription.Text = product.ProductDescription; txt_Stock.Text = product.Stock.ToString(); //txt_Size.Text = product.Size; } }
private void Button_Update(object sender, RoutedEventArgs e) { ProductService.ProductB productUpdated = new ProductService.ProductB(); productUpdated.ProductId = product.ProductId; productUpdated.ProductName = txt_Name.Text; productUpdated.Price = decimal.Parse(txt_Price.Text); productUpdated.Stock = Int32.Parse(txt_Stock.Text); productUpdated.ProductDescription = product.ProductDescription; //productUpdated.Size = product.Size; if (product.ProductName != Name) { if (!prodClient.CheckIfNameExists(txt_Name.Text)) { product.ProductName = txt_Name.Text; } else { MessageBox.Show("This name already exists!"); } } else { productUpdated.ProductName = txt_Name.Text; } bool updated = prodClient.UpdateProduct(productUpdated); if (updated) { MessageBox.Show("Product was updated!"); } else { MessageBox.Show("Something went wrong!"); } txt_prodList.Items.Clear(); loadAllProducts(); }
/* private void Button_Click(object sender, RoutedEventArgs e) * { * if (listBox.SelectedItem != null && txt_quntity.Text != null) * { * int quantity = Convert.ToInt32(txt_quntity.Text); * int minStock = Convert.ToInt32(txt_stock.Text); * if (quantity != 0 && quantity <= minStock) * { * int productID = productIndexes[listBox.SelectedIndex]; * orderClient.AddOrderLine(productID, quantity); * ListBoxItem listBoxItem = new ListBoxItem(); * string content = (listBox.Items[productID] as ListBoxItem).Content.ToString() + " x " + txt_quntity.Text; + listBoxItem.Content = content; + listBoxItem.Tag = productID; + listBox_OrderLines.Items.Add(listBoxItem); + } + } + }*/ private void Button_Add(object sender, RoutedEventArgs e) { if (prodSelect == null) { MessageBox.Show("You have to choose product!"); return; } if (txt_quntity.Text == "") { MessageBox.Show("You have to insert the quantity!"); return; } if (usernId == 0) { MessageBox.Show("You have to log in before make an order!"); return; } OrderLineService.OrderLine orderLine = new OrderLineService.OrderLine(); OrderLineService.OrderLine returnOrderLine = new OrderLineService.OrderLine(); int prodId = productLine.ProductId; int quantity = Int32.Parse(txt_quntity.Text); if (quantity > productLine.Stock) { MessageBox.Show("The quntity is more than the product stock!"); return; } prodClient.RemoveStockFromProduct(prodId, quantity); totalPrice += (quantity * productLine.Price); orderLine.Price = productLine.Price * quantity; orderLine.ProductID = prodId; orderLine.Quantity = quantity; returnOrderLine = orderLineClient.CreateOrderLine(orderLine); orderLinesToOrder.Add(returnOrderLine); listBox_OrderLines.Items.Clear(); foreach (OrderLineService.OrderLine ol in orderLinesToOrder) { string result = ""; var sb = new StringBuilder(); ProductService.ProductB prod = new ProductService.ProductB(); prod = prodClient.GetProduct(ol.ProductID); sb.Append(ol.OrderLineId + ". " + prod.ProductName + " " + ol.Quantity + "x" + prod.Price); result = sb.ToString(); listBox_OrderLines.Items.Add(result); result = ""; sb.Clear(); } txt_quntity.Text = ""; txt_stock.Text = ""; txt_price.Text = ""; txt_describtion.Text = ""; listBox.SelectedItem = null; }