示例#1
0
        private static void AddOrder()
        {
            try
            {
                Console.Clear();
                Console.Write("Enter ID medicine: ");
                Medicine medicine = new Medicine(int.Parse(Console.ReadLine()));

                medicine.Reload();
                Order order;

                if (medicine.WithPrescription == true)
                {
                    int id = AddPrescription();
                    if (id == 0)
                    {
                        Console.WriteLine("Error, try again");
                        return;
                    }

                    Prescription prescription = new Prescription(id);
                    order = new Order(medicine, prescription);
                    order.Save();
                    return;
                }

                order = new Order(medicine);
                order.Save();
            }
            catch (FormatException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
示例#2
0
        public Order(Medicine medicine, Prescription prescription)
        {
            try
            {
                if (medicine.ID == 0)
                {
                    throw new Exception("Medicine ID doesn't exist");
                }

                MedicineID = medicine.ID;

                if (prescription.ID == 0)
                {
                    throw new Exception("Prescription ID doesn't exist");
                }
                PrescrionID = prescription.ID;

                _medicine = medicine;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.Message);
            }
        }
示例#3
0
        private static void AddMedicine()
        {
            Medicine medicine = new Medicine();

            medicine.Save();
        }
示例#4
0
        private static void EditMedicine()
        {
            Medicine medicine = new Medicine();

            medicine.Update();
        }
示例#5
0
        public void Update()
        {
            try
            {
                Console.Write("Medicine ID: ");
                string   id          = Console.ReadLine().ToString();
                Medicine OldMedicine = new Medicine(int.Parse(id));
                OldMedicine.Reload();

                Console.Clear();
                Console.WriteLine("What change?");
                Console.WriteLine("Name: N");
                Console.WriteLine("Manufacturer: M");
                Console.WriteLine("Price: P");
                Console.WriteLine("Amount: A");
                Console.WriteLine("WithPrescription: WP");
                string command = Console.ReadLine().ToString().Trim();
                string param   = "";

                switch (command)
                {
                case "N":
                    param = "Name";
                    Console.Clear();
                    Console.WriteLine($"Old value {OldMedicine.Name}");
                    Console.Write("New value: ");
                    command = Console.ReadLine().ToString().Trim();
                    break;

                case "M":
                    param = "Manufacturer";
                    Console.Clear();
                    Console.WriteLine($"Old value {OldMedicine.Manufacturer}");
                    Console.Write("New value: ");
                    command = Console.ReadLine().ToString().Trim();
                    break;

                case "P":
                    param = "Price";
                    Console.Clear();
                    Console.WriteLine($"Old value {OldMedicine.Price}");
                    Console.Write("New value: ");
                    command = Console.ReadLine().ToString().Trim();
                    break;

                case "A":
                    param = "Amount";
                    Console.Clear();
                    Console.WriteLine($"Old value {OldMedicine.Amount}");
                    Console.Write("New value: ");
                    command = Console.ReadLine().ToString().Trim();
                    break;

                case "WP":
                    param = "WithPrescription";
                    Console.Clear();
                    Console.WriteLine($"Old value {OldMedicine.WithPrescription}");
                    Console.Write("New value (y/n): ");
                    command = Console.ReadLine().ToString().Trim();
                    if (command == "y")
                    {
                        command = "1";
                    }
                    else if (command == "n")
                    {
                        command = "0";
                    }
                    else
                    {
                        Console.WriteLine("Wrong format");
                    } Update();
                    break;
                }

                Open();
                sqlCommand.CommandText = $"Update Medicines Set {param} = '{command}' Where MedicineID = {id};";
                var sqlReaderCheck = sqlCommand.ExecuteNonQuery();
                Close();



                if (Name == "")
                {
                    throw new Exception("Incorect Medicine Name");
                }
            }
            catch (FormatException e)
            {
                Console.WriteLine("Invalid format, try again, " + e.Message);
                Console.Clear();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error, try again, " + e.Message);
                Console.Clear();
            }
        }