SchedByWeek.aspx.cs
上传用户:autodoor
上传日期:2022-08-04
资源大小:9973k
文件大小:7k
- 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;
- using qminoa.DA.Schedule;
- namespace qminoa.Webs.Schedule
- {
- public class SchedByWeek : qminoa.Webs.PageBase
- {
- protected System.Web.UI.WebControls.Label lblUName;
- 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.ImageButton cmdQuery;
- protected System.Web.UI.WebControls.Label lblErr;
- protected System.Web.UI.WebControls.Label lblYear;
- protected System.Web.UI.WebControls.Label lblDate;
- protected System.Web.UI.WebControls.LinkButton cmdToday;
- protected System.Web.UI.WebControls.LinkButton cmdMonth;
- protected System.Web.UI.WebControls.LinkButton cmdWeek;
- protected System.Web.UI.WebControls.LinkButton cmdDay;
- protected System.Web.UI.WebControls.LinkButton cmdLastDay;
- protected System.Web.UI.WebControls.Label lblHeader;
- protected System.Web.UI.WebControls.LinkButton cmdNextDay;
- private static DateTime date = new DateTime();
- private void Page_Load(object sender, System.EventArgs e)
- {
- this.PageBegin("我的日程",false);
- if(!IsPostBack)
- {
- if(Request.QueryString["date"] != null)
- {
- date =DateTime.Parse(Request.QueryString["date"]);
- DisplayDate(date);
- }
- else
- {
- date= DateTime.Now;
- DisplayDate(DateTime.Now);
- }
- }
- }
-
- void DisplayDate(DateTime date)
- {
- 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;
- }
- #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.dropMonth.SelectedIndexChanged += new System.EventHandler(this.dropMonth_SelectedIndexChanged);
- this.dropDay.SelectedIndexChanged += new System.EventHandler(this.dropDay_SelectedIndexChanged);
- this.cmdQuery.Click += new System.Web.UI.ImageClickEventHandler(this.cmdQuery_Click);
- this.cmdMonth.Click += new System.EventHandler(this.cmdMonth_Click);
- this.cmdDay.Click += new System.EventHandler(this.cmdDay_Click);
- this.cmdLastDay.Click += new System.EventHandler(this.cmdLastDay_Click);
- this.cmdNextDay.Click += new System.EventHandler(this.cmdNextDay_Click);
- this.Load += new System.EventHandler(this.Page_Load);
- }
- #endregion
-
- private void cmdMonth_Click(object sender, System.EventArgs e)
- {
- Response.Redirect("Schedule.aspx?date="+date.ToShortDateString());
- }
- private void cmdDay_Click(object sender, System.EventArgs e)
- {
- Response.Redirect("SchedByDay.aspx?date="+date.ToShortDateString());
- }
- 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);
- DisplayDate(date);
- }
- }
- private void cmdLastDay_Click(object sender, System.EventArgs e)
- {
- System.TimeSpan duration = new System.TimeSpan(7, 0, 0, 0);
- date=date.Subtract(duration);
- DisplayDate(date);
- }
-
- private void cmdNextDay_Click(object sender, System.EventArgs e)
- {
- System.TimeSpan duration = new System.TimeSpan(7, 0, 0, 0);
- date=date.Add(duration);
- DisplayDate(date);
- }
-
- 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 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;
- }
- }
- public string ssubject(int i)
- {
- string strDisInfo="";
- DateTime Date = new DateTime();
- Date = DateTime.Parse(sDate(i));
- SqlCommand objcommand = new SqlCommand();
- SqlDataReader objdatareader;
- ScheduleDA objschdule = new ScheduleDA();
- objcommand = objschdule.SchRead(Convert.ToInt16(this.Empid),Date);
- objcommand.Connection.Open();
- objdatareader=objcommand.ExecuteReader();
- try
- {
- while(objdatareader.Read())
- {
- int SchID = Int32.Parse(objdatareader.GetInt32(1).ToString());
- DateTime FDate = new DateTime();
- FDate = DateTime.Parse(objdatareader.GetSqlDateTime(2).ToString());
- string FDate_hour = FDate.Hour.ToString();
- string FDate_Minute = FDate.Minute.ToString();
- if(FDate_Minute == "0")
- {
- FDate_Minute = "00";
- }
- string Subject = objdatareader.GetValue(0).ToString();
- if(Subject.Length > 4)
- {
- Subject = Subject.Substring(0,4);
- Subject += "..";
- }
- strDisInfo+="<br>"+"<A href=schaddup.aspx?reurl=schedbyweek.aspx&id="+SchID+"&day="+date+" class=td style='FONT-WEIGHT: 400'>☉"+FDate_hour+":"+FDate_Minute+" "+Subject+" </A>";
- }
- objdatareader.Close();
- objcommand.Connection.Close();
- return strDisInfo;
- }
- catch
- {
- return "读取日程,出现错误!";
- }
- }
- public string 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.ToShortDateString();
- }
- public int day(string date)
- {
- return Int32.Parse(DateTime.Parse(date).Day.ToString());
- }
- 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;
- }
- }
- }