/// <summary> /// Removes bills from the register and from the total /// </summary> /// <param name="bill"></param> public void RemoveBills(Bills bill) { if (bill is Bills.One) { drawer.RemoveBill(Bills.One, 1); TotalValue -= 1; Ones--; } if (bill is Bills.Two) { drawer.RemoveBill(Bills.Two, 1); TotalValue -= 2; Twos--; } if (bill is Bills.Five) { drawer.RemoveBill(Bills.Five, 1); TotalValue -= 5; Fives--; } if (bill is Bills.Ten) { drawer.RemoveBill(Bills.Ten, 1); TotalValue -= 10; Tens--; } if (bill is Bills.Twenty) { drawer.RemoveBill(Bills.Twenty, 1); TotalValue -= 20; Twenties--; } if (bill is Bills.Fifty) { drawer.RemoveBill(Bills.Fifty, 1); TotalValue -= 50; Fifties--; } if (bill is Bills.Hundred) { drawer.RemoveBill(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> /// Balances the coins in the drawer to make effective change /// </summary> /// <param name="b"></param> private void BalanceCoins(Coins c) { Coins result = c; int quantity = 0; while (quantity == 0) { result = c + 1; switch (result) { /* Nickels */ case Coins.Nickel: quantity = cd.Nickels; break; /* Dimes */ case Coins.Dime: quantity = cd.Dimes; break; /* Quarters */ case Coins.Quarter: quantity = cd.Quarters; break; /* Half Dollas */ case Coins.HalfDollar: quantity = cd.HalfDollars; break; /* Dolla Coins */ case Coins.Dollar: quantity = cd.Dollars; /* If no dolla coins are availible go to bills */ if (quantity == 0) { if (cd.Ones > 0) { cd.RemoveBill(Bills.One, 1); cd.AddCoin(Coins.Dollar, 1); result = c; quantity = 0; } else { BalanceBills(Bills.One); } } break; default: throw new NotImplementedException("Should never be reached"); } } switch (result) { case Coins.Dollar: cd.RemoveCoin(Coins.Dollar, 1); cd.AddCoin(Coins.HalfDollar, 2); if (c == Coins.HalfDollar) { break; } else { goto case Coins.HalfDollar; } case Coins.HalfDollar: cd.RemoveCoin(Coins.HalfDollar, 1); cd.AddCoin(Coins.Quarter, 2); if (c == Coins.Quarter) { break; } else { goto case Coins.Quarter; } case Coins.Quarter: cd.RemoveCoin(Coins.Quarter, 1); cd.AddCoin(Coins.Dime, 2); cd.AddCoin(Coins.Nickel, 1); if (c == Coins.Dime) { break; } else { goto case Coins.Dime; } case Coins.Dime: cd.RemoveCoin(Coins.Dime, 1); cd.AddCoin(Coins.Nickel, 2); if (c == Coins.Nickel) { break; } else { goto case Coins.Nickel; } case Coins.Nickel: cd.RemoveCoin(Coins.Nickel, 1); cd.AddCoin(Coins.Penny, 5); break; default: throw new NotImplementedException("Should never be reached"); } }
/// <summary> /// public method to remove bills to the drawer /// </summary> /// <param name="t">type of bill</param> /// <param name="q">quantity of bill</param> public void RemoveBill(Bills t, int q) { drawer.RemoveBill(t, q); }
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); } }
/// <summary> /// Calculates change if there is change, the denomination of the change is then added to the appropriate bills or coins array with the /// change with the appropriate amount subtracted from the change variable and the appropriate the bill or coin removed from the drawer /// this will continue the change is 0. Then a StringBuilder builds the string used to the tell amount of change that needs to be given /// back to the customer. Then another StringBuilder is used to build the reciept using the order number, date and time, the list array of /// IOrderItem with the according prices and SpecialInstructions, the subtotal, total, the cash paid for the transaction, and the change /// given back which is then printed by the RecieptPrinter instance. The container is then swapped back to the OrderControl. /// </summary> /// <param name="change">Passed in amount of change</param> private void ChangeCalculator(int change) { double Change = change / 100.0; int[] bills = { 0, 0, 0, 0, 0, 0, 0 }; int[] coins = { 0, 0, 0, 0, 0 }; if (change > 0) { while (change > 0) { if (change >= 10000 && drawer.GetBillQuantity(Bills.Hundred) > 0) { bills[0]++; change -= 10000; drawer.RemoveBill(Bills.Hundred, 1); } else if (change >= 5000 && drawer.GetBillQuantity(Bills.Fifty) > 0) { bills[1]++; change -= 5000; drawer.RemoveBill(Bills.Fifty, 1); } else if (change >= 2000 && drawer.GetBillQuantity(Bills.Twenty) > 0) { bills[2]++; change -= 2000; drawer.RemoveBill(Bills.Twenty, 1); } else if (change >= 1000 && drawer.GetBillQuantity(Bills.Ten) > 0) { bills[3]++; change -= 1000; drawer.RemoveBill(Bills.Ten, 1); } else if (change >= 500 && drawer.GetBillQuantity(Bills.Five) > 0) { bills[4]++; change -= 500; drawer.RemoveBill(Bills.Five, 1); } else if (change >= 200 && drawer.GetBillQuantity(Bills.Two) > 0) { bills[5]++; change -= 200; drawer.RemoveBill(Bills.Two, 1); } else if (change >= 100 && drawer.GetBillQuantity(Bills.One) > 0) { bills[6]++; change -= 100; drawer.RemoveBill(Bills.One, 1); } else if (change >= 50 && drawer.GetCoinQuantity(Coins.HalfDollar) > 0) { coins[0]++; change -= 50; drawer.RemoveCoin(Coins.HalfDollar, 1); } else if (change >= 25 && drawer.GetCoinQuantity(Coins.Quarter) > 0) { coins[1]++; change -= 25; drawer.RemoveCoin(Coins.Quarter, 1); } else if (change >= 10 && drawer.GetCoinQuantity(Coins.Dime) > 0) { coins[2]++; change -= 10; drawer.RemoveCoin(Coins.Dime, 1); } else if (change >= 5 && drawer.GetCoinQuantity(Coins.Nickel) > 0) { coins[3]++; change -= 5; drawer.RemoveCoin(Coins.Nickel, 1); } else if (change >= 1 && drawer.GetCoinQuantity(Coins.Nickel) > 0) { coins[4]++; change -= 1; drawer.RemoveCoin(Coins.Penny, 1); } } StringBuilder changeList = new StringBuilder(); changeList.Append("Give customer back:\n"); if (bills[0] > 0) { changeList.Append(bills[0].ToString() + " Hundred dollar bill(s)\n"); } if (bills[1] > 0) { changeList.Append(bills[1].ToString() + " Fifty dollar bill\n"); } if (bills[2] > 0) { changeList.Append(bills[2].ToString() + " Twenty dollar bill(s)\n"); } if (bills[3] > 0) { changeList.Append(bills[3].ToString() + " Ten dollar bill\n"); } if (bills[4] > 0) { changeList.Append(bills[4].ToString() + " Five dollar bill\n"); } if (bills[5] > 0) { changeList.Append(bills[5].ToString() + " Two dollar bill(s)\n"); } if (bills[6] > 0) { changeList.Append(bills[6].ToString() + " One dollar bill\n"); } if (coins[0] > 0) { changeList.Append(coins[0].ToString() + " Half-dollar\n"); } if (coins[1] > 0) { changeList.Append(coins[1].ToString() + " Quarter\n"); } if (coins[2] > 0) { changeList.Append(coins[2].ToString() + " Dime(s)\n"); } if (coins[3] > 0) { changeList.Append(coins[3].ToString() + " Nickel\n"); } if (coins[4] > 0) { changeList.Append(coins[4].ToString() + " Penny/Pennies\n"); } MessageBox.Show(changeList.ToString() + "\n"); } var printer = new ReceiptPrinter(); var sb = new StringBuilder(); var order = DataContext as Order; sb.Append("Order " + order.OrderNumber.ToString() + "\n"); sb.Append(DateTime.Today.ToString() + "\n"); foreach (IOrderItem item in list) { sb.Append(item.ToString() + "\t\t" + item.Price.ToString("c") + "\n"); if (item.SpecialInstructions != null) { foreach (string instruction in item.SpecialInstructions) { sb.Append("\t" + instruction + "\n"); } } } sb.Append("\nSubtotal:\t" + order.Subtotal.ToString("c") + "\n"); sb.Append("Total:\t" + TotalLabel.Text + "\n"); sb.Append("Cash\t" + TotalLabel.Text + "\n"); sb.Append("Change\t" + Change.ToString("c")); printer.Print(sb.ToString()); var screen = new MenuItemSelectionControl(); var orderControl = this.FindAncestor <OrderControl>(); if (orderControl == null) { throw new Exception("An ancestor of OrderControl expected be an OrderControl instead of null"); } orderControl.SwapScreen(screen); orderControl.DataContext = new Order(); }
/// <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; } }
/// <summary> /// Gets change and prints a receipt /// </summary> /// <param name="amount"></param> void GiveChange(double amount) { StringBuilder changegiven = new StringBuilder(); double change = Math.Round(Math.Abs(amount), 2); double changeprint = change; while (Math.Round(change, 2) != 0) { if (change >= 100 && drawer.Hundreds > 0) { drawer.RemoveBill(Bills.Hundred, 1); changegiven.Append("Hundred Bill \n"); change -= 100; } else if (change >= 50 && drawer.Fifties > 0) { drawer.RemoveBill(Bills.Fifty, 1); changegiven.Append("Fifty Bill \n"); change -= 50; } else if (change >= 20 && drawer.Twenties > 0) { drawer.RemoveBill(Bills.Twenty, 1); changegiven.Append("Twenty Bill \n"); change -= 20; } else if (change >= 10 && drawer.Tens > 0) { drawer.RemoveBill(Bills.Ten, 1); changegiven.Append("Ten Bill \n"); change -= 10; } else if (change >= 5 && drawer.Fives > 0) { drawer.RemoveBill(Bills.Five, 1); changegiven.Append("Five Bill \n"); change -= 5; } else if (change >= 1 && drawer.Ones > 0) { drawer.RemoveBill(Bills.One, 1); changegiven.Append("Dollar Bill \n"); change -= 1; } else if (change >= .5 && drawer.HalfDollars > 0) { drawer.RemoveCoin(Coins.HalfDollar, 1); changegiven.Append("Half Dollar \n"); change -= .50; } else if (change >= .25 && drawer.Quarters > 0) { drawer.RemoveCoin(Coins.Quarter, 1); changegiven.Append("Quarter \n"); change -= .25; } else if (change >= .1 && drawer.Dimes > 0) { drawer.RemoveCoin(Coins.Dime, 1); changegiven.Append("Dime \n"); change -= .10; } else if (change >= .05 && drawer.Nickels > 0) { drawer.RemoveCoin(Coins.Nickel, 1); changegiven.Append("Nickel \n"); change -= .05; } else if (change >= .01 && drawer.Pennies > 0) { drawer.RemoveCoin(Coins.Penny, 1); changegiven.Append("Penny \n"); change -= .01; } else if (drawer.Pennies == 0) { MessageBox.Show("Not Enough Change Adding a new registers worth"); drawer = new CashDrawer(); } else if (change < 0.00) { break; } } ReceiptPrinter printer = new ReceiptPrinter(); StringBuilder sb = new StringBuilder(); sb.Append("\n"); sb.Append("\nOrder Number " + neworder.OrderNumber.ToString()); string date = DateTime.Now.ToString(); sb.Append("\n" + date); foreach (IOrderItem item in neworder.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 " + neworder.Subtotal.ToString("C2")); sb.Append("\nTotal With Tax " + neworder.total.ToString("C2")); sb.Append("\nAmount Paid " + AmountAdded.ToString("C2")); sb.Append("\nChange Returned " + changeprint.ToString("C2")); printer.Print(sb.ToString()); MessageBox.Show("Receipt Printed"); DataContext = new Order(); var orderControl = this.FindAncestor <OrderControl>(); orderControl.SwapOrderScreen(new OrderControl()); }
/// <summary> /// Finds the smallest amout of changed needed to be given and removes bill from register /// </summary> /// <param name="totalOwed"></param> /// <returns></returns> public string FindChange(double change) { int give = 0; StringBuilder sb = new StringBuilder(); if (change == 0.00) { sb.Append("Exact amount given. No Change."); } else { give = (int)change / 100; if (view.Hundreds > 0 && change > 100) { if (give <= view.Hundreds) { sb.Append(give + "x Hundred Dollar Bill(s)\n"); change = change % 100; view.RemoveBill(Bills.Hundred, give); } } give = (int)change / 50; if (view.Fifties > 0 && change > 50) { if (give <= view.Fifties) { sb.Append(give + "x Fifty Dollar Bill(s)\n"); change = change % 50; view.RemoveBill(Bills.Fifty, give); } } give = (int)change / 20; if (view.Twenties > 0 && change > 20) { if (give <= view.Twenties) { sb.Append(give + "x Twenty Dollar Bill(s)n"); change = change % 20; view.RemoveBill(Bills.Twenty, give); } } give = (int)change / 10; if (view.Tens > 0 && change > 10) { if (give <= view.Tens) { sb.Append(give + "x Ten Dollar Bill(s)\n"); change = change % 10; view.RemoveBill(Bills.Ten, give); } } give = (int)change / 5; if (view.Fives > 0 && change > 5) { if (give <= view.Fives) { sb.Append(give + "x Five Dollar Bill(s)\n"); change = change % 5; view.RemoveBill(Bills.Five, give); } } give = (int)change / 2; if (view.Twos > 0 && change > 2) { if (give <= view.Twos) { sb.Append(give + "x Two Dollar Bill(s)\n"); change = change % 2; view.RemoveBill(Bills.Two, give); } } give = (int)change / 1; if (view.Ones > 0 && change > 1) { if (give <= view.Ones) { sb.Append(give + "x One Dollar Bill(s)\n"); change = change % 1; view.RemoveBill(Bills.One, give); } } give = (int)change / 1; if (view.Dollars > 0 && change > 1) { if (give <= view.Dollars) { sb.Append(give + "x One Dollar Coin(s)\n"); change = change % 1; view.RemoveCoin(Coins.Dollar, give); } } give = (int)(change / .5); if (view.HalfDollars > 0 && change > 0.5) { if (give <= view.HalfDollars) { sb.Append(give + "x Half Dollar Coin(s)\n"); change = change % .5; view.RemoveCoin(Coins.HalfDollar, give); } } give = (int)(change / .25); if (view.Quarters > 0 && change > 0.25) { if (give <= view.Quarters) { sb.Append(give + "x Quarter(s)\n"); change = change % .25; view.RemoveCoin(Coins.Quarter, give); } } give = (int)(change / .10); if (view.Dimes > 0 && change > 0.10) { if (give <= view.Dimes) { sb.Append(give + "x Dime(s)\n"); change = change % .10; view.RemoveCoin(Coins.Dime, give); } } give = (int)(change / .05); if (view.Nickels > 0 && change > 0.05) { if (give <= view.Nickels) { sb.Append(give + "x Nickel(s)\n"); change = change % .05; view.RemoveCoin(Coins.Nickel, give); } } give = (int)(change / .01); if (view.Pennies > 0 && change > 0.01) { if (give <= view.Pennies) { sb.Append(give + "x Penny(s)\n"); change = change % .01; view.RemoveCoin(Coins.Penny, give); } } if (view.Hundreds == 0 && view.Fifties == 0 && view.Twenties == 0 && view.Tens == 0 && view.Fives == 0 && view.Twos == 0 & view.Ones == 0 && view.Dollars == 0 && view.HalfDollars == 0 && view.Quarters == 0 && view.Dimes == 0 && view.Nickels == 0 && view.Pennies == 0) { sb.Append("Cannot give change. Please restock register cash amount and restart order."); } } return(sb.ToString()); }