private void ChildRemoved(object sender, ChildRemovedEventArgs e) { RemoveChildren(e.person); generationManager.RemoveChild(e.person, e.name); for (int i = 1; i < generationManager.generationList.Count; i++) { ConnectChildrenToParents((object)generationManager.generationList[i], new GenerationChangedEventArgs()); } if (generationManager.GetGenerationByID(e.person.Value.GenerationID).GenerationGridList.Count == 0) { generationManager.generationList.Remove(generationManager.GetGenerationByID(e.person.Value.GenerationID)); treeGrid.RowDefinitions.Remove(treeGrid.RowDefinitions[treeGrid.RowDefinitions.Count - 1]); } if (e.person != PersonTree.Tree) { PersonTree.GetNodeByName(PersonTree.Tree, e.person.Parent.Value.Name, e.person.Parent.Value.Partner).Remove(e.person); } else { PersonTree.Tree = new Node <Person>(new Person(), null); PersonTree.Tree.Parent = null; } }
private void RemoveChildButton_Click(object sender, RoutedEventArgs e) { string child = string.Empty; string partner = string.Empty; if (Regex.Split(this.ChildCombobox.SelectedItem.ToString(), " & ").Length == 1) { child = this.ChildCombobox.SelectedItem.ToString(); } else if (Regex.Split(this.ChildCombobox.SelectedItem.ToString(), " & ").Length == 2) { child = Regex.Split(this.ChildCombobox.SelectedItem.ToString(), " & ")[0]; partner = Regex.Split(this.ChildCombobox.SelectedItem.ToString(), " & ")[1]; } Node <Person> childNode = PersonTree.GetNodeByName(PersonTree.Tree, child, partner); ChildRemovedEventArgs eventArgs = new ChildRemovedEventArgs() { person = childNode, name = child }; ChildRemoved?.Invoke(this, eventArgs); this.Close(); }
private void LoadTree(Person person, Node <Person> node) { if (node.Parent != null) { Node <Person> parent = PersonTree.GetNodeByName(PersonTree.Tree, node.Parent.Value.Name, node.Parent.Value.Partner); parent.AddChild(person, node.Parent); parent.Children[parent.Children.Count - 1].SubscribeToNewChildAdded(PersonTree.NewChildAdded); } }
private void AddButton_Click(object sender, RoutedEventArgs e) { if (this.PartnerName.Text == string.Empty) { MessageBox.Show(Application.Current.Resources["AddPartnerWindowEmptyPartnerErrorMessage"].ToString(), Application.Current.Resources["AddPartnerWindowEmptyPartnerErroMessageBoxTitle"].ToString()); } else { Node <Person> child = null; if (Regex.Split(this.ChildCombobox.SelectedValue.ToString(), " & ").Length == 1) { child = PersonTree.GetNodeByName(PersonTree.Tree, this.ChildCombobox.SelectedValue.ToString(), string.Empty); } else if (Regex.Split(this.ChildCombobox.SelectedValue.ToString(), " & ").Length == 2) { child = PersonTree.GetNodeByName(PersonTree.Tree, Regex.Split(this.ChildCombobox.SelectedValue.ToString(), " & ")[0], Regex.Split(this.ChildCombobox.SelectedValue.ToString(), " & ")[1]); } string errorMessage = string.Empty; DateTime birthDate; DateTime deathDate; Nullable <DateTime> partnerBirthDate = null; Nullable <DateTime> partnerDeathDate = null; try { birthDate = DateTime.ParseExact(this.PartnerBirthDate.Text.ToString(), "dd/MM/yyyy", null, DateTimeStyles.None); partnerBirthDate = (Nullable <DateTime>)birthDate; } catch (FormatException) { if (this.PartnerBirthDate.Text.ToString() == string.Empty) { partnerBirthDate = null; } else { errorMessage += (string)FindResource("AddPartnerWindowPartnerBirthDateFormatError"); } } try { deathDate = DateTime.ParseExact(this.PartnerDeathDate.Text.ToString(), "dd/MM/yyyy", null, DateTimeStyles.None); partnerDeathDate = (Nullable <DateTime>)deathDate; } catch (FormatException) { if (this.PartnerDeathDate.Text.ToString() == string.Empty) { partnerDeathDate = null; } else { errorMessage += "\n" + (string)FindResource("AddPartnerWindowPartnerDeathDateFormatError"); } } if (errorMessage == string.Empty) { if (PersonTree.GetNodeByName(PersonTree.Tree, this.PartnerName.Text, string.Empty) != null) { child.Value.IsPartnerInFamily = true; } child.Value.Partner = this.PartnerName.Text; child.Value.PartnerBirthDate = partnerBirthDate; child.Value.PartnerDeathDate = partnerDeathDate; child.Value.PartnerBirthPlace = this.PartnerBirthPlace.Text; PartnerAddedEventArgs eventArgs = new PartnerAddedEventArgs(); eventArgs.childName = child.Value.Name; eventArgs.partnerName = child.Value.Partner; eventArgs.birthDate = child.Value.PartnerBirthDate; eventArgs.deathDate = child.Value.PartnerDeathDate; eventArgs.birthPlace = child.Value.PartnerBirthPlace; PartnerAdded?.Invoke(this, eventArgs); this.Close(); } else { MessageBox.Show(errorMessage, (string)FindResource("DateFormatErrorMessageBoxTitle")); } } }
private void AddButton_Click(object sender, RoutedEventArgs e) { if (this.NewPersonName.Text == string.Empty) { MessageBox.Show(Application.Current.Resources["AddChildWindowEmptyNewNameErrorMessage"].ToString(), Application.Current.Resources["AddChildWindowEmptyNewNameErroMessageBoxTitle"].ToString()); } else { if (parentList.Count == 0) { Person newPerson = new Person(this.NewPersonName.Text); newPerson.BirthPlace = this.NewPersonBirthPlace.Text; string errorMessage = string.Empty; DateTime birthDate; DateTime deathDate; try { birthDate = DateTime.ParseExact(this.NewPersonBirthDate.Text.ToString(), "dd/MM/yyyy", null, DateTimeStyles.None); newPerson.BirthDate = (Nullable <DateTime>)birthDate; } catch (FormatException) { if (this.NewPersonBirthDate.Text.ToString() == string.Empty) { newPerson.BirthDate = null; } else { errorMessage += "\n" + (string)FindResource("AddChildWindowBirthDateFormatError"); } } try { deathDate = DateTime.ParseExact(this.NewPersonDeathDate.Text.ToString(), "dd/MM/yyyy", null, DateTimeStyles.None); newPerson.DeathDate = (Nullable <DateTime>)deathDate; } catch (FormatException) { if (this.NewPersonDeathDate.Text.ToString() == string.Empty) { newPerson.BirthDate = null; } else { errorMessage += "\n" + (string)FindResource("AddChildWindowDeathDateFormatError"); } } if (this.NewPersonPartnerName.Text.ToString() != string.Empty) { newPerson.Partner = this.NewPersonPartnerName.Text; newPerson.PartnerBirthPlace = this.NewPersonPartnerBirthPlace.Text; DateTime partnerBirthDate; DateTime partnerDeathDate; try { partnerBirthDate = DateTime.ParseExact(this.NewPersonPartnerBirthDate.Text.ToString(), "dd/MM/yyyy", null, DateTimeStyles.None); newPerson.PartnerBirthDate = (Nullable <DateTime>)partnerBirthDate; } catch (FormatException) { if (this.NewPersonPartnerBirthDate.Text.ToString() == string.Empty) { newPerson.PartnerBirthDate = null; } else { errorMessage += (string)FindResource("AddChildWindowPartnerBirthDateFormatError"); } } try { partnerDeathDate = DateTime.ParseExact(this.NewPersonPartnerDeathDate.Text.ToString(), "dd/MM/yyyy", null, DateTimeStyles.None); newPerson.PartnerDeathDate = (Nullable <DateTime>)partnerDeathDate; } catch (FormatException) { if (this.NewPersonPartnerDeathDate.Text.ToString() == string.Empty) { newPerson.PartnerDeathDate = null; } else { errorMessage += "\n" + (string)FindResource("AddChildWindowPartnerDeathDateFormatError"); } } } if (errorMessage == string.Empty) { PersonTree.Tree.Value = newPerson; NewChildAddedEventArgs <Person> eventArgs = new NewChildAddedEventArgs <Person>(); eventArgs.child = PersonTree.Tree.Value; FirstChildAddedEvent?.Invoke(this, eventArgs); this.Close(); } else { MessageBox.Show(errorMessage, (string)FindResource("AddChildWindowDateFormatErrorMessageBoxTitle")); } } else { Node <Person> parent; string parent1 = Regex.Split(this.ParentCombobox.SelectedItem.ToString(), " & ")[0]; string parent2 = Regex.Split(this.ParentCombobox.SelectedItem.ToString(), " & ")[1]; parent = PersonTree.GetNodeByName(PersonTree.Tree, parent1, parent2); if (parent.Value.Partner != string.Empty) { Person newPerson = new Person(this.NewPersonName.Text); newPerson.BirthPlace = this.NewPersonBirthPlace.Text; string errorMessage = string.Empty; DateTime birthDate; DateTime deathDate; if (PersonTree.GetNodeByName(PersonTree.Tree, this.NewPersonName.Text, this.NewPersonPartnerName.Text) != null) { errorMessage += Application.Current.Resources["AddChildWindowDuplicatedNameError"]; } try { birthDate = DateTime.ParseExact(this.NewPersonBirthDate.Text.ToString(), "dd/MM/yyyy", null, DateTimeStyles.None); newPerson.BirthDate = (Nullable <DateTime>)birthDate; } catch (FormatException) { if (this.NewPersonBirthDate.Text.ToString() == string.Empty) { newPerson.BirthDate = null; } else { errorMessage += "\n" + (string)FindResource("AddChildWindowBirthDateFormatError"); } } try { deathDate = DateTime.ParseExact(this.NewPersonDeathDate.Text.ToString(), "dd/MM/yyyy", null, DateTimeStyles.None); newPerson.DeathDate = (Nullable <DateTime>)deathDate; } catch (FormatException) { if (this.NewPersonDeathDate.Text.ToString() == string.Empty) { newPerson.BirthDate = null; } else { errorMessage += "\n" + (string)FindResource("AddChildWindowDeathDateFormatError"); } } if (this.NewPersonPartnerName.Text.ToString() != string.Empty) { newPerson.Partner = this.NewPersonPartnerName.Text; newPerson.PartnerBirthPlace = this.NewPersonPartnerBirthPlace.Text; DateTime partnerBirthDate; DateTime partnerDeathDate; if (PersonTree.GetNodeByName(PersonTree.Tree, this.NewPersonPartnerName.Text, string.Empty) != null) { newPerson.IsPartnerInFamily = true; } try { partnerBirthDate = DateTime.ParseExact(this.NewPersonPartnerBirthDate.Text.ToString(), "dd/MM/yyyy", null, DateTimeStyles.None); newPerson.PartnerBirthDate = (Nullable <DateTime>)partnerBirthDate; } catch (FormatException) { if (this.NewPersonPartnerBirthDate.Text.ToString() == string.Empty) { newPerson.PartnerBirthDate = null; } else { errorMessage += "\n" + (string)FindResource("AddChildWindowPartnerBirthDateFormatError"); } } try { partnerDeathDate = DateTime.ParseExact(this.NewPersonPartnerDeathDate.Text.ToString(), "dd/MM/yyyy", null, DateTimeStyles.None); newPerson.PartnerDeathDate = (Nullable <DateTime>)partnerDeathDate; } catch (FormatException) { if (this.NewPersonPartnerDeathDate.Text.ToString() == string.Empty) { newPerson.PartnerDeathDate = null; } else { errorMessage += "\n" + (string)FindResource("AddChildWindowPartnerDeathDateFormatError"); } } } if (errorMessage == string.Empty) { parent.AddChild(newPerson, parent); parent.Children[parent.Children.Count - 1].SubscribeToNewChildAdded(PersonTree.NewChildAdded); this.Close(); } else { if (errorMessage.Substring(0, 1) == "\n") { errorMessage = errorMessage.Substring(1, errorMessage.Length - 1); } MessageBox.Show(errorMessage, (string)FindResource("AddChildWindowErrorMessageBoxTitle")); } } else { MessageBox.Show((string)FindResource("AddChildWindowEmptyParentPartnerError"), (string)FindResource("AddChildWindowEmptyParentPartnerErrorMessageBoxTitle")); } } } }
private void AddButton_Click(object sender, RoutedEventArgs e) { string errorMessage = string.Empty; if (this.FatherName.Text == string.Empty) { errorMessage += Application.Current.Resources["AddParentsWindowEmptyFatherErrorMessage"].ToString(); } if (this.MotherName.Text == string.Empty) { errorMessage += "\n" + Application.Current.Resources["AddParentsWindowEmptyMotherErrorMessage"].ToString(); } if (errorMessage != string.Empty) { MessageBox.Show(errorMessage, (string)FindResource("AddParentsWindowEmptyParentsMessageBoxTitle")); } else { if (this.FatherCheckBox.IsChecked == false && this.MotherCheckBox.IsChecked == false) { MessageBox.Show((string)FindResource("AddParentsWindowNoPrimaryParentErrorMessage"), (string)FindResource("AddParentsWindowNoPrimaryParentMessageBoxTitle")); } else { DateTime birthDate; DateTime deathDate; Nullable <DateTime> fatherBirthDate = null; Nullable <DateTime> fatherDeathDate = null; try { birthDate = DateTime.ParseExact(this.FatherBirthDate.Text.ToString(), "dd/MM/yyyy", null, DateTimeStyles.None); fatherBirthDate = (Nullable <DateTime>)birthDate; } catch (FormatException) { if (this.FatherBirthDate.Text.ToString() == string.Empty) { fatherBirthDate = null; } else { errorMessage += (string)FindResource("AddParentsWindowInvalidFatherBirthDateError"); } } try { deathDate = DateTime.ParseExact(this.FatherDeathDate.Text.ToString(), "dd/MM/yyyy", null, DateTimeStyles.None); fatherDeathDate = (Nullable <DateTime>)deathDate; } catch (FormatException) { if (this.FatherDeathDate.Text.ToString() == string.Empty) { fatherDeathDate = null; } else { errorMessage += (string)FindResource("AddParentsWindowInvalidFatherDeathDateError"); } } Nullable <DateTime> motherBirthDate = null; Nullable <DateTime> motherDeathDate = null; try { birthDate = DateTime.ParseExact(this.MotherBirthDate.Text.ToString(), "dd/MM/yyyy", null, DateTimeStyles.None); motherBirthDate = (Nullable <DateTime>)birthDate; } catch (FormatException) { if (this.MotherBirthDate.Text.ToString() == string.Empty) { motherBirthDate = null; } else { errorMessage += (string)FindResource("AddParentsWindowInvalidMotherBirthDateError"); } } try { deathDate = DateTime.ParseExact(this.MotherDeathDate.Text.ToString(), "dd/MM/yyyy", null, DateTimeStyles.None); motherDeathDate = (Nullable <DateTime>)deathDate; } catch (FormatException) { if (this.MotherDeathDate.Text.ToString() == string.Empty) { motherDeathDate = null; } else { errorMessage += (string)FindResource("AddParentsWindowInvalidMotherDeathDateError"); } } if (errorMessage == string.Empty) { Person parent = new Person(); if (FatherCheckBox.IsChecked == true) { parent.Name = this.FatherName.Text; parent.BirthDate = fatherBirthDate; parent.DeathDate = fatherDeathDate; parent.BirthPlace = this.FatherBirthPlace.Text; parent.Partner = this.MotherName.Text; parent.PartnerBirthDate = motherBirthDate; parent.PartnerDeathDate = motherDeathDate; parent.PartnerBirthPlace = this.MotherBirthPlace.Text; } else { parent.Name = this.MotherName.Text; parent.BirthDate = motherBirthDate; parent.DeathDate = motherDeathDate; parent.BirthPlace = this.MotherBirthPlace.Text; parent.Partner = this.FatherName.Text; parent.PartnerBirthDate = fatherBirthDate; parent.PartnerDeathDate = fatherDeathDate; parent.PartnerBirthPlace = this.FatherBirthPlace.Text; } Node <Person> parentNode = new Node <Person>(parent, null); parentNode.SubscribeToNewChildAdded(PersonTree.NewChildAdded); Node <Person> child = null; if (Regex.Split(this.ChildCombobox.SelectedItem.ToString(), " & ").Length == 1) { child = PersonTree.GetNodeByName(PersonTree.Tree, this.ChildCombobox.SelectedItem.ToString(), string.Empty); } else if (Regex.Split(this.ChildCombobox.SelectedItem.ToString(), " & ").Length == 2) { child = PersonTree.GetNodeByName(PersonTree.Tree, Regex.Split(this.ChildCombobox.SelectedItem.ToString(), " & ")[0], Regex.Split(this.ChildCombobox.SelectedItem.ToString(), " & ")[1]); } child.Parent = parentNode; parentNode.Children.Add(child); PersonTree.Tree = parentNode; ParentsAddedEventArgs eventArgs = new ParentsAddedEventArgs() { parent = parentNode }; ParentsAdded?.Invoke(this, eventArgs); this.Close(); } else { } } } /* * else * { * Node<Person> child = PersonTree.GetNodeByName(PersonTree.Tree , this.ChildCombobox.SelectedValue.ToString()); * string errorMessage = string.Empty; * * DateTime birthDate; * DateTime deathDate; * Nullable<DateTime> partnerBirthDate = null; * Nullable<DateTime> partnerDeathDate = null; * * try * { * birthDate = DateTime.ParseExact(this.PartnerBirthDate.Text.ToString(), "dd/MM/yyyy", null, DateTimeStyles.None); * partnerBirthDate = (Nullable<DateTime>) birthDate; * } * catch(FormatException) * { * if(this.PartnerBirthDate.Text.ToString() == string.Empty) * { * partnerBirthDate = null; * } * else * { * errorMessage += (string)FindResource("AddPartnerWindowPartnerBirthDateFormatError"); * } * } * * try * { * deathDate = DateTime.ParseExact(this.PartnerDeathDate.Text.ToString(), "dd/MM/yyyy", null, DateTimeStyles.None); * partnerDeathDate = (Nullable<DateTime>)deathDate; * } * catch (FormatException) * { * if (this.PartnerDeathDate.Text.ToString() == string.Empty) * { * partnerDeathDate = null; * } * else * { * errorMessage += "\n" + (string)FindResource("AddPartnerWindowPartnerDeathDateFormatError"); * } * } * * if (errorMessage == string.Empty) * { * child.Value.Partner = this.PartnerName.Text; * child.Value.PartnerBirthDate = partnerBirthDate; * child.Value.PartnerDeathDate = partnerDeathDate; * child.Value.PartnerBirthPlace = this.PartnerBirthPlace.Text; * * PartnerAddedEventArgs eventArgs = new PartnerAddedEventArgs(); * eventArgs.childName = child.Value.Name; * eventArgs.partnerName = child.Value.Partner; * eventArgs.birthDate = child.Value.PartnerBirthDate; * eventArgs.deathDate = child.Value.PartnerDeathDate; * eventArgs.birthPlace = child.Value.PartnerBirthPlace; * * PartnerAdded?.Invoke(this, eventArgs); * this.Close(); * } * else * { * MessageBox.Show(errorMessage, (string)FindResource("DateFormatErrorMessageBoxTitle")); * } * * } */ }
public void FirstChildAdded(object sender, NewChildAddedEventArgs <Person> e) { AddGeneration(new Generation(null)); generationList[generationList.Count - 1].AddPerson(PersonTree.GetNodeByName(PersonTree.Tree, e.child.Name, e.child.Partner)); PersonTree.Tree.Value.GenerationID = generationList[generationList.Count - 1].GenerationID; }
public void AddPartner(string childName, string partnerName, Nullable <DateTime> birthDate, Nullable <DateTime> deathDate, string birthPlace) { Node <Person> child = PersonTree.GetNodeByName(PersonTree.Tree, childName, partnerName); GetGenerationByID(child.Value.GenerationID).AddPartner(childName, partnerName, birthDate, deathDate, birthPlace); }
private void NewChildAdded(object sender, NewChildAddedEventArgs <Person> e) { generationManager.AddChild(PersonTree.GetNodeByName(PersonTree.Tree, e.child.Name, e.child.Partner)); }
private void ConnectChildrenToParents(object sender, GenerationChangedEventArgs e) { Generation generation = (Generation)sender; List <Node <Person> > personList = new List <Node <Person> >(); foreach (Grid grid in generation.GenerationGridList) { foreach (TextBox textBox in grid.Children.OfType <TextBox>()) { Node <Person> nextPerson = null; if (generation.TextBoxList.IndexOf(textBox) != generation.TextBoxList.Count - 1) { if (PersonTree.GetNodeByName(PersonTree.Tree, textBox.Text, generation.TextBoxList[generation.TextBoxList.IndexOf(textBox) + 1].Text) != null) { nextPerson = PersonTree.GetNodeByName(PersonTree.Tree, textBox.Text, generation.TextBoxList[generation.TextBoxList.IndexOf(textBox) + 1].Text); } } else { nextPerson = PersonTree.GetNodeByName(PersonTree.Tree, textBox.Text, string.Empty); } if (nextPerson != null) { if (nextPerson.Value.GenerationID == generation.GenerationID) { if (!personList.Any(item => item.Value.Name == nextPerson.Value.Name)) { personList.Add(nextPerson); } } } } } for (int i = 0; i < ConnectionsGrid.Children.Count; i++) { if (ConnectionsGrid.Children[i].GetType() == typeof(Line) && ((Line)ConnectionsGrid.Children[i]).Name == "Child" + generation.GenerationID.ToString().Replace("-", string.Empty)) { ConnectionsGrid.Children.Remove(ConnectionsGrid.Children[i]); i--; } } //for (int i = 0; i < generation.ParentsGridList[parentIndex].Children.Count - 1; i++) //{ // if (generation.ParentsGridList[parentIndex].Children[i].GetType() == typeof(Line) && // ((Line)generation.ParentsGridList[parentIndex].Children[i]).Name == // "Child" + generation.GenerationID.ToString().Replace("-", string.Empty)) // { // generation.ParentsGridList[parentIndex].Children.Remove(generation.ParentsGridList[parentIndex].Children[i]); // i--; // } //} foreach (Node <Person> person in personList) { int parentIndex = 0; int parentColumnIndex = 0; bool found = false; for (int i = 0; i < generation.ParentsGridList.Count; i++) { for (int j = 0; j < generation.ParentsGridList[i].Children.Count && !found; j++) { if (generation.ParentsGridList[i].Children[j].GetType() == typeof(TextBox)) { if ((string)generation.ParentsGridList[i].Children[j].GetValue(TextBox.TextProperty) == person.Parent.Value.Name) { parentIndex = i; parentColumnIndex = Grid.GetColumn(generation.ParentsGridList[i].Children[j]); found = true; } } } } Line verticalLine1 = new Line() { Stroke = Brushes.Black, Visibility = Visibility.Visible, StrokeThickness = 1, X1 = 12.5, X2 = 12.5, Y1 = SystemFonts.MessageFontSize, Y2 = SystemFonts.MessageFontSize * 2 + 1, Stretch = Stretch.None, Name = "Child" + generation.GenerationID.ToString().Replace("-", string.Empty) }; generation.ParentsGridList[parentIndex].Children.Add(verticalLine1); Grid.SetRow(verticalLine1, 0); Grid.SetColumn(verticalLine1, parentColumnIndex + 1); Line verticalLine2 = new Line() { Stroke = Brushes.Black, Visibility = Visibility.Visible, StrokeThickness = 1, X1 = 12.5, X2 = 12.5, Y1 = 0, Y2 = SystemFonts.MessageFontSize * 2 + 2, Stretch = Stretch.None, Name = "Child" + generation.GenerationID.ToString().Replace("-", string.Empty) }; generation.ParentsGridList[parentIndex].Children.Add(verticalLine2); Grid.SetRow(verticalLine2, 1); Grid.SetColumn(verticalLine2, parentColumnIndex + 1); Line verticalLine3 = new Line() { Stroke = Brushes.Black, Visibility = Visibility.Visible, StrokeThickness = 1, X1 = 12.5, X2 = 12.5, Y1 = 0, Y2 = SystemFonts.MessageFontSize * 3 + 8, Stretch = Stretch.None, Name = "Child" + generation.GenerationID.ToString().Replace("-", string.Empty) }; generation.ParentsGridList[parentIndex].Children.Add(verticalLine3); Grid.SetRow(verticalLine3, 2); Grid.SetColumn(verticalLine3, parentColumnIndex + 1); Line verticalLine4 = new Line() { Stroke = Brushes.Black, Visibility = Visibility.Visible, StrokeThickness = 1, X1 = 12.5, X2 = 12.5, Y1 = 0, Y2 = SystemFonts.MessageFontSize * 3 + 8, Stretch = Stretch.None, Name = "Child" + generation.GenerationID.ToString().Replace("-", string.Empty) }; generation.ParentsGridList[parentIndex].Children.Add(verticalLine4); Grid.SetRow(verticalLine4, 4); Grid.SetColumn(verticalLine4, parentColumnIndex + 1); verticalLine4.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); verticalLine4.Arrange(new Rect(verticalLine3.DesiredSize)); verticalLine4.UpdateLayout(); Point endPoint = verticalLine4.TranslatePoint(new Point(verticalLine4.X2, verticalLine4.Y2), ConnectionsGrid); int generationGridIndex = 0; int textBoxColumnIndex = 0; foreach (Grid grid in generation.GenerationGridList) { foreach (TextBox textBox in grid.Children.OfType <TextBox>()) { if (textBox.Text == person.Value.Name) { generationGridIndex = generation.GenerationGridList.IndexOf(grid); textBoxColumnIndex = Grid.GetColumn(textBox); } } } Line verticalLine5 = new Line() { Stroke = Brushes.Black, Visibility = Visibility.Visible, StrokeThickness = 1, X1 = 125, X2 = 125, Y1 = 4, Y2 = -SystemFonts.MessageFontSize * 2 - 2, Stretch = Stretch.None, Name = "Child" + generation.GenerationID.ToString().Replace("-", string.Empty) }; generation.GenerationGridList[generationGridIndex].Children.Add(verticalLine5); Grid.SetRow(verticalLine5, 0); Grid.SetColumn(verticalLine5, textBoxColumnIndex); verticalLine5.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); verticalLine5.Arrange(new Rect(verticalLine5.DesiredSize)); verticalLine5.UpdateLayout(); Point startPoint = verticalLine5.TranslatePoint(new Point(verticalLine5.X2, verticalLine5.Y2), ConnectionsGrid); Line horizontalLine1 = new Line() { Stroke = Brushes.Black, Visibility = Visibility.Visible, StrokeThickness = 1, X1 = startPoint.X, X2 = endPoint.X, Y1 = startPoint.Y, Y2 = endPoint.Y, Stretch = Stretch.None, Name = "Child" + generation.GenerationID.ToString().Replace("-", string.Empty) }; ConnectionsGrid.Children.Add(horizontalLine1); if (person.Value.Partner != string.Empty) { Line horizontalLine = new Line() { Stroke = Brushes.Black, Visibility = Visibility.Visible, StrokeThickness = 1, X1 = 0, X2 = 25, Y1 = SystemFonts.MessageFontSize, Y2 = SystemFonts.MessageFontSize, Stretch = Stretch.None, Name = "Child" + generation.GenerationID.ToString().Replace("-", string.Empty) }; generation.GenerationGridList[generationGridIndex].Children.Add(horizontalLine); Grid.SetRow(horizontalLine, 0); Grid.SetColumn(horizontalLine, textBoxColumnIndex + 1); } } List <Node <Person> > parentsList = new List <Node <Person> >(); foreach (Node <Person> person in personList) { if (!parentsList.Contains(person.Parent)) { parentsList.Add(person.Parent); } } foreach (Node <Person> parent in parentsList) { Node <Person> firstPerson = personList.FirstOrDefault(p => p.Parent == parent); Node <Person> lastPerson = personList.LastOrDefault(p => p.Parent == parent); Grid generationGrid = null; foreach (Grid grid in generation.GenerationGridList) { foreach (TextBox textBox in grid.Children.OfType <TextBox>()) { if (textBox.Text == firstPerson.Value.Name) { generationGrid = grid; } } } int numberOfPartners = 0; for (int i = personList.IndexOf(firstPerson); i < personList.IndexOf(lastPerson); i++) { if (personList[i].Value.Partner != string.Empty) { numberOfPartners++; } } } }