Esempio n. 1
0
    /// <summary>
    /// Gets and bulk updates timezones. Called when the "Get and bulk update timezones" button is pressed.
    /// Expects the CreateTimezone method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateTimezones()
    {
        // Prepare the parameters
        string where = "TimeZoneName LIKE N'MyNewTimezone%'";

        // Get the data
        DataSet timezones = TimeZoneInfoProvider.GetTimeZones(where, null);

        if (!DataHelper.DataSourceIsEmpty(timezones))
        {
            // Loop through the individual items
            foreach (DataRow timezoneDr in timezones.Tables[0].Rows)
            {
                // Create object from DataRow
                TimeZoneInfo modifyTimezone = new TimeZoneInfo(timezoneDr);

                // Update the properties
                modifyTimezone.TimeZoneDisplayName = modifyTimezone.TimeZoneDisplayName.ToUpper();

                // Save the changes
                TimeZoneInfoProvider.SetTimeZoneInfo(modifyTimezone);
            }

            return(true);
        }

        return(false);
    }
    /// <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);
        }
    }
Esempio n. 3
0
    /// <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);
    }
Esempio n. 4
0
    /// <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);
    }
Esempio n. 5
0
    /// <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;
        }
    }