public ScheduleWindow(Customer customer, List <TimeTable> schedule) { InitializeComponent(); _customer = customer; if (_customer.Mode == Mode.User) { btnAdd.Visibility = Visibility.Hidden; btnDelete.Visibility = Visibility.Hidden; } var stationRepository = new SqlStationRepository(_connectionString); List <string> stations = stationRepository.GetAllNames(); stations.Insert(0, ""); cmbStation.ItemsSource = stations; cmbStation.SelectedItem = ""; var routeRepository = new SqlRouteRepository(_connectionString); List <string> routes = routeRepository.GetAllNumbers(); routes.Insert(0, ""); cmbRoute.ItemsSource = routes; cmbRoute.SelectedItem = ""; dgrDataSchedule.ItemsSource = schedule; }
private void btnAdd_Click(object sender, RoutedEventArgs e) { if (String.IsNullOrEmpty(txtName.Text)) { MessageBox.Show("No station name", "Empty field", MessageBoxButton.OK, MessageBoxImage.Error); return; } string stationName = txtName.Text; var stationRepository = new SqlStationRepository(_connectionString); try { int id = stationRepository.Insert(stationName); txtName.Text = ""; MessageBox.Show(String.Format("Station {0} added with id = {1}.", stationName, id), "Success", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception exception) { MessageBox.Show(exception.Message, "Number error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void btnStation_Click(object sender, RoutedEventArgs e) { var stationRepositoty = new SqlStationRepository(_connectionString); var stationWindow = new StationWindow(_customer, stationRepositoty.SelectAll()); wndMainWindow.IsEnabled = false; stationWindow.ShowDialog(); wndMainWindow.IsEnabled = true; }
private void btnSearch_Click(object sender, RoutedEventArgs e) { string routeNumber = String.IsNullOrEmpty((string)cmbRoute.SelectedItem) ? null : (string)cmbRoute.SelectedItem; string busNumber = String.IsNullOrEmpty((string)cmbBus.SelectedItem) ? null : (string)cmbBus.SelectedItem; var stationSqlRepository = new SqlStationRepository(_connectionString); dgrDataStations.ItemsSource = stationSqlRepository.SearchAll(routeNumber, busNumber); }
private void btnAdd_Click(object sender, RoutedEventArgs e) { var addStationWindow = new AddStationWindow(); wndStation.IsEnabled = false; addStationWindow.ShowDialog(); var stationRepository = new SqlStationRepository(_connectionString); dgrDataStations.ItemsSource = stationRepository.SelectAll(); wndStation.IsEnabled = true; }
public AddRouteWindow(Customer customer) { InitializeComponent(); var stationRepository = new SqlStationRepository(_connectionString); List <string> stations = stationRepository.GetAllNames(); dgrStation.ItemsSource = stations; dgrAddedStation.ItemsSource = new List <string>(); _customer = customer; txtNumber.Focus(); }
private void btnStation_Click(object sender, RoutedEventArgs e) { var stationRepository = new SqlStationRepository(_connectionString); if (dgrDataSchedule.SelectedItem == null) { MessageBox.Show("Not selected schedule.", "Selection", MessageBoxButton.OK, MessageBoxImage.Error); return; } int scheduleId = ((TimeTable)dgrDataSchedule.SelectedItem).Id; var stationWindow = new StationWindow(_customer, stationRepository.GetStationBySchedule(scheduleId)); wndSchedule.Close(); stationWindow.ShowDialog(); }
private void btnStations_Click(object sender, RoutedEventArgs e) { var stationRepository = new SqlStationRepository(_connectionString); if (dgrDataDrivers.SelectedItem == null) { MessageBox.Show("Not selected driver.", "Selection", MessageBoxButton.OK, MessageBoxImage.Error); return; } int driverId = ((Driver)dgrDataDrivers.SelectedItem).Id; var stationWindow = new StationWindow(_customer, stationRepository.GetStationByDriver(driverId)); wndDriver.Close(); stationWindow.ShowDialog(); }
private void btnDelete_Click(object sender, RoutedEventArgs e) { var stationRepository = new SqlStationRepository(_connectionString); if (dgrDataStations.SelectedItem == null) { MessageBox.Show("Not selected station.", "Selection", MessageBoxButton.OK, MessageBoxImage.Error); return; } int stationId = ((BusStation)dgrDataStations.SelectedItem).Id; MessageBoxResult answer = MessageBox.Show(String.Format("You really want to delete bus {0}?", ((BusStation)dgrDataStations.SelectedItem).Name), "Deleting", MessageBoxButton.YesNo, MessageBoxImage.Question); if (answer == MessageBoxResult.Yes) { stationRepository.Delete(stationId); dgrDataStations.ItemsSource = stationRepository.SelectAll(); } }
public ModifyRouteWindow(Customer customer, Route route) { InitializeComponent(); _customer = customer; _route = route; txtNumber.Text = _route.Number; txtDistance.Text = _route.Distance.ToString(); txtDuration.Text = _route.Duration.ToString(); txtPrice.Text = _route.Price.ToString(); var stationRepository = new SqlStationRepository(_connectionString); _stations = stationRepository.GetStationByRoute(_route.Id); List <string> allStationName = stationRepository.GetAllNames(); List <string> addedStations = new List <string>(); foreach (BusStation station in _stations) { addedStations.Add(station.Name); } List <string> notAddedStations = new List <string>(); for (var i = 0; i < allStationName.Count; i++) { if (!addedStations.Contains(allStationName[i])) { notAddedStations.Add(allStationName[i]); } } dgrAddedStation.ItemsSource = addedStations; dgrStation.ItemsSource = notAddedStations; txtNumber.Focus(); }
public RouteWindow(Customer customer, List <Route> routes) { InitializeComponent(); _customer = customer; if (_customer.Mode == Mode.User) { btnAdd.Visibility = Visibility.Hidden; btnDelete.Visibility = Visibility.Hidden; btnModify.Visibility = Visibility.Hidden; } var stationRepository = new SqlStationRepository(_connectionString); List <string> stations = stationRepository.GetAllNames(); stations.Insert(0, ""); cmbStation.ItemsSource = stations; cmbStation.SelectedItem = ""; dgrDataRoutes.ItemsSource = routes; }
private void btnAdd_Click(object sender, RoutedEventArgs e) { if (String.IsNullOrEmpty(txtNumber.Text)) { MessageBox.Show("No name", "Empty field", MessageBoxButton.OK, MessageBoxImage.Error); return; } string number = txtNumber.Text; if (String.IsNullOrEmpty(txtDistance.Text)) { MessageBox.Show("No distance", "Empty field", MessageBoxButton.OK, MessageBoxImage.Error); return; } int distance = 0; if (!int.TryParse(txtDistance.Text, out distance)) { MessageBox.Show("Distance is not integer", "Cast error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (distance <= 0) { MessageBox.Show("Distance <= 0", "Cast error", MessageBoxButton.OK, MessageBoxImage.Error); return; } int duration = 0; if (!int.TryParse(txtDuration.Text, out duration)) { MessageBox.Show("Duration is not integer", "Cast error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (duration <= 0) { MessageBox.Show("Duration <= 0", "Cast error", MessageBoxButton.OK, MessageBoxImage.Error); return; } int price = 0; if (!int.TryParse(txtPrice.Text, out price)) { MessageBox.Show("Price is not integer", "Cast error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (price <= 0) { MessageBox.Show("Price <= 0", "Cast error", MessageBoxButton.OK, MessageBoxImage.Error); return; } List <string> addedStations = (List <string>)dgrAddedStation.ItemsSource; if (addedStations.Count < 2) { MessageBox.Show("Route must have at least 2 stations", "Stations error", MessageBoxButton.OK, MessageBoxImage.Error); return; } var routeRepository = new SqlRouteRepository(_connectionString); var newRoute = new Route() { Number = number, Distance = distance, Duration = duration, Price = price }; try { int id = routeRepository.Insert(_customer.Id, newRoute); for (var i = 0; i < addedStations.Count; i++) { routeRepository.AddStationToRoute(number, addedStations[i], i + 1); } txtNumber.Text = ""; txtDuration.Text = ""; txtDistance.Text = ""; txtPrice.Text = ""; var stationRepository = new SqlStationRepository(_connectionString); dgrStation.ItemsSource = stationRepository.GetAllNames(); dgrAddedStation.ItemsSource = new List <string>(); MessageBox.Show(String.Format("Route {0} added with id = {1}.", number, id), "Success", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception exception) { MessageBox.Show(exception.Message, "Number error", MessageBoxButton.OK, MessageBoxImage.Error); } }