Esempio n. 1
0
        /// <summary>
        /// 返回分页数据
        /// Created:20170330(ChengMengjia)
        /// </summary>
        /// <param name="QueryHead"></param>
        /// <param name="QueryBody"></param>
        /// <param name="qlist"></param>
        /// <returns></returns>
        public static GridData GetGridData(int PageIndex, int PageSize, string QueryHead, string QueryBody, List <QueryField> qlist)
        {
            GridData result = new GridData();

            result.count = 0;
            result.data  = new DataTable();
            string  sql = "select count(1) n " + QueryBody;
            DataSet ds  = ExecuteDataset(sql, qlist);

            if (ds != null && ds.Tables.Count > 0)
            {
                result.count = int.Parse(ds.Tables[0].Rows[0]["n"].ToString());
                sql          = QueryHead + QueryBody;
                DataTable dt = NHHelper.ExecutePageDataTable(sql, qlist, PageSize, PageIndex);
                if (dt != null)
                {
                    dt.Columns.Add("RowNo");
                    int i = 1;
                    if (PageIndex >= 1)
                    {
                        i += (PageIndex - 1) * PageSize;
                    }
                    foreach (DataRow row in dt.Rows)
                    {
                        row["RowNo"] = i;
                        i++;
                    }
                }
                result.data = dt;
            }
            return(result);
        }