Exemple #1
0
        public void Show()
        {
            try
            {
                var connection = ActiveRecord.Open();

                using (connection)
                {
                    connection.Open();
                    var sqlCommand = new SqlCommand();
                    sqlCommand.Connection  = connection;
                    sqlCommand.CommandText = "SELECT * FROM Prescriptions";

                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();

                    while (sqlDataReader.Read())
                    {
                        Console.WriteLine();
                        Console.WriteLine("ID: " + sqlDataReader["ID"]);
                        Console.WriteLine("Nazwa Klienta: " + sqlDataReader["CustomerName"]);
                        Console.WriteLine("Pesel: " + sqlDataReader["PESEL"]);
                        Console.WriteLine("Numer recepty: " + sqlDataReader["PrescriptionNumber"]);



                        Console.WriteLine();
                    }
                    Console.ReadLine();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemple #2
0
        public static bool Check(int ID)
        {
            try
            {
                var connection = ActiveRecord.Open();

                int id = 0;
                id = ID;

                using (connection)
                {
                    connection.Open();
                    var sqlCommand = new SqlCommand();
                    sqlCommand.Connection  = connection;
                    sqlCommand.CommandText = "SELECT COUNT(*) FROM Prescriptions WHERE ID = @id";

                    var sqlIDParam = new SqlParameter
                    {
                        DbType        = System.Data.DbType.Int32,
                        Value         = ID,
                        ParameterName = "@id"
                    };

                    sqlCommand.Parameters.Add(sqlIDParam);


                    int userCount = (int)sqlCommand.ExecuteScalar();

                    if (userCount >= 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Nie ma takiego id");
                Console.WriteLine(e.Message);
                return(false);
            }
        }
Exemple #3
0
        public void Show()
        {
            try
            {
                var connection = ActiveRecord.Open();

                using (connection)
                {
                    connection.Open();
                    var sqlCommand = new SqlCommand();
                    sqlCommand.Connection  = connection;
                    sqlCommand.CommandText = "SELECT * FROM Medicines";

                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();

                    while (sqlDataReader.Read())
                    {
                        Console.WriteLine();
                        Console.WriteLine("ID: " + sqlDataReader["ID"]);
                        Console.WriteLine("Nazwa: " + sqlDataReader["Name"]);
                        Console.WriteLine("Producent: " + sqlDataReader["Manufacturer"]);
                        Console.WriteLine("Cena: " + sqlDataReader["Price"]);
                        Console.WriteLine("Ilość: " + sqlDataReader["Amount"]);
                        Console.Write("Na recepte: ");
                        if (Convert.ToBoolean(sqlDataReader["WithPrescription"]) == true)
                        {
                            Console.Write("Tak");
                        }
                        else
                        {
                            Console.Write("Nie");
                        }

                        Console.WriteLine();
                    }
                    Console.ReadLine();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        public void Show()
        {
            try
            {
                var connection = ActiveRecord.Open();

                using (connection)
                {
                    connection.Open();
                    var sqlCommand = new SqlCommand();
                    sqlCommand.Connection  = connection;
                    sqlCommand.CommandText = "SELECT * FROM Orders";

                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();

                    while (sqlDataReader.Read())
                    {
                        Console.WriteLine();
                        Console.WriteLine("ID: " + sqlDataReader["ID"]);
                        Console.WriteLine("ID leku: " + sqlDataReader["MedicinID"]);
                        Console.WriteLine("ID recepty: " + sqlDataReader["PrescriptionID"]);
                        Console.WriteLine("Data: " + sqlDataReader["Date"]);
                        Console.WriteLine("Ilość: " + sqlDataReader["Amount"]);



                        Console.WriteLine();
                    }
                    Console.ReadLine();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemple #5
0
        public override void Reload()
        {
            var connection = ActiveRecord.Open();

            do
            {
                try
                {
                    Console.WriteLine("Podaj Id do modyfikacji: ");
                    string ID = Console.ReadLine();


                    if (Prescription.Check(Int32.Parse(ID)) == false)
                    {
                        Console.ReadKey();
                        return;
                    }

                    Console.WriteLine("Nazwa klienta: ");
                    string customerName = Console.ReadLine();
                    Console.WriteLine("PESEL: ");
                    string pesel = Console.ReadLine();
                    Console.WriteLine("Numer recepty: ");
                    string prescriptionNumber = Console.ReadLine();



                    Prescription prescription = new Prescription(customerName, pesel, prescriptionNumber);



                    using (connection)
                    {
                        connection.Open();
                        var sqlCommand = new SqlCommand();
                        sqlCommand.Connection  = connection;
                        sqlCommand.CommandText = @"UPDATE  Prescriptions SET CustomerName = @customerName, PESEL = @pesel, PrescriptionNumber = @prescriptionNumber 
                                                   WHERE ID = @ID";

                        var sqlCustomerNameParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.AnsiString,
                            Value         = prescription.CustomerName,
                            ParameterName = "@customerName"
                        };

                        var sqlPESELParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.AnsiString,
                            Value         = prescription.PESEL,
                            ParameterName = "@pesel"
                        };

                        var sqlPrescriptionNumberParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.AnsiString,
                            Value         = prescription.PrescriptionNumber,
                            ParameterName = "@prescriptionNumber"
                        };

                        var sqlIDParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.Int32,
                            Value         = ID,
                            ParameterName = "@ID"
                        };


                        sqlCommand.Parameters.Add(sqlCustomerNameParam);
                        sqlCommand.Parameters.Add(sqlPESELParam);
                        sqlCommand.Parameters.Add(sqlPrescriptionNumberParam);
                        sqlCommand.Parameters.Add(sqlIDParam);

                        sqlCommand.ExecuteNonQuery();
                    }

askTheUser2:
                    Console.WriteLine("Chcesz zmodyfikować kolejną pozycję? (T/N): ");
                    string addAnother = Console.ReadLine().Trim().ToLower();
                    if (addAnother == "t")
                    {
                        continue;
                    }
                    else if (addAnother == "n")
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Nieznana odpowiedź");
                        goto askTheUser2;
                    }
                }


                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            } while (true);
        }
Exemple #6
0
        public override void Save()
        {
            do
            {
                try
                {
                    var connection = ActiveRecord.Open();

                    Console.WriteLine("Nazwa klienta: ");
                    string customerName = Console.ReadLine();
                    Console.WriteLine("PESEL: ");
                    string pesel = Console.ReadLine();
                    Console.WriteLine("Numer recepty: ");
                    string prescriptionNumber = Console.ReadLine();



                    Prescription prescription = new Prescription(customerName, pesel, prescriptionNumber);


                    using (connection)
                    {
                        connection.Open();
                        var sqlCommand = new SqlCommand();
                        sqlCommand.Connection  = connection;
                        sqlCommand.CommandText = @"INSERT INTO Prescriptions (CustomerName, PESEL, PrescriptionNumber)
			                             VALUES (@CustomerName, @PESEL, @PrescriptionNumber)"            ;

                        var sqlCustomerNameParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.AnsiString,
                            Value         = prescription.CustomerName,
                            ParameterName = "@customerName"
                        };

                        var sqlPESELParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.AnsiString,
                            Value         = prescription.PESEL,
                            ParameterName = "@pesel"
                        };

                        var sqlPrescriptionNumberParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.AnsiString,
                            Value         = prescription.PrescriptionNumber,
                            ParameterName = "@prescriptionNumber"
                        };

                        var sqlIDParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.Int32,
                            Value         = ID,
                            ParameterName = "@ID"
                        };


                        sqlCommand.Parameters.Add(sqlCustomerNameParam);
                        sqlCommand.Parameters.Add(sqlPESELParam);
                        sqlCommand.Parameters.Add(sqlPrescriptionNumberParam);
                        sqlCommand.Parameters.Add(sqlIDParam);

                        sqlCommand.ExecuteNonQuery();
                    }

askTheUser2:
                    Console.WriteLine("Chcesz dodać kolejną pozycję? (T/N): ");
                    string addAnother = Console.ReadLine().Trim().ToLower();
                    if (addAnother == "t")
                    {
                        continue;
                    }
                    else if (addAnother == "n")
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Nieznana odpowiedź");
                        goto askTheUser2;
                    }
                }


                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            } while (true);
        }
Exemple #7
0
        public override void Remove()
        {
            do
            {
                try
                {
                    Console.WriteLine("Podaj Id do usuniecia: ");
                    string ID = Console.ReadLine();



                    if (Prescription.Check(Int32.Parse(ID)) == false)
                    {
                        Console.ReadKey();
                        return;
                    }

                    var connection = ActiveRecord.Open();

                    using (connection)
                    {
                        connection.Open();
                        var sqlCommand = new SqlCommand();
                        sqlCommand.Connection  = connection;
                        sqlCommand.CommandText = @"DELETE FROM Prescriptions WHERE ID = @ID";



                        var sqlIDParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.Int32,
                            Value         = ID,
                            ParameterName = "@ID"
                        };

                        sqlCommand.Parameters.Add(sqlIDParam);

                        sqlCommand.ExecuteNonQuery();
                    }

askTheUser2:
                    Console.WriteLine("Chcesz usunąć kolejną pozycję? (T/N): ");
                    string addAnother = Console.ReadLine().Trim().ToLower();
                    if (addAnother == "t")
                    {
                        continue;
                    }
                    else if (addAnother == "n")
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Nieznana odpowiedź");
                        goto askTheUser2;
                    }
                }


                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            } while (true);
        }
        public override void Reload()
        {
            var connection = ActiveRecord.Open();

            do
            {
                try
                {
                    Console.WriteLine("Podaj numer Id zamówienia do modyfikacji: ");
                    string ID = Console.ReadLine();


                    if (Order.Check(Int32.Parse(ID)) == false)
                    {
                        Console.ReadKey();
                        return;
                    }

                    Console.WriteLine("Id leku: ");
                    int medicinId = Int32.Parse(Console.ReadLine());
                    Console.WriteLine("Id recepty: ");
                    int prescriptionId = Int32.Parse(Console.ReadLine());
                    Console.WriteLine("Data: ");
                    DateTime date = DateTime.Parse(Console.ReadLine(), System.Globalization.CultureInfo.InvariantCulture);
                    Console.WriteLine("Ilość: ");
                    int amount = Int32.Parse(Console.ReadLine());

                    Order order = new Order(medicinId, prescriptionId, date, amount);

                    using (connection)
                    {
                        connection.Open();
                        var sqlCommand = new SqlCommand();
                        sqlCommand.Connection  = connection;
                        sqlCommand.CommandText = @"UPDATE  Orders SET MedicinID = @medicinId, PrescriptionID = @prescriptionId, Date = @date, Amount = @amount
                                                   WHERE ID = @ID";


                        var sqlMedicinIDParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.Int32,
                            Value         = order.MedicinID,
                            ParameterName = "@medicinId"
                        };

                        var sqlPrescriptionIDParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.Int32,
                            Value         = order.PrescriptionID,
                            ParameterName = "@prescriptionId"
                        };
                        var sqlDateParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.DateTime,
                            Value         = order.Date,
                            ParameterName = "@date"
                        };

                        var sqlAmountParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.Int32,
                            Value         = order.Amount,
                            ParameterName = "@amount"
                        };

                        var sqlIDParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.Int32,
                            Value         = ID,
                            ParameterName = "@ID"
                        };


                        sqlCommand.Parameters.Add(sqlMedicinIDParam);
                        sqlCommand.Parameters.Add(sqlPrescriptionIDParam);
                        sqlCommand.Parameters.Add(sqlDateParam);
                        sqlCommand.Parameters.Add(sqlAmountParam);
                        sqlCommand.Parameters.Add(sqlIDParam);

                        sqlCommand.ExecuteNonQuery();
                    }

askTheUser2:
                    Console.WriteLine("Chcesz zmodyfikować kolejną pozycję? (T/N): ");
                    string addAnother = Console.ReadLine().Trim().ToLower();
                    if (addAnother == "t")
                    {
                        continue;
                    }
                    else if (addAnother == "n")
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Nieznana odpowiedź");
                        goto askTheUser2;
                    }
                }


                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            } while (true);
        }
        public override void Save()
        {
            do
            {
                try
                {
                    var connection = ActiveRecord.Open();


                    Console.WriteLine("Id leku: ");
                    int medicinId = Int32.Parse(Console.ReadLine());
                    Console.WriteLine("Id recepty: ");
                    int prescriptionId = Int32.Parse(Console.ReadLine());
                    Console.WriteLine("Data: ");
                    DateTime date = DateTime.Parse(Console.ReadLine(), System.Globalization.CultureInfo.InvariantCulture);
                    Console.WriteLine("Ilość: ");
                    int amount = Int32.Parse(Console.ReadLine());

                    Order order = new Order(medicinId, prescriptionId, date, amount);


                    using (connection)
                    {
                        connection.Open();
                        var sqlCommand = new SqlCommand();
                        sqlCommand.Connection  = connection;
                        sqlCommand.CommandText = @"INSERT INTO Orders (Orders.MedicinID, Orders.PrescriptionID, Date, Amount)
													VALUES ( (select ID from Medicines where ID = @medicinId), (select ID from Prescriptions where ID = @prescriptionId), @date, @amount)"                                                    ;



                        var sqlMedicinIDParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.Int32,
                            Value         = order.MedicinID,
                            ParameterName = "@medicinId"
                        };

                        var sqlPrescriptionIDParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.Int32,
                            Value         = order.PrescriptionID,
                            ParameterName = "@prescriptionId"
                        };
                        var sqlDateParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.DateTime,
                            Value         = order.Date,
                            ParameterName = "@date"
                        };

                        var sqlAmountParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.Int32,
                            Value         = order.Amount,
                            ParameterName = "@amount"
                        };

                        var sqlIDParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.Int32,
                            Value         = ID,
                            ParameterName = "@ID"
                        };


                        sqlCommand.Parameters.Add(sqlMedicinIDParam);
                        sqlCommand.Parameters.Add(sqlPrescriptionIDParam);
                        sqlCommand.Parameters.Add(sqlDateParam);
                        sqlCommand.Parameters.Add(sqlAmountParam);
                        sqlCommand.Parameters.Add(sqlIDParam);

                        sqlCommand.ExecuteNonQuery();
                    }

askTheUser2:
                    Console.WriteLine("Chcesz dodać kolejną pozycję? (T/N): ");
                    string addAnother = Console.ReadLine().Trim().ToLower();
                    if (addAnother == "t")
                    {
                        continue;
                    }
                    else if (addAnother == "n")
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Nieznana odpowiedź");
                        goto askTheUser2;
                    }
                }


                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            } while (true);
        }
Exemple #10
0
        public override void Reload()
        {
            var connection = ActiveRecord.Open();

            do
            {
                try
                {
                    Console.WriteLine("Podaj Id do modyfikacji: ");
                    string ID = Console.ReadLine();


                    if (Medicin.Check(Int32.Parse(ID)) == false)
                    {
                        Console.ReadKey();
                        return;
                    }

                    Console.WriteLine("Nazwa: ");
                    string name = Console.ReadLine();
                    Console.WriteLine("Producent: ");
                    string manufacturer = Console.ReadLine();
                    Console.WriteLine("Cena: ");
                    decimal price = Decimal.Parse(Console.ReadLine());
                    Console.WriteLine("Ilość: ");
                    int amount = Int32.Parse(Console.ReadLine());
askTheUser:
                    Console.WriteLine("Na recepte (T/N): ");
                    string tempPerscription = Console.ReadLine().ToLower().Trim();
                    bool   withPrescription = false;
                    if (tempPerscription == "t")
                    {
                        withPrescription = true;
                    }
                    else if (tempPerscription == "n")
                    {
                        withPrescription = false;
                    }
                    else
                    {
                        Console.WriteLine("Błędny format.");
                        goto askTheUser;
                    }


                    Medicin medicin = new Medicin(name, manufacturer, price, amount, withPrescription);



                    using (connection)
                    {
                        connection.Open();
                        var sqlCommand = new SqlCommand();
                        sqlCommand.Connection  = connection;
                        sqlCommand.CommandText = @"UPDATE  Medicines SET Name = @name, Manufacturer = @Manufacturer, Price = @Price, Amount = @Amount, WithPrescription = @WithPrescription 
                                                   WHERE ID = @ID";

                        var sqlNameParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.AnsiString,
                            Value         = medicin.Name,
                            ParameterName = "@name"
                        };

                        var sqlManufacturerParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.AnsiString,
                            Value         = medicin.Manufacturer,
                            ParameterName = "@Manufacturer"
                        };

                        var sqlPriceParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.Decimal,
                            Value         = medicin.Price,
                            ParameterName = "@Price"
                        };
                        var sqlAmountParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.Int32,
                            Value         = medicin.Amount,
                            ParameterName = "@Amount"
                        };
                        var sqlWithPrescriptionParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.Boolean,
                            Value         = medicin.WithPrescription,
                            ParameterName = "@WithPrescription"
                        };

                        var sqlIDParam = new SqlParameter
                        {
                            DbType        = System.Data.DbType.Int32,
                            Value         = ID,
                            ParameterName = "@ID"
                        };


                        sqlCommand.Parameters.Add(sqlNameParam);
                        sqlCommand.Parameters.Add(sqlManufacturerParam);
                        sqlCommand.Parameters.Add(sqlPriceParam);
                        sqlCommand.Parameters.Add(sqlAmountParam);
                        sqlCommand.Parameters.Add(sqlWithPrescriptionParam);
                        sqlCommand.Parameters.Add(sqlIDParam);

                        sqlCommand.ExecuteNonQuery();
                    }

askTheUser2:
                    Console.WriteLine("Chcesz zmodyfikować kolejną pozycję? (T/N): ");
                    string addAnother = Console.ReadLine().Trim().ToLower();
                    if (addAnother == "t")
                    {
                        continue;
                    }
                    else if (addAnother == "n")
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Nieznana odpowiedź");
                        goto askTheUser2;
                    }
                }


                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            } while (true);
        }