public void AddEntry(DateTime fromTime, DateTime toTime) { ServiceWindow newEntry = new ServiceWindow(); newEntry.AllWeekDays = true; newEntry.From = fromTime; newEntry.To = toTime; Entries.Add(newEntry); }
private void RemoveItems() { if (MessageBox.Show("Are you sure you want to remove the selected entries?", "Remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { foreach (ListViewItem lvi in lvwTimes.SelectedItems) { ServiceWindow timeWindow = (ServiceWindow)lvi.Tag; SelectedServiceWindows.Times.Remove(timeWindow); lvwTimes.Items.Remove(lvi); } } }
private void lvwTimes_SelectedIndexChanged(object sender, EventArgs e) { if (lvwTimes.SelectedItems.Count > 0) { cmdRemove.Enabled = true; ServiceWindow timeWindow = (ServiceWindow)lvwTimes.SelectedItems[0].Tag; fromTimeMaskedTextBox.Text = timeWindow.From.ToString("HH:mm:ss"); toTimeMaskedTextBox.Text = timeWindow.To.ToString("HH:mm:ss"); } else { cmdRemove.Enabled = false; fromTimeMaskedTextBox.Text = ""; toTimeMaskedTextBox.Text = ""; } }
public void AddEntry(DateTime fromTime, DateTime toTime, bool sunday, bool monday, bool tuesday, bool wednesday, bool thursday, bool friday, bool saturday) { ServiceWindow newEntry = new ServiceWindow(); newEntry.AllWeekDays = true; newEntry.From = fromTime; newEntry.To = toTime; if (sunday) { newEntry.Days.Add(DayOfWeek.Sunday); } if (monday) { newEntry.Days.Add(DayOfWeek.Monday); } if (tuesday) { newEntry.Days.Add(DayOfWeek.Tuesday); } if (wednesday) { newEntry.Days.Add(DayOfWeek.Wednesday); } if (thursday) { newEntry.Days.Add(DayOfWeek.Thursday); } if (friday) { newEntry.Days.Add(DayOfWeek.Friday); } if (saturday) { newEntry.Days.Add(DayOfWeek.Saturday); } newEntry.AllWeekDays = (sunday && monday && tuesday && wednesday && thursday && friday && saturday) || !(sunday || monday || tuesday || wednesday || thursday || friday || saturday); Entries.Add(newEntry); }
private void cmdUpdate_Click(object sender, EventArgs e) { DateTime testFromTm; if (!DateTime.TryParse(fromTimeMaskedTextBox.Text, out testFromTm)) { MessageBox.Show("Invalid 'From' time specified!", "From time", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); fromTimeMaskedTextBox.Focus(); return; } DateTime testToTm; if (!DateTime.TryParse(toTimeMaskedTextBox.Text, out testToTm)) { MessageBox.Show("Invalid 'To' time specified!", "To time", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); toTimeMaskedTextBox.Focus(); return; } if (testFromTm >= testToTm) { MessageBox.Show("'From' must be before 'To' time!", "Time", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); fromTimeMaskedTextBox.Focus(); return; } ServiceWindow newTimeWindow = new ServiceWindow(DateTime.Parse(fromTimeMaskedTextBox.Text), DateTime.Parse(toTimeMaskedTextBox.Text)); if (lvwTimes.SelectedItems.Count > 0) { ServiceWindow timeWindow = (ServiceWindow)lvwTimes.SelectedItems[0].Tag; SelectedServiceWindows.Times.Remove(timeWindow); } SelectedServiceWindows.Times.Add(newTimeWindow); LoadServiceWindowsTimes(); fromTimeMaskedTextBox.Text = ""; toTimeMaskedTextBox.Text = ""; }