/// <summary> /// Constructor for console cashier /// </summary> /// <param name="cm"></param> /// <param name="t"></param> /// <param name="rHan"></param> /// <param name="aHan"></param> /// <param name="cmHan"></param> /// <param name="cHan"></param> public ConsoleGUI(CashierModel cm, DateTime t, RemoveItemHandler rHan, AddItemHandler aHan, CompleteSaleHandler cmHan, CreateSaleHandler cHan) { _cm = cm; _rHan = rHan; _aHan = aHan; _cmHan = cmHan; _cHan = cHan; _date = t; }
/// <summary> /// Initializes the cashier GUI. /// </summary> /// <param name="cm">An instance of cashier model</param> /// <param name="t">The date for the cashier's sales</param> /// <param name="rHan">RemoveItemHandler delegate</param> /// <param name="aHan">AddItemHandler delegate</param> /// <param name="cmHan">CompleteSaleHandler delegate</param> /// <param name="cHan">CreateSaleHandler delegate</param> public CashierGUI(CashierModel cm, DateTime t, RemoveItemHandler rHan, AddItemHandler aHan, CompleteSaleHandler cmHan, CreateSaleHandler cHan) { InitializeComponent(); _cashierModel = cm; _itemsd = _cashierModel.GetItemsForSale(); uxItems.Columns.Add("Name", 93); uxItems.Columns.Add("Price", 93); uxCart.Columns.Add("Name", 93); uxCart.Columns.Add("Quantity", 93); uxCart.Columns.Add("Price", 92); date = t; _totCost = 0; this._rHan = rHan; this._aHan = aHan; this._cmHan = cmHan; this._cHan = cHan; foreach (KeyValuePair <string, double> k in _itemsd) { uxItems.Items.Add(new ListViewItem(new[] { k.Key, String.Format("{0:c}", k.Value) })); } }
static void Main(string[] args) { SalesDatabase db = new Sales501.SalesDatabase(); Console.WriteLine("\n 1) Cashier GUI \n"); Console.WriteLine(" 2) Customer Service \n"); Console.WriteLine(" 3) Rebate \n"); Console.WriteLine(" 4) Console GUI \n"); Console.WriteLine(" 5) Quit \n"); Console.WriteLine("------------------"); char a = '0'; while (a != '5') { Console.Write("Select an option: "); a = Console.ReadLine()[0]; switch (a) { case '1': Console.Write("\nEnter the date(MM/DD): "); DateTime date = new DateTime(); bool successfulDate = false; while (!successfulDate) { try { date = Convert.ToDateTime(Console.ReadLine()); successfulDate = true; } catch (Exception err) { Console.WriteLine("Enter a valid date."); } } CashierModel cm = new CashierModel(db); CashierController cc = new CashierController(cm); CashierGUI cg = new CashierGUI(cm, date, cc.handleRemoveItem, cc.handleAddItem, cc.handleCompleteSale, cc.handleCreateSale); cm.register(cg.update); var t = new Thread(() => cashGUI(cg)); t.Start(); break; case '2': CustomerServiceModel csm = new CustomerServiceModel(db); CustomerServiceController csc = new CustomerServiceController(csm); CustomerServiceGUI csGUI = new CustomerServiceGUI(csm, csc.HandleGetSale, csc.HandleReturnItem); csm.register(csGUI.update); var r = new Thread(() => servGUI(csGUI)); r.Start(); break; case '3': RebateModel rm = new RebateModel(db); RebateController rc = new RebateController(rm); RebateGUI rGUI = new RebateGUI(rm, rc.handleGenerateRebate, rc.handleEnterRebate); rm.register(rGUI.update); var re = new Thread(() => rebateGUI(rGUI)); re.Start(); break; case '4': ConsoleGUI(db); Console.Clear(); Console.WriteLine("\n 1) Cashier GUI \n"); Console.WriteLine(" 2) Customer Service \n"); Console.WriteLine(" 3) Rebate \n"); Console.WriteLine(" 4) Console GUI \n"); Console.WriteLine(" 5) Quit \n"); Console.WriteLine("------------------"); break; case '5': Application.Exit(); break; default: Console.WriteLine("Enter a number 1-5 \n"); a = Console.ReadLine()[0]; break; } } }
/// <summary> /// Initializes the controller /// </summary> /// <param name="cm">A Cashier Model instance</param> public CashierController(CashierModel cm) { _cashierModel = cm; }
/// <summary> /// Runs the ConsoleGUI /// </summary> /// <param name="db">the sales database</param> static void ConsoleGUI(SalesDatabase db) { Console.Clear(); Console.WriteLine("\n 1) Create Sale Transaction \n"); Console.WriteLine(" 2) Return Item \n"); Console.WriteLine(" 3) Rebate Request \n"); Console.WriteLine(" 4) Generate Rebate \n"); Console.WriteLine(" 5) Quit \n"); Console.WriteLine("------------------"); char a = '0'; RebateModel rm = null; RebateController rc = null; while (a != '5') { Console.Write("\n\nSelect an option: "); a = Console.ReadLine()[0]; switch (a) { case '1': Console.Write("\nEnter the date(MM/DD): "); DateTime date = new DateTime(); bool successfulDate = false; while (!successfulDate) { try { date = Convert.ToDateTime(Console.ReadLine()); successfulDate = true; } catch (Exception err) { Console.WriteLine("Enter a valid date."); } } CashierModel cm = new CashierModel(db); CashierController cc = new CashierController(cm); ConsoleGUI sales = new ConsoleGUI(cm, date, cc.handleRemoveItem, cc.handleAddItem, cc.handleCompleteSale, cc.handleCreateSale); sales.ListItems(); sales.AddItem(); break; case '2': CustomerServiceModel csm = new CustomerServiceModel(db); CustomerServiceController csc = new CustomerServiceController(csm); ConsoleGUI sc = new ConsoleGUI(csm, csc.HandleGetSale, csc.HandleReturnItem); sc.ReturnItem(); break; case '3': rm = new RebateModel(db); rc = new RebateController(rm); ConsoleGUI rebate = new ConsoleGUI(rm, rc.handleGenerateRebate, rc.handleEnterRebate); rebate.Rebate(); break; case '4': try { ConsoleGUI grebate = new ConsoleGUI(rm, rc.handleGenerateRebate, rc.handleEnterRebate); grebate.GenerateRebate(); } catch (Exception ex) { Console.WriteLine("Request Rebates first!"); } break; case '5': break; default: Console.WriteLine("Enter a number 1-5 \n"); a = Console.ReadLine()[0]; break; } } }