Ejemplo n.º 1
0
        public Medicine Find(int key)
        {
            IDatabase db = new MSSqlDatabase();
            db.Connect();

            db.BeginTransaction();

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

            DbDataReader reader = db.Select(command);

            Dictionary<int, Medicine> medicines = this.Read(reader, db);

            reader.Close();

            db.EndTransaction();
            db.Close();

            if (medicines.Count == 0)
                return null;
            else
                return medicines.Values.ToList()[0];
        }
        public void Insert(string p_id, ExaminationType e)
        {
            IDatabase db = new MSSqlDatabase();
            db.Connect();

            DbCommand command = db.CreateCommand(sqlINSERT);
            PrepareCommand(db, command, e);
            e.Id = db.ExecuteScalar(command);

            db.Close();
        }
Ejemplo n.º 3
0
        public void InsertRequest(string p_id, Request r)
        {
            SampleRequest er = (SampleRequest)r;
            IDatabase db = new MSSqlDatabase();
            db.Connect();

            DbCommand command = db.CreateCommand(sqlINSERT);
            PrepareCommand(db, command, er);
            er.Id = db.ExecuteScalar(command);

            db.Close();
        }
        public void Delete(ExaminationType e)
        {
            IDatabase db = new MSSqlDatabase();
            db.Connect();

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

            db.ExecuteNonQuery(command);

            db.Close();
        }
Ejemplo n.º 5
0
        public void DeleteRequest(Request r)
        {
            SampleRequest er = (SampleRequest)r;
            IDatabase db = new MSSqlDatabase();
            db.Connect();

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

            db.ExecuteNonQuery(command);

            db.Close();
        }
        public List<ExaminationType> SelectAll()
        {
            IDatabase db = new MSSqlDatabase();
            db.Connect();

            DbCommand command = db.CreateCommand(sqlSELECT);

            DbDataReader reader = db.Select(command);

            List<ExaminationType> e = this.Read(reader, db);

            reader.Close();
            db.Close();

            return e;
        }
        public ExaminationType Find(int id)
        {
            IDatabase db = new MSSqlDatabase();
            db.Connect();

            DbCommand command = db.CreateCommand(sqlFIND);

            DbDataReader reader = db.Select(command);

            ExaminationType e = this.Read(reader, db)[0];

            reader.Close();
            db.Close();

            return e;
        }
        public List<Request> SelectRequests(string p_id)
        {
            IDatabase db = new MSSqlDatabase();
            db.Connect();

            DbCommand command = db.CreateCommand(sqlSELECT);
            command.Parameters.Add(db.CreateParameter("@id", "char", p_id.Length));
            command.Parameters["@id"].Value = p_id;

            DbDataReader reader = db.Select(command);

            List<Request> p = this.Read(reader);

            reader.Close();
            db.Close();

            return p;
        }
Ejemplo n.º 9
0
        public Dictionary<int, Medicine> LoadAsDict()
        {
            IDatabase db = new MSSqlDatabase();
            db.Connect();

            db.BeginTransaction();

            DbCommand command = db.CreateCommand(sqlSELECTALL);

            DbDataReader reader = db.Select(command);

            Dictionary<int, Medicine> medicines = this.Read(reader, db);

            reader.Close();

            db.EndTransaction();
            db.Close();

            return medicines;
        }
Ejemplo n.º 10
0
        public void DeleteRequest(Request r)
        {
            Prescription er = (Prescription)r;
            IDatabase db = new MSSqlDatabase();
            db.Connect();

            db.BeginTransaction();

            this.DeleteMedicines(er);

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

            db.ExecuteNonQuery(command);

            db.EndTransaction();

            db.Close();
        }
        public void UpdateRequest(Request r)
        {
            ExaminationRequest er = (ExaminationRequest)r;
            IDatabase db = new MSSqlDatabase();
            db.Connect();

            DbCommand command = db.CreateCommand(sqlUPDATE);
            PrepareCommand(db, command, er);
            command.Parameters.Add(db.CreateParameter("@id", "int"));
            command.Parameters["@id"].Value = er.Id;
            db.ExecuteNonQuery(command);

            db.Close();
        }
Ejemplo n.º 12
0
        public void InsertRequest(string p_id, Request r)
        {
            Prescription er = (Prescription)r;
            if (er.Medicines.Count == 0)
            {
                throw new ApplicationException(ErrorMessages.Messages["REQ_P_medicines"]);
            }

            IDatabase db = new MSSqlDatabase();
            db.Connect();

            db.BeginTransaction();

            DbCommand command = db.CreateCommand(sqlINSERT);
            PrepareCommand(db, command, er, p_id);
            er.Id = db.ExecuteScalar(command);

            int added = this.InsertMedicines(er, db);

            db.EndTransaction();

            if (added != er.Medicines.Count)
            {
                db.Rollback();
            }

            db.Close();
        }
Ejemplo n.º 13
0
        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();
        }
Ejemplo n.º 14
0
        public void UpdateRequest(Request r)
        {
            Prescription er = (Prescription)r;
            IDatabase db = new MSSqlDatabase();
            db.Connect();

            db.BeginTransaction();

            DbCommand command = db.CreateCommand(sqlUPDATE);
            command.Parameters.Add(db.CreateParameter("@date", "datetime"));
            command.Parameters["@date"].Value = er.Created;
            command.Parameters.Add(db.CreateParameter("@id", "int"));
            command.Parameters["@id"].Value = er.Id;
            db.ExecuteNonQuery(command);

            this.DeleteMedicines(er);
            int added = this.InsertMedicines(er, db);

            db.EndTransaction();

            if (added != er.Medicines.Count)
            {
                db.Rollback();
            }

            db.Close();
        }