Exemple #1
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var str = value as string;
            if (str != null)
            {
                var dwc = new DaysOfWeekConverter();
                var mc = new MonthDayConverter();
                var avc = new AlarmAfterValuesConverter();
                var dtc = new DateTimeConverter();

                var sch = new PNNoteSchedule();
                var values = str.Split(DEL_INNER);
                if (values.Length == Enum.GetValues(typeof(Fields)).Length)
                {
                    sch.AlarmAfter = (AlarmAfterValues)avc.ConvertFromString(values[(int)Fields.AlarmAfter]);
                    var dateFromString = dtc.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.AlarmDate]);
                    if (dateFromString != null)
                        sch.AlarmDate = (DateTime)dateFromString;
                    dateFromString = dtc.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.LastRun]);
                    if (dateFromString != null)
                        sch.LastRun = (DateTime)dateFromString;
                    sch.MonthDay = (MonthDay)mc.ConvertFromString(values[(int)Fields.MonthDay]);
                    sch.RepeatCount = Convert.ToInt32(values[(int)Fields.RepeatCount]);
                    sch.Sound = values[(int)Fields.Sound];
                    sch.SoundInLoop = Convert.ToBoolean(values[(int)Fields.SoundInLoop]);
                    dateFromString = dtc.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.StartDate]);
                    if (dateFromString != null)
                        sch.StartDate = (DateTime)dateFromString;
                    sch.StartFrom = (ScheduleStart)Convert.ToInt32(values[(int)Fields.StartFrom]);
                    sch.StopAfter = Convert.ToInt32(values[(int)Fields.StopAfter]);
                    sch.Track = Convert.ToBoolean(values[(int)Fields.Track]);
                    sch.Type = (ScheduleType)Convert.ToInt32(values[(int)Fields.Type]);
                    sch.UseTts = Convert.ToBoolean(values[(int)Fields.UseTTS]);
                    sch.Weekdays = (List<DayOfWeek>)dwc.ConvertFromString(values[(int)Fields.Weekdays]);
                    sch.ProgramToRunOnAlert = values[(int)Fields.ExtRun];
                    sch.CloseOnNotification = Convert.ToBoolean(values[(int)Fields.CloseOnNotify]);
                }
                return sch;
            }
            return base.ConvertFrom(context, culture, value);
        }
Exemple #2
0
 internal string GetNoteScheduleDescription(PNNoteSchedule sc, DayOfWeekStruct[] days)
 {
     try
     {
         if (sc.Type == ScheduleType.None)
             return "";
         CultureInfo ci = new CultureInfo(Instance.GetLanguageCulture());
         string result = PNStatic.ScheduleDescriptions[sc.Type];
         switch (sc.Type)
         {
             case ScheduleType.Once:
                 result = result.Replace(PNStrings.PLACEHOLDER1, sc.AlarmDate.ToString(PNStatic.Settings.GeneralSettings.DateFormat, ci));
                 break;
             case ScheduleType.EveryDay:
                 result = result.Replace(PNStrings.PLACEHOLDER1, sc.AlarmDate.ToString(PNStatic.Settings.GeneralSettings.TimeFormat, ci));
                 break;
             case ScheduleType.RepeatEvery:
             case ScheduleType.After:
                 result = sc.AlarmAfter.Years > 0
                              ? result.Replace(PNStrings.YEARS,
                                               sc.AlarmAfter.Years.ToString(CultureInfo.InvariantCulture) + " " +
                                               Instance.GetControlText("lblAfterYears", "Years"))
                              : result.Replace(PNStrings.YEARS, "");
                 result = sc.AlarmAfter.Months > 0
                              ? result.Replace(PNStrings.MONTHS,
                                               sc.AlarmAfter.Months.ToString(CultureInfo.InvariantCulture) + " " +
                                               Instance.GetControlText("lblAfterMonths", "Months"))
                              : result.Replace(PNStrings.MONTHS, "");
                 result = sc.AlarmAfter.Weeks > 0
                              ? result.Replace(PNStrings.WEEKS,
                                               sc.AlarmAfter.Weeks.ToString(CultureInfo.InvariantCulture) + " " +
                                               Instance.GetControlText("lblAfterWeeks", "Weeks"))
                              : result.Replace(PNStrings.WEEKS, "");
                 result = sc.AlarmAfter.Days > 0
                              ? result.Replace(PNStrings.DAYS,
                                               sc.AlarmAfter.Days.ToString(CultureInfo.InvariantCulture) + " " +
                                               Instance.GetControlText("lblAfterDays", "Days"))
                              : result.Replace(PNStrings.DAYS, "");
                 result = sc.AlarmAfter.Hours > 0
                              ? result.Replace(PNStrings.HOURS,
                                               sc.AlarmAfter.Hours.ToString(CultureInfo.InvariantCulture) + " " +
                                               Instance.GetControlText("lblAfterHours", "Hours"))
                              : result.Replace(PNStrings.HOURS, "");
                 result = sc.AlarmAfter.Minutes > 0
                              ? result.Replace(PNStrings.MINUTES,
                                               sc.AlarmAfter.Minutes.ToString(CultureInfo.InvariantCulture) + " " +
                                               Instance.GetControlText("lblAfterMinutes", "Minutes"))
                              : result.Replace(PNStrings.MINUTES, "");
                 result = sc.AlarmAfter.Seconds > 0
                              ? result.Replace(PNStrings.SECONDS,
                                               sc.AlarmAfter.Seconds.ToString(CultureInfo.InvariantCulture) + " " +
                                               Instance.GetControlText("lblAfterSeconds", "Seconds"))
                              : result.Replace(PNStrings.SECONDS, "");
                 result += " ";
                 result += Instance.GetControlText("lblAfterStart", "Starting from:");
                 result += " ";
                 if (sc.StartFrom == ScheduleStart.ExactTime)
                 {
                     result += Instance.GetControlText("optAfterExact", "Exact time");
                     result += " ";
                     result += sc.StartDate.ToString(PNStatic.Settings.GeneralSettings.DateFormat, ci);
                 }
                 else
                 {
                     result += Instance.GetControlText("optAfterProgram", "Program start");
                 }
                 break;
             case ScheduleType.Weekly:
                 result += " ";
                 foreach (DayOfWeek wd in sc.Weekdays)
                 {
                     result += days.FirstOrDefault(dw => dw.DayOfW == wd).Name;
                     result += ", ";
                 }
                 if (result.EndsWith(", "))
                 {
                     result = result.Substring(0, result.Length - 2);
                 }
                 result += " ";
                 result += Instance.GetControlText("lblWeeklyAt", "At:");
                 result += " ";
                 result += sc.AlarmDate.ToString(PNStatic.Settings.GeneralSettings.TimeFormat, ci);
                 break;
             case ScheduleType.MonthlyExact:
                 result = result.Replace(PNStrings.PLACEHOLDER1, sc.AlarmDate.Day.ToString(CultureInfo.InvariantCulture));
                 result = result.Replace(PNStrings.PLACEHOLDER2, sc.AlarmDate.ToString(PNStatic.Settings.GeneralSettings.TimeFormat, ci));
                 break;
             case ScheduleType.MonthlyDayOfWeek:
                 result = result.Replace(PNStrings.PLACEHOLDER1, days.FirstOrDefault(wd => wd.DayOfW == sc.MonthDay.WeekDay).Name);
                 result = result.Replace(PNStrings.PLACEHOLDER2, Instance.GetOrdinalName(sc.MonthDay.OrdinalNumber));
                 result = result.Replace(PNStrings.PLACEHOLDER3, sc.AlarmDate.ToString(PNStatic.Settings.GeneralSettings.TimeFormat, ci));
                 break;
         }
         return result;
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
         return "";
     }
 }
        private void setUpSchedule()
        {
            try
            {
                var temp = (PNNoteSchedule)_Schedule.Clone();
                if ((ScheduleType)cboScheduleType.SelectedIndex == ScheduleType.None)
                {
                    _Schedule = new PNNoteSchedule();
                    return;
                }
                _Schedule = new PNNoteSchedule
                {
                    Type = (ScheduleType)cboScheduleType.SelectedIndex,
                    RepeatCount = temp.RepeatCount,
                    StopAfter = temp.StopAfter,
                    Sound = temp.Sound,
                    SoundInLoop = temp.SoundInLoop,
                    Track = temp.Track,
                    UseTts = temp.UseTts,
                    ProgramToRunOnAlert = temp.ProgramToRunOnAlert,
                    CloseOnNotification = temp.CloseOnNotification,
                    TimeZone = (TimeZoneInfo)cboTimeZone.SelectedItem
                };

                switch (_Schedule.Type)
                {
                    case ScheduleType.Once:
                        _Schedule.AlarmDate = dtpOnce.DateValue;
                        break;
                    case ScheduleType.After:
                        _Schedule.StartFrom = optAfterExact.IsChecked != null && optAfterExact.IsChecked.Value ? ScheduleStart.ExactTime : ScheduleStart.ProgramStart;
                        _Schedule.StartDate = dtpAfter.DateValue;
                        _Schedule.AlarmAfter.Years = (int)updAfterYears.Value;
                        _Schedule.AlarmAfter.Months = (int)updAfterMonths.Value;
                        _Schedule.AlarmAfter.Weeks = (int)updAfterWeeks.Value;
                        _Schedule.AlarmAfter.Days = (int)updAfterDays.Value;
                        _Schedule.AlarmAfter.Hours = (int)updAfterHours.Value;
                        _Schedule.AlarmAfter.Minutes = (int)updAfterMinutes.Value;
                        _Schedule.AlarmAfter.Seconds = (int)updAfterSeconds.Value;
                        break;
                    case ScheduleType.EveryDay:
                        _Schedule.AlarmDate = dtpEvery.DateValue;
                        break;
                    case ScheduleType.RepeatEvery:
                        _Schedule.StartFrom = optRepeatExact.IsChecked != null && optRepeatExact.IsChecked.Value ? ScheduleStart.ExactTime : ScheduleStart.ProgramStart;
                        _Schedule.StartDate = dtpRepeat.DateValue;
                        _Schedule.AlarmAfter.Years = (int)updRepeatYears.Value;
                        _Schedule.AlarmAfter.Months = (int)updRepeatMonths.Value;
                        _Schedule.AlarmAfter.Weeks = (int)updRepeatWeeks.Value;
                        _Schedule.AlarmAfter.Days = (int)updRepeatDays.Value;
                        _Schedule.AlarmAfter.Hours = (int)updRepeatHours.Value;
                        _Schedule.AlarmAfter.Minutes = (int)updRepeatMinutes.Value;
                        _Schedule.AlarmAfter.Seconds = (int)updRepeatSeconds.Value;
                        break;
                    case ScheduleType.Weekly:
                        _Schedule.Weekdays.Clear();
                        if (chkW0.IsChecked != null && chkW0.IsChecked.Value)
                        {
                            _Schedule.Weekdays.Add((DayOfWeek) chkW0.Tag);
                        }
                        if (chkW1.IsChecked != null && chkW1.IsChecked.Value)
                        {
                            _Schedule.Weekdays.Add((DayOfWeek) chkW1.Tag);
                        }
                        if (chkW2.IsChecked != null && chkW2.IsChecked.Value)
                        {
                            _Schedule.Weekdays.Add((DayOfWeek) chkW2.Tag);
                        }
                        if (chkW3.IsChecked != null && chkW3.IsChecked.Value)
                        {
                            _Schedule.Weekdays.Add((DayOfWeek) chkW3.Tag);
                        }
                        if (chkW4.IsChecked != null && chkW4.IsChecked.Value)
                        {
                            _Schedule.Weekdays.Add((DayOfWeek) chkW4.Tag);
                        }
                        if (chkW5.IsChecked != null && chkW5.IsChecked.Value)
                        {
                            _Schedule.Weekdays.Add((DayOfWeek) chkW5.Tag);
                        }
                        if (chkW6.IsChecked != null && chkW6.IsChecked.Value)
                        {
                            _Schedule.Weekdays.Add((DayOfWeek) chkW6.Tag);
                        }
                        _Schedule.AlarmDate = dtpWeekly.DateValue;
                        _Schedule.StartDate = DateTime.Today;
                        break;
                    case ScheduleType.MonthlyExact:
                        _Schedule.StartDate = DateTime.Today;
                        _Schedule.AlarmDate = new DateTime(2000, 1, cboExactDate.SelectedIndex + 1,
                                dtpMonthExact.DateValue.Hour, dtpMonthExact.DateValue.Minute,
                                dtpMonthExact.DateValue.Second);
                        break;
                    case ScheduleType.MonthlyDayOfWeek:
                        _Schedule.StartDate = DateTime.Today;
                        _Schedule.AlarmDate = dtpDW.DateValue;
                        _Schedule.MonthDay.OrdinalNumber = (DayOrdinal)(cboOrdinal.SelectedIndex + 1);
                        var dwReal = cboDW.SelectedItem as DwReal;
                        if (dwReal != null)
                            _Schedule.MonthDay.WeekDay = dwReal.DayW;
                        break;
                    case ScheduleType.MultipleAlerts:
                        foreach (var st in grdAlerts.Children.OfType<StackPanel>())
                        {
                            var dtp = st.Children[1] as DateTimePicker;
                            if (dtp == null) continue;
                            var date = dtp.DateValue;
                            if (_Schedule.MultiAlerts.All(a => a.Date != date))
                            {
                                _Schedule.MultiAlerts.Add(new MultiAlert
                                {
                                    Raised = dtp.IsBlackoutDate,
                                    Date = date
                                });
                            }
                        }
                        break;
                }
                var prog = Convert.ToString(cboRunExternal.SelectedItem);
                var ext = PNStatic.Externals.FirstOrDefault(p => p.Name == prog);
                _Schedule.ProgramToRunOnAlert = ext == null ? "" : ext.Name;
                if (chkHideUntilAlert.IsChecked != null)
                {
                    _Schedule.CloseOnNotification = chkHideUntilAlert.IsChecked.Value;
                }
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
            }
        }
Exemple #4
0
 public bool Equals(PNNoteSchedule sc)
 {
     if ((object)sc == null)
         return false;
     return (_Type == sc._Type
         && _AlarmDate.IsDateEqual(sc._AlarmDate)
         && _Sound == sc._Sound
         && _StopAfter == sc._StopAfter
         && _Track == sc._Track
         && _SoundInLoop == sc._SoundInLoop
         && _RepeatCount == sc._RepeatCount
         && _UseTts == sc._UseTts
         && _StartFrom == sc._StartFrom
         && _MonthDay == sc._MonthDay
         && _AlarmAfter == sc._AlarmAfter
         && !_Weekdays.Inequals(sc._Weekdays)
         && ProgramToRunOnAlert == sc.ProgramToRunOnAlert
         && CloseOnNotification == sc.CloseOnNotification
         && _MultiAlerts.IsEqual(sc._MultiAlerts)
         && _TimeZone == sc._TimeZone);
 }