Beispiel #1
0
        /// <summary>
        /// When the user selects another entry on the left listbox, we update the labels below.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lbEntries_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lbEntries.SelectedIndex == -1)
            {
                lblEntryDescription.Text = "";
                return;
            }

            ScheduleEntry temp       = lbEntriesData[lbEntries.SelectedIndex];
            string        label_text = "Title: " + temp.Title;

            // Simple entry ?
            if (temp is SimpleScheduleEntry)
            {
                SimpleScheduleEntry x = (SimpleScheduleEntry)temp;
                label_text += "\nOne Off Entry\n Start: " + x.StartDate + "\n End: " + x.EndDate + "\n Expired: " + x.Expired;
                label_text += "\n\n Options\n  Blocking: " + ((x.Options & ScheduleEntryOptions.Blocking) != ScheduleEntryOptions.None);
                label_text += "\n  Silent: " + ((x.Options & ScheduleEntryOptions.Quiet) != ScheduleEntryOptions.None);
                label_text += "\n  Uses Eve Time: " + ((x.Options & ScheduleEntryOptions.EVETime) != ScheduleEntryOptions.None);
            }
            // Or recurring entry ?
            else
            {
                RecurringScheduleEntry x = (RecurringScheduleEntry)temp;
                label_text += "\nRecurring Entry:\n Start: " + x.StartDate + "\n End: " + x.EndDate + "\n Frequency: " + x.Frequency;
                if (x.Frequency == RecurringFrequency.Monthly)
                {
                    label_text += "\n  Day of Month: " + x.DayOfMonth + "\n  On Overflow: " + x.OverflowResolution;
                }
                else if (x.Frequency == RecurringFrequency.Weekly)
                {
                    DateTime nowish   = DateTime.Now.Date;
                    DateTime Initial  = x.StartDate.AddDays((x.DayOfWeek - x.StartDate.DayOfWeek + 7) % 7);
                    Double   datediff = ((7 * x.WeeksPeriod) - (nowish.Subtract(Initial).Days % (7 * x.WeeksPeriod))) % (7 * x.WeeksPeriod);
                    if (((nowish.AddDays(datediff)).Add(TimeSpan.FromSeconds(x.StartTimeInSeconds))) < DateTime.Now)
                    {
                        datediff = datediff + (7 * x.WeeksPeriod);
                    }
                    label_text += "\n  Day of Week: " + x.DayOfWeek + "\n  Every: " + x.WeeksPeriod + " weeks\n  Next: " + (nowish.AddDays(datediff)).Add(TimeSpan.FromSeconds(x.StartTimeInSeconds));
                }
                if (x.EndTimeInSeconds > 86400)
                {
                    x.EndTimeInSeconds -= 86400;
                }
                label_text += "\n Start Time: " + TimeSpan.FromSeconds(x.StartTimeInSeconds).ToString() + "\n End Time: " + TimeSpan.FromSeconds(x.EndTimeInSeconds).ToString() + "\n Expired: " + x.Expired;
                label_text += "\n Options\n  Blocking: " + ((x.Options & ScheduleEntryOptions.Blocking) != 0);
                label_text += "\n  Silent: " + ((x.Options & ScheduleEntryOptions.Quiet) != 0);
                label_text += "\n  Uses Eve Time: " + ((x.Options & ScheduleEntryOptions.EVETime) != 0);
            }

            // Update the description
            lblEntryDescription.Text = label_text;
        }
Beispiel #2
0
        /// <summary>
        /// Generates the schedule entry.
        /// </summary>
        /// <returns></returns>
        private ScheduleEntry GenerateScheduleEntry()
        {
            ScheduleEntry result = null;

            if (rbOneTime.Checked)
            {
                SimpleScheduleEntry sse = new SimpleScheduleEntry
                {
                    StartDate = new DateTime(
                        m_oneTimeStartDate.AddSeconds(m_oneTimeStartTime).Ticks,
                        DateTimeKind.Unspecified),
                    EndDate = new DateTime(
                        m_oneTimeEndDate.AddSeconds(m_oneTimeEndTime).Ticks,
                        DateTimeKind.Unspecified)
                };

                result = sse;
            }
            else if (rbRecurring.Checked)
            {
                RecurringScheduleEntry rse = new RecurringScheduleEntry
                {
                    StartDate          = m_recurringDateFrom,
                    EndDate            = m_recurringDateTo,
                    StartTimeInSeconds = m_recurringStartTime,
                    EndTimeInSeconds   = m_recurringEndTime,
                    DayOfMonth         = Convert.ToInt32(nudRecurDayOfMonth.Value),
                    OverflowResolution = GetRecurringOverflowDropdown(),
                    Frequency          = GetRecurringFrequencyDropdown(),
                    DayOfWeek          = GetRecurringFrequencyDayOfWeek()
                };

                if (rse.Frequency == RecurringFrequency.Weekly)
                {
                    rse.WeeksPeriod = Convert.ToInt32(nudWeeklyFrequency.Value);
                }

                result = rse;
            }

            if (result == null)
            {
                return(null);
            }

            result.Title   = tbTitle.Text;
            result.Options = GetTypeFlags();

            return(result);
        }
Beispiel #3
0
        private ScheduleEntry GenerateScheduleEntry()
        {
            ScheduleEntry result = null;

            if (rbOneTime.Checked)
            {
                SimpleScheduleEntry sse = new SimpleScheduleEntry();
                sse.StartDate = new DateTime(
                    (m_oneTimeStartDate + TimeSpan.FromSeconds(m_oneTimeStartTime)).Ticks, DateTimeKind.Unspecified);
                sse.EndDate = new DateTime(
                    (m_oneTimeEndDate + TimeSpan.FromSeconds(m_oneTimeEndTime)).Ticks, DateTimeKind.Unspecified);

                result = sse;
            }
            else if (rbRecurring.Checked)
            {
                RecurringScheduleEntry rse = new RecurringScheduleEntry();
                rse.StartDate = m_recurringDateFrom;
                rse.EndDate   = m_recurringDateTo;
                DayOfWeek dow = DayOfWeek.Monday;
                rse.Frequency = GetRecurringFrequencyDropdown(ref dow);
                rse.DayOfWeek = dow;
                if (rse.Frequency == RecurringFrequency.Weekly)
                {
                    rse.WeeksPeriod = Convert.ToInt32(nudWeeklyFrequency.Value);
                }
                rse.DayOfMonth         = Convert.ToInt32(nudRecurDayOfMonth.Value);
                rse.OverflowResolution = GetRecurringOverflowDropdown();
                rse.StartTimeInSeconds = m_recurringStartTime;
                rse.EndTimeInSeconds   = m_recurringEndTime;
                result = rse;
            }

            if (result != null)
            {
                result.Title   = tbTitle.Text;
                result.Options = GetTypeFlags();
            }

            return(result);
        }
Beispiel #4
0
        /// <summary>
        /// Updates from entry.
        /// </summary>
        private void UpdateFromEntry()
        {
            if (m_scheduleEntry == null)
            {
                return;
            }

            tbTitle.Text = m_scheduleEntry.Title;
            SetTypeFlags(m_scheduleEntry.Options);

            SimpleScheduleEntry    sse = m_scheduleEntry as SimpleScheduleEntry;
            RecurringScheduleEntry rse = m_scheduleEntry as RecurringScheduleEntry;

            if (sse != null)
            {
                rbOneTime.Checked   = true;
                rbRecurring.Checked = false;
                SetOneTimeStartDate(sse.StartDate);
                tbOneTimeStartTime.Text = sse.StartDate.ToShortTimeString();
                SetOneTimeEndDate(sse.EndDate);
                tbOneTimeEndTime.Text = sse.EndDate.ToShortTimeString();
            }
            else if (rse != null)
            {
                rbOneTime.Checked   = false;
                rbRecurring.Checked = true;
                SetRecurringDateFrom(rse.StartDate);
                SetRecurringDateTo(rse.EndDate);
                SetRecurringFrequencyDropdown(rse.Frequency, rse.DayOfWeek, rse.WeeksPeriod);
                nudRecurDayOfMonth.Value = rse.DayOfMonth;
                SetRecurringOverflowDropdown(rse.OverflowResolution);
                DateTime tstart = DateTime.Today.AddSeconds(rse.StartTimeInSeconds);
                DateTime tend   = DateTime.Today.AddSeconds(rse.EndTimeInSeconds);
                tbRecurringTimeFrom.Text = tstart.ToShortTimeString();
                tbRecurringTimeTo.Text   = tend.ToShortTimeString();
            }

            ValidateData();
        }
        /// <summary>
        /// Shows a tooltip enumerating all of entries for this day
        /// </summary>
        /// <param name="datetime"></param>
        private void ShowCalendarTooltip(DateTime datetime)
        {
            // How can you only localize the date?
            StringBuilder content = new StringBuilder();

            foreach (ScheduleEntry entry in Scheduler.Entries.Where(x => x.IsToday(datetime)).OrderBy(x => x.Title))
            {
                DateTime from = datetime;
                DateTime to   = datetime;

                // Simple entry ?
                if (entry is SimpleScheduleEntry)
                {
                    SimpleScheduleEntry simple = (SimpleScheduleEntry)entry;

                    from = simple.StartDate;
                    to   = simple.EndDate;
                }
                // Or recurring entry ?
                else
                {
                    RecurringScheduleEntry recurring = (RecurringScheduleEntry)entry;

                    // Does this always have one entry?
                    IEnumerable <ScheduleDateTimeRange> ranges     = recurring.GetRangesInPeriod(new DateTime(datetime.Year, datetime.Month, datetime.Day, 0, 0, 0), new DateTime(datetime.Year, datetime.Month, datetime.Day, 23, 59, 59));
                    IEnumerator <ScheduleDateTimeRange> enumranges = ranges.GetEnumerator();
                    while (enumranges.MoveNext())
                    {
                        ScheduleDateTimeRange r = enumranges.Current;
                        from = r.From;
                        to   = r.To;
                    }
                }

                // If the "from" date is before the selected date
                if (!(from.Year == datetime.Year && from.Month == datetime.Month && from.Day == datetime.Day))
                {
                    // Set date to midnight today
                    from = new DateTime(datetime.Year, datetime.Month, datetime.Day, 0, 0, 0);
                }

                // If the "to" date is after the selected date
                if (!(to.Year == datetime.Year && to.Month == datetime.Month && to.Day == datetime.Day))
                {
                    // Set date to last second before tomorrows midnight
                    to = new DateTime(datetime.Year, datetime.Month, datetime.Day, 23, 59, 59);
                }

                // Append the tooltip content
                content.Append(entry.Title);

                if ((entry.Options & ScheduleEntryOptions.EVETime) != ScheduleEntryOptions.None)
                {
                    // In case local time conversion extends beyond the entry date,
                    // we display also the ending date
                    var toLocalTime = (to.Day == to.ToLocalTime().Day ?
                                       to.ToLocalTime().ToString("HH:mm") : to.ToLocalTime().ToString());

                    content.AppendFormat(" [ EVE Time: {0} - {1} ] ", from.ToString("HH:mm"), to.ToString("HH:mm"));
                    content.AppendFormat(" [ Local Time: {0} - {1} ] ", from.ToLocalTime().ToString("HH:mm"), toLocalTime);
                }
                else
                {
                    content.AppendFormat(" [ {0} - {1} ] ", from.ToString("HH:mm"), to.ToString("HH:mm"));
                }
                content.AppendLine();
            }

            m_tooltip.ToolTipTitle = String.Format(CultureConstants.DefaultCulture, "Entries for {0}", datetime.ToString("d"));
            m_tooltip.SetToolTip(calControl, content.ToString());
            m_tooltip.Active = true;
        }
        /// <summary>
        /// Update the entry's description
        /// </summary>
        private void UpdateEntryDescription()
        {
            ScheduleEntry temp = lbEntriesData[lbEntries.SelectedIndex];
            StringBuilder sb   = new StringBuilder();

            sb.AppendFormat("Title: {0}", temp.Title).AppendLine();

            // Simple entry ?
            if (temp is SimpleScheduleEntry)
            {
                SimpleScheduleEntry simpleEntry = (SimpleScheduleEntry)temp;

                sb.AppendLine("One Off Entry");
                sb.AppendFormat(CultureConstants.DefaultCulture, " Start: {0}", simpleEntry.StartDate).AppendLine();
                sb.AppendFormat(CultureConstants.DefaultCulture, " End: {0}", simpleEntry.EndDate).AppendLine();
                sb.AppendFormat(CultureConstants.DefaultCulture, " Expired: {0}", simpleEntry.Expired).AppendLine();
                sb.AppendLine();
                sb.AppendLine("Options");
                sb.AppendFormat(CultureConstants.DefaultCulture, " Blocking: {0}",
                                (simpleEntry.Options & ScheduleEntryOptions.Blocking) != ScheduleEntryOptions.None).AppendLine();
                sb.AppendFormat(CultureConstants.DefaultCulture, " Silent: {0}",
                                (simpleEntry.Options & ScheduleEntryOptions.Quiet) != ScheduleEntryOptions.None).AppendLine();
                sb.AppendFormat(CultureConstants.DefaultCulture, " Uses Eve Time: {0}",
                                (simpleEntry.Options & ScheduleEntryOptions.EVETime) != ScheduleEntryOptions.None).AppendLine();
            }
            // Or recurring entry ?
            else
            {
                RecurringScheduleEntry recurringEntry = (RecurringScheduleEntry)temp;

                sb.AppendLine("Recurring Entry");
                sb.AppendFormat(CultureConstants.DefaultCulture, " Start: {0}",
                                recurringEntry.StartDate.ToShortDateString()).AppendLine();
                sb.AppendFormat(CultureConstants.DefaultCulture, " End: {0}",
                                recurringEntry.EndDate.ToShortDateString()).AppendLine();
                sb.AppendFormat(CultureConstants.DefaultCulture, " Frequency: {0}",
                                recurringEntry.Frequency).AppendLine();

                if (recurringEntry.Frequency == RecurringFrequency.Monthly)
                {
                    sb.AppendFormat(CultureConstants.DefaultCulture, "  Day of Month: {0}", recurringEntry.DayOfMonth).AppendLine();
                    sb.AppendFormat(CultureConstants.DefaultCulture, "  On Overflow: {0}", recurringEntry.OverflowResolution).AppendLine();
                }
                else if (recurringEntry.Frequency == RecurringFrequency.Weekly)
                {
                    DateTime nowish   = DateTime.Now.Date;
                    DateTime initial  = recurringEntry.StartDate.AddDays((recurringEntry.DayOfWeek - recurringEntry.StartDate.DayOfWeek + 7) % 7);
                    Double   datediff = ((7 * recurringEntry.WeeksPeriod) - (nowish.Subtract(initial).Days % (7 * recurringEntry.WeeksPeriod))) % (7 * recurringEntry.WeeksPeriod);

                    if (((nowish.AddDays(datediff)).Add(TimeSpan.FromSeconds(recurringEntry.StartTimeInSeconds))) < DateTime.Now)
                    {
                        datediff = datediff + (7 * recurringEntry.WeeksPeriod);
                    }

                    sb.AppendFormat(CultureConstants.DefaultCulture, "  Day of Week: {0}", recurringEntry.DayOfWeek).AppendLine();
                    sb.AppendFormat(CultureConstants.DefaultCulture, "  Every: {0} week{1}",
                                    recurringEntry.WeeksPeriod, (recurringEntry.WeeksPeriod == 1 ? String.Empty : "s")).AppendLine();
                    sb.AppendFormat(CultureConstants.DefaultCulture, "  Next: {0}",
                                    (nowish.AddDays(datediff)).Add(TimeSpan.FromSeconds(recurringEntry.StartTimeInSeconds)).ToShortDateString()).AppendLine();
                }

                if (recurringEntry.EndTimeInSeconds > 86400)
                {
                    recurringEntry.EndTimeInSeconds -= 86400;
                }

                sb.AppendFormat(CultureConstants.DefaultCulture, " Start Time: {0}",
                                TimeSpan.FromSeconds(recurringEntry.StartTimeInSeconds).ToString()).AppendLine();
                sb.AppendFormat(CultureConstants.DefaultCulture, " End Time: {0}",
                                TimeSpan.FromSeconds(recurringEntry.EndTimeInSeconds).ToString()).AppendLine();
                sb.AppendFormat(CultureConstants.DefaultCulture, " Expired: {0}", recurringEntry.Expired).AppendLine();
                sb.AppendLine();
                sb.AppendLine("Options");
                sb.AppendFormat(CultureConstants.DefaultCulture, " Blocking: {0}",
                                (recurringEntry.Options & ScheduleEntryOptions.Blocking) != ScheduleEntryOptions.None).AppendLine();
                sb.AppendFormat(CultureConstants.DefaultCulture, " Silent: {0}",
                                (recurringEntry.Options & ScheduleEntryOptions.Quiet) != ScheduleEntryOptions.None).AppendLine();
                sb.AppendFormat(CultureConstants.DefaultCulture, " Uses Eve Time: {0}",
                                (recurringEntry.Options & ScheduleEntryOptions.EVETime) != ScheduleEntryOptions.None).AppendLine();
            }

            // Update the description
            lblEntryDescription.Text = sb.ToString();
        }
Beispiel #7
0
        /// <summary>
        /// Update the entry's description
        /// </summary>
        private void UpdateEntryDescription()
        {
            ScheduleEntry temp = m_lbEntriesData[lbEntries.SelectedIndex];
            StringBuilder sb   = new StringBuilder();

            sb.AppendLine($"Title: {temp.Title}");

            // Simple entry ?
            SimpleScheduleEntry simpleEntry = temp as SimpleScheduleEntry;

            if (simpleEntry != null)
            {
                sb
                .AppendLine("One Off Entry")
                .AppendLine($" Start: {simpleEntry.StartDate}")
                .AppendLine($" End: {simpleEntry.EndDate}")
                .AppendLine($" Expired: {simpleEntry.Expired}")
                .AppendLine()
                .AppendLine("Options")
                .AppendLine($" Blocking: {(simpleEntry.Options & ScheduleEntryOptions.Blocking) != ScheduleEntryOptions.None}")
                .AppendLine($" Silent: {(simpleEntry.Options & ScheduleEntryOptions.Quiet) != ScheduleEntryOptions.None}")
                .AppendLine(
                    $" Uses Eve Time: {(simpleEntry.Options & ScheduleEntryOptions.EVETime) != ScheduleEntryOptions.None}");
            }
            // Or recurring entry ?
            else
            {
                RecurringScheduleEntry recurringEntry = (RecurringScheduleEntry)temp;

                sb
                .AppendLine("Recurring Entry")
                .AppendLine($" Start: {recurringEntry.StartDate.ToShortDateString()}")
                .AppendLine($" End: {recurringEntry.EndDate.ToShortDateString()}")
                .AppendLine($" Frequency: {recurringEntry.Frequency}");

                switch (recurringEntry.Frequency)
                {
                case RecurringFrequency.Monthly:
                {
                    sb
                    .AppendLine($"  Day of Month: {recurringEntry.DayOfMonth}")
                    .AppendLine($"  On Overflow: {recurringEntry.OverflowResolution}");
                }
                break;

                case RecurringFrequency.Weekly:
                {
                    DateTime nowish  = DateTime.Now.Date;
                    DateTime initial =
                        recurringEntry.StartDate.AddDays((recurringEntry.DayOfWeek - recurringEntry.StartDate.DayOfWeek +
                                                          DaysOfWeek) % DaysOfWeek);
                    Double datediff = (DaysOfWeek * recurringEntry.WeeksPeriod -
                                       nowish.Subtract(initial).Days % (DaysOfWeek * recurringEntry.WeeksPeriod)) %
                                      (DaysOfWeek * recurringEntry.WeeksPeriod);

                    DateTime noWishDateTime =
                        nowish.AddDays(datediff).Add(TimeSpan.FromSeconds(recurringEntry.StartTimeInSeconds));

                    if (noWishDateTime < DateTime.Now)
                    {
                        datediff       = datediff + DaysOfWeek * recurringEntry.WeeksPeriod;
                        noWishDateTime =
                            nowish.AddDays(datediff).Add(TimeSpan.FromSeconds(recurringEntry.StartTimeInSeconds));
                    }

                    sb
                    .AppendLine($"  Day of Week: {recurringEntry.DayOfWeek}")
                    .AppendLine($"  Every: {recurringEntry.WeeksPeriod}" +
                                $" week{(recurringEntry.WeeksPeriod == 1 ? String.Empty : "s")}")
                    .AppendLine($"  Next: {noWishDateTime.ToShortDateString()}");
                }
                break;
                }

                if (recurringEntry.EndTimeInSeconds > OneDaysSeconds)
                {
                    recurringEntry.EndTimeInSeconds -= OneDaysSeconds;
                }

                sb
                .AppendLine($" Start Time: {TimeSpan.FromSeconds(recurringEntry.StartTimeInSeconds)}")
                .AppendLine($" End Time: {TimeSpan.FromSeconds(recurringEntry.EndTimeInSeconds)}")
                .AppendLine($" Expired: {recurringEntry.Expired}")
                .AppendLine()
                .AppendLine("Options")
                .AppendLine(
                    $" Blocking: {(recurringEntry.Options & ScheduleEntryOptions.Blocking) != ScheduleEntryOptions.None}")
                .AppendLine($" Silent: {(recurringEntry.Options & ScheduleEntryOptions.Quiet) != ScheduleEntryOptions.None}")
                .AppendLine(
                    $" Uses Eve Time: {(recurringEntry.Options & ScheduleEntryOptions.EVETime) != ScheduleEntryOptions.None}");
            }

            // Update the description
            lblEntryDescription.Text = sb.ToString();
        }