예제 #1
0
 public MainWindow()
 {
     InitializeComponent();
     cashdrawer              = new CashDrawer();
     orderControl            = new OrderControl();
     screenHousingmain.Child = orderControl;
 }
        /// <summary>
        /// When the credit button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OnCreditButtonClicked(object sender, RoutedEventArgs e)
        {
            CardTerminal card   = new CardTerminal();
            Order        o      = (Order)DataContext;
            double       total  = o.Total;
            ResultCode   result = card.ProcessTransaction(total);

            if (result == ResultCode.Success)
            {
                ReceiptPrinter rp      = Register.ReceiptPrinter;
                String         reciept = ReceiptCreator();
                reciept += "\n\nPaid by Credit Card\n\n";
                reciept += DateTime.Now.ToString() + "\n\n";

                rp.Print(reciept);


                var          orderInfo = this.FindAncestor <OrderControl>();
                OrderControl od        = new OrderControl();
                orderInfo.SwapOrderSum(od);
            }
            else
            {
                MessageBox.Show(result.ToString());
            }
        }
예제 #3
0
        private void CreditCard_Clicked(object sender, RoutedEventArgs e)
        {
            CardTerminal ct     = new CardTerminal();
            ResultCode   result = ResultCode.UnknownErrror;
            string       name   = "Unknown Error";

            try
            {
                result = ct.ProcessTransaction(((Order)DataContext).Total);
                name   = Enum.GetName(typeof(ResultCode), result);
            }
            catch (DrawerOverdrawException)
            {
                MessageBox.Show("Card Over Drawn");
            }
            if (result != ResultCode.Success)
            {
                MessageBox.Show("Error " + name);
                return;
            }
            else if (result == ResultCode.Success)
            {
                MessageBox.Show("Error " + name);
                OrderControl parent = ((OrderControl)((Border)Parent).Parent);
                MainWindow   main   = (MainWindow)((Grid)(parent.Parent)).Parent;
                main.DataContext = new Order();
                Credit_print();
                parent.SwapScreen(null);
            }
        }
        /// <summary>
        /// When customer pays with credit, processes credit card.
        /// If processing is successful, prints the receipt and processes the payment, else the cashier is
        /// given the option to select pay with Cash or Credit or Cancel Transaction
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OnPayWithCreditButtonClicked(object sender, RoutedEventArgs e)
        {
            string cred = "Credit";
            // process transaction using instance of the CardTerminal class
            CardTerminal cardTerm = new CardTerminal();
            Order        o        = (Order)DataContext;
            // cardterminal class had one method - ProcessTransaction(amount to charge as double)
            // process transaction process card swiped and returns a resultcode enum value
            ResultCode result = cardTerm.ProcessTransaction(o.TotalWithTax);

            // result code is "Success" or "InsufficientFunds" "CancelledCard" "ReadError" "UnknownError"
            // if result is success you should finish order by printing receipt and return to ordering screen with new order object
            if (result == ResultCode.Success)
            {
                MessageBox.Show("Payment was a " + result.ToString() + "!");
                PrintTheReceipt(o, cred);
                var          orderInfo = this.FindAncestor <OrderControl>();
                OrderControl oc        = new OrderControl();
                orderInfo.SwapOrderSum(oc);
            }
            // if result is any error, inform user and display transaction screen s ocashier can attempt a different payment method
            else
            {
                MessageBox.Show("There was an error of type: " + result.ToString());
            }
        }
 /// <summary>
 /// Sets up the transaction control
 /// </summary>
 /// <param name="dc"></param>
 /// <param name="co"></param>
 public TransactionControl(CashDrawer dc, OrderControl co)
 {
     DataContext = this;
     InitializeComponent();
     cd                = dc;
     oc                = co;
     ord               = oc.DataContext as Order;
     Subtotal          = ord.Subtotal;
     Tax               = ord.Tax;
     Total             = ord.Total;
     CashPay.IsEnabled = false;
     LeftToPay         = Total;
     Items             = ord.Items;
     OrderNumber       = ord.OrderNumber;
     foreach (IOrderItem i in Items)
     {
         OrderList.Items.Add(i.ToString());
         PriceBox.Items.Add(i.Price.ToString("C2"));
         foreach (string s in i.SpecialInstructions)
         {
             OrderList.Items.Add(s);
             PriceBox.Items.Add("");
         }
     }
     PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Subtotal"));
     PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Tax"));
     PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Total"));
     PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Items"));
     PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("OrderNumber"));
     PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("LeftToPay"));
 }
        public TestTransControl(CashDrawer cd, OrderControl o)
        {
            DataContext = this;
            InitializeComponent();

            oc = o;
            Order or = (Order)o.DataContext;

            /* Cash should not be able to complete until enough has been received */
            CompleteCashButton.IsEnabled = false;

            /* Assign the cash drawer instance */
            this.cd = cd;

            /* Get the important stuff out of the order */
            PrevOrderNumber = or.OrderNumber;
            Items           = or.Items;

            /* Do some quick maffs */
            Subtotal     = or.Subtotal;
            Tax          = Subtotal * .16;
            TotalWithTax = Subtotal + Tax;

            /* How much do we need to charge the customer? */
            AmountLeftToTender = TotalWithTax;

            /* Let the xaml know that we updated properties */
            PopulateItemsStackPanel();
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Subtotal"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Tax"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("TotalWithTax"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("AmountLeftToTender"));
        }
예제 #7
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.ordercon = ((PointOfSale.OrderControl)(target));
                return;

            case 2:
                this.frame = ((System.Windows.Controls.Frame)(target));

            #line 18 "..\..\MainWindow.xaml"
                this.frame.LoadCompleted += new System.Windows.Navigation.LoadCompletedEventHandler(this.LoadCompleted);

            #line default
            #line hidden

            #line 19 "..\..\MainWindow.xaml"
                this.frame.DataContextChanged += new System.Windows.DependencyPropertyChangedEventHandler(this.DataContextChanged);

            #line default
            #line hidden
                return;
            }
            this._contentLoaded = true;
        }
        /// <summary>
        /// event handler for choosing to pay via credit
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnCreditPay(object sender, RoutedEventArgs e)
        {
            CardTerminal terminal = new CardTerminal();
            ResultCode   result   = terminal.ProcessTransaction(double.Parse(Total.Text));

            switch (result)
            {
            case ResultCode.CancelledCard:
                MessageBox.Show("Card Cancelled", "Transaction Failed");
                break;

            case ResultCode.InsufficentFunds:
                MessageBox.Show("Insufficient Funds", "Transaction Failed");
                break;

            case ResultCode.ReadError:
                MessageBox.Show("Card Read Error!", "Error");
                break;

            case ResultCode.Success:
                PrintReceipt(true, 0, 0);
                var          main         = this.FindAncestor <MainWindow>();
                OrderControl orderControl = new OrderControl(drawer);
                main.Display(orderControl);
                break;

            case ResultCode.UnknownErrror:
                MessageBox.Show("Unknown Error!", "Error");
                break;
            }
        }
예제 #9
0
        /// <summary>
        /// Constructor for MainWindow.
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            // Create the first order and set the DataContext to that order.
            var data = new Order();

            this.DataContext = data;

            // Initialize MainOrderControl, MainOrderTransactionControl, MainCollectCashFromCustomerControl,
            // MainModelViewCashRegister, MainGiveChangeToCustomerControl, MainSwapBillsForCoinsControl,
            // and MainManageRegisterDrawerControl.
            MainOrderControl                   = new OrderControl();
            MainOrderTransactionControl        = new OrderTransactionControl();
            MainCollectCashFromCustomerControl = new CollectCashFromCustomerControl();
            MainModelViewCashRegister          = new ModelViewCashRegister(new CashDrawer());
            MainGiveChangeToCustomerControl    = new GiveChangeToCustomerControl();
            MainSwapBillsForCoinsControl       = new SwapBillsForCoinsControl();
            MainManageRegisterDrawerControl    = new ManageRegisterDrawerControl();

            // Set the DataContext of MainCollectCashFromCustomerControl,
            // MainGiveChangeToCustomerControl,ManageRegisterDrawerControl,
            // and MainBillToCoinSwapControl to the MainModelViewCashRegister.
            MainCollectCashFromCustomerControl.DataContext = MainModelViewCashRegister;
            MainGiveChangeToCustomerControl.DataContext    = MainModelViewCashRegister;
            MainSwapBillsForCoinsControl.DataContext       = MainModelViewCashRegister;
            MainManageRegisterDrawerControl.DataContext    = MainModelViewCashRegister;


            // Add the orderControl as the child of this window.
            this.Content = MainOrderControl;
        }
        /// <summary>
        /// event handler to process when complete payment by cash
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void CompletePaymentByCash(object sender, RoutedEventArgs e)
        {
            var mainWindow = this.FindAncestor <MainWindow>();
            var screen     = new OrderControl();

            mainWindow.SwapScreen(screen);
        }
        /// <summary>
        /// This method creates a new Order and swaps the screen to a new OrderControl
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OnCancelTransactionClicked(object sender, RoutedEventArgs e)
        {
            var          orderInfo = this.FindAncestor <OrderControl>();
            OrderControl o         = new OrderControl();

            orderInfo.SwapOrderSum(o);
        }
예제 #12
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();
                    }
                }
            }
        }
예제 #13
0
        /// <summary>
        /// Handles click event on the Credit Card payment option button by instantiating an CardTerminal
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void CreditCardPaymentBtn_Clicked(object sender, RoutedEventArgs e)
        {
            CardTerminal terminal = new CardTerminal();
            double       total    = ((TransactionControl)ExtensionMethods.ExtensionMethods.FindAncestor <TransactionControl>(this)).Total;

            //Possible results from running total balance for order on terminal
            switch (terminal.ProcessTransaction(total))
            {
            case ResultCode.Success:
                CreditTransactionCompleted?.Invoke(this, new RoutedEventArgs());
                OrderControl oc = ExtensionMethods.ExtensionMethods.FindAncestor <OrderControl>(this);
                oc.DataContext = new Order();
                oc.CustomizationContainer.Child = new MenuItemSelectionControl();
                break;

            case ResultCode.InsufficentFunds:
                MessageBox.Show("Insufficient funds. Please submit another form of payment.");
                break;

            case ResultCode.CancelledCard:
                MessageBox.Show("Cancelled card. Please submit another form of payment.");
                break;

            case ResultCode.ReadError:
                MessageBox.Show("Read error. Please try again.");
                break;

            case ResultCode.UnknownErrror:
                MessageBox.Show("An error occurred. Please try again;");
                break;
            }
        }
예제 #14
0
        /// <summary>
        /// Handles order wpf when cancel button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CancelTransaction_Click(object sender, RoutedEventArgs e)
        {
            OrderControl newOrderControl = new OrderControl();

            newOrderControl.CompleteOrderButton.IsEnabled = true;
            newOrderControl.ItemSelectButton.IsEnabled    = true;
            Window.SwapScreen(newOrderControl);
        }
예제 #15
0
        private void CancelButtonClick(object sender, RoutedEventArgs e)
        {
            var orderControl = new OrderControl();

            var mainWindow = this.FindAncestor <MainWindow>();

            mainWindow.SwapScreenMain(orderControl);
        }
예제 #16
0
        /// <summary>
        /// Event handler for when the Cancel Order Button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CancelOrderButton_Click(object sender, RoutedEventArgs e)
        {
            var mainWindow   = this.FindAncestor <MainWindow>();
            var orderControl = new OrderControl();

            orderControl.DataContext         = new Order();
            mainWindow.WindowContainer.Child = orderControl;
        }
        /// <summary>
        /// event handler for choosing to cancel the order
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnCancelOrder(object sender, RoutedEventArgs e)
        {
            var          main         = this.FindAncestor <MainWindow>();
            OrderControl orderControl = new OrderControl(drawer);

            orderControl.DataContext = new Order();
            main.Display(orderControl);
        }
        private void CancelButtonClick(object sender, RoutedEventArgs e)
        {
            var orderControl = this.FindAncestor <OrderControl>();
            var screen       = new OrderControl();

            Order.OrderNumber++;
            orderControl.full.Child = screen;
        }
        /// <summary>
        /// Handles order wpf
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CancelTransaction(object sender, RoutedEventArgs e)
        {
            Window = this.FindAncestor <MainWindow>();
            OrderControl Order = new OrderControl();

            Order.CompleteOrderButton.IsEnabled = true;
            Order.ItemSelectButton.IsEnabled    = true;
            Window.SwapScreen(new OrderControl());
        }
예제 #20
0
        public ChangeView(OrderControl orderC, double change)
        {
            InitializeComponent();
            orderControl           = orderC;
            ChangeDisplayText.Text = String.Format("Resulting Change: {0:C}", change);
            ReceiptPrinter receiptPrinter = new ReceiptPrinter();

            receiptPrinter.Print(ReceiptBuilder(change));
        }
예제 #21
0
 /// <summary>
 /// initalizes xaml, adds the order control, clears the drawer, add's the listener, and format's the textboxes
 /// </summary>
 /// <param name="orderC">ordercontrol passed from transaction control</param>
 public CashRegisterControl(OrderControl orderC)
 {
     InitializeComponent();
     orderControl = orderC;
     ClearDrawer();
     (DataContext as CashRegisterModelView).TotalValueChanged += new EventHandler(updateTotal);
     TargetTotalText.Text = String.Format("Enter cash to pay the Order Total: {0:C}", TargetTotal);
     GoalTotalText.Text   = String.Format("Cash entered so far: {0:C}", (DataContext as CashRegisterModelView).TotalValue);
 }
        private void newOrder()
        {
            var order        = new Order();
            var orderControl = this.FindAncestor <OrderControl>();
            var screen       = new OrderControl();

            screen.DataContext = order;
            orderControl.swapScreen(screen);
        }
예제 #23
0
        public CashControl(OrderControl order)
        {
            InitializeComponent();
            oc = order;
            CashDrawer.ResetDrawer();
            //(DataContext as RoundRegisterModelView).TotalValueChanged += new EventHandler(updateTotal);
            //Total.Text = String.Format("Enter cash to pay the Order Total: {0:C}", oc.T);
//          GoalTotalText.Text = String.Format("Cash entered so far: {0:C}", (DataContext as RoundRegisterModelView).TotalValue);
        }
 /// <summary>
 /// Click event of print button
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void OnPrintButtonClicked(object sender, RoutedEventArgs e)
 {
     if (DataContext is Order data)
     {
         PrintReciept(data);
         var screen = new OrderControl();
         MainTransactionControl.Child = screen;
     }
 }
 public SideCustomizationScreen(Side side, OrderControl orderC)
 {
     InitializeComponent();
     CurrentSide       = side;
     orderControl      = orderC;
     SmallSize.Click  += OnAddSmallSizeClicked;
     MediumSize.Click += OnAddMediumSizeClicked;
     LargeSize.Click  += OnAddLargeSizeClicked;
     RemoveSide.Click += OnAddRemoveSideClicked;
 }
예제 #26
0
        /// <summary>
        /// When complete button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OnCompleteClicked(object sender, RoutedEventArgs e)
        {
            CashRegisterModelView cr = (CashRegisterModelView)DataContext;

            cr.complete();
            var          orderInfo = this.FindAncestor <OrderControl>();
            OrderControl o         = new OrderControl();

            orderInfo.SwapOrderSum(o);
        }
 /// <summary>
 /// Event handler for adding the pulled pork entree to the order
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void OnAddPecosPulledPorkButtonClicked(object sender, RoutedEventArgs e)
 {
     if (DataContext is Order data)
     {
         var newPulledPork = new PecosPulledPork();
         var screen        = new CustomizePecosPulledPork();
         screen.DataContext = newPulledPork;
         data.Add(newPulledPork);
         orderControl = this.FindAncestor <OrderControl>();
         orderControl.SwapScreen(screen);
     }
 }
 /// <summary>
 /// Event handler for adding the trail burger entree to the order
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void OnAddTrailBurgerButtonClicked(object sender, RoutedEventArgs e)
 {
     if (DataContext is Order data)
     {
         var newTrailBurger = new TrailBurger();
         var screen         = new CustomizeTrailBurger();
         screen.DataContext = newTrailBurger;
         data.Add(newTrailBurger);
         orderControl = this.FindAncestor <OrderControl>();
         orderControl.SwapScreen(screen);
     }
 }
예제 #29
0
 /// <summary>
 /// This method adds the Angry Chicken to the list
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void AddAngryChicken_Click(object sender, RoutedEventArgs e)
 {
     orderControl = this.FindAncestor <OrderControl>();
     if (DataContext is Order order)
     {
         var entree = new AngryChicken();
         var screen = new CustomizeAngryChicken();
         screen.DataContext = entree;
         order.Add(entree);
         orderControl.SwapScreen(screen);
     }
 }
 /// <summary>
 /// Completes order and prints the receipt.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnCompleteButton_Clicked(object sender, RoutedEventArgs e)
 {
     if (DataContext is CashRegisterModelView view)
     {
         if (total == owed)
         {
             receiptPrinter.Print(order.Receipt(false, 0, 0));
             var screen = new OrderControl();
             this.Content = screen;
         }
     }
 }