/// <summary> /// 查询数据列表、返回 DataTable /// </summary> /// <param name="strSql">Sql语句</param> /// <param name="jqgridparam">分页参数</param> /// <returns></returns> public DataTable FindTablePageBySql(string strSql, ref JqGridParam jqgridparam) { string orderField = jqgridparam.sidx; string orderType = jqgridparam.sord; int pageIndex = jqgridparam.page; int pageSize = jqgridparam.rows; int totalRow = jqgridparam.records; DataTable dt = DataFactory.Database().FindTablePageBySql(strSql, orderField, orderType, pageIndex, pageSize, ref totalRow); jqgridparam.records = totalRow; return dt; }
public ActionResult TestTableMegaListJson(JqGridParam jqgridparam) { Stopwatch watch = CommonHelper.TimerStart(); string UserId = ManageProvider.Provider.Current().UserId; DataTable ListData = this.FindTablePageBySql("SELECT TestId, Code, FullName, CreateDate, CreateUserName, Remark FROM TestTable", ref jqgridparam); var JsonData = new { total = jqgridparam.total, page = jqgridparam.page, records = jqgridparam.records, costtime = CommonHelper.TimerEnd(watch), rows = ListData, }; return Content(JsonData.ToJson()); }
/// <summary> /// 获取数据库表数据 /// </summary> /// <param name="tableName">表名</param> /// <param name="ParameterJson">查询条件</param> /// <param name="jqgridparam">分页参数</param> /// <returns></returns> public DataTable GetDataTableList(string tableName, string ParameterJson, ref JqGridParam jqgridparam) { StringBuilder strSql = new StringBuilder(); List<DbParameter> parameter = new List<DbParameter>(); strSql.Append("SELECT * FROM " + tableName + " WHERE 1=1"); if (!string.IsNullOrEmpty(ParameterJson) && ParameterJson.Length > 2) { strSql.Append(ConditionBuilder.GetWhereSql(ParameterJson.JonsToList<Condition>(), out parameter)); } int totalRow = jqgridparam.records; DataTable dt = DataFactory.Database().FindTablePageBySql(strSql.ToString(), parameter.ToArray(), jqgridparam.sidx, jqgridparam.sord, jqgridparam.page, jqgridparam.rows, ref totalRow); jqgridparam.records = totalRow; return dt; }
/// <summary> /// 查询数据库表数据 /// </summary> /// <param name="tableName">表名</param> /// <param name="ParameterJson">查询条件</param> /// <param name="jqgridparam">分页参数</param> /// <returns></returns> public ActionResult GridDataTableListJson(string tableName, string ParameterJson, JqGridParam jqgridparam) { try { Stopwatch watch = CommonHelper.TimerStart(); DataTable ListData = base_databasebll.GetDataTableList(tableName, ParameterJson, ref jqgridparam); var JsonData = new { total = jqgridparam.total, page = jqgridparam.page, records = jqgridparam.records, costtime = CommonHelper.TimerEnd(watch), rows = ListData, }; string str = JsonData.ToJson(); return Content(JsonData.ToJson()); } catch (Exception ex) { Base_SysLogBll.Instance.WriteLog("", OperationType.Query, "-1", "异常错误:" + ex.Message); return null; } }