/// <summary> /// 获取符合查询条件的前几行数据 /// </summary> public List <Demo.SQLServerModelQuery.Model.SysUserModel> GetList(int Top, Demo.SQLServerModelQuery.Model.SysUserQueryModel query, string filedOrder) { // 从查询条件获取SQL条件语句 string strWhere = ConditionToSql.ToSqlText(query.Condition); SqlParameter[] paras = ConditionToSql.ToSqlParas(query.Condition); // 构造SQL查询语句 StringBuilder strSql = new StringBuilder(); strSql.Append("select "); if (Top > 0) { strSql.Append(" top " + Top.ToString()); } strSql.Append(" * "); strSql.Append(" FROM SysUser "); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } strSql.Append(" order by " + filedOrder); // 执行查询 DataSet ds = SQLServerHelper.Query(strSql.ToString(), paras); // 转换查询结果为List<T>,并返回 return(DataTableToList(ds.Tables[0])); }
/// <summary> /// 获取符合查询条件的全部记录数 /// </summary> public int InfoCount(Demo.SQLServerModelQuery.Model.SysUserQueryModel query) { // 从查询条件获取SQL条件语句 string strWhere = ConditionToSql.ToSqlText(query.Condition); SqlParameter[] paras = ConditionToSql.ToSqlParas(query.Condition); return(InfoCount(strWhere, paras)); }
/// <summary> /// 获取符合查询条件的分页数据 /// </summary> /// <param name="query">查询条件</param> /// <param name="page">分页条件</param> /// <returns></returns> public List <Demo.SQLServerModelQuery.Model.SysUserModel> GetList(Demo.SQLServerModelQuery.Model.SysUserQueryModel query, string sortFiled, ref PageInfo page) { //if(string.IsNullOrEmpty(sortFiled)){ // sortFiled="AddTime DESC"; //} // 从查询条件获取SQL条件语句 string strWhere = ConditionToSql.ToSqlText(query.Condition); SqlParameter[] paras = ConditionToSql.ToSqlParas(query.Condition); // 总记录数 page.RecordCount = InfoCount(strWhere, paras); // 分页数据 string strSQL = PageQueryHelper.GetPageSQL(page.CurrentPage, page.PageSize, strWhere, sortFiled, "SysUser", "ID"); DataSet ds = SQLServerHelper.Query(strSQL, paras); return(DataTableToList(ds.Tables[0])); }