/// <summary> /// /// </summary> /// <param name="top">top=0取全部,top>0取top条</param> /// <param name="nodecode"></param> /// <param name="isAudit"></param> /// <param name="isIndex"></param> /// <returns></returns> public DataTable GetTopZtNews(int top, int ztId, bool isAudit, bool isIndex) { WhereClipBuilder wcb = new WhereClipBuilder(); if (ztId > 0) { wcb.And(cmsNewsTopicRel._.TopicId == ztId); } if (isAudit) { wcb.And(cmsNews._.IsAudit == 1); // 已审核的 } if (isIndex) { wcb.And(cmsNews._.IsIndex == 1); // 已推荐的 } FromSection fs = GetFromSection(null, null) .InnerJoin <cmsNewsCatalog>(cmsNewsCatalog._.NodeCode == cmsNews._.NodeCode) .InnerJoin <cmsNewsTopicRel>(cmsNews._.Id == cmsNewsTopicRel._.NewsId) .Select(cmsNews._.All, cmsNewsCatalog._.NodeName) .Where(wcb.ToWhereClip()) .OrderBy(cmsNews._.EditTime.Desc); if (top > 0) { fs = fs.Top(top); } return(fs.ToDataTable()); }
/// <summary> /// 创建分页查询 /// </summary> /// <param name="fromSection"></param> /// <param name="startIndex"></param> /// <param name="endIndex"></param> /// <returns></returns> public override FromSection CreatePageFromSection(FromSection fromSection, int startIndex, int endIndex) { Check.Require(startIndex, "startIndex", Check.GreaterThanOrEqual <int>(1)); Check.Require(endIndex, "endIndex", Check.GreaterThanOrEqual <int>(1)); Check.Require(startIndex <= endIndex, "startIndex must be less than endIndex!"); Check.Require(fromSection, "fromSection", Check.NotNullOrEmpty); //Check.Require(fromSection.OrderByClip, "query.OrderByClip", Check.NotNullOrEmpty); //OrderByClip orderBy = fromSection.OrderByClip; fromSection.TableName = string.Concat("(", fromSection.SqlString, ") tmpi_table"); fromSection.Select(new Field("tmpi_table.*")); fromSection.AddSelect(new Field("rownum AS rn")); fromSection.OrderBy(OrderByClip.None); fromSection.DistinctString = string.Empty; fromSection.PrefixString = string.Empty; fromSection.GroupBy(GroupByClip.None); fromSection.Parameters = fromSection.Parameters; fromSection.Where(new WhereClip("rownum <=" + endIndex.ToString())); if (startIndex > 1) { fromSection.TableName = string.Concat("(", fromSection.SqlString, ")"); fromSection.Select(Field.All); fromSection.Where(new WhereClip(string.Concat("rn>=", startIndex.ToString()))); } return(fromSection); }
/// <summary> /// /// </summary> /// <param name="loginName"></param> /// <param name="trueName"></param> /// <param name="deptName"></param> /// <param name="roleId"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="recordCount"></param> /// <returns></returns> public List <cmsUser> GetUsersByFilter(string loginName, string trueName, string deptName, int roleId, int pageIndex, int pageSize, ref int recordCount) { UserRoleService urs = UserRoleService.GetInstance(); WhereClipBuilder wcb = new WhereClipBuilder(); if (!string.IsNullOrEmpty(loginName)) { wcb.And(cmsUser._.UName.Contain(loginName.Trim())); } if (!string.IsNullOrEmpty(trueName)) { wcb.And(cmsUser._.Name.Contain(trueName.Trim())); } if (!string.IsNullOrEmpty(deptName.Trim())) { wcb.And(cmsUser._.DeptName.Contain(deptName.Trim())); } if (roleId > 0) { FromSection fs = DBSession.CurrentSession.From <cmsUserRole>() .Select(cmsUserRole._.UserId) .Where(cmsUserRole._.RoleId == roleId); wcb.And(cmsUser._.Id.SubQueryIn(fs)); } return(GetList(wcb.ToWhereClip(), cmsUser._.UName.Asc, pageIndex, pageSize, ref recordCount)); }
/// <summary> /// Dos.ORM query state /// </summary> /// <param name="query"></param> /// <param name="currentPageNumber"></param> /// <param name="pageSize"></param> /// <param name="additionalQueryFunc"></param> public DosQueryState(FromSection <T> query, int currentPageNumber, int pageSize, Func <FromSection <T>, FromSection <T> > additionalQueryFunc = null) { if (query == null) { throw new ArgumentNullException(nameof(query)); } if (currentPageNumber < 0) { throw new ArgumentOutOfRangeException(nameof(currentPageNumber), $"{nameof(currentPageNumber)} can not be less than zero"); } if (pageSize < 0) { throw new ArgumentOutOfRangeException(nameof(pageSize), $"{nameof(pageSize)} can not be less than zero"); } // InternalDosOrmQuery = query.Page(pageSize, currentPageNumber); //_mLazyDosQueryMembers = new Lazy<IEnumerable<T>>(()=> (additionalQueryFunc?.Invoke(InternalDosOrmQuery) ?? InternalDosOrmQuery).ToList()); var currentQuery = additionalQueryFunc == null ? query : additionalQueryFunc(query); _mLazyDosQueryMembers = new Lazy <IEnumerable <T> >(() => (additionalQueryFunc?.Invoke(query) ?? query).Page(pageSize, currentPageNumber).ToList()); }
private void GetMyJc() { var topid1 = Common.CryptHelper.DESEncrypt.Decrypt(Dos.Common.CookieHelper.Get("curYHJCAes1"), WebConfigurationManager.AppSettings["PassWordKey"]); FromSection <HdPicHit> fromsection = DbSession.Default.From <HdPicHit>() .Where(s => s.wxopenid.Equals(topid1) && s.extend1.Equals("115")).OrderBy(HdPicHit._.addtime.Desc); var list = fromsection.Page(30, 1).ToList(); List <object> listDesc = new List <object>(); if (list.Count > 0) { foreach (var item in list) { listDesc.Add(new { id = item.Id, sjd = item.extend2, jc = item.name, sy = item.status }); } string jsonstrlist = JsonHelper.GetJsonString(new jsonResult { code = "succ", result = listDesc, count = list.Count }); _ct.Response.Write(jsonstrlist); } else { string jsonstrlist = JsonHelper.GetJsonString(new jsonResult { code = "error", result = "", count = 0 }); _ct.Response.Write(jsonstrlist); } }
private void GetBannerList() { FromSection <Forms> fromsection = DbSession.Default.From <Forms>() .Where(s => s.Type.Equals(22)) .OrderBy(s => s.AddTime); var list = fromsection.SetCacheTimeOut(5000).ToList(); List <object> listDesc = new List <object>(); if (list.Count > 0) { foreach (var item in list) { listDesc.Add(new { id = item.Id, title = item.Title, url = item.Source, img = globalVariables.NewsImgServer + item.Income }); } string jsonstrlist = JsonHelper.GetJsonString(new jsonResult { code = "succ", result = listDesc, count = list.Count }); _ct.Response.Write(jsonstrlist); } else { string jsonstrlist = JsonHelper.GetJsonString(new jsonResult { code = "error", result = "", count = 0 }); _ct.Response.Write(jsonstrlist); } }
private void GetXMList() { FromSection <Activity> fromsection = DbSession.Default.From <Activity>() .Where(s => s.Status.Equals(0) && s.Type.Equals(10)); var list = fromsection.Page(10, 1).ToList(); List <object> listDesc = new List <object>(); if (list.Count > 0) { foreach (var item in list) { listDesc.Add(new { id = item.ID, sjd = item.Title, gj = item.Entitle, img = item.Conver, sb = item.Extend }); } string jsonstrlist = JsonHelper.GetJsonString(new jsonResult { code = "succ", result = listDesc, count = list.Count }); _ct.Response.Write(jsonstrlist); } else { string jsonstrlist = JsonHelper.GetJsonString(new jsonResult { code = "error", result = "", count = 0 }); _ct.Response.Write(jsonstrlist); } }
/// <summary> /// 根据栏目编号获取推荐到首页的列表 /// </summary> /// <param name="nodecode"></param> /// <param name="top"></param> /// <param name="isLike"></param> /// <returns></returns> public DataTable GetIndexList(long langId, string nodecode, int top, bool isLike) { if (top <= 0 || top > 10) { top = 10; } WhereClipBuilder wcb = new WhereClipBuilder(); wcb.And(cmsNews._.LangId == langId); if (!string.IsNullOrEmpty(nodecode)) { if (!isLike) { wcb.And(cmsNews._.NodeCode == nodecode); } else { wcb.And(cmsNews._.NodeCode.BeginWith(nodecode)); } } wcb.And(cmsNews._.IsAudit == 1); // 已审核的 wcb.And(cmsNews._.IsIndex == 1); // 推荐到首页的 FromSection fs = GetFromSection(wcb.ToWhereClip(), null) .InnerJoin <cmsNewsCatalog>(cmsNewsCatalog._.NodeCode == cmsNews._.NodeCode) .Select(cmsNews._.All, cmsNewsCatalog._.NodeName) .Top(top) .OrderBy(cmsNews._.IsTop.Desc && cmsNews._.EditTime.Desc); return(fs.ToDataTable()); }
/// <summary> /// 创建分页查询 /// </summary> /// <param name="fromSection"></param> /// <param name="startIndex"></param> /// <param name="endIndex"></param> /// <returns></returns> public override FromSection CreatePageFromSection(FromSection fromSection, int startIndex, int endIndex) { Check.Require(startIndex, "startIndex", Check.GreaterThanOrEqual<int>(1)); Check.Require(endIndex, "endIndex", Check.GreaterThanOrEqual<int>(1)); Check.Require(startIndex <= endIndex, "startIndex must be less than endIndex!"); Check.Require(fromSection, "fromSection", Check.NotNullOrEmpty); //Check.Require(fromSection.OrderByClip, "query.OrderByClip", Check.NotNullOrEmpty); //OrderByClip orderBy = fromSection.OrderByClip; fromSection.TableName = string.Concat("(", fromSection.SqlString, ") tmpi_table"); fromSection.Select(new Field("tmpi_table.*")); fromSection.AddSelect(new Field("rownum AS rn")); fromSection.OrderBy(OrderByClip.None); fromSection.DistinctString = string.Empty; fromSection.PrefixString = string.Empty; fromSection.GroupBy(GroupByClip.None); fromSection.Parameters = fromSection.Parameters; fromSection.Where(new WhereClip("rownum <=" + endIndex.ToString())); if (startIndex > 1) { fromSection.TableName = string.Concat("(", fromSection.SqlString, ")"); fromSection.Select(Field.All); fromSection.Where(new WhereClip(string.Concat("rn>=", startIndex.ToString()))); } return fromSection; }
/// <summary> /// /// </summary> /// <param name="top"></param> /// <param name="nodecode"></param> /// <param name="isLike"></param> /// <param name="isAudit"></param> /// <param name="isIndex"></param> /// <returns></returns> public DataTable GetTopNews(int top, string nodecode, bool isLike, bool isAudit, bool isIndex) { WhereClipBuilder wcb = new WhereClipBuilder(); if (!string.IsNullOrEmpty(nodecode)) { if (!isLike) { wcb.And(cmsNews._.NodeCode == nodecode); } else { wcb.And(cmsNews._.NodeCode.BeginWith(nodecode)); } } if (isAudit) { wcb.And(cmsNews._.IsAudit == 1); // 已审核的 } if (isIndex) { wcb.And(cmsNews._.IsIndex == 1); // 已推荐的 } FromSection fs = GetFromSection(wcb.ToWhereClip(), null) .InnerJoin <cmsNewsCatalog>(cmsNewsCatalog._.NodeCode == cmsNews._.NodeCode) .Select(cmsNews._.All, cmsNewsCatalog._.NodeName) .OrderBy(cmsNews._.IsTop.Desc && cmsNews._.EditTime.Desc); if (top > 0) { fs = fs.Top(top); } return(fs.ToDataTable()); }
/// <summary> /// /// </summary> /// <param name="nodecode"></param> /// <param name="isLike"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="recordCount"></param> /// <returns></returns> public DataTable GetList(long langId, string nodecode, bool isLike, int pageIndex, int pageSize, ref int recordCount) { WhereClipBuilder wcb = new WhereClipBuilder(); wcb.And(cmsNews._.LangId == langId); if (!string.IsNullOrEmpty(nodecode)) { if (!isLike) { wcb.And(cmsNews._.NodeCode == nodecode); } else { wcb.And(cmsNews._.NodeCode.BeginWith(nodecode)); } } wcb.And(cmsNews._.IsAudit == 1); // 已审核的 FromSection fs = GetFromSection(wcb.ToWhereClip(), null) .InnerJoin <cmsNewsCatalog>(cmsNewsCatalog._.NodeCode == cmsNews._.NodeCode) .Select(cmsNews._.All, cmsNewsCatalog._.NodeName) .OrderBy(cmsNews._.IsTop.Desc && cmsNews._.EditTime.Desc); recordCount = fs.Count(); return(fs.Page(pageSize, pageIndex).ToDataTable()); }
/// <summary> /// Dos.ORM page /// </summary> /// <param name="query"></param> /// <param name="currentPageNumber"></param> /// <param name="pageSize"></param> /// <param name="totalMemberCount"></param> /// <param name="additionalQueryFunc"></param> public DosPage(FromSection <T> query, int currentPageNumber, int pageSize, int totalMemberCount, Func <FromSection <T>, FromSection <T> > additionalQueryFunc = null) : base() { var skip = (currentPageNumber - 1) * pageSize; var state = new DosQueryState <T>(query, currentPageNumber, pageSize, additionalQueryFunc); InitializeMetaInfo()(currentPageNumber)(pageSize)(totalMemberCount)(skip)(); base._initializeAction = InitializeMemberList()(state)(CurrentPageSize)(skip); }
//private void SetZan(HttpContext context) //{ // try // { // int tmphid = 0; // int.TryParse(context.Request.Form["tmpid"], out tmphid); // string topid = context.Request.Form["tmpopenid"]; // var tmpopenid = Common.CryptHelper.DESEncrypt.Decrypt(topid, WebConfigurationManager.AppSettings["PassWordKey"]); // int nums1 = 0; // int ist = 0; // DateTime t1 = DateTime.Now.Date; // DateTime tm2 = DateTime.Now.AddDays(1).Date; // DateTime t2 = Convert.ToDateTime(WebConfigurationManager.AppSettings["endtime12"]); // DateTime t3 = t2.AddDays(1); // var userInfo = UserApi.Info(AccessTokenContainer.TryGetToken(WebConfigurationManager.AppSettings["wxappid1"], WebConfigurationManager.AppSettings["wxsecret1"]), tmpopenid); // if (string.IsNullOrEmpty(_ct.Request.UserAgent) || (!_ct.Request.UserAgent.Contains("MicroMessenger") && !_ct.Request.UserAgent.Contains("Windows Phone"))) // { // context.Response.Write("{\"ismsgs\":\"0\",\"ist\":\"" + 2 + "\"}"); // } // else // { // if (DateTime.Compare(t1, t2) < 0) // { // if (tmphid > 0) // { // int idnum = 0; // using (WXDBEntities db = new WXDBEntities()) // { // //var ctcount = db.HdPicHit.Where(s => s.wxopenid.Equals(tmpopenid) && s.addtime > t1 && s.addtime < tm2).Count(); // //if (ctcount >= 3) // //{ // // context.Response.Write("{\"ismsgs\":\"0\",\"ist\":\"" + 2 + "\"}"); // //} // //else // //{ // //var tmpdel = db.HdPicHit.Where(s => s.wxopenid.Equals(tmpopenid) && s.hdpicid.Equals(tmphid) && s.addtime > t1 && s.addtime < tm2).FirstOrDefault(); // var tmpdel = db.HdPicHit.Where(s => s.wxopenid.Equals(tmpopenid) && s.extend1.Equals("108")).FirstOrDefault(); // if (tmpdel != null) // { // context.Response.Write("{\"ismsgs\":\"0\",\"ist\":\"" + 5 + "\"}"); // } // else // { // HdPicHit model = new HdPicHit(); // model.addtime = DateTime.Now; // model.updatetime = DateTime.Now; // model.extend1 = "108"; // model.extend2 = ""; // model.orders = 0; // model.status = 0; // model.wxopenid = tmpopenid; // model.name = ""; // model.hdpicid = tmphid; // db.HdPicHit.AddObject(model); // db.SaveChanges(); // HdPic tmodel = db.HdPic.Where(s => s.Id == tmphid).FirstOrDefault(); // if (tmodel != null) // { // nums1 = tmodel.Orders + 1; // SqlParameter[] para = new SqlParameter[] { // new SqlParameter("@Id",tmodel.Id), // new SqlParameter("@Orders",tmodel.Orders+1), // new SqlParameter("@UpdateTime",DateTime.Now) // }; // var ct = db.ExecuteStoreCommand(" update HdPic set Orders=@Orders, UpdateTime=@UpdateTime where Id=@Id", para); // } // else // { // nums1 = 0; // } // ist = 1; // context.Response.Write("{\"ismsgs\":\"" + nums1 + "\",\"ist\":\"" + 1 + "\"}"); // //} // } // } // } // else // { // context.Response.Write("{\"ismsgs\":\"0\",\"ist\":\"" + 0 + "\"}"); // } // } // else // { // context.Response.Write("{\"ismsgs\":\"0\",\"ist\":\"" + 3 + "\"}"); // } // } // } // catch (Exception) // { // context.Response.Write("{\"ismsgs\":\"0\",\"ist\":\"" + 4 + "\"}"); // } //} protected void GetImgList() { int page = 0; int pagesize = 8; int.TryParse(_ct.Request.Form["tmppage"], out page); if (page < 1) { page = 0; } int.TryParse(_ct.Request.Form["pagesize"], out pagesize); using (WXDBEntities db = new WXDBEntities()) { int skipsize = page * pagesize; int tmpage = page + 1; //var list = new List<HdPic>(); //////.OrderByDescending(s => s.Orders). //list = db.HdPic.Where(s => s.Status == 0 && s.Extend2.Equals("108")).OrderByDescending(s => s.Orders).ThenBy(s => s.UpdateTime).Skip(skipsize).Take(pagesize).ToList(); FromSection <Dos.Model.HdPic> fromsection = DbSession.Default.From <Dos.Model.HdPic>() .Where(s => s.Extend2.Equals("108")) .OrderBy(Dos.Model.HdPic._.Orders.Desc, Dos.Model.HdPic._.UpdateTime.Asc); var list = fromsection.Page(pagesize, tmpage).ToList(); //DbSession.Default.FromSql("select row from (select row_number() over (order by orders desc,updatetime asc) row,extend1 from hdpic where Extend2='108') newtable where extend1=@extend1").AddInParameter("@extend1", DbType.String, "321").ToScalar(); //SqlSection str = new SqlSection(); //str.(DbSession) //IQueryable<HdPic> list = db.HdPic.OrderByDescending(s => s.Orders).ThenBy(s => s.UpdateTime).Where(s => s.Extend2.Equals("108")); //var dblist = list.ToPagedList(tmpage, pagesize); List <object> listDesc = new List <object>(); if (list.Count > 0) { foreach (var item in list) { listDesc.Add(new { id = item.Id, name = item.Name, nums = item.Orders, tcont = item.PicUrl }); } string jsonstrlist = JsonHelper.GetJsonString(new jsonResult { code = "succ", result = listDesc, count = list.Count }); _ct.Response.Write(jsonstrlist); } else { string jsonstrlist = JsonHelper.GetJsonString(new jsonResult { code = "error", result = "", count = 0 }); _ct.Response.Write(jsonstrlist); } } }
/// <summary> /// /// </summary> /// <param name="type"></param> /// <returns></returns> public int Count(int type) { FromSection fs = entCMS.Services.DBSession.CurrentSession.From <cmsNews>() .InnerJoin <cmsNewsCatalog>(cmsNews._.NodeCode == cmsNewsCatalog._.NodeCode) .Select(cmsNewsCatalog._.NodeName, cmsNews._.All) .Where(cmsNewsCatalog._.NodeType == type) .OrderBy(cmsNews._.EditTime.Desc); return(fs.Count()); }
/// <summary> /// /// </summary> /// <param name="langId"></param> /// <param name="keyword">搜索关键字</param> /// <param name="type">搜索类别:0-按标题搜,1-按内容搜,2-按标题或内容搜</param> /// <param name="nodecode">如果为空,则全局搜;不为空,则在本类下搜</param> /// <param name="isLike">是否搜索子类</param> /// <param name="pageIndex">页码</param> /// <param name="pageSize"></param> /// <param name="recordCount"></param> /// <returns></returns> public DataTable Search(int langId, string keyword, int type, string nodecode, bool isLike, int pageIndex, int pageSize, ref int recordCount) { WhereClipBuilder wcb = new WhereClipBuilder(); if (!string.IsNullOrEmpty(nodecode) && nodecode != "0000") { if (!isLike) { wcb.And(cmsNews._.NodeCode == nodecode); } else { wcb.And(cmsNews._.NodeCode.BeginWith(nodecode)); } } wcb.And(cmsNews._.IsAudit == 1); // 已审核的 wcb.And(cmsNews._.IsIndex == 1); // 已推荐的 if (!string.IsNullOrEmpty(keyword)) { switch (type) { case -1: break; case 0: wcb.And(cmsNews._.Title.Contain(keyword)); break; case 1: wcb.And(cmsNews._.Content.Contain(keyword)); break; case 2: wcb.And(cmsNews._.Title.Contain(keyword) || cmsNews._.Content.Contain(keyword)); break; } } if (langId > 0) { wcb.And(cmsNewsCatalog._.LangId == langId); } FromSection fs = GetFromSection(null, null) .InnerJoin <cmsNewsCatalog>(cmsNewsCatalog._.NodeCode == cmsNews._.NodeCode) .Select(cmsNews._.All, cmsNewsCatalog._.NodeName) .Where(wcb.ToWhereClip()) .OrderBy(cmsNews._.IsTop.Desc && cmsNews._.EditTime.Desc); recordCount = fs.Count(); return(fs .Page(pageSize, pageIndex) .ToDataTable()); }
/// <summary> /// 获取图片列表 /// </summary> /// <param name="context"></param> protected void GetImgList() { int page = 0; int pagesize = 8; int.TryParse(_ct.Request.Form["tmppage"], out page); if (page < 1) { page = 0; } int.TryParse(_ct.Request.Form["pagesize"], out pagesize); using (WXDBEntities db = new WXDBEntities()) { int skipsize = page * pagesize; int tmpage = page + 1; //var list = db.HdPic.Where(s => s.Status == 0 && s.Extend2.Equals("107")).OrderBy(s => s.AddTime).Skip(skipsize).Take(pagesize).ToList(); FromSection <Dos.Model.HdPic> fromsection = DbSession.Default.From <Dos.Model.HdPic>() .Where(s => s.Extend2.Equals("107")); var list = fromsection.Page(pagesize, tmpage).ToList(); //IQueryable<HdPic> list = db.HdPic.Where(s => s.Status == 0 && s.Extend2.Equals("107")).OrderBy(s => s.AddTime); //var dblist = list.ToPagedList(tmpage, pagesize); //.OrderByDescending(s => s.Orders). //list = .Skip(skipsize).Take(pagesize).ToList(); //int count = db.HdPic.Where(s => s.Status == 0 && s.Extend2.Equals("107")).Count(); List <object> listDesc = new List <object>(); if (list.Count > 0) { foreach (var item in list) { listDesc.Add(new { id = item.Id, name = item.Name, nums = item.Orders, imgurl = item.PicUrl, ntnum = item.Extend4 }); } string jsonstrlist = JsonHelper.GetJsonString(new jsonResult { code = "succ", result = listDesc, count = list.Count }); _ct.Response.Write(jsonstrlist); } else { string jsonstrlist = JsonHelper.GetJsonString(new jsonResult { code = "error", result = "", count = 0 }); _ct.Response.Write(jsonstrlist); } } }
/// <summary> /// 创建分页查询 /// </summary> /// <param name="fromSection"></param> /// <param name="startIndex"></param> /// <param name="endIndex"></param> /// <returns></returns> public override FromSection CreatePageFromSection(FromSection fromSection, int startIndex, int endIndex) { Check.Require(startIndex, "startIndex", Check.GreaterThanOrEqual <int>(1)); Check.Require(endIndex, "endIndex", Check.GreaterThanOrEqual <int>(1)); Check.Require(startIndex <= endIndex, "startIndex must be less than endIndex!"); Check.Require(fromSection, "fromSection", Check.NotNullOrEmpty); //Check.Require(fromSection.OrderByClip, "query.OrderByClip", Check.NotNullOrEmpty); fromSection.LimitString = string.Concat(" limit ", (startIndex - 1).ToString(), ",", (endIndex - startIndex + 1).ToString()); return(fromSection); }
public DataTable GetDataTableWithLang() { FromSection <cmsCompany> fs = GetFromSection(null, null); DataTable dt = fs .InnerJoin <cmsLanguage>(cmsLanguage._.Id == cmsCompany._.LangId) .Select(cmsCompany._.All, cmsLanguage._.Name.As("LangName")) .ToDataTable(); return(dt); }
/// <summary> /// 得到实体类 /// </summary> /// <param name="ID"></param> /// <returns></returns> public T GetModel(params object[] id) { if (id == null || id.Length == 0) { return(null); } Field[] pkfields = Hxj.Data.Common.EntityCache.GetPrimaryKeyFields <T>(); if (id == null) { throw new ArgumentNullException("请指定主键值!"); } if (pkfields == null || pkfields.Length == 0) { throw new Exception("数据表[" + Hxj.Data.Common.EntityCache.GetTableName <T>() + "]不存在任何主键!"); } T t = null; if (pkfields.Length == 1) { if (_trans != null) { t = _trans.From <T>().Where(Hxj.Data.Common.EntityCache.GetPrimaryKeyFields <T>()[0] == id).ToFirst(); } t = DBSession.CurrentSession.From <T>().Where(Hxj.Data.Common.EntityCache.GetPrimaryKeyFields <T>()[0] == id[0]).ToFirst(); } else { if (id.Length != pkfields.Length) { throw new Exception("指定的主键值个数与数据表的主键个数不符!"); } FromSection <T> section = null; if (_trans != null) { section = _trans.From <T>(); } else { section = DBSession.CurrentSession.From <T>(); } WhereClipBuilder wcb = new WhereClipBuilder(); for (int i = 0; i < pkfields.Length; i++) { wcb.And(pkfields[i] == id[i]); } t = section.Where(wcb.ToWhereClip()).ToFirst(); } GetRelations(ref t); return(t); }
/// <summary> /// /// </summary> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="recordCount"></param> /// <returns></returns> public DataTable GetDataTable(int pageIndex, int pageSize, ref int recordCount) { FromSection fs = GetFromSection(null, null) .LeftJoin <cmsLinkGroup>(cmsLinkGroup._.Id == cmsLink._.GroupId) .Select(cmsLink._.All, cmsLinkGroup._.Name.As("TypeName")) .OrderBy(cmsLink._.GroupId.Asc && cmsLink._.OrderNo.Asc && cmsLink._.Id.Desc); recordCount = fs.Count(); return(fs .Page(pageSize, pageIndex) .ToDataTable()); }
/// <summary> /// 得到案例列表信息 /// </summary> private void GetALList() { int tyid = 0; int.TryParse(_ct.Request.Form["typid"], out tyid); int page = 0; int pagesize = 8; int.TryParse(_ct.Request.Form["tmppage"], out page); if (page < 1) { page = 0; } int.TryParse(_ct.Request.Form["pagesize"], out pagesize); int skipsize = page * pagesize; int tmpage = page + 1; FromSection <Forms> fromsection = DbSession.Default.From <Forms>() .Where(s => !s.Status.Equals(2) && s.Type.Equals(tyid)) .OrderBy(s => s.Orders).OrderByDescending(s => s.AddTime); var list = fromsection.Page(pagesize, tmpage).ToList(); List <object> listDesc = new List <object>(); if (list.Count > 0) { foreach (var item in list) { listDesc.Add(new { id = item.Id, img = globalVariables.NewsImgServer + item.Income, title = item.Title, desc = item.Remark, url = item.Source }); } string jsonstrlist = JsonHelper.GetJsonString(new jsonResult { code = "succ", result = listDesc, count = list.Count }); _ct.Response.Write(jsonstrlist); } else { string jsonstrlist = JsonHelper.GetJsonString(new jsonResult { code = "error", result = "", count = 0 }); _ct.Response.Write(jsonstrlist); } }
/// <summary> /// 读取列表 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="query"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="isOrderBy"></param> /// <returns></returns> public static async Task <Page <T> > ToPageAsync <T>(this FromSection <T> query, int pageIndex, int pageSize, bool isOrderBy = false) where T : Dos.ORM.Entity { var page = new Page <T>(); var totalItems = query.Count(); var totalPages = totalItems != 0 ? (totalItems % pageSize) == 0 ? (totalItems / pageSize) : (totalItems / pageSize) + 1 : 0; page.CurrentPage = pageIndex; page.ItemsPerPage = pageSize; page.TotalItems = totalItems; page.TotalPages = totalPages; page.Items = totalItems == 0 ? null : query.Page(pageSize, pageIndex).ToList(); return(page); }
/// <summary> /// 创建分页查询 /// </summary> /// <param name="fromSection"></param> /// <param name="startIndex"></param> /// <param name="endIndex"></param> /// <returns></returns> public override FromSection CreatePageFromSection(FromSection fromSection, int startIndex, int endIndex) { Check.Require(startIndex, "startIndex", Check.GreaterThanOrEqual<int>(1)); Check.Require(endIndex, "endIndex", Check.GreaterThanOrEqual<int>(1)); Check.Require(startIndex <= endIndex, "startIndex must be less than endIndex!"); Check.Require(fromSection, "fromSection", Check.NotNullOrEmpty); if (startIndex == 1) { return base.CreatePageFromSection(fromSection, startIndex, endIndex); } if (OrderByClip.IsNullOrEmpty(fromSection.OrderByClip)) { foreach (Field f in fromSection.Fields) { if (!f.PropertyName.Equals("*")) { fromSection.OrderBy(f.Asc); break; } } } Check.Require(!OrderByClip.IsNullOrEmpty(fromSection.OrderByClip), "query.OrderByClip could not be null or empty!"); if (fromSection.Fields.Count == 0) { fromSection.Select(Field.All); } fromSection.AddSelect(new Field(string.Concat("row_number() over(", fromSection.OrderByString, ") AS tmp_rowid"))); //OrderByClip tempOrderBy = fromSection.OrderByClip; fromSection.OrderBy(OrderByClip.None); fromSection.TableName = string.Concat("(", fromSection.SqlString, ") AS tmp_table"); fromSection.Parameters = fromSection.Parameters; fromSection.DistinctString = string.Empty; fromSection.PrefixString = string.Empty; fromSection.GroupBy(GroupByClip.None); fromSection.Select(Field.All); //fromSection.OrderBy(tempOrderBy); fromSection.Where(new WhereClip(string.Concat("tmp_rowid BETWEEN ", startIndex.ToString(), " AND ", endIndex.ToString()))); return fromSection; }
/// <summary> /// 创建分页查询 /// </summary> /// <param name="fromSection"></param> /// <param name="startIndex"></param> /// <param name="endIndex"></param> /// <returns></returns> public override FromSection CreatePageFromSection(FromSection fromSection, int startIndex, int endIndex) { Check.Require(startIndex, "startIndex", Check.GreaterThanOrEqual <int>(1)); Check.Require(endIndex, "endIndex", Check.GreaterThanOrEqual <int>(1)); Check.Require(startIndex <= endIndex, "startIndex must be less than endIndex!"); Check.Require(fromSection, "fromSection", Check.NotNullOrEmpty); if (startIndex == 1) { return(base.CreatePageFromSection(fromSection, startIndex, endIndex)); } if (OrderByClip.IsNullOrEmpty(fromSection.OrderByClip)) { foreach (Field f in fromSection.Fields) { if (!f.PropertyName.Equals("*")) { fromSection.OrderBy(f.Asc); break; } } } Check.Require(!OrderByClip.IsNullOrEmpty(fromSection.OrderByClip), "query.OrderByClip could not be null or empty!"); if (fromSection.Fields.Count == 0) { fromSection.Select(Field.All); } fromSection.AddSelect(new Field(string.Concat("row_number() over(", fromSection.OrderByString, ") AS tmp_rowid"))); //OrderByClip tempOrderBy = fromSection.OrderByClip; fromSection.OrderBy(OrderByClip.None); fromSection.TableName = string.Concat("(", fromSection.SqlString, ") AS tmp_table"); fromSection.Parameters = fromSection.Parameters; fromSection.DistinctString = string.Empty; fromSection.PrefixString = string.Empty; fromSection.GroupBy(GroupByClip.None); fromSection.Select(Field.All); //fromSection.OrderBy(tempOrderBy); fromSection.Where(new WhereClip(string.Concat("tmp_rowid BETWEEN ", startIndex.ToString(), " AND ", endIndex.ToString()))); return(fromSection); }
private void GetYHlist() { int page = 0; int pagesize = 15; int.TryParse(_ct.Request.Form["tmppage"], out page); if (page < 1) { page = 0; } int.TryParse(_ct.Request.Form["pagesize"], out pagesize); int skipsize = page * pagesize; int tmpage = page + 1; FromSection <Dos.Model.HdPic> fromsection = DbSession.Default.From <Dos.Model.HdPic>() .Where(s => s.Extend2.Equals("115")) .OrderBy(HdPic._.Orders.Desc, HdPic._.UpdateTime.Asc); var list = fromsection.Page(pagesize, tmpage).ToList(); List <object> listDesc = new List <object>(); if (list.Count > 0) { foreach (var item in list) { listDesc.Add(new { id = item.Id, img = item.PicUrl, nickname = item.Name, nums = item.Orders }); } string jsonstrlist = JsonHelper.GetJsonString(new jsonResult { code = "succ", result = listDesc, count = list.Count }); _ct.Response.Write(jsonstrlist); } else { string jsonstrlist = JsonHelper.GetJsonString(new jsonResult { code = "error", result = "", count = 0 }); _ct.Response.Write(jsonstrlist); } }
/// <summary> /// Get specific page from original DosQueryable source /// </summary> /// <typeparam name="T">element type of your DosQueryable source</typeparam> /// <param name="query">original DosQueryable source</param> /// <param name="pageNumber">page number</param> /// <param name="pageSize">page size</param> /// <param name="additionalQueryFunc"></param> /// <returns></returns> public static IPage <T> GetPage <T>(this FromSection <T> query, int pageNumber, int pageSize, Func <FromSection <T>, FromSection <T> > additionalQueryFunc = null) where T : Entity { if (query == null) { throw new ArgumentNullException(nameof(query), $"{nameof(query)} can not be null."); } if (pageNumber < 0) { throw new IndexOutOfRangeException($"{nameof(pageNumber)} can not be less than zero"); } if (pageSize < 0) { throw new IndexOutOfRangeException($"{nameof(pageSize)} can not be less than zero"); } return(new DosPage <T>(query, pageNumber, pageSize, DosHelper.Count(query), additionalQueryFunc: additionalQueryFunc)); }
/// <summary> /// Make Dos.ORM Query`1 source to DosePage collection. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="query"></param> /// <param name="pageSize"></param> /// <param name="limitedMemberCount"></param> /// <param name="additionalQueryFunc"></param> /// <returns></returns> public static PaginableDosQuery <T> CreatePageSet <T>(FromSection <T> query, int?pageSize = null, int?limitedMemberCount = null, Func <FromSection <T>, FromSection <T> > additionalQueryFunc = null) where T : Entity { if (query == null) { throw new ArgumentNullException(nameof(query)); } if (pageSize == null) { pageSize = PaginableSettingsManager.Settings.DefaultPageSize; } var size = pageSize.Value; var realMemberCount = GetRealMemberCountFunc()(limitedMemberCount)(DosHelper.Count(query)); var realPageCount = GetRealPageCountFunc()(realMemberCount)(size); return(limitedMemberCount.IsValid() && limitedMemberCount.HasValue ? new PaginableDosQuery <T>(query, size, realPageCount, realMemberCount, limitedMemberCount.Value, additionalQueryFunc) : new PaginableDosQuery <T>(query, size, realPageCount, realMemberCount, additionalQueryFunc)); }
/// <summary> /// 根据模块类别获取列表 /// </summary> /// <param name="type"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="recordCount"></param> /// <returns></returns> public DataTable GetListByType(long langId, string type, int pageIndex, int pageSize, ref int recordCount) { string[] types = type.Split('|'); WhereClipBuilder wcb = new WhereClipBuilder(); wcb.And(cmsNewsCatalog._.LangId == langId); if (types.Length > 0) { wcb.And(cmsNewsCatalog._.NodeType.SelectIn(types)); } FromSection fs = GetFromSection(wcb.ToWhereClip(), null) .InnerJoin <cmsNewsCatalog>(cmsNewsCatalog._.NodeCode == cmsNews._.NodeCode) .Select(cmsNews._.All, cmsNewsCatalog._.NodeName) .OrderBy(cmsNews._.IsTop.Desc && cmsNews._.EditTime.Desc); recordCount = fs.Count(); return(fs.Page(pageSize, pageIndex).ToDataTable()); }
/// <summary> /// 根据栏目类型获取推荐到首页的列表 /// </summary> /// <param name="nodetype"></param> /// <param name="top"></param> /// <returns></returns> public DataTable GetIndexList(long langId, int nodetype, int top) { if (top <= 0 || top > 10) { top = 10; } WhereClipBuilder wcb = new WhereClipBuilder(); wcb.And(cmsNews._.LangId == langId); wcb.And(cmsNewsCatalog._.NodeType == nodetype); wcb.And(cmsNews._.IsAudit == 1); // 已审核的 wcb.And(cmsNews._.IsIndex == 1); // 推荐到首页的 FromSection fs = GetFromSection(wcb.ToWhereClip(), null) .InnerJoin <cmsNewsCatalog>(cmsNewsCatalog._.NodeCode == cmsNews._.NodeCode) .Select(cmsNews._.All, cmsNewsCatalog._.NodeName) .Top(top) .OrderBy(cmsNews._.IsTop.Desc && cmsNews._.EditTime.Desc); return(fs.ToDataTable()); }
/// <summary> /// 提取某专题下的分页文章 /// </summary> /// <param name="ztId"></param> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <param name="recordCount"></param> /// <returns></returns> public DataTable GetZtNewsList(int ztId, int pageSize, int pageIndex, ref int recordCount) { WhereClipBuilder wcb = new WhereClipBuilder(); if (ztId > 0) { wcb.And(cmsNewsTopicRel._.TopicId == ztId); } wcb.And(cmsNews._.IsAudit == 1); // 已审核的 wcb.And(cmsNews._.IsIndex == 1); // 已推荐的 FromSection fs = GetFromSection(null, null) .InnerJoin <cmsNewsCatalog>(cmsNewsCatalog._.NodeCode == cmsNews._.NodeCode) .InnerJoin <cmsNewsTopicRel>(cmsNews._.Id == cmsNewsTopicRel._.NewsId) .Select(cmsNews._.All, cmsNewsCatalog._.NodeName) .Where(wcb.ToWhereClip()) .OrderBy(cmsNews._.EditTime.Desc); recordCount = fs.Count(); return(fs.Page(pageSize, pageIndex).ToDataTable()); }
/// <summary> /// 使用linq查询(分页) /// </summary> /// <typeparam name="TEntity"></typeparam> /// <typeparam name="OutEntity"></typeparam> /// <param name="linq"></param> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <param name="lambdaOrderBy"></param> /// <returns></returns> public PageResponse <OutEntity> getListByPaging <TEntity, OutEntity>(FromSection <TEntity> linq, int pageSize, int pageIndex, Expression <Func <TEntity, object> > lambdaOrderBy = null) where TEntity : Entity { if (pageIndex <= 0) { pageIndex = 1; } if (pageSize <= 0) { pageSize = 10; } PageResponse <OutEntity> result = new PageResponse <OutEntity>(); result.totalItems = linq.Count(); List <OutEntity> sqlList = new List <OutEntity>(); if (lambdaOrderBy != null) { sqlList = linq.OrderBy(lambdaOrderBy).Page(pageSize, pageIndex).ToList <OutEntity>(); } else { sqlList = linq.Page(pageSize, pageIndex).ToList <OutEntity>(); } if (sqlList == null || sqlList.Count == 0) { return(null); } result.items = sqlList; result.currentPage = pageIndex; result.itemsPerPage = pageSize; result.totalPages = result.totalItems / pageSize; if ((result.totalItems % pageSize) != 0) { result.totalPages++; } return(result); }
private void BindRepeater() { int page = AspNetPager1.CurrentPageIndex; if (!this.IsPostBack) { if (Request["page"] + "" != "") { page = int.Parse(Request["page"] + ""); } } FromSection <Dos.Model.Manager_Groups> fromsection = DbSession.Default.From <Dos.Model.Manager_Groups>() .Where(s => s.Status.Equals(0)) .OrderBy(s => s.AddTime).OrderByDescending(s => s.Id); //List<object> listDesc = new List<object>(); //var carlist = DbSession.Default.fr.Manager_Groups.Where(s => s.Status.Equals(0)).OrderBy(o => o.AddTime).ThenByDescending(o => o.Id); if (!string.IsNullOrEmpty(txtKeywords.Text.Trim())) { fromsection = fromsection.Where(s => s.Name.Contains(txtKeywords.Text)); } //carlist.ToPagedList(page, AspNetPager1.PageSize); AspNetPager1.RecordCount = fromsection.Count(); ltlCount.Text = "<b>" + fromsection.Count() + "</b>"; var dblist = fromsection.Page(AspNetPager1.PageSize, page).ToList(); if (!this.IsPostBack) { if (Request["page"] + "" != "") { int temp = int.Parse(Request["page"] + ""); AspNetPager1.CurrentPageIndex = temp; } } WebUtil.CtrlToList <Dos.Model.Manager_Groups>(rptLoop, dblist); }
/// <summary> /// 创建分页查询 /// </summary> /// <param name="fromSection"></param> /// <param name="startIndex"></param> /// <param name="endIndex"></param> /// <returns></returns> public override FromSection CreatePageFromSection(FromSection fromSection, int startIndex, int endIndex) { Check.Require(startIndex, "startIndex", Check.GreaterThanOrEqual<int>(1)); Check.Require(endIndex, "endIndex", Check.GreaterThanOrEqual<int>(1)); Check.Require(startIndex <= endIndex, "startIndex must be less than endIndex!"); Check.Require(fromSection, "fromSection", Check.NotNullOrEmpty); //Check.Require(fromSection.OrderByClip, "query.OrderByClip", Check.NotNullOrEmpty); fromSection.LimitString = string.Concat(" limit ", (startIndex - 1).ToString(), ",", (endIndex - startIndex + 1).ToString()); return fromSection; }
/// <summary> /// EXISTS /// </summary> /// <param name="fromSection"></param> /// <returns></returns> public static WhereClip Exists(FromSection fromSection) { return new WhereClip(string.Concat(" EXISTS (", fromSection.SqlString, ") "), fromSection.Parameters.ToArray()); }
/// <summary> /// 创建分页查询 /// </summary> /// <param name="fromSection"></param> /// <param name="startIndex"></param> /// <param name="endIndex"></param> /// <returns></returns> public virtual FromSection CreatePageFromSection(FromSection fromSection, int startIndex, int endIndex) { Check.Require(startIndex, "startIndex", Check.GreaterThanOrEqual<int>(1)); Check.Require(endIndex, "endIndex", Check.GreaterThanOrEqual<int>(1)); Check.Require(startIndex <= endIndex, "startIndex must be less than endIndex!"); Check.Require(fromSection, "fromSection", Check.NotNullOrEmpty); int pageSize = endIndex - startIndex + 1; if (startIndex == 1) { fromSection.PrefixString = string.Concat(" TOP ", pageSize.ToString()); } else { if (OrderByClip.IsNullOrEmpty(fromSection.OrderByClip)) { foreach (Field f in fromSection.Fields) { if (!f.PropertyName.Equals("*") && f.PropertyName.IndexOf('(') == -1) { fromSection.OrderBy(f.Asc); break; } } } Check.Require(!OrderByClip.IsNullOrEmpty(fromSection.OrderByClip), "query.OrderByClip could not be null or empty!"); int count = fromSection.Count(fromSection); List<Parameter> list = fromSection.Parameters; if (endIndex > count) { int lastnumber = count - startIndex + 1; if (startIndex > count) lastnumber = count % pageSize; fromSection.PrefixString = string.Concat(" TOP ", lastnumber.ToString()); fromSection.OrderBy(fromSection.OrderByClip.ReverseOrderByClip); // fromSection.TableName = string.Concat(" (", fromSection.SqlString, ") AS temp_table "); fromSection.PrefixString = string.Empty; fromSection.DistinctString = string.Empty; fromSection.GroupBy(GroupByClip.None); fromSection.Select(Field.All); fromSection.OrderBy(fromSection.OrderByClip.ReverseOrderByClip); fromSection.Where(WhereClip.All); } else { if (startIndex < count / 2) { fromSection.PrefixString = string.Concat(" TOP ", endIndex.ToString()); fromSection.TableName = string.Concat(" (", fromSection.SqlString, ") AS tempIntable "); fromSection.PrefixString = string.Concat(" TOP ", pageSize.ToString()); fromSection.DistinctString = string.Empty; fromSection.GroupBy(GroupByClip.None); fromSection.Select(Field.All); fromSection.OrderBy(fromSection.OrderByClip.ReverseOrderByClip); fromSection.Where(WhereClip.All); // fromSection.TableName = string.Concat(" (", fromSection.SqlString, ") AS tempOuttable "); fromSection.PrefixString = string.Empty; fromSection.OrderBy(fromSection.OrderByClip.ReverseOrderByClip); } else { fromSection.PrefixString = string.Concat(" TOP ", (count - startIndex + 1).ToString()); fromSection.OrderBy(fromSection.OrderByClip.ReverseOrderByClip); fromSection.TableName = string.Concat(" (", fromSection.SqlString, ") AS tempIntable "); fromSection.PrefixString = string.Concat(" TOP ", pageSize.ToString()); fromSection.DistinctString = string.Empty; fromSection.GroupBy(GroupByClip.None); fromSection.Select(Field.All); fromSection.OrderBy(fromSection.OrderByClip.ReverseOrderByClip); fromSection.Where(WhereClip.All); } } fromSection.Parameters = list; } return fromSection; }