コード例 #1
0
ファイル: AirlineMVVM.cs プロジェクト: petfol/tap-desktop
        public AirlineMVVM(Airline airline)
        {
            this.Airline = airline;

            this.Alliance = this.Airline.Alliances.Count == 0 ? null : this.Airline.Alliances[0];

            this.DeliveredFleet = new ObservableCollection <FleetAirliner>();
            foreach (FleetAirliner airliner in this.Airline.Fleet.FindAll(a => a.Airliner.BuiltDate <= GameObject.GetInstance().GameTime))
            {
                this.DeliveredFleet.Add(airliner);
            }

            this.OrderedFleet = this.Airline.Fleet.FindAll(a => a.Airliner.BuiltDate > GameObject.GetInstance().GameTime);
            this.Finances     = new ObservableCollection <AirlineFinanceMVVM>();
            this.LoanRate     = GeneralHelpers.GetAirlineLoanRate(this.Airline);

            this.Loans              = new ObservableCollection <LoanMVVM>();
            this.Pilots             = new ObservableCollection <PilotMVVM>();
            this.Wages              = new ObservableCollection <AirlineFeeMVVM>();
            this.Discounts          = new ObservableCollection <AirlineFeeMVVM>();
            this.Facilities         = new ObservableCollection <AirlineFacilityMVVM>();
            this.TrainingFacilities = new ObservableCollection <AirlineFacilityMVVM>();
            this.Fees            = new ObservableCollection <AirlineFeeMVVM>();
            this.Chargers        = new ObservableCollection <AirlineFeeMVVM>();
            this.Subsidiaries    = new ObservableCollection <SubsidiaryAirline>();
            this.Insurances      = new ObservableCollection <AirlineInsurance>();
            this.Advertisements  = new ObservableCollection <AirlineAdvertisementMVVM>();
            this.Destinations    = new ObservableCollection <AirlineDestinationMVVM>();
            this.AirlineAirlines = new ObservableCollection <Airline>();
            this.FundsAirlines   = new ObservableCollection <Airline>();
            this.Routes          = new List <AirlineRouteMVVM>();
            this.Codeshares      = new ObservableCollection <Airline>();
            this.Cooperations    = new List <CooperationMVVM>();

            this.Airline.Routes.ForEach(r => this.Routes.Add(new AirlineRouteMVVM(r)));
            this.Airline.Loans.FindAll(l => l.IsActive).ForEach(l => this.Loans.Add(new LoanMVVM(l, this.Airline)));
            this.Airline.Pilots.ForEach(p => this.Pilots.Add(new PilotMVVM(p)));

            this.UnassignedPilots = this.Pilots.Count(p => p.Pilot.Airliner == null);
            this.PilotsToRetire   = this.Pilots.Count(p => p.Pilot.Profile.Age == Pilot.RetirementAge - 1);

            FeeTypes.GetTypes(FeeType.eFeeType.Wage).FindAll(f => f.FromYear <= GameObject.GetInstance().GameTime.Year).ForEach(f => this.Wages.Add(new AirlineFeeMVVM(f, this.Airline.Fees.getValue(f))));
            FeeTypes.GetTypes(FeeType.eFeeType.Discount).FindAll(f => f.FromYear <= GameObject.GetInstance().GameTime.Year).ForEach(f => this.Discounts.Add(new AirlineFeeMVVM(f, this.Airline.Fees.getValue(f))));

            FeeTypes.GetTypes(FeeType.eFeeType.FoodDrinks).FindAll(f => f.FromYear <= GameObject.GetInstance().GameTime.Year).ForEach(f => this.Chargers.Add(new AirlineFeeMVVM(f, this.Airline.Fees.getValue(f))));

            FeeTypes.GetTypes(FeeType.eFeeType.Fee).FindAll(f => f.FromYear <= GameObject.GetInstance().GameTime.Year).ForEach(f => this.Fees.Add(new AirlineFeeMVVM(f, this.Airline.Fees.getValue(f))));

            this.Airline.Subsidiaries.ForEach(s => this.Subsidiaries.Add(s));
            this.Airline.InsurancePolicies.ForEach(i => this.Insurances.Add(i));
            this.Airline.Codeshares.ForEach(c => this.Codeshares.Add(c.Airline1 == this.Airline ? c.Airline2 : c.Airline1));

            foreach (Airport airport in this.Airline.Airports)
            {
                foreach (Cooperation cooperation in airport.Cooperations.Where(c => c.Airline == this.Airline))
                {
                    this.Cooperations.Add(new CooperationMVVM(airport, cooperation));
                }
            }

            setValues();

            this.Colors = new List <PropertyInfo>();

            foreach (PropertyInfo c in typeof(Colors).GetProperties())
            {
                this.Colors.Add(c);
            }

            foreach (Airport airport in this.Airline.Airports.OrderByDescending(a => this.Airline.Airports[0] == a).ThenBy(a => a.Profile.Name))
            {
                this.Destinations.Add(new AirlineDestinationMVVM(airport, airport.hasHub(this.Airline)));
            }

            double buyingPrice = this.Airline.getValue() * 1000000 * 1.10;

            this.IsBuyable = !this.Airline.IsHuman && GameObject.GetInstance().HumanAirline.Money > buyingPrice;

            this.ActiveQuantity  = new List <AirlinerQuantityMVVM>();
            this.OrderedQuantity = new List <AirlinerQuantityMVVM>();

            var fleet = new List <FleetAirliner>(this.Airline.Fleet);

            foreach (FleetAirliner airliner in fleet)
            {
                if (airliner.Airliner.BuiltDate > GameObject.GetInstance().GameTime)
                {
                    if (this.OrderedQuantity.Any(o => o.Type == airliner.Airliner.Type))
                    {
                        this.OrderedQuantity.First(o => o.Type == airliner.Airliner.Type).Quantity++;
                    }
                    else
                    {
                        this.OrderedQuantity.Add(new AirlinerQuantityMVVM(airliner.Airliner.Type, 1));
                    }
                }
                else
                {
                    if (this.ActiveQuantity.Any(o => o.Type == airliner.Airliner.Type))
                    {
                        this.ActiveQuantity.First(o => o.Type == airliner.Airliner.Type).Quantity++;
                    }
                    else
                    {
                        this.ActiveQuantity.Add(new AirlinerQuantityMVVM(airliner.Airliner.Type, 1));
                    }
                }
            }

            this.HasAlliance = this.Alliance != null || this.Codeshares.Count > 0;
        }
コード例 #2
0
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double amount = System.Convert.ToDouble(values[0]);
            int    lenght = System.Convert.ToInt16(values[1]) * 12;

            return(new ValueCurrencyConverter().Convert(MathHelpers.GetMonthlyPayment(amount, GeneralHelpers.GetAirlineLoanRate(GameObject.GetInstance().HumanAirline), lenght) * GameObject.GetInstance().Difficulty.LoanLevel));
        }
コード例 #3
0
        public AirlineMVVM(Airline airline)
        {
            this.Airline = airline;

            this.Alliance = this.Airline.Alliances.Count == 0 ? null : this.Airline.Alliances[0];

            this.DeliveredFleet = new ObservableCollection <FleetAirliner>();
            foreach (FleetAirliner airliner in this.Airline.Fleet.FindAll(a => a.Airliner.BuiltDate <= GameObject.GetInstance().GameTime))
            {
                this.DeliveredFleet.Add(airliner);
            }

            this.OrderedFleet = this.Airline.Fleet.FindAll(a => a.Airliner.BuiltDate > GameObject.GetInstance().GameTime);
            this.Finances     = new ObservableCollection <AirlineFinanceMVVM>();
            this.LoanRate     = GeneralHelpers.GetAirlineLoanRate(this.Airline);

            this.Loans           = new ObservableCollection <LoanMVVM>();
            this.Pilots          = new ObservableCollection <Pilot>();
            this.Wages           = new ObservableCollection <AirlineFeeMVVM>();
            this.Discounts       = new ObservableCollection <AirlineFeeMVVM>();
            this.Facilities      = new ObservableCollection <AirlineFacilityMVVM>();
            this.Fees            = new ObservableCollection <AirlineFeeMVVM>();
            this.Chargers        = new ObservableCollection <AirlineFeeMVVM>();
            this.Subsidiaries    = new ObservableCollection <SubsidiaryAirline>();
            this.Insurances      = new ObservableCollection <AirlineInsurance>();
            this.Advertisements  = new ObservableCollection <AirlineAdvertisementMVVM>();
            this.Destinations    = new ObservableCollection <AirlineDestinationMVVM>();
            this.AirlineAirlines = new ObservableCollection <Airline>();

            this.Airline.Loans.FindAll(l => l.IsActive).ForEach(l => this.Loans.Add(new LoanMVVM(l)));
            this.Airline.Pilots.ForEach(p => this.Pilots.Add(p));

            FeeTypes.GetTypes(FeeType.eFeeType.Wage).FindAll(f => f.FromYear <= GameObject.GetInstance().GameTime.Year).ForEach(f => this.Wages.Add(new AirlineFeeMVVM(f, this.Airline.Fees.getValue(f))));
            FeeTypes.GetTypes(FeeType.eFeeType.Discount).FindAll(f => f.FromYear <= GameObject.GetInstance().GameTime.Year).ForEach(f => this.Discounts.Add(new AirlineFeeMVVM(f, this.Airline.Fees.getValue(f))));

            FeeTypes.GetTypes(FeeType.eFeeType.FoodDrinks).FindAll(f => f.FromYear <= GameObject.GetInstance().GameTime.Year).ForEach(f => this.Chargers.Add(new AirlineFeeMVVM(f, this.Airline.Fees.getValue(f))));

            FeeTypes.GetTypes(FeeType.eFeeType.Fee).FindAll(f => f.FromYear <= GameObject.GetInstance().GameTime.Year).ForEach(f => this.Fees.Add(new AirlineFeeMVVM(f, this.Airline.Fees.getValue(f))));

            this.Airline.Subsidiaries.ForEach(s => this.Subsidiaries.Add(s));
            this.Airline.InsurancePolicies.ForEach(i => this.Insurances.Add(i));

            setValues();

            this.Colors = new List <PropertyInfo>();

            foreach (PropertyInfo c in typeof(Colors).GetProperties())
            {
                this.Colors.Add(c);
            }

            foreach (Airport airport in this.Airline.Airports.OrderByDescending(a => this.Airline.Airports[0] == a).ThenBy(a => a.Profile.Name))
            {
                this.Destinations.Add(new AirlineDestinationMVVM(airport, airport.hasHub(this.Airline)));
            }


            double buyingPrice = this.Airline.getValue() * 1000000 * 1.10;

            this.IsBuyable = !this.Airline.IsHuman && GameObject.GetInstance().HumanAirline.Money > buyingPrice;
        }
コード例 #4
0
        public PopUpLoan()
        {
            InitializeComponent();
            this.Uid = "1000";

            this.Title = Translator.GetInstance().GetString("PopUpLoan", this.Uid);

            this.Width = 400;

            this.Height = 175;

            this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;

            StackPanel mainPanel = new StackPanel();

            mainPanel.Margin = new Thickness(10, 10, 10, 10);

            ListBox lbLoan = new ListBox();

            lbLoan.ItemContainerStyleSelector = new ListBoxItemStyleSelector();
            lbLoan.SetResourceReference(ListBox.ItemTemplateProperty, "QuickInfoItem");


            cbAmount = new ComboBox();
            cbAmount.SetResourceReference(ComboBox.StyleProperty, "ComboBoxTransparentStyle");
            cbAmount.Width = 150;
            cbAmount.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Right;
            cbAmount.ItemStringFormat           = "{0:c}";
            cbAmount.SelectionChanged          += new SelectionChangedEventHandler(cbLoan_SelectionChanged);

            cbAmount.Items.Add(1000000);
            cbAmount.Items.Add(5000000);
            cbAmount.Items.Add(10000000);
            cbAmount.Items.Add(25000000);
            cbAmount.Items.Add(50000000);
            cbAmount.Items.Add(75000000);
            cbAmount.Items.Add(100000000);


            lbLoan.Items.Add(new QuickInfoValue("Amount", cbAmount));



            cblength = new ComboBox();
            cblength.SetResourceReference(ComboBox.StyleProperty, "ComboBoxTransparentStyle");
            cblength.Width = 150;
            cblength.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Right;
            cblength.SelectionChanged          += new SelectionChangedEventHandler(cbLoan_SelectionChanged);

            cblength.Items.Add(1);
            cblength.Items.Add(2);
            cblength.Items.Add(5);
            cblength.Items.Add(10);
            cblength.Items.Add(20);
            cblength.Items.Add(25);

            lbLoan.Items.Add(new QuickInfoValue("length in years", cblength));

            txtMonthlyPayment       = new TextBlock();
            txtMonthlyPayment.Width = 150;

            lbLoan.Items.Add(new QuickInfoValue("Monthly payment", txtMonthlyPayment));

            lbLoan.Items.Add(new QuickInfoValue("Rate (Airline value)", UICreator.CreateTextBlock(string.Format("{0}%", GeneralHelpers.GetAirlineLoanRate(GameObject.GetInstance().HumanAirline)))));
            mainPanel.Children.Add(lbLoan);

            mainPanel.Children.Add(createButtonsPanel());

            this.Content = mainPanel;

            cblength.SelectedIndex = 0;
            cbAmount.SelectedIndex = 0;
        }
コード例 #5
0
        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            double amount = Convert.ToDouble(cbAmount.SelectedItem);
            int    length = Convert.ToInt16(cblength.SelectedItem) * 12;

            this.Selected = new Loan(GameObject.GetInstance().GameTime, amount, length, GeneralHelpers.GetAirlineLoanRate(GameObject.GetInstance().HumanAirline));
            this.Close();
        }
コード例 #6
0
        private void cbLoan_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            double amount = Convert.ToDouble(cbAmount.SelectedItem);
            int    length = Convert.ToInt16(cblength.SelectedItem) * 12;

            txtMonthlyPayment.Text = new ValueCurrencyConverter().Convert(MathHelpers.GetMonthlyPayment(amount, GeneralHelpers.GetAirlineLoanRate(GameObject.GetInstance().HumanAirline), length)).ToString();//string.Format("{0:c}",MathHelpers.GetMonthlyPayment(amount,GeneralHelpers.GetAirlineLoanRate(GameObject.GetInstance().HumanAirline),length));
        }