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 void RefreshTree(Vertexcs cur) { cnv.Children.Clear(); 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); for (int i = 0; i < vert.Count; i++) { if (vert[i].ParentId == cur.Id && vert[i].Probability != default(double)) { DrawNewVertex(vert[i]); DrawNewLine(vert[i], cur); DrawRootVertexes(vert[i]); } } }
private void DrawGRINLine(Vertexcs min) { for (int i = 0; i < vert.Count; i++) { if (min.ParentId == vert[i].Id) { Line l = new Line(); l.X1 = vert[i].X / 2 + Widht / 2; l.Y1 = vert[i].Y; l.X2 = min.X / 2 + Widht / 2; l.Y2 = min.Y; l.Stroke = Brushes.Green; l.Width = 10; cnv.Children.Add(l); if (vert[i].Probability == default(double)) { break; } else { DrawGRINLine(vert[i]); } } } }
private List <Vertexcs> DeliteVertexes(Vertexcs currentvertex) { List <Vertexcs> delete = new List <Vertexcs>(); for (int i = 0; i < vert.Count; i++) { if (vert[i].Probability != 0 && vert[i].ParentId == currentvertex.Id) { //DeliteVertexes(vert[i]); delete.Add(vert[i]); //vert.Remove(vert[i]); //i--; } } for (int i = 0; i < vert.Count; i++) { for (int j = 0; j < delete.Count; j++) { if (vert[i].Probability != 0 && vert[i].ParentId == delete[j].Id) { delete.Add(vert[i]); } } } return(delete); }
/// <summary> /// рисует линии соединяющие точки графа /// </summary> /// <param name="newver"></param> /// <param name="parent"></param> private void DrawNewLine(Vertexcs newver, Vertexcs parent) { Line l = new Line(); l.X1 = parent.X; l.Y1 = parent.Y + 20; l.X2 = newver.X; l.Y2 = newver.Y; l.Stroke = Brushes.Black; cnv.Children.Add(l); }
private bool ExistChild(Vertexcs curver) { for (int i = 0; i < vert.Count; i++) { if (curver.Id == vert[i].ParentId && vert[i].Probability != default) { return(false); } } return(true); }
/// <summary> /// рисует вершины /// </summary> /// <param name="newver"></param> private void DrawNewVertex(Vertexcs newver) { Button but = new Button(); but.DataContext = newver; but.HorizontalAlignment = HorizontalAlignment.Left; but.VerticalAlignment = VerticalAlignment.Top; but.Margin = new Thickness(newver.X - 10, newver.Y, Widht - newver.X - 10, Height - newver.Y - 20); but.Height = 20; but.Width = 20; but.Background = new ImageBrush(new BitmapImage(new Uri(pathplus))); but.Click += But_Click; cnv.Children.Add(but); }
private void DrawNewVertex(Vertexcs newver) { Point point = new Point(newver.X, newver.Y); Ellipse elipse = new Ellipse(); elipse.Width = 6; elipse.Height = 6; elipse.HorizontalAlignment = HorizontalAlignment.Left; elipse.VerticalAlignment = VerticalAlignment.Top; elipse.StrokeThickness = 2; elipse.Stroke = Brushes.Black; elipse.Margin = new Thickness(newver.X / 2 + Widht / 2 - 3, newver.Y - 3, 0, 0); cnv.Children.Add(elipse); }
/// <summary> /// выдает ряд дерева /// </summary> /// <param name="parent"></param> /// <param name="k"></param> private void CurrenRow(Vertexcs parent, ref int k) { for (int i = 0; i < vert.Count; i++) { if (parent.ParentId == vert[i].Id && vert[i].Probability == default(double)) { return; } if (parent.ParentId == vert[i].Id && vert[i].Probability != default(double)) { k++; CurrenRow(vert[i], ref k); } } }
private void CostCurrentBranch(Vertexcs curver, double k) { double cost = k; for (int i = 0; i < vert.Count; i++) { if (curver.Id == vert[i].ParentId && vert[i].Probability != default) { cost += vert[i].Probability * vert[i].Cost; CostCurrentBranch(vert[i], cost); cost -= vert[i].Probability * vert[i].Cost; } } if (ExistChild(curver)) { curver.Value = cost; } }
public async Task IsertNewVertex(Vertexcs current, int Id) { await sqlConnect.OpenAsync(); SqlCommand command = new SqlCommand("INSERT INTO [RiskTree] (ParentId,Description,Cost,Probability,X,Y) VALUES(@ParentId,@Description,@Cost,@Probability,@X,@Y)", sqlConnect); command.Parameters.AddWithValue("ParentId", Id); command.Parameters.AddWithValue("Description", current.Description); command.Parameters.AddWithValue("Cost", current.Cost); command.Parameters.AddWithValue("Probability", current.Probability); command.Parameters.AddWithValue("X", current.X); command.Parameters.AddWithValue("Y", current.Y); await command.ExecuteNonQueryAsync(); sqlConnect.Close(); }
public async Task <Vertexcs> GiveVertex(Vertexcs vertex) { SqlDataReader sqlReader = null; SqlCommand command = new SqlCommand("SELECT * FROM[RiskTree]", sqlConnect); await sqlConnect.OpenAsync(); try { sqlReader = await command.ExecuteReaderAsync(); while (await sqlReader.ReadAsync()) { if (vertex.ParentId == Convert.ToInt32(sqlReader["ParentId"]) && Convert.ToDouble(Parsing(Convert.ToString(sqlReader["Probability"]))) != default(Double) && Convert.ToDouble(Parsing(Convert.ToString(sqlReader["X"]))) == vertex.X && Convert.ToDouble(Parsing(Convert.ToString(sqlReader["Y"]))) == vertex.Y) { return(new Vertexcs(Convert.ToInt32(sqlReader["Id"]), Convert.ToInt32(sqlReader["ParentId"]), Convert.ToString(sqlReader["Description"]), Convert.ToDouble(Parsing(Convert.ToString(sqlReader["Cost"]))), Convert.ToDouble(Parsing(Convert.ToString(sqlReader["Probability"]))), Convert.ToDouble(Parsing(Convert.ToString(sqlReader["X"]))), Convert.ToDouble(Parsing(Convert.ToString(sqlReader["Y"]))))); } } return(null); } catch (Exception) { return(null); } finally { if (sqlReader != null) { sqlReader.Close(); } sqlConnect.Close(); } }