/// <summary> /// Creates timezone. Called when the "Create timezone" button is pressed. /// </summary> private bool CreateTimezone() { // Create new timezone object TimeZoneInfo newTimezone = new TimeZoneInfo(); // Set the properties newTimezone.TimeZoneDisplayName = "My new timezone"; newTimezone.TimeZoneName = "MyNewTimezone"; newTimezone.TimeZoneGMT = -12; newTimezone.TimeZoneDaylight = true; newTimezone.TimeZoneRuleStartRule = "MAR|SUN|1|LAST|3|0|1"; newTimezone.TimeZoneRuleEndRule = "OCT|SUN|1|LAST|3|0|0"; newTimezone.TimeZoneRuleStartIn = TimeZoneInfoProvider.CreateRuleDateTime(newTimezone.TimeZoneRuleStartRule); newTimezone.TimeZoneRuleEndIn = TimeZoneInfoProvider.CreateRuleDateTime(newTimezone.TimeZoneRuleEndRule); // Save the timezone TimeZoneInfoProvider.SetTimeZoneInfo(newTimezone); return(true); }
/// <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 (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(startRuleEditor.Rule), DateTime.Now); timeZoneObj.TimeZoneRuleEndIn = ValidationHelper.GetDateTime(TimeZoneInfoProvider.CreateRuleDateTime(endRuleEditor.Rule), DateTime.Now); timeZoneObj.TimeZoneRuleStartRule = startRuleEditor.Rule; timeZoneObj.TimeZoneRuleEndRule = 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 { ShowError(GetString("TimeZ.Edit.TimeZoneNameExists")); } } else { ShowError(errorMessage); } }