Example #1
0
        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);
            }
        }
Example #2
0
        /// <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;
            }
        }
Example #3
0
        public static void DeleteMedicine()
        {
            try
            {
                int id = Ask.ForMedicineId("Podaj ID leku: ");

                using (var medicine = new Medicine())
                {
                    medicine.Reload(id);

                    if (medicine.OrderExistsForMedicine())
                    {
                        ConsoleEx.WriteLine(ConsoleColor.Red, "Lek nie może zostać usunięty ponieważ istnieją dla niego zamówienia. ");
                    }
                    else
                    {
                        var medicineToDelete = new List <Medicine>()
                        {
                            medicine
                        };

                        DisplayMedicineList(medicineToDelete);
                        Console.WriteLine();

                        if (Ask.ForBool("Czy na pewno chcesz usunąć lek: t/n "))
                        {
                            medicine.Remove();
                            ConsoleEx.WriteLine(Console.ForegroundColor, "Lek został usunięty. ");
                            Console.WriteLine();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleEx.WriteLine(ConsoleColor.Red, "Wystąpił błąd. ERROR: {0}", e.Message);
            }
        }
Example #4
0
        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);
            }
        }