private void AddToInventory(object sender, RoutedEventArgs e) { if (ProductBox.SelectedItem != null) { ListBoxItem selectedItem = (ListBoxItem)ProductBox.SelectedItem; ProductServiceReference.ProductServiceClient ProductServiceProxy = new ProductServiceReference.ProductServiceClient(); Product product = ProductServiceProxy.Find(int.Parse(selectedItem.DataContext.ToString())); foreach (ListBoxItem item in InventoryBox.Items) { if (int.Parse(item.DataContext.ToString()) == product.Id) { item.Content = product.Name + ", " + (int.Parse(item.Content.ToString().Split(',').Last().Trim()) + 1); } } if (InventoryBox.Items.Cast <ListBoxItem>().Where(item => int.Parse(item.DataContext.ToString()) == product.Id).Count() <= 0) { ListBoxItem Item = new ListBoxItem { Content = product.Name + ", 1", DataContext = product.Id }; InventoryBox.Items.Add(Item); } this.SetRemainingBalance(); } }
private void LoadProducts() { ProductBox.Items.Clear(); ProductServiceReference.ProductServiceClient ProductServiceProxy = new ProductServiceReference.ProductServiceClient(); Product[] products = ProductServiceProxy.All(); foreach (Product product in products) { ListBoxItem Item = new ListBoxItem { Content = product.Name + ": \u20AC" + Math.Truncate(product.Price * 100) / 100 + " Vooraad: " + product.Stock, DataContext = product.Id }; ProductBox.Items.Add(Item); } }
private void SetRemainingBalance() { ProductServiceReference.ProductServiceClient ProductServiceProxy = new ProductServiceReference.ProductServiceClient(); CustomerServiceReference.CustomerServiceClient customerServiceProxy = new CustomerServiceReference.CustomerServiceClient(); double price = 0; foreach (ListBoxItem item in InventoryBox.Items) { Product product = ProductServiceProxy.Find(int.Parse(item.DataContext.ToString())); price += product.Price * int.Parse(item.Content.ToString().Split(',').Last().Trim()); } int customerId = Int16.Parse(Application.Current.Resources["CUSTOMER_ID"].ToString()); RemainingBalance.Content = customerServiceProxy.Find(customerId).Balance - price; }
private void RemoveFromInventory(object sender, RoutedEventArgs e) { if (ProductBox.SelectedItem != null) { ListBoxItem selectedItem = (ListBoxItem)InventoryBox.SelectedItem; if (int.Parse(selectedItem.Content.ToString().Split(',').Last().Trim()) <= 1) { InventoryBox.Items.Remove(selectedItem); } else { ProductServiceReference.ProductServiceClient ProductServiceProxy = new ProductServiceReference.ProductServiceClient(); Product product = ProductServiceProxy.Find(int.Parse(selectedItem.DataContext.ToString())); selectedItem.Content = product.Name + ", " + (int.Parse(selectedItem.Content.ToString().Split(',').Last().Trim()) - 1); } this.SetRemainingBalance(); } }