public static void ModifyMedicine() { try { int id = Ask.ForMedicineId("Podaj ID leku: "); using (var medicine = new Medicine()) { medicine.Reload(id); ConsoleEx.WriteLine(Console.ForegroundColor, "Pozostaw puste jeżeli nie chcesz zmieniać: "); string name = Ask.ForString("Podaj nazwę leku: ", true, medicine.Name); string manufacturer = Ask.ForString("Podaj producenta leku: ", true, medicine.Manufacturer); decimal price = Ask.ForDecimal("Podaj cenę leku: ", true, medicine.Price); decimal amount = Ask.ForDecimal("Podaj ilość leku: ", true, medicine.Amount); bool withPrescription = Ask.ForBool("Na receptę t/n: ", true, medicine.WithPrescription); Console.WriteLine(); var medicineToMod = new List <Medicine>() { medicine, new Medicine(name, manufacturer, price, amount, withPrescription) }; DisplayMedicineList(medicineToMod); Console.WriteLine(); if (Ask.ForBool("Czy na pewno chcesz wprowadzić zmiany: t/n ")) { medicine.Name = name; medicine.Manufacturer = manufacturer; medicine.Price = price; medicine.Amount = amount; medicine.WithPrescription = withPrescription; medicine.Save(); ConsoleEx.WriteLine(Console.ForegroundColor, "Zmiany zostały wprowadzone. "); Console.WriteLine(); } } } catch (Exception e) { ConsoleEx.WriteLine(ConsoleColor.Red, "Wystąpił błąd. ERROR: {0}", e.Message); } }
public static void AddMedicine() { string name = Ask.ForString("Podaj nazwę leku: "); string manufacturer = Ask.ForString("Podaj producenta leku: "); decimal price = Ask.ForDecimal("Podaj cenę leku: "); decimal amount = Ask.ForDecimal("Podaj ilość leku: "); bool withPrescription = Ask.ForBool("Na receptę t/n: "); try { using (var medicine = new Medicine(name, manufacturer, price, amount, withPrescription)) { medicine.Save(); ConsoleEx.WriteLine(Console.ForegroundColor, "Lek został dodany"); } } catch (Exception e) { ConsoleEx.WriteLine(ConsoleColor.Red, "Wystąpił błąd. ERROR: {0}", e.Message); } }
/// <summary> /// Menu for medicines /// </summary> public static void Choice() { ConsoleEx.WriteLine("Avaiable commands for Medicines:\n1. Show all (show)\n2. Add medicine (add)\n3. Edit medicine (edit)\n4. Remove medicine (rem)\n5. Go to previous menu (exit)", ConsoleColor.Yellow); Medicine med = new Medicine(); string choice = Console.ReadLine(); if (choice == "1" || choice.ToLower() == "show") { Console.Clear(); med.ShowAll(); } else if (choice == "2" || choice.ToLower() == "add") { Console.Clear(); med.Save(); } else if (choice == "3" || choice == "edit") { Console.Clear(); Console.Write("Write Medicine's ID to "); ConsoleEx.Write("Edit: ", ConsoleColor.Cyan); int id = Int32.Parse(Console.ReadLine()); med.Reload(id); } else if (choice == "4" || choice.ToLower() == "remove") { Console.Clear(); Console.Write("Write Medicine's ID to "); ConsoleEx.Write("Remove: ", ConsoleColor.Red); int id = Int32.Parse(Console.ReadLine()); med.Remove(id); } else if (choice == "5" || choice.ToLower() == "exit") { Console.Clear(); return; } }
public static void AddOrder() { try { int id = Ask.ForMedicineId("Podaj ID leku do sprzedaży: "); DateTime saleDate = Ask.ForDate("Podaj datę sprzedaży bądź pozostaw puste aby uzupełnić bieżącą datą: ", true, DateTime.Now); decimal amount = Ask.ForDecimal("Podaj ilość sprzedawanych sztuk: "); using (var medicine = new Medicine()) { medicine.Reload(id); while (medicine.Amount < amount) { ConsoleEx.WriteLine(ConsoleColor.Red, "Wprowadzona ilość sztuk przekracza ilość w magazynie. "); if (Ask.ForBool($"Czy ustawić ilość na maksymalną dostepną ilość {medicine.Amount} t/n: ")) { amount = medicine.Amount; } else { amount = Ask.ForDecimal("Podaj nową ilość sprzedawanych sztuk: "); } } int? prescriptioId = null; Prescription prescription = null; if (medicine.WithPrescription) { string customerName = Ask.ForString("Podaj imię i nazwisko: "); string pesel = Ask.ForPesel("Podaje PESEL: "); string prescriptionNumber = Ask.ForString("Podaj numer recepty: "); prescription = new Prescription(customerName, pesel, prescriptionNumber); } if (Ask.ForBool($"Czy zapisać wprowadzone zamówienie t/n: ")) { medicine.Amount -= amount; medicine.Save(); if (medicine.WithPrescription && prescription != null) { using (prescription) { prescription.Save(); prescriptioId = prescription.ID; } } using (var order = new Order(prescriptioId, id, saleDate, amount)) { order.Save(); } } } } catch (Exception e) { ConsoleEx.WriteLine(ConsoleColor.Red, "Wystąpił błąd. ERROR: {0}", e.Message); } }
private static void AddCMD(string commandType, string[] commandValues, Prescription lastPrescription, Medicine lastMedicine) { if (commandType == "AddMedicine") { if (commandValues.Length == 6) { //[int id],[string name],[string manufacturer],[decimal price],[int amount],[bool withPrescription] int id = Convert.ToInt32(commandValues[0]); string name = Convert.ToString(commandValues[1]); string manufacturer = Convert.ToString(commandValues[2]); decimal price = Convert.ToDecimal(commandValues[3]); int amount = Convert.ToInt32(commandValues[4]); bool withPrescription = Convert.ToBoolean(commandValues[5]); Medicine myMedicine = new Medicine(id, name, manufacturer, price, amount, withPrescription); myMedicine.Save(); Program.LastMedicine = myMedicine; } else { Console.WriteLine("Nieprawidlowa ilość, lub format atrybutów."); } } else if (commandType == "AddPrescription") { if (commandValues.Length == 4) { //[int id],[string customerName],[string pesel],[int prescriptionNumber] int id = Convert.ToInt32(commandValues[0]); string customerName = Convert.ToString(commandValues[1]); string pesel = Convert.ToString(commandValues[2]); int prescriptionNumber = Convert.ToInt32(commandValues[3]); Prescription myPrescription = new Prescription(id, customerName, pesel, prescriptionNumber); myPrescription.Save(); Program.LastPrescription = myPrescription; } else { Console.WriteLine("Nieprawidlowa ilość, lub format atrybutów."); } } else if (commandType == "AddOrder") { if (commandValues.Length == 5) { //[int id],[Prescription prescriptionObj],[Medicine medicineObj],[string date],[int amount] int id = Convert.ToInt32(commandValues[0]); int lastPresciptionNumber = Convert.ToInt32(commandValues[1]); int lastMedicineNumber = Convert.ToInt32(commandValues[2]); if (lastPresciptionNumber != 0) { Program.LastPrescription = new Prescription(lastPresciptionNumber); } if (lastMedicineNumber != 0) { Program.LastMedicine = new Medicine(lastMedicineNumber); } string date = Convert.ToString(commandValues[3]); int amount = Convert.ToInt32(commandValues[4]); if (LastPrescription != null && LastMedicine != null) { Order myOrder = new Order(id, LastPrescription, LastMedicine, date, amount); myOrder.Save(); Program.LastOrder = myOrder; } else { Console.WriteLine("Nie udało się utworzyć [Order]"); } } else { Console.WriteLine("Nieprawidlowa ilość, lub format atrybutów."); } } }