示例#1
0
        private void Calculate()
        {
            if (!company.CheckChance)
            {
                throw new Exception("Сумма шансов должна быть 1!");
            }
            if (company == null || bank == null)
            {
                return;
            }

            DrawingTree.M?.Clear();
            DrawingTree.predictions?.Clear();
            DrawingTree.forecastNii?.Clear();
            DrawingTree.chancies?.Clear();

            foreach (Company item in companies)
            {
                prodecties.Add(Predictions.GetPrediction(bank, item, Convert.ToSingle(this.textBox2.Text.Replace(".", ","))).Sort());
            }
            for (int i = 0; i < prodecties[0].Length; ++i)
            {
                DrawingTree.predictions.Add(new System.Windows.Controls.Label()
                {
                    Content = prodecties[0][i].ToString()
                });
            }
            foreach (float item in Predictions.ForecastNii)
            {
                DrawingTree.forecastNii.Add(new System.Windows.Controls.Label()
                {
                    Content = item.ToString()
                });
            }

            #region Node
            //
            // ----------------------------------------------------------------------------
            //
            this.notBuyProdectionNodeMaxChance.Text = textGroupLabel + " " + companies[1].changes[0].ToString();
            this.notBuyProdectionNodeMinChance.Text = textGroupLabel + " " + companies[1].changes[1].ToString();
            this.notBuyProdectionNodeSrChance.Text  = textGroupLabel + " " + companies[1].changes[2].ToString();

            //Left
            List <System.Windows.Controls.Label> lst = new List <System.Windows.Controls.Label>();

            for (int i = 0; i < companies[1].changes.Length; ++i)
            {
                lst.Add(new System.Windows.Controls.Label()
                {
                    Content = companies[1].changes[i].ToString()
                });
            }

            DrawingTree.chancies.Add(lst);
            lst = new List <System.Windows.Controls.Label>();

            this.notBuyProdectionNodeMaxMoney.Text = prodecties[1][0].ToString();
            this.notBuyProdectionNodeMinMoney.Text = prodecties[1][1].ToString();
            this.notBuyProdectionNodeSrMoney.Text  = prodecties[1][2].ToString();
            //
            // 1 node
            //
            this.firstNodeMaxChance.Text = textGroupLabel + " " + companies[4].changes[0].ToString();
            this.firstNodeSrChance.Text  = textGroupLabel + " " + companies[4].changes[1].ToString();
            this.firstNodeMinChance.Text = textGroupLabel + " " + companies[4].changes[2].ToString();

            for (int i = 0; i < companies[4].changes.Length; ++i)
            {
                lst.Add(new System.Windows.Controls.Label()
                {
                    Content = companies[4].changes[i].ToString()
                });
            }

            DrawingTree.chancies.Add(lst);
            lst = new List <System.Windows.Controls.Label>();

            this.firstNodeMaxMoney.Text = prodecties[0][0].ToString();
            this.firstNodeSrMoney.Text  = prodecties[0][1].ToString();
            this.firstNodeMinMoney.Text = prodecties[0][2].ToString();
            //
            // 2 node
            //
            this.secondNodeMaxChance.Text = textGroupLabel + " " + companies[2].changes[0].ToString();
            this.secondNodeMinChance.Text = textGroupLabel + " " + companies[2].changes[1].ToString();
            this.secondNodeSrChance.Text  = textGroupLabel + " " + companies[2].changes[2].ToString();

            for (int i = 0; i < companies[2].changes.Length; ++i)
            {
                lst.Add(new System.Windows.Controls.Label()
                {
                    Content = companies[2].changes[i].ToString()
                });
            }

            DrawingTree.chancies.Add(lst);
            lst = new List <System.Windows.Controls.Label>();

            this.secondNodeMaxMoney.Text = prodecties[2][0].ToString();
            this.secondNodeMinMoney.Text = prodecties[2][1].ToString();
            this.secondNodeSrMoney.Text  = prodecties[2][2].ToString();
            //
            // 3 node
            //
            this.thirdNodeMaxChance.Text = textGroupLabel + " " + companies[0].changes[0].ToString();
            this.thirdNodeSrChance.Text  = textGroupLabel + " " + companies[0].changes[1].ToString();
            this.thirdNodeMinChance.Text = textGroupLabel + " " + companies[0].changes[2].ToString();

            for (int i = 0; i < companies[0].changes.Length; ++i)
            {
                lst.Add(new System.Windows.Controls.Label()
                {
                    Content = companies[0].changes[i].ToString()
                });
            }

            DrawingTree.chancies.Add(lst);

            this.thirdNodeMaxMoney.Text = prodecties[3][0].ToString();
            this.thirdNodeSrMoney.Text  = prodecties[3][1].ToString();
            this.thirdNodeMinMoney.Text = prodecties[3][2].ToString();
            //
            // ----------------------------------------------------------------------------
            //
            #endregion

            this.firstNode_M.Text = bank.money > Predictions.M[3] ? bank.money.ToString() : Predictions.M[3].ToString();
            DrawingTree.M.Add(new System.Windows.Controls.Label {
                Content = firstNode_M.Text
            });

            this.secondNode_M.Text = bank.money > Predictions.M[2] ? bank.money.ToString() : Predictions.M[2].ToString();
            DrawingTree.M.Add(new System.Windows.Controls.Label {
                Content = secondNode_M.Text
            });

            this.thirdNode_M.Text             = this.notBuyProdectionNode_M.Text
                                              = this.notBuyProdectionLabel.Text = bank.money > Predictions.M[1] ? bank.money.ToString() : Predictions.M[1].ToString();
            DrawingTree.M.Add(new System.Windows.Controls.Label {
                Content = thirdNode_M.Text
            });

            this.mountAvr.Text  = Predictions.MountPrice.ToString();
            this.martPrice.Text = bank.money.ToString();

            float prodectionMoney = bank.money +
                                    Convert.ToSingle(data["forecast"][data["forecast"].Count - 1].Replace(".", ",")) +
                                    Convert.ToSingle(data["chance"][data["chance"].Count - 1].Replace(".", ","));
            this.notBuyProdectionLabel.Text = bank.money.ToString();
            this.fullSum.Text = prodectionMoney.ToString();

            DrawingTree.FullSum = new System.Windows.Controls.Label()
            {
                Content = fullSum.Text
            };
            DrawingTree.Root = new System.Windows.Controls.Label()
            {
                Content = this.notBuyProdectionLabel.Text
            };

            Write();
        }