/// <summary> /// This is the Purchasing Menu. It contains Add Money, Select Products, and Complete Transaction options. /// </summary> public void PurchasingMenu() { bool done = false; while (!done) { Console.WriteLine("(1) Add Money"); Console.WriteLine("(2) Select Products"); Console.WriteLine("(3) Complete Transaction"); Console.WriteLine($"Current Account Balance: ${this.accounting.DisplayMoney()}"); string userInput = Console.ReadLine(); switch (userInput) { // Defaults to this if userInput is anything but 1, 2, or 3. default: Console.WriteLine("Please select an appropriate option."); break; //Add Money case "1": Console.Write("How much money would you like to add to your account? "); try { int amountToAdd = int.Parse(Console.ReadLine()); this.AddMoney(amountToAdd); files.AccountPurchasesLog(accounting, "Added", amountToAdd); } catch (FormatException ex) { Console.WriteLine("Please use whole number values only. " + "(" + ex.Message + ")"); } break; // Select Products case "2": if (accounting.DisplayMoney() == 0.00M) { Console.WriteLine("Please deposit money into your account before trying to make a purchase."); break; } Console.WriteLine("Which product would you like to add to your cart? "); string userProductCode = Console.ReadLine().ToUpper(); this.SelectProduct(userProductCode); break; // Complete Transaction case "3": DisplayPurchaseReport(); files.AccountPurchasesLog(accounting, "Change", 0); accounting.ResetBalance(); done = true; break; } } }
/// <summary> /// Write to Log file. This specifically deals with Money related prints -- Adding money and giving change. /// </summary> /// <param name="accounting"></param> /// <param name="inputType"></param> /// <param name="moneyAdded"></param> public void AccountPurchasesLog(Accounting accounting, string inputType, int moneyAdded) { using (StreamWriter writer = new StreamWriter(Path.Combine(filePath, "Log.txt"), true)) { switch (inputType) { case "Added": writer.WriteLine($"{DateTime.Now} ADD MONEY: {moneyAdded.ToString("C")} {accounting.DisplayMoney().ToString("C")}"); break; case "Change": writer.WriteLine($"{DateTime.Now} GIVE CHANGE: {accounting.DisplayMoney().ToString("C")} $0.00"); break; } } }
/// <summary> /// Write to Log file. This specifically deals with purchased items. /// </summary> /// <param name="cateringItem"></param> /// <param name="accounting"></param> /// <param name="purchasedQuantity"></param> public void PurchasesLog(CateringItem cateringItem, Accounting accounting, int purchasedQuantity) { using (StreamWriter writer = new StreamWriter(Path.Combine(filePath, "Log.txt"), true)) { writer.WriteLine($"{DateTime.Now} {purchasedQuantity} {cateringItem.Product} {cateringItem.ProductCode} {cateringItem.Price * purchasedQuantity} {accounting.DisplayMoney()}"); } }