public ActionResult AddAjax(JournalInfoEntity journalEntity) { try { if (!Request.IsAjaxRequest()) { return Content("{\"result\":\"failure\",\"msg\":\"非法请求\"}"); } string msg = ""; if (ModelState.IsValid) { IJournalInfoService journalService = ServiceContainer.Instance.Container.Resolve<IJournalInfoService>(); JournalInfoQuery queryEntity = new JournalInfoQuery(); queryEntity.JournalName = WKT.Common.Security.SecurityUtils.SafeSqlString(journalEntity.JournalName); IList<JournalInfoEntity> list = journalService.GetJournalInfoList(queryEntity); if (list.Count > 0) { msg = "{\"result\":\"failure\",\"msg\":\"该编辑部已经存在\"}"; } else { bool flag = journalService.AddJournalInfo(journalEntity); if (flag) { msg = "{\"result\":\"success\"}"; } else { msg = "{\"result\":\"failure\",\"msg\":\"添加失败,请检查\"}"; } } } else { msg = "{\"result\":\"failure\",\"msg\":\"" + this.ExpendErrors() + "\"}"; } return Content(msg); } catch (Exception ex) { LogProvider.Instance.Error("添加编辑部异常:" + ex.Message); return Content("{\"result\":\"error\",\"msg\":\"" + ex.Message + "\"}"); } }
/// <summary> /// 将查询实体转换为Where语句 /// <param name="query">查询实体</param> /// <returns>获取Where语句,不包含Where</returns> /// </summary> public string JournalInfoQueryToSQLWhere(JournalInfoQuery query) { StringBuilder sbWhere = new StringBuilder(" 1=1 "); if (query.Status != null) { sbWhere.Append(" AND Status= ").Append(query.Status.Value); } if (!string.IsNullOrEmpty(query.JournalName)) { sbWhere.AppendFormat(" AND JournalName='{0}'", WKT.Common.Security.SecurityUtils.SafeSqlString(query.JournalName)); } if (!string.IsNullOrEmpty(query.ServiceStartDate)) { sbWhere.AppendFormat(" AND ServiceStartDate>='{0}'", WKT.Common.Security.SecurityUtils.SafeSqlString(query.ServiceStartDate)); } if (!string.IsNullOrEmpty(query.ServiceEndDate)) { sbWhere.AppendFormat(" AND ServiceEndDate<='{0}'", WKT.Common.Security.SecurityUtils.SafeSqlString(query.ServiceEndDate)); } if (sbWhere.ToString() == " 1=1 ") { return string.Empty; } else { return sbWhere.ToString(); } }
/// <summary> /// 将查询实体转换为Order语句 /// <param name="query">查询实体</param> /// <returns>获取Order语句,不包含Order</returns> /// </summary> public string JournalInfoQueryToSQLOrder(JournalInfoQuery query) { return " JournalID DESC"; }
public Pager<JournalInfoEntity> GetJournalInfoPageList(JournalInfoQuery query) { int recordCount=0; string whereSQL=JournalInfoQueryToSQLWhere(query); string orderBy=JournalInfoQueryToSQLOrder(query); DataSet ds=db.GetPagingData("JournalInfo","JournalID,JournalName,SiteUrl,ServiceStartDate,ServiceEndDate,Linkman,LinkTel,Fax,Email,Mobile,Address,ZipCode,AuthorizationCode,Status,Note,AddDate",orderBy,whereSQL,query.CurrentPage,query.PageSize,out recordCount); Pager<JournalInfoEntity> pager=new Pager<JournalInfoEntity>(); if(ds!=null && ds.Tables.Count>0) { pager.ItemList= MakeJournalInfoList(ds.Tables[0]); } pager.CurrentPage=query.CurrentPage; pager.PageSize=query.PageSize; pager.TotalRecords=recordCount; return pager; }
public List<JournalInfoEntity> GetJournalInfoList(JournalInfoQuery query) { List<JournalInfoEntity> list = new List<JournalInfoEntity>(); StringBuilder sqlCommandText = new StringBuilder(); sqlCommandText.Append("SELECT JournalID,JournalName,SiteUrl,ServiceStartDate,ServiceEndDate,Linkman,LinkTel,Fax,Email,Mobile,Address,ZipCode,AuthorizationCode,Status,Note,AddDate FROM dbo.JournalInfo WITH(NOLOCK)"); string whereSQL = JournalInfoQueryToSQLWhere(query); string orderBy=JournalInfoQueryToSQLOrder(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 = MakeJournalInfoList(dr); } return list; }
/// <summary> /// 分页获取符合查询条件的数据 /// </summary> /// <param name="journalInfoQuery">JournalInfoQuery查询实体对象</param> /// <returns>Pager<JournalInfoEntity></returns> public Pager<JournalInfoEntity> GetJournalInfoPageList(JournalInfoQuery journalInfoQuery) { return JournalInfoBusProvider.GetJournalInfoPageList(journalInfoQuery); }
/// <summary> /// 获取所有符合查询条件的数据 /// </summary> /// <param name="journalInfoQuery">JournalInfoQuery查询实体对象</param> /// <returns>List<JournalInfoEntity></returns> public List<JournalInfoEntity> GetJournalInfoList(JournalInfoQuery journalInfoQuery) { return JournalInfoBusProvider.GetJournalInfoList(journalInfoQuery); }
public ActionResult IndexAjax(JournalInfoQuery queryEntity) { if (!Request.IsAjaxRequest()) { return Content("{\"result\":\"error\",\"msg\":\"非法访问\"}"); } else { IJournalInfoService journalService = ServiceContainer.Instance.Container.Resolve<IJournalInfoService>(); queryEntity.CurrentPage = queryEntity.CurrentPage + 1; WKT.Model.Pager<JournalInfoEntity> journalList = journalService.GetJournalInfoPageList(queryEntity); if (journalList != null) { return Content("{\"result\":\"success\",\"msg\":\"成功\",\"data\":" + JsonConvert.SerializeObject(journalList) + "}"); } else { return Content("{\"result\":\"error\",\"msg\":\"系统出现异常,请稍后再试\"}"); } } }
/// <summary> /// 编辑部管理 /// </summary> /// <returns></returns> public ActionResult Index() { ViewBag.TotalCount = 0; IJournalInfoService journalService = ServiceContainer.Instance.Container.Resolve<IJournalInfoService>(); JournalInfoQuery queryEntity = new JournalInfoQuery(); queryEntity.CurrentPage = 1; Pager<JournalInfoEntity> pagerJournalList = journalService.GetJournalInfoPageList(queryEntity); IList<JournalInfoEntity> listJournal = new List<JournalInfoEntity>(); if (pagerJournalList != null) { listJournal = pagerJournalList.ItemList; ViewBag.TotalCount = pagerJournalList.TotalRecords; } return View(listJournal); }
/// <summary> /// 获取所有符合查询条件的数据 /// </summary> /// <param name="journalInfoQuery">JournalInfoQuery查询实体对象</param> /// <returns>List<JournalInfoEntity></returns> public List<JournalInfoEntity> GetJournalInfoList(JournalInfoQuery journalInfoQuery) { return JournalInfoDataAccess.Instance.GetJournalInfoList(journalInfoQuery); }