public void RemoveProductFromListIfPossible(Coordinates currentCoordinates) { Coordinates lCoords = new Coordinates(currentCoordinates.x, currentCoordinates.y - 1); Coordinates rCoords = new Coordinates(currentCoordinates.x, currentCoordinates.y + 1); if (!ShopMap.ContainsKey(lCoords) || !ShopMap.ContainsKey(rCoords)) { return; } if (IsTheItemOnListOfProductLeft(currentCoordinates)) { foreach (var c in ListOfProducts.ToList()) { if (c.NameOfProduct.StateOfCell == ShopMap[lCoords].StateOfCell) { ListOfProducts.Remove(c); } } } if (IsTheItemOnListOfProductRight(currentCoordinates)) { foreach (var c in ListOfProducts.ToList()) { if (c.NameOfProduct.StateOfCell == ShopMap[rCoords].StateOfCell) { ListOfProducts.Remove(c); } } } }
public bool CheckTopAlleyRight(Coordinates current) { Coordinates check = new Coordinates(current.x, current.y + 1); if (!ShopMap.ContainsKey(check)) { return(false); } int column = current.y + 1; bool isThere = false; List <CellState> cellsProducts = new List <CellState>(); var subCells = ShopMap.Select(i => i.Key).Where(d => d.y == column && d.x <= current.x).ToList(); for (int i = 0; i < subCells.Count(); i++) { cellsProducts.Add(ShopMap[subCells[i]]); } foreach (CellState s in cellsProducts) { if (ListOfProducts.Contains(new Product(s))) { isThere = true; } } return(isThere); }
private void Clear() { DishName.Clear(); ProductPlus.Clear(); ProductCounter.Clear(); ListOfProducts.Clear(); TextOfrepice.Clear(); }
public InvoiceManager() { listOfInvoice = new ListOfInvoice(); listOfProducts = new ListOfProducts(); listOfCustomers = new ListOfCustomers(); listOfInvoice.Load(listOfCustomers, listOfProducts); }
public void SendProduct(Product product, int count) { if (ListOfProducts.Find(x => product.Id == x) >= 0) { product.SetCount(product.Count + count); GeneralInfo.DataProvider.UpdateProduct(product); } }
public void SeeIfProductIsAdded() { ListOfProducts productList = new ListOfProducts(new List <Product>() { new Product(1, "Mælk", "l", "Food") }, null); Assert.AreEqual(productList.NumberOfProducts, 1); }
public void SeeIfProductByIDReturnsNullIfProductDoesNotExist() { List <Product> products = new List <Product>() { new Product(1, "Mælk", "l", "Food"), new Product(2, "Kage", "kg", "Snack") }; ListOfProducts productlist = new ListOfProducts(products, null); Assert.AreEqual(productlist.FindProductByID(1).PrimaryProductName, "Mælk"); }
/// <summary> /// Function clear some user elements. /// </summary> private void Clear() { Cursor.Current = Cursors.Arrow; DishName.Clear(); ProductPlus.Clear(); ProductCounter.Clear(); ListOfProducts.Clear(); TextOfrepice.Clear(); Cursor.Current = Cursors.Arrow; }
public Product RunToGetProduct() { bool exit = false; ListOfProducts listOfProducts = new ListOfProducts(); int currentRecord = 0; string separator = new string('_', Console.WindowWidth); do { Console.Clear(); EnhancedConsole.WriteAt(0, 0, "PRODUCTSS " + (currentRecord + 1).ToString("000") + "/" + listOfProducts.Amount.ToString("000"), "white"); EnhancedConsole.WriteAt(0, 1, separator, "gray"); WriteProduct(listOfProducts, currentRecord); EnhancedConsole.WriteAt(0, Console.WindowHeight - 4, separator, "gray"); EnhancedConsole.WriteAt(0, Console.WindowHeight - 3, "1.-Previous Product" + " 2.-Next Product" + " 3.-Search", "white"); EnhancedConsole.WriteAt(0, Console.WindowHeight - 2, "PRESS ENTER TO SELECT THE PRODUCT", "white"); switch (Console.ReadKey().Key) { case ConsoleKey.LeftArrow: case ConsoleKey.NumPad1: case ConsoleKey.D1: //Previus if (currentRecord != 0) { currentRecord--; } break; case ConsoleKey.RightArrow: case ConsoleKey.NumPad2: case ConsoleKey.D2: //Next //I cant allProducts[count+1] != null if (currentRecord != listOfProducts.Amount - 1) { currentRecord++; } break; case ConsoleKey.NumPad3: case ConsoleKey.D3: //Search SearchByText(listOfProducts, ref currentRecord); break; case ConsoleKey.Enter: exit = true; break; } } while (!exit); return(listOfProducts.Get(currentRecord)); }
public virtual void AddSomeItems() { Random rand = new Random(); int j = rand.Next(1, 3); for (int i = 0; i < j; i++) { ListOfProducts.Add(new Item()); System.Threading.Thread.Sleep(50); } }
public IActionResult HandleReceipt() { if (ListOfProducts.getListOfProducts().Count == 0) { return(RedirectToAction("noProductsSelected", "Error")); } ReceiptViewModel rvm = new ReceiptViewModel(); rvm.products = ListOfProducts.getListOfProducts(); return(View(rvm)); }
public void TestIfRightAmountOfLines() { List <Product> products = new List <Product>() { new Product(1, "Mælk", "l", "Food"), new Product(2, "Kage", "kg", "Snack") }; ListOfProducts listOfProducts = new ListOfProducts(products, null); ListOfTransactions transactions = new ListOfTransactions(ReadFromFiles.ReadFromTransactionFileToListOfTransactions(validTransactionFileWithTwoTransactions, listOfProducts, null), null); Assert.AreEqual(transactions.NumberOfTransactions, 2); }
public void HelpMenuAndControl(ListOfProducts listOfProducts, int countProducts, string separator) { string[] help = { "This text gives help", "This one helps too", "This one its even longer, so we need to check if the " + "string its too long" }; int count = 0; bool exit = false; do { Console.Clear(); EnhancedConsole.WriteAt(0, 0, "productS " + (count + 1).ToString("000") + "/" + listOfProducts.Amount.ToString("000"), "white"); EnhancedConsole.WriteAt(0, 1, separator, "gray"); WriteProduct(listOfProducts, countProducts); EnhancedConsole.WriteAt(0, Console.WindowHeight - 4, separator, "gray"); EnhancedConsole.WriteAt(0, Console.WindowHeight - 3, "1.-Previous Product" + " 2.-Next Product" + " 3.-Search by record" + " 4.-Search" + " 5.-Add Product", "white"); EnhancedConsole.WriteAt(0, Console.WindowHeight - 2, "6.-Edit record" + " 0.-Exit F1.-Help", "white"); Console.BackgroundColor = ConsoleColor.Red; EnhancedConsole.DrawWindow(Console.WindowWidth / 4, Console.WindowHeight / 4, help[count]); Console.BackgroundColor = ConsoleColor.DarkBlue; switch (Console.ReadKey().Key) { case ConsoleKey.LeftArrow: if (count != 0) { count--; } break; case ConsoleKey.RightArrow: if (count != help.Length - 1) { count++; } break; case ConsoleKey.Escape: exit = true; break; } } while (!exit); }
public void TestIfRightTransactionsIsMade() { List <Product> products = new List <Product>() { new Product(1, "Mælk", "l", "Food"), new Product(2, "Kage", "kg", "Snack") }; ListOfProducts listOfProducts = new ListOfProducts(products, null); ListOfTransactions transactions = new ListOfTransactions(ReadFromFiles.ReadFromTransactionFileToListOfTransactions(validTransactionFileWithTwoTransactions, listOfProducts, null), null); Assert.AreEqual(transactions.FindTransactionByID(1).AmountOfMoney, 10); }
public void SeeIfProductByIDWorksByProductType() { List <Product> products = new List <Product>() { new Product(1, "Mælk", "l", "Food"), new Product(2, "Kage", "kg", "Snack") }; ListOfProducts productlist = new ListOfProducts(products, null); Product foundProduct = productlist.FindProductByID(1); //See if the product found is the same as the expected Assert.IsTrue(foundProduct.TypeOfProduct == "Food"); }
// Using bind to prevent overposting. public IActionResult CreateReceipt([Bind("name", "address", "city")] ReceiptViewModel receiptvm) { if (ModelState.IsValid) { Receipt finalreceipt = new Receipt(); finalreceipt.city = receiptvm.city; finalreceipt.address = receiptvm.address; finalreceipt.name = receiptvm.name; finalreceipt.products = Utitlities.getProductsInHtml(); finalreceipt.totalPrice = Utitlities.getTotalPrice(); context.Receipts.Add(finalreceipt); context.SaveChanges(); ListOfProducts.clear(); return(View(finalreceipt)); } return(RedirectToAction("errorCreatingReceipt", "Error")); }
/// <summary> /// Displays the parameters of the recipe. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RecipesTreeView_AfterSelect(object sender, TreeViewEventArgs e) { Cursor.Current = Cursors.Arrow; if (!product.MyDishes(RecipesTreeView.SelectedNode.Text)) { DishName.Text = product.dishName; ListOfProducts.Clear(); for (int i = 0; i < product.dishProductsName.Count; i++) { ListOfProducts.Text += $"{product.dishProductsName[i]} - {product.dishProductCounter[i]} {product.dishProductsDim[i]}\r\n"; } TextOfrepice.Text = product.dishRecipe; } Cursor.Current = Cursors.Arrow; }
public IActionResult RegisterOrder(ProductViewModel productvm) { // Clear the list of products, incase the user redirects to Home. ListOfProducts.clear(); // Check that atleast one product is ordered. bool oneProductOrdered = oneProductIsAtleastOrdered(productvm); if (ModelState.IsValid && oneProductOrdered) { ICollection <Product> myproducts = new List <Product>(); Product bread = new Bread(productvm.AmountOfBread); Product juice = new Juice(productvm.AmountOfJuice); ListOfProducts.addProduct(bread); ListOfProducts.addProduct(juice); return(RedirectToAction("handleReceipt", "Receipt")); } return(RedirectToAction("orderError", "Error")); }
public bool IsTheItemOnListOfProductLeft(Coordinates currentCoordinates) { Coordinates check = new Coordinates(currentCoordinates.x, currentCoordinates.y - 1); if (!ShopMap.ContainsKey(check)) { return(false); } bool isThere = false; Coordinates cords = new Coordinates(currentCoordinates.x, currentCoordinates.y - 1); ShopMap.TryGetValue(cords, out CellState cell); foreach (var products in ListOfProducts) { if (ListOfProducts.Contains(new Product(cell))) { isThere = true; } } return(isThere); }
public void SearchByNumber(ListOfProducts list, ref int count) { string numberSTR; ushort number; do { Console.Clear(); Console.SetCursorPosition(0, 10); EnhancedConsole.WriteAt(0, 10, "Enter the number you are looking for", "white"); numberSTR = EnhancedConsole.GetAt(0, 11, 3); }while (!UInt16.TryParse(numberSTR, out number)); if (number > 0 && number <= list.Amount) { count = number - 1; } else { EnhancedConsole.WriteAt(0, 10, "Wrong Number!", "white"); Console.ReadLine(); } }
private static void WriteProduct(ListOfProducts listOfProducts, int count) { int y = 5; EnhancedConsole.WriteAt(0, y, "CODE: ", "gray"); EnhancedConsole.WriteAt(15, y, listOfProducts.Get(count).GetCode(), "white"); y++; EnhancedConsole.WriteAt(0, y, "DESCRIPTION: ", "gray"); EnhancedConsole.WriteAt(15, y, listOfProducts.Get(count).GetDescription(), "white"); y++; EnhancedConsole.WriteAt(0, y, "CATEGORY: ", "gray"); EnhancedConsole.WriteAt(15, y, listOfProducts.Get(count).GetCategory(), "white"); y++; EnhancedConsole.WriteAt(0, y, "SELL PRICE: ", "gray"); EnhancedConsole.WriteAt(15, y, listOfProducts.Get(count).GetSellPrice() .ToString() + "$", "white"); y++; EnhancedConsole.WriteAt(0, y, "BUY PRICE: ", "gray"); EnhancedConsole.WriteAt(15, y, listOfProducts.Get(count).GetBuyPrice() .ToString() + "$", "white"); y++; EnhancedConsole.WriteAt(0, y, "STOCK: ", "gray"); EnhancedConsole.WriteAt(15, y, listOfProducts.Get(count).GetStock() .ToString(), "white"); y++; EnhancedConsole.WriteAt(0, y, "MINIMUM STOCK: ", "gray"); EnhancedConsole.WriteAt(15, y, listOfProducts.Get(count).GetMinStock() .ToString(), "white"); y++; }
public void Run() { bool exit = false; ListOfProducts listOfProducts = new ListOfProducts(); string separator = new string('_', Console.WindowWidth); do { Console.Clear(); EnhancedConsole.WriteAt(0, 0, "PRODUCTSS " + (currentRecord + 1).ToString("000") + "/" + listOfProducts.Amount.ToString("000"), "white"); EnhancedConsole.WriteAt(0, 1, separator, "gray"); WriteProduct(listOfProducts, currentRecord); EnhancedConsole.WriteAt(0, Console.WindowHeight - 4, separator, "gray"); EnhancedConsole.WriteAt(0, Console.WindowHeight - 3, "1.-Previous" + " 2.-Next" + " 3.-Number" + " 4.-Search" + " 5.-Add", "white"); EnhancedConsole.WriteAt(0, Console.WindowHeight - 2, "6.-Edit record" + " 0.-Exit A.-Advanced F1.-Help", "white"); EnhancedConsole.ShowClock(); switch (Console.ReadKey().Key) { case ConsoleKey.LeftArrow: case ConsoleKey.NumPad1: case ConsoleKey.D1: //Previus if (currentRecord != 0) { currentRecord--; } break; case ConsoleKey.RightArrow: case ConsoleKey.NumPad2: case ConsoleKey.D2: //Next //I cant allProducts[currentRecord+1] != null if (currentRecord != listOfProducts.Amount - 1) { currentRecord++; } break; case ConsoleKey.NumPad3: case ConsoleKey.D3: //Search by number SearchByNumber(listOfProducts, ref currentRecord); break; case ConsoleKey.NumPad4: case ConsoleKey.D4: //Search by text SearchByText(listOfProducts, ref currentRecord); break; case ConsoleKey.NumPad5: case ConsoleKey.D5: //Add Product Console.Clear(); listOfProducts.Add(GetDataToCreateProduct()); break; case ConsoleKey.NumPad6: case ConsoleKey.D6: //EDIT Modify(listOfProducts, currentRecord); break; case ConsoleKey.A: AdvancedMenu(); break; case ConsoleKey.F1: HelpMenuAndControl(listOfProducts, currentRecord, separator); break; case ConsoleKey.NumPad0: case ConsoleKey.D0: //EXIT exit = true; break; } } while (!exit); }
public decimal TotalPrice() { return(ListOfProducts.Sum(product => product.Price)); }
public void Modify(ListOfProducts listOfProducts, int count) { int y = 5; Console.Clear(); Console.SetCursorPosition(0, Console.WindowHeight - 2); Console.WriteLine("To not change something, just press Enter"); Console.SetCursorPosition(0, 5); string aux; aux = listOfProducts.Get(count).GetCode(); EnhancedConsole.WriteAt(0, y, "Code: " + listOfProducts.Get(count).GetCode() .ToString(), "white"); y++; string code = EnhancedConsole.GetAt(0, y, 20); if (code == "") { code = aux; } listOfProducts.Get(count).SetCode(code); y++; aux = listOfProducts.Get(count).GetDescription(); EnhancedConsole.WriteAt(0, y, "Description: " + listOfProducts.Get(count).GetDescription() .ToString(), "white"); y++; string description = EnhancedConsole.GetAt(0, y, 10); if (description == "") { description = aux; } listOfProducts.Get(count).SetDescription(description); y++; aux = listOfProducts.Get(count).GetCategory(); EnhancedConsole.WriteAt(0, y, "Category: " + listOfProducts.Get(count).GetCategory() .ToString(), "white"); y++; string category = EnhancedConsole.GetAt(0, y, 10); if (category == "") { category = aux; } listOfProducts.Get(count).SetCategory(category); y++; double auxDouble = listOfProducts.Get(count).GetSellPrice(); EnhancedConsole.WriteAt(0, y, "Sell Price: " + listOfProducts.Get(count).GetSellPrice() .ToString(), "white"); y++; string sellPriceSTR; double sellPrice; do { sellPriceSTR = EnhancedConsole.GetAt(0, y, 9); } while ((!Double.TryParse(sellPriceSTR, out sellPrice)) && sellPriceSTR != ""); if (sellPriceSTR == "") { sellPrice = auxDouble; } listOfProducts.Get(count).SetSellPrice(sellPrice); y++; auxDouble = listOfProducts.Get(count).GetBuyPrice(); EnhancedConsole.WriteAt(0, y, "Buy Price: " + listOfProducts.Get(count).GetBuyPrice() .ToString(), "white"); y++; string buyPriceSTR; double buyPrice; do { buyPriceSTR = EnhancedConsole.GetAt(0, y, 9); } while ((!Double.TryParse(buyPriceSTR, out buyPrice)) && buyPriceSTR != ""); if (buyPriceSTR == "") { buyPrice = auxDouble; } listOfProducts.Get(count).SetBuyPrice(buyPrice); y++; uint auxUINT = listOfProducts.Get(count).GetStock(); EnhancedConsole.WriteAt(0, y, "Stock: " + listOfProducts.Get(count).GetStock() .ToString(), "white"); y++; string stockSTR; uint stock; do { stockSTR = EnhancedConsole.GetAt(0, y, 9); } while ((!UInt32.TryParse(stockSTR, out stock)) && stockSTR != ""); if (stockSTR == "") { stock = auxUINT; } listOfProducts.Get(count).SetStock(stock); y++; auxUINT = listOfProducts.Get(count).GetMinStock(); EnhancedConsole.WriteAt(0, y, "Minimum Stock: " + listOfProducts.Get(count).GetMinStock() .ToString(), "white"); y++; string minStockSTR; uint minStock; do { minStockSTR = EnhancedConsole.GetAt(0, y, 9); } while ((!UInt32.TryParse(minStockSTR, out minStock)) && minStockSTR != ""); if (minStockSTR == "") { minStock = auxUINT; } listOfProducts.Get(count).SetMinStock(minStock); y++; }
public void SearchByText(ListOfProducts listOfProducts, ref int count) { Console.Clear(); EnhancedConsole.WriteAt(0, 10, "What are you looking for?", "white"); string search = EnhancedConsole.GetAt(0, 11, 15); search = search.ToLower(); bool found = false; do { if (listOfProducts.Get(count).GetCode().ToLower(). Contains(search) || listOfProducts.Get(count).GetDescription().ToLower(). Contains(search) || listOfProducts.Get(count).GetCategory().ToLower(). Contains(search) || listOfProducts.Get(count).GetSellPrice().ToString(). Contains(search) || listOfProducts.Get(count).GetBuyPrice().ToString(). Contains(search)) { found = true; Console.Clear(); EnhancedConsole.WriteAt(0, 10, "Found on the record " + (count + 1).ToString("000"), "yellow"); Console.ReadLine(); count--; } count++; }while (!found && count < listOfProducts.Amount - 1); if (!found) { Console.Clear(); EnhancedConsole.WriteAt(0, 10, "Not Found!", "red"); EnhancedConsole.WriteAt(0, 12, "Do you want to search from the first record?", "white"); count = 0; if (Console.ReadKey().Key == ConsoleKey.Y) { do { if (listOfProducts.Get(count).GetCode().ToLower(). Contains(search) || listOfProducts.Get(count).GetDescription().ToLower(). Contains(search) || listOfProducts.Get(count).GetCategory().ToLower(). Contains(search) || listOfProducts.Get(count).GetSellPrice().ToString(). Contains(search) || listOfProducts.Get(count).GetBuyPrice().ToString(). Contains(search)) { found = true; Console.Clear(); EnhancedConsole.WriteAt(0, 10, "Found on the record " + (count + 1).ToString("000"), "yellow"); Console.ReadLine(); count--; } count++; }while (!found && count < listOfProducts.Amount - 1); if (!found) { Console.Clear(); EnhancedConsole.WriteAt(0, 10, "Not Found!", "red"); Console.ReadLine(); count = 0; } } } }
public ProductManager() { listOfProducts = new ListOfProducts(); currentRecord = 0; }
public ShowRoomViewModel() { //_connection = DependencyService.Get<ISQLiteConnectionService>().GetConnection(); //_unitOfWork = new UnitOfWork(_connection); ProductList = new ListOfProducts(); }
public virtual void AddItem(Item a) { ListOfProducts.Add(a); }
public virtual void AddProduct(Product.Product product, int volume) { ListOfProducts.Add(new Item(product, volume)); }
public void Load(ListOfCustomers customers, ListOfProducts products) { DirectoryInfo d = new DirectoryInfo("invoices/"); foreach (FileInfo f in d.GetFiles("*.dat")) { StreamReader invoicesInput = new StreamReader(f.FullName); string line; string[] invoicessAux; int invoiceMax = 1; try { do { line = invoicesInput.ReadLine(); if (line != null) { invoicessAux = line.Split(';'); int invoiceNumber = Int32.Parse(invoicessAux[0]); if (invoiceNumber > invoiceMax) { invoiceMax = invoiceNumber; } Invoice.invoiceCount = invoiceMax; string[] dateAux = invoicessAux[1].Split('/'); DateTime date = new DateTime(Int32.Parse(dateAux[2]), Int32.Parse(dateAux[1]), Int32.Parse(dateAux[0])); string key = invoicessAux[2]; int countCustomers = 0; bool found = false; do { if (key == customers.Get(countCustomers).GetKey()) { found = true; countCustomers--; } countCustomers++; }while (countCustomers < customers.Amount && !found); myInvoices.Add(new Invoice(invoiceNumber, date, customers.Get(countCustomers))); Product p; string code; double price; int amount; int countProduct; if (invoicessAux.Length > 3) { for (int i = 3; i < invoicessAux.Length; i += 3) //We start at 1, to not get out of the array size { countProduct = 0; found = false; code = invoicessAux[i]; do { if (code == products.Get(countProduct).GetCode()) { found = true; countProduct--; } countProduct++; }while (countProduct < products.Amount && !found); p = products.Get(countProduct); amount = Int32.Parse(invoicessAux[i + 1]); price = Double.Parse(invoicessAux[i + 2]); myInvoices.Last().AddLine(p, amount, price); } } } }while (line != null); invoicesInput.Close(); } catch (PathTooLongException) { Console.WriteLine("Error: Path Too Long."); throw; } catch (FileNotFoundException) { Console.WriteLine("Error: File not found."); throw; } catch (IOException e) { Console.WriteLine("I/O error: " + e); throw; } catch (Exception e) { Console.WriteLine("Error: " + e); throw; } } }