/// <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());
            }
        }
        /* HAHAHAHAHAHA going below here is confusing. I do alot of jumping through switch cases. If you go past here
         *  take your time to read line by line and follow the jumps. Its the only way you'll make it though :) */


        /// <summary>
        /// The consumer is wanting to pay by card
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PaybyCardButton_Click(object sender, RoutedEventArgs e)
        {
            CardTerminal ct = new CardTerminal();

            CashRegister.ResultCode rc = ct.ProcessTransaction(TotalWithTax);

            switch (rc)
            {
            case CashRegister.ResultCode.Success:
                PrintReceipt(0);
                break;

            case CashRegister.ResultCode.InsufficentFunds:
                PaybyCardButton.IsEnabled = false;
                MessageBox.Show("Error: No funds on card\n\tCard button is being disabled!");
                break;

            case CashRegister.ResultCode.CancelledCard:
                PaybyCardButton.IsEnabled = false;
                MessageBox.Show("Error: Cancelled Card\n\tCard button is being disabled!");
                break;

            case CashRegister.ResultCode.ReadError:
                MessageBox.Show("Error: Card Read Error!!!\n\tPlease try swiping card again!");
                break;

            case CashRegister.ResultCode.UnknownErrror:
                MessageBox.Show("Error: Unknown Error\n\tPlease try swiping card again!");
                break;

            default:
                throw new NotImplementedException("Should never be reached");
            }
        }
        /// <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;
            }
        }
예제 #4
0
        /// <summary>
        /// Prints the receipt after a credit payment, or shows an error in the cardreading
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnCreditPayment(object sender, RoutedEventArgs e)
        {
            CardTerminal ct      = new CardTerminal();
            ResultCode   message = ct.ProcessTransaction(Total);

            if (message != ResultCode.Success)
            {
                MessageBox.Show(message.ToString());
            }
            else
            {
                ReceiptPrinter rp = new ReceiptPrinter();
                StringBuilder  sb = new StringBuilder();
                sb.Append("Order #" + orderSummary.OrderNumber.Text + "\n" + DateTime.Now.ToString() + "\n\n");
                foreach (IOrderItem i in orderSummary.listBox.Items)
                {
                    sb.Append(i.ToString() + String.Format(" {0:C2}", i.Price) + "\n");
                    foreach (string s in i.SpecialInstructions)
                    {
                        sb.Append(s + "\n");
                    }
                }
                sb.Append("\n");
                sb.Append("Subtotal: " + orderSummary.Subtotal.Text + "\n");
                sb.Append(String.Format("Total: {0:C2}\n", Total));
                sb.Append("Credit\n\n");
                rp.Print(sb.ToString());
                MessageBox.Show(sb.ToString());
                orderSummary.IsEnabled     = true;
                TransactionContainer.Child = new OrderControl();
            }
        }
예제 #5
0
        private void PayCredit_Click(object sender, RoutedEventArgs e)
        {
            Order      or   = (Order)this.DataContext;
            var        card = new CardTerminal();
            ResultCode res  = card.ProcessTransaction(total);

            if (res == ResultCode.Success)
            {
                var      pr   = new ReceiptPrinter();
                DateTime date = DateTime.Now;
                string   rec  = ("Order: " + or.OrderNumber + " " + date.ToString() + " " + ReceiptHelper(or) + "Subtotal: " + or.Subtotal.ToString("C") +
                                 " Total: " + ((or.Subtotal * 0.16 + or.Subtotal).ToString("C")) + " Credit");
                pr.Print(rec);
                var wind = this.FindAncestor <MainWindow>();
                wind.Content = new OrderControl();
            }
            else if (res == ResultCode.InsufficentFunds)
            {
                ErrorBox.Text = "Insufficient Funds on Card.";
            }
            else if (res == ResultCode.ReadError)
            {
                ErrorBox.Text = "Card Read Error, Try Again.";
            }
            else if (res == ResultCode.CancelledCard)
            {
                ErrorBox.Text = "Card Has Been Cancelled.";
            }
            else if (res == ResultCode.UnknownErrror)
            {
                ErrorBox.Text = "Unknown Error Occured.";
            }
        }
        /// <summary>
        /// Handles the transaction for a credit card purchase
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void On_Credit_Button_Click(object sender, RoutedEventArgs e)
        {
            Order        order  = (Order)this.DataContext;
            CardTerminal credit = new CardTerminal();
            ResultCode   result = credit.ProcessTransaction(order.Total);
            string       Error  = "";

            switch (result.ToString())
            {
            case "Success":
                PrintReceipt();
                break;

            case "InsufficientFunds":
                Error = "Insufficient Funds";
                break;

            case "CancelledCard":
                Error = "Cancelled Card";
                break;

            case "ReadError":
                Error = "Read Error";
                break;

            default:
                Error = "Unknown Error";
                break;
            }
        }
        /// <summary>
        /// Proccess Credit Card Transaction
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnCreditClicked(object sender, RoutedEventArgs e)
        {
            CardTerminal card = new CardTerminal();

            paymentMethod = false;
            ReceiptPrinter printer = new ReceiptPrinter();
            MainWindow     mw      = this.FindAncestor <MainWindow>();

            if (DataContext is Order order)
            {
                var result = card.ProcessTransaction(TotalWithTax);
                if (result == ResultCode.Success)
                {
                    MessageBox.Show("Success");
                    printer.Print(Reciept());
                    mw.DataContext     = new Order();
                    mw.Container.Child = new OrderControl();
                }
                else
                {
                    MessageBox.Show(result.ToString());
                    mw.Container.Child = new TransactionControl(order);
                }
            }
        }
        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);
            }
        }
        void CreditPayment(object sender, RoutedEventArgs e)
        {
            CardTerminal terminal = new CardTerminal();

            if (DataContext is Order order)
            {
                ResultCode result = terminal.ProcessTransaction(order.Total);


                switch (result)
                {
                case ResultCode.Success:


                    PrintReceipt();

                    MessageBox.Show("Transaction Complete");

                    SwapScreenToOrderControl();
                    break;

                default:
                    MessageBox.Show(result.ToString());
                    break;
                }
            }
            //put the right amount in the parameters//////////////////
            //result code success case to get receipt///////////////
            //print receipt./////////////////
            //return to order screen./////////////
        }
예제 #10
0
        /// <summary>
        /// Event handler for when the Credit Payment Button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CreditPaymentButton_Click(object sender, RoutedEventArgs e)
        {
            Cash = false;
            CardTerminal   card    = new CardTerminal();
            ReceiptPrinter printer = new ReceiptPrinter();

            if (DataContext is Order order)
            {
                switch (card.ProcessTransaction(order.Total))
                {
                case ResultCode.Success:
                    credit = true;
                    printer.Print(ReceiptText());
                    CancelOrderButton_Click(new object(), new RoutedEventArgs());
                    break;

                case ResultCode.InsufficentFunds:
                    MessageBox.Show("Error: " + ResultCode.InsufficentFunds.ToString());
                    break;

                case ResultCode.CancelledCard:
                    MessageBox.Show("Error: " + ResultCode.CancelledCard.ToString());
                    break;

                case ResultCode.ReadError:
                    MessageBox.Show("Error: " + ResultCode.ReadError.ToString());
                    break;

                case ResultCode.UnknownErrror:
                    MessageBox.Show("Error: " + ResultCode.UnknownErrror.ToString());
                    break;
                }
            }
        }
        /// <summary>
        /// Handles credit card payment
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CreditPayment(object sender, RoutedEventArgs e)
        {
            CardTerminal cardTerminal = new CardTerminal();

            current.payment    = TypeOfPayment.Credit;
            current.AmountPaid = current.Total;
            ResultCode code = cardTerminal.ProcessTransaction(current.Total);

            switch (code)
            {
            case ResultCode.Success:
                MessageBox.Show("Success: Card Accepted. Printing Receipt");
                FinishCurrentTransaction();
                break;

            case ResultCode.CancelledCard:
                MessageBox.Show("Error: Cancelled Card");
                break;

            case ResultCode.InsufficentFunds:
                MessageBox.Show("Error: Insufficent Funds");
                break;

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

            case ResultCode.UnknownErrror:
                MessageBox.Show("Error: Unknown Error");
                break;
            }
        }
        /// <summary>
        /// Click event for credit button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void CreditButtonClicked(object sender, RoutedEventArgs e)
        {
            UsedCredit     = true;
            Cash.IsEnabled = false;

            CardOutput.Items.Add("Reading Card....");
            var terminal = new CardTerminal();

            if (DataContext is Order data)
            {
                ResultCode result = terminal.ProcessTransaction(data.Total);
                if (result == ResultCode.Success)
                {
                    CardOutput.Items.Add("Card Read Success");
                    CancelOrder.IsEnabled      = false;
                    Credit.IsEnabled           = false;
                    PrintAndContinue.IsEnabled = true;
                }
                else
                {
                    CardOutput.Items.Add("Error. Please try again or use a different form of payment.");
                    Cash.IsEnabled = true;
                }
            }
        }
예제 #13
0
        /// <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());
            }
        }
예제 #14
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);
            }
        }
예제 #15
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";
            }
        }
        /// <summary>
        /// Creates a click event for the Credit button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnCreditPaymentClicked(object sender, RoutedEventArgs e)
        {
            var          orderControl = this.FindAncestor <OrderControl>();
            CardTerminal terminal     = new CardTerminal();
            ResultCode   result       = ResultCode.InsufficentFunds;

            if (DataContext is Order o)
            {
                result = terminal.ProcessTransaction(o.Subtotal);
                if (result != ResultCode.Success)
                {
                    MessageBox.Show("Card Reader Error - Try Again", "ERROR", MessageBoxButton.OK);
                }
                else
                {
                    ReceiptPrinter receipt = new ReceiptPrinter();
                    receipt.Print(o.ToString());
                    orderControl.Stupid();
                    orderControl.SwapScreen(new MenuItemSelectionControl());
                }
            }
            else
            {
                MessageBox.Show("Coding Error - Try Again", "ERROR", MessageBoxButton.OK);
            }
        }
예제 #17
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;
            }
        }
        /// <summary>
        /// Click event for the option to pay with credit card
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PayWithCreditClicked(object sender, RoutedEventArgs e)
        {
            Order        o  = (Order)DataContext;
            CardTerminal ct = new CardTerminal();

            ResultCode result = ct.ProcessTransaction(o.Total);

            if (DataContext is Order order)
            {
                switch (result)
                {
                case ResultCode.Success:
                    MessageBox.Show("Payment Successful");
                    receipt.Print("Order Number: " + order.OrderNumber.ToString() + "\n");
                    receipt.Print("Date: " + DateTime.Now.ToString() + "\n");
                    foreach (IOrderItem item in order.Items)
                    {
                        receipt.Print(item.ToString() + "  ");
                        receipt.Print(String.Format("{0:C2}", item.Price) + "\n");
                        foreach (string s in item.SpecialInstructions)
                        {
                            receipt.Print("- " + s.ToString() + "\n");
                        }
                    }
                    receipt.Print("Payed with: Credit\n\n");
                    break;

                case ResultCode.InsufficentFunds:
                    MessageBox.Show("Insufficent Funds, please try a different card or pay with cash");
                    break;

                case ResultCode.ReadError:
                    MessageBox.Show("Read Error, please try again");
                    break;

                case ResultCode.UnknownErrror:
                    MessageBox.Show("Unknown Error, please try again");
                    break;

                case ResultCode.CancelledCard:
                    MessageBox.Show("This card is cancelled, please use a different cad or pay with cash");
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
        }
        /// <summary>
        /// Pay with card click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PayCard_Click(object sender, RoutedEventArgs e)
        {
            var cardTerminal = new CardTerminal();

            var status = cardTerminal.ProcessTransaction((this.DataContext as Order).Total);

            if (status == ResultCode.Success)
            {
                PrintReciept("Card", (this.DataContext as Order).Total, 0);
                var orderControl = this.FindAncestor <OrderControl>();
                orderControl.CompleteOrder.IsEnabled = true;
                orderControl.ItemSelection.IsEnabled = true;
                orderControl.CancelOrder.IsEnabled   = true;
                orderControl?.SwapScreen(new MenuItemSelectionControl());
            }
        }
예제 #20
0
        private void OnCreditClick(object sender, RoutedEventArgs e)
        {
            var        cardTerminal = new CardTerminal(); //New card terminal
            ResultCode result       = cardTerminal.ProcessTransaction((this.DataContext as Order).TotalCost);

            switch (result)
            {
            case ResultCode.Success:
                PrintReceiptForTransaction((this.DataContext as Order).TotalCost, 0, "Card");
                var control = this.FindAncestor <OrderControl>();
                control.DataContext          = new Order();
                control.CompleteT.Visibility = Visibility.Visible;
                control.Container.Child      = new MenuItemSelectionControl();
                break;
            }
        }
예제 #21
0
        private void CreditButtonClick(object sender, RoutedEventArgs e)
        {
            var card = new CardTerminal();

            if (DataContext is Order data)
            {
                ResultCode result = card.ProcessTransaction(data.Total);

                switch (result)
                {
                case ResultCode.Success:
                    ReceiptPrinter receiptPrinter = new ReceiptPrinter();

                    var orderControl = new OrderControl();

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

                    ReceiptPrinter print = new ReceiptPrinter();

                    print.Print(data.OrderNumber.ToString());
                    print.Print(DateTime.Now.ToString());
                    foreach (IOrderItem item in data.Items)
                    {
                        print.Print(item.ToString() + " : " + item.Price.ToString());
                        print.Print(item.SpecialInstructions.ToString());
                    }

                    print.Print(data.Total.ToString());
                    break;

                case ResultCode.InsufficentFunds:
                    cardStatus = "Insufficent Funds";
                    break;

                case ResultCode.ReadError:
                    cardStatus = "Read Error";
                    break;

                case ResultCode.UnknownErrror:
                    cardStatus = "Unknown Error";
                    break;
                }

                CardStatus.Text = cardStatus;
            }
        }
예제 #22
0
        /// <summary>
        /// Specifies credit payment
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnPaymentCredit_Click(object sender, RoutedEventArgs e)
        {
            var terminal = new CardTerminal();
            var printer  = new ReceiptPrinter();

            if (DataContext is Order)
            {
                var data = DataContext as Order;

                //Implies Credit Payment type false would imply a debit payment type.
                data.PaymentType = true;
                ResultCode result = terminal.ProcessTransaction(data.Total);
                switch (result)
                {
                case ResultCode.Success:
                    printer.Print(data.Receipt);
                    CardPayment();
                    MessageBox.Show("Transaction Successful!");
                    break;

                case ResultCode.CancelledCard:
                    CardPayment();
                    MessageBox.Show("Transaction failed due to cancelled card.");
                    break;

                case ResultCode.InsufficentFunds:
                    CardPayment();
                    MessageBox.Show("Transaction failed due to Insufficient Funds.");
                    break;

                case ResultCode.ReadError:
                    CardPayment();
                    MessageBox.Show("Transaction failed due to Read Error.");
                    break;

                case ResultCode.UnknownErrror:
                    CardPayment();
                    MessageBox.Show("Transaction failed due to unkown error.");
                    break;

                default:
                    CardPayment();
                    MessageBox.Show("Transaction failed due to unkown error.");
                    break;
                }
            }
        }
예제 #23
0
        /// <summary>
        /// Processes the transaction and either prints out a receipt or returns the user a error
        /// </summary>
        private void CreditButton_Click(object sender, RoutedEventArgs e)
        {
            ReceiptPrinter receipt = new ReceiptPrinter();
            CardTerminal   card    = new CardTerminal();
            DateTime       now     = DateTime.Now;

            ///string[] s = data.Prices;

            switch (card.ProcessTransaction(data.TaxedSubtotal).ToString())
            {
            /// + now + "\n" + data.Items + "\n" + data.ItemPrices + "\n" + data.Subtotal + "\n" + data.TaxedSubtotal + "\n" + "Credit Transaction."
            case "Success":
                receipt.Print(data.OrderNumber.ToString() + "\n");
                receipt.Print(now + "\n");
                foreach (IOrderItem item in data.Items)
                {
                    ///foreach(string s in itemPrices)
                    ///{

                    receipt.Print(item + "\n");
                    ///receipt.Print(str + "\n");

                    ///}
                }
                ////+ "   " + str
                receipt.Print("Subtotal = " + data.Subtotal + "\n");
                receipt.Print("Taxed Total = " + data.TaxedSubtotal + "\n");
                receipt.Print("Credit Transaction.  \n");
                break;

            case "InsufficientFunds":
                MessageBox.Show("Error: Insufficient Funds. There is not enough funds on the card.");
                break;

            case "CancelledCard":
                MessageBox.Show("Error: Card Cancelled. This card is no longer in order and has been cancelled.");
                break;

            case "ReadError":
                MessageBox.Show("Error: Read Error. Please try the card again.");
                break;

            case "Unknown Error":
                MessageBox.Show("Error: Unknown Error. Please try the card again.");
                break;
            }
        }
예제 #24
0
        /// <summary>
        /// Handles when the credit card button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OnCreditButtonClicked(object sender, RoutedEventArgs e)
        {
            var cardTerminal = new CardTerminal();

            if (DataContext is Order data)
            {
                ResultCode result = cardTerminal.ProcessTransaction(data.Total);

                if (result == ResultCode.Success)
                {
                    ReceiptPrinting(data, true);
                }
                else
                {
                    MessageBox.Show(result.ToString());
                }
            }
        }
예제 #25
0
        /// <summary>
        /// Method for Payment using a Credit Card
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CreditPaymentButton_Clicked(object sender, RoutedEventArgs e)
        {
            if (DataContext is Order order)
            {
                CardTerminal terminal = new CardTerminal();
                ResultCode   result   = terminal.ProcessTransaction(order.total);
                if (result == ResultCode.Success)
                {
                    ReceiptPrinter printer = new ReceiptPrinter();

                    StringBuilder sb = new StringBuilder();
                    sb.Append("\n");
                    sb.Append("\nOrder Number " + order.OrderNumber.ToString());
                    string date = DateTime.Now.ToString();
                    sb.Append("\n" + date);
                    foreach (IOrderItem item in order.Items)
                    {
                        sb.Append("\n" + item.ToString() + "   ");
                        sb.Append(item.Price.ToString("C2"));
                        foreach (string instruct in item.SpecialInstructions)
                        {
                            sb.Append("\n" + instruct.ToString());
                        }
                    }
                    sb.Append("\nSubtotal " + order.Subtotal.ToString("C2"));
                    sb.Append("\nTotal With Tax " + order.total.ToString("C2"));
                    sb.Append("\nCredit used");



                    printer.Print(sb.ToString());

                    MessageBox.Show("Receipt Printed");

                    DataContext = new Order();
                    var orderControl = this.FindAncestor <OrderControl>();
                    orderControl.SwapOrderScreen(new OrderControl());
                }
                else
                {
                    MessageBox.Show(result.ToString());
                }
            }
        }
예제 #26
0
        /// <summary>
        /// paying with credit card
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Card_Click(object sender, RoutedEventArgs e)
        {
            CardTerminal readCard = new CardTerminal();

            double totalPrice = Convert.ToDouble(Sum.Text.ToString());


            string read = readCard.ProcessTransaction(totalPrice).ToString();

            if (read == "Success")
            {
                var      ordercontrol = this.FindAncestor <OrderControl>();
                string[] orderItems   = new string[ordercontrol.OrderControlOrderSummaryControl.ListBoxSummary.Items.Count];
                for (int i = 0; i < ordercontrol.OrderControlOrderSummaryControl.ListBoxSummary.Items.Count; i++)
                {
                    orderItems[i] = ordercontrol.OrderControlOrderSummaryControl.ListBoxSummary.Items[i].ToString();
                }
                string ordernumber = ordercontrol.OrderControlOrderSummaryControl.OrderNumber.ToString();
                double subtotal    = Convert.ToDouble(Sub.Text.ToString());

                ReceiptPrinter rp = new ReceiptPrinter();
                rp.Print(PrintCredit(totalPrice, subtotal, ordernumber, orderItems));

                ordercontrol.SwapScreen(new MenuItemSelectionControl());
                ordercontrol.DataContext = new Order();
            }
            if (read == "InsufficientFunds")
            {
                MessageBox.Show("Insufficient Funds");
            }
            if (read == "CancelledCard")
            {
                MessageBox.Show("Cancelled Card");
            }
            if (read == "ReadError")
            {
                MessageBox.Show("Read Error");
            }
            if (read == "UnkownError")
            {
                MessageBox.Show("Unkown Error");
            }
        }
        void OnPayByCredit(object sender, RoutedEventArgs e)
        {
            var orderControl = this.FindAncestor <OrderControl>();
            var Card         = new CardTerminal();
            var result       = Card.ProcessTransaction(FinalPrice).ToString();

            if (result == "Success")
            {
                //print receipt
                CreateReciept(true, 0, 0);
                //start a new order:
                orderControl.ChangeMode(new OrderSummaryControl());
                orderControl.SwapScreen(new MenuItemSelectionControl());
            }
            else
            {
                FinalPriceDisp.Text = result;
            }
        }
예제 #28
0
        /// <summary>
        /// takes user to finish paying with credit
        /// </summary>
        /// <param name="sender">button</param>
        /// <param name="e">event args</param>
        private void CreditButton_Click(object sender, RoutedEventArgs e)
        {
            var          orderControl = this.FindAncestor <OrderControl>();
            CardTerminal terminal     = new CardTerminal();

            ResultCode result = terminal.ProcessTransaction((orderControl.DataContext as Order).Total);

            if (result == ResultCode.Success)
            {
                ReceiptPrinter receiptPrinter = new ReceiptPrinter();
                receiptPrinter.Print(ReceiptBuilder());
                orderControl.DataContext     = new Order();
                orderControl.Container.Child = new MenuItemSelectionControl();
            }
            else
            {
                ErrorTextBlock.Text = "ERROR! The transaction had a(n) " + result.ToString() + "!";
            }
        }
        /// <summary>
        /// Click event for if the user selects Pay By Card
        /// </summary>
        /// <param name="sender">The button selected</param>
        /// <param name="e">Routed Event Args</param>
        private void PayByCardButtonClicked(object sender, RoutedEventArgs e)
        {
            var        cardTerminal = new CardTerminal(); //New card terminal
            double     total        = Convert.ToDouble(tbTotal.Text.Substring(1));
            ResultCode result       = cardTerminal.ProcessTransaction(total);
            TextBlock  output       = new TextBlock(); //The PaymentBorder will be filled with this textbox

            switch (result)
            {
            case ResultCode.Success:
                PrintReceiptForCardTransaction();
                var control = this.FindAncestor <OrderControl>();
                control.DataContext = new Order();
                control.CompleteOrderButton.Visibility = Visibility.Visible;
                control.Container.Child = new MenuItemSelectionControl();
                break;

            case ResultCode.CancelledCard:
                output.Text         = "The card has been cancelled.\nPlease try again.";
                PaymentBorder.Child = output;
                break;

            case ResultCode.InsufficentFunds:
                output.Text         = "The card has insufficient fund.\nPlease try again.";
                PaymentBorder.Child = output;
                break;

            case ResultCode.ReadError:
                output.Text         = "Error reading card.\nPlease try again.";
                PaymentBorder.Child = output;
                break;

            case ResultCode.UnknownErrror:
                output.Text         = "Unknown error reading card.\nPlease try again.";
                PaymentBorder.Child = output;
                break;

            default:
                output.Text         = "Error";
                PaymentBorder.Child = output;
                break;
            }
        }
        private void CreditButtonClick(object sender, RoutedEventArgs e)
        {
            CardTerminal terminal  = new CardTerminal();
            double       tempTotal = double.Parse(total.Text.ToString(), System.Globalization.NumberStyles.Currency);
            ResultCode   code      = terminal.ProcessTransaction(tempTotal);
            bool         card      = true;

            if (code == ResultCode.Success)
            {
                PrintReceipt(card);
                var orderControl = this.FindAncestor <OrderControl>();
                var screen       = new OrderControl();
                Order.OrderNumber++;
                orderControl.full.Child = screen;
            }
            else
            {
                ErrorCode.Text = code.ToString();
            }
        }