/// <summary> /// 设置翻页控件的属性,并且添加CustomInfo /// </summary> /// <param name="pager"></param> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> public static void SetMagicPager(MagicPager pager, int pageSize, int pageIndex) { pager.Visible = true; pager.AlwaysShow = true; pager.PageSize = pageSize; pager.CurrentPageIndex = pageIndex; pager.CustomInfoText = ""; pager.ShowMaxPageCountBox = false; pager.ShowPageSizeBox = false; //pager.CustomInfoText += string.Format("<span class='pager_text'>记录总数:</span><span style='font-weight:bold;' class='pager_text'>{0}</span>", pager.RecordCount); if (pager.RecordCount > 0) { pager.CustomInfoText += string.Format("<span style='font-weight:bold;' class='pager_text'>{1}</span><span class='pager_text'>/{0} </span>", pager.PageCount, pageIndex); } pager.Layout = LayoutType.Div; pager.PagingButtonType = PagingButtonType.Text; pager.PagingButtonSpacing = 2; pager.FirstPageText = "首页"; pager.PrevPageText = "上一页"; pager.NextPageText = "下一页"; pager.LastPageText = "尾页"; pager.TextBeforeInputBox = ""; pager.TextAfterInputBox = " 页 "; pager.ShowPageIndex = false; pager.CustomInfoTextAlign = HorizontalAlign.Right; pager.ShowInputBox = ShowInputBox.Always; pager.CustomInfoSectionWidth = Unit.Pixel(280); }
//MagicToolbar's MagicItem OnClick Event Handler, it's for both the top one and the bottom one. protected void MagicItemCommand(object sender, MagicItemEventArgs e) { try { Repeater rpt = null; MagicPager pager = null; bool isGroup = false;; if (e.CommandName == "DeleteUser") { // do delete rpt = this.rptSubscribeUser; pager = this.magicPagerUser; isGroup = false; } else if (e.CommandName == "DeleteGroup") { rpt = this.rptSubscribeGroup; pager = this.magicPagerGroup; isGroup = true; } if (rpt != null) { using (_session = new Session()) { foreach (RepeaterItem item in rpt.Items) { HtmlInputCheckBox chk = item.FindControl("checkbox") as HtmlInputCheckBox; if (chk != null && chk.Checked) { int subscriberId = Cast.Int(chk.Attributes["subscriberId"]); MsgSubscriber.Delete(_session, subscriberId); } } QueryAndBindData(rpt, pager, isGroup, 1, pager.PageSize, true); } } } catch (UnauthorizedException ex) { WebUtil.ShowMsg(this, ex.Message, "警告"); } catch (ApplicationException ex) { WebUtil.ShowMsg(this, ex.Message, "提示"); } catch (Exception ex) { logger.Info("删除MsgSubscriber", ex); WebUtil.ShowMsg(this, "发生未处理的异常,请刷新页面重新操作,或者联系系统管理员"); } }
protected virtual void BindPager(int currentPageIndex) { if (PagerIDArray != null && PagerIDArray.Length > 0) { MagicPager pager = this.FindControl(PagerIDArray[0]) as MagicPager; int pageSize = 0; int iPageCount = 0; if (pager != null) { pageSize = pager.PageSize; iPageCount = pager.MaxPageCount; } if (iPageCount < 0) { iPageCount = 20; } int maxdatacount = iPageCount * pageSize; int fromIndex = (currentPageIndex - 1) * pageSize; int toIndex = pageSize;//(currentPageIndex * pageSize); int datacount = DoQuery(fromIndex, pageSize, maxdatacount); maxdatacount = (maxdatacount > datacount) ? datacount : maxdatacount; foreach (string pagerId in PagerIDArray) { pager = this.FindControl(pagerId) as MagicPager; WebUtil.SetMagicPager(pager, pageSize, maxdatacount, currentPageIndex); } } else { DoQuery(-1, -1, -1); } }
/// <summary> /// /// </summary> /// <param name="pager"></param> /// <param name="pageSize"></param> /// <param name="recordCount"></param> /// <param name="currentIndex"></param> public static void SetMagicPager(MagicPager pager, int pageSize, int recordCount, int currentIndex) { pager.RecordCount = recordCount; SetMagicPager(pager, pageSize, currentIndex); }
/// <summary> /// Get query conditions from page , and query data from db, then bind the query result to Repeater /// </summary> private void QueryAndBindData(Repeater rpt, MagicPager pager, bool isGroup, int pageIndex, int pageSize, bool fetchRecordCount) { string tmplCode = txtTmplCode.Text.Trim(); DataTable dtMsgBuscriber = null; int recordCount = 0; string oql = ""; if (!isGroup) oql = @"select s.SubscriberId as SubscriberId, s.TmplCode as TmplCode, s.UserId as UserId, u.UserName as UserName, u.FullName as FullName, s.SubscribeTime as SubscribeTime from MsgSubscriber s inner join User u on s.UserId=u.UserId and s.IsGroup=0"; else oql = @" select s.SubscriberId as SubscriberId, s.TmplCode as TmplCode, s.UserId as UserId, s.GroupId as GroupId, g.Name as GroupName, g.Description as Description, s.SubscribeTime as SubscribeTime from MsgSubscriber s inner join UserGroup g on s.GroupId=g.GroupId and s.IsGroup=1"; using (Session session = new Session()) { ObjectQuery query = session.CreateObjectQuery(oql); query.Attach(typeof(MsgSubscriber)); if (isGroup) query.Attach(typeof(UserGroup)); else query.Attach(typeof(User)); query.And(Exp.Eq("s.TmplCode", tmplCode)); query.SetPage(pageIndex, pageSize); dtMsgBuscriber = query.DataSet().Tables[0]; if (fetchRecordCount) recordCount = query.Count(); } rpt.DataSource = dtMsgBuscriber; rpt.DataBind(); if (fetchRecordCount) { pager.RecordCount = recordCount; } WebUtil.SetMagicPager(pager, pageSize, pageIndex); }
/// <summary> /// Get query conditions from page , and query data from db, then bind the query result to Repeater /// </summary> private void QueryAndBindData(Repeater rpt, MagicPager pager, bool isGroup, int pageIndex, int pageSize, bool fetchRecordCount) { string tmplCode = txtTmplCode.Text.Trim(); DataTable dtMsgBuscriber = null; int recordCount = 0; string oql = ""; if (!isGroup) { oql = @"select s.SubscriberId as SubscriberId, s.TmplCode as TmplCode, s.UserId as UserId, u.UserName as UserName, u.FullName as FullName, s.SubscribeTime as SubscribeTime from MsgSubscriber s inner join User u on s.UserId=u.UserId and s.IsGroup=0"; } else { oql = @" select s.SubscriberId as SubscriberId, s.TmplCode as TmplCode, s.UserId as UserId, s.GroupId as GroupId, g.Name as GroupName, g.Description as Description, s.SubscribeTime as SubscribeTime from MsgSubscriber s inner join UserGroup g on s.GroupId=g.GroupId and s.IsGroup=1"; } using (Session session = new Session()) { ObjectQuery query = session.CreateObjectQuery(oql); query.Attach(typeof(MsgSubscriber)); if (isGroup) { query.Attach(typeof(UserGroup)); } else { query.Attach(typeof(User)); } query.And(Exp.Eq("s.TmplCode", tmplCode)); query.SetPage(pageIndex, pageSize); dtMsgBuscriber = query.DataSet().Tables[0]; if (fetchRecordCount) { recordCount = query.Count(); } } rpt.DataSource = dtMsgBuscriber; rpt.DataBind(); if (fetchRecordCount) { pager.RecordCount = recordCount; } WebUtil.SetMagicPager(pager, pageSize, pageIndex); }