Example #1
0
 private void bCreate_Click(object sender, EventArgs e)
 {
     this.rForm = new RequestForm();
     if (rForm.ShowDialog(this) == DialogResult.OK)
     {
         Prescription p = new Prescription();
         p.Created = rForm.Date;
         rForm.Medicines.ForEach(m => p.Add(m));
         try
         {
             this.service.AddPrescription(this.patient, p);
             this.prescriptionBindingSource.Insert(0, p);
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
 public void AddPrescription(Patient p, Prescription pres)
 {
     pm.InsertRequest(p, pres);
 }
 public void RemovePrescription(Prescription p)
 {
     pm.DeleteRequest(p);
 }
        private List<Request> Read(DbDataReader reader, IDatabase db)
        {
            List<Request> requests = new List<Request>();
            MedicineMapper medcat = MedicineMapper.GetInstance();

            while (reader.Read())
            {
                Prescription er = new Prescription();
                er.Id = reader.GetInt32(0);
                er.Created = reader.GetDateTime(1);

                DbCommand command = db.CreateCommand(sqlSELECTMEDICINE);
                command.Parameters.Add(db.CreateParameter("@id", "int"));
                command.Parameters["@id"].Value = er.Id;
                DbDataReader medicines = db.Select(command);
                er.Medicines = this.ReadMedicines(medicines, medcat);

                medicines.Close();

                requests.Add(er);
            }

            return requests;
        }
        private void PrepareCommand(IDatabase db, DbCommand cmd, Prescription er, string p_id)
        {
            cmd.Parameters.Add(db.CreateParameter("@date", "datetime"));
            cmd.Parameters["@date"].Value = er.Created;

            cmd.Parameters.Add(db.CreateParameter("@person", "char", p_id.Length));
            cmd.Parameters["@person"].Value = p_id;
        }
        private int InsertMedicines(Prescription p, IDatabase db)
        {
            int added = 0;
            DbCommand command;

            foreach (Medicine m in p.Medicines)
            {
                command = db.CreateCommand(sqlINSERTMEDICINE);
                command.Parameters.Add(db.CreateParameter("@id", "int"));
                command.Parameters["@id"].Value = p.Id;

                command.Parameters.Add(db.CreateParameter("@medicineid", "int"));
                command.Parameters["@medicineid"].Value = m.Id;

                added += db.ExecuteNonQuery(command);
            }

            return added;
        }
        private void DeleteMedicines(Prescription p)
        {
            IDatabase db = new MSSqlDatabase();
            db.Connect();

            DbCommand command = db.CreateCommand(sqlDELETEMEDICINES);
            command.Parameters.Add(db.CreateParameter("@id", "int"));
            command.Parameters["@id"].Value = p.Id;

            db.ExecuteNonQuery(command);

            db.Close();
        }