Esempio n. 1
0
        //creates a route and returns if success
        private Boolean createRoute()
        {
            Route   route        = null;
            Airport destination1 = (Airport)cbDestination1.SelectedItem;
            Airport destination2 = (Airport)cbDestination2.SelectedItem;
            Airport stopover1    = (Airport)cbStopover1.SelectedItem;
            Airport stopover2    = cbStopover2.Visibility == System.Windows.Visibility.Visible ? (Airport)cbStopover2.SelectedItem : null;

            try
            {
                if (AirlineHelpers.IsRouteDestinationsOk(GameObject.GetInstance().HumanAirline, destination1, destination2, rbPassenger.IsChecked.Value ? Route.RouteType.Passenger : Route.RouteType.Cargo, stopover1, stopover2))
                {
                    Guid id = Guid.NewGuid();

                    //passenger route
                    if (rbPassenger.IsChecked.Value)
                    {
                        route = new PassengerRoute(id.ToString(), destination1, destination2, 0);

                        foreach (MVVMRouteClass rac in this.Classes)
                        {
                            ((PassengerRoute)route).getRouteAirlinerClass(rac.Type).FarePrice = rac.FarePrice;

                            foreach (MVVMRouteFacility facility in rac.Facilities)
                            {
                                ((PassengerRoute)route).getRouteAirlinerClass(rac.Type).addFacility(facility.SelectedFacility);
                            }
                        }
                    }
                    //cargo route
                    else
                    {
                        double cargoPrice = Convert.ToDouble(txtCargoPrice.Text);
                        route = new CargoRoute(id.ToString(), destination1, destination2, cargoPrice);
                    }

                    FleetAirlinerHelpers.CreateStopoverRoute(route, stopover1, stopover2);

                    GameObject.GetInstance().HumanAirline.addRoute(route);

                    return(true);
                }
            }
            catch (Exception ex)
            {
                WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", ex.Message), Translator.GetInstance().GetString("MessageBox", ex.Message, "message"), WPFMessageBoxButtons.Ok);

                return(false);
            }

            return(false);
        }
Esempio n. 2
0
        //creates a route and returns if success
        private Boolean createRoute()
        {
            Route    route        = null;
            Airport  destination1 = (Airport)cbDestination1.SelectedItem;
            Airport  destination2 = (Airport)cbDestination2.SelectedItem;
            Airport  stopover1    = (Airport)cbStopover1.SelectedItem;
            Airport  stopover2    = cbStopover2.Visibility == System.Windows.Visibility.Visible ? (Airport)cbStopover2.SelectedItem : null;
            DateTime startDate    = dpStartDate.IsEnabled && dpStartDate.SelectedDate.HasValue ? dpStartDate.SelectedDate.Value : GameObject.GetInstance().GameTime;

            Weather.Season season = rbSeasonAll.IsChecked.Value ? Weather.Season.All_Year : Weather.Season.Winter;
            season = rbSeasonSummer.IsChecked.Value ? Weather.Season.Summer : season;
            season = rbSeasonWinter.IsChecked.Value ? Weather.Season.Winter : season;

            try
            {
                if (AirlineHelpers.IsRouteDestinationsOk(GameObject.GetInstance().HumanAirline, destination1, destination2, this.RouteType, stopover1, stopover2))
                {
                    Guid id = Guid.NewGuid();

                    //passenger route
                    if (this.RouteType == Route.RouteType.Passenger)
                    {
                        //Vis på showroute
                        route = new PassengerRoute(id.ToString(), destination1, destination2, startDate, 0);

                        foreach (MVVMRouteClass rac in this.Classes)
                        {
                            ((PassengerRoute)route).getRouteAirlinerClass(rac.Type).FarePrice = rac.FarePrice;

                            foreach (MVVMRouteFacility facility in rac.Facilities)
                            {
                                ((PassengerRoute)route).getRouteAirlinerClass(rac.Type).addFacility(facility.SelectedFacility);
                            }
                        }
                    }
                    //cargo route
                    else if (this.RouteType == Route.RouteType.Cargo)
                    {
                        double cargoPrice = Convert.ToDouble(txtCargoPrice.Text);
                        route = new CargoRoute(id.ToString(), destination1, destination2, startDate, cargoPrice);
                    }
                    else if (this.RouteType == Route.RouteType.Mixed)
                    {
                        double cargoPrice = Convert.ToDouble(txtCargoPrice.Text);

                        route = new CombiRoute(id.ToString(), destination1, destination2, startDate, 0, cargoPrice);

                        foreach (MVVMRouteClass rac in this.Classes)
                        {
                            ((PassengerRoute)route).getRouteAirlinerClass(rac.Type).FarePrice = rac.FarePrice;

                            foreach (MVVMRouteFacility facility in rac.Facilities)
                            {
                                ((PassengerRoute)route).getRouteAirlinerClass(rac.Type).addFacility(facility.SelectedFacility);
                            }
                        }
                    }

                    FleetAirlinerHelpers.CreateStopoverRoute(route, stopover1, stopover2);

                    route.Season = season;

                    GameObject.GetInstance().HumanAirline.addRoute(route);

                    return(true);
                }
            }
            catch (Exception ex)
            {
                WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", ex.Message), Translator.GetInstance().GetString("MessageBox", ex.Message, "message"), WPFMessageBoxButtons.Ok);

                return(false);
            }

            return(false);
        }
Esempio n. 3
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            Airline airline   = GameObject.GetInstance().HumanAirline;
            Airport dest1     = (Airport)cbDestination1.SelectedItem;
            Airport dest2     = (Airport)cbDestination2.SelectedItem;
            Airport stopover1 = ucStopover1.Value;
            Airport stopover2 = ucStopover2.Value;

            Boolean stopoverOk = (stopover1 == null ? true : AirportHelpers.HasFreeGates(stopover1, airline)) && (stopover2 == null ? true : AirportHelpers.HasFreeGates(stopover2, airline));

            if (AirportHelpers.HasFreeGates(dest1, airline) && AirportHelpers.HasFreeGates(dest2, airline) && stopoverOk)
            {
                Route route = null;
                Guid  id    = Guid.NewGuid();

                if (this.RouteType == Route.RouteType.Passenger)
                {
                    route = new PassengerRoute(id.ToString(), dest1, dest2, 0);

                    foreach (RouteAirlinerClass aClass in this.Classes.Values)
                    {
                        ((PassengerRoute)route).getRouteAirlinerClass(aClass.Type).FarePrice = aClass.FarePrice;

                        foreach (RouteFacility facility in aClass.getFacilities())
                        {
                            ((PassengerRoute)route).getRouteAirlinerClass(aClass.Type).addFacility(facility);
                        }

                        ((PassengerRoute)route).getRouteAirlinerClass(aClass.Type).Seating = aClass.Seating;
                    }
                }
                if (this.RouteType == Route.RouteType.Cargo)
                {
                    route = new CargoRoute(id.ToString(), dest1, dest2, this.CargoPrice);
                }


                if (stopover1 != null)
                {
                    if (stopover2 != null)
                    {
                        route.addStopover(FleetAirlinerHelpers.CreateStopoverRoute(dest1, stopover1, stopover2, route, false, this.RouteType));
                    }
                    else
                    {
                        route.addStopover(FleetAirlinerHelpers.CreateStopoverRoute(dest1, stopover1, dest2, route, false, this.RouteType));
                    }
                }

                if (stopover2 != null)
                {
                    if (stopover1 != null)
                    {
                        route.addStopover(FleetAirlinerHelpers.CreateStopoverRoute(stopover1, stopover2, dest2, route, true, this.RouteType));
                    }
                    else
                    {
                        route.addStopover(FleetAirlinerHelpers.CreateStopoverRoute(dest1, stopover2, dest2, route, false, this.RouteType));
                    }
                }

                airline.addRoute(route);

                PageNavigator.NavigateTo(new PageRoutes());

                this.Visibility = System.Windows.Visibility.Collapsed;

                route.LastUpdated = GameObject.GetInstance().GameTime;
            }
            else
            {
                WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2501"), Translator.GetInstance().GetString("MessageBox", "2501", "message"), WPFMessageBoxButtons.Ok);
            }
        }