private void btnTimetable_Click(object sender, RoutedEventArgs e) { var scheduleRepository = new SqlScheduleRepository(_connectionString); var timeTableWindow = new ScheduleWindow(_customer, scheduleRepository.SelectAll()); wndMainWindow.IsEnabled = false; timeTableWindow.ShowDialog(); wndMainWindow.IsEnabled = true; }
private void btnAdd_Click(object sender, RoutedEventArgs e) { var addScheduleWindow = new AddScheduleWindow(); wndSchedule.IsEnabled = false; addScheduleWindow.ShowDialog(); var scheduleRepository = new SqlScheduleRepository(_connectionString); dgrDataSchedule.ItemsSource = scheduleRepository.SelectAll(); wndSchedule.IsEnabled = true; }
private void btnTimeTable_Click(object sender, RoutedEventArgs e) { var scheduleRepository = new SqlScheduleRepository(_connectionString); if (dgrDataRoutes.SelectedItem == null) { MessageBox.Show("Not selected route.", "Selection", MessageBoxButton.OK, MessageBoxImage.Error); return; } int routeId = ((Route)dgrDataRoutes.SelectedItem).Id; var scheduleWindow = new ScheduleWindow(_customer, scheduleRepository.GetTimeTableByRoute(routeId)); wndRoute.Close(); scheduleWindow.ShowDialog(); }
private void btnSearch_Click(object sender, RoutedEventArgs e) { string stationName = String.IsNullOrEmpty((string)cmbStation.SelectedItem) ? null : (string)cmbStation.SelectedItem; string routeNumber = String.IsNullOrEmpty((string)cmbRoute.SelectedItem) ? null : (string)cmbRoute.SelectedItem; TimeSpan?from = null; if (!String.IsNullOrEmpty(txtFrom.Text)) { TimeSpan fromTime; if (TimeParser.ParseTime(txtFrom.Text, out fromTime)) { from = fromTime; } else { MessageBox.Show("From is not time.", "Cast error", MessageBoxButton.OK, MessageBoxImage.Error); return; } } TimeSpan?to = null; if (!String.IsNullOrEmpty(txtTo.Text)) { TimeSpan toTime; if (TimeParser.ParseTime(txtTo.Text, out toTime)) { to = toTime; } else { MessageBox.Show("To is not time.", "Cast error", MessageBoxButton.OK, MessageBoxImage.Error); return; } } var scheduleSqlRepository = new SqlScheduleRepository(_connectionString); dgrDataSchedule.ItemsSource = scheduleSqlRepository.SearchAll(routeNumber, stationName, from, to); }
private void btnDelete_Click(object sender, RoutedEventArgs e) { var scheduleRepository = new SqlScheduleRepository(_connectionString); if (dgrDataSchedule.SelectedItem == null) { MessageBox.Show("Not selected schedule.", "Selection", MessageBoxButton.OK, MessageBoxImage.Error); return; } int scheduleId = ((TimeTable)dgrDataSchedule.SelectedItem).Id; MessageBoxResult answer = MessageBox.Show(String.Format("You really want to delete bus #{0}?", ((TimeTable)dgrDataSchedule.SelectedItem).Id), "Deleting", MessageBoxButton.YesNo, MessageBoxImage.Question); if (answer == MessageBoxResult.Yes) { scheduleRepository.Delete(scheduleId); dgrDataSchedule.ItemsSource = scheduleRepository.SelectAll(); } }
private void btnAdd_Click(object sender, RoutedEventArgs e) { if (String.IsNullOrEmpty(txtBusNumber.Text)) { MessageBox.Show("No bus number", "Empty field", MessageBoxButton.OK, MessageBoxImage.Error); return; } string busNumber = txtBusNumber.Text; if (String.IsNullOrEmpty(txtDepartureTime.Text)) { MessageBox.Show("No departure time", "Empty field", MessageBoxButton.OK, MessageBoxImage.Error); return; } TimeSpan departureTime = new TimeSpan(); if (!TimeParser.ParseTime(txtDepartureTime.Text, out departureTime)) { MessageBox.Show("Departure time is not time", "Cast error", MessageBoxButton.OK, MessageBoxImage.Error); return; } var scheduleRepository = new SqlScheduleRepository(_connectionString); try { int id = scheduleRepository.Insert(busNumber, departureTime); txtBusNumber.Text = ""; txtDepartureTime.Text = ""; MessageBox.Show(String.Format("Schedule id = {0}.", id), "Success", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception exception) { MessageBox.Show(exception.Message, "Number error", MessageBoxButton.OK, MessageBoxImage.Error); } }