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

.net编程

开发平台:

Others

  1. using System;
  2. using System.Web.UI.WebControls;
  3. using System.Configuration;
  4. using qminoa.BLL.PM;
  5. namespace qminoa.Webs.PM
  6. {
  7. public class Calendar : System.Web.UI.Page
  8. {
  9. protected System.Web.UI.WebControls.DropDownList MonthSelect;
  10. protected System.Web.UI.WebControls.DropDownList YearSelect;
  11. protected System.Web.UI.WebControls.Calendar Cal;
  12. protected System.Web.UI.WebControls.Label lblDate;
  13. protected System.Web.UI.WebControls.Button OKButton;
  14. protected System.Web.UI.WebControls.Button CancelButton;
  15. protected System.Web.UI.HtmlControls.HtmlInputHidden datechosen;
  16. private void Page_Load(object sender, System.EventArgs e)
  17. {
  18. if (!Page.IsPostBack)
  19. {
  20. string selected = Request.QueryString["selected"];
  21. string id = Request.QueryString["id"];
  22. string form = Request.QueryString["formname"];
  23. string postBack = Request.QueryString["postBack"];
  24. Cal.FirstDayOfWeek = (System.Web.UI.WebControls.FirstDayOfWeek)1;//(System.Web.UI.WebControls.FirstDayOfWeek)Convert.ToInt32(ConfigurationSettings.AppSettings[Global.CfgKeyFirstDayOfWeek]);
  25. try
  26. {
  27. Cal.SelectedDate = Cal.VisibleDate = Convert.ToDateTime(selected);
  28. }
  29. catch
  30. {
  31. Cal.SelectedDate = Cal.VisibleDate = DateTime.Today;
  32. }
  33. FillCalendarChoices();
  34. SelectCorrectValues();
  35. OKButton.Attributes.Add("onClick", "window.opener.SetDate('" + form + "','" + id + "', document.Calendar.datechosen.value," + postBack + ");");
  36. CancelButton.Attributes.Add("onClick", "CloseWindow()");
  37. }
  38. }
  39. private void FillCalendarChoices()
  40. {
  41. DateTime thisdate = new DateTime(DateTime.Today.Year,1,1);
  42. for (int x=0; x<12; x++)
  43. {
  44. ListItem li = new ListItem(thisdate.ToString("MMMM"), thisdate.Month.ToString());
  45. MonthSelect.Items.Add(li);
  46. thisdate = thisdate.AddMonths(1);
  47. }
  48. for (int y=1994; y <= thisdate.Year; y++)
  49. {
  50. YearSelect.Items.Add(y.ToString());
  51. }
  52. }
  53.  
  54. private void SelectCorrectValues()
  55. {
  56. lblDate.Text = Cal.SelectedDate.ToShortDateString();
  57. datechosen.Value = lblDate.Text;
  58. MonthSelect.SelectedIndex = MonthSelect.Items.IndexOf(MonthSelect.Items.FindByValue(Cal.SelectedDate.Month.ToString()));
  59. YearSelect.SelectedIndex = YearSelect.Items.IndexOf(YearSelect.Items.FindByValue(Cal.SelectedDate.Year.ToString()));
  60. }
  61. #region Web Form Designer generated code
  62. override protected void OnInit(EventArgs e)
  63. {
  64. //
  65. // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  66. //
  67. InitializeComponent();
  68. base.OnInit(e);
  69. }
  70. /// <summary>
  71. /// Required method for Designer support - do not modify
  72. /// the contents of this method with the code editor.
  73. /// </summary>
  74. private void InitializeComponent()
  75. {    
  76. this.MonthSelect.SelectedIndexChanged += new System.EventHandler(this.MonthSelect_SelectedIndexChanged);
  77. this.YearSelect.SelectedIndexChanged += new System.EventHandler(this.YearSelect_SelectedIndexChanged);
  78. this.Cal.SelectionChanged += new System.EventHandler(this.Cal_SelectionChanged);
  79. this.ID = "Calendar";
  80. this.Load += new System.EventHandler(this.Page_Load);
  81. }
  82. #endregion
  83. private void Cal_SelectionChanged(object sender, System.EventArgs e)
  84. {
  85. Cal.VisibleDate = Cal.SelectedDate;
  86. SelectCorrectValues();
  87. }
  88. private void MonthSelect_SelectedIndexChanged(object sender, System.EventArgs e)
  89. {
  90. Cal.SelectedDate = Cal.VisibleDate 
  91. = new DateTime(Convert.ToInt32(YearSelect.SelectedItem.Value), 
  92.    Convert.ToInt32(MonthSelect.SelectedItem.Value), 1);;
  93. SelectCorrectValues();
  94. }
  95. private void YearSelect_SelectedIndexChanged(object sender, System.EventArgs e)
  96. {
  97. Cal.SelectedDate = Cal.VisibleDate 
  98. = new DateTime(Convert.ToInt32(YearSelect.SelectedItem.Value), 
  99.    Convert.ToInt32(MonthSelect.SelectedItem.Value), 1);;
  100. SelectCorrectValues();
  101. }
  102. }
  103. }