ManageMeeting.aspx.cs
资源名称:OA_at.rar [点击查看]
上传用户:tree100901
上传日期:2007-06-03
资源大小:2295k
文件大小:11k
源码类别:
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>
- /// ManageMeeting 的摘要说明。
- /// </summary>
- public class ManageMeeting : System.Web.UI.Page
- {
- protected System.Data.SqlClient.SqlConnection MyConnection;
- protected System.Web.UI.WebControls.Label stats;
- private int totalMeeting;
- protected System.Web.UI.WebControls.DataGrid MyDataGrid;
- protected System.Web.UI.WebControls.Button Button1;
- public string PID;
- 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 MyCommand = new SqlDataAdapter("SelectAllMeeting",MyConnection);
- MyCommand.SelectCommand.CommandType = CommandType.StoredProcedure;
- DataSet ds = new DataSet();
- MyCommand.Fill(ds,"Meeting");
- MyConnection.Close();
- DataView dv = ds.Tables[0].DefaultView;
- totalMeeting=ds.Tables[0].Rows.Count;
- if (Session["tableAllMeeting"] == null)
- Session["tableAllMeeting"] = ds.Tables[0];
- if (Session["sorterAllMeeting"] == null)
- {
- Session["sorterAllMeeting"] ="Date";
- Session["sortAllMeeting"]=" DESC";
- }
- dv.Sort = (String) Session["sorterAllMeeting"]+(String) Session["sortAllMeeting"];
- ShowStats();
- return dv;
- }
- public void MyDataGrid_PageIndexChanged(Object sender, DataGridPageChangedEventArgs e)
- {
- DataGrid gridThatCausedEvent = (DataGrid) sender;
- gridThatCausedEvent.CurrentPageIndex = e.NewPageIndex;
- gridThatCausedEvent.DataSource = CreateDataSource();
- gridThatCausedEvent.DataBind();
- }
- public void MyDataGrid_Sort(Object sender, DataGridSortCommandEventArgs e)
- {
- Session["sorterAllMeeting"] = (string)e.SortExpression;
- Session["sortAllMeeting"]=(Session["sortAllMeeting"].ToString()==" ASC")?
- " DESC":" ASC";
- MyDataGrid.DataSource = CreateDataSource();
- MyDataGrid.DataBind();
- foreach (DataGridItem item in MyDataGrid.Controls[0].Controls)
- {
- if (item.ItemType == ListItemType.Header)
- {
- Label lb =(Label)item.FindControl((string)Session["sorterAllMeeting"]);
- lb.Text = (Session["sortAllMeeting"].ToString()==" DESC")?
- "↓":"↑";
- }
- }
- }
- private void ShowStats()
- {
- if (totalMeeting == 0)
- {
- MyDataGrid.Visible = false;
- stats.Text = "未找到符合条件的记录!";
- }
- else
- {
- MyDataGrid.Visible = true;
- int startOffset = (totalMeeting > 0) ?
- (MyDataGrid.CurrentPageIndex*MyDataGrid.PageSize+1) : 0;
- int pageEndOffset = (MyDataGrid.CurrentPageIndex+1)*(MyDataGrid.PageSize);
- int endOffset = (pageEndOffset > totalMeeting) ? totalMeeting : pageEndOffset;
- string SortName;
- switch(Session["sorterAllMeeting"].ToString())
- {
- case "Title":
- SortName = "会议主题";
- break;
- case "Date":
- SortName="发送时间";
- break;
- case "PersonID":
- SortName = "发送人";
- break;
- case "Caller":
- SortName = "召集人";
- break;
- case "MeetingDate":
- SortName = "会议时间";
- break;
- default:
- SortName="发送时间";
- break;
- }
- stats.Text = String.Format("<B>共</B>{2}<B>条记录中的</B>{0}-{1}<B>条记录 根据</B>{3}<B>排序</B>",
- startOffset,endOffset,totalMeeting,SortName)+MyDataGrid.Items.Count.ToString();
- MyDataGrid.PagerStyle.Visible = (totalMeeting <= MyDataGrid.PageSize) ? false : true;
- }
- }
- public void MyDataGrid_ItemCreated(Object sender, DataGridItemEventArgs e)
- {
- if((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
- {
- }
- if((e.Item.ItemType == ListItemType.Header))
- {
- for(int i = 0; i<5; i++)
- {
- Label lb = new Label();
- if(i==0)
- lb.ID = "Title";
- if(i==1)
- lb.ID = "MeetingDate";
- if(i==2)
- lb.ID = "Date";
- if(i==3)
- lb.ID = "Caller";
- if(i==4)
- lb.ID = "PersonID";
- lb.Text = "↓";
- e.Item.Cells[i].Controls.Add(lb);
- }
- }
- }
- public void MyDataGrid_ItemDataBound(Object sender, DataGridItemEventArgs e)
- {
- if((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
- {
- string MeetingID = DataBinder.Eval(e.Item.DataItem, "MeetingID").ToString();
- string AID0 = DataBinder.Eval(e.Item.DataItem, "AccepterID").ToString();
- AID0 =AID0.Trim().Replace("(","").Replace(")","");
- string AID =CleanInput(AID0);
- string CID0 = DataBinder.Eval(e.Item.DataItem, "Caller").ToString();
- CID0 =CID0.Trim().Replace("(","").Replace(")","");
- string CID =CleanInput(CID0);
- string [] str = AID.Split(new char[] {','});
- string [] Cstr = CID.Split(new char[] {','});
- string SID = e.Item.Cells[4].Text.Trim();
- string CallerName="";
- for(int i=0;i<Cstr.Length;i++)
- {
- if(Cstr[i]!="")
- {
- SqlCommand MyCommand2 = new SqlCommand("PersonName",MyConnection);
- MyCommand2.CommandType = CommandType.StoredProcedure;
- MyCommand2.Parameters.Add(new SqlParameter("@PersonID", SqlDbType.Int, 4));
- MyCommand2.Parameters["@PersonID"].Value = Cstr[i];
- if(MyConnection.State.ToString()=="Closed")
- MyConnection.Open();
- SqlDataReader myReader2 = MyCommand2.ExecuteReader();
- while(myReader2.Read())
- CallerName += ","+myReader2["Name"].ToString();
- myReader2.Close();
- }
- }
- e.Item.Cells[3].Text = CallerName.Substring(1);
- SqlCommand MyCommand1 = new SqlCommand("PersonName",MyConnection);
- MyCommand1.CommandType = CommandType.StoredProcedure;
- MyCommand1.Parameters.Add(new SqlParameter("@PersonID", SqlDbType.Int, 4));
- MyCommand1.Parameters["@PersonID"].Value = SID;
- if(MyConnection.State.ToString()=="Closed")
- MyConnection.Open();
- SqlDataReader myReader1 = MyCommand1.ExecuteReader();
- while(myReader1.Read())
- e.Item.Cells[4].Text = myReader1["Name"].ToString();
- myReader1.Close();
- string AccepterName="";
- for(int i=0;i<str.Length;i++)
- {
- if(str[i]!="")
- {
- SqlCommand MyCommand2 = new SqlCommand("PersonName",MyConnection);
- MyCommand2.CommandType = CommandType.StoredProcedure;
- MyCommand2.Parameters.Add(new SqlParameter("@PersonID", SqlDbType.Int, 4));
- MyCommand2.Parameters["@PersonID"].Value = str[i];
- if(MyConnection.State.ToString()=="Closed")
- MyConnection.Open();
- SqlDataReader myReader2 = MyCommand2.ExecuteReader();
- while(myReader2.Read())
- AccepterName += ","+myReader2["Name"].ToString();
- myReader2.Close();
- }
- }
- e.Item.ToolTip = "本通知发送给了"+AccepterName.Substring(1);
- MyConnection.Close();
- if(e.Item.Cells[0].Text.Length>15)
- e.Item.Cells[0].Text = e.Item.Cells[0].Text.Substring(0,15)+"......";
- LinkButton myDeleteButton1;
- LinkButton myDeleteButton2;
- LinkButton myDeleteButton3;
- myDeleteButton1 = (LinkButton) e.Item.Cells[5].Controls[0];
- myDeleteButton1.Attributes.Add("onclick", @"if(confirm('你确认要修改这条记录吗?')) window.open('EditMeeting.aspx?MeetingID="+MeetingID+"','_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,revisable=no,left=100,top=0,width=550,height=352');return false;");
- myDeleteButton2 = (LinkButton) e.Item.Cells[6].Controls[0];
- myDeleteButton2.Attributes.Add("onclick", @"window.open('ViewMeetingState.aspx?MeetingID="+MeetingID+"','_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,revisable=no,left=100,top=0,width=185,height="+str.Length*35+"');return false;");
- myDeleteButton3 = (LinkButton) e.Item.Cells[7].Controls[0];
- myDeleteButton3.Attributes.Add("onclick", @"return confirm('你确认要删除这条记录吗?');");
- }
- }
- public void MyDataGrid_Delete(Object sender, DataGridCommandEventArgs E)
- {
- SqlCommand MyCommand = new SqlCommand("DeleteMeeting",MyConnection);
- MyCommand.CommandType = CommandType.StoredProcedure;
- MyCommand.Parameters.Add(new SqlParameter("@MeetingID", SqlDbType.Int, 4));
- MyCommand.Parameters["@MeetingID"].Value = MyDataGrid.DataKeys[(int)E.Item.ItemIndex];
- if(MyConnection.State.ToString()=="Closed")
- MyConnection.Open();
- try
- {
- MyCommand.ExecuteNonQuery();
- }
- catch (SqlException)
- {
- RegisterStartupScript("alert","<script>alert('出现错误:未能删除记录!')</" + "script>");
- }
- MyConnection.Close();
- if ((MyDataGrid.CurrentPageIndex!=0)&&((int)E.Item.ItemIndex==0))
- {
- if (MyDataGrid.Items.Count==1)
- MyDataGrid.CurrentPageIndex-=1;
- }
- MyDataGrid.DataSource = CreateDataSource();
- MyDataGrid.DataBind();
- Response.Write("<script>opener.location.href=opener.location.href;opener=null;window.close();</"+"script>");
- }
- #region Web 窗体设计器生成的代码
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
- //
- InitializeComponent();
- base.OnInit(e);
- }
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.Button1.Click += new System.EventHandler(this.Button1_Click);
- this.Load += new System.EventHandler(this.Page_Load);
- }
- #endregion
- private void Button1_Click(object sender, System.EventArgs e)
- {
- string bb = "";
- for( int i = 0; i < MyDataGrid.Items.Count; i++ )
- {
- RadioButton rb0 = ( RadioButton )MyDataGrid.Items[i].FindControl("rb_0");
- RadioButton rb1 = ( RadioButton )MyDataGrid.Items[i].FindControl("rb_1");
- RadioButton rb2 = ( RadioButton )MyDataGrid.Items[i].FindControl("rb_2");
- if(rb0.Checked)
- bb = "0";
- if(rb1.Checked)
- bb = "1";
- if(rb2.Checked)
- bb = "2";
- SqlCommand MyCommand2= new SqlCommand("UpdateMeetingResult", MyConnection);
- MyCommand2.CommandType = CommandType.StoredProcedure;
- MyCommand2.Parameters.Add(new SqlParameter("@MeetingID", SqlDbType.Int, 4));
- MyCommand2.Parameters["@MeetingID"].Value = Int32.Parse(MyDataGrid.Items[i].Cells[9].Text.ToString().Trim());
- MyCommand2.Parameters.Add(new SqlParameter("@Result", SqlDbType.NVarChar,10));
- MyCommand2.Parameters["@Result"].Value = bb;
- if(MyConnection.State.ToString()=="Closed")
- MyConnection.Open();
- MyCommand2.ExecuteNonQuery();
- MyConnection.Close();
- }
- }
- public String CleanInput(string strIn)
- {
- return System.Text.RegularExpressions.Regex.Replace(strIn, @"[^w,]", "");
- }
- }
- }