public void ClearItemView() { if (_itemView == null) { return; } _itemView.Clear(); ItemViewFactory.i.FreeItemView(_itemView); }
private void NewItem() { view.Clear(); view.ShowMessage("Enter the product name:"); string prodname = Console.ReadLine(); while (prodname.Length < 2) { view.ShowError("Please enter a suitable length name"); prodname = Console.ReadLine(); } view.ShowMessage("Please enter the product description"); string proddesc = Console.ReadLine(); while (proddesc.Length < 5) { view.ShowError("Please enter a suitable length description"); } view.ShowMessage("Please enter the product price"); string prodprice = Console.ReadLine(); float price; while (!float.TryParse(prodprice, out (price))) { view.ShowError("Please enter a valid price."); prodprice = Console.ReadLine(); } view.ShowMessage("Please enter 0 for food (kitchen) item, or 1 for drink (bar) item:"); string prodtype = Console.ReadLine(); int itemType; bool status = int.TryParse(prodtype, out (itemType)); while (status == false || !(itemType == 1 || itemType == 0)) { view.ShowError("Please enter a valid option."); prodtype = Console.ReadLine(); status = int.TryParse(prodtype, out (itemType)); } // should have valid product specs. Lets create (and write): // get next valid item ID from the DB: int itemId = DBManager.GetNextProductId(); if (itemType == 1) { // drink item DrinkItem createdDrink = new DrinkItem(itemId, prodname, proddesc, price); itemManager.AddItem(createdDrink); DBManager.AddProduct(createdDrink); } else if (itemType == 0) { // food item FoodItem createdFood = new FoodItem(itemId, prodname, proddesc, price); itemManager.AddItem(createdFood); DBManager.AddProduct(createdFood); } else { // shouldn't get here. throw new ArgumentOutOfRangeException(); } Show(); }