Example #1
0
        /// <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);
        }
Example #2
0
        /// <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);
        }
Example #3
0
        /// <summary>
        /// 返回DataSet结果存储过程
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="Model"></param>
        /// <param name="ConnectionName">数据库连接名字</param>
        /// <returns></returns>
        public static DataSet GTDsStorage <T>(this T Model, string ConnectionName = null) where T : new()
        {
            List <SqlParameter> Parameter = new List <SqlParameter>();

            PropertyInfo[] propertys = Model.GetType().GetProperties();
            string         ModelName = Model.GetType().Name;

            foreach (PropertyInfo pi in propertys)
            {
                GDColoum objAttrs = pi.GetCustomAttribute <GDColoum>();
                if (objAttrs != null)
                {
                    object obj = pi.GetValue(Model, null);
                    if (obj != null)
                    {
                        Parameter.Add(new SqlParameter("@" + pi.Name, pi.GetValue(Model, null)));
                    }
                }
            }
            SQLServerDBHeper Helper = GetDBHeper(ConnectionName);

            return(Helper.MoreExecuteStorage(ModelName, Parameter.ToArray()));
        }