public AlarmObject(DateTime inputDateTime, String inputEnabled, AlarmSounds inputSound, int inputSnooze) { this.targetTime = inputDateTime; this.enabled = inputEnabled; this.sound = inputSound; this.snooze = inputSnooze; }
private void plusButton_Click(object sender, EventArgs e) { AddEditForm form = new AddEditForm(); using (form) { var result = form.ShowDialog(); if (result == DialogResult.OK) { form.populateList(); sound = form.sound; snoozeTiming = form.snoozeTime; DateTime input = new DateTime(form.returnedYear, form.returnedMonth, form.returnedDay, form.returnedHour, form.returnedMinute, form.returnedSecond); AlarmObject myObject = new AlarmObject(input, form.alarmEnabled, sound, snoozeTiming); listBox.Items.Add(myObject); if (form.alarmEnabled == "on") { DateTime targetTime = new DateTime(form.returnedYear, form.returnedMonth, form.returnedDay, form.returnedHour, form.returnedMinute, form.returnedSecond); DateTime nowTime = DateTime.Now; TimeSpan ts = targetTime.Subtract(nowTime); int milliseconds = (int)ts.TotalMilliseconds; if (milliseconds < 0) { errorLabel.Text = "The selected alarm date has to be later than the current date"; return; } this.outputLabel.Text = "Status : Alarm is Running "; timerArray[count] = new Timer { Interval = milliseconds }; timerArray[count].Enabled = true; timerArray[count].Tick += new System.EventHandler(OnTimerEvent); } count++; editButton.Enabled = true; saveToFile(); if (count == 10) { plusButton.Enabled = false; } } } }
public static void Read(ListBox x, int y, Button button) { string line; try { using (StreamReader sr = new StreamReader("AlarmsData.txt")) { while ((line = sr.ReadLine()) != null) { Console.WriteLine(line); string[] splits = line.Split(' '); DateTime mySavedTime = DateTime.Parse(splits[0]); String mySavedEnabled = splits[1]; AlarmSounds mySavedSound = AlarmSounds.Radar; switch (splits[2]) { case "Radar": mySavedSound = AlarmSounds.Radar; break; case "Beacon": mySavedSound = AlarmSounds.Beacon; break; case "Chimes": mySavedSound = AlarmSounds.Chimes; break; case "Circuit": mySavedSound = AlarmSounds.Circuit; break; case "Reflection": mySavedSound = AlarmSounds.Reflection; break; } int mySavedSnooze = int.Parse(line); AlarmObject myObject = new AlarmObject(mySavedTime, "off", mySavedSound, mySavedSnooze); x.Items.Add(myObject); y++; button.Enabled = true; } } } catch (Exception e) { //MessageBox.Show("Somehting went wrong"); } }
public AddEditForm(DateTime inputDateTime, String inputEnabled, AlarmSounds inputSound, int inputSnooze) { InitializeComponent(); populateList(); this.dateTimePicker.Value = inputDateTime; this.soundList.SelectedItem = inputSound; this.snoozeTimer.Value = inputSnooze; if (inputEnabled == "on") { this.onCheckBox.Checked = true; } }
private void setButton_Click(object sender, EventArgs e) { this.returnedYear = dateTimePicker.Value.Year; this.returnedMonth = dateTimePicker.Value.Month; this.returnedDay = dateTimePicker.Value.Day; this.returnedHour = dateTimePicker.Value.Hour; this.returnedMinute = dateTimePicker.Value.Minute; this.returnedSecond = dateTimePicker.Value.Second; this.snoozeTime = Convert.ToInt32(snoozeTimer.Value); //this.sound = (AlarmSounds)soundList.SelectedItem var sName = soundList.SelectedItem.ToString(); switch (sName) { case "Radar": this.sound = AlarmSounds.Radar; break; case "Beacon": this.sound = AlarmSounds.Beacon; break; case "Chimes": this.sound = AlarmSounds.Chimes; break; case "Reflection": this.sound = AlarmSounds.Reflection; break; case "Circuit": this.sound = AlarmSounds.Circuit; break; } if (onCheckBox.Checked == true) { this.alarmEnabled = "on"; } else { this.alarmEnabled = "off"; } this.DialogResult = DialogResult.OK; this.Close(); }
private void editButton_Click(object sender, EventArgs e) { int selectedIndex = listBox.SelectedIndex; if (selectedIndex != -1) { AlarmObject myObject = (AlarmObject)listBox.SelectedItem; using (var form = new AddEditForm(myObject.getTargetTime(), myObject.getEnabled(), myObject.getSound(), myObject.getSnooze())) { var result = form.ShowDialog(); if (result == DialogResult.OK) { DateTime targetTime = new DateTime(form.returnedYear, form.returnedMonth, form.returnedDay, form.returnedHour, form.returnedMinute, form.returnedSecond); AlarmSounds targetSound = form.sound; int targetSnoozeTime = form.snoozeTime; if (timerArray[selectedIndex] != null) { if (timerArray[selectedIndex].Enabled == true) { timerArray[selectedIndex].Stop(); } } myObject.setTargetTime(targetTime); myObject.setEnabled(form.alarmEnabled); myObject.setSound(targetSound); myObject.setSnooze(targetSnoozeTime); listBox.Items.RemoveAt(selectedIndex); listBox.Items.Insert(selectedIndex, myObject); saveToFile(); if (form.alarmEnabled == "on") { DateTime nowTime = DateTime.Now; TimeSpan ts = targetTime.Subtract(nowTime); int milliseconds = (int)ts.TotalMilliseconds; int snooze = form.snoozeTime; if (milliseconds < 0) { errorLabel.Text = "The selected alarm date has to be later than the current date"; return; } if (snooze < 0 && snooze > 30) { errorLabel.Text = "The selected snooze time has to be between 0 and 30 seconds"; return; } this.outputLabel.Text = "Status : Alarm is Running "; timerArray[selectedIndex] = new Timer { Interval = milliseconds }; timerArray[selectedIndex].Enabled = true; timerArray[selectedIndex].Tick += new System.EventHandler(OnTimerEvent); } } } } else { errorLabel.Text = "Status : Please select an alarm in the box before clicking edit"; } }
public void setSound(AlarmSounds inputsound) { sound = inputsound; }