public List <MoveFormEntity> FindAll(DateRangeCondition condition, PagerInfo pager) { pager.ComputePageCount(QueryCount(condition)); var list = new List <MoveFormEntity>(); var orderSql = " ORDER BY "; if (pager.OrderFields.Count > 0) { foreach (var field in pager.OrderFields) { orderSql += field.Field + (field.Desc ? " DESC" : "") + ","; } } else { orderSql += "form_no DESC"; } var sql = string.Format(@"SELECT {0} FROM move_form WHERE status != 'deleted' and {1}", MOVE_COLUMNS, GetConditionSql(condition)); sql = @"SELECT * FROM ( SELECT ROW_NUMBER() OVER(" + orderSql + @") pid," + MOVE_COLUMNS + @" FROM (" + sql + @") t ) t1 WHERE t1.pid BETWEEN @p_pageNo * @p_pageSize + 1 AND (@p_pageNo + 1) * @p_pageSize "; var dc = Db.GetSqlStringCommand(sql); AddParameter(dc, condition); Db.AddInParameter(dc, "p_pageNo", DbType.Int32, pager.PageIndex); Db.AddInParameter(dc, "p_pageSize", DbType.Int32, pager.PageSize); using (IDataReader reader = Db.ExecuteReader(dc)) { while (reader.Read()) { var entity = new MoveFormEntity(); entity.Init(reader); list.Add(entity); } } return(list); }
public MoveFormEntity FindOne(string id) { var sql = string.Format("select {0} from move_form where id = @p_id", MOVE_COLUMNS); 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 MoveFormEntity(); entity.Init(reader); return(entity); } } return(null); }