/// <summary> /// 分页 /// </summary> /// <typeparam name="T">对象</typeparam> /// <param name="Source">List</param> /// <param name="Exp">查询条件</param> /// <returns></returns> public GDPaging <T> GDPaging <T>(T Source, Expression <Func <T, bool> > Exp, int ThisPage = 1, int PageSize = 10) where T : new() { T t = new T(); string Where = Exp.DealExpress(); SQLPropertyInfo PropertyInfos = new SQLPropertyInfo(); string Sort = PropertyInfos.GDGetIsIncrease(t) + " Desc"; GDPaging <T> GDModel = new GDPaging <T>(); List <T> lt = new List <T>(); SqlParameter[] parameter = { new SqlParameter("@ThisPage", ThisPage), new SqlParameter("@PageSize", PageSize), new SqlParameter("@TableName", typeof(T).Name), new SqlParameter("@Condition", string.IsNullOrEmpty(Where)?"":(" and " + Where)), new SqlParameter("@Sorting", Sort) }; DataSet ds = BsStorageDs("GT_Paging", parameter); if (ds == null || ds.Tables.Count < 2 || ds.Tables[0].Rows.Count == 0) { GDModel.GDModel = new List <T>(); return(GDModel); } else { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { lt.Add(ds.Tables[0].Rows[i].ToModel <T>()); } GDModel.GDModel = lt; GDModel.Count = Convert.ToInt32(ds.Tables[1].Rows[0][0]); } return(GDModel); }
/// <summary> /// 分页 /// </summary> /// <typeparam name="T">对象</typeparam> /// <param name="Source">List</param> /// <returns></returns> public GDPaging <T> GDPaging <T>(IEnumerable <T> Source, int ThisPage = 1, int PageSize = 10) where T : new() { T t = new T(); string Where = Source.ToString().Contains("Where") ? (Source.AsQueryable().Expression).DealExpress() : ""; SQLPropertyInfo PropertyInfos = new SQLPropertyInfo(); string Sort = PropertyInfos.GDGetIsIncrease(t) + " Desc"; GDPaging <T> GDModel = new GDPaging <T>(); List <T> lt = new List <T>(); SqlParameter[] parameter = { new SqlParameter("@ThisPage", ThisPage), new SqlParameter("@PageSize", PageSize), new SqlParameter("@TableName", typeof(T).Name), new SqlParameter("@Condition", Where), new SqlParameter("@Sorting", Sort) }; DataSet ds = BsStorageDs("GT_Paging", parameter); if (ds == null || ds.Tables.Count < 2 || ds.Tables[0].Rows.Count == 0) { GDModel.GDModel = new List <T>(); return(GDModel); } else { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { lt.Add(ds.Tables[0].Rows[i].ToModel <T>()); } GDModel.GDModel = lt; GDModel.Count = Convert.ToInt32(ds.Tables[1].Rows[0][0]); } return(GDModel); }
/// <summary> /// 分页查询 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="ThisPage">当前页数</param> /// <param name="Storing">排序</param> /// <param name="PageSize">分页大小</param> /// <param name="source">查询条件</param> /// <param name="ConnectionName">数据库连接名字</param> /// <returns></returns> public static GDPaging <T> GTPaging <T>(this IEnumerable <T> source, int ThisPage = 1, int PageSize = 10, string Storing = null, string ConnectionName = null) where T : new() { SQLServerDBHeper Helper = GetDBHeper(ConnectionName); GDPaging <T> GDModel = new GDPaging <T>(); List <T> lt = new List <T>(); string ModelName = typeof(T).Name; List <string> Conditions = new List <string>(); string DbValue = string.Empty; SqlParameter[] parameter = { new SqlParameter("@ThisPage", ThisPage), new SqlParameter("@PageSize", PageSize), new SqlParameter("@TableName", ModelName), new SqlParameter("@Condition", source.ToString().Contains("Where")?(source.AsQueryable().Expression).DealExpress():""), new SqlParameter("@Sorting", (string.IsNullOrEmpty(Storing)?(" Id desc"):Storing)) }; DataSet ds = Helper.MoreExecuteStorage("GT_Paging", parameter); if (ds == null || ds.Tables.Count < 2 || ds.Tables[0].Rows.Count == 0) { GDModel.GDModel = new List <T>(); return(GDModel); } else { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { lt.Add(ds.Tables[0].Rows[i].ToModel <T>()); } GDModel.GDModel = lt; GDModel.Count = Convert.ToInt32(ds.Tables[1].Rows[0][0]); } return(GDModel); }
/// <summary> /// 分页查询 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="Model">对象</param> /// <param name="ThisPage">当前页数</param> /// <param name="Condition">条件</param> /// <param name="Storing">排序</param> /// <param name="PageSize">当前也分大小</param> /// <param name="ConnectionName">数据库连接名字</param> /// <returns></returns> public static GDPaging <T> GTPagingByCondition <T>(this T Model, int ThisPage, string Condition, int PageSize = 10, string Storing = null, string ConnectionName = null) where T : new() { SQLServerDBHeper Helper = GetDBHeper(ConnectionName); GDPaging <T> GDModel = new GDPaging <T>(); List <T> lt = new List <T>(); string ModelName = Model.GetType().Name; SqlParameter[] parameter = { new SqlParameter("@ThisPage", ThisPage), new SqlParameter("@PageSize", PageSize), new SqlParameter("@TableName", ModelName), new SqlParameter("@Condition", Condition), new SqlParameter("@Sorting", (string.IsNullOrEmpty(Storing)?(" Id desc"):Storing)) }; DataSet ds = Helper.MoreExecuteStorage("GT_Paging", parameter); if (ds == null || ds.Tables.Count < 2 || ds.Tables[0].Rows.Count == 0) { return(GDModel); } else { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { lt.Add(ds.Tables[0].Rows[i].ToModel <T>()); } GDModel.GDModel = lt; GDModel.Count = Convert.ToInt32(ds.Tables[1].Rows[0][0]); } return(GDModel); }
/// <summary> /// 分页 /// </summary> /// <typeparam name="T">对象</typeparam> /// <typeparam name="TRuslt">对象</typeparam> /// <param name="Source">List</param> /// <param name="Exp">查询条件</param> /// <param name="OrderBy">排序字段</param> /// <param name="SType">排序类型</param> /// <param name="ThisPage"></param> /// <param name="PageSize"></param> /// <returns></returns> public GDPaging <T> GDPaging <T, TRuslt>(T Source, Expression <Func <T, bool> > Exp, Expression <Func <T, TRuslt> > OrderBy, SQLEnum.SortType SType, int ThisPage = 1, int PageSize = 10) where T : new() { string Where = Exp.DealExpress(); string[] Sort = OrderBy.DealExpress().Split(','); for (int i = 0; i < Sort.Length; i++) { Sort[i] = $" {Sort[i]} {Enum.GetName(typeof(SQLEnum.SortType), SType)}"; } GDPaging <T> GDModel = new GDPaging <T>(); List <T> lt = new List <T>(); SqlParameter[] parameter = { new SqlParameter("@ThisPage", ThisPage), new SqlParameter("@PageSize", PageSize), new SqlParameter("@TableName", typeof(T).Name), new SqlParameter("@Condition", (string.IsNullOrEmpty(Where)?"":(" and " + Where))), new SqlParameter("@Sorting", string.Join(",", Sort)) }; DataSet ds = BsStorageDs("GT_Paging", parameter); if (ds == null || ds.Tables.Count < 2 || ds.Tables[0].Rows.Count == 0) { GDModel.GDModel = new List <T>(); return(GDModel); } else { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { lt.Add(ds.Tables[0].Rows[i].ToModel <T>()); } GDModel.GDModel = lt; GDModel.Count = Convert.ToInt32(ds.Tables[1].Rows[0][0]); } return(GDModel); }
/// <summary> /// 分页 /// </summary> /// <typeparam name="T">对象</typeparam> /// <typeparam name="TRuslt">对象</typeparam> /// <param name="Source">List</param> /// <param name="OrderBy">排序</param> /// <param name="ThisPage">当前页</param> /// <param name="PageSize"></param> /// <returns></returns> public GDPaging <T> GDPaging <T, TRuslt>(IEnumerable <T> Source, Expression <Func <T, TRuslt> > OrderBy, int ThisPage = 1, int PageSize = 10) where T : new() { string Where = Source.ToString().Contains("Where") ? (Source.AsQueryable().Expression).DealExpress() : ""; string[] Sort = OrderBy.DealExpress().Split(','); for (int i = 0; i < Sort.Length; i++) { Sort[i] = $" {Sort[i]} Desc"; } GDPaging <T> GDModel = new GDPaging <T>(); List <T> lt = new List <T>(); SqlParameter[] parameter = { new SqlParameter("@ThisPage", ThisPage), new SqlParameter("@PageSize", PageSize), new SqlParameter("@TableName", typeof(T).Name), new SqlParameter("@Condition", Where), new SqlParameter("@Sorting", string.Join(",", Sort)) }; DataSet ds = BsStorageDs("GT_Paging", parameter); if (ds == null || ds.Tables.Count < 2 || ds.Tables[0].Rows.Count == 0) { GDModel.GDModel = new List <T>(); return(GDModel); } else { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { lt.Add(ds.Tables[0].Rows[i].ToModel <T>()); } GDModel.GDModel = lt; GDModel.Count = Convert.ToInt32(ds.Tables[1].Rows[0][0]); } return(GDModel); }