MySchedule.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>
- /// MySchedule 的摘要说明。
- /// </summary>
- public class MySchedule : System.Web.UI.Page
- {
- protected System.Data.SqlClient.SqlConnection MyConnection;
- protected System.Web.UI.WebControls.Label stats;
- private int totalSchedule;
- 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)
- {
- MyConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand MyCommand00 = new SqlCommand("PersonID",MyConnection);
- MyCommand00.CommandType = CommandType.StoredProcedure;
- MyCommand00.Parameters.Add(new SqlParameter("@Name", SqlDbType.NVarChar, 50));
- MyCommand00.Parameters["@Name"].Value = User.Identity.Name;
- MyConnection.Open();
- SqlDataReader myReader00 = MyCommand00.ExecuteReader();
- myReader00.Read();
- PID = myReader00.GetInt32(0).ToString();
- myReader00.Close();
- if(!IsPostBack)
- {
- MyDataGrid.DataSource = CreateDataSource();
- MyDataGrid.DataBind();
- }
- // 在此处放置用户代码以初始化页面
- }
- private ICollection CreateDataSource()
- {
- MyConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlDataAdapter MyCommand = new SqlDataAdapter("SelectMySchedule",MyConnection);
- MyCommand.SelectCommand.CommandType = CommandType.StoredProcedure;
- MyCommand.SelectCommand.Parameters.Add(new SqlParameter("@PersonID", SqlDbType.Int, 4));
- MyCommand.SelectCommand.Parameters["@PersonID"].Value = Int32.Parse(PID);
- DataSet ds = new DataSet();
- MyCommand.Fill(ds,"Schedule");
- MyConnection.Close();
- DataView dv = ds.Tables[0].DefaultView;
- totalSchedule=ds.Tables[0].Rows.Count;
- if (Session["tableMySchedule"] == null)
- Session["tableMySchedule"] = ds.Tables[0];
- if (Session["sorterMySchedule"] == null)
- {
- Session["sorterMySchedule"] ="Date";
- Session["sortMySchedule"]=" DESC";
- }
- dv.Sort = (String) Session["sorterMySchedule"]+(String) Session["sortMySchedule"];
- 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["sorterMySchedule"] = (string)e.SortExpression;
- Session["sortMySchedule"]=(Session["sortMySchedule"].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["sorterMySchedule"]);
- lb.Text = (Session["sortMySchedule"].ToString()==" DESC")?
- "↓":"↑";
- }
- }
- }
- private void ShowStats()
- {
- if (totalSchedule == 0)
- {
- MyDataGrid.Visible = false;
- stats.Text = "未找到符合条件的记录!";
- }
- else
- {
- MyDataGrid.Visible = true;
- int startOffset = (totalSchedule > 0) ?
- (MyDataGrid.CurrentPageIndex*MyDataGrid.PageSize+1) : 0;
- int pageEndOffset = (MyDataGrid.CurrentPageIndex+1)*(MyDataGrid.PageSize);
- int endOffset = (pageEndOffset > totalSchedule) ? totalSchedule : pageEndOffset;
- string SortName;
- switch(Session["sorterMySchedule"].ToString())
- {
- case "Contents":
- SortName = "日程计划";
- break;
- case "Date":
- SortName="编制时间";
- break;
- case "PlanTime":
- SortName = "预定时间";
- break;
- case "Result":
- SortName = "计划状态";
- break;
- default:
- SortName="编制时间";
- break;
- }
- stats.Text = String.Format("<B>共</B>{2}<B>条记录中的</B>{0}-{1}<B>条记录 根据</B>{3}<B>排序</B>",
- startOffset,endOffset,totalSchedule,SortName)+MyDataGrid.Items.Count.ToString();
- MyDataGrid.PagerStyle.Visible = (totalSchedule <= 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<4; i++)
- {
- Label lb = new Label();
- if(i==0)
- lb.ID = "Contents";
- if(i==1)
- lb.ID = "PlanTime";
- if(i==2)
- lb.ID = "Date";
- if(i==3)
- lb.ID = "Result";
- 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))
- {
- if(e.Item.Cells[0].Text.Length>15)
- e.Item.Cells[0].Text = e.Item.Cells[0].Text.Substring(0,15)+"......";
- LinkButton myDeleteButton;
- myDeleteButton = (LinkButton) e.Item.Cells[4].Controls[0];
- myDeleteButton.Attributes.Add("onclick", @"return confirm('你确认要删除此信息吗?');");
- }
- }
- public void MyDataGrid_Delete(Object sender, DataGridCommandEventArgs E)
- {
- SqlCommand MyCommand = new SqlCommand("DeleteSchedule",MyConnection);
- MyCommand.CommandType = CommandType.StoredProcedure;
- MyCommand.Parameters.Add(new SqlParameter("@ScheduleID", SqlDbType.Int, 4));
- MyCommand.Parameters["@ScheduleID"].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>");
- }
- 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("UpdateScheduleResult", MyConnection);
- MyCommand2.CommandType = CommandType.StoredProcedure;
- MyCommand2.Parameters.Add(new SqlParameter("@ScheduleID", SqlDbType.Int, 4));
- MyCommand2.Parameters["@ScheduleID"].Value = Int32.Parse(MyDataGrid.Items[i].Cells[5].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();
- }
- }
- #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
- }
- }