private static void SellMedWithPrescription(int id) { try { Console.WriteLine("How much do you want to sell?:"); int amount = Int32.Parse(Console.ReadLine()); int Id = id; DateTime date = DateTime.Now; var order = new Order(null, Id, date, amount); Console.WriteLine("Podaj dane recepty:"); Console.WriteLine("Imię i nazwisko:"); string customerName = Console.ReadLine(); Console.WriteLine("Pesel:"); string pesel = Console.ReadLine(); Console.WriteLine("Numer recepty:"); int prescriptionNumber = Int32.Parse(Console.ReadLine()); var prescription = new Prescription(customerName, pesel, prescriptionNumber); using (SqlConnection connection = new SqlConnection(connectionString)) { var sqlCommand = new SqlCommand(); sqlCommand.Connection = connection; sqlCommand.CommandText = @"INSERT INTO Prescriptions (CustomerName, PESEL, PrescriptionNumber) VALUES (@CustomerName, @PESEL, @PrescriptionNumber); SELECT SCOPE_IDENTITY();" ; var sqlCustomerNameParam = new SqlParameter { DbType = System.Data.DbType.String, Value = prescription.CustomerName, ParameterName = "@CustomerName" }; var sqlPeselParam = new SqlParameter { DbType = System.Data.DbType.String, Value = prescription.Pesel, ParameterName = "@PESEL" }; var sqlPresciptionNumberParam = new SqlParameter { DbType = System.Data.DbType.Int32, Value = prescription.PrescriptionNumber, ParameterName = "@PrescriptionNumber" }; sqlCommand.Parameters.Add(sqlCustomerNameParam); sqlCommand.Parameters.Add(sqlPeselParam); sqlCommand.Parameters.Add(sqlPresciptionNumberParam); connection.Open(); var addedPrescriptionId = sqlCommand.ExecuteScalar(); sqlCommand = new SqlCommand(); sqlCommand.Connection = connection; sqlCommand.CommandText = @"INSERT INTO Orders (PrescriptionId, MedicineId, Date, Amount) VALUES (@PrescriptionId, @MedicineId, @Date, @Amount);" ; var sqlPrescIdParam = new SqlParameter { DbType = System.Data.DbType.Int32, Value = addedPrescriptionId, ParameterName = "@PrescriptionId" }; var sqlIdParam = new SqlParameter { DbType = System.Data.DbType.Int32, Value = id, ParameterName = "@MedicineId" }; 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" }; sqlCommand.Parameters.Add(sqlIdParam); sqlCommand.Parameters.Add(sqlDateParam); sqlCommand.Parameters.Add(sqlAmountParam); sqlCommand.Parameters.Add(sqlPrescIdParam); sqlCommand.ExecuteNonQuery(); EditAmountForOders(id, amount); connection.Close(); } } catch (Exception e) { Console.WriteLine(e.Message); } }