private void button1_Click(object sender, EventArgs e) { foreach (var date in monthCalendar1.Dates()) { if (!CheckIfExists(date)) { _calendar.Schedulers.Add(new Scheduler { Bells = new List <Bell>(), Date = new DateTime(date.Year, date.Month, date.Day), Enabled = true }); _context.Schedulers.Add(new Scheduler { Bells = new List <Bell>(), Date = new DateTime(date.Year, date.Month, date.Day), Enabled = true }); _context.SaveChanges(); } else { _calendar.Schedulers.Where(x => x.Date.ToShortDateString() == date.ToShortDateString()).FirstOrDefault().Enabled = true; try { _context.Schedulers.Where(x => x.Date.ToShortDateString() == date.ToShortDateString()).FirstOrDefault().Enabled = true; _context.SaveChanges(); } catch (Exception ex) { } } } var startDate = monthCalendar1.SelectionStart; int index = 0; for (int i = 0; i < _calendar.Schedulers.Count; i++) { if (_calendar.Schedulers.ElementAt(i).Date.ToLongDateString().Equals(startDate.ToLongDateString())) { index = i; break; } } selectedScheduler = _calendar.Schedulers.ElementAt(index); DayScheduler form = new DayScheduler(selectedScheduler, _context); form.FormClosing += new FormClosingEventHandler(CopySchedulers); form.FormClosing += new FormClosingEventHandler(CreateTriggers); form.Show(); }
private void deleteBellButton_Click(object sender, EventArgs e) { foreach (ListViewItem item in bellListView.SelectedItems) { Bell bellToRemove = null; foreach (var bell in _scheduler.Bells) { if (bell.BellTime.ToLongTimeString().Equals(item.Text) && bell.SoundPath.Equals(item.SubItems[1].Text)) { bellToRemove = bell; } } if (bellToRemove != null) { _scheduler.Bells.Remove(bellToRemove); try { _context.Bells.Remove(bellToRemove); _context.SaveChanges(); } catch (Exception ex) { } } } foreach (ListViewItem eachItem in bellListView.SelectedItems) { bellListView.Items.Remove(eachItem); } }
private void button2_Click(object sender, EventArgs e) { _bell.BellTime = dateTimePicker1.Value; _bell.SoundPath = pathTextBox.Text; _bell.PlayFullSound = fullSoundRadioButton.Checked; _bell.NumberOfSeconds = _bell.PlayFullSound ? 9 : Int32.Parse(timerNum.Value.ToString()); try { var dbBell = _context.Bells.Where(x => x.ID == _bell.ID).FirstOrDefault(); dbBell.BellTime = _bell.BellTime; dbBell.SoundPath = _bell.SoundPath; dbBell.PlayFullSound = _bell.PlayFullSound; dbBell.NumberOfSeconds = _bell.NumberOfSeconds; _context.SaveChanges(); } catch (Exception ex) { } this.Close(); }