/// <summary> /// 分页获取符合查询条件的数据 /// </summary> /// <param name="apiServerInfoQuery">ApiServerInfoQuery查询实体对象</param> /// <returns>Pager<ApiServerInfoEntity></returns> public Pager<ApiServerInfoEntity> GetApiServerInfoPageList(ApiServerInfoQuery apiServerInfoQuery) { return ApiServerInfoBusProvider.GetApiServerInfoPageList(apiServerInfoQuery); }
public Pager<ApiServerInfoEntity> GetApiServerInfoPageList(ApiServerInfoQuery query) { int recordCount=0; string whereSQL=ApiServerInfoQueryToSQLWhere(query); string orderBy=ApiServerInfoQueryToSQLOrder(query); DataSet ds=db.GetPagingData("ApiServerInfo","ApiServerID,SiteName,SiteUrl,Status,Note,AddDate",orderBy,whereSQL,query.CurrentPage,query.PageSize,out recordCount); Pager<ApiServerInfoEntity> pager=new Pager<ApiServerInfoEntity>(); if(ds!=null && ds.Tables.Count>0) { pager.ItemList= MakeApiServerInfoList(ds.Tables[0]); } pager.CurrentPage=query.CurrentPage; pager.PageSize=query.PageSize; pager.TotalRecords=recordCount; return pager; }
/// <summary> /// 将查询实体转换为Order语句 /// <param name="query">查询实体</param> /// <returns>获取Order语句,不包含Order</returns> /// </summary> public string ApiServerInfoQueryToSQLOrder(ApiServerInfoQuery query) { return " ApiServerID DESC"; }
public List<ApiServerInfoEntity> GetApiServerInfoList(ApiServerInfoQuery query) { List<ApiServerInfoEntity> list = new List<ApiServerInfoEntity>(); StringBuilder sqlCommandText = new StringBuilder(); sqlCommandText.Append("SELECT ApiServerID,SiteName,SiteUrl,Status,Note,AddDate FROM dbo.ApiServerInfo WITH(NOLOCK)"); string whereSQL = ApiServerInfoQueryToSQLWhere(query); string orderBy=ApiServerInfoQueryToSQLOrder(query); if(!string.IsNullOrEmpty(whereSQL)) sqlCommandText.Append(" WHERE " + whereSQL); if(!string.IsNullOrEmpty(orderBy)) sqlCommandText.Append(" ORDER BY " + orderBy); DbCommand cmd = db.GetSqlStringCommand(sqlCommandText.ToString()); using(IDataReader dr = db.ExecuteReader(cmd)) { list = MakeApiServerInfoList(dr); } return list; }
/// <summary> /// 将查询实体转换为Where语句 /// <param name="query">查询实体</param> /// <returns>获取Where语句,不包含Where</returns> /// </summary> public string ApiServerInfoQueryToSQLWhere(ApiServerInfoQuery query) { StringBuilder sbWhere = new StringBuilder(" 1=1 "); if (query.Status != null) { sbWhere.Append(" AND Status= ").Append(query.Status.Value); } if (!string.IsNullOrEmpty(query.SiteName)) { sbWhere.AppendFormat(" AND SiteName='{0}'", WKT.Common.Security.SecurityUtils.SafeSqlString(query.SiteName)); } if (sbWhere.ToString() == " 1=1 ") { return string.Empty; } else { return sbWhere.ToString(); } }
/// <summary> /// 获取所有符合查询条件的数据 /// </summary> /// <param name="apiServerInfoQuery">ApiServerInfoQuery查询实体对象</param> /// <returns>List<ApiServerInfoEntity></returns> public List<ApiServerInfoEntity> GetApiServerInfoList(ApiServerInfoQuery apiServerInfoQuery) { return ApiServerInfoDataAccess.Instance.GetApiServerInfoList(apiServerInfoQuery); }
public ActionResult IndexAjax(ApiServerInfoQuery queryEntity) { if (!Request.IsAjaxRequest()) { return Content("{\"result\":\"error\",\"msg\":\"非法访问\"}"); } else { IApiServerInfoService apiServerService = ServiceContainer.Instance.Container.Resolve<IApiServerInfoService>(); queryEntity.CurrentPage = queryEntity.CurrentPage + 1; WKT.Model.Pager<ApiServerInfoEntity> apiServerPagerList = apiServerService.GetApiServerInfoPageList(queryEntity); if (apiServerPagerList != null) { return Content("{\"result\":\"success\",\"msg\":\"成功\",\"data\":" + JsonConvert.SerializeObject(apiServerPagerList) + "}"); } else { return Content("{\"result\":\"error\",\"msg\":\"系统出现异常,请稍后再试\"}"); } } }
/// <summary> /// 首页 /// </summary> /// <returns></returns> public ActionResult Index() { ViewBag.TotalCount = 0; IApiServerInfoService apiServerService = ServiceContainer.Instance.Container.Resolve<IApiServerInfoService>(); ApiServerInfoQuery queryEntity = new ApiServerInfoQuery(); queryEntity.CurrentPage = 1; Pager<ApiServerInfoEntity> pagerApiServerList = apiServerService.GetApiServerInfoPageList(queryEntity); IList<ApiServerInfoEntity> listServer = new List<ApiServerInfoEntity>(); if (pagerApiServerList != null) { listServer = pagerApiServerList.ItemList; ViewBag.TotalCount = pagerApiServerList.TotalRecords; } return View(listServer); }