Ejemplo 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);
    }
    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;
    }
Ejemplo n.º 3
0
    /// <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);
        }
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Sets connection string, inits application and finalizes the database data (macro signatures, time zones, license).
    /// </summary>
    private void FinalizeDBInstallation()
    {
        SetAppConnectionString();

        UpdateMacroSignatures();

        // Recalculate time zone daylight saving start and end.
        TimeZoneInfoProvider.GenerateTimeZoneRules();

        CheckLicense();
    }
Ejemplo n.º 6
0
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void uniGrid_OnAction(string actionName, object actionArgument)
    {
        switch (actionName)
        {
        case "edit":
            URLHelper.Redirect("TimeZone_Edit.aspx?zoneid=" + Convert.ToString(actionArgument));
            break;

        case "delete":
            TimeZoneInfoProvider.DeleteTimeZoneInfo(Convert.ToInt32(actionArgument));
            break;
        }
    }
Ejemplo n.º 7
0
    /// <summary>
    /// Procedures which automatically imports the upgrade export package with all WebParts, Widgets, Reports and TimeZones.
    /// </summary>
    private static void UpgradeImportPackage()
    {
        // Import
        try
        {
            RequestStockHelper.Remove("CurrentDomain", true);

            var importSettings = new SiteImportSettings(MembershipContext.AuthenticatedUser)
            {
                DefaultProcessObjectType = ProcessObjectEnum.All,
                SourceFilePath           = mUpgradePackagePath,
                WebsitePath = mWebsitePath
            };

            using (var context = new CMSActionContext())
            {
                context.DisableLogging();
                context.CreateVersion  = false;
                context.LogIntegration = false;

                ImportProvider.ImportObjectsData(importSettings);

                // Regenerate time zones
                TimeZoneInfoProvider.GenerateTimeZoneRules();

                // Delete the files for separable modules which are not install and therefore not needed
                DeleteWebPartsOfUninstalledModules();

                ImportMetaFiles(Path.Combine(mWebsitePath, "App_Data\\CMSTemp\\Upgrade"));
            }
        }
        catch (Exception ex)
        {
            EventLogProvider.LogException(EVENT_LOG_INFO, "Upgrade", ex);
        }
        finally
        {
            try
            {
                RefreshMacroSignatures();

                EventLogProvider.LogInformation(EVENT_LOG_INFO, "Upgrade - Finish");
            }
            catch (Exception ex)
            {
                EventLogProvider.LogException(EVENT_LOG_INFO, "Upgrade", ex);
            }
        }
    }
Ejemplo n.º 8
0
    /// <summary>
    /// Fills dropdownlist with values and realoades it.
    /// </summary>
    public void ReloadData()
    {
        drpTimeZoneTypeSelector.Items.Clear();
        DataHelper.FillListControlWithEnum(typeof(TimeZoneTypeEnum), drpTimeZoneTypeSelector, "timez.type", TimeZoneInfoProvider.GetTimeZoneTypeString);

        string tmp = TimeZoneInfoProvider.GetTimeZoneTypeString(TimeZoneType);

        if (drpTimeZoneTypeSelector.Items.FindByValue(tmp) != null)
        {
            drpTimeZoneTypeSelector.SelectedValue = tmp;
        }
        else
        {
            drpTimeZoneTypeSelector.SelectedValue = null;
            TimeZoneType = TimeZoneTypeEnum.Inherit;
        }
    }
Ejemplo n.º 9
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);
    }
Ejemplo n.º 10
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);
    }
Ejemplo n.º 11
0
    /// <summary>
    /// Fill drop down list.
    /// </summary>
    /// <param name="ds">Data set with time zones</param>
    /// <param name="dataValue">Data value field</param>
    private void FillDropdown(string dataValue)
    {
        if (drpTimeZoneSelector.Items.Count == 0)
        {
            DataSet ds = TimeZoneInfoProvider.GetTimeZones(null, "TimeZoneGMT", -1, "TimeZoneID ,TimeZoneGMT, TimeZoneName, TimeZoneDisplayName");

            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                string text = null;

                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    text = String.Format("(UTC{0:+00.00;-00.00}) {1}", row["TimeZoneGMT"], row["TimeZoneDisplayName"]);
                    drpTimeZoneSelector.Items.Add(new ListItem(text, row[dataValue].ToString()));
                }
            }

            // Add none record if needed
            if (AddNoneItemsRecord)
            {
                drpTimeZoneSelector.Items.Insert(0, new ListItem(GetString("General.SelectNone"), ""));
            }
        }
    }
Ejemplo n.º 12
0
    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();
    }
Ejemplo n.º 13
0
    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;
    }
    private static void Upgrade60Import()
    {
        EventLogProvider evp = new EventLogProvider();

        // Import
        try
        {
            RequestStockHelper.Remove("CurrentDomain", true);

            SiteImportSettings importSettings = new SiteImportSettings(CMSContext.CurrentUser)
            {
                DefaultProcessObjectType = ProcessObjectEnum.All,
                SourceFilePath           = mUpgradePackagePath,
                WebsitePath = mWebsitePath
            };

            ImportProvider.ImportObjectsData(importSettings);

            // Regenerate time zones
            TimeZoneInfoProvider.GenerateTimeZoneRules();

            #region "Separability"

            String        webPartsPath = mWebsitePath + "CMSWebParts\\";
            List <String> files        = new List <string>();
            // Create list of files to remove
            if (!ModuleEntry.IsModuleLoaded(ModuleEntry.BIZFORM))
            {
                files.AddRange(GetAllFiles(webPartsPath + "BizForms"));
            }
            if (!ModuleEntry.IsModuleLoaded(ModuleEntry.BLOGS))
            {
                files.AddRange(GetAllFiles(webPartsPath + "Blogs"));
            }
            if (!ModuleEntry.IsModuleLoaded(ModuleEntry.COMMUNITY))
            {
                files.AddRange(GetAllFiles(webPartsPath + "Community"));
            }
            if (!ModuleEntry.IsModuleLoaded(ModuleEntry.ECOMMERCE))
            {
                files.AddRange(GetAllFiles(webPartsPath + "Ecommerce"));
            }
            if (!ModuleEntry.IsModuleLoaded(ModuleEntry.EVENTMANAGER))
            {
                files.AddRange(GetAllFiles(webPartsPath + "Events"));
            }
            if (!ModuleEntry.IsModuleLoaded(ModuleEntry.FORUMS))
            {
                files.AddRange(GetAllFiles(webPartsPath + "Forums"));
            }
            if (!ModuleEntry.IsModuleLoaded(ModuleEntry.MEDIALIBRARY))
            {
                files.AddRange(GetAllFiles(webPartsPath + "MediaLibrary"));
            }
            if (!ModuleEntry.IsModuleLoaded(ModuleEntry.MESSAGEBOARD))
            {
                files.AddRange(GetAllFiles(webPartsPath + "MessageBoards"));
            }
            if (!ModuleEntry.IsModuleLoaded(ModuleEntry.MESSAGING))
            {
                files.AddRange(GetAllFiles(webPartsPath + "Messaging"));
            }
            if (!ModuleEntry.IsModuleLoaded(ModuleEntry.NEWSLETTER))
            {
                files.AddRange(GetAllFiles(webPartsPath + "Newsletters"));
            }
            if (!ModuleEntry.IsModuleLoaded(ModuleEntry.NOTIFICATIONS))
            {
                files.AddRange(GetAllFiles(webPartsPath + "Notifications"));
            }
            if (!ModuleEntry.IsModuleLoaded(ModuleEntry.ONLINEMARKETING))
            {
                files.AddRange(GetAllFiles(webPartsPath + "OnlineMarketing"));
            }
            if (!ModuleEntry.IsModuleLoaded(ModuleEntry.POLLS))
            {
                files.AddRange(GetAllFiles(webPartsPath + "Polls"));
            }
            if (!ModuleEntry.IsModuleLoaded(ModuleEntry.PROJECTMANAGEMENT))
            {
                files.AddRange(GetAllFiles(webPartsPath + "ProjectManagement"));
            }
            if (!ModuleEntry.IsModuleLoaded(ModuleEntry.REPORTING))
            {
                files.AddRange(GetAllFiles(webPartsPath + "Reporting"));
            }

            // Remove webparts for separated modules
            foreach (String file in files)
            {
                try
                {
                    File.Delete(file);
                }
                catch (Exception ex)
                {
                    evp.LogEvent("Upgrade to 6.0", "Upgrade", ex);
                }
            }

            #endregion

            evp.LogEvent("I", DateTime.Now, "Upgrade to 6.0", "Upgrade - Finish");
        }
        catch (Exception ex)
        {
            evp.LogEvent("Upgrade to 6.0", "Upgrade", ex);
        }
    }
Ejemplo n.º 15
0
    /// <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);
    }
Ejemplo n.º 16
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;
        }
    }