예제 #1
0
파일: UtilService.cs 프로젝트: ZackQuy/MeU
 /// <summary>
 /// 分页查询
 /// </summary>
 /// <param name="pSpPagingParam">查询参数</param>
 /// <param name="total">表总条数</param>
 /// <returns>表格</returns>
 public DataTable QueryPageTable(SpPagingParam pSpPagingParam, ref int total)
 {
     try
     {
         MySqlParameter[] parameters =
         {
             new MySqlParameter("?p_tablename",  MySqlDbType.VarChar, 100),
             new MySqlParameter("?p_sort",       MySqlDbType.VarChar, 100),
             new MySqlParameter("?p_pagesize",   MySqlDbType.Int32),
             new MySqlParameter("?p_startindex", MySqlDbType.Int32),
             new MySqlParameter("?p_filter",     MySqlDbType.VarChar, 100),
             new MySqlParameter("?p_fields",     MySqlDbType.VarChar, 100),
             new MySqlParameter("?p_outrows",    MySqlDbType.Int32),
         };
         parameters[0].Value     = pSpPagingParam.tableName;
         parameters[1].Value     = pSpPagingParam.sort;
         parameters[2].Value     = pSpPagingParam.pageSize;
         parameters[3].Value     = pSpPagingParam.page;
         parameters[4].Value     = pSpPagingParam.whereClause;
         parameters[5].Value     = pSpPagingParam.fields;
         parameters[6].Direction = ParameterDirection.Output;
         DataSet   ds       = new DataSet();
         DataTable dtResult = ApplicationManager.DefaultConnection.QueryData("GetDataByPageTABLE", parameters, 1).Tables[0];
         total = Convert.ToInt32(parameters[6].Value);
         return(dtResult);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #2
0
        protected override string OnExecute()
        {
            HttpContext context = this.SpContext as HttpContext;

            try
            {
                string tableName   = "p_terminal";                     //设备表
                string fields      = "cid,sbbm,sbmc,jxh,jd,wd";        //返回字段
                string whereClause = context.Request["keyWord"] ?? ""; //where部分
                string strPage     = context.Request["start"] ?? "1";  //
                string strPageSize = context.Request["pageSize"] ?? "15";
                string sort        = context.Request["sort"] ?? "";
                string userName    = context.Request["userName"] ?? "";
                int    page        = Convert.ToInt32(strPage);
                if (page <= 0)
                {
                    page = 1;
                }
                if (!string.IsNullOrEmpty(whereClause))
                {
                    whereClause = string.Format("where CONCAT(IFNULL(sbmc,''),' ',IFNULL(sbbm,''),' ',IFNULL(jxh,'')) LIKE '%{0}%'", whereClause);
                }
                int           pageSize       = Convert.ToInt32(strPageSize);
                SpPagingParam pSpPagingParam = new SpPagingParam()
                {
                    tableName   = tableName,
                    pageSize    = pageSize,
                    page        = page,
                    sort        = sort,
                    whereClause = whereClause,
                    fields      = fields
                };
                IUtilService utilService = SpServiceFactory.CreateUtilService();
                int          total       = 0;
                DataTable    dtResult    = utilService.QueryPageTable(pSpPagingParam, ref total);
                return(this.ToJsonP(dtResult.ToStandardJson(true, total, "分页列表数据")));
            }
            catch (Exception ex)
            {
                Log.Error("分页查询异常:" + ex.Message.ToString());
                throw ex;
            }
        }