asp.net微信开发(自定义会话管理)(2)

PagedDataSource pds = new PagedDataSource(); protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { BindGustBookList(); this.DataBind(); UsersInfo user = Session["Users"] as UsersInfo; if (user != null && user.RolsId == 1) { this.BtnDelete.Enabled = true; } else { this.BtnDelete.Enabled = false; } } } private void BindGustBookList() { WeixinKeFuService wkf = new WeixinKeFuService(); List<WeixinKeFuInfo> wkflists = wkf.GetAllWeixinKeFuInfoList(); //if (this.DDLState.SelectedValue.Equals("1")) //{ // lists = gbs.GetAllGustBookListByState(); //} //else if (this.DDLState.SelectedValue.Equals("2")) //{ // lists = gbs.GetAllGustBookListByState2(); //} //else //{ // lists = gbs.GetAllGustBookList(); //} pds.DataSource = wkflists; pds.AllowPaging = true; pds.PageSize = 20;//每页显示为20条 int CurrentPage; if (!String.IsNullOrWhiteSpace(this.txtPageIndex.Text.ToString().Trim())) { CurrentPage = Convert.ToInt32(this.txtPageIndex.Text.ToString().Trim()); } else if (Request.QueryString["Page"] != null) { CurrentPage = Convert.ToInt32(Request.QueryString["Page"]); } else { CurrentPage = 1; } pds.CurrentPageIndex = CurrentPage - 1;//当前页的索引就等于当前页码-1; if (!pds.IsFirstPage) { //Request.CurrentExecutionFilePath 为当前请求的虚拟路径 this.lnkTop.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage - 1); this.lnkFist.Enabled = this.lnkTop.Enabled = true; this.lnkNext.Enabled = this.lnkLast.Enabled = true; } else { this.lnkFist.Enabled = this.lnkTop.Enabled = false; this.lnkNext.Enabled = this.lnkLast.Enabled = true; this.lnkFist.Attributes.Add("style", "color:#ced9df;"); this.lnkTop.Attributes.Add("style", "color:#ced9df;"); this.lnkNext.Attributes.Remove("style"); this.lnkLast.Attributes.Remove("style"); } if (!pds.IsLastPage) { //Request.CurrentExecutionFilePath 为当前请求的虚拟路径 this.lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage + 1); this.lnkFist.Enabled = this.lnkTop.Enabled = true; this.lnkNext.Enabled = this.lnkLast.Enabled = true; } else { this.lnkNext.Enabled = this.lnkLast.Enabled = false; this.lnkFist.Enabled = this.lnkTop.Enabled = true; this.lnkNext.Attributes.Add("style", "color:#ced9df;"); this.lnkLast.Attributes.Add("style", "color:#ced9df;"); this.lnkFist.Attributes.Remove("style"); this.lnkTop.Attributes.Remove("style"); } this.lnkFist.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(1);//跳转至首页 this.lnkLast.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(pds.PageCount);//跳转至末页 this.RepeaterGustBookList.DataSource = pds; this.RepeaterGustBookList.DataBind(); this.lbCountData.Text = wkflists.Count.ToString(); this.lbPageIndex.Text = (pds.CurrentPageIndex + 1).ToString(); this.lbPageSize.Text = "每页" + pds.PageSize.ToString() + "条记录"; this.lbCountPage.Text = pds.PageCount.ToString(); this.txtPageIndex.Text = (pds.CurrentPageIndex + 1).ToString(); if (int.Parse(wkflists.Count.ToString()) <= int.Parse(pds.PageSize.ToString())) { this.lnkFist.Visible = this.lnkTop.Visible = this.lnkNext.Visible = this.lnkLast.Visible = this.txtPageIndex.Visible = this.LinkBtnToPage.Visible = false; } else { this.lnkFist.Visible = this.lnkTop.Visible = this.lnkNext.Visible = this.lnkLast.Visible = this.txtPageIndex.Visible = this.LinkBtnToPage.Visible = true; } } /// <summary> /// 删除选中 /// </summary> /// <param></param> /// <param></param> protected void BtnDelete_Click(object sender, EventArgs e) { Boolean bools = false; foreach (RepeaterItem di in this.RepeaterGustBookList.Items) { CheckBox checkIn = (CheckBox)di.FindControl("CheckIn"); if (checkIn.Checked) { bools = true; Label lbGustNo = di.FindControl("lbUId") as Label; WeixinKeFuService wkf = new WeixinKeFuService(); int num = wkf.DeleteWeixinKeFuInfo(int.Parse(lbGustNo.Text.ToString())); if (num > 0) { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('删除成功!');location='WeiXinSessionList.aspx'", true); } else { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('删除失败!');location='WeiXinSessionList.aspx'", true); } } } if (!bools) { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('未选中删除项!');location='WeiXinSessionList.aspx'", true); } } /// <summary> /// 全选全不选 /// </summary> /// <param></param> /// <param></param> protected void CheckAll_CheckedChanged(object sender, EventArgs e) { CheckBox checkAll = (CheckBox)sender; foreach (RepeaterItem d in this.RepeaterGustBookList.Items) { CheckBox checkIn = (CheckBox)d.FindControl("CheckIn"); checkIn.Checked = checkAll.Checked; } } protected void LinkBtnLook_Click(object sender, EventArgs e) { BindGustBookList(); } /// <summary> /// 绑定事件 /// </summary> /// <param></param> /// <param></param> protected void RepeaterGustBookList_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Header) { CheckBox checkAll = e.Item.FindControl("CheckAll") as CheckBox; checkAll.AutoPostBack = true; } if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { WeixinKeFuInfo wkf = e.Item.DataItem as WeixinKeFuInfo; Label lbUId = e.Item.FindControl("lbUId") as Label; lbUId.Text = wkf.UId.ToString(); WxMessageService wms = new WxMessageService(); WxMessageInfo wminfo = wms.GetTopLastFaSongDateByUId(lbUId.Text.ToString()); if(wminfo!=null&&!String.IsNullOrWhiteSpace(wminfo.FaSongDate.ToString())) { Label lblastDate = e.Item.FindControl("lblastDate") as Label; lblastDate.Text = wminfo.FaSongDate.ToString(); DateTime datesystemss = DateTime.Parse(System.DateTime.Now.ToString()); DateTime lastLoingDatess = DateTime.Parse(lblastDate.Text.ToString()); TimeSpan ts11 = new TimeSpan(datesystemss.Ticks); TimeSpan ts22 = new TimeSpan(lastLoingDatess.Ticks); TimeSpan ts33 = ts11.Subtract(ts22).Duration(); Label lbState = e.Item.FindControl("lbState") as Label; string chaoshifenzhong = ts33.TotalMinutes.ToString(); if (double.Parse(chaoshifenzhong) <=10) { lbState.Text = "会话中"; lbState.Attributes.Add("style","color:red;"); } else { lbState.Text = "已结束"; } Label lbChaoshi = e.Item.FindControl("lbChaoshi") as Label; DateTime datesystem = DateTime.Parse(System.DateTime.Now.ToString()); DateTime lastLoingDate = DateTime.Parse(lblastDate.Text.ToString()); TimeSpan ts1 = new TimeSpan(datesystem.Ticks); TimeSpan ts2 = new TimeSpan(lastLoingDate.Ticks); TimeSpan ts3 = ts1.Subtract(ts2).Duration(); lbChaoshi.Text = ts3.Days.ToString() + "天" + ts3.Hours.ToString() + "小时" + ts3.Minutes.ToString() + "分钟"; } //////根据用户的openId获取用户昵称 //WeiXinServer wxs = new WeiXinServer(); /////从缓存读取accesstoken //string Access_token = Cache["Access_token"] as string; //if (Access_token == null) //{ // //如果为空,重新获取 // Access_token = wxs.GetAccessToken(); // //设置缓存的数据7000秒后过期 // Cache.Insert("Access_token", Access_token, null, DateTime.Now.AddSeconds(7000), System.Web.Caching.Cache.NoSlidingExpiration); //} //string Access_tokento = Access_token.Substring(17, Access_token.Length - 37); //string jsonres = ""; //jsonres = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + Access_tokento + "&openid=" + wkf.UserOpenId; //HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(jsonres); //myRequest.Method = "GET"; //HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); //StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8); //string content = reader.ReadToEnd(); //reader.Close(); ////使用前需药引用Newtonsoft.json.dll文件 //JObject jsonObj = JObject.Parse(content); //Label lbNikeName = e.Item.FindControl("lbNikeName") as Label; //Label lbSex = e.Item.FindControl("lbSex") as Label; //lbNikeName.Text = jsonObj["nickname"].ToString(); //if (jsonObj["sex"].ToString().Equals("1")) //{ // lbSex.Text = "男"; //} //else //{ // lbSex.Text = "女"; //} } } /// <summary> /// 输入页码提交跳转 /// </summary> /// <param></param> /// <param></param> protected void LinkBtnToPage_Click(object sender, EventArgs e) { if (String.IsNullOrWhiteSpace(this.txtPageIndex.Text.ToString().Trim())) { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('页码不能为空!')", true); this.txtPageIndex.Focus(); return; } if (IsNum(this.txtPageIndex.Text.ToString().Trim())) { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('页码数只能输入数字!')", true); this.txtPageIndex.Focus(); this.txtPageIndex.Text = this.lbPageIndex.Text.ToString(); return; } if (int.Parse(this.txtPageIndex.Text.ToString().Trim()) > int.Parse(this.lbCountPage.Text.ToString().Trim())) { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('所输页数不能大于总页数!')", true); this.txtPageIndex.Focus(); this.txtPageIndex.Text = this.lbPageIndex.Text.ToString(); return; } BindGustBookList(); } /// <summary> /// 判断是否是数字 /// </summary> /// <param></param> /// <returns></returns> public static bool IsNum(string text) // { for (int i = 0; i < text.Length; i++) { if (!Char.IsNumber(text, i)) { return true; //输入的不是数字 } } return false; //否则是数字 }

此代码已包含,后台分页功能,仔细研究下,即可使用.
点击开启会话的页面:MessageWindow.aspx如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjwjjy.html