示例#1
0
        /// <summary>
        /// Contains the behavior after the complete order button is pressed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OnCancelOrderButtonClicked(object sender, RoutedEventArgs e)
        {
            this.DataContext = new Order();
            var screen = new MenuItemSelectionControl();

            SwapScreen(screen);
        }
示例#2
0
        /// <summary>
        /// Event handler for credit button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CreditButtonClicked(object sender, RoutedEventArgs e)
        {
            if (DataContext is Order order)
            {
                ResultCode result = CardTerminal.ProcessTransaction(order.Total);

                if (result != ResultCode.Success)
                {
                    OrderStatusLabel.Text = $"Order Status: {result.ToString()}";
                }
                else
                {
                    OrderControl orderControl = this.FindAncestor <OrderControl>();

                    if (orderControl != null)
                    {
                        MenuItemSelectionControl screen = new MenuItemSelectionControl();
                        orderControl.DataContext = new Order();
                        orderControl.SwapScreen(screen); // Switch screen
                        PrintReceipt(order, false, 0, 0);
                    }
                    else
                    {
                        throw new NullReferenceException();
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Sends the user back to the menu screen to fix any issues with the order
        /// </summary>
        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            var orderControl = this.FindAncestor <OrderControl>();
            MenuItemSelectionControl menu = new MenuItemSelectionControl();

            orderControl?.SwapScreen(menu);
        }
        private void OnCreditSelect(object sender, RoutedEventArgs e)
        {
            CardTerminal cardTerminal = new CardTerminal();
            double       total;

            if (DataContext is Order order)
            {
                total = order.Total;
                ResultCode result = cardTerminal.ProcessTransaction(total);
                if (result == ResultCode.Success)
                {
                    PrintRecipt(true);
                }
                if (result == ResultCode.ReadError)
                {
                    ReadErrorPopup.IsOpen = true;
                    return;
                }
                if (result == ResultCode.UnknownErrror)
                {
                    UnknownErrorPopup.IsOpen = true;
                    return;
                }
                if (result == ResultCode.InsufficentFunds)
                {
                    InsufficientFunds.IsOpen = true;
                    return;
                }
                var orderControl        = this.FindAncestor <OrderControl>();
                FrameworkElement screen = new MenuItemSelectionControl();
                orderControl.SwapScreen(screen);
                orderControl.CancelOrderButton_Click(this, e);
            }
        }
示例#5
0
        /// <summary>
        /// Create a cash drawer instance that will not change
        /// </summary>
        //public static CashDrawer CowBoyCashDrawer = new CashDrawer();


        /// <summary>
        /// Event handler for pay with card button
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">e</param>
        public void PayWithCard(object sender, RoutedEventArgs e)
        {
            CardTerminal terminal = new CardTerminal();

            var result = terminal.ProcessTransaction((Convert.ToDouble(TotalValue.Text)));


            if (result == ResultCode.Success)
            {
                PrintReciept(true);
                var orderControl        = this.FindAncestor <OrderControl>();
                FrameworkElement screen = new MenuItemSelectionControl();
                orderControl.SwapScreen(screen);
                orderControl.CancelOrderButton_Click(this, e);
            }
            else if (result == ResultCode.CancelledCard)
            {
                ErrorCodeDisplay.Text = "Card Canceled \nPlease try a different payment method";
            }
            else if (result == ResultCode.InsufficentFunds)
            {
                ErrorCodeDisplay.Text = "Insufficent Funds on Card\nPlease try a different payment method";
            }
            else if (result == ResultCode.ReadError)
            {
                ErrorCodeDisplay.Text = "Card Read Error \nPlease try a different payment method";
            }
            else if (result == ResultCode.UnknownErrror)
            {
                ErrorCodeDisplay.Text = "Unknown Error \nPlease try a different payment method";
            }
        }
        private void OnCancelSelect(object sender, RoutedEventArgs e)
        {
            var orderControl        = this.FindAncestor <OrderControl>();
            FrameworkElement screen = new MenuItemSelectionControl();

            orderControl.SwapScreen(screen);
            orderControl.CancelOrderButton_Click(this, e);
        }
示例#7
0
        /// <summary>
        /// a method which will find the ancestor when an event has been changed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EventChanged(object sender, RoutedEventArgs e)
        {
            var ancestor = this.FindAncestor <OrderControl>();

            if (ancestor is OrderControl)
            {
                ancestor.propChanged();
                var screen = new MenuItemSelectionControl();
                ancestor.SwapScreen(screen);
            }
        }
        private void DeleteBtn_Click(object sender, RoutedEventArgs e)
        {
            Order items = DataContext as Order;
            var   item  = (e.OriginalSource as FrameworkElement).DataContext;

            items.Remove(item as IOrderItem);
            var screen       = new MenuItemSelectionControl();
            var orderControl = this.FindAncestor <OrderControl>();

            orderControl?.SwapScreen(screen);
        }
示例#9
0
        private void RemoveButtonClick(object sender, RoutedEventArgs e)
        {
            var orderControl = this.FindAncestor <OrderControl>();
            var screen       = new MenuItemSelectionControl();

            if (DataContext is Order order)
            {
                var btn = sender as Button;
                order.Remove(btn.DataContext as IOrderItem);
                orderControl?.SwapScreen(screen);
            }
        }
 /// <summary>
 /// Button click event
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ButtClicked(object sender, RoutedEventArgs e)
 {
     if (sender is Button butt)
     {
         if (DataContext is Order ord)
         {
             ord.Remove((IOrderItem)butt.DataContext);
             var scr   = new MenuItemSelectionControl();
             var order = this.FindAncestor <OrderControl>();
             order.SwapScreen(scr);
         }
     }
 }
示例#11
0
        /// <summary>
        /// Handles the cancel button click and swaps the Container with the OrderControl.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CancelButtonClicked(object sender, RoutedEventArgs e)
        {
            var screen = new MenuItemSelectionControl();

            var orderControl = this.FindAncestor <OrderControl>();

            if (orderControl == null)
            {
                throw new Exception("An ancestor of OrderControl expected be an OrderControl instead of null");
            }

            orderControl.SwapScreen(screen);
            orderControl.DataContext = new Order();
        }
示例#12
0
        /// <summary>
        /// Finds the parent OrderControl of the calling button and
        /// swaps its current MenuItemSelectionControl/Customization
        /// screen with a new MenuItemSelectionControl screen.
        /// Then it finds the parent ListBox for the calling Button
        /// and removes the DataContext of the calling Button
        /// (which is an IOrderItem) from the DataContext
        /// of the parent ListBox.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnDeleteItem(object sender, RoutedEventArgs e)
        {
            // Find the parent OrderControl and swap its MenuItemSelectionControl/
            // Customization screen with a new MenuItemSelectionControl.
            var orderControlParent = (sender as Button).FindAncestor <OrderControl>();
            var newMenu            = new MenuItemSelectionControl();

            orderControlParent.SwapScreen(newMenu);

            // Find the parent listBox and remove the calling Button's DataContext
            // from the parent listBox's DataContext.
            var listBoxParent = (sender as Button).FindAncestor <ListBox>();

            ((Order)listBoxParent.DataContext).Remove(((sender as Button).DataContext as IOrderItem));
        }
示例#13
0
        /// <summary>
        /// A proxy event listener that passes on SelectionChanged events
        /// </summary>
        /// <param name="sender">The ListBox that had its selection changed</param>
        /// <param name="e">The event arguments</param>
        private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            FrameworkElement screen = null;
            IOrderItem       item   = (IOrderItem)((ListBox)sender).SelectedItem;
            var orderControl        = this.FindAncestor <OrderControl>();

            if (item != null)
            {
                screen = (FrameworkElement)item.Screen;
            }
            else
            {
                screen = new MenuItemSelectionControl();
            }

            orderControl?.SwapScreen(screen);
        }
        /// <summary>
        /// Switches the screen to the selected item in the order list
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OrderListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            FrameworkElement elem;
            IOrderItem       i = (IOrderItem)((ListBox)sender).SelectedItem;
            var orderControl   = this.FindAncestor <OrderControl>();

            //Weird base case here where if you delete the last item while the customization screen is still up it crashes and dies
            if (i != null)
            {
                elem = (FrameworkElement)i.Screen;
            }
            else
            {
                elem = new MenuItemSelectionControl();
            }

            orderControl?.SwapScreen(elem);
        }
示例#15
0
        /// <summary>
        /// finds the item and removes it from the order and sends screen back to menu item selection
        /// </summary>
        /// <param name="sender">button</param>
        /// <param name="e">event args</param>
        private void RemoveButtonClicked(object sender, RoutedEventArgs e)
        {
            var orderControl = this.FindAncestor <OrderControl>();

            if (orderControl == null)
            {
                return;
            }
            FrameworkElement screen = new MenuItemSelectionControl();

            if (DataContext is Order data)
            {
                if (sender is Button button)
                {
                    if (button.DataContext is IOrderItem item)
                    {
                        orderControl?.SwapScreen(screen);
                        data.Remove(item);
                    }
                }
            }
        }
示例#16
0
        /// <summary>
        /// Handles the credit button clicked, the card terminal instance then produces a code from the ProcessTransaction method a switch
        /// statement handles the ResultCode produced with a MessageBox that shows the appropriate message except for the ResultCode.Success which
        /// uses a StringBuilder to build a reciept using the order number, date and time, the list array of IOrderItem with the according prices
        /// and SpecialInstructions, the subtotal, total, and that credit used to pay for the transaction which is then printed by the
        /// RecieptPrinter instance. The container is then swapped back to the OrderControl.
        /// </summary>
        /// <param name="sender">The credit button</param>
        /// <param name="e">Event arguments</param>
        private void CreditButtonClicked(object sender, RoutedEventArgs e)
        {
            var        terminal  = new CardTerminal();
            string     totalText = TotalLabel.Text.Substring(1);
            double     total     = Convert.ToDouble(totalText);
            ResultCode code      = terminal.ProcessTransaction(total);

            switch (code)
            {
            case ResultCode.CancelledCard:
                MessageBox.Show("Cancelled Card.");
                break;

            case ResultCode.InsufficentFunds:
                MessageBox.Show("Card has insufficent funds.");
                break;

            case ResultCode.ReadError:
                MessageBox.Show("Card reader error.");
                break;

            case ResultCode.Success:
                var printer = new ReceiptPrinter();
                var sb      = new StringBuilder();
                var order   = DataContext as Order;
                sb.Append("Order " + order.OrderNumber.ToString() + "\n");
                sb.Append(DateTime.Today.ToString() + "\n");
                var list = OrderList.ItemsSource as IOrderItem[];
                foreach (IOrderItem item in list)
                {
                    sb.Append(item.ToString() + "\t\t" + item.Price.ToString("c") + "\n");
                    if (item.SpecialInstructions != null)
                    {
                        foreach (string instruction in item.SpecialInstructions)
                        {
                            sb.Append("\t" + instruction + "\n");
                        }
                    }
                }
                sb.Append("\nSubtotal:\t" + order.Subtotal.ToString("c") + "\n");
                sb.Append("Total:\t" + TotalLabel.Text + "\n");
                sb.Append("Credit\t" + TotalLabel.Text);
                printer.Print(sb.ToString());

                var screen = new MenuItemSelectionControl();

                var orderControl = this.FindAncestor <OrderControl>();
                if (orderControl == null)
                {
                    throw new Exception("An ancestor of OrderControl expected be an OrderControl instead of null");
                }

                orderControl.SwapScreen(screen);
                orderControl.DataContext = new Order();
                break;

            case ResultCode.UnknownErrror:
                MessageBox.Show("Unknown error occurred.");
                break;
            }
        }
示例#17
0
        /// <summary>
        /// Calculates change if there is change, the denomination of the change is then added to the appropriate bills or coins array with the
        /// change with the appropriate amount subtracted from the change variable and the appropriate the bill or coin removed from the drawer
        /// this will continue the change is 0. Then a StringBuilder builds the string used to the tell amount of change that needs to be given
        /// back to the customer. Then another StringBuilder is used to build the reciept using the order number, date and time, the list array of
        /// IOrderItem with the according prices and SpecialInstructions, the subtotal, total, the cash paid for the transaction, and the change
        /// given back which is then printed by the RecieptPrinter instance. The container is then swapped back to the OrderControl.
        /// </summary>
        /// <param name="change">Passed in amount of change</param>
        private void ChangeCalculator(int change)
        {
            double Change = change / 100.0;

            int[] bills = { 0, 0, 0, 0, 0, 0, 0 };
            int[] coins = { 0, 0, 0, 0, 0 };
            if (change > 0)
            {
                while (change > 0)
                {
                    if (change >= 10000 && drawer.GetBillQuantity(Bills.Hundred) > 0)
                    {
                        bills[0]++;
                        change -= 10000;
                        drawer.RemoveBill(Bills.Hundred, 1);
                    }
                    else if (change >= 5000 && drawer.GetBillQuantity(Bills.Fifty) > 0)
                    {
                        bills[1]++;
                        change -= 5000;
                        drawer.RemoveBill(Bills.Fifty, 1);
                    }
                    else if (change >= 2000 && drawer.GetBillQuantity(Bills.Twenty) > 0)
                    {
                        bills[2]++;
                        change -= 2000;
                        drawer.RemoveBill(Bills.Twenty, 1);
                    }
                    else if (change >= 1000 && drawer.GetBillQuantity(Bills.Ten) > 0)
                    {
                        bills[3]++;
                        change -= 1000;
                        drawer.RemoveBill(Bills.Ten, 1);
                    }
                    else if (change >= 500 && drawer.GetBillQuantity(Bills.Five) > 0)
                    {
                        bills[4]++;
                        change -= 500;
                        drawer.RemoveBill(Bills.Five, 1);
                    }
                    else if (change >= 200 && drawer.GetBillQuantity(Bills.Two) > 0)
                    {
                        bills[5]++;
                        change -= 200;
                        drawer.RemoveBill(Bills.Two, 1);
                    }
                    else if (change >= 100 && drawer.GetBillQuantity(Bills.One) > 0)
                    {
                        bills[6]++;
                        change -= 100;
                        drawer.RemoveBill(Bills.One, 1);
                    }
                    else if (change >= 50 && drawer.GetCoinQuantity(Coins.HalfDollar) > 0)
                    {
                        coins[0]++;
                        change -= 50;
                        drawer.RemoveCoin(Coins.HalfDollar, 1);
                    }
                    else if (change >= 25 && drawer.GetCoinQuantity(Coins.Quarter) > 0)
                    {
                        coins[1]++;
                        change -= 25;
                        drawer.RemoveCoin(Coins.Quarter, 1);
                    }
                    else if (change >= 10 && drawer.GetCoinQuantity(Coins.Dime) > 0)
                    {
                        coins[2]++;
                        change -= 10;
                        drawer.RemoveCoin(Coins.Dime, 1);
                    }
                    else if (change >= 5 && drawer.GetCoinQuantity(Coins.Nickel) > 0)
                    {
                        coins[3]++;
                        change -= 5;
                        drawer.RemoveCoin(Coins.Nickel, 1);
                    }
                    else if (change >= 1 && drawer.GetCoinQuantity(Coins.Nickel) > 0)
                    {
                        coins[4]++;
                        change -= 1;
                        drawer.RemoveCoin(Coins.Penny, 1);
                    }
                }
                StringBuilder changeList = new StringBuilder();
                changeList.Append("Give customer back:\n");
                if (bills[0] > 0)
                {
                    changeList.Append(bills[0].ToString() + " Hundred dollar bill(s)\n");
                }
                if (bills[1] > 0)
                {
                    changeList.Append(bills[1].ToString() + " Fifty dollar bill\n");
                }
                if (bills[2] > 0)
                {
                    changeList.Append(bills[2].ToString() + " Twenty dollar bill(s)\n");
                }
                if (bills[3] > 0)
                {
                    changeList.Append(bills[3].ToString() + " Ten dollar bill\n");
                }
                if (bills[4] > 0)
                {
                    changeList.Append(bills[4].ToString() + " Five dollar bill\n");
                }
                if (bills[5] > 0)
                {
                    changeList.Append(bills[5].ToString() + " Two dollar bill(s)\n");
                }
                if (bills[6] > 0)
                {
                    changeList.Append(bills[6].ToString() + " One dollar bill\n");
                }
                if (coins[0] > 0)
                {
                    changeList.Append(coins[0].ToString() + " Half-dollar\n");
                }
                if (coins[1] > 0)
                {
                    changeList.Append(coins[1].ToString() + " Quarter\n");
                }
                if (coins[2] > 0)
                {
                    changeList.Append(coins[2].ToString() + " Dime(s)\n");
                }
                if (coins[3] > 0)
                {
                    changeList.Append(coins[3].ToString() + " Nickel\n");
                }
                if (coins[4] > 0)
                {
                    changeList.Append(coins[4].ToString() + " Penny/Pennies\n");
                }
                MessageBox.Show(changeList.ToString() + "\n");
            }

            var printer = new ReceiptPrinter();
            var sb      = new StringBuilder();
            var order   = DataContext as Order;

            sb.Append("Order " + order.OrderNumber.ToString() + "\n");
            sb.Append(DateTime.Today.ToString() + "\n");
            foreach (IOrderItem item in list)
            {
                sb.Append(item.ToString() + "\t\t" + item.Price.ToString("c") + "\n");
                if (item.SpecialInstructions != null)
                {
                    foreach (string instruction in item.SpecialInstructions)
                    {
                        sb.Append("\t" + instruction + "\n");
                    }
                }
            }
            sb.Append("\nSubtotal:\t" + order.Subtotal.ToString("c") + "\n");
            sb.Append("Total:\t" + TotalLabel.Text + "\n");
            sb.Append("Cash\t" + TotalLabel.Text + "\n");
            sb.Append("Change\t" + Change.ToString("c"));
            printer.Print(sb.ToString());

            var screen = new MenuItemSelectionControl();

            var orderControl = this.FindAncestor <OrderControl>();

            if (orderControl == null)
            {
                throw new Exception("An ancestor of OrderControl expected be an OrderControl instead of null");
            }

            orderControl.SwapScreen(screen);
            orderControl.DataContext = new Order();
        }
示例#18
0
        /// <summary>
        /// takes in an item and finds the corresponding screen for it and then applies the context to it
        /// </summary>
        /// <param name="item">menu item</param>
        /// <returns>returns the screen with the context</returns>
        private FrameworkElement SwapScreenHelper(object item)
        {
            FrameworkElement screen = new MenuItemSelectionControl();

            if (item is AngryChicken)
            {
                screen             = new AngryChickenCustomization();
                screen.DataContext = item;
            }
            else if (item is CowpokeChili)
            {
                screen             = new CowpokeChiliCustomization();
                screen.DataContext = item;
            }
            else if (item is RustlersRibs)
            {
                screen             = new RustlersRibsCustomization();
                screen.DataContext = item;
            }
            else if (item is PecosPulledPork)
            {
                screen             = new PecosPulledPorkCustomization();
                screen.DataContext = item;
            }
            else if (item is TrailBurger)
            {
                screen             = new TrailBurgerCustomization();
                screen.DataContext = item;
            }
            else if (item is DakotaDoubleBurger)
            {
                screen             = new DakotaDoubleBurgerCustomization();
                screen.DataContext = item;
            }
            else if (item is TexasTripleBurger)
            {
                screen             = new TexasTripleBurgerCustomization();
                screen.DataContext = item;
            }
            else if (item is PanDeCampo)
            {
                screen             = new PanDeCampoCustomization();
                screen.DataContext = item;
            }
            else if (item is CornDodgers)
            {
                screen             = new CornDodgersCustomization();
                screen.DataContext = item;
            }
            else if (item is ChiliCheeseFries)
            {
                screen             = new ChiliCheeseFriesCustomization();
                screen.DataContext = item;
            }
            else if (item is BakedBeans)
            {
                screen             = new BakedBeansCustomization();
                screen.DataContext = item;
            }
            else if (item is JerkedSoda)
            {
                screen             = new JerkedSodaCustomization();
                screen.DataContext = item;
            }
            else if (item is CowboyCoffee)
            {
                screen             = new CowboyCoffeeCustomization();
                screen.DataContext = item;
            }
            else if (item is TexasTea)
            {
                screen             = new TexasTeaCustomization();
                screen.DataContext = item;
            }
            else if (item is Water)
            {
                screen             = new WaterCustomization();
                screen.DataContext = item;
            }
            return(screen);
        }
示例#19
0
        /// <summary>
        /// when the user is done customizing their order, this will take them back to the menu item selection screen
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OnItemSelectionButtonClicked(object sender, RoutedEventArgs e)
        {
            var screen = new MenuItemSelectionControl();

            SwapScreen(screen);
        }