Esempio n. 1
0
 public bool AddBill(DrawerFlag _flag, int _id, int _managerid, Bill _bill)
 {
     lock (this.syncRoot)
     {
         CashDrawer _drawer = null;
         if (TryGetDrawer(_flag, out _drawer, _id, _managerid))
         {
             return(_drawer.AddBill(time, _bill));
         }
         return(false);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Adds bills to the register and to the total
 /// </summary>
 /// <param name="bill"></param>
 public void AddBills(Bills bill)
 {
     if (bill is Bills.One)
     {
         drawer.AddBill(Bills.One, 1);
         TotalValue += 1;
         Ones++;
     }
     if (bill is Bills.Two)
     {
         drawer.AddBill(Bills.Two, 1);
         TotalValue += 2;
         Twos++;
     }
     if (bill is Bills.Five)
     {
         drawer.AddBill(Bills.Five, 1);
         TotalValue += 5;
         Fives++;
     }
     if (bill is Bills.Ten)
     {
         drawer.AddBill(Bills.Ten, 1);
         TotalValue += 10;
         Tens++;
     }
     if (bill is Bills.Twenty)
     {
         drawer.AddBill(Bills.Twenty, 1);
         TotalValue += 20;
         Twenties++;
     }
     if (bill is Bills.Fifty)
     {
         drawer.AddBill(Bills.Fifty, 1);
         TotalValue += 50;
         Fifties++;
     }
     if (bill is Bills.Hundred)
     {
         drawer.AddBill(Bills.Hundred, 1);
         TotalValue += 100;
         Hundreds++;
     }
     PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("TotalValue"));
 }
        /// <summary>
        /// Handles every single button click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtClick(object sender, RoutedEventArgs e)
        {
            switch (((Button)sender).Name)
            {
            case "IncreasePennies":
                ChangeOfProperty("Pennies", 0, .01);
                break;

            case "IncreaseNickels":
                ChangeOfProperty("Nickels", 0, .05);
                break;

            case "IncreaseDimes":
                ChangeOfProperty("Dimes", 0, .1);
                break;

            case "IncreaseQuarters":
                ChangeOfProperty("Quarters", 0, .25);
                break;

            case "IncreaseHalfDollars":
                ChangeOfProperty("HalfDollars", 0, .5);
                break;

            case "IncreaseDollars":
                ChangeOfProperty("Dollars", 0, 1);
                break;

            case "IncreaseOnes":
                ChangeOfProperty("Ones", 0, 1);
                break;

            case "IncreaseTwos":
                ChangeOfProperty("Twos", 0, 2);
                break;

            case "IncreaseFives":
                ChangeOfProperty("Fives", 0, 5);
                break;

            case "IncreaseTens":
                ChangeOfProperty("Tens", 0, 10);
                break;

            case "IncreaseTwenties":
                ChangeOfProperty("Twenties", 0, 20);
                break;

            case "IncreaseFifties":
                ChangeOfProperty("Fifties", 0, 50);
                break;

            case "IncreaseHundreds":
                ChangeOfProperty("Hundreds", 0, 100);
                break;

            case "DecreasePennies":
                if (Pennies != 0)
                {
                    ChangeOfProperty("Pennies", 1, .01);
                }
                break;

            case "DecreaseNickels":
                if (Nickels != 0)
                {
                    ChangeOfProperty("Nickels", 1, .05);
                }
                break;

            case "DecreaseDimes":
                if (Dimes != 0)
                {
                    ChangeOfProperty("Dimes", 1, .1);
                }
                break;

            case "DecreaseQuarters":
                if (Quarters != 0)
                {
                    ChangeOfProperty("Quarters", 1, .25);
                }
                break;

            case "DecreaseHalfDollars":
                if (HalfDollars != 0)
                {
                    ChangeOfProperty("HalfDollars", 1, .5);
                }
                break;

            case "DecreaseDollars":
                if (Dollars != 0)
                {
                    ChangeOfProperty("Dollars", 1, 1);
                }
                break;

            case "DecreaseOnes":
                if (Ones != 0)
                {
                    ChangeOfProperty("Ones", 1, 1);
                }
                break;

            case "DecreaseTwos":
                if (Twos != 0)
                {
                    ChangeOfProperty("Twos", 1, 2);
                }
                break;

            case "DecreaseFives":
                if (Fives != 0)
                {
                    ChangeOfProperty("Fives", 1, 5);
                }
                break;

            case "DecreaseTens":
                if (Tens != 0)
                {
                    ChangeOfProperty("Tens", 1, 10);
                }
                break;

            case "DecreaseTwenties":
                if (Twenties != 0)
                {
                    ChangeOfProperty("Twenties", 1, 20);
                }
                break;

            case "DecreaseFifties":
                if (Fifties != 0)
                {
                    ChangeOfProperty("Fifties", 1, 50);
                }
                break;

            case "DecreaseHundreds":
                if (Hundreds != 0)
                {
                    ChangeOfProperty("Hundreds", 1, 100);
                }
                break;

            case "CancelPay":
                NewOrder();
                break;

            case "CardPay":
                CardTerminal ct = new CardTerminal();
                ResultCode   r  = ct.ProcessTransaction(Total);
                switch (r)
                {
                case ResultCode.Success:
                    Paid = Total;
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Paid"));
                    Receipt(1);
                    break;

                case ResultCode.InsufficentFunds:
                    MessageBox.Show("Error: Card has insufficient funds\n\nTry different card or pay with cash.");
                    Error.Text    = "Error: Card has insufficient";
                    ExtError.Text = "funds";
                    break;

                case ResultCode.CancelledCard:
                    MessageBox.Show("Error: Card cancelled\n\nTry different card or pay with cash.");
                    Error.Text    = "Error: Card cancelled";
                    ExtError.Text = "";
                    break;

                case ResultCode.ReadError:
                    MessageBox.Show("Error: Bad swipe\n\nPlease try swiping again.");
                    Error.Text    = "Error: Bad swipe";
                    ExtError.Text = "";
                    break;

                case ResultCode.UnknownErrror:
                    MessageBox.Show("Error: Unknown error\n\n Please try swiping again.");
                    Error.Text    = "Error: Unknown error";
                    ExtError.Text = "";
                    break;
                }
                break;

            case "CashPay":
                foreach (Coins c in Enum.GetValues(typeof(Coins)) as Coins[])
                {
                    switch (c)
                    {
                    case Coins.Penny:
                        cd.AddCoin(c, Pennies);
                        break;

                    case Coins.Nickel:
                        cd.AddCoin(c, Nickels);
                        break;

                    case Coins.Dime:
                        cd.AddCoin(c, Dimes);
                        break;

                    case Coins.Quarter:
                        cd.AddCoin(c, Quarters);
                        break;

                    case Coins.HalfDollar:
                        cd.AddCoin(c, HalfDollars);
                        break;

                    case Coins.Dollar:
                        cd.AddCoin(c, Dollars);
                        break;
                    }
                }
                foreach (Bills c in Enum.GetValues(typeof(Bills)) as Bills[])
                {
                    switch (c)
                    {
                    case Bills.One:
                        cd.AddBill(c, Ones);
                        break;

                    case Bills.Two:
                        cd.AddBill(c, Twos);
                        break;

                    case Bills.Five:
                        cd.AddBill(c, Fives);
                        break;

                    case Bills.Ten:
                        cd.AddBill(c, Tens);
                        break;

                    case Bills.Twenty:
                        cd.AddBill(c, Twenties);
                        break;

                    case Bills.Fifty:
                        cd.AddBill(c, Fifties);
                        break;

                    case Bills.Hundred:
                        cd.AddBill(c, Hundreds);
                        break;
                    }
                }
                if (LeftToPay < 0)
                {
                    Change = LeftToPay;
                    double ch = Change;
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Change"));
                    var changeC = new List <Coins>();
                    var changeB = new List <Bills>();
                    var c       = Enum.GetValues(typeof(Coins)) as Coins[];
                    var b       = Enum.GetValues(typeof(Bills)) as Bills[];
                    Array.Reverse(c);
                    Array.Reverse(b);
                    int    bi = 0;
                    double v  = Math.Round(0.0, 2);
                    foreach (Bills i in b)
                    {
                        Bills j = i;
                        switch (j)
                        {
                        case Bills.One:
                            bi = cd.Ones;
                            v  = 1;
                            break;

                        case Bills.Two:
                            bi = cd.Twos;
                            v  = 2;
                            if (bi == 0)
                            {
                                j--;
                                goto case Bills.One;
                            }
                            break;

                        case Bills.Five:
                            bi = cd.Fives;
                            v  = 5;
                            break;

                        case Bills.Ten:
                            bi = cd.Tens;
                            v  = 10;
                            break;

                        case Bills.Twenty:
                            bi = cd.Twenties;
                            v  = 20;
                            break;

                        case Bills.Fifty:
                            bi = cd.Fifties;
                            v  = 50;
                            break;

                        case Bills.Hundred:
                            bi = cd.Hundreds;
                            v  = 100;
                            break;
                        }
                        while (ch - v >= 0)
                        {
                            if (bi == 0)
                            {
                                BreakBills(j);
                            }
                            ch -= v;
                            cd.RemoveBill(j, 1);
                            changeB.Add(j);
                            bi--;
                        }
                    }
                    foreach (Coins i in c)
                    {
                        Coins j = i;
                        switch (j)
                        {
                        case Coins.Penny:
                            bi = cd.Pennies;
                            v  = 0.01;
                            break;

                        case Coins.Nickel:
                            bi = cd.Nickels;
                            v  = 0.05;
                            break;

                        case Coins.Dime:
                            bi = cd.Dimes;
                            v  = 0.10;
                            break;

                        case Coins.Quarter:
                            bi = cd.Quarters;
                            v  = 0.25;
                            break;

                        case Coins.HalfDollar:
                            bi = cd.HalfDollars;
                            v  = 0.50;
                            if (bi == 0)
                            {
                                j--;
                                goto case Coins.Quarter;
                            }
                            break;

                        case Coins.Dollar:
                            bi = cd.Dollars;
                            v  = 1.00;
                            if (bi == 0)
                            {
                                j--;
                                goto case Coins.HalfDollar;
                            }
                            break;
                        }
                        while (ch - v >= 0)
                        {
                            if (bi == 0)
                            {
                                int   be = 0;
                                Coins co = j + 1;
                                switch (co)
                                {
                                case Coins.Nickel:
                                    be = cd.Nickels;
                                    if (be == 0)
                                    {
                                        co++;
                                        goto case Coins.Dime;
                                    }
                                    break;

                                case Coins.Dime:
                                    be = cd.Dimes;
                                    if (be == 0)
                                    {
                                        co++;
                                        goto case Coins.Quarter;
                                    }
                                    break;

                                case Coins.Quarter:
                                    be = cd.Quarters;
                                    if (be == 0)
                                    {
                                        co++;
                                        goto case Coins.HalfDollar;
                                    }
                                    break;

                                case Coins.HalfDollar:
                                    be = cd.HalfDollars;
                                    if (be == 0)
                                    {
                                        co++;
                                        goto case Coins.Dollar;
                                    }
                                    break;

                                case Coins.Dollar:
                                    be = cd.Dollars;
                                    if (be == 0)
                                    {
                                        if (cd.Ones > 0)
                                        {
                                            cd.RemoveBill(Bills.One, 1);
                                            cd.AddCoin(Coins.Dollar, 1);
                                        }
                                        else
                                        {
                                            BreakBills(Bills.One);
                                            goto case Coins.Dollar;
                                        }
                                    }
                                    break;

                                default:
                                    new NotImplementedException();
                                    break;
                                }
                                switch (co)
                                {
                                case Coins.Nickel:
                                    cd.RemoveCoin(Coins.Nickel, 1);
                                    cd.AddCoin(Coins.Penny, 5);
                                    break;

                                case Coins.Dime:
                                    cd.RemoveCoin(Coins.Dime, 1);
                                    cd.AddCoin(Coins.Nickel, 2);
                                    if (j == Coins.Nickel)
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        goto case Coins.Nickel;
                                    }

                                case Coins.Quarter:
                                    cd.RemoveCoin(Coins.Quarter, 1);
                                    cd.AddCoin(Coins.Dime, 2);
                                    cd.AddCoin(Coins.Nickel, 1);
                                    if (j == Coins.Dime)
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        goto case Coins.Dime;
                                    }

                                case Coins.HalfDollar:
                                    cd.RemoveCoin(Coins.HalfDollar, 1);
                                    cd.AddCoin(Coins.Quarter, 2);
                                    if (j == Coins.Quarter)
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        goto case Coins.Quarter;
                                    }

                                case Coins.Dollar:
                                    cd.RemoveCoin(Coins.Dollar, 1);
                                    cd.AddCoin(Coins.Quarter, 4);
                                    if (j == Coins.Quarter)
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        goto case Coins.Quarter;
                                    }

                                default:
                                    new NotImplementedException();
                                    break;
                                }
                            }
                            ch -= v;
                            cd.RemoveCoin(j, 1);
                            changeC.Add(j);
                            bi--;
                        }
                    }
                    StringBuilder sb = new StringBuilder();
                    sb.Append("Change to give back:\n\t");
                    foreach (Bills bill in changeB)
                    {
                        sb.Append(bill.ToString() + "\n\t");
                    }
                    foreach (Coins coin in changeC)
                    {
                        sb.Append(coin.ToString() + "\n\t");
                    }
                    MessageBox.Show(sb.ToString());
                }
                while (cd.Pennies >= 105)
                {
                    cd.RemoveCoin(Coins.Penny, 5);
                    cd.AddCoin(Coins.Nickel, 1);
                }
                while (cd.Nickels >= 82)
                {
                    cd.RemoveCoin(Coins.Nickel, 2);
                    cd.AddCoin(Coins.Dime, 1);
                }
                while (cd.Dimes >= 105)
                {
                    cd.RemoveCoin(Coins.Dime, 5);
                    cd.AddCoin(Coins.Quarter, 2);
                }
                while (cd.Quarters >= 44)
                {
                    cd.RemoveCoin(Coins.Quarter, 4);
                    cd.AddBill(Bills.One, 1);
                }
                while (cd.HalfDollars >= 2)
                {
                    cd.RemoveCoin(Coins.HalfDollar, 2);
                    cd.AddBill(Bills.One, 1);
                }
                while (cd.Dollars >= 5)
                {
                    cd.RemoveCoin(Coins.Dollar, 5);
                    cd.AddBill(Bills.Five, 1);
                }
                while (cd.Ones >= 80)
                {
                    cd.RemoveBill(Bills.One, 5);
                    cd.AddBill(Bills.Five, 1);
                }
                while (cd.Twos >= 5)
                {
                    cd.RemoveBill(Bills.Two, 5);
                    cd.AddBill(Bills.Ten, 1);
                }
                while (cd.Fives >= 8)
                {
                    cd.RemoveBill(Bills.Five, 2);
                    cd.AddBill(Bills.Ten, 1);
                }
                while (cd.Tens >= 4)
                {
                    cd.RemoveBill(Bills.Ten, 2);
                    cd.AddBill(Bills.Twenty, 1);
                }
                while (cd.Twenties >= 5)
                {
                    cd.RemoveBill(Bills.Twenty, 5);
                    cd.AddBill(Bills.Hundred, 1);
                }
                while (cd.Fifties >= 2)
                {
                    cd.RemoveBill(Bills.Fifty, 2);
                    cd.AddBill(Bills.Hundred, 1);
                }
                Receipt(0);
                break;
            }
            if (LeftToPay <= 0)
            {
                CashPay.IsEnabled = true;
            }
            else
            {
                CashPay.IsEnabled = false;
            }
            if (Paid != 0)
            {
                CardPay.IsEnabled = false;
            }
            else
            {
                CardPay.IsEnabled = true;
            }
        }
        /// <summary>
        /// Adds the bills and coins to the drawer
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CompleteCashButton_Click(object sender, RoutedEventArgs e)
        {
            foreach (Coins coin in (Coins[])Enum.GetValues(typeof(Coins)))
            {
                int quantity;

                /* Add all the coins to the drawer */
                switch (coin)
                {
                /* Pennies */
                case Coins.Penny:
                    quantity = Pennies;
                    break;

                /* Nickels */
                case Coins.Nickel:
                    quantity = Nickels;
                    break;

                /* Dimes */
                case Coins.Dime:
                    quantity = Dimes;
                    break;

                /* Quarters */
                case Coins.Quarter:
                    quantity = Quarters;
                    break;

                /* Half Dollars */
                case Coins.HalfDollar:
                    quantity = HalfDollars;
                    break;

                /* Dollars */
                case Coins.Dollar:
                    quantity = DollarCoins;
                    break;

                /* Should never be reached */
                default:
                    throw new NotImplementedException("Should never be reached");
                }
                cd.AddCoin(coin, quantity);
            }

            foreach (Bills bill in (Bills[])Enum.GetValues(typeof(Bills)))
            {
                int quantity;

                /* Add the bills to the drawer */
                switch (bill)
                {
                /* One Bills */
                case Bills.One:
                    quantity = OneBill;
                    break;

                /* Two Bills */
                case Bills.Two:
                    quantity = TwoBill;
                    break;

                /* Five Bills */
                case Bills.Five:
                    quantity = FiveBill;
                    break;

                /* Ten Bills */
                case Bills.Ten:
                    quantity = TenBill;
                    break;

                /* Twenty Bills */
                case Bills.Twenty:
                    quantity = TwentyBill;
                    break;

                /* Fifty Bills */
                case Bills.Fifty:
                    quantity = FiftyBill;
                    break;

                /* Hundred Bills */
                case Bills.Hundred:
                    quantity = HundredBill;
                    break;

                default:
                    throw new NotImplementedException("Should never be reached");
                }
                /* Add the bills to the drawer */
                cd.AddBill(bill, quantity);
            }

            /* See if change needs to be made */
            if (AmountLeftToTender < 0)
            {
                MakeChange();
            }

            /* Print the receipt */
            PrintReceipt(1);
        }
Esempio n. 5
0
 /// <summary>
 /// public method to add bills to the drawer
 /// </summary>
 /// <param name="t">type of bill</param>
 /// <param name="q">quantity of bill</param>
 public void AddBill(Bills t, int q)
 {
     drawer.AddBill(t, q);
 }
Esempio n. 6
0
        private void Confirm_Click(object sender, RoutedEventArgs e)
        {
            Order  order  = (Order)DataContext;
            double change = Total - order.Total;

            if (Pennies != 0)
            {
                drawer.AddCoin(Coins.Penny, Pennies);
            }
            else if (Nickles != 0)
            {
                drawer.AddCoin(Coins.Nickel, Nickles);
            }
            else if (Dimes != 0)
            {
                drawer.AddCoin(Coins.Dime, Dimes);
            }
            else if (Quarters != 0)
            {
                drawer.AddCoin(Coins.Quarter, Quarters);
            }
            else if (HalfDollars != 0)
            {
                drawer.AddCoin(Coins.HalfDollar, HalfDollars);
            }
            else if (Dollars != 0)
            {
                drawer.AddCoin(Coins.Dollar, Dollars);
            }
            else if (Ones != 0)
            {
                drawer.AddBill(Bills.One, Ones);
            }
            else if (Twos != 0)
            {
                drawer.AddBill(Bills.Two, Twos);
            }
            else if (Fives != 0)
            {
                drawer.AddBill(Bills.Five, Fives);
            }
            else if (Tens != 0)
            {
                drawer.AddBill(Bills.Ten, Tens);
            }
            else if (Twenties != 0)
            {
                drawer.AddBill(Bills.Twenty, Twenties);
            }
            else if (Fifties != 0)
            {
                drawer.AddBill(Bills.Fifty, Fifties);
            }
            else if (Hundreds != 0)
            {
                drawer.AddBill(Bills.Hundred, Hundreds);
            }



            if (change < 0)
            {
                MessageBox.Show("Insuficient Funds");
                return;
            }
            else if (change > drawer.TotalValue)
            {
                MessageBox.Show("Error Not enough money to break this bill");
                return;
            }
            else if (change == 0)
            {
                MessageBox.Show("Sucess");
                OrderControl parent = ((OrderControl)((Border)Parent).Parent);
                MainWindow   main   = (MainWindow)((Grid)(parent.Parent)).Parent;
                main.DataContext = new Order();
            }
            else
            {
                MessageBox.Show("Change Due: " + change.ToString("C"));
                while (change >= 0.009999999999999999999999999999999999999)
                {
                    if (change - 100 > 0 && drawer.Hundreds > 0)
                    {
                        drawer.RemoveBill(Bills.Hundred, 1);
                        change -= 100;
                    }
                    if (change - 50 > 0 && drawer.Fifties > 0)
                    {
                        drawer.RemoveBill(Bills.Fifty, 1);
                        change -= 50;
                    }
                    if (change - 20 > 0 && drawer.Twenties > 0)
                    {
                        drawer.RemoveBill(Bills.Twenty, 1);
                        change -= 20;
                    }
                    if (change - 10 > 0 && drawer.Tens > 0)
                    {
                        drawer.RemoveBill(Bills.Ten, 1);
                        change -= 10;
                    }
                    if (change - 5 > 0 && drawer.Fives > 0)
                    {
                        drawer.RemoveBill(Bills.Five, 1);
                        change -= 5;
                    }
                    if (change - 1 > 0 && drawer.Ones > 0)
                    {
                        drawer.RemoveBill(Bills.One, 1);
                        change -= 1;
                    }
                    if (change - 1 > 0 && drawer.Dollars > 0)
                    {
                        drawer.RemoveCoin(Coins.Dollar, 1);
                        change -= 1;
                    }
                    if (change - .50 > 0 && drawer.HalfDollars > 0)
                    {
                        drawer.RemoveCoin(Coins.HalfDollar, 1);
                        change -= .50;
                    }
                    if (change - .25 > 0 && drawer.Quarters > 0)
                    {
                        drawer.RemoveCoin(Coins.Quarter, 1);
                        change -= .25;
                    }
                    if (change - .10 > 0 && drawer.Dimes > 0)
                    {
                        drawer.RemoveCoin(Coins.Dime, 1);
                        change -= .10;
                    }
                    if (change - .05 > 0 && drawer.Nickels > 0)
                    {
                        drawer.RemoveCoin(Coins.Nickel, 1);
                        change -= .05;
                    }
                    if (change - .01 > 0 && drawer.Pennies > 0)
                    {
                        drawer.RemoveCoin(Coins.Penny, 1);
                        change -= .01;
                    }
                }

                OrderControl parent = (OrderControl)((Border)Parent).Parent;
                MainWindow   main   = (MainWindow)((Grid)(parent.Parent)).Parent;
                Cash_Print(Total);
                main.DataContext = new Order();
                parent.SwapScreen(null);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// On the event of a bill or coin button click the amount variable will take the value of the appropriate coin or bill denomination
        /// multiplied with the quantity amount and adds the amount of coin(s)/bill(s) to the register, then TotalPaid label will be updated,
        /// denomination of money will then be added to the money list view, and quantity will be reset to 1. When totalPaid is greater than or
        /// equal to total, then change is calculated as an int by and multiplying totalPaid and total by 100 and taking the difference and passed
        /// into the ChangeCalculator method, change is then made into a double by divding the int change by 100 which is displayed with the
        /// Change label
        /// </summary>
        /// <param name="sender">The button clicked</param>
        /// <param name="e">Event arguments</param>
        private void AddingBillsAndCoinsButtonClicked(object sender, RoutedEventArgs e)
        {
            double amount = 0.00;

            quantity = Convert.ToInt32(QuantityLabel.Text);
            var button = sender as Button;

            switch (button.Tag)
            {
            case "Pennies":
                drawer.AddCoin(Coins.Penny, quantity);
                amount = 0.01 * quantity;
                break;

            case "Nickels":
                drawer.AddCoin(Coins.Nickel, quantity);
                amount = 0.05 * quantity;
                break;

            case "Dimes":
                drawer.AddCoin(Coins.Dime, quantity);
                amount = 0.10 * quantity;
                break;

            case "Quarters":
                drawer.AddCoin(Coins.Quarter, quantity);
                amount = 0.25 * quantity;
                break;

            case "HalfDollars":
                drawer.AddCoin(Coins.HalfDollar, quantity);
                amount = 0.50 * quantity;
                break;

            case "Dollars":
                drawer.AddCoin(Coins.Dollar, quantity);
                amount = 1.00 * quantity;
                break;

            case "Ones":
                drawer.AddBill(Bills.One, quantity);
                amount = 1.00 * quantity;
                break;

            case "Twos":
                drawer.AddBill(Bills.Two, quantity);
                amount = 2.00 * quantity;
                break;

            case "Fives":
                drawer.AddBill(Bills.Five, quantity);
                amount = 5.00 * quantity;
                break;

            case "Tens":
                drawer.AddBill(Bills.Ten, quantity);
                amount = 10.00 * quantity;
                break;

            case "Twenties":
                drawer.AddBill(Bills.Twenty, quantity);
                amount = 20.00 * quantity;
                break;

            case "Fifties":
                drawer.AddBill(Bills.Fifty, quantity);
                amount = 50.00 * quantity;
                break;

            case "Hundreds":
                drawer.AddBill(Bills.Hundred, quantity);
                amount = 100.00 * quantity;
                break;
            }
            totalPaid           = totalPaid + amount;
            TotalPaidLabel.Text = totalPaid.ToString("c");
            AddedMoneyList.Items.Add(amount.ToString("c"));
            quantity           = 1;
            QuantityLabel.Text = quantity.ToString();
            string totalString = TotalLabel.Text.Substring(1);

            total = Convert.ToDouble(totalString);
            if (totalPaid >= total)
            {
                total     = total * 100;
                totalPaid = totalPaid * 100;
                int    change = (int)(totalPaid - total);
                double Change = (double)(change / 100.0);
                ChangeTB.Visibility = Visibility.Visible;
                ChangeLabel.Text    = Change.ToString("c");
                ChangeCalculator(change);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Helper method that adds bills to the drawer, finds which currency to return as change, and removes them from the drawer
        /// </summary>
        private void DrawerHelp()
        {
            //Backing variables holding the number of each denomination to return as change.  Used for StringBuilder change return.
            int dollarB  = 0;
            int twos     = 0;
            int fives    = 0;
            int tens     = 0;
            int twentys  = 0;
            int fiftys   = 0;
            int hundreds = 0;
            int dollarC  = 0;
            int halfD    = 0;
            int quarters = 0;
            int dimes    = 0;
            int nickels  = 0;
            int pennys   = 0;

            //The target amount of change to return to customer
            double change    = Total - goal;
            bool   insChange = false;

            //Adding bills from customer to drawer.
            if (TextOnes.Text != "")
            {
                cs.AddBill(Bills.One, Convert.ToInt32(TextOnes.Text));
            }
            if (TextTwos.Text != "")
            {
                cs.AddBill(Bills.Two, Convert.ToInt32(TextTwos.Text));
            }
            if (TextFives.Text != "")
            {
                cs.AddBill(Bills.Five, Convert.ToInt32(TextFives.Text));
            }
            if (TextTens.Text != "")
            {
                cs.AddBill(Bills.Ten, Convert.ToInt32(TextTens.Text));
            }
            if (TextTwentys.Text != "")
            {
                cs.AddBill(Bills.Twenty, Convert.ToInt32(TextTwentys.Text));
            }
            if (TextFiftys.Text != "")
            {
                cs.AddBill(Bills.Fifty, Convert.ToInt32(TextFiftys.Text));
            }
            if (TextHundreds.Text != "")
            {
                cs.AddBill(Bills.Hundred, Convert.ToInt32(TextHundreds.Text));
            }
            if (TextPennys.Text != "")
            {
                cs.AddCoin(Coins.Penny, Convert.ToInt32(TextPennys.Text));
            }
            if (TextNickels.Text != "")
            {
                cs.AddCoin(Coins.Nickel, Convert.ToInt32(TextNickels.Text));
            }
            if (TextDimes.Text != "")
            {
                cs.AddCoin(Coins.Dime, Convert.ToInt32(TextDimes.Text));
            }
            if (TextQuarters.Text != "")
            {
                cs.AddCoin(Coins.Quarter, Convert.ToInt32(TextQuarters.Text));
            }
            if (TextHalfDollar.Text != "")
            {
                cs.AddCoin(Coins.HalfDollar, Convert.ToInt32(TextHalfDollar.Text));
            }
            if (TextCoinDollars.Text != "")
            {
                cs.AddCoin(Coins.Dollar, Convert.ToInt32(TextCoinDollars.Text));
            }

            //Finding the number of each denomination to return to equal exact change based on the change variable calculated above.
            while (!(change < .01))
            {
                if (change >= 100.00 && cs.Hundreds > 0)
                {
                    change -= 100.00;
                    cs.RemoveBill(Bills.Hundred, 1);
                    hundreds++;
                }
                else if (change >= 50.00 && cs.Fifties > 0)
                {
                    change -= 50.00;
                    cs.RemoveBill(Bills.Fifty, 1);
                    fiftys++;
                }
                else if (change >= 20.0 && cs.Twenties > 0)
                {
                    change -= 20.00;
                    cs.RemoveBill(Bills.Twenty, 1);
                    twentys++;
                }
                else if (change >= 10.0 && cs.Tens > 0)
                {
                    change -= 10.00;
                    cs.RemoveBill(Bills.Ten, 1);
                    tens++;
                }
                else if (change >= 5.0 && cs.Fives > 0)
                {
                    change -= 5.00;
                    cs.RemoveBill(Bills.Five, 1);
                    fives++;
                }
                else if (change >= 2.0 && cs.Twos > 0)
                {
                    change -= 2.00;
                    cs.RemoveBill(Bills.Two, 1);
                    twos++;
                }
                else if (change >= 1.0 && cs.Ones > 0)
                {
                    change -= 1.0;
                    cs.RemoveBill(Bills.One, 1);
                    dollarB++;
                }
                else if (change >= 1.0 && cs.Dollars > 0)
                {
                    change -= 1.0;
                    cs.RemoveCoin(Coins.Dollar, 1);
                    dollarC++;
                }
                else if (change >= .5 && cs.HalfDollars > 0)
                {
                    change -= .5;
                    cs.RemoveCoin(Coins.HalfDollar, 1);
                    halfD++;
                }
                else if (change > .25 && cs.Quarters > 0)
                {
                    change -= .25;
                    cs.RemoveCoin(Coins.Quarter, 1);
                    quarters++;
                }
                else if (change >= .1 && cs.Dimes > 0)
                {
                    change -= .1;
                    cs.RemoveCoin(Coins.Dime, 1);
                    dimes++;
                }
                else if (change >= .05 && cs.Nickels > 0)
                {
                    change -= .05;
                    cs.RemoveCoin(Coins.Nickel, 1);
                    nickels++;
                }
                else if (change < .05 && cs.Pennies > 0)
                {
                    change -= .01;
                    cs.RemoveCoin(Coins.Penny, 1);
                    pennys++;
                }
                else
                {
                    //There is not enough of each denomination to complete the transaction so I'll ask the worker to restock the register.
                    TextChange.Text   = "Not enough Money in Register please refill.";
                    DoneBtn.IsEnabled = true;
                    insChange         = true;
                    break;
                }
            }

            if (!insChange)
            {
                //Creating the string to display to the worker regarding customer change to return
                StringBuilder sb = new StringBuilder();
                if (dollarB > 0)
                {
                    sb.Append(dollarB);
                    sb.Append("x Dollar Bill(s). ");
                }
                if (twos > 0)
                {
                    sb.Append(twos);
                    sb.Append("x 2 Dollar Bill(s). ");
                }
                if (fives > 0)
                {
                    sb.Append(fives);
                    sb.Append("x 5 Dollar Bill(s). ");
                }
                if (tens > 0)
                {
                    sb.Append(tens);
                    sb.Append("x 10 Dollar Bill(s). ");
                }
                if (twentys > 0)
                {
                    sb.Append(twentys);
                    sb.Append("x 20 Dollar Bill(s). ");
                }
                if (fiftys > 0)
                {
                    sb.Append(fiftys);
                    sb.Append("x 50 Dollar Bill(s). ");
                }
                if (hundreds > 0)
                {
                    sb.Append(hundreds);
                    sb.Append("x 100 Dollar Bill(s). ");
                }
                if (halfD > 0)
                {
                    sb.Append(halfD);
                    sb.Append("x Half Dollars. ");
                }
                if (quarters > 0)
                {
                    sb.Append(quarters);
                    sb.Append("x Quarters. ");
                }
                if (dimes > 0)
                {
                    sb.Append(dimes);
                    sb.Append("x Dimes. ");
                }
                if (nickels > 0)
                {
                    sb.Append(nickels);
                    sb.Append("x Nickels. ");
                }
                if (pennys > 0)
                {
                    sb.Append(pennys);
                    sb.Append("x Pennys. ");
                }
                TextChange.Text = sb.ToString();

                //Disabling Input textboxes to indicate that transaction is over.  Also enables the Done button to finish transaction.
                DoneBtn.IsEnabled         = true;
                TextOnes.IsEnabled        = false;
                TextTwos.IsEnabled        = false;
                TextFives.IsEnabled       = false;
                TextTens.IsEnabled        = false;
                TextTwentys.IsEnabled     = false;
                TextFiftys.IsEnabled      = false;
                TextHundreds.IsEnabled    = false;
                TextCoinDollars.IsEnabled = false;
                TextHalfDollar.IsEnabled  = false;
                TextQuarters.IsEnabled    = false;
                TextDimes.IsEnabled       = false;
                TextNickels.IsEnabled     = false;
                TextPennys.IsEnabled      = false;
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Adds a Dollar Bill when button clicked to drawer
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void DollarBill_Click(object sender, RoutedEventArgs e)
 {
     drawer.AddBill(Bills.One, 1);
     AmountAdded += 1;
     InvokePropertyChanged("Ones");
 }