コード例 #1
0
        //orders the airliners
        private void orderAirliners(Airport airport, double discount = 0)
        {
            DateTime deliveryDate = getDeliveryDate();

            Guid id = Guid.NewGuid();

            foreach (AirlinerTypeMVVM type in this.SelectedAirliners)
            {
                Airliner airliner = new Airliner(id.ToString(), type.Type, GameObject.GetInstance().HumanAirline.Profile.Country.TailNumbers.getNextTailNumber(), deliveryDate);
                Model.AirlinerModel.Airliners.AddAirliner(airliner);

                FleetAirliner.PurchasedType pType = FleetAirliner.PurchasedType.Bought;
                GameObject.GetInstance().HumanAirline.addAirliner(pType, airliner, airport);

                airliner.clearAirlinerClasses();

                AirlinerHelpers.CreateAirlinerClasses(airliner);

                foreach (AirlinerClass aClass in airliner.Classes)
                {
                    foreach (AirlinerFacility facility in aClass.getFacilities())
                    {
                        aClass.setFacility(GameObject.GetInstance().HumanAirline, facility);
                    }
                }
            }

            int    totalAmount = this.SelectedAirliners.Count;
            double price       = this.SelectedAirliners.Sum(a => a.Type.Price);

            double totalPrice = price * ((1 - GeneralHelpers.GetAirlinerOrderDiscount(totalAmount))) * ((100 - discount) / 100);

            AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -totalPrice);
        }
コード例 #2
0
        private void order_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            long price = this.Orders.Sum(o => o.Type.Price * o.Amount);

            this.Discount = Convert.ToInt64(price * (GeneralHelpers.GetAirlinerOrderDiscount(this.Orders.Sum(o => o.Amount)) / 100));

            if (GameObject.GetInstance().HumanAirline.Contract != null && GameObject.GetInstance().HumanAirline.Contract.Manufacturer == this.Orders.First().Type.Manufacturer)
            {
                this.Discount += Convert.ToInt64(price * (GameObject.GetInstance().HumanAirline.Contract.Discount / 100));
            }

            this.TotalAmount = price - this.Discount;
        }
コード例 #3
0
        //the update for the order
        public void orderUpdated()
        {
            long price = this.Orders.Sum(o => o.getOrderPrice());

            this.Discount = Convert.ToInt64(price * (GeneralHelpers.GetAirlinerOrderDiscount(this.Orders.Sum(o => o.Amount)) / 100));

            if (GameObject.GetInstance().HumanAirline.Contract != null && this.Orders.Count > 0 && GameObject.GetInstance().HumanAirline.Contract.Manufacturer == this.Orders.First().Type.Manufacturer)
            {
                this.Discount += Convert.ToInt64(price * (GameObject.GetInstance().HumanAirline.Contract.Discount / 100));
            }

            this.TotalAmount = price - this.Discount;

            this.DeliveryDate = getDeliveryDate();
        }
コード例 #4
0
        //orders the airliners
        private void orderAirliners(double discount = 0)
        {
            DateTime deliveryDate = this.Orders.getDeliveryDate();

            Guid id = Guid.NewGuid();

            foreach (AirlinerOrderMVVM order in this.Orders.Orders)
            {
                for (int i = 0; i < order.Amount; i++)
                {
                    Airliner airliner = new Airliner(id.ToString(), order.Type, GameObject.GetInstance().HumanAirline.Profile.Country.TailNumbers.getNextTailNumber(), deliveryDate);
                    Model.AirlinerModel.Airliners.AddAirliner(airliner);

                    FleetAirliner.PurchasedType pType = FleetAirliner.PurchasedType.Bought;
                    GameObject.GetInstance().HumanAirline.addAirliner(pType, airliner, order.Homebase);

                    airliner.clearAirlinerClasses();

                    foreach (AirlinerClass aClass in order.Classes)
                    {
                        AirlinerClass tClass = new AirlinerClass(aClass.Type, aClass.SeatingCapacity);
                        tClass.RegularSeatingCapacity = aClass.RegularSeatingCapacity;

                        foreach (AirlinerFacility facility in aClass.getFacilities())
                        {
                            tClass.setFacility(GameObject.GetInstance().HumanAirline, facility);
                        }

                        airliner.addAirlinerClass(tClass);
                    }
                }
            }

            int    totalAmount = this.Orders.Orders.Sum(o => o.Amount);
            double price       = this.Orders.Orders.Sum(o => o.Type.Price * o.Amount);

            double totalPrice = price * ((1 - GeneralHelpers.GetAirlinerOrderDiscount(totalAmount))) * ((100 - discount) / 100);

            AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -totalPrice);
        }
コード例 #5
0
        //shows the orders
        private void showOrders()
        {
            double  price           = 0;
            int     airliners       = 0;
            Boolean contractedOrder = false;

            lbOrders.Items.Clear();

            foreach (AirlinerOrder order in orders)
            {
                lbOrders.Items.Add(order);

                price     += order.Type.Price * order.Amount;
                airliners += order.Amount;
            }

            if (GameObject.GetInstance().HumanAirline.Contract != null && GameObject.GetInstance().HumanAirline.Contract.Manufacturer == this.Manufacturer)
            {
                contractedOrder = true;
            }

            double discount = price * (GeneralHelpers.GetAirlinerOrderDiscount(airliners) / 100); //price- price * + (GeneralHelpers.GetAirlinerOrderDiscount(airliners));<

            if (contractedOrder)
            {
                discount += price * (GameObject.GetInstance().HumanAirline.Contract.Discount / 100);
            }



            txtDiscount.Text   = new ValueCurrencyConverter().Convert(discount).ToString();         // string.Format("{0:C}", discount);
            txtTotalPrice.Text = new ValueCurrencyConverter().Convert(price - discount).ToString(); // string.Format("{0:C}", price - discount);

            showPossibleHomebases();

            btnOrder.IsEnabled = orders.Count > 0 && cbAirport.SelectedItem != null;
        }
コード例 #6
0
        private void btnOrder_Click(object sender, RoutedEventArgs e)
        {
            Boolean hasHomebases = true;

            foreach (AirlinerOrderMVVM order in this.Orders.Orders)
            {
                if (order.Homebase == null)
                {
                    hasHomebases = false;
                }
            }
            Boolean contractedOrder = false;
            Boolean tryOrder        = true;

            DateTime deliveryDate = this.Orders.getDeliveryDate();

            if (!hasHomebases)
            {
                WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2002"), Translator.GetInstance().GetString("MessageBox", "2002", "message"), WPFMessageBoxButtons.Ok);
            }
            else
            {
                if (GameObject.GetInstance().HumanAirline.Contract != null)
                {
                    if (GameObject.GetInstance().HumanAirline.Contract.Manufacturer == this.Manufacturer)
                    {
                        contractedOrder = true;
                    }
                    else
                    {
                        double terminationFee      = GameObject.GetInstance().HumanAirline.Contract.getTerminationFee();
                        WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2010"), string.Format(Translator.GetInstance().GetString("MessageBox", "2010", "message"), GameObject.GetInstance().HumanAirline.Contract.Manufacturer.Name, terminationFee), WPFMessageBoxButtons.YesNo);

                        if (result == WPFMessageBoxResult.Yes)
                        {
                            AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -terminationFee);
                            GameObject.GetInstance().HumanAirline.Contract = null;

                            this.Contract.Contracted = null;
                        }
                        tryOrder = result == WPFMessageBoxResult.Yes;
                    }
                }

                if (tryOrder)
                {
                    int    totalAmount = this.Orders.Orders.Sum(o => o.Amount);
                    double price       = this.Orders.Orders.Sum(o => o.Type.Price * o.Amount);

                    double totalPrice = price * ((1 - GeneralHelpers.GetAirlinerOrderDiscount(totalAmount)));

                    if (contractedOrder)
                    {
                        totalPrice = totalPrice * ((100 - GameObject.GetInstance().HumanAirline.Contract.Discount) / 100);
                    }

                    double downpaymentPrice = 0;

                    downpaymentPrice = totalPrice * (GameObject.GetInstance().Difficulty.PriceLevel / 10);

                    if (cbDownPayment.IsChecked.Value)
                    {
                        if (downpaymentPrice > GameObject.GetInstance().HumanAirline.Money)
                        {
                            WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2001"), Translator.GetInstance().GetString("MessageBox", "2001", "message"), WPFMessageBoxButtons.Ok);
                        }
                        else
                        {
                            WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2009"), string.Format(Translator.GetInstance().GetString("MessageBox", "2009", "message"), totalPrice, downpaymentPrice), WPFMessageBoxButtons.YesNo);

                            if (result == WPFMessageBoxResult.Yes)
                            {
                                foreach (AirlinerOrderMVVM order in this.Orders.Orders)
                                {
                                    for (int i = 0; i < order.Amount; i++)
                                    {
                                        Guid id = Guid.NewGuid();

                                        Airliner airliner = new Airliner(id.ToString(), order.Type, GameObject.GetInstance().HumanAirline.Profile.Country.TailNumbers.getNextTailNumber(), deliveryDate);

                                        airliner.clearAirlinerClasses();

                                        foreach (AirlinerClass aClass in order.Classes)
                                        {
                                            AirlinerClass tClass = new AirlinerClass(aClass.Type, aClass.SeatingCapacity);
                                            tClass.RegularSeatingCapacity = aClass.RegularSeatingCapacity;

                                            foreach (AirlinerFacility facility in aClass.getFacilities())
                                            {
                                                tClass.setFacility(GameObject.GetInstance().HumanAirline, facility);
                                            }

                                            airliner.addAirlinerClass(tClass);
                                        }


                                        Model.AirlinerModel.Airliners.AddAirliner(airliner);

                                        FleetAirliner.PurchasedType pType = FleetAirliner.PurchasedType.BoughtDownPayment;
                                        GameObject.GetInstance().HumanAirline.addAirliner(pType, airliner, order.Homebase);
                                    }
                                }
                                if (contractedOrder)
                                {
                                    GameObject.GetInstance().HumanAirline.Contract.PurchasedAirliners += this.Orders.Orders.Sum(o => o.Amount);
                                }
                                AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -downpaymentPrice);

                                TabControl tab_main = UIHelpers.FindChild <TabControl>(this.Tag as Page, "tabMenu");

                                if (tab_main != null)
                                {
                                    var matchingItem =
                                        tab_main.Items.Cast <TabItem>()
                                        .Where(item => item.Tag.ToString() == "Order")
                                        .FirstOrDefault();

                                    tab_main.SelectedItem = matchingItem;
                                }
                            }
                        }
                    }
                    else
                    {
                        if (totalPrice > GameObject.GetInstance().HumanAirline.Money)
                        {
                            WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2001"), Translator.GetInstance().GetString("MessageBox", "2001", "message"), WPFMessageBoxButtons.Ok);
                        }
                        else
                        {
                            if (this.Orders.Orders.Sum(o => o.Amount) > 0)
                            {
                                WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2008"), string.Format(Translator.GetInstance().GetString("MessageBox", "2008", "message"), totalPrice), WPFMessageBoxButtons.YesNo);

                                if (result == WPFMessageBoxResult.Yes)
                                {
                                    orderAirliners(contractedOrder ? GameObject.GetInstance().HumanAirline.Contract.Discount : 0);

                                    TabControl tab_main = UIHelpers.FindChild <TabControl>(this.Tag as Page, "tabMenu");

                                    if (tab_main != null)
                                    {
                                        var matchingItem =
                                            tab_main.Items.Cast <TabItem>()
                                            .Where(item => item.Tag.ToString() == "Order")
                                            .FirstOrDefault();

                                        tab_main.SelectedItem = matchingItem;
                                    }
                                }

                                if (contractedOrder)
                                {
                                    GameObject.GetInstance().HumanAirline.Contract.PurchasedAirliners += this.Orders.Orders.Sum(o => o.Amount);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #7
0
        private void btnOrder_Click(object sender, RoutedEventArgs e)
        {
            Boolean contractedOrder = false;
            Boolean tryOrder        = true;

            if (GameObject.GetInstance().HumanAirline.Contract != null)
            {
                Boolean sameManufaturer = this.SelectedAirliners.FirstOrDefault(a => a.Type.Manufacturer != GameObject.GetInstance().HumanAirline.Contract.Manufacturer) == null;

                if (sameManufaturer)
                {
                    contractedOrder = true;
                }
                else
                {
                    double terminationFee      = GameObject.GetInstance().HumanAirline.Contract.getTerminationFee();
                    WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2010"), string.Format(Translator.GetInstance().GetString("MessageBox", "2010", "message"), GameObject.GetInstance().HumanAirline.Contract.Manufacturer.Name, terminationFee), WPFMessageBoxButtons.YesNo);

                    if (result == WPFMessageBoxResult.Yes)
                    {
                        AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -terminationFee);
                        GameObject.GetInstance().HumanAirline.Contract = null;
                    }
                    tryOrder = result == WPFMessageBoxResult.Yes;
                }
            }

            if (tryOrder)
            {
                int    totalAmount = this.SelectedAirliners.Count;
                double price       = this.SelectedAirliners.Sum(a => a.Type.Price);

                double totalPrice = price * ((1 - GeneralHelpers.GetAirlinerOrderDiscount(totalAmount)));

                if (contractedOrder)
                {
                    totalPrice = totalPrice * ((100 - GameObject.GetInstance().HumanAirline.Contract.Discount) / 100);
                }

                if (totalPrice > GameObject.GetInstance().HumanAirline.Money)
                {
                    WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2001"), Translator.GetInstance().GetString("MessageBox", "2001", "message"), WPFMessageBoxButtons.Ok);
                }
                else
                {
                    ComboBox cbHomebase = new ComboBox();
                    cbHomebase.SetResourceReference(ComboBox.StyleProperty, "ComboBoxTransparentStyle");
                    cbHomebase.ItemTemplate        = Application.Current.Resources["AirportCountryItem"] as DataTemplate;
                    cbHomebase.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                    cbHomebase.Width = 200;

                    long minRunway = this.SelectedAirliners.Max(a => a.Type.MinRunwaylength);

                    var homebases = AirlineHelpers.GetHomebases(GameObject.GetInstance().HumanAirline, minRunway);

                    foreach (Airport airport in homebases)
                    {
                        cbHomebase.Items.Add(airport);
                    }

                    cbHomebase.SelectedIndex = 0;

                    if (PopUpSingleElement.ShowPopUp(Translator.GetInstance().GetString("PageFleetAirlinerInformation", "1014"), cbHomebase) == PopUpSingleElement.ButtonSelected.OK && cbHomebase.SelectedItem != null)
                    {
                        Airport airport = cbHomebase.SelectedItem as Airport;

                        orderAirliners(airport, contractedOrder ? GameObject.GetInstance().HumanAirline.Contract.Discount : 0);

                        if (contractedOrder)
                        {
                            GameObject.GetInstance().HumanAirline.Contract.PurchasedAirliners += totalAmount;
                        }

                        var sList = new List <AirlinerTypeMVVM>(this.SelectedAirliners);
                        foreach (AirlinerTypeMVVM type in sList)
                        {
                            type.IsSelected = false;
                        }

                        this.SelectedAirliners.Clear();
                    }
                }
            }
        }
コード例 #8
0
        private void btnOrder_Click(object sender, RoutedEventArgs e)
        {
            Boolean contractedOrder = false;
            Boolean tryOrder        = true;

            Airport airport = (Airport)cbAirport.SelectedItem;

            if (airport == null)
            {
                WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2002"), Translator.GetInstance().GetString("MessageBox", "2002", "message"), WPFMessageBoxButtons.Ok);
            }
            else
            {
                if (GameObject.GetInstance().HumanAirline.Contract != null)
                {
                    if (GameObject.GetInstance().HumanAirline.Contract.Manufacturer == this.Manufacturer)
                    {
                        contractedOrder = true;
                    }
                    else
                    {
                        double terminationFee      = GameObject.GetInstance().HumanAirline.Contract.getTerminationFee();
                        WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2010"), string.Format(Translator.GetInstance().GetString("MessageBox", "2010", "message"), GameObject.GetInstance().HumanAirline.Contract.Manufacturer.Name, terminationFee), WPFMessageBoxButtons.YesNo);

                        if (result == WPFMessageBoxResult.Yes)
                        {
                            AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -terminationFee);
                            GameObject.GetInstance().HumanAirline.Contract = null;
                        }
                        tryOrder = result == WPFMessageBoxResult.Yes;
                    }
                }

                if (tryOrder)
                {
                    int    totalAmount = orders.Sum(o => o.Amount);
                    double price       = orders.Sum(o => o.Type.Price * o.Amount);

                    double totalPrice = price * ((1 - GeneralHelpers.GetAirlinerOrderDiscount(totalAmount)));

                    if (contractedOrder)
                    {
                        totalPrice = totalPrice * ((100 - GameObject.GetInstance().HumanAirline.Contract.Discount) / 100);
                    }

                    double downpaymentPrice = 0;

                    downpaymentPrice = totalPrice * (GameObject.GetInstance().Difficulty.PriceLevel / 10);

                    if (cbDownPayment.IsChecked.Value)
                    {
                        if (downpaymentPrice > GameObject.GetInstance().HumanAirline.Money)
                        {
                            WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2001"), Translator.GetInstance().GetString("MessageBox", "2001", "message"), WPFMessageBoxButtons.Ok);
                        }
                        else
                        {
                            WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2009"), string.Format(Translator.GetInstance().GetString("MessageBox", "2009", "message"), totalPrice, downpaymentPrice), WPFMessageBoxButtons.YesNo);

                            if (result == WPFMessageBoxResult.Yes)
                            {
                                foreach (AirlinerOrder order in orders)
                                {
                                    for (int i = 0; i < order.Amount; i++)
                                    {
                                        Guid id = Guid.NewGuid();

                                        Airliner airliner = new Airliner(id.ToString(), order.Type, GameObject.GetInstance().HumanAirline.Profile.Country.TailNumbers.getNextTailNumber(), dpDate.SelectedDate.Value);

                                        airliner.clearAirlinerClasses();

                                        foreach (AirlinerClass aClass in order.Classes)
                                        {
                                            AirlinerClass tClass = new AirlinerClass(aClass.Type, aClass.SeatingCapacity);
                                            tClass.RegularSeatingCapacity = aClass.RegularSeatingCapacity;

                                            foreach (AirlinerFacility facility in aClass.getFacilities())
                                            {
                                                tClass.setFacility(GameObject.GetInstance().HumanAirline, facility);
                                            }

                                            airliner.addAirlinerClass(tClass);
                                        }


                                        Airliners.AddAirliner(airliner);

                                        FleetAirliner.PurchasedType pType = FleetAirliner.PurchasedType.BoughtDownPayment;
                                        GameObject.GetInstance().HumanAirline.addAirliner(pType, airliner, airport);
                                    }
                                }
                                if (contractedOrder)
                                {
                                    GameObject.GetInstance().HumanAirline.Contract.PurchasedAirliners += orders.Sum(o => o.Amount);
                                }
                                AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Purchases, -downpaymentPrice);

                                PageNavigator.NavigateTo(new PageAirliners());
                            }
                        }
                    }
                    else
                    {
                        if (totalPrice > GameObject.GetInstance().HumanAirline.Money)
                        {
                            WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2001"), Translator.GetInstance().GetString("MessageBox", "2001", "message"), WPFMessageBoxButtons.Ok);
                        }
                        else
                        {
                            if (orders.Sum(o => o.Amount) > 0)
                            {
                                WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2008"), string.Format(Translator.GetInstance().GetString("MessageBox", "2008", "message"), totalPrice), WPFMessageBoxButtons.YesNo);

                                if (result == WPFMessageBoxResult.Yes)
                                {
                                    if (contractedOrder)
                                    {
                                        AirlineHelpers.OrderAirliners(GameObject.GetInstance().HumanAirline, orders, airport, dpDate.SelectedDate.Value, GameObject.GetInstance().HumanAirline.Contract.Discount);
                                    }
                                    else
                                    {
                                        AirlineHelpers.OrderAirliners(GameObject.GetInstance().HumanAirline, orders, airport, dpDate.SelectedDate.Value);
                                    }

                                    PageNavigator.NavigateTo(new PageAirliners());
                                }

                                if (contractedOrder)
                                {
                                    GameObject.GetInstance().HumanAirline.Contract.PurchasedAirliners += orders.Sum(o => o.Amount);
                                }
                            }
                        }
                    }
                }
                this.ParentPage.updatePage();
            }
        }