/// <summary> /// Display the Details Add Intermediate section /// </summary> private void ShowDetailsAddIntermediate(ParentSetCollection possibleParents) { // Display the Details Add Intermediate section ((Storyboard)Resources["ExpandDetailsAddIntermediate"]).Begin(this); // Bind the possible parents ParentsListBox.ItemsSource = possibleParents; }
/// <summary> /// Gets the combination of parent sets for this person and his/her spouses /// </summary> /// <returns></returns> public ParentSetCollection MakeParentSets() { ParentSetCollection parentSets = new ParentSetCollection(); foreach (Person spouse in Spouses) { ParentSet ps = new ParentSet(this, spouse); // Don't add the same parent set twice. if (!parentSets.Contains(ps)) { parentSets.Add(ps); } } return(parentSets); }
private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { if (DataContext != null) { if (family != null && family.Current != null && family.Current.HasParents) { // Programmatically set the possible parents that can be selected. ParentSetCollection psc = family.Current.PossibleParentSets; ParentsEditListBox.ItemsSource = psc; // Cannot simply set the selected parent like so: ParentsEditListBox.SelectedItem = family.Current.ParentSet; // Need to use .Equals and set the index for (int i = 0; i <= psc.Count - 1; i++) { if (psc[i].Equals(family.Current.ParentSet)) { ParentsEditListBox.SelectedIndex = i; } } } SetFamilyMemberAddButton(); } }
private void AddExistingButton_Click(object sender, RoutedEventArgs e) { Person existingPerson = (Person)ExistingPeopleListBox.SelectedItem; bool SelectParent = false; ParentSetCollection possibleParents = family.Current.PossibleParentSets; // Perform the action based on the selected relationship switch ((FamilyMemberComboBoxValue)ExistingFamilyMemberComboBox.SelectedValue) { case FamilyMemberComboBoxValue.Father: existingPerson.Gender = Gender.Male; RelationshipHelper.AddParent(family, family.Current, existingPerson); SetNextFamilyMemberAction(FamilyMemberComboBoxValue.Mother); break; case FamilyMemberComboBoxValue.Mother: existingPerson.Gender = Gender.Female; RelationshipHelper.AddParent(family, family.Current, existingPerson); SetNextFamilyMemberAction(FamilyMemberComboBoxValue.Brother); break; case FamilyMemberComboBoxValue.Brother: existingPerson.Gender = Gender.Male; // Check to see if there are multiple parents if (possibleParents.Count > 1) { SelectParent = true; } else { RelationshipHelper.AddSibling(family, family.Current, existingPerson); } break; case FamilyMemberComboBoxValue.Sister: existingPerson.Gender = Gender.Female; // Check to see if there are multiple parents if (possibleParents.Count > 1) { SelectParent = true; } else { RelationshipHelper.AddSibling(family, family.Current, existingPerson); } break; case FamilyMemberComboBoxValue.Spouse: RelationshipHelper.AddSpouse(family, family.Current, existingPerson, SpouseModifier.Current); SetNextFamilyMemberAction(FamilyMemberComboBoxValue.Son); break; case FamilyMemberComboBoxValue.Son: existingPerson.Gender = Gender.Male; if (family.Current.Spouses.Count > 1) { possibleParents = family.Current.MakeParentSets(); SelectParent = true; } else { RelationshipHelper.AddChild(family, family.Current, existingPerson); } break; case FamilyMemberComboBoxValue.Daughter: existingPerson.Gender = Gender.Female; if (family.Current.Spouses.Count > 1) { possibleParents = family.Current.MakeParentSets(); SelectParent = true; } else { RelationshipHelper.AddChild(family, family.Current, existingPerson); } break; } if (SelectParent) { ShowDetailsAddIntermediate(possibleParents); } else { // Use animation to hide the Details Add section ((Storyboard)Resources["CollapseAddExisting"]).Begin(this); FamilyMemberComboBox.SelectedIndex = -1; FamilyMemberAddButton.Focus(); } }
/// <summary> /// Handles adding new people /// </summary> private void AddButton_Click(object sender, RoutedEventArgs e) { // To make it a little more user friendly, set the next action for the family member button to be the same as the current relationship being added. SetNextFamilyMemberAction((FamilyMemberComboBoxValue)FamilyMemberComboBox.SelectedValue); // The new person to be added Person newPerson = new Person(FirstNameInputTextBox.Text, LastNameInputTextBox.Text) { IsLiving = (IsLivingInputCheckbox.IsChecked == null) ? true : (bool)IsLivingInputCheckbox.IsChecked }; DateTime birthdate = App.StringToDate(BirthDateInputTextBox.Text); if (birthdate != DateTime.MinValue) { newPerson.BirthDate = birthdate; } newPerson.BirthPlace = BirthPlaceInputTextBox.Text; bool SelectParent = false; ParentSetCollection possibleParents = family.Current.PossibleParentSets; // Perform the action based on the selected relationship switch ((FamilyMemberComboBoxValue)FamilyMemberComboBox.SelectedValue) { case FamilyMemberComboBoxValue.Father: newPerson.Gender = Gender.Male; RelationshipHelper.AddParent(family, family.Current, newPerson); SetNextFamilyMemberAction(FamilyMemberComboBoxValue.Mother); break; case FamilyMemberComboBoxValue.Mother: newPerson.Gender = Gender.Female; RelationshipHelper.AddParent(family, family.Current, newPerson); SetNextFamilyMemberAction(FamilyMemberComboBoxValue.Brother); break; case FamilyMemberComboBoxValue.Brother: newPerson.Gender = Gender.Male; // Check to see if there are multiple parents if (possibleParents.Count > 1) { SelectParent = true; } else { RelationshipHelper.AddSibling(family, family.Current, newPerson); } break; case FamilyMemberComboBoxValue.Sister: newPerson.Gender = Gender.Female; // Check to see if there are multiple parents if (possibleParents.Count > 1) { SelectParent = true; } else { RelationshipHelper.AddSibling(family, family.Current, newPerson); } break; case FamilyMemberComboBoxValue.Spouse: RelationshipHelper.AddSpouse(family, family.Current, newPerson, SpouseModifier.Current); SetNextFamilyMemberAction(FamilyMemberComboBoxValue.Son); break; case FamilyMemberComboBoxValue.Son: newPerson.Gender = Gender.Male; if (family.Current.Spouses.Count > 1) { possibleParents = family.Current.MakeParentSets(); SelectParent = true; } else { RelationshipHelper.AddChild(family, family.Current, newPerson); } break; case FamilyMemberComboBoxValue.Daughter: newPerson.Gender = Gender.Female; if (family.Current.Spouses.Count > 1) { possibleParents = family.Current.MakeParentSets(); SelectParent = true; } else { RelationshipHelper.AddChild(family, family.Current, newPerson); } break; } if (SelectParent) { ShowDetailsAddIntermediate(possibleParents); } else { // Use animation to hide the Details Add section ((Storyboard)Resources["CollapseDetailsAdd"]).Begin(this); FamilyMemberComboBox.SelectedIndex = -1; FamilyMemberAddButton.Focus(); } family.OnContentChanged(newPerson); }
/// <summary> /// Display the Details Add Intermediate section /// </summary> private void ShowDetailsAddIntermediate(ParentSetCollection possibleParents) { // Display the Details Add Intermediate section ((Storyboard)this.Resources["ExpandDetailsAddIntermediate"]).Begin(this); // Bind the possible parents ParentsListBox.ItemsSource = possibleParents; }