MoreInfomation.aspx.cs
资源名称:OA_at.rar [点击查看]
上传用户:tree100901
上传日期:2007-06-03
资源大小:2295k
文件大小:5k
源码类别:
OA系统
开发平台:
C#
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Data;
- using System.Data.SqlClient;
- using System.Drawing;
- using System.Web;
- using System.Web.SessionState;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.HtmlControls;
- namespace OA
- {
- /// <summary>
- /// MoreInfomation 的摘要说明。
- /// </summary>
- public class MoreInfomation : System.Web.UI.Page
- {
- protected System.Data.SqlClient.SqlConnection MyConnection;
- protected System.Web.UI.WebControls.DataGrid MyDataGrid;
- public int InfoCategoryID=1,PageIndex=1;
- protected System.Web.UI.WebControls.Label PagePrev;
- protected System.Web.UI.WebControls.Label InfoCategoryName;
- protected System.Web.UI.WebControls.Label RCount;
- protected System.Web.UI.WebControls.Label PageNext;
- private void Page_Load(object sender, System.EventArgs e)
- {
- if (!IsPostBack)
- {
- MyConnection = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
- if(Request.QueryString["InfoCategoryID"]!=null)
- InfoCategoryID = Int32.Parse(Request.QueryString["InfoCategoryID"].ToString());
- SqlCommand MyCommand00 = new SqlCommand("SelectInfoCategoryName",MyConnection);
- MyCommand00.CommandType = CommandType.StoredProcedure;
- MyCommand00.Parameters.Add(new SqlParameter("@InfoCategoryID", SqlDbType.Int, 4));
- MyCommand00.Parameters["@InfoCategoryID"].Value = InfoCategoryID;
- MyConnection.Open();
- SqlDataReader myReader = MyCommand00.ExecuteReader();
- while(myReader.Read())
- {
- InfoCategoryName.Text = myReader.GetString(0).ToString();
- }
- myReader.Close();
- if(Request.QueryString["PageIndex"]!=null)
- PageIndex = Int32.Parse(Request.QueryString["PageIndex"].ToString());
- SqlCommand MyCommand0 = new SqlCommand("GetInfomation", MyConnection);
- MyCommand0.CommandType = CommandType.StoredProcedure;
- MyCommand0.Parameters.Add("@pageindex",1);
- MyCommand0.Parameters.Add("@pagesize",1);
- MyCommand0.Parameters.Add("@docount",true);
- MyCommand0.Parameters.Add("@InfoCategoryID",InfoCategoryID);
- if(MyConnection.State.ToString()=="Closed")
- MyConnection.Open();
- int RecordCount = (int)MyCommand0.ExecuteScalar();
- RCount.Text = "记录总数:"+RecordCount.ToString();
- MyConnection.Close();
- MyDataGrid.DataSource = CreateDataSource();
- MyDataGrid.DataBind();
- int Prev = PageIndex-1;
- int Next = PageIndex+1;
- if(PageIndex ==1)
- {
- PagePrev.Text = "上页";
- PagePrev.Enabled =false;
- }
- else
- PagePrev.Text = "<a href ='MoreInfomation.aspx?InfoCategoryID="+InfoCategoryID+"&PageIndex="+Prev+"'>上页</"+"a>";
- int LastPage;
- if((RecordCount-RecordCount/MyDataGrid.PageSize*MyDataGrid.PageSize)>0)
- LastPage = RecordCount/MyDataGrid.PageSize+1;
- else
- LastPage = RecordCount/MyDataGrid.PageSize;
- if(PageIndex==LastPage)
- {
- PageNext.Text="下页";
- PageNext.Enabled = false;
- }
- else
- PageNext.Text = "<a href ='MoreInfomation.aspx?InfoCategoryID="+InfoCategoryID+"&PageIndex="+Next+"'>下页</"+"a>";
- }
- // 在此处放置用户代码以初始化页面
- }
- private ICollection CreateDataSource()
- {
- MyConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlDataAdapter MyCommand = new SqlDataAdapter("GetInfomation",MyConnection);
- MyCommand.SelectCommand.CommandType = CommandType.StoredProcedure;
- MyCommand.SelectCommand.Parameters.Add("@pageindex",PageIndex);
- MyCommand.SelectCommand.Parameters.Add("@pagesize",MyDataGrid.PageSize);
- MyCommand.SelectCommand.Parameters.Add("@docount",false);
- MyCommand.SelectCommand.Parameters.Add("@InfoCategoryID",InfoCategoryID);
- DataSet ds = new DataSet();
- MyCommand.Fill(ds,"Infomation");
- MyConnection.Close();
- DataView dv = ds.Tables[0].DefaultView;
- /* totalDocument=ds.Tables[0].Rows.Count;
- if (Session["table"] == null)
- Session["table"] = ds.Tables[0];
- if (Session["sorter"] == null)
- {
- Session["sorter"] ="Date";
- Session["sort"]=" DESC";
- }
- dv.Sort = (String) Session["sorter"]+(String) Session["sort"];
- ShowStats();
- */ return dv;
- }
- public string Switch(object obj)
- {
- string str = obj.ToString();
- if (str.Length > 18)
- {
- return (str.Substring(0,18) + "......");
- }
- else
- {
- return str;
- }
- }
- #region Web 窗体设计器生成的代码
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
- //
- InitializeComponent();
- base.OnInit(e);
- }
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.Load += new System.EventHandler(this.Page_Load);
- }
- #endregion
- }
- }