Calendar.aspx.cs
上传用户:autodoor
上传日期:2022-08-04
资源大小:9973k
文件大小:4k
- using System;
- using System.Web.UI.WebControls;
- using System.Configuration;
- using qminoa.BLL.PM;
- namespace qminoa.Webs.PM
- {
- public class Calendar : System.Web.UI.Page
- {
- protected System.Web.UI.WebControls.DropDownList MonthSelect;
- protected System.Web.UI.WebControls.DropDownList YearSelect;
- protected System.Web.UI.WebControls.Calendar Cal;
- protected System.Web.UI.WebControls.Label lblDate;
- protected System.Web.UI.WebControls.Button OKButton;
- protected System.Web.UI.WebControls.Button CancelButton;
- protected System.Web.UI.HtmlControls.HtmlInputHidden datechosen;
- private void Page_Load(object sender, System.EventArgs e)
- {
- if (!Page.IsPostBack)
- {
- string selected = Request.QueryString["selected"];
- string id = Request.QueryString["id"];
- string form = Request.QueryString["formname"];
- string postBack = Request.QueryString["postBack"];
-
- Cal.FirstDayOfWeek = (System.Web.UI.WebControls.FirstDayOfWeek)1;//(System.Web.UI.WebControls.FirstDayOfWeek)Convert.ToInt32(ConfigurationSettings.AppSettings[Global.CfgKeyFirstDayOfWeek]);
-
- try
- {
- Cal.SelectedDate = Cal.VisibleDate = Convert.ToDateTime(selected);
- }
- catch
- {
- Cal.SelectedDate = Cal.VisibleDate = DateTime.Today;
- }
-
- FillCalendarChoices();
- SelectCorrectValues();
- OKButton.Attributes.Add("onClick", "window.opener.SetDate('" + form + "','" + id + "', document.Calendar.datechosen.value," + postBack + ");");
- CancelButton.Attributes.Add("onClick", "CloseWindow()");
- }
- }
- private void FillCalendarChoices()
- {
- DateTime thisdate = new DateTime(DateTime.Today.Year,1,1);
- for (int x=0; x<12; x++)
- {
- ListItem li = new ListItem(thisdate.ToString("MMMM"), thisdate.Month.ToString());
- MonthSelect.Items.Add(li);
- thisdate = thisdate.AddMonths(1);
- }
- for (int y=1994; y <= thisdate.Year; y++)
- {
- YearSelect.Items.Add(y.ToString());
- }
- }
-
- private void SelectCorrectValues()
- {
- lblDate.Text = Cal.SelectedDate.ToShortDateString();
- datechosen.Value = lblDate.Text;
- MonthSelect.SelectedIndex = MonthSelect.Items.IndexOf(MonthSelect.Items.FindByValue(Cal.SelectedDate.Month.ToString()));
- YearSelect.SelectedIndex = YearSelect.Items.IndexOf(YearSelect.Items.FindByValue(Cal.SelectedDate.Year.ToString()));
- }
- #region Web Form Designer generated code
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN: This call is required by the ASP.NET Web Form Designer.
- //
- InitializeComponent();
- base.OnInit(e);
- }
-
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.MonthSelect.SelectedIndexChanged += new System.EventHandler(this.MonthSelect_SelectedIndexChanged);
- this.YearSelect.SelectedIndexChanged += new System.EventHandler(this.YearSelect_SelectedIndexChanged);
- this.Cal.SelectionChanged += new System.EventHandler(this.Cal_SelectionChanged);
- this.ID = "Calendar";
- this.Load += new System.EventHandler(this.Page_Load);
- }
- #endregion
- private void Cal_SelectionChanged(object sender, System.EventArgs e)
- {
- Cal.VisibleDate = Cal.SelectedDate;
- SelectCorrectValues();
- }
- private void MonthSelect_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- Cal.SelectedDate = Cal.VisibleDate
- = new DateTime(Convert.ToInt32(YearSelect.SelectedItem.Value),
- Convert.ToInt32(MonthSelect.SelectedItem.Value), 1);;
- SelectCorrectValues();
- }
- private void YearSelect_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- Cal.SelectedDate = Cal.VisibleDate
- = new DateTime(Convert.ToInt32(YearSelect.SelectedItem.Value),
- Convert.ToInt32(MonthSelect.SelectedItem.Value), 1);;
- SelectCorrectValues();
- }
- }
- }