DepSch.aspx.cs
上传用户:autodoor
上传日期:2022-08-04
资源大小:9973k
文件大小:13k
- using System;
- using System.Data;
- using System.Web.UI.WebControls;
- using System.Web.UI.HtmlControls;
- using qminoa.Common;
- using qminoa.DA;
- using qminoa.DA.Schedule;
- namespace qminoa.Webs.Schedule
- {
- public class DepSch : qminoa.Webs.PageBase
- {
- protected System.Web.UI.WebControls.DropDownList dropBranch;
- protected System.Web.UI.WebControls.DropDownList dropDep;
- protected System.Web.UI.WebControls.TextBox txtName;
- protected System.Web.UI.WebControls.ImageButton cmdQuery;
- protected System.Web.UI.WebControls.TextBox txtYear;
- protected System.Web.UI.WebControls.DropDownList dropMonth;
- protected System.Web.UI.WebControls.DropDownList dropDay;
- protected System.Web.UI.WebControls.Label lblErr;
- protected System.Web.UI.WebControls.Label lblEmpNum;
- protected System.Web.UI.WebControls.Label lblDate;
- protected System.Web.UI.WebControls.LinkButton cmdToday;
- protected System.Web.UI.WebControls.HyperLink lnkByWeek;
- protected System.Web.UI.WebControls.HyperLink lnkByDay;
- protected System.Web.UI.WebControls.LinkButton cmdLastDay;
- protected System.Web.UI.WebControls.Label lblHeader;
- protected System.Web.UI.WebControls.LinkButton cmdNextDay;
- protected System.Web.UI.WebControls.DataGrid dgdData;
-
- private static DateTime date = DateTime.Now;
- private static DataTable DepSchTB = new DataTable();
-
- private void Page_Load(object sender, System.EventArgs e)
- {
- this.PageBegin("部门日程",true);
- if(this.EmpRightCode < 1)
- {
- cmdQuery.Visible = false;
- dropBranch.Enabled = false;
- dropDep.Enabled = false;
- txtName.Enabled = false;
- txtYear.Enabled = false;
- dropMonth.Enabled = false;
- dropDay.Enabled = false;
- }
- if(!IsPostBack)
- {
- date = DateTime.Now;
- AdminDB admin = new AdminDB();
- dropBranch.DataSource=admin.GetAllBranch();
- dropBranch.DataBind();
- dropBranch.Items.Add(new ListItem("--选择全部--","0"));
- dropBranch.SelectedIndex = dropBranch.Items.Count - 1;
- dropDep.DataSource=admin.GetDepByBranch(Int32.Parse(dropBranch.SelectedItem.Value));
- dropDep.DataBind();
- dropDep.Items.Add(new ListItem("--选择全部--","0"));
- dropDep.SelectedIndex = dropDep.Items.Count - 1;
- WeekBind();
- dgdDatabind();
- }
- }
- #region Web Form Designer generated code
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
- //
- InitializeComponent();
- base.OnInit(e);
- }
-
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.dropBranch.SelectedIndexChanged += new System.EventHandler(this.dropBranch_SelectedIndexChanged);
- this.cmdQuery.Click += new System.Web.UI.ImageClickEventHandler(this.cmdQuery_Click);
- this.dropMonth.SelectedIndexChanged += new System.EventHandler(this.dropMonth_SelectedIndexChanged);
- this.dropDay.SelectedIndexChanged += new System.EventHandler(this.dropDay_SelectedIndexChanged);
- this.cmdLastDay.Click += new System.EventHandler(this.cmdLastDay_Click);
- this.cmdNextDay.Click += new System.EventHandler(this.cmdNextDay_Click);
- this.dgdData.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dgdData_PageIndexChanged);
- this.dgdData.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgdData_ItemDataBound);
- this.Load += new System.EventHandler(this.Page_Load);
- }
- #endregion
- public DateTime sdate(int i)
- {
- int j = num(date);
- DateTime Date = new DateTime();
- Date=date;
- System.TimeSpan duration1 = new System.TimeSpan(j, 0, 0, 0);
- Date=Date.Subtract(duration1);
- System.TimeSpan duration2 = new System.TimeSpan(i, 0, 0, 0);
- Date=Date.Add(duration2);
- return Date;
- }
-
- public int num(DateTime date)
- {
- int j=0;
- switch(date.DayOfWeek.ToString())
- {
- case "Sunday":
- j = 0;
- break;
- case "Monday":
- j = 1;
- break;
- case "Tuesday":
- j = 2;
- break;
- case "Wednesday":
- j = 3;
- break;
- case "Thursday":
- j = 4;
- break;
- case "Friday":
- j = 5;
- break;
- case "Saturday":
- j = 6;
- break;
- }
- return j;
- }
- private void dropMonth_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- int numday = DateTime.DaysInMonth(Int32.Parse(txtYear.Text),dropMonth.SelectedIndex + 1);
- if(dropDay.SelectedIndex + 1 > numday)
- {
- lblErr.Visible = true;
- lblErr.Text = "日期错误";
- dropDay.SelectedIndex = numday - 1;
- }
- }
- private void dgdDatabind()
- {
- DepSchTB.Clear();
- DepSchTB.Columns.Clear();
- string Subject0,Subject1,Subject2,Subject3,Subject4,Subject5,Subject6;
- DepSchTB.Columns.Add("name");
- DepSchTB.Columns.Add("w0");
- DepSchTB.Columns.Add("w1");
- DepSchTB.Columns.Add("w2");
- DepSchTB.Columns.Add("w3");
- DepSchTB.Columns.Add("w4");
- DepSchTB.Columns.Add("w5");
- DepSchTB.Columns.Add("w6");
- ScheduleDA objdepsch = new ScheduleDA();
- DataTable oldempdatatable = new DataTable();
- oldempdatatable = objdepsch.cpdepempread(dropBranch.SelectedItem.Text,dropDep.SelectedItem.Text,txtName.Text);
- for(int i = 0; i < oldempdatatable.Rows.Count; i++)
- {
- DataRow dr = DepSchTB.NewRow();
- DepSchTB.Rows.Add(dr);
- DepSchTB.Rows[i]["name"] = oldempdatatable.Rows[i][0].ToString();
-
- DataTable dt0 = new DataTable();
- dt0 = objdepsch.cpdepschread(DateTime.Parse(sdate(0).ToShortDateString()),Int16.Parse(oldempdatatable.Rows[i][1].ToString()));
- for(int j = 0; j < dt0.Rows.Count; j++)
- {
- if(dt0.Rows[j][0].ToString().Length > 4)
- {
- Subject0 = dt0.Rows[j][0].ToString().Substring(0,4);
- Subject0 += "..";
- }
- else
- {
- Subject0 = dt0.Rows[j][0].ToString();
- }
- DepSchTB.Rows[i]["w0"] += "☉"+"<A href=SchAddUp.aspx?reurl=depsch.aspx&ID="+Int16.Parse(dt0.Rows[j][1].ToString())+">"+Subject0+"</A>"+"<br>";
- }
-
- DataTable dt1 = new DataTable();
- dt1 = objdepsch.cpdepschread(DateTime.Parse(sdate(1).ToShortDateString()),Int16.Parse(oldempdatatable.Rows[i][1].ToString()));
- for(int j = 0; j < dt1.Rows.Count; j++)
- {
- if(dt1.Rows[j][0].ToString().Length > 4)
- {
- Subject1 = dt1.Rows[j][0].ToString().Substring(0,4);
- Subject1 += "..";
- }
- else
- {
- Subject1 = dt1.Rows[j][0].ToString();
- }
- DepSchTB.Rows[i]["w1"] += "☉"+"<A href=SchAddUp.aspx?reurl=depsch.aspx&ID="+Int16.Parse(dt1.Rows[j][1].ToString())+">"+Subject1+"</A>"+"<br>";
- }
- DataTable dt2 = new DataTable();
- dt2 = objdepsch.cpdepschread(DateTime.Parse(sdate(2).ToShortDateString()),Int16.Parse(oldempdatatable.Rows[i][1].ToString()));
- for(int j = 0; j < dt2.Rows.Count; j++)
- {
- if(dt2.Rows[j][0].ToString().Length > 4)
- {
- Subject2 = dt2.Rows[j][0].ToString().Substring(0,4);
- Subject2 += "..";
- }
- else
- {
- Subject2 = dt2.Rows[j][0].ToString();
- }
- DepSchTB.Rows[i]["w2"] += "☉"+"<A href=SchAddUp.aspx?reurl=depsch.aspx&ID="+Int16.Parse(dt2.Rows[j][1].ToString())+">"+Subject2+"</A>"+"<br>";
- }
- DataTable dt3 = new DataTable();
- dt3 = objdepsch.cpdepschread(DateTime.Parse(sdate(3).ToShortDateString()),Int16.Parse(oldempdatatable.Rows[i][1].ToString()));
- for(int j = 0; j < dt3.Rows.Count; j++)
- {
- if(dt3.Rows[j][0].ToString().Length > 4)
- {
- Subject3 = dt3.Rows[j][0].ToString().Substring(0,4);
- Subject3 += "..";
- }
- else
- {
- Subject3 = dt3.Rows[j][0].ToString();
- }
- DepSchTB.Rows[i]["w3"] += "☉"+"<A href=SchAddUp.aspx?reurl=depsch.aspx&ID="+Int16.Parse(dt3.Rows[j][1].ToString())+">"+Subject3+"</A>"+"<br>";
- }
-
- DataTable dt4 = new DataTable();
- dt4 = objdepsch.cpdepschread(DateTime.Parse(sdate(4).ToShortDateString()),Int16.Parse(oldempdatatable.Rows[i][1].ToString()));
- for(int j = 0; j < dt4.Rows.Count; j++)
- {
- if(dt4.Rows[j][0].ToString().Length > 4)
- {
- Subject4 = dt4.Rows[j][0].ToString().Substring(0,4);
- Subject4 += "..";
- }
- else
- {
- Subject4 = dt4.Rows[j][0].ToString();
- }
- DepSchTB.Rows[i]["w4"] += "☉"+"<A href=SchAddUp.aspx?reurl=depsch.aspx&ID="+Int16.Parse(dt4.Rows[j][1].ToString())+">"+Subject4+"</A>"+"<br>";
- }
- DataTable dt5 = new DataTable();
- dt5 = objdepsch.cpdepschread(DateTime.Parse(sdate(5).ToShortDateString()),Int16.Parse(oldempdatatable.Rows[i][1].ToString()));
- for(int j = 0; j < dt5.Rows.Count; j++)
- {
- if(dt5.Rows[j][0].ToString().Length > 4)
- {
- Subject5 = dt5.Rows[j][0].ToString().Substring(0,4);
- Subject5 += "..";
- }
- else
- {
- Subject5 = dt5.Rows[j][0].ToString();
- }
- DepSchTB.Rows[i]["w5"] += "☉"+"<A href=SchAddUp.aspx?reurl=depsch.aspx&ID="+Int16.Parse(dt5.Rows[j][1].ToString())+">"+Subject5+"</A>"+"<br>";
- }
- DataTable dt6 = new DataTable();
- dt6 = objdepsch.cpdepschread(DateTime.Parse(sdate(6).ToShortDateString()),Int16.Parse(oldempdatatable.Rows[i][1].ToString()));
- for(int j = 0; j < dt6.Rows.Count; j++)
- {
- if(dt6.Rows[j][0].ToString().Length > 4)
- {
- Subject6 = dt6.Rows[j][0].ToString().Substring(0,4);
- Subject6 += "..";
- }
- else
- {
- Subject6 = dt6.Rows[j][0].ToString();
- }
- DepSchTB.Rows[i]["w6"] += "☉"+"<A href=SchAddUp.aspx?reurl=depsch.aspx&ID="+Int16.Parse(dt6.Rows[j][1].ToString())+">"+Subject6+"</A>"+"<br>";
- }
- }
- dgdData.DataSource = DepSchTB.DefaultView;
- dgdData.DataBind();
- }
- private void dgdData_PageIndexChanged(object sender, DataGridPageChangedEventArgs e)
- {
- dgdData.CurrentPageIndex=e.NewPageIndex;
- dgdData.DataSource = DepSchTB;
- dgdData.DataBind();
- }
- public int count()
- {
- return DepSchTB.Rows.Count;
- }
- private void cmdLastDay_Click(object sender, System.EventArgs e)
- {
- System.TimeSpan duration = new System.TimeSpan(7, 0, 0, 0);
- date=date.Subtract(duration);
- dgdDatabind();
- WeekBind();
- }
- private void cmdNextDay_Click(object sender, System.EventArgs e)
- {
- System.TimeSpan duration = new System.TimeSpan(7, 0, 0, 0);
- date=date.Add(duration);
- dgdDatabind();
- WeekBind();
- }
- private void WeekBind()
- {
- string Day = "";
- switch(date.DayOfWeek.ToString())
- {
- case "Sunday":
- Day="星期日";
- break;
- case "Monday":
- Day="星期一";
- break;
- case "Tuesday":
- Day="星期二";
- break;
- case "Wednesday":
- Day="星期三";
- break;
- case "Thursday":
- Day="星期四";
- break;
- case "Friday":
- Day="星期五";
- break;
- case "Saturday":
- Day="星期六";
- break;
- }
- lblHeader.Text = date.Year +"年"+ date.Month +"月"+ date.Day +"日"+" "+" "+" "+Day;
- txtYear.Text = date.Year.ToString();
- dropMonth.SelectedIndex = date.Month - 1;
- dropDay.SelectedIndex = date.Day - 1;
- }
- private void dropDay_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- int numday = DateTime.DaysInMonth(Int32.Parse(txtYear.Text),dropMonth.SelectedIndex + 1);
- if(dropDay.SelectedIndex + 1 > numday)
- {
- lblErr.Visible = true;
- lblErr.Text = "日期错误";
- dropDay.SelectedIndex = numday - 1;
- }
- }
- private void cmdQuery_Click(object sender, System.Web.UI.ImageClickEventArgs e)
- {
- if(!(txtYear.Text==""))
- {
- int year,month,day;
- year=Int32.Parse(txtYear.Text);
- month=dropMonth.SelectedIndex + 1;
- day=Int32.Parse(dropDay.SelectedItem.Text);
- date = new DateTime(year,month,day);
- dgdDatabind();
- WeekBind();
- dgdDatabind();
- }
- }
- private void dropBranch_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- string txtdropBranch;
- txtdropBranch = dropBranch.SelectedItem.Text;
- AdminDB admin = new AdminDB();
- dropDep.DataSource=admin.GetDepByBranch(Int32.Parse(dropBranch.SelectedItem.Value));
- dropDep.DataBind();
- dropDep.Items.Add(new ListItem("--选择全部--","0"));
- dropDep.SelectedIndex = dropDep.Items.Count - 1;
- }
- public int day(DateTime date)
- {
- int Num= Int32.Parse(date.Day.ToString());
- int numday = DateTime.DaysInMonth(Int32.Parse(date.Year.ToString()),Int32.Parse(date.Month.ToString()));
-
- if(Num > numday)
- {
- Num -= numday;
- }
- int lastnumday;
- if(Int32.Parse(date.Month.ToString())==1)
- {
- lastnumday = DateTime.DaysInMonth(Int32.Parse(date.Year.ToString())-1,12);
- }
- else
- {
- lastnumday = DateTime.DaysInMonth(Int32.Parse(date.Year.ToString()),Int32.Parse(date.Month.ToString())-1);
- }
-
- if(Num < 1)
- {
- Num += lastnumday;
- }
-
- return Num;
- }
- private void dgdData_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
- {
- ListItemType itemType = e.Item.ItemType;
- e.Item.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#fff7ce';cursor='hand';" ;
- if (itemType == ListItemType.Item )
- {
- e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#dedfde';";
- }
- else if( itemType == ListItemType.AlternatingItem)
- {
- e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#ffffff';";
- }
- }
- }
- }