public AlarmController(AlarmModel model, AlarmView view)
        {
            this.model = model;
            this.view = view;

            this.view.timeTextBox.Text = this.model.When.ToString("HH:mm");
            this.view.nameTextBox.Text = this.model.Name;
            this.view.offButton.Enabled = this.model.IsArmed;

            this.view.offButton.Click += OnClickOffButton;

            this.model.FiringChange += OnFiringChange;

            this.flashTimer = new Timer();
            this.flashTimer.Interval = 200;
            this.flashTimer.Tick += ToggleBackground;
        }
Exemple #2
0
        private void OnScheduleChange(Object sender, EventArgs e)
        {
            this.form.BeginInvoke(new MethodInvoker(delegate() {
                if (this.alarmControllers != null) {
                    for (int i = 0; i < this.alarmControllers.Count; i++) {
                        this.form.tableLayoutPanel.Controls.RemoveAt(i);
                        this.alarmControllers[i].Dispose();
                    }
                }

                this.alarmControllers = new List<AlarmController>();
                List<AlarmModel> todaysAlarms = new List<AlarmModel>();
                foreach (AlarmModel model in this.model.Alarms)
                    // Can't arm an alarm if we have nothing listening to it
                    if (true) //(alarm.when.Date == DateTime.Now.Date)
                        todaysAlarms.Add(model);
                for (int i = 0; i < todaysAlarms.Count; i++) {
                    AlarmModel alarm = todaysAlarms[i];
                    AlarmView control = new AlarmView();
                    AlarmController controller = new AlarmController(alarm, control);
                    this.form.tableLayoutPanel.Controls.Add(control);
                    this.alarmControllers.Add(controller);

                    alarm.FiringChange += this.AlarmFiringChange;
                }

                this.model.ReadyForAlarms();
            }));
        }