Exemplo n.º 1
0
        /// <summary>
        /// 获取easyui datagrid 所需要的JSON数据
        /// </summary>
        /// <param name="pageindex">第几页</param>
        /// <param name="pagesize">每页记录数</param>
        /// <param name="keyfield">主键字段名</param>
        /// <param name="where">条件</param>
        /// <param name="sort">排序字段</param>
        /// <param name="tablename">表名</param>
        /// <returns></returns>
        public static string GetJsonForEasyuiDatagrid(int pageindex, int pagesize, string keyfield, string where, string sort, string tablename)
        {
            int recordcount = 0;

            DataTable dt = SqlEasy.GetDataByPager2000("*", tablename, where, sort, keyfield, pageindex, pagesize, out recordcount);

            string s = "{\"total\":" + recordcount.ToString() + ",\"rows\":" + JsonConvert.SerializeObject(dt) + "}";

            return(s);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取指定表的数据,并转换为jqgrid 的JSON格式。适用于sql2000 以上版本
        /// </summary>
        /// <param name="fields">要选取的列,以逗号隔开</param>
        /// <param name="pageindex">当前第几页</param>
        /// <param name="pagesize">每页记录条数</param>
        /// <param name="orderfield">排序</param>
        /// <param name="key">关键字</param>
        /// <param name="where">条件</param>
        /// <param name="tbname">表名或视图名</param>
        /// <returns></returns>
        public static string GetJsonforjQgrid(string fields, int pageindex, int pagesize, string orderfield, string key, string where, string tbname)
        {
            int recordcount = 0;


            DataTable dt        = SqlEasy.GetDataByPager2000(fields, tbname, where, orderfield, key, pageindex, pagesize, out recordcount);
            int       pagecount = SqlEasy.GetDataPages(pagesize, recordcount);
            //string json = DataTableToJSONJquery(dt);
            string json = JsonConvert.SerializeObject(dt);

            string s = "{\"totalpages\":\"" + pagecount.ToString() + "\",\"currpage\":\"" + pageindex.ToString() + "\",\"totalrecords\":\"" + recordcount.ToString() + "\",\"griddata\":}";

            json = s.Insert(s.Length - 1, json);

            return(json);
        }