コード例 #1
0
        private void Cbx_items_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                string tableNo = (Cbx_tables.SelectedItem as RestaurantTable).tableNo;

                MenuCard item = Cbx_items.SelectedItem as MenuCard;
                if (item != null && item.itemName != "Choose an Item")
                {
                    Random rnd = new Random();
                    Cbx_items.SelectedItem = item.itemName;
                    var    res            = (from p in App._menu where p.itemName == item.itemName select p).FirstOrDefault();
                    string formattedPrice = res.price.ToString();
                    formattedPrice.Replace('.', ',');
                    //double priceVal;

                    //if (double.TryParse(res.price, System.Globalization.NumberStyles.Float, germanCulture, out priceVal))
                    //{
                    //    double valInGermanFormat = priceVal;

                    //}
                    ObservableCollection <Order> orderList = new ObservableCollection <Order>(App._orders);
                    var list = (from o in orderList where o.table.tableNo == tableNo select o).FirstOrDefault();

                    if (list != null)
                    {
                        int itemId = rnd.Next(0, 99);
                        list.orderItems.Add(new OrderItems {
                            itemName = res.itemName, allergens = res.allergens, price = formattedPrice, totalQuantityPrice = formattedPrice, quantity = 1, itemId = itemId, category = res.category.ToString()
                        });
                        _orderList            = list;
                        Lbx_order.Visibility  = Visibility.Visible;
                        Lbx_order.ItemsSource = null;
                        Lbx_order.ItemsSource = _orderList.orderItems;
                    }
                    else
                    {
                        int itemId = rnd.Next(0, 99);
                        if (_orderList != null)
                        {
                            _orderList.orderItems.Add(new OrderItems {
                                itemName = res.itemName, allergens = res.allergens, price = formattedPrice, totalQuantityPrice = formattedPrice, quantity = 1, itemId = itemId, category = res.category.ToString()
                            });
                        }
                        else
                        {
                            int id = rnd.Next(0, 999);
                            _orderList = new Order {
                                id = id, orderedDate = DateTime.Now, table = new RestaurantTable {
                                    tableNo = tableNo
                                }, orderItems = new List <OrderItems> {
                                    new OrderItems {
                                        itemName = res.itemName, allergens = res.allergens, price = formattedPrice, totalQuantityPrice = formattedPrice, quantity = 1, category = res.category.ToString()
                                    }
                                }
                            };
                        }
                        Lbx_order.Visibility  = Visibility.Visible;
                        Lbx_order.ItemsSource = null;
                        Lbx_order.ItemsSource = _orderList.orderItems;
                    }
                }

                this.DataContext = _orderList;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.InnerException);
            }
        }
コード例 #2
0
        private void Lbx_items_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string   tableNo = (Cbx_tables.SelectedItem as RestaurantTable).tableNo;
            MenuCard item    = Lbx_items.SelectedItem as MenuCard;

            if (item != null)
            {
                Random rnd = new Random();
                Tbx_searchItem.Text = item.itemName;
                var    res            = (from p in _menuCard where p.itemName == item.itemName select p).FirstOrDefault();
                int    itemId         = rnd.Next(0, 99);
                string formattedPrice = res.price.ToString();
                formattedPrice.Replace('.', ',');
                if (App._orders.Count == 0)
                {
                    if (_orderList == null)
                    {
                        int id = rnd.Next(0, 999);
                        _orderList = new Order {
                            id = id, orderedDate = DateTime.Now, table = new RestaurantTable {
                                isIndoor = false, isBooked = true, tableNo = "3"
                            }, waiterId = 3, orderItems = new List <OrderItems> {
                                new OrderItems {
                                    itemName = res.itemName, allergens = res.allergens, price = formattedPrice, totalQuantityPrice = formattedPrice, quantity = 1, itemId = itemId, category = res.category.ToString()
                                }
                            }
                        };
                    }
                    else
                    {
                        _orderList.orderItems.Add(new OrderItems {
                            itemName = res.itemName, allergens = res.allergens, price = formattedPrice, totalQuantityPrice = formattedPrice, quantity = 1, itemId = itemId, category = res.category.ToString()
                        });
                    }

                    var updatedOrdr = _orderList.orderItems;
                    Lbx_order.ItemsSource = null;
                    Lbx_order.ItemsSource = updatedOrdr;
                }
                else
                {
                    ObservableCollection <Order> orderList = new ObservableCollection <Order>(App._orders);
                    _orderList = (from o in orderList where o.table.tableNo == Cbx_tables.SelectedItem.ToString() select o).FirstOrDefault();
                    if (_orderList != null)
                    {
                        _orderList.orderItems.Add(new OrderItems {
                            itemName = res.itemName, allergens = res.allergens, price = formattedPrice, totalQuantityPrice = formattedPrice, quantity = 1, itemId = itemId, category = res.category.ToString()
                        });
                        var updatedOrdr = _orderList.orderItems;
                    }
                    else
                    {
                        int id = rnd.Next(0, 999);


                        _orderList = new Order {
                            id = id, orderedDate = DateTime.Now, table = new RestaurantTable {
                                isIndoor = false, isBooked = true, tableNo = "3"
                            }, waiterId = 3, orderItems = new List <OrderItems> {
                                new OrderItems {
                                    itemName = res.itemName, allergens = res.allergens, price = formattedPrice, totalQuantityPrice = formattedPrice, quantity = 1, itemId = itemId, category = res.category.ToString()
                                }
                            }
                        };
                    }
                    Lbx_order.Visibility  = Visibility.Visible;
                    Lbx_order.ItemsSource = null;
                    Lbx_order.ItemsSource = _orderList.orderItems;
                }
            }
            this.DataContext = _orderList;
        }