コード例 #1
0
        /// <summary>
        /// "Done" function. Should be called when the user attempts to finish creating/editing
        /// a RepeatingAlarm.
        ///
        /// If everything looks good, this will publish through the event aggregator either an
        /// EditAlarmEvent or a NewAlarmEvent (depending on create/edit mode).
        ///
        /// Sends either a SuccessEvent on a success or a NoRepeatError in the case that this
        /// was called, but the Alarm created had no repeats set.
        /// </summary>
        private void Done()
        {
            RepeatingAlarm alarm = new RepeatingAlarm();

            setAlarmRepeats(alarm);

            if (alarm.HasRepeats())
            {
                if (_isEditMode)
                {
                    EditAlarmWrapper wrapper = new EditAlarmWrapper(_oldAlarm, alarm);
                    _eventAggregator.GetEvent <EditAlarmEvent>().Publish(wrapper);
                }
                else
                {
                    _eventAggregator.GetEvent <NewAlarmEvent>().Publish(alarm);
                }

                // All done, fire success event
                if (SuccessEvent != null)
                {
                    this.SuccessEvent(this, EventArgs.Empty);
                }
            }
            else
            {
                // No repeats were set; fire error event
                if (NoRepeatError != null)
                {
                    this.NoRepeatError(this, EventArgs.Empty);
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Edit mode constructor.
 /// </summary>
 /// <param name="alarm">Alarm to be edited.</param>
 /// <param name="eventAggregator">App event aggregator.</param>
 public RepeatAlarmPresenter(RepeatingAlarm alarm, IEventAggregator eventAggregator)
 {
     this._eventAggregator = eventAggregator;
     InitLists();
     _isEditMode = true;
     _oldAlarm   = alarm;
     UpdateFromEditAlarm(alarm, DayOfWeek.Sunday, ref _sunCheck, SunTimes);
     UpdateFromEditAlarm(alarm, DayOfWeek.Monday, ref _monCheck, MonTimes);
     UpdateFromEditAlarm(alarm, DayOfWeek.Tuesday, ref _tueCheck, TueTimes);
     UpdateFromEditAlarm(alarm, DayOfWeek.Wednesday, ref _wedCheck, WedTimes);
     UpdateFromEditAlarm(alarm, DayOfWeek.Thursday, ref _thuCheck, ThuTimes);
     UpdateFromEditAlarm(alarm, DayOfWeek.Friday, ref _friCheck, FriTimes);
     UpdateFromEditAlarm(alarm, DayOfWeek.Saturday, ref _satCheck, SatTimes);
 }
コード例 #3
0
        /// <summary>
        /// Opens the View for SetRepeatingAlarm, either in New Alarm mode (default) or
        /// in Edit mode (if a RepeatingAlarm is passed).
        /// </summary>
        /// <param name="alarm">The alarm to edit. If null, then create a new alarm.</param>
        private void SetRepeatView(RepeatingAlarm alarm = null)
        {
            SetRepeatAlarm setAlarm;

            if (alarm == null)
            {
                // set new alarm
                setAlarm = new SetRepeatAlarm();
            }
            else
            {
                //edit alarm
                setAlarm = new SetRepeatAlarm(alarm);
            }
            Main.Children.Add(setAlarm);
        }
コード例 #4
0
 /// <summary>
 /// Method to handle setting all strings and checkbox-booleans according to
 /// the existing repeats in an alarm that has been passed in to edit.
 /// </summary>
 /// <param name="alarm">The Alarm eing edited.</param>
 /// <param name="day">The day of the week to check for repeats in the Alarm.</param>
 /// <param name="checkBox">The corresponding ViewModel boolean for this day (as ref).</param>
 /// <param name="timeInfo">The TimeInfo class for this day.</param>
 private void UpdateFromEditAlarm(RepeatingAlarm alarm, DayOfWeek day, ref bool checkBox, RepeatTimePresenter timeInfo)
 {
     if (alarm.RepeatsOn(day))
     {
         checkBox = true;
         TimeSpan span     = alarm.GetRepeatForDay(day);
         int      hoursNum = (span.Hours > 12) ? (span.Hours - 12) : span.Hours;
         if (hoursNum == 0)
         {
             hoursNum = 12;
         }
         string hours = hoursNum.ToString();
         string mins  = span.Minutes.ToString("D2");
         timeInfo.Hours = hours;
         timeInfo.Mins  = mins;
         if (span.Hours >= 12)
         {
             timeInfo.AmPm = "PM";
         }
     }
 }
コード例 #5
0
        /// <summary>
        /// Sets up the repeats on a RepeatingAlarm based on parameters of
        /// the ViewModel. Essentially parses the RepeatTimePresenter for
        /// each day if the corresponding boolean is set, and then sets
        /// the appropriate repeat in the alarm.
        /// </summary>
        /// <param name="alarm">The RepeatingAlarm to set repeats for.</param>
        private void setAlarmRepeats(RepeatingAlarm alarm)
        {
            TimeSpan time;

            if (SunCheck)
            {
                time = parseRepeats(SunTimes);
                alarm.SetRepeat(DayOfWeek.Sunday, /*repeats*/ true, time);
            }
            if (MonCheck)
            {
                time = parseRepeats(MonTimes);
                alarm.SetRepeat(DayOfWeek.Monday, /*repeats*/ true, time);
            }
            if (TueCheck)
            {
                time = parseRepeats(TueTimes);
                alarm.SetRepeat(DayOfWeek.Tuesday, /*repeats*/ true, time);
            }
            if (WedCheck)
            {
                time = parseRepeats(WedTimes);
                alarm.SetRepeat(DayOfWeek.Wednesday, /*repeats*/ true, time);
            }
            if (ThuCheck)
            {
                time = parseRepeats(ThuTimes);
                alarm.SetRepeat(DayOfWeek.Thursday, /*repeats*/ true, time);
            }
            if (FriCheck)
            {
                time = parseRepeats(FriTimes);
                alarm.SetRepeat(DayOfWeek.Friday, /*repeats*/ true, time);
            }
            if (SatCheck)
            {
                time = parseRepeats(SatTimes);
                alarm.SetRepeat(DayOfWeek.Saturday, /*repeats*/ true, time);
            }
        }
コード例 #6
0
 /// <summary>
 /// Edit mode constructor
 /// </summary>
 /// <param name="editAlarm">The alarm to be edited.</param>
 public SetRepeatAlarm(RepeatingAlarm alarm)
 {
     this.DataContext = new RepeatAlarmPresenter(alarm, ApplicationService.Instance.EventAggregator);
     InitializeComponent();
     AddEventHandlers();
 }