コード例 #1
0
        /// <summary>
        /// Menu for prescriptions
        /// </summary>
        public static void Choice()
        {
            ConsoleEx.WriteLine("Avaiable commands for Prescriptions:\n1. Show all (show)\n2. Add prescription (add)\n3. Edit presctription (edit)\n4. Remove prescription (rem)\n5. Go to previous menu (exit)", ConsoleColor.Magenta);
            Prescription pres   = new Prescription();
            string       choice = Console.ReadLine();

            if (choice == "1" || choice.ToLower() == "show")
            {
                Console.Clear();
                pres.ShowAll();
            }
            else if (choice == "2" || choice.ToLower() == "add")
            {
                Console.Clear();
                pres.Save();
            }
            else if (choice == "3" || choice == "edit")
            {
                Console.Clear();
                pres.ShowAll();
                Console.Write("Write Prescription's ID to ");
                ConsoleEx.Write("Edit: ", ConsoleColor.Cyan);
                int id = Int32.Parse(Console.ReadLine());
                pres.Reload(id);
            }
            else if (choice == "4" || choice.ToLower() == "remove")
            {
                Console.Clear();
                Console.Write("Write Prescripion's ID to ");
                ConsoleEx.Write("Remove: ", ConsoleColor.Red);
                int id = Int32.Parse(Console.ReadLine());
                pres.Remove(id);
            }
            else if (choice == "5" || choice.ToLower() == "exit")
            {
                Console.Clear();
                return;
            }
        }
コード例 #2
0
        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.");
                }
            }
        }