/// <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="Source">对象</param> /// <returns></returns> public List <T> GDList <T>(T Source, Expression <Func <T, bool> > Exp) where T : new() { T t = new T(); string Where = Exp.DealExpress(); SQLPropertyInfo PropertyInfos = new SQLPropertyInfo(); string Sort = PropertyInfos.GDGetIsIncrease(t) + " Desc"; DataTable dt = BsDataTable($"select * from {typeof(T).Name} where 1=1 {(string.IsNullOrEmpty(Where) ? "" : (" and " + Where))} Order By {Sort}"); return(dt.ToModel <T>()); }
/// <summary> /// 获取多条数据无排序,默认排序为主键倒序 /// </summary> /// <typeparam name="T">对象</typeparam> /// <param name="Source">对象</param> /// <returns></returns> public List <T> GDList <T>(IEnumerable <T> Source) 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"; DataTable dt = BsDataTable($"select * from {typeof(T).Name} where 1=1 {Where} Order By {Sort}"); return(dt.ToModel <T>()); }