コード例 #1
0
        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();
            }
        }
コード例 #2
0
        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;
        }
コード例 #3
0
        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();
            }
        }