Example #1
0
 /// <summary>
 /// Reads in alarms from file and populates data field
 /// </summary>
 public void ReadAlarms()
 {
     //Reads in alarm info from persistent text file and populates alarmList variable
     if (File.Exists(filename))
     {
         StreamReader sr = new StreamReader(filename);
         while (!sr.EndOfStream)
         {
             string[] alarmData = sr.ReadLine().Split(',');
             Tone     t         = (Tone)Enum.Parse(typeof(Tone), alarmData[5]);
             //from AlarmWriter:
             //return $"{a.Time.Hour},{a.Time.Minute},{a.Time.Second},{a.Status},{a.SnoozeInterval},{a.Ringtone}";
             bool     running = (alarmData[3] == "Running");
             AlarmMVC a       = new AlarmMVC(
                 Convert.ToInt32(alarmData[0]),
                 Convert.ToInt32(alarmData[1]),
                 Convert.ToInt32(alarmData[2]),
                 running,
                 Convert.ToInt32(alarmData[4]),
                 t);
             data.AddAlarm(a);
         }
         sr.Close();
     }
 }
Example #2
0
        /// <summary>
        /// Adds an alarm to the collection if maximum size has not been reached
        /// </summary>
        /// <param name="a"></param>
        /// <returns></returns>
        public bool AddAlarm(AlarmMVC a)
        {
            bool added = false;

            if (alarms.Count < size)
            {
                alarms.Add(a);
                added = true;
            }
            return(added);
        }
Example #3
0
        /// <summary>
        /// Handles click event on the set button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uxSetAlarmBtn_Click(object sender, EventArgs e)
        {
            AlarmMVC result;
            DateTime selectedTime = uxTimePicker.Value;
            int      snooze       = Convert.ToUInt16(uxSnoozeIntvlUpDwn.Value);
            Tone     tone         = (Tone)uxToneComboBx.SelectedItem;

            result = new AlarmMVC(selectedTime.Hour, selectedTime.Minute, selectedTime.Second, uxOn.Checked, snooze, tone);
            handler(result, alarmIndex);
            this.Close();
        }
Example #4
0
 /// <summary>
 /// Method to edit alarms according th changes made in the edit form
 /// </summary>
 /// <param name="a"></param>
 /// <param name="index"></param>
 public void HandleEdit(AlarmMVC a, int index)
 {
     if (index == -1)
     {
         model.AddAlarm(a);
     }
     else
     {
         model.EditAlarm(index, a);
     }
     observer(AppState.LISTENING, -1);
 }
Example #5
0
        /// <summary>
        /// Constructor passing alarm and its index
        /// </summary>
        /// <param name="a">alarm to be edited, or null if new alarm</param>
        /// <param name="index">index of alarm in alarmList</param>
        public EditForm(AlarmMVC a, int index, EditHandler eh)
        {
            InitializeComponent();
            handler                  = eh;
            uxTimePicker.Format      = DateTimePickerFormat.Time;
            uxTimePicker.ShowUpDown  = true;
            uxToneComboBx.DataSource = Enum.GetValues(typeof(Tone));

            alarmIndex = index;
            if (a != null)
            {
                DateTime alarmValue = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, a.Time.Hour, a.Time.Minute, a.Time.Second);
                uxTimePicker.Value         = alarmValue;
                uxOn.Checked               = (a.Status == AlarmStatus.Running);
                uxToneComboBx.SelectedItem = a.Ringtone;
                uxSnoozeIntvlUpDwn.Value   = a.SnoozeInterval;
            }
        }
Example #6
0
 /// <summary>
 /// Prints the time and status of the alarm for persistent storage
 ///  HH,MM,SS,STATUS
 /// </summary>
 /// <param name="a"></param>
 /// <returns></returns>
 private string PrintAlarm(AlarmMVC a)
 {
     return($"{a.Time.Hour},{a.Time.Minute},{a.Time.Second},{a.Status},{a.SnoozeInterval},{a.Ringtone}");
 }
Example #7
0
 /// <summary>
 /// Edits the indexed alarm by replacing it with AlarmMVC passed as parameter
 /// </summary>
 /// <param name="index"></param>
 /// <param name="a"></param>
 public void EditAlarm(int index, AlarmMVC a)
 {
     alarms[index] = a;
 }