//+++++++++++++++++++++++++++++++++++++ Stock Request Checking - OPTION 2 & 3 ++++++++++++++++++++++++++++++++++++++++++++++++++++// private void RequestSend(List <StockRequest> stockRequest, List <StoreInv> storeStock, Store store, int threshNum) { Console.WriteLine(); bool loop = true; while (loop) { Console.WriteLine("Enter ID to Add to Store Inventory or 'quit' to Return to Store Menu: "); string sID = Console.ReadLine(); //quit functioning if (sID.Equals("quit", StringComparison.InvariantCultureIgnoreCase) || sID.Equals("q", StringComparison.InvariantCultureIgnoreCase)) { loop = false; Console.Clear(); } else { int id; //int checking bool result = Int32.TryParse(sID, out id);; if (!result) { Console.WriteLine("Invalid Input\n"); } else { // gets last request's ID and increments to give new stock_request ID int idcount; StockRequest lastRequest = stockRequest[stockRequest.Count() - 1]; idcount = lastRequest.ID; idcount++; bool idFound = false; foreach (StoreInv storeInv in storeStock) { //check user ID matches a store_inventory ID if (id == storeInv.ID) { idFound = true; //checks if enough stock, if so warn user if (threshNum <= storeInv.Quantity) { while (loop) { Console.WriteLine("WARNING: store has enough stock, do you wish to continue? (yes/no)"); string cont = Console.ReadLine(); //user wishes to continue even with enough stock available if (cont.Equals("yes", StringComparison.InvariantCultureIgnoreCase) || cont.Equals("y", StringComparison.InvariantCultureIgnoreCase)) { while (loop) { //stock request will sent - functionality loop = SentRequest(stockRequest, storeInv, store, idcount); } } else if (cont.Equals("no", StringComparison.InvariantCultureIgnoreCase) || cont.Equals("n", StringComparison.InvariantCultureIgnoreCase)) { loop = false; Console.Clear(); break; } else { Console.WriteLine("Invalid Input\n"); } } } else { //stock request will sent - functionality loop = SentRequest(stockRequest, storeInv, store, idcount); } } } if (!idFound) { Console.WriteLine("Invalid Input!\n"); } } } } }
//+++++++++++++++++++++++++++++++++++++ Adding New Product to Store Inventory - OPTION 3 ++++++++++++++++++++++++++++++++++++++++++++++++++++// private void PrintItems(List <OwnerStock> ownerInv, List <StoreInv> storeInv, Store store, List <StockRequest> stockRequest) { Console.WriteLine(); Console.WriteLine("ID\tProduct\t\tCurrent Stock"); Console.WriteLine("_____________________________________"); List <OwnerStock> tempList = new List <OwnerStock>(); foreach (OwnerStock ownerStock in ownerInv) { bool found = false; foreach (StoreInv storeStock in storeInv) { if (ownerStock.Product == storeStock.Product) { found = true; break; } } if (!found) { Console.WriteLine("{0}\t{1}\t\t{2}", ownerStock.ID, ownerStock.Product, ownerStock.StockLevel); } } Console.WriteLine(); bool flag = true; while (flag) { // user input // Console.WriteLine("Enter Product ID to Add Product to Store or 'quit' to Return to Store Menu: "); string sID = Console.ReadLine(); if (sID.Equals("quit", StringComparison.InvariantCultureIgnoreCase) || sID.Equals("q", StringComparison.InvariantCultureIgnoreCase)) { flag = false; Console.Clear(); } else { int id; // error handle int converstion bool result = Int32.TryParse(sID, out id); if (!result) { Console.WriteLine("Invalid Input!\n"); } else { int count; bool idMatch = false; bool notFound = false; // temporary lists which alter json files List <StockRequest> stockReqs = stockRequest; List <StoreInv> tempStoreInv = storeInv; foreach (OwnerStock ownerStock in ownerInv) { // checking user input ID matches owner_inventory IDs if (id == ownerStock.ID) { idMatch = true; // checking user selected owner_inventory product is not in chosen store_inventory foreach (StoreInv storeStock in storeInv) { if (storeStock.Product == ownerStock.Product) { notFound = true; break; } } // if product is not in store_inventory if (!notFound) { // add product to store_inventory with no Quantity tempStoreInv.Add(new StoreInv() { ID = ownerStock.ID, Product = ownerStock.Product, Quantity = 0 }); json.WriteStoreStock(tempStoreInv, store); // gets last request's ID and increments to give new stock_request ID StockRequest lastRequest = stockRequest[stockRequest.Count() - 1]; count = lastRequest.ID; count++; // add request to give Quantity of 3 of newly added product to store_inventory // to be approved by Owner stockReqs.Add(new StockRequest() { ID = count, StoreName = store.StoreName, Product = ownerStock.Product, Quantity = 3 }); json.WriteRequests(stockReqs); // return to Franchise menu with success message flag = false; Console.Clear(); Console.WriteLine("Item Added\n"); break; } else { Console.WriteLine("Invalid Input\n"); break; } } } if (!idMatch) { Console.WriteLine("Invalid Input!\n"); } } } } }