ManageNotification.aspx.cs
资源名称:OA_at.rar [点击查看]
上传用户:tree100901
上传日期:2007-06-03
资源大小:2295k
文件大小:8k
源码类别:
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>
- /// ManageNotification 的摘要说明。
- /// </summary>
- public class ManageNotification : System.Web.UI.Page
- {
- protected System.Data.SqlClient.SqlConnection MyConnection;
- protected System.Web.UI.WebControls.DataGrid MyDataGrid;
- protected System.Web.UI.WebControls.TextBox Contents;
- protected System.Web.UI.HtmlControls.HtmlInputButton AddNotification;
- public string PID;
- protected System.Web.UI.WebControls.Label stats;
- private int totalNotification;
- private void Page_Load(object sender, System.EventArgs e)
- {
- CheckUser CHU = new CheckUser();
- CHU.UserName = User.Identity.Name;
- PID = CHU.UserID.ToString();
- if(CHU.Is_FileManager() == false)
- Response.Write("<script>alert('对不起,你没有查看此页面的权限!');history.back(2)</" + "script>");
- MyConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
- if(!IsPostBack)
- {
- MyDataGrid.DataSource = CreateDataSource();
- MyDataGrid.DataBind();
- }
- // 在此处放置用户代码以初始化页面
- }
- private ICollection CreateDataSource()
- {
- MyConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlDataAdapter MyCommand2 = new SqlDataAdapter("SelectAllNotification",MyConnection);
- MyCommand2.SelectCommand.CommandType = CommandType.StoredProcedure;
- DataSet ds = new DataSet();
- MyCommand2.Fill(ds, "Notification");
- DataView dv = ds.Tables["Notification"].DefaultView;
- totalNotification=ds.Tables["Notification"].Rows.Count;
- ShowStats();
- return dv;
- }
- public void MyDataGrid_PageIndexChanged(Object sender, DataGridPageChangedEventArgs e)
- {
- DataGrid gridThatCausedEvent = (DataGrid) sender;
- gridThatCausedEvent.CurrentPageIndex = e.NewPageIndex;
- gridThatCausedEvent.DataSource = CreateDataSource();
- gridThatCausedEvent.DataBind();
- }
- private void AddNotification_ServerClick(object sender, System.EventArgs e)
- {
- Page.Validate();
- if ( !Page.IsValid )
- {
- return;
- }
- if(Contents.Text.Trim()!="")
- {
- SqlCommand MyCommand = new SqlCommand("InsertNotification", MyConnection);
- MyCommand.CommandType = CommandType.StoredProcedure;
- MyCommand.Parameters.Add(new SqlParameter("@Contents", SqlDbType.NVarChar, 200));
- MyCommand.Parameters["@Contents"].Value = Contents.Text;
- MyCommand.Parameters.Add(new SqlParameter("@PersonID", SqlDbType.Int, 4));
- MyCommand.Parameters["@PersonID"].Value = Int32.Parse(PID);
- MyCommand.Connection.Open();
- try
- {
- MyCommand.ExecuteNonQuery();
- }
- catch
- {
- }
- MyCommand.Connection.Close();
- Contents.Text = "";
- MyDataGrid.DataSource = CreateDataSource();
- MyDataGrid.DataBind();
- }
- else
- RegisterStartupScript("alert","<script>alert('公告内容不能为空!')</" + "script>");
- }
- public void MyDataGrid_Delete(Object sender, DataGridCommandEventArgs E)
- {
- MyConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand MyCommand = new SqlCommand("DeleteNotification",MyConnection);
- MyCommand.CommandType = CommandType.StoredProcedure;
- MyCommand.Parameters.Add(new SqlParameter("@NotificationID", SqlDbType.Int, 4));
- MyCommand.Parameters["@NotificationID"].Value = MyDataGrid.DataKeys[(int)E.Item.ItemIndex];
- if(MyConnection.State.ToString()=="Closed")
- MyConnection.Open();
- try
- {
- MyCommand.ExecuteNonQuery();
- }
- catch
- {
- RegisterStartupScript("alert","<script>alert('出现错误:未能删除记录!')</" + "script>");
- }
- MyConnection.Close();
- MyDataGrid.DataSource = CreateDataSource();
- MyDataGrid.DataBind();
- }
- public void MyDataGrid_ItemDataBound(Object sender, DataGridItemEventArgs e)
- {
- if((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
- {
- string NotificationID = DataBinder.Eval(e.Item.DataItem, "NotificationID").ToString();
- string PersonID = DataBinder.Eval(e.Item.DataItem, "PersonID").ToString();
- LinkButton myDeleteButton;
- myDeleteButton = (LinkButton) e.Item.Cells[0].Controls[0];
- myDeleteButton.Attributes.Add("onclick", @"return confirm('你确认要删除此信息吗?');");
- SqlCommand MyCommand0 = new SqlCommand("PersonName",MyConnection);
- MyCommand0.CommandType = CommandType.StoredProcedure;
- MyCommand0.Parameters.Add(new SqlParameter("@PersonID", SqlDbType.Int, 4));
- MyCommand0.Parameters["@PersonID"].Value = Int32.Parse(PersonID);
- if(MyConnection.State.ToString()=="Closed")
- MyConnection.Open();
- SqlDataReader myReader0 = MyCommand0.ExecuteReader();
- myReader0.Read();
- e.Item.Cells[3].Text = myReader0["Name"].ToString();
- myReader0.Close();
- MyConnection.Close();
- string Contents = DataBinder.Eval(e.Item.DataItem, "Contents").ToString();
- if(Contents.Length>15)
- Contents = Contents.Substring(0,15)+"......";
- e.Item.Cells[2].Text = "<a href = javascript:window.open('Notification.aspx?NotificationID="+NotificationID+"','_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,revisable=no,width=300,top=0,height=300');window.close();>"+Contents+"</a>";
- }
- }
- public void MyDataGrid_ItemCommand(Object sender, DataGridCommandEventArgs e)
- {
- switch(((LinkButton)e.CommandSource).CommandName)
- {
- case "Cancel":
- Cancel(e);
- break;
- default:
- break;
- }
- }
- public void Cancel(DataGridCommandEventArgs e)
- {
- MyConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
- int itemindex = e.Item.ItemIndex;
- SqlCommand MyCommand0 = new SqlCommand("UpdateNotificationState",MyConnection);
- MyCommand0.CommandType = CommandType.StoredProcedure;
- MyCommand0.Parameters.Add(new SqlParameter("@NotificationID", SqlDbType.Int, 4));
- MyCommand0.Parameters["@NotificationID"].Value = MyDataGrid.DataKeys[(int)e.Item.ItemIndex];
- if(MyConnection.State.ToString()=="Closed")
- MyConnection.Open();
- MyCommand0.ExecuteNonQuery();
- MyConnection.Close();
- MyDataGrid.DataSource = CreateDataSource();
- MyDataGrid.DataBind();
- RegisterStartupScript("alert","<script>alert('取消成功!')</script>");
- }
- private void ShowStats()
- {
- if (totalNotification == 0)
- {
- MyDataGrid.Visible = false;
- stats.Text = "未找到符合条件的记录!";
- }
- else
- {
- MyDataGrid.Visible = true;
- int startOffset = (totalNotification > 0) ?
- (MyDataGrid.CurrentPageIndex*MyDataGrid.PageSize+1) : 0;
- int pageEndOffset = (MyDataGrid.CurrentPageIndex+1)*(MyDataGrid.PageSize);
- int endOffset = (pageEndOffset > totalNotification) ? totalNotification : pageEndOffset;
- stats.Text = String.Format("<B>共</B>{2}<B>条记录中的</B>{0}-{1}<B>条记录",
- startOffset,endOffset,totalNotification);
- MyDataGrid.PagerStyle.Visible = (totalNotification <= MyDataGrid.PageSize) ? false : true;
- }
- }
- #region Web 窗体设计器生成的代码
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
- //
- InitializeComponent();
- base.OnInit(e);
- }
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.AddNotification.ServerClick += new System.EventHandler(this.AddNotification_ServerClick);
- this.Load += new System.EventHandler(this.Page_Load);
- }
- #endregion
- }
- }