示例#1
0
        private void addBtn_Click(object sender, EventArgs e)
        {
            IObserver newEvent = new AlarmObserver();
            DateTime  aimTime  = new DateTime(DateTime.Now.Date.Year, DateTime.Now.Date.Month, DateTime.Now.Date.Day, (int)numericUpDownH.Value, (int)numericUpDownM.Value, (int)numericUpDownS.Value);

            if (DateTime.Now.CompareTo(aimTime) > 0)
            {
                aimTime = aimTime.AddDays(1);
            }
            switch (comboBox.Text)
            {
            case "Alarm":
                newEvent = new AlarmObserver(watch, "alarm.wav", aimTime);
                break;

            case "Timer":
                Timer eventTimer = new Timer("alarm.wav", aimTime);
                break;

            case "Stopwatch":
                Stopwatch eventStwtch = new Stopwatch();
                break;

            default:
                MessageBox.Show("No such option!");
                break;
            }
            eventsList.Add(newEvent);
            PrintEvents(newEvent);
            if (comboBox.Text.Equals("Alarm"))
            {
                MessageBox.Show(comboBox.Text + " added");
            }
        }