Exemple #1
0
        private static void CreateDonation(HospitalProductDonationEntity donation, Database db, DbTransaction trans)
        {
            var sql = string.Format(@"insert into hospital_product_donations({0}) values
(@p_id,@p_hospital_id,@p_unit_id,@p_vendor_id,@p_product_id,@p_total_count,@p_used_count)", COLUMNS);

            donation.Id = Guid.NewGuid().ToString();

            var cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "p_id", DbType.String, donation.Id);
            db.AddInParameter(cmd, "p_hospital_id", DbType.String, donation.HospitalId);
            db.AddInParameter(cmd, "p_unit_id", DbType.String, donation.UnitId);
            db.AddInParameter(cmd, "p_vendor_id", DbType.String, donation.VendorId);
            db.AddInParameter(cmd, "p_product_id", DbType.String, donation.ProductId);
            db.AddInParameter(cmd, "p_total_count", DbType.Decimal, donation.TotalCount);
            db.AddInParameter(cmd, "p_used_count", DbType.Decimal, donation.UsedCount);

            db.ExecuteNonQuery(cmd, trans);
        }
Exemple #2
0
        public static IList <HospitalProductDonationEntity> GetDonationByProducts(string hospitalId, string unitId, string vendorId, IList <string> products)
        {
            var list = new List <HospitalProductDonationEntity>();

            if (products == null || products.Count == 0)
            {
                return(list);
            }

            IList <string> names;
            string         namesSql;

            StringHelper.GenerInParameters("p_product", products.Count, out names, out namesSql);

            var sql = string.Format(@"select {0} from hospital_product_donations 
where hospital_id=@p_hospital_id and unit_id=@p_unit_id and vendor_id=@p_vendor_id and product_id in ({1})", COLUMNS, namesSql);

            var db  = DatabaseFactory.CreateDatabase();
            var cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "p_hospital_id", DbType.String, hospitalId);
            db.AddInParameter(cmd, "p_unit_id", DbType.String, unitId);
            db.AddInParameter(cmd, "p_vendor_id", DbType.String, vendorId);
            for (var i = 0; i < products.Count; i++)
            {
                db.AddInParameter(cmd, names[i], DbType.String, products[i]);
            }

            using (var reader = db.ExecuteReader(cmd))
            {
                while (reader.Read())
                {
                    var entity = new HospitalProductDonationEntity();
                    entity.Init(reader);

                    list.Add(entity);
                }
            }

            return(list);
        }