Example #1
0
        /// <summary>
        /// This handles the Add command for the recurrence data grid
        /// </summary>
        /// <param name="source">The source of the event</param>
        /// <param name="e">The event arguments</param>
        protected void dgRecurrences_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            if (e.CommandName == "Add")
            {
                // Save changes to the edited item if there is one
                if (dgRecurrences.EditItemIndex != -1)
                {
                    dgRecurrences_UpdateCommand(source, new DataGridCommandEventArgs(
                                                    dgRecurrences.Items[dgRecurrences.EditItemIndex], e.CommandSource, e));
                }

                // Ignore the request if the page is not valid
                if (!Page.IsValid)
                {
                    return;
                }

                // Add a new recurrence and go into edit mode on it
                RecurringObject ro = GetCurrentObject();

                RRuleProperty rrule = new RRuleProperty();
                rrule.Recurrence.RecurDaily(1);
                ro.RecurrenceRules.Add(rrule);

                dgRecurrences.EditItemIndex = ro.RecurrenceRules.Count - 1;
                dgRecurrences.DataSource    = ro.RecurrenceRules;
                dgRecurrences.DataBind();
            }
        }
Example #2
0
        //=====================================================================

        /// <summary>
        /// Add a recurrence rule
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event parameters</param>
        private void btnAddRRule_Click(object sender, EventArgs e)
        {
            using (RecurrencePropertiesDlg dlg = new RecurrencePropertiesDlg())
            {
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    // Add the recurrence rule to the collection and the list box using the appropriate type
                    if (!editsExceptions)
                    {
                        RRuleProperty rr = new RRuleProperty();
                        dlg.GetRecurrence(rr.Recurrence);
                        rRules.Add(rr);
                        lbRRules.Items.Add(rr.Recurrence.ToString());
                    }
                    else
                    {
                        ExRuleProperty er = new ExRuleProperty();
                        dlg.GetRecurrence(er.Recurrence);
                        rRules.Add(er);
                        lbRRules.Items.Add(er.Recurrence.ToString());
                    }
                }
            }

            this.SetButtonStates();
        }
Example #3
0
        //=====================================================================

        /// <summary>
        /// This is overridden to allow cloning of a PDI object
        /// </summary>
        /// <returns>A clone of the object</returns>
        public override object Clone()
        {
            RRuleProperty o = new RRuleProperty();

            o.Clone(this);
            return(o);
        }
Example #4
0
        //=====================================================================

        /// <summary>
        /// This is used to load the VCalendar.TimeZones collection with time zone information from the registry
        /// </summary>
        public static void LoadTimeZoneInfo()
        {
            string   keyName, display, standardDesc, dstDesc;
            TIMEZONE tz;

            VCalendar.TimeZones.Clear();

            // To keep things simple, we'll load the time zone data from the settings available in the registry.
            // We could take it a step further and load it from something like a copy of the Olson time zone
            // database but I haven't been that ambitious yet.
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                keyName = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones";
            }
            else
            {
                keyName = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Time Zones";
            }

            using (var rk = Registry.LocalMachine.OpenSubKey(keyName))
            {
                foreach (string s in rk.GetSubKeyNames())
                {
                    using (var rsk = rk.OpenSubKey(s))
                    {
                        display      = (string)rsk.GetValue("Display");
                        standardDesc = (string)rsk.GetValue("Std");
                        dstDesc      = (string)rsk.GetValue("Dlt");
                        tz           = TIMEZONE.FromRegistry(rsk.GetValue("TZI"));
                    }

                    // Create the time zone object
                    VTimeZone vtz = new VTimeZone();
                    vtz.TimeZoneId.Value = display;

                    ObservanceRule or = vtz.ObservanceRules.Add(ObservanceRuleType.Standard);

                    or.OffsetFrom.TimeSpanValue = TimeSpan.FromMinutes(tz.nBias + tz.nDaylightBias).Negate();
                    or.OffsetTo.TimeSpanValue   = TimeSpan.FromMinutes(tz.nBias + tz.nStandardBias).Negate();
                    or.TimeZoneNames.Add(standardDesc);

                    // If the standard date month is zero, it doesn't use standard time.  Assume 01/01/1970 and
                    // set it up to return the offset.
                    if (tz.standardDate.wMonth == 0)
                    {
                        or.StartDateTime.DateTimeValue = new DateTime(1970, 1, 1);
                    }
                    else
                    {
                        // If year is zero, its a recurrence.  If not zero, it's a fixed date.
                        if (tz.standardDate.wYear == 0)
                        {
                            or.StartDateTime.DateTimeValue = tz.standardDate.ToDateTime(1970);

                            RRuleProperty rrule = new RRuleProperty();

                            rrule.Recurrence.RecurYearly(
                                (tz.standardDate.wDay > 4) ? DayOccurrence.Last : (DayOccurrence)tz.standardDate.wDay,
                                tz.standardDate.DayOfWeek(), tz.standardDate.wMonth, 1);

                            or.RecurrenceRules.Add(rrule);
                        }
                        else
                        {
                            or.StartDateTime.DateTimeValue = tz.standardDate.ToDateTime();
                            or.RecurDates.Add(or.StartDateTime.DateTimeValue);
                        }
                    }

                    // If the daylight month is zero, it doesn't use DST.  The standard rule will handle
                    // everything.
                    if (tz.daylightDate.wMonth != 0)
                    {
                        or = vtz.ObservanceRules.Add(ObservanceRuleType.Daylight);

                        or.OffsetFrom.TimeSpanValue = TimeSpan.FromMinutes(tz.nBias + tz.nStandardBias).Negate();
                        or.OffsetTo.TimeSpanValue   = TimeSpan.FromMinutes(tz.nBias + tz.nDaylightBias).Negate();
                        or.TimeZoneNames.Add(dstDesc);

                        // If year is zero, its a recurrence.  If not zero, it's a fixed date.
                        if (tz.daylightDate.wYear == 0)
                        {
                            or.StartDateTime.DateTimeValue = tz.daylightDate.ToDateTime(1970);

                            RRuleProperty rrule = new RRuleProperty();

                            rrule.Recurrence.RecurYearly(
                                (tz.daylightDate.wDay > 4) ? DayOccurrence.Last : (DayOccurrence)tz.daylightDate.wDay,
                                tz.daylightDate.DayOfWeek(), tz.daylightDate.wMonth, 1);

                            or.RecurrenceRules.Add(rrule);
                        }
                        else
                        {
                            or.StartDateTime.DateTimeValue = tz.daylightDate.ToDateTime();
                            or.RecurDates.Add(or.StartDateTime.DateTimeValue);
                        }
                    }

                    VCalendar.TimeZones.Add(vtz);
                }
            }

            // Put the time zones in sorted order
            VCalendar.TimeZones.Sort(true);
        }
Example #5
0
        //=====================================================================

        /// <summary>
        /// This is overridden to allow cloning of a PDI object
        /// </summary>
        /// <returns>A clone of the object</returns>
        public override object Clone()
        {
            RRuleProperty o = new RRuleProperty();
            o.Clone(this);
            return o;
        }