protected void Page_Load(object sender, EventArgs e) { // Control initialization rfvName.ErrorMessage = GetString("TimeZ.Edit.rfvName"); rfvDisplayName.ErrorMessage = GetString("TimeZ.Edit.rfvDisplayName"); rfvGMT.ErrorMessage = GetString("TimeZ.Edit.rfvGMT"); rvGMTDouble.ErrorMessage = GetString("TimeZ.Edit.rvGMTDouble"); lblTimeZoneRuleStart.Text = lblTimeZoneRuleEnd.Text = GetString("general.na"); rvGMTDouble.MinimumValue = (-12.0).ToString(); rvGMTDouble.MaximumValue = (13.0).ToString(); string currentTimeZone = GetString("TimeZ.Edit.NewItem"); startRuleEditor.TitleText = GetString("TimeZ.Edit.TimeZoneRuleStartRule"); endRuleEditor.TitleText = GetString("TimeZ.Edit.TimeZoneRuleEndRule"); // Get timeZone id from query string zoneId = QueryHelper.GetInteger("zoneid", 0); if (zoneId > 0) { var timeZoneObj = TimeZoneInfoProvider.GetTimeZoneInfo(zoneId); //Set edited object EditedObject = timeZoneObj; if (timeZoneObj != null) { currentTimeZone = timeZoneObj.TimeZoneDisplayName; // Fill editing form if (!RequestHelper.IsPostBack()) { LoadData(timeZoneObj); // Show that the timeZone was created or updated successfully if (QueryHelper.GetBoolean("saved", false) && !RequestHelper.IsPostBack()) { ShowChangesSaved(); } } } } // Initializes page title control PageBreadcrumbs.Items.Add(new BreadcrumbItem { Text = GetString("TimeZ.Edit.ItemList"), RedirectUrl = "~/CMSModules/TimeZones/Pages/TimeZone_List.aspx" }); PageBreadcrumbs.Items.Add(new BreadcrumbItem { Text = currentTimeZone }); PageTitle.TitleText = (zoneId > 0) ? GetString("timez.edit.properties") : GetString("timez.edit.newtimezone"); startRuleEditor.Enabled = chkTimeZoneDaylight.Checked; endRuleEditor.Enabled = chkTimeZoneDaylight.Checked; }
/// <summary> /// Deletes timezone. Called when the "Delete timezone" button is pressed. /// Expects the CreateTimezone method to be run first. /// </summary> private bool DeleteTimezone() { // Get the timezone TimeZoneInfo deleteTimezone = TimeZoneInfoProvider.GetTimeZoneInfo("MyNewTimezone"); // Delete the timezone TimeZoneInfoProvider.DeleteTimeZoneInfo(deleteTimezone); return(deleteTimezone != null); }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { string errorMessage = new Validator() .NotEmpty(txtTimeZoneName.Text, rfvName.ErrorMessage) .NotEmpty(txtTimeZoneDisplayName.Text, rfvDisplayName.ErrorMessage) .NotEmpty(txtTimeZoneGMT.Text, rfvGMT.ErrorMessage) .IsCodeName(txtTimeZoneName.Text, GetString("general.invalidcodename")) .IsDouble(txtTimeZoneGMT.Text, rvGMTDouble.ErrorMessage) .Result; if (chkTimeZoneDaylight.Checked) { if ((!startRuleEditor.IsValid()) || (!endRuleEditor.IsValid())) { errorMessage = GetString("TimeZ.RuleEditor.NotValid"); } } if (String.IsNullOrEmpty(errorMessage)) { // TimeZoneName must to be unique TimeZoneInfo timeZoneObj = TimeZoneInfoProvider.GetTimeZoneInfo(txtTimeZoneName.Text.Trim()); // If timeZoneName value is unique if ((timeZoneObj == null) || (timeZoneObj.TimeZoneID == zoneId)) { // If timeZoneName value is unique -> determine whether it is update or insert if ((timeZoneObj == null)) { // Get TimeZoneInfo object by primary key or create new one timeZoneObj = TimeZoneInfoProvider.GetTimeZoneInfo(zoneId) ?? new TimeZoneInfo(); } timeZoneObj.TimeZoneName = txtTimeZoneName.Text.Trim(); timeZoneObj.TimeZoneDaylight = chkTimeZoneDaylight.Checked; timeZoneObj.TimeZoneDisplayName = txtTimeZoneDisplayName.Text.Trim(); timeZoneObj.TimeZoneRuleStartRule = startRuleEditor.Rule; timeZoneObj.TimeZoneRuleEndRule = endRuleEditor.Rule; timeZoneObj.TimeZoneGMT = Convert.ToDouble(txtTimeZoneGMT.Text.Trim()); TimeZoneInfoProvider.SetTimeZoneInfo(timeZoneObj); URLHelper.Redirect(UrlResolver.ResolveUrl("TimeZone_Edit.aspx?zoneid=" + Convert.ToString(timeZoneObj.TimeZoneID) + "&saved=1")); } else { ShowError(GetString("TimeZ.Edit.TimeZoneNameExists")); } } else { ShowError(errorMessage); } }
/// <summary> /// Gets and updates timezone. Called when the "Get and update timezone" button is pressed. /// Expects the CreateTimezone method to be run first. /// </summary> private bool GetAndUpdateTimezone() { // Get the timezone TimeZoneInfo updateTimezone = TimeZoneInfoProvider.GetTimeZoneInfo("MyNewTimezone"); if (updateTimezone != null) { // Update the properties updateTimezone.TimeZoneDisplayName = updateTimezone.TimeZoneDisplayName.ToLower(); // Save the changes TimeZoneInfoProvider.SetTimeZoneInfo(updateTimezone); return(true); } return(false); }
protected void Page_Load(Object sender, EventArgs e) { // Get parameters selDate = QueryHelper.GetString("selDate", ""); allowEmpty = QueryHelper.GetBoolean("allowempty", false); editTime = QueryHelper.GetBoolean("editTime", false); controlId = QueryHelper.GetText("controlid", ""); SetBrowserClass(); ScriptHelper.RegisterTooltip(Page); // Disable caching Response.Cache.SetCacheability(HttpCacheability.NoCache); pagetitle = GetString("Calendar.Title"); // Fill in the dropdown values if (drpHours.Items.Count == 0) { FillNumbers(drpHours, 0, 23); } if (drpMinutes.Items.Count == 0) { FillNumbers(drpMinutes, 0, 59); } if (drpSeconds.Items.Count == 0) { FillNumbers(drpSeconds, 0, 59); } // Fill in the month selector if (drpMonth.Items.Count == 0) { FillMonths(drpMonth, mCulture); } // Setup the buttons btnCancel.Text = GetString("general.cancel"); btnCancel.Attributes.Add("onclick", "return CloseDialog();"); if (editTime) { btnNow.Text = GetString("Calendar.Now"); } else { btnNow.Text = GetString("Calendar.Today"); } btnOk.Text = GetString("general.ok"); btnNA.Text = GetString("general.na"); btnNA.Attributes.Add("onclick", "CloseWindow(" + ScriptHelper.GetString(controlId) + ", ''); return false;"); if (!RequestHelper.IsPostBack()) { DateTime now = TimeZoneHelper.GetUserDateTime(MembershipContext.AuthenticatedUser); // Selected date if (selDate == "") { SetTime(now, true); } else { SetTime(ValidationHelper.GetDateTime(selDate, now), true); } // Allow empty ? if (!allowEmpty) { btnNA.Visible = false; } else { btnNA.Visible = true; } // Edit time ? if (editTime) { pnlTime.Visible = true; } else { pnlTime.Visible = false; } } // Display time zone in form 'GMT+1:00' int timeZoneId = QueryHelper.GetInteger("timezoneid", 0); if (timeZoneId > 0) { TimeZoneInfo tzi = TimeZoneInfoProvider.GetTimeZoneInfo(timeZoneId); if (tzi != null) { lblGMTShift.Visible = true; lblGMTShift.Text = TimeZoneHelper.GetUTCStringOffset(tzi); ScriptHelper.AppendTooltip(lblGMTShift, TimeZoneHelper.GetUTCLongStringOffset(tzi), "help"); } } // Next and previous month images calDate.NextMonthText = "<img src=\"" + GetImageUrl("Design/Controls/Calendar/next.png") + "\" />"; calDate.PrevMonthText = "<img src=\"" + GetImageUrl("Design/Controls/Calendar/previous.png") + "\" />"; RegisterModalPageScripts(); RegisterEscScript(); }
protected void Page_Load(object sender, EventArgs e) { CurrentMaster.Page.Title = "Time Zone - Edit"; // Set context help CurrentMaster.Title.HelpTopicName = "time_zones_edit"; CurrentMaster.Title.HelpName = "helpTopic"; // Control initialization rfvName.ErrorMessage = GetString("TimeZ.Edit.rfvName"); rfvDisplayName.ErrorMessage = GetString("TimeZ.Edit.rfvDisplayName"); rfvGMT.ErrorMessage = GetString("TimeZ.Edit.rfvGMT"); rvGMTDouble.ErrorMessage = GetString("TimeZ.Edit.rvGMTDouble"); rvGMTDouble.MinimumValue = (-12.0).ToString(); rvGMTDouble.MaximumValue = (13.0).ToString(); string currentTimeZone = GetString("TimeZ.Edit.NewItem"); // Get timeZone id from querystring zoneid = QueryHelper.GetInteger("zoneid", 0); if (zoneid > 0) { TimeZoneInfo timeZoneObj = TimeZoneInfoProvider.GetTimeZoneInfo(zoneid); if (timeZoneObj != null) { currentTimeZone = timeZoneObj.TimeZoneDisplayName; // Fill editing form if (!RequestHelper.IsPostBack()) { LoadData(timeZoneObj); // Show that the timeZone was created or updated successfully if ((ValidationHelper.GetString(Request.QueryString["saved"], "") == "1") && !URLHelper.IsPostback()) { ShowChangesSaved(); } } } } else { plcDSTInfo.Visible = false; } // Initializes page title control string[,] breadcrumbs = new string[2, 3]; breadcrumbs[0, 0] = GetString("TimeZ.Edit.ItemList"); breadcrumbs[0, 1] = "~/CMSModules/TimeZones/Pages/TimeZone_List.aspx"; breadcrumbs[0, 2] = ""; breadcrumbs[1, 0] = currentTimeZone; breadcrumbs[1, 1] = ""; breadcrumbs[1, 2] = ""; CurrentMaster.Title.Breadcrumbs = breadcrumbs; if (QueryHelper.GetString("zoneid", "") != "") { CurrentMaster.Title.TitleText = GetString("timez.edit.properties"); CurrentMaster.Title.TitleImage = GetImageUrl("Objects/CMS_TimeZone/object.png"); } else { CurrentMaster.Title.TitleText = GetString("timez.edit.newtimezone"); CurrentMaster.Title.TitleImage = GetImageUrl("Objects/CMS_TimeZone/new.png"); } startRuleEditor.Enabled = chkTimeZoneDaylight.Checked; endRuleEditor.Enabled = chkTimeZoneDaylight.Checked; }
/// <summary> /// Gets iCalendar file content. /// </summary> /// <param name="row">Datarow</param> protected byte[] GetContent(IDataContainer data, int timeZoneId) { if (data != null) { // Get time zone info for shifting event time to specific time zone TimeZoneInfo tzi = null; if (timeZoneId > 0) { tzi = TimeZoneInfoProvider.GetTimeZoneInfo(timeZoneId); } if ((tzi == null) && (TimeZoneHelper.TimeZonesEnabled())) { // Get time zone for current site tzi = TimeZoneHelper.GetSiteTimeZoneInfo(CMSContext.CurrentSite); } // Get event start time DateTime eventStart = ValidationHelper.GetDateTime(data.GetValue("EventDate"), DataHelper.DATETIME_NOT_SELECTED); // Shift current time to GMT DateTime currentDateGMT = DateTime.Now; currentDateGMT = TimeZoneHelper.ConvertTimeZoneDateTimeToGMT(currentDateGMT, tzi); // Get if it is all day event bool isAllDay = ValidationHelper.GetBoolean(data.GetValue("EventAllDay"), false); // Create content StringBuilder content = new StringBuilder(); content.AppendLine("BEGIN:vCalendar"); content.AppendLine("METHOD:PUBLISH"); content.AppendLine("BEGIN:vEvent"); content.Append("DTSTAMP:").Append(currentDateGMT.ToString("yyyyMMdd'T'HHmmss")).AppendLine("Z"); content.Append("DTSTART"); if (isAllDay) { content.Append(";VALUE=DATE:").AppendLine(eventStart.ToString("yyyyMMdd")); } else { // Shift event start time to GMT eventStart = TimeZoneHelper.ConvertTimeZoneDateTimeToGMT(eventStart, tzi); content.Append(":").Append(eventStart.ToString("yyyyMMdd'T'HHmmss")).AppendLine("Z"); } // Get event end time DateTime eventEnd = ValidationHelper.GetDateTime(data.GetValue("EventEndDate"), DataHelper.DATETIME_NOT_SELECTED); if (eventEnd != DataHelper.DATETIME_NOT_SELECTED) { content.Append("DTEND"); if (isAllDay) { content.Append(";VALUE=DATE:").AppendLine(eventEnd.AddDays(1).ToString("yyyyMMdd")); } else { // Shift event end time to GMT eventEnd = TimeZoneHelper.ConvertTimeZoneDateTimeToGMT(eventEnd, tzi); content.Append(":").Append(eventEnd.ToString("yyyyMMdd'T'HHmmss")).AppendLine("Z"); } } // Get location string location = ValidationHelper.GetString(data.GetValue("EventLocation"), string.Empty); // Include location if specified if (!String.IsNullOrEmpty(location)) { content.Append("LOCATION:").AppendLine(HTMLHelper.StripTags(HttpUtility.HtmlDecode(location))); } content.Append("DESCRIPTION:").AppendLine(HTMLHelper.StripTags(HttpUtility.HtmlDecode(ValidationHelper.GetString(data.GetValue("EventDetails"), "")).Replace("\r\n", "").Replace("<br />", "\\n")) + "\\n\\n" + HTMLHelper.StripTags(HttpUtility.HtmlDecode(ValidationHelper.GetString(data.GetValue("EventLocation"), "")).Replace("\r\n", "").Replace("<br />", "\\n"))); content.Append("SUMMARY:").AppendLine(HttpUtility.HtmlDecode(ValidationHelper.GetString(data.GetValue("EventName"), ""))); content.AppendLine("PRIORITY:3"); content.AppendLine("BEGIN:vAlarm"); content.AppendLine("TRIGGER:P0DT0H15M"); content.AppendLine("ACTION:DISPLAY"); content.AppendLine("DESCRIPTION:Reminder"); content.AppendLine("END:vAlarm"); content.AppendLine("END:vEvent"); content.AppendLine("END:vCalendar"); // Return byte array return(Encoding.UTF8.GetBytes(content.ToString())); } return(null); }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { string errorMessage = new Validator() .NotEmpty(txtTimeZoneName.Text, rfvName.ErrorMessage) .NotEmpty(txtTimeZoneDisplayName.Text, rfvDisplayName.ErrorMessage) .NotEmpty(txtTimeZoneGMT.Text, rfvGMT.ErrorMessage) .IsCodeName(txtTimeZoneName.Text, GetString("general.invalidcodename")) .IsDouble(txtTimeZoneGMT.Text, rvGMTDouble.ErrorMessage) .Result; if (this.chkTimeZoneDaylight.Checked) { if ((!this.startRuleEditor.IsValid()) || (!this.endRuleEditor.IsValid())) { errorMessage = GetString("TimeZ.RuleEditor.NotValid"); } } if (errorMessage == "") { // timeZoneName must to be unique TimeZoneInfo timeZoneObj = TimeZoneInfoProvider.GetTimeZoneInfo(txtTimeZoneName.Text.Trim()); // if timeZoneName value is unique if ((timeZoneObj == null) || (timeZoneObj.TimeZoneID == zoneid)) { // if timeZoneName value is unique -> determine whether it is update or insert if ((timeZoneObj == null)) { // get TimeZoneInfo object by primary key timeZoneObj = TimeZoneInfoProvider.GetTimeZoneInfo(zoneid); if (timeZoneObj == null) { // create new item -> insert timeZoneObj = new TimeZoneInfo(); } } timeZoneObj.TimeZoneName = txtTimeZoneName.Text.Trim(); timeZoneObj.TimeZoneDaylight = chkTimeZoneDaylight.Checked; timeZoneObj.TimeZoneDisplayName = txtTimeZoneDisplayName.Text.Trim(); timeZoneObj.TimeZoneRuleStartIn = ValidationHelper.GetDateTime(TimeZoneInfoProvider.CreateRuleDateTime(this.startRuleEditor.Rule), DateTime.Now); timeZoneObj.TimeZoneRuleEndIn = ValidationHelper.GetDateTime(TimeZoneInfoProvider.CreateRuleDateTime(this.endRuleEditor.Rule), DateTime.Now); timeZoneObj.TimeZoneRuleStartRule = this.startRuleEditor.Rule; timeZoneObj.TimeZoneRuleEndRule = this.endRuleEditor.Rule; timeZoneObj.TimeZoneGMT = Convert.ToDouble(txtTimeZoneGMT.Text.Trim()); TimeZoneInfoProvider.SetTimeZoneInfo(timeZoneObj); URLHelper.Redirect("TimeZone_Edit.aspx?zoneid=" + Convert.ToString(timeZoneObj.TimeZoneID) + "&saved=1"); } else { lblError.Visible = true; lblError.Text = GetString("TimeZ.Edit.TimeZoneNameExists"); } } else { lblError.Visible = true; lblError.Text = errorMessage; } }