SchedByWeek.aspx.cs
上传用户:autodoor
上传日期:2022-08-04
资源大小:9973k
文件大小:7k
源码类别:

.net编程

开发平台:

Others

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Drawing;
  7. using System.Web;
  8. using System.Web.SessionState;
  9. using System.Web.UI;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.HtmlControls;
  12. using qminoa.DA.Schedule;
  13. namespace qminoa.Webs.Schedule
  14. {
  15. public class SchedByWeek : qminoa.Webs.PageBase
  16. {
  17. protected System.Web.UI.WebControls.Label lblUName;
  18. protected System.Web.UI.WebControls.TextBox txtYear;
  19. protected System.Web.UI.WebControls.DropDownList dropMonth;
  20. protected System.Web.UI.WebControls.DropDownList dropDay;
  21. protected System.Web.UI.WebControls.ImageButton cmdQuery;
  22. protected System.Web.UI.WebControls.Label lblErr;
  23. protected System.Web.UI.WebControls.Label lblYear;
  24. protected System.Web.UI.WebControls.Label lblDate;
  25. protected System.Web.UI.WebControls.LinkButton cmdToday;
  26. protected System.Web.UI.WebControls.LinkButton cmdMonth;
  27. protected System.Web.UI.WebControls.LinkButton cmdWeek;
  28. protected System.Web.UI.WebControls.LinkButton cmdDay;
  29. protected System.Web.UI.WebControls.LinkButton cmdLastDay;
  30. protected System.Web.UI.WebControls.Label lblHeader;
  31. protected System.Web.UI.WebControls.LinkButton cmdNextDay;
  32. private static DateTime date = new DateTime();
  33. private void Page_Load(object sender, System.EventArgs e)
  34. {
  35. this.PageBegin("我的日程",false);
  36. if(!IsPostBack)
  37. {
  38. if(Request.QueryString["date"] != null)
  39. {
  40. date =DateTime.Parse(Request.QueryString["date"]);
  41. DisplayDate(date);
  42. }
  43. else
  44. {
  45. date= DateTime.Now;
  46. DisplayDate(DateTime.Now);
  47. }
  48. }
  49. }
  50.         
  51. void DisplayDate(DateTime date)
  52. {
  53. string Day = "";
  54. switch(date.DayOfWeek.ToString())
  55. {
  56. case "Sunday":
  57. Day="星期日";
  58. break;
  59. case "Monday":
  60. Day="星期一";
  61. break;
  62. case "Tuesday":
  63. Day="星期二";
  64. break;
  65. case "Wednesday":
  66. Day="星期三";
  67. break;
  68. case "Thursday":
  69. Day="星期四";
  70. break;
  71. case "Friday":
  72. Day="星期五";
  73. break;
  74. case "Saturday":
  75. Day="星期六";
  76. break;
  77. }
  78.             
  79. lblHeader.Text = date.Year +"年"+ date.Month +"月"+ date.Day +"日"+" "+" "+" "+Day;
  80. txtYear.Text = date.Year.ToString();
  81. dropMonth.SelectedIndex = date.Month - 1;
  82. dropDay.SelectedIndex = date.Day - 1;
  83. }
  84. #region Web Form Designer generated code
  85. override protected void OnInit(EventArgs e)
  86. {
  87. //
  88. // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
  89. //
  90. InitializeComponent();
  91. base.OnInit(e);
  92. }
  93. /// <summary>
  94. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  95. /// 此方法的内容。
  96. /// </summary>
  97. private void InitializeComponent()
  98. {    
  99. this.dropMonth.SelectedIndexChanged += new System.EventHandler(this.dropMonth_SelectedIndexChanged);
  100. this.dropDay.SelectedIndexChanged += new System.EventHandler(this.dropDay_SelectedIndexChanged);
  101. this.cmdQuery.Click += new System.Web.UI.ImageClickEventHandler(this.cmdQuery_Click);
  102. this.cmdMonth.Click += new System.EventHandler(this.cmdMonth_Click);
  103. this.cmdDay.Click += new System.EventHandler(this.cmdDay_Click);
  104. this.cmdLastDay.Click += new System.EventHandler(this.cmdLastDay_Click);
  105. this.cmdNextDay.Click += new System.EventHandler(this.cmdNextDay_Click);
  106. this.Load += new System.EventHandler(this.Page_Load);
  107. }
  108. #endregion
  109. private void cmdMonth_Click(object sender, System.EventArgs e)
  110. {
  111. Response.Redirect("Schedule.aspx?date="+date.ToShortDateString());
  112. }
  113. private void cmdDay_Click(object sender, System.EventArgs e)
  114. {
  115. Response.Redirect("SchedByDay.aspx?date="+date.ToShortDateString());
  116. }
  117. private void cmdQuery_Click(object sender, System.Web.UI.ImageClickEventArgs e)
  118. {
  119. if(!(txtYear.Text==""))
  120. {
  121. int year,month,day;
  122. year=Int32.Parse(txtYear.Text);
  123. month=dropMonth.SelectedIndex + 1;
  124. day=Int32.Parse(dropDay.SelectedItem.Text);
  125. date = new DateTime(year,month,day);
  126. DisplayDate(date);
  127. }
  128. }
  129. private void cmdLastDay_Click(object sender, System.EventArgs e)
  130. {
  131. System.TimeSpan duration = new System.TimeSpan(7, 0, 0, 0);
  132. date=date.Subtract(duration);
  133. DisplayDate(date);
  134. }
  135.         
  136. private void cmdNextDay_Click(object sender, System.EventArgs e)
  137. {
  138. System.TimeSpan duration = new System.TimeSpan(7, 0, 0, 0);
  139. date=date.Add(duration);
  140. DisplayDate(date);
  141. }
  142.         
  143. private void dropDay_SelectedIndexChanged(object sender, System.EventArgs e)
  144. {
  145. int numday = DateTime.DaysInMonth(Int32.Parse(txtYear.Text),dropMonth.SelectedIndex + 1);
  146. if(dropDay.SelectedIndex + 1 > numday)
  147. {
  148. lblErr.Visible = true;
  149. lblErr.Text = "日期错误";
  150. dropDay.SelectedIndex = numday - 1;
  151. }
  152. }
  153.         
  154. private void dropMonth_SelectedIndexChanged(object sender, System.EventArgs e)
  155. {
  156. int numday = DateTime.DaysInMonth(Int32.Parse(txtYear.Text),dropMonth.SelectedIndex + 1);
  157. if(dropDay.SelectedIndex + 1 > numday)
  158. {
  159. lblErr.Visible = true;
  160. lblErr.Text = "日期错误";
  161. dropDay.SelectedIndex = numday - 1;
  162. }
  163. }
  164. public string ssubject(int i)
  165. {
  166. string strDisInfo="";
  167.             DateTime Date = new DateTime();
  168. Date = DateTime.Parse(sDate(i));
  169. SqlCommand objcommand = new SqlCommand();
  170. SqlDataReader objdatareader;  
  171. ScheduleDA objschdule = new ScheduleDA();
  172. objcommand = objschdule.SchRead(Convert.ToInt16(this.Empid),Date);
  173. objcommand.Connection.Open();
  174. objdatareader=objcommand.ExecuteReader();
  175. try
  176. {
  177. while(objdatareader.Read())
  178. {
  179. int SchID = Int32.Parse(objdatareader.GetInt32(1).ToString());
  180. DateTime FDate = new DateTime();
  181. FDate = DateTime.Parse(objdatareader.GetSqlDateTime(2).ToString());
  182. string FDate_hour = FDate.Hour.ToString();
  183. string FDate_Minute = FDate.Minute.ToString();
  184. if(FDate_Minute == "0")
  185. {
  186. FDate_Minute = "00";
  187. }
  188.         string Subject = objdatareader.GetValue(0).ToString();
  189. if(Subject.Length > 4)
  190. {
  191. Subject = Subject.Substring(0,4);
  192. Subject += ".."; 
  193. }
  194. 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>";
  195. }
  196. objdatareader.Close();
  197. objcommand.Connection.Close();
  198. return strDisInfo;
  199. }
  200. catch
  201. {
  202. return "读取日程,出现错误!";
  203. }
  204. }
  205. public string sDate(int i)
  206. {
  207. int j = num(date);
  208. DateTime Date = new DateTime();
  209.             Date=date;
  210. System.TimeSpan duration1 = new System.TimeSpan(j, 0, 0, 0);
  211. Date=Date.Subtract(duration1);
  212. System.TimeSpan duration2 = new System.TimeSpan(i, 0, 0, 0);
  213. Date=Date.Add(duration2);
  214. return Date.ToShortDateString();
  215. }
  216. public int day(string date)
  217. {
  218. return Int32.Parse(DateTime.Parse(date).Day.ToString());
  219. }
  220. public int num(DateTime date)
  221. {
  222. int j=0;
  223. switch(date.DayOfWeek.ToString())
  224. {
  225. case "Sunday":
  226. j = 0;
  227. break;
  228. case "Monday":
  229. j = 1;
  230. break;
  231. case "Tuesday":
  232. j = 2;
  233. break;
  234. case "Wednesday":
  235. j = 3;
  236. break;
  237. case "Thursday":
  238. j = 4;
  239. break;
  240. case "Friday":
  241. j = 5;
  242. break;
  243. case "Saturday":
  244. j = 6;
  245. break;
  246. }
  247. return j;
  248. }
  249. }
  250. }