/// <summary> /// Shows and returns all products from the database /// </summary> /// <returns>product database</returns> private static ProductsDatabase ShowProducts() { Output(welcomeText); ShowCredit(); ProductsDatabase products = new ProductsDatabase(); Output(products.Show()); return(products); }
/// <summary> /// Start machine logic /// </summary> public static void StartMachine() { Console.Clear(); bool end = false; do { ProductsDatabase products = ShowProducts(); Pay(); if (isAdmin) { AdminLogic.StartAdminLogic(); } ShowCredit(); Output(products.Show()); ChooseProduct(products); EndTransaction(); end = true; } while (!end); Pause(); }
/// <summary> /// Delete product record from database /// </summary> public static void DeleteProduct() { int input = -1; bool correctInput = false; int actionChoice = -1; Console.Clear(); ProductsDatabase products = new ProductsDatabase(); Console.WriteLine(products.ShowAdmin()); do { Console.WriteLine("Wybierz produkt który chcesz usunąć " + adminName); try { input = int.Parse(Console.ReadLine()); if (input > 0) { correctInput = true; } else { correctInput = false; } } catch (System.FormatException) { correctInput = false; } } while (!correctInput); Console.WriteLine(adminName + " Czy chcesz usunąć produkt numer " + input + "?\n" + "1 - Tak\n" + "2 - Nie\n" + "3 - Chce usunąć inny produkt"); do { try { actionChoice = int.Parse(Console.ReadLine()); if (actionChoice > 0) { correctInput = true; } else { correctInput = false; } } catch (System.FormatException) { correctInput = false; } }while (!correctInput); switch (actionChoice) { case 1: ProductsDatabase.DeleteProduct(input, products); Console.WriteLine("Skasowano"); Thread.Sleep(2500); StartAdminLogic(); break; case 2: StartAdminLogic(); break; case 3: DropProduct(); break; default: Console.WriteLine("Coś poszło nie tak!"); Thread.Sleep(2500); StartAdminLogic(); break; } }
/// <summary> /// Drops product quantity /// </summary> public static void DropProduct() { int input = -1; bool correctInput = false; int quantity = -1; int actionChoice = -1; int prod = 0; Console.Clear(); ProductsDatabase products = new ProductsDatabase(); Console.WriteLine(products.ShowAdmin()); do { Console.WriteLine("Wybierz produkt którego ilość chcesz zmniejszyć " + adminName); try { input = int.Parse(Console.ReadLine()); if (input > 0) { prod = input; correctInput = true; } else { correctInput = false; } } catch (System.FormatException) { correctInput = false; } } while (!correctInput); do { Console.WriteLine("Ile sztuk chcesz wyjąć? " + adminName); try { quantity = int.Parse(Console.ReadLine()); if (quantity > 0) { correctInput = true; } else { correctInput = false; } } catch (System.FormatException) { correctInput = false; } } while (!correctInput); long productQuantity = (products.Products[prod - 1].Quantity); if (quantity <= productQuantity) { Console.WriteLine(adminName + " Czy chcesz wyjąć " + quantity + " sztuk produktu numer " + input + "?\n" + "1 - Tak\n" + "2 - Nie\n" + "3 - Chce wyjąć inny produkt"); do { try { actionChoice = int.Parse(Console.ReadLine()); if (actionChoice > 0) { correctInput = true; } else { correctInput = false; } } catch (System.FormatException) { correctInput = false; } } while (!correctInput); switch (actionChoice) { case 1: ProductsDatabase.DropQuantity(input, quantity, products); Console.WriteLine("Wyjęto"); Thread.Sleep(2500); StartAdminLogic(); break; case 2: StartAdminLogic(); break; case 3: DropProduct(); break; default: Console.WriteLine("Coś poszło nie tak!"); Thread.Sleep(2500); StartAdminLogic(); break; } } else { Console.WriteLine("Nie możesz wyjąć więcej produktów niż jest dostępne"); Thread.Sleep(2500); DropProduct(); } }
/// <summary> /// Adds new product to database /// </summary> public static void AddNewProduct() { bool correctInput = false; string name; float price = 0f; int quantity = -1; int input = -1; Console.Clear(); Console.WriteLine("Dodaj nowy produkt \n" + "Podaj nazwę produktu:"); name = Console.ReadLine(); do { Console.WriteLine("Podaj cenę :"); try { price = float.Parse(Console.ReadLine()); if (price > 0) { correctInput = true; } else { correctInput = false; } } catch (System.FormatException) { Console.WriteLine("Zrobiłeś coś źle, wyprować daną jeszcze raz"); correctInput = false; } } while (!correctInput); do { Console.WriteLine("Podaj ilość :"); try { quantity = int.Parse(Console.ReadLine()); if (quantity > 0) { correctInput = true; } else { correctInput = false; } } catch (System.FormatException) { Console.WriteLine("Zrobiłeś coś źle, wyprować daną jeszcze raz"); correctInput = false; } } while (!correctInput); do { Console.WriteLine("Czy wszystko się zgadza " + adminName + "?\n" + "Nazwa: " + name + " cena: " + price + " ilość: " + quantity); Console.WriteLine("1 - Wszystko git \n 2 - Chce poprawić dane \n" + "3 - Anuluj i wróć do menu administratora "); try { input = int.Parse(Console.ReadLine()); if (input > 0) { correctInput = true; } else { correctInput = false; } } catch (System.FormatException) { correctInput = false; Console.WriteLine("To nie jest jedna z opcji"); } } while (!correctInput); switch (input) { case 1: ProductsDatabase.AddNewProduct(name, price, quantity); break; case 2: AddNewProduct(); break; case 3: StartAdminLogic(); break; default: Console.WriteLine("To nie jest jedna z opcji"); break; } }
/// <summary> /// Updates product quantity in database /// </summary> public static void AddProduct() { int input = -1; bool correctInput = false; int quantity = -1; Console.Clear(); ProductsDatabase products = new ProductsDatabase(); Console.WriteLine(products.ShowAdmin()); do { Console.WriteLine("Wybierz produkt który chcesz uzupełnić " + adminName); try { input = int.Parse(Console.ReadLine()); if (input > 0) { correctInput = true; } else { correctInput = false; } } catch (System.FormatException) { correctInput = false; Thread.Sleep(3000); Console.Clear(); } } while (!correctInput); do { Console.WriteLine("Ile sztuk chcesz dodać? " + adminName); try { quantity = int.Parse(Console.ReadLine()); if (quantity > 0) { correctInput = true; } else { correctInput = false; } } catch (System.FormatException) { correctInput = false; } } while (!correctInput); Console.WriteLine(adminName + " Czy chcesz dodać " + quantity + " sztuk produktu numer " + input + "?\n" + "1 - Tak\n" + "2 - Nie\n" + "3 - Chce dodać inny produkt"); int actionChoice = int.Parse(Console.ReadLine()); switch (actionChoice) { case 1: ProductsDatabase.Increment(input, quantity, products); Console.WriteLine("Dodano"); Thread.Sleep(2500); StartAdminLogic(); break; case 2: StartAdminLogic(); break; case 3: AddProduct(); break; default: Console.WriteLine("Coś poszło nie tak!"); Thread.Sleep(2500); StartAdminLogic(); break; } }
/// <summary> /// Choose a product from the database /// </summary> /// <param name="products">database to choose from</param> public static void ChooseProduct(ProductsDatabase products) { bool choosedProduct = false; int prod = 0; double productCost; Int64 productQuantity; int length = products.Products.Count; do { Console.Clear(); ShowCredit(); Output(products.Show()); Output(chooseProduct); try { prod = int.Parse(Input()); if (length >= prod) { choosedProduct = true; } else { choosedProduct = false; Output(wrongNumber); Thread.Sleep(2500); } } catch (System.FormatException) { choosedProduct = false; Output(wrongFormat); Thread.Sleep(2500); } } while (!choosedProduct); productQuantity = products.Products[prod - 1].Quantity; if (productQuantity > 0) { productCost = products.Products[prod - 1].Price; //check if price is lower or equal to credit if (productCost > fullMoney) { Output(notEnoughMoney); Thread.Sleep(2500); Console.Clear(); Pay(); } else { fullMoney = ChangeCalculator.CalculateChange(fullMoney, (float)productCost); ProductsDatabase.Decrement(prod, products); TransactionsDatabase.AddTransaction(prod); Console.Clear(); } } else { Output(itemUnavailable); EndTransaction(); Pause(); StartMachine(); } }