/managers/Calendar.aspx.cs

http://github.com/gmhawash/SSR · C# · 102 lines · 77 code · 18 blank · 7 comment · 8 complexity · 4574a060892e92776a0a7625abbaebaf MD5 · raw file

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