private async void Delite_Click(object sender, RoutedEventArgs e)
        {
            cnv.Children.Clear();
            TreeCommands tc = new TreeCommands();

            if (((Vertexcs)Add.DataContext).Probability != 0)
            {
                List <Vertexcs> d = DeliteVertexes((Vertexcs)Add.DataContext);
                d.Add((Vertexcs)Add.DataContext);
                await tc.DeliteVerTex(d);

                vert = await tc.GiveALlVertex();
            }
            Button but = new Button();

            but.HorizontalAlignment = HorizontalAlignment.Left;
            but.VerticalAlignment   = VerticalAlignment.Top;
            but.Margin      = new Thickness(Widht / 2 - 10, 50, Widht / 2 - 10, Height - 70);
            but.Background  = new ImageBrush(new BitmapImage(new Uri(pathplus)));
            Back.Background = new ImageBrush(new BitmapImage(new Uri(path)));
            but.DataContext = FirstVer;
            but.Height      = 20;
            but.Width       = 20;
            but.Click      += But_Click;
            cnv.Children.Add(but);
            DrawRootVertexes(FirstVer);
            CostCurrentBranch(FirstVer, 0);
            DrawMaxDangerous();
        }
        private async void Window_Activated(object sender, EventArgs e)
        {
            if (flag)
            {
                Widht  = cnv.ActualWidth;
                Height = cnv.ActualHeight;

                DataCommands dc = new DataCommands();
                SelectedRisks = await dc.GiveAllRisks(project);

                if (SelectedRisks == null)
                {
                    SelectedRisks = new List <Risk>();
                }
                Drawing();
                TreeCommands tc = new TreeCommands();
                vert = await tc.GiveALlVertex();

                FirstVerTex = await tc.GiveFristVertex(drisk.Id);

                GiveTitle();
                CreateFirstVertex();
                CostCurrentBranch(FirstVerTex, 0);
                DrawMaxDangerous();
                WriteInListView();
                flag = false;
            }
        }
        private async void Window_Activated(object sender, EventArgs e)
        {
            if (flag)
            {
                try
                {
                    Widht  = cnv.ActualWidth;
                    Height = cnv.ActualHeight;
                    Label lab = new Label();
                    lab.HorizontalAlignment = HorizontalAlignment.Center;
                    lab.VerticalAlignment   = VerticalAlignment.Top;
                    lab.Content             = drisk.RiskName;
                    grid.Children.Add(lab);
                    TreeCommands tc  = new TreeCommands();
                    Button       but = new Button();
                    but.HorizontalAlignment = HorizontalAlignment.Left;
                    but.VerticalAlignment   = VerticalAlignment.Top;
                    but.Margin      = new Thickness(Widht / 2 - 10, 50, Widht / 2 - 10, Height - 70);
                    but.Background  = new ImageBrush(new BitmapImage(new Uri(pathplus)));
                    Back.Background = new ImageBrush(new BitmapImage(new Uri(path)));
                    Back.Foreground = new ImageBrush(new BitmapImage(new Uri(path)));
                    if (!await tc.Exist(drisk.Id))
                    {
                        FirstVer = new Vertexcs(drisk.Id, drisk.RiskName, Widht / 2, 50);
                        await tc.IsertNewVertex(FirstVer, drisk.Id);

                        FirstVer = await tc.GiveFristVertex(drisk.Id);

                        but.DataContext = FirstVer;
                    }
                    else
                    {
                        FirstVer = await tc.GiveFristVertex(drisk.Id);

                        but.DataContext = FirstVer;
                    }
                    but.Height = 20;
                    but.Width  = 20;
                    but.Click += But_Click;
                    cnv.Children.Add(but);
                    vert = await tc.GiveALlVertex();

                    DrawRootVertexes(FirstVer);
                    CostCurrentBranch(FirstVer, 0);
                    DrawMaxDangerous();
                    flag = false;
                }
                catch (NullReferenceException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        private async void AddNewVertex_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (((Button)sender).DataContext == null)
                {
                    throw new Exception("выбрете вершину");
                }
                if (DESC.Text == "")
                {
                    throw new Exception("Заполните поле Description");
                }
                if (!double.TryParse(COST.Text, out double d))
                {
                    throw new Exception("значение Cost должно быть вещественным числом больше нуля");
                }
                if (double.Parse(COST.Text) <= 0)
                {
                    throw new Exception("значение Cost должно быть вещественным числом больше нуля");
                }
                if (!double.TryParse(Prob.Text, out double d1))
                {
                    throw new Exception("Значение Probability должно быть вещественным числом в предалам (0,1)");
                }
                if (double.Parse(Prob.Text) > 1)
                {
                    throw new Exception("Значение Probability должно быть вещественным числом в предалам (0,1)");
                }
                if (double.Parse(Prob.Text) < 0)
                {
                    throw new Exception("Значение Probability должно быть вещественным числом в предалам (0,1)");
                }
                Vertexcs parent = ((Vertexcs)((Button)sender).DataContext);

                int row = 1;
                CurrenRow(parent, ref row);
                if (parent.Probability != 0)
                {
                    row++;
                }
                if (row >= 4)
                {
                    throw new ArgumentException("Ветвь дерева не может превышать 4");
                }
                Vertexcs newver;
                string   line = $"{(parent.X - Widht / (2 * Math.Pow(4, row))):f3}";
                if (Cheker(double.Parse(line)))
                {
                    newver = new Vertexcs(parent.Id, DESC.Text, double.Parse(COST.Text), double.Parse(Prob.Text), parent.X - Widht / (2 * Math.Pow(4, row)), parent.Y + 50);
                }
                else
                {
                    line = $"{(parent.X + Widht / (2 * Math.Pow(4, row))):f3}";
                    if (Cheker(double.Parse(line)))
                    {
                        newver = new Vertexcs(parent.Id, DESC.Text, double.Parse(COST.Text), double.Parse(Prob.Text), parent.X + Widht / (2 * Math.Pow(4, row)), parent.Y + 50);
                    }
                    else
                    {
                        line = $"{(parent.X - 3 * Widht / (2 * Math.Pow(4, row))):f3}";
                        if (Cheker(double.Parse(line)))
                        {
                            newver = new Vertexcs(parent.Id, DESC.Text, double.Parse(COST.Text), double.Parse(Prob.Text), parent.X - 3 * Widht / (2 * Math.Pow(4, row)), parent.Y + 50);
                        }
                        else
                        {
                            line = $"{(parent.X + 3 * Widht / (2 * Math.Pow(4, row))):f3}";
                            if (Cheker(double.Parse(line)))
                            {
                                newver = new Vertexcs(parent.Id, DESC.Text, double.Parse(COST.Text), double.Parse(Prob.Text), parent.X + 3 * Widht / (2 * Math.Pow(4, row)), parent.Y + 50);
                            }
                            else
                            {
                                throw new Exception("Количество детей не может превышать 4");
                            }
                        }
                    }
                }
                TreeCommands tc = new TreeCommands();
                await tc.IsertNewVertex(newver, parent.Id);

                newver = await tc.GiveVertex(newver);

                vert.Add(newver);



                RefreshTree(FirstVer);
                Clear();
                CostCurrentBranch(FirstVer, 0);
                DrawMaxDangerous();
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show(ex.Message, "Enpty Exception");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Enpty Exception");
            }
        }