Beispiel #1
0
        private void SubmitOrder(object sender, RoutedEventArgs e)
        {
            OnMyWayDatabase OnMyWayDb          = new OnMyWayDatabase();
            var             TableSelectedQuery = (from t in OnMyWayDb.TableSelecteds
                                                  where t.Id == 1
                                                  select t).FirstOrDefault();

            if (TableSelectedQuery.TableId != 0)
            {
                Dishe  Adishe        = new Dishe();
                string OrderedDishes = "";
                for (int i = 0; i < AvailableDishesListView.SelectedItems.Count; i++)
                {
                    Adishe         = (Dishe)AvailableDishesListView.SelectedItems[i];
                    OrderedDishes += Adishe.DisheId + ",";
                }
                var GetSelectedTableQuery = (from t in OnMyWayDb.Tables
                                             where t.TableId == TableSelectedQuery.TableId
                                             select t).FirstOrDefault();
                GetSelectedTableQuery.TableStatus = "Eating";
                GetSelectedTableQuery.DisheList   = OrderedDishes;
                OnMyWayDb.SaveChanges();
                PushMsg("Ordered Dishes", "Selected dishes have been set for table: " + TableSelectedQuery.TableId);
            }
            else
            {
                PushMsg("No Table Selected", "Please select a table for the order.");
            }
        }
        private void EventDeleteDishes(object sender, RoutedEventArgs e)
        {
            OnMyWayDatabase OnMyWayDb = new OnMyWayDatabase();
            Dishe           Adishe    = new Dishe();
            bool            CanCommit = false;

            for (int i = 0; i < DishesDataGrid.SelectedItems.Count; i++)
            {
                if (CanCommit == false)
                {
                    CanCommit = true;
                }
                Adishe = (Dishe)DishesDataGrid.SelectedItems[i];
                var GetDishesQuery = from d in OnMyWayDb.Dishes
                                     where d.DisheId == Adishe.DisheId
                                     select d;
                foreach (Dishe dishe in GetDishesQuery)
                {
                    OnMyWayDb.Dishes.Remove(dishe);
                }
            }
            if (CanCommit == true)
            {
                OnMyWayDb.SaveChanges();
                PushMsg("Dishe Deleted", "Selected dishes was successfully Deleted.");
                ShowDishes();
            }
        }
        private void EventUpdateDishes(object sender, RoutedEventArgs e)
        {
            OnMyWayDatabase OnMyWayDb = new OnMyWayDatabase();
            Dishe           Adishe    = new Dishe();
            bool            CanCommit = false;

            for (int i = 0; i < DishesDataGrid.Items.Count; i++)
            {
                if (CanCommit == false)
                {
                    CanCommit = true;
                }
                Adishe = (Dishe)DishesDataGrid.Items[i];
                var GetDishesQuery = (from d in OnMyWayDb.Dishes
                                      where d.DisheId == Adishe.DisheId
                                      select d).FirstOrDefault();
                GetDishesQuery.DisheName        = Adishe.DisheName;
                GetDishesQuery.DisheDescription = Adishe.DisheDescription;
                GetDishesQuery.DishePrice       = Adishe.DishePrice;
            }
            if (CanCommit == true)
            {
                OnMyWayDb.SaveChanges();
                PushMsg("Dishes Saved", "All changes to dishes have been saved.");
                ShowDishes();
            }
        }
        private void AddDishe(object sender, RoutedEventArgs e)
        {
            Dishe NewDishe  = new Dishe();
            bool  CanCommit = false;

            if (DisheNameTextBox.Text.Length != 0)
            {
                NewDishe.DisheName = DisheNameTextBox.Text;
                if (DisheDescriptionTextBox.Text.Length != 0)
                {
                    NewDishe.DisheDescription = DisheDescriptionTextBox.Text;
                    if (DishePriceTextBox.Text.Length != 0)
                    {
                        try
                        {
                            NewDishe.DishePrice = double.Parse(DishePriceTextBox.Text);
                            CanCommit           = true;
                        }
                        catch
                        {
                            PushMsg("Price Error", "Invalid price input!");
                        }
                    }
                    else
                    {
                        PushMsg("Price Error", "Dishe needs a price!");
                    }
                }
                else
                {
                    PushMsg("Description Error", "Dishe needs a description!");
                }
            }
            else
            {
                PushMsg("Name Error", "Dishe needs a name!");
            }
            if (CanCommit == true)
            {
                OnMyWayDatabase OnMyWayDb = new OnMyWayDatabase();
                OnMyWayDb.Dishes.Add(NewDishe);
                OnMyWayDb.SaveChanges();
                PushMsg("Dishe Added", "Dishe was successfully added.\n\nPlease refresh Admin Panel to view changes.");
            }
        }