public static IList <DispatchFormEntity> GetDispatches(int formNo, string hospitalID)
        {
            var sql = string.Format("select {0} from dispatch_form where order_form_no=@p_form_no and hospital_id=@p_hospital_id", COLUMN_SQL);

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

            db.AddInParameter(dc, "p_form_no", DbType.Int32, formNo);
            db.AddInParameter(dc, "p_hospital_id", DbType.String, hospitalID);

            var list = new List <DispatchFormEntity>();

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

                    list.Add(entity);
                }
            }

            return(list);
        }
        private static DispatchFormEntity Get(string id, Database db, DbTransaction trans)
        {
            var sql = string.Format("select {0} from dispatch_form {1} where id=@p_id", COLUMN_SQL, TransHelper.UpdateLock(trans));

            if (db == null)
            {
                db = DatabaseFactory.CreateDatabase();
            }

            var dc = db.GetSqlStringCommand(sql);

            db.AddInParameter(dc, "p_id", DbType.String, id);

            DispatchFormEntity entity = null;

            using (var reader = (trans == null ? db.ExecuteReader(dc) : db.ExecuteReader(dc, trans)))
            {
                while (reader.Read())
                {
                    entity = new DispatchFormEntity();
                    entity.Init(reader);

                    break;
                }
            }

            return(entity);
        }
        public static IList <DispatchFormEntity> Query(DispatchQueryCondition condition, PagerInfo pager)
        {
            var baseSql      = @"select {0} from dispatch_form where 1=1 {1}";
            var conditionSql = GetConditionSql(condition);

            var db = DatabaseFactory.CreateDatabase();

            pager.ComputePageCount(QueryCount(baseSql, conditionSql, condition, db));

            var orderSql = " order by ";

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

            var sql = string.Format(baseSql, COLUMN_SQL, conditionSql);

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

            var cmd = db.GetSqlStringCommand(sql);

            AddParameters(condition, db, cmd);
            db.AddInParameter(cmd, "p_pageNo", DbType.Int32, pager.PageIndex);
            db.AddInParameter(cmd, "p_pageSize", DbType.Int32, pager.PageSize);

            var list = new List <DispatchFormEntity>();

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

                    list.Add(entity);
                }
            }

            return(list);
        }
        public static DispatchFormEntity Get(string id)
        {
            var sql = string.Format("select {0} from dispatch_form where id=@p_id", COLUMN_SQL);

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

            db.AddInParameter(dc, "p_id", DbType.String, id);

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

                    return(entity);
                }
            }

            return(null);
        }
        public static IList <DispatchFormEntity> Query(IList <string> orderDetailIds)
        {
            var list = new List <DispatchFormEntity>();

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

            IList <string> paramNames;
            string         paramSql;

            LIMS.Util.StringHelper.GenerInParameters("p_order_detail_id", orderDetailIds.Count, out paramNames, out paramSql);

            var sql = string.Format(@"select {0} from dispatch_form where order_detail_id in ({1}) and status in ('{2}','{3}','{4}')", COLUMN_SQL, paramSql, DispatchFormStatus.Waiting, DispatchFormStatus.Confirmed, DispatchFormStatus.Dispatching);

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

            for (var i = 0; i < orderDetailIds.Count; i++)
            {
                db.AddInParameter(dc, paramNames[i], DbType.String, orderDetailIds[i]);
            }

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

                    list.Add(entity);
                }
            }

            return(list);
        }