Пример #1
0
        private void addButton_Click(object sender, EventArgs e)
        {
            //Showing the AlarmForm dialog box.
            AlarmForm alarmForm = new AlarmForm();
            alarmForm.ShowDialog();

            if (alarmForm.DialogResult == DialogResult.OK)
            {
                bool alarmExists = _alarms.Search(alarmForm.Alarm.AlarmTime);
                //Checking to see if the alarm exists. If not it will be added to the form.
                if (alarmExists)
                {
                    MessageBox.Show("Sorry cannot add a duplicate alarm time.", this.Text, MessageBoxButtons.OK);

                    //Refreshing the alarms listbox.
                    refreshAlarmsList();
                }
                else
                {
                    //Adding the alarm object to the list.
                    _alarms.Add(alarmForm.Alarm);

                    //Saving the data.
                    _alarms.SaveAlarmsToFile(dataPath);

                    //Refreshing the alarms listbox.
                    refreshAlarmsList();
                }
            }
        }
Пример #2
0
        private void editButton_Click(object sender, EventArgs e)
        {
            //Making sure there is an alarm in the form to edit.
            if (alarmsListBox.SelectedIndex > -1)
            {
                //Getting the alarm time.
                string alarmTime = _alarms.GetAlarm(alarmsListBox.SelectedIndex);
                DateTime time = DateTime.Parse(alarmTime);
                int hour = int.Parse(time.ToString("HH"));
                int minutes = int.Parse(time.ToString("mm"));

                //Getting the alarm category.
                string category = _alarms.GetAlarmCategory(alarmsListBox.SelectedIndex);

                //Getting the alarm enabled status.
                bool enabled = _alarms.GetEnabledStatus(alarmsListBox.SelectedIndex);

                AlarmForm editAlarmForm = new AlarmForm(hour, minutes, category, enabled);
                editAlarmForm.ShowDialog();

                //Removing the alarm to be edited. This is so it won't think the edited alarm is a duplicate.
                _alarms.DeleteAlarmFromList(alarmsListBox.SelectedIndex);

                if (editAlarmForm.DialogResult == DialogResult.OK)
                {
                    bool alarmExists = _alarms.Search(editAlarmForm.Alarm.AlarmTime);
                    //Checking to see if the edited alarm already exists. If so removing it and the user will have to re-add the alarm.
                    if (alarmExists)
                    {
                        MessageBox.Show("Sorry, cannot edit an alarm to an already existing time. Please re-add your alarm.", this.Text, MessageBoxButtons.OK);

                        //Refreshing the alarms listbox.
                        refreshAlarmsList();
                    }
                    else
                    {
                        //Removing an re-adding the edited alarm to the _alarms list and the mainform listbox.
                        _alarms.Add(editAlarmForm.Alarm);
                        refreshAlarmsList();
                        _alarms.GetAlarmsList();    //Test method call to verify the edited alarms was added to the list. Can remove later.
                    }
                }
            }
            else
            {
                MessageBox.Show("No alarms selected for editing.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }