public override void ViewStoreProducts(double threshold = 0) { if (!StoreList.isEmpty()) { if (threshold >= 0) { StoreList.ViewStoreList(false); } } else { Console.WriteLine("Store is empty!"); } }
private void Search() { if (StoreList.isEmpty()) { Console.WriteLine("Store is empty, nothing to search for!"); return; } Dictionary <int, string> categories = new Dictionary <int, string>(); int idx = 1; foreach (Product p in StoreList.List.Values) { if (!categories.ContainsValue(p.ProductCategory) && p.ProductQuantity > 0) { categories.Add(idx++, p.ProductCategory); } } if (categories.Count == 0) { Console.WriteLine("Store is empty, nothing to search for!"); return; } foreach (KeyValuePair <int, string> d in categories) { Console.WriteLine(d.Key + ". " + d.Value); } try { Console.Write("Enter your choice(1-{0}): ", categories.Count); int choice = Convert.ToInt32(Console.ReadLine()); if (!(choice >= 1 && choice <= categories.Count)) { throw new FormatException(); } Console.WriteLine("{0,-25} {1,-25} {2,-25} {3,-10} {4,-10}", "ID", "Name", "Category", "Price", "Quantity"); foreach (Product p in StoreList.List.Values) { if (p.ProductCategory == categories[choice] && p.ProductQuantity > 0) { p.Print(); } } } catch (FormatException) { Console.WriteLine("Wrong value entered or category doesn\'t exist!"); } }
public override void AddProduct() { if (StoreList.isEmpty()) { Console.WriteLine("Store is empty!"); return; } Console.WriteLine("Available products"); StoreList.ViewStoreList(false); Console.WriteLine("Products in basket"); Basket.ViewBasket(); Console.Write("Enter product ID to add to basket: "); string tempID = Console.ReadLine(); try { Product temp = StoreList.GetProduct(tempID).Clone(); if (temp.ProductQuantity == 0) { throw new NullReferenceException(); } Console.Write("Enter quantity: "); double uquan = Convert.ToDouble(Console.ReadLine()); if (uquan < 0) { throw new FormatException(); } if (temp.ProductQuantity - uquan >= 0) { temp.ProductQuantity = uquan; StoreList.GetProduct(tempID).ProductQuantity -= uquan; Basket.Add(temp, uquan); SaveUser(); } else { Console.WriteLine("Desired quantity is unavailable!"); } } catch (NullReferenceException) { Console.WriteLine("Product doesn\'t exist!"); } catch (FormatException) { Console.WriteLine("Wrong value entered!"); } }
public override void ViewStoreProducts(double threshold) { if (StoreList.isEmpty()) { Console.WriteLine("Store is empty!"); return; } if (threshold > 0) { Console.WriteLine("{0,-25} {1,-25} {2,-25} {3,-10} {4,-10}", "ID", "Name", "Category", "Price", "Quantity"); foreach (Product p in StoreList.List.Values) { if (p.ProductQuantity >= threshold) { p.Print(); } } } else { Console.WriteLine("Wrong value entered!"); } }