private void CreateBtn_Click(object sender, EventArgs e)
        {
            var errorMessage = new StringBuilder();

            var name = nameBox.Text;

            if (string.IsNullOrEmpty(name))
            {
                errorMessage.Append("Name cannot be empty!\n");
            }
            else if (!CheckNameUnique(name))
            {
                errorMessage.Append("Name already used!\n");
                nameBox.Text = string.Empty;
            }

            if (!int.TryParse(intervalBox.Text, out var interval))
            {
                errorMessage.Append("Interval can contain whole numbers only!\n");
                intervalBox.Text = string.Empty;
            }
            else if (interval < 1)
            {
                errorMessage.Append("Interval can contain positive numbers only!\n");
                intervalBox.Text = string.Empty;
            }

            if (errorMessage.Length != 0)
            {
                MessageBox.Show(errorMessage.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var reminder = new Reminder(name, interval, repeatYesRBtn.Checked);

            CreateReminder?.Invoke(sender, new ReminderEventArgs {
                Reminder = reminder
            });
        }
Esempio n. 2
0
 /// <summary>
 /// Stops and removes reminder from list of reminders
 /// </summary>
 public void RemoveReminder(Reminder reminder, ref List <Reminder> reminders)
 {
     reminder.Stop();
     reminders.Remove(reminder);
 }
Esempio n. 3
0
 /// <summary>
 /// Adds reminder to list of reminders
 /// </summary>
 public void AddToReminders(Reminder reminder, ref List <Reminder> reminders)
 {
     reminders.Add(reminder);
 }