PageRenderTime 135ms CodeModel.GetById 52ms app.highlight 4ms RepoModel.GetById 77ms app.codeStats 0ms

/managers/Calendar.aspx.cs

http://github.com/gmhawash/SSR
C# | 102 lines | 77 code | 18 blank | 7 comment | 8 complexity | 4574a060892e92776a0a7625abbaebaf MD5 | raw file
  1using System;
  2using System.Data;
  3using System.Configuration;
  4using System.Web;
  5using System.Web.Security;
  6using System.Web.UI;
  7using System.Web.UI.WebControls;
  8using System.Web.UI.WebControls.WebParts;
  9using System.Web.UI.HtmlControls;
 10using System.Collections.Generic;
 11using ASPNET.StarterKit.BusinessLogicLayer;
 12
 13public partial class Calendar_aspx : Page {
 14  public string controlToEdit;
 15  public string isPostBack;
 16
 17
 18  public Calendar_aspx() {
 19    LoadComplete += new EventHandler(Page_LoadComplete);
 20  }
 21
 22  void Page_Load(object sender, EventArgs e) {
 23    if (!Page.IsPostBack) {
 24      controlToEdit = Request.QueryString["controlID"];
 25      Session.Add("controlToEdit", controlToEdit);
 26      isPostBack = Request.QueryString["isPostBack"];
 27      Session.Add("isPostBack", isPostBack);
 28
 29
 30      // Cast first day of the week from web.config file.  Set it to the calendar
 31      Cal.FirstDayOfWeek = (System.Web.UI.WebControls.FirstDayOfWeek)Convert.ToInt32(ConfigurationManager.AppSettings["FirstDayOfWeek"]);
 32
 33      // Select the Correct date for Calendar from query string
 34      // If fails, pick the current date on Calendar
 35      try {
 36        Cal.SelectedDate = Cal.VisibleDate = Convert.ToDateTime(lblDate.Text);
 37      }
 38      catch {
 39        Cal.SelectedDate = Cal.VisibleDate = DateTime.Today;
 40      }
 41
 42      // Fills in correct values for the dropdown menus
 43      FillCalendarChoices();
 44      SelectCorrectValues();
 45    }
 46    else {
 47
 48      if (Session["controlToEdit"] != null)
 49        controlToEdit = (string)Session["controlToEdit"];
 50
 51
 52      if (Session["isPostBack"] != null)
 53        isPostBack = (string)Session["isPostBack"];
 54    }
 55  }
 56  void Page_LoadComplete(object sender, System.EventArgs e) {
 57    OKButton.OnClientClick = "javascript:window.opener.SetControlValue('" + this.controlToEdit + "','" + lblDate.Text + "','" + this.isPostBack + "');";
 58  }
 59
 60  protected void FillCalendarChoices() {
 61    DateTime thisdate = (DateTime.Now).AddYears(5); ;
 62  
 63    // Fills in month values
 64    for (int x = 0; x < 12; x++) {
 65      // Loops through 12 months of the year and fills in each month value
 66      ListItem li = new ListItem(thisdate.ToString("MMMM"), thisdate.Month.ToString());
 67      MonthSelect.Items.Add(li);
 68      thisdate = thisdate.AddMonths(1);
 69    }
 70
 71    // Fills in year values and change y value to other years if necessary
 72    for (int y = 2000; y <= thisdate.Year; y++) {
 73      YearSelect.Items.Add(y.ToString());
 74    }
 75  }
 76
 77  protected void SelectCorrectValues() {
 78    lblDate.Text = Cal.SelectedDate.ToShortDateString();
 79    datechosen.Value = lblDate.Text;
 80    MonthSelect.SelectedIndex = MonthSelect.Items.IndexOf(MonthSelect.Items.FindByValue(Cal.SelectedDate.Month.ToString()));
 81    YearSelect.SelectedIndex = YearSelect.Items.IndexOf(YearSelect.Items.FindByValue(Cal.SelectedDate.Year.ToString()));
 82  }
 83
 84  protected void Cal_SelectionChanged(object sender, System.EventArgs e) {
 85    Cal.VisibleDate = Cal.SelectedDate;
 86    SelectCorrectValues();
 87  }
 88
 89  protected void MonthSelect_SelectedIndexChanged(object sender, System.EventArgs e) {
 90    Cal.SelectedDate = Cal.VisibleDate
 91        = new DateTime(Convert.ToInt32(YearSelect.SelectedItem.Value),
 92                       Convert.ToInt32(MonthSelect.SelectedItem.Value), 1); ;
 93    SelectCorrectValues();
 94  }
 95
 96  protected void YearSelect_SelectedIndexChanged(object sender, System.EventArgs e) {
 97    Cal.SelectedDate = Cal.VisibleDate
 98        = new DateTime(Convert.ToInt32(YearSelect.SelectedItem.Value),
 99                       Convert.ToInt32(MonthSelect.SelectedItem.Value), 1); ;
100    SelectCorrectValues();
101  }
102}