public StationWindow(Customer customer, List <BusStation> stations)
        {
            InitializeComponent();

            _customer = customer;
            if (_customer.Mode == Mode.User)
            {
                btnAdd.Visibility    = Visibility.Hidden;
                btnDelete.Visibility = Visibility.Hidden;
            }

            var routeRepository = new SqlRouteRepository(_connectionString);

            List <string> routes = routeRepository.GetAllNumbers();

            routes.Insert(0, "");

            cmbRoute.ItemsSource  = routes;
            cmbRoute.SelectedItem = "";

            var busRepository = new SqlBusRepository(_connectionString);

            List <string> buses = busRepository.GetAllNumbers();

            buses.Insert(0, "");

            cmbBus.ItemsSource  = buses;
            cmbBus.SelectedItem = "";

            dgrDataStations.ItemsSource = stations;
        }
        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 btnRoutes_Click(object sender, RoutedEventArgs e)
        {
            var routeRepository = new SqlRouteRepository(_connectionString);
            var routeWindow     = new RouteWindow(_customer, routeRepository.SelectAll());

            wndMainWindow.IsEnabled = false;
            routeWindow.ShowDialog();
            wndMainWindow.IsEnabled = true;
        }
Beispiel #4
0
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            var addRouteWindow = new AddRouteWindow(_customer);

            wndRoute.IsEnabled = false;
            addRouteWindow.ShowDialog();

            var routeRepository = new SqlRouteRepository(_connectionString);

            dgrDataRoutes.ItemsSource = routeRepository.SelectAll();

            wndRoute.IsEnabled = true;
        }
Beispiel #5
0
        private void btnModify_Click(object sender, RoutedEventArgs e)
        {
            if (dgrDataRoutes.SelectedItem == null)
            {
                MessageBox.Show("Not selected route.", "Selection", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            Route route = (Route)dgrDataRoutes.SelectedItem;

            var modifyRouteWindow = new ModifyRouteWindow(_customer, route);

            modifyRouteWindow.ShowDialog();

            var routeRepository = new SqlRouteRepository(_connectionString);

            dgrDataRoutes.ItemsSource = routeRepository.SelectAll();
        }
Beispiel #6
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            var routeRepository = new SqlRouteRepository(_connectionString);

            if (dgrDataRoutes.SelectedItem == null)
            {
                MessageBox.Show("Not selected route.", "Selection", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            int routeId = ((Route)dgrDataRoutes.SelectedItem).Id;

            MessageBoxResult answer = MessageBox.Show(String.Format("You really want to delete route {0} and all related objects?",
                                                                    ((Route)dgrDataRoutes.SelectedItem).Number), "Deleting", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (answer == MessageBoxResult.Yes)
            {
                routeRepository.Delete(routeId);
                dgrDataRoutes.ItemsSource = routeRepository.SelectAll();
            }
        }
Beispiel #7
0
        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            string stationName = String.IsNullOrEmpty((string)cmbStation.SelectedItem) ? null : (string)cmbStation.SelectedItem;

            int?maxPrice = null;

            if (!String.IsNullOrEmpty(txtMaxPrice.Text))
            {
                int max;
                if (int.TryParse(txtMaxPrice.Text, out max))
                {
                    maxPrice = max;
                }
                else
                {
                    MessageBox.Show("Price is not integer.", "Cast error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }

            int?maxDuration = null;

            if (!String.IsNullOrEmpty(txtMaxDuration.Text))
            {
                int max;
                if (int.TryParse(txtMaxDuration.Text, out max))
                {
                    maxDuration = max;
                }
                else
                {
                    MessageBox.Show("Duration is not integer.", "Cast error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }

            var routeSqlRepository = new SqlRouteRepository(_connectionString);

            dgrDataRoutes.ItemsSource = routeSqlRepository.SearchAll(stationName, maxPrice, maxDuration);
        }
Beispiel #8
0
        private void btnModify_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);

            number = number == _route.Number ? null : number;

            int?distanceRoute = null;

            if (distance != _route.Distance)
            {
                distanceRoute = distance;
            }

            int?durationRoute = null;

            if (duration != _route.Duration)
            {
                durationRoute = duration;
            }

            int?priceRoute = null;

            if (price != _route.Price)
            {
                priceRoute = price;
            }

            try
            {
                routeRepository.Update(_customer.Id, _route.Id, number, durationRoute, distanceRoute, priceRoute);
                for (var i = 0; i < _stations.Count; i++)
                {
                    routeRepository.DeleteStationToRoute(_stations[i].Name, _route.Id);
                }

                for (var i = 0; i < addedStations.Count; i++)
                {
                    routeRepository.AddStationToRoute(_route.Number, addedStations[i], i + 1);
                }

                wndModifyRoute.Close();
                if (number != null || durationRoute != null || distanceRoute != null || priceRoute != null)
                {
                    MessageBox.Show(String.Format("Route {0} updated.", number), "Success", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "Number error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        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);
            }
        }