main_msg_list.aspx.cs
上传用户:woolgirl
上传日期:2020-04-18
资源大小:243k
文件大小:8k
源码类别:

SCSI/ASPI

开发平台:

Others

  1. using System;
  2. using System.Data;
  3. using System.Data.OleDb;//ACCESS
  4. using System.Configuration;
  5. using System.Collections;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.WebControls.WebParts;
  11. using System.Web.UI.HtmlControls;
  12. using Wuqi.Webdiyer;
  13. public partial class main_msg_list : System.Web.UI.Page
  14. {
  15.     
  16.     //conn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("aspnetpager.mdb"));
  17.     OleDbConnection conn = liuyinconn.connstr();
  18.     OleDbCommand cmd;
  19.     protected void Page_Load(object sender, EventArgs e)
  20.     {
  21.         if (!Page.IsPostBack)
  22.         {
  23.             string action = Request.QueryString["action"];
  24.             
  25.             if (action == "0")
  26.             {
  27.                 cmd = new OleDbCommand("select count(yl_id) from yl_message WHERE yl_sh=0", conn);
  28.             }
  29.             else
  30.             {
  31.                 cmd = new OleDbCommand("select count(yl_id) from yl_message WHERE yl_sh=1", conn);
  32.             }
  33.             try
  34.             {
  35.                 conn.Open();//打开数据库链接 ;
  36.             }
  37.             catch
  38.             {
  39.                 Response.Write("参数错误!");
  40.                 Response.End();
  41.             }
  42.             
  43.             
  44.             pager.RecordCount = (int)cmd.ExecuteScalar();
  45.             conn.Close();
  46.             BindData();
  47.    
  48.             //获取分页属性值
  49.              /*
  50.            psize.Items.FindByValue(pager.PageSize.ToString()).Selected = true;
  51.            //获取导航按钮属性值
  52.            
  53.            bcount.Items.FindByValue(pager.NumericButtonCount.ToString()).Selected = true;
  54.            showfl.Checked = pager.ShowFirstLast;
  55.            showpn.Checked = pager.ShowPrevNext;
  56.            showindex.Checked = pager.ShowPageIndex;
  57.            cnindex.Checked = pager.ChinesePageIndex;
  58.            showdb.Checked = pager.ShowDisabledButtons;
  59.            bpadding.Text = pager.PagingButtonSpacing.ToString();
  60.            bfstring.Text = pager.NumericButtonTextFormatString;
  61.            fptext.Text = pager.FirstPageText;
  62.            lptext.Text = pager.LastPageText;
  63.            nptext.Text = pager.NextPageText;
  64.            pptext.Text = pager.PrevPageText;
  65.            
  66.            //获取用户自定义信息区属性值
  67.            cuswidth.Text = pager.CustomInfoSectionWidth.ToString();
  68.            cusalign.Items.FindByValue(pager.CustomInfoTextAlign.ToString()).Selected = true;
  69.            cusstyle.Text = pager.CustomInfoStyle;
  70.            //获取文本框及提交按钮属性值
  71.            showbox.Items[(int)pager.ShowInputBox].Selected = true;
  72.            subtext.Text = pager.SubmitButtonText;
  73.            txtbeforebox.Text = pager.TextBeforeInputBox;
  74.            txtafterbox.Text = pager.TextAfterInputBox;
  75.            boxstyle.Text = pager.InputBoxStyle;
  76.            threshold.Text = pager.ShowBoxThreshold.ToString();
  77.            //获取图片按钮属性值
  78.            btntype.SelectedIndex = (pager.PagingButtonType == PagingButtonType.Text) ? 0 : 1;
  79.            imgpath.Text = pager.ImagePath;
  80.            imgext.Text = pager.ButtonImageExtension;
  81.            imgnameext.Text = pager.ButtonImageNameExtension;
  82.            cpinameext.Text = pager.CpiButtonImageNameExtension;
  83.            disnameext.Text = pager.DisabledButtonImageNameExtension;
  84.            */
  85.         }
  86.     }
  87.     public void BindData()
  88.     {
  89.         string action = Request.QueryString["action"];
  90.         string sql = "";
  91.         if (action == "0")
  92.         {
  93.             sql = "SELECT yl_id,yl_title,yl_body,yl_name,yl_tel,yl_face,yl_adddate,yl_uid,yl_uidHF,yl_sh FROM yl_message WHERE yl_sh=0 ORDER BY yl_adddate DESC";
  94.         }
  95.         else
  96.         {
  97.             sql = "SELECT yl_id,yl_title,yl_body,yl_name,yl_tel,yl_face,yl_adddate,yl_uid,yl_uidHF,yl_sh FROM yl_message WHERE yl_sh=1 ORDER BY yl_adddate DESC";
  98.         }
  99.         cmd = new OleDbCommand(sql, conn);
  100.         OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
  101.         DataSet rs = new DataSet();  // 生成DataSet对象并填充数据 
  102.         adapter.Fill(rs, pager.PageSize * (pager.CurrentPageIndex - 1), pager.PageSize, "msg"); // 将Repeater控件进行数据绑定 
  103.         repeater.DataSource = rs.Tables["msg"];
  104.         repeater.DataBind();
  105.         //获取并显示分页信息
  106.         cindex.Text = pager.CurrentPageIndex.ToString();
  107.         rcount.Text = pager.RecordCount.ToString();
  108.         pcount.Text = pager.PageCount.ToString();
  109.         pagesize.Text = pager.PageSize.ToString();
  110.         pagesleft.Text = pager.PagesRemain.ToString();
  111.         recordsleft.Text = pager.RecordsRemain.ToString();
  112.         
  113.         //动态设置用户自定义文本内容
  114.         //pager.CustomInfoText = "记录总数:<font color="blue"><b>" + pager.RecordCount.ToString() + "</b></font>";
  115.        // pager.CustomInfoText += " 总页数:<font color="blue"><b>" + pager.PageCount.ToString() + "</b></font>";
  116.        // pager.CustomInfoText += " 当前页:<font color="red"><b>" + pager.CurrentPageIndex.ToString() + "</b></font>";
  117.        // showisec.SelectedIndex = (int)pager.ShowCustomInfoSection;
  118.         conn.Close();
  119.     }
  120.     public void ChangePage(object src, PageChangedEventArgs e)
  121.     {
  122.         pager.CurrentPageIndex = e.NewPageIndex;
  123.         BindData();
  124.     }
  125.     public void ChangePagerProperties(object src, EventArgs e)
  126.     {
  127.         /*
  128.         //设置分页属性值
  129.         pager.PageSize = int.Parse(psize.SelectedItem.Value);
  130.         //设置导航按钮属性值
  131.         pager.NumericButtonCount = int.Parse(bcount.SelectedItem.Value);
  132.         pager.ShowFirstLast = showfl.Checked;
  133.         pager.ShowPrevNext = showpn.Checked;
  134.         pager.ShowPageIndex = showindex.Checked;
  135.         if (!IsInputEmpty(fptext.Text))
  136.             pager.FirstPageText = fptext.Text;
  137.         if (!IsInputEmpty(lptext.Text))
  138.             pager.LastPageText = lptext.Text;
  139.         if (!IsInputEmpty(pptext.Text))
  140.             pager.PrevPageText = pptext.Text;
  141.         if (!IsInputEmpty(nptext.Text))
  142.             pager.NextPageText = nptext.Text;
  143.         pager.ChinesePageIndex = cnindex.Checked;
  144.         pager.ShowDisabledButtons = showdb.Checked;
  145.         pager.PagingButtonSpacing = Unit.Parse(bpadding.Text);
  146.         pager.NumericButtonTextFormatString = bfstring.Text;
  147.         //设置文本框及提交按钮属性值
  148.         pager.ShowInputBox = (ShowInputBox)Enum.Parse(typeof(ShowInputBox), showbox.SelectedItem.Value);
  149.         pager.SubmitButtonText = subtext.Text;
  150.         pager.TextBeforeInputBox = txtbeforebox.Text;
  151.         pager.TextAfterInputBox = txtafterbox.Text;
  152.         pager.ShowBoxThreshold = int.Parse(threshold.Text.Trim());
  153.         //设置图片按钮属性值
  154.         pager.PagingButtonType = (PagingButtonType)Enum.Parse(typeof(PagingButtonType), btntype.SelectedItem.Value);
  155.         //设置用户自定义文本区属性值
  156.         pager.HorizontalAlign = (showisec.SelectedIndex == 2) ? HorizontalAlign.Left : HorizontalAlign.Right;
  157.         pager.ShowCustomInfoSection = (ShowCustomInfoSection)Enum.Parse(typeof(ShowCustomInfoSection), showisec.SelectedItem.Value);
  158.         pager.CustomInfoSectionWidth = Unit.Parse(cuswidth.Text.Trim());
  159.         pager.CustomInfoTextAlign = (HorizontalAlign)Enum.Parse(typeof(HorizontalAlign), cusalign.SelectedItem.Value);
  160.         pager.CustomInfoStyle = cusstyle.Text;
  161.         BindData();
  162.         */
  163.     }
  164.     bool IsInputEmpty(string input)
  165.     {
  166.         if (input.Trim().Length > 0)
  167.             return false;
  168.         return true;
  169.     }
  170.   //计算总共有多少条记录 
  171.   public int CalculateRecord()
  172.   {
  173.       int intCount;
  174.       OleDbConnection conn = liuyinconn.connstr();
  175.       conn.Open();//打开数据库链接 ;
  176.       string strCount = "select count(*) as yl_id from yl_message";
  177.       OleDbCommand MyComm = new OleDbCommand(strCount, conn);
  178.       OleDbDataReader rs = MyComm.ExecuteReader();
  179.       if (rs.Read())
  180.       {
  181.           intCount = Int32.Parse(rs["yl_id"].ToString());
  182.       }
  183.       else
  184.       {
  185.           intCount = 0;
  186.       }
  187.       rs.Close();
  188.       conn.Close();
  189.       return intCount;
  190.   }
  191. }