Beispiel #1
0
        public static IList <GoodsInventoryEntity> Query(DateRangeCondition condition)
        {
            var sql = string.Format(GetBaseQuerySql(condition), "a.id,a.product_id,a.hospital_id,a.original_count,a.usable_count,a.granted_count,a.split_count,b.name,b.full_name");

            sql += " order by name";

            var list = new List <GoodsInventoryEntity>();
            var db   = DatabaseFactory.CreateDatabase();
            var dc   = db.GetSqlStringCommand(sql);

            AddParameter(dc, db, condition);

            using (var reader = db.ExecuteReader(dc))
            {
                while (reader.Read())
                {
                    var entity = new GoodsInventoryEntity();
                    entity.Init(reader);
                    //entity.ProductName = reader["name"].ToString();
                    //entity.ProductFullName = reader["full_name"].ToString();

                    list.Add(entity);
                }
            }

            return(list);
        }
Beispiel #2
0
        public static IList <GoodsInventoryEntity> Get(IList <string> productIds, string hospitalId, Database db, DbTransaction trans)
        {
            var sql = string.Format("select {0} from goods_inventory {2} where product_id in ('{1}') and hospital_id=@p_hospital_id", COLUMN_SQL, string.Join("','", productIds), TransHelper.UpdateLock(trans));

            if (db == null)
            {
                db = DatabaseFactory.CreateDatabase();
            }
            var dc = db.GetSqlStringCommand(sql);

            db.AddInParameter(dc, "p_hospital_id", DbType.String, hospitalId);

            var list   = new List <GoodsInventoryEntity>();
            var reader = trans == null?db.ExecuteReader(dc) : db.ExecuteReader(dc, trans);

            try
            {
                while (reader.Read())
                {
                    var entity = new GoodsInventoryEntity();
                    entity.Init(reader);

                    list.Add(entity);
                }
            }
            finally
            {
                reader.Close();
            }

            return(list);
        }
Beispiel #3
0
        public static GoodsInventoryEntity QueryEarlyExpiredDateInventory(string productId, string storeroomId, DateTime expiredDate, string hospitalId)
        {
            var sql = string.Format(@"select top 1 {0} from goods_inventory 
where hospital_id=@p_hospital_id and product_id=@p_product_id and storeroom_id=@p_storeroom_id
    and expired_date<@p_expired_date and expired_date>@p_today 
order by expired_date
", COLUMN_SQL);
            var db  = DatabaseFactory.CreateDatabase();
            var cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "p_hospital_id", DbType.String, hospitalId);
            db.AddInParameter(cmd, "p_product_id", DbType.String, productId);
            db.AddInParameter(cmd, "p_storeroom_id", DbType.String, storeroomId);
            db.AddInParameter(cmd, "p_expired_date", DbType.DateTime, expiredDate);
            db.AddInParameter(cmd, "p_today", DbType.DateTime, DateTime.Today);

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

                    return(entity);
                }
            }

            return(null);
        }
Beispiel #4
0
        public static IList <GoodsInventoryEntity> Query(DateRangeCondition condition, PagerInfo pager)
        {
            pager.ComputePageCount(QueryCount(condition));

            var list     = new List <GoodsInventoryEntity>();
            var orderSql = " ORDER BY ";

            if (pager.OrderFields.Count > 0)
            {
                foreach (var field in pager.OrderFields)
                {
                    orderSql += field.Field + (field.Desc ? " DESC" : "") + ",";
                }
            }
            else
            {
                orderSql += "name";
            }

            var sql = string.Format(GetBaseQuerySql(condition), "a.id,a.product_id,a.hospital_id,a.original_count,a.usable_count,a.granted_count,a.split_count,b.name,b.full_name");

            sql = @"SELECT * FROM
            (
                SELECT ROW_NUMBER() OVER(" + orderSql + @") pid,*
                FROM (" + sql + @") t 
            ) t1 WHERE t1.pid BETWEEN @p_pageNo * @p_pageSize + 1 AND (@p_pageNo + 1) * @p_pageSize";

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

            AddParameter(dc, db, condition);

            db.AddInParameter(dc, "p_pageNo", DbType.Int32, pager.PageIndex);
            db.AddInParameter(dc, "p_pageSize", DbType.Int32, pager.PageSize);

            using (var reader = db.ExecuteReader(dc))
            {
                while (reader.Read())
                {
                    var entity = new GoodsInventoryEntity();
                    entity.Init(reader);
                    //entity.ProductName = reader["name"].ToString();
                    //entity.ProductFullName = reader["full_name"].ToString();

                    list.Add(entity);
                }
            }

            return(list);
        }
Beispiel #5
0
        public static GoodsInventoryEntity Get(string productId, string hospitalId)
        {
            var sql = string.Format("select {0} from goods_inventory where product_id=@p_product_id and hospital_id=@p_hospital_id", COLUMN_SQL);

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

            db.AddInParameter(dc, "p_product_id", DbType.String, productId);
            db.AddInParameter(dc, "p_hospital_id", DbType.String, hospitalId);

            using (var reader = db.ExecuteReader(dc))
            {
                if (reader.Read())
                {
                    var entity = new GoodsInventoryEntity();
                    entity.Init(reader);

                    return(entity);
                }
            }

            return(null);
        }