Exemplo n.º 1
0
        public void TestAddMother(PersonView person)
        {
            // Select the person
            family.SelectedPerson = person;

            if (family.SelectedPerson.MotherRelationship != null)
            {
                // Should not be able to add this relationship
                Assert.IsFalse(family.SelectedPerson.AddMother.CanExecute(this), "CanExecute should be false");
            }
            else
            {                
                // Count people & relationships
                int people = family.Members.Count;
                int relationships = family.Relationships.Count;

                // Add relationship
                family.SelectedPerson.AddMother.Execute(this);

                // Should have this relationship
                Assert.IsNotNull(family.SelectedPerson.MotherRelationship, "Should have this relationship");

                // People & relationship count should have increased
                Assert.AreEqual(people + 1, family.Members.Count, "Wrong family member count");
                Assert.AreEqual(relationships + 1, family.Relationships.Count, "Wrong family relationship count");
            }
        }
Exemplo n.º 2
0
        public void TestRemoveMother(PersonView person)
        {
            // Select the person
            family.SelectedPerson = person;

            if (family.SelectedPerson.MotherRelationship != null)
            {                              
                // Count people & relationships
                int people = family.Members.Count;
                int relationships = family.Relationships.Count;
                int siblings = family.SelectedPerson.SiblingRelationships.Count;
                List<RelationshipView> siblingList = family.SelectedPerson.MotherRelationship.PersonSource.ChildRelationships.ToList();
                int motherChildren = family.SelectedPerson.MotherRelationship.PersonSource.ChildRelationships.Count;

                // Remove the relationship               
                family.SelectedPerson.MotherRelationship.Delete.Execute(this);
               
                // Should not have this relationship
                Assert.IsNull(family.SelectedPerson.MotherRelationship, "Should not have this relationship");

                // Should be able to add this relationship
                Assert.IsTrue(family.SelectedPerson.AddMother.CanExecute(this), "CanExecute should be true");
                
                // People count should remain
                Assert.AreEqual(people, family.Members.Count, "Wrong family member count");

                // Relationship count should have decreased
                Assert.AreEqual(relationships - 1, family.Relationships.Count, "Wrong family relationship count");

                // Sibling count could have decreased
                Assert.AreEqual(siblings - motherChildren + 1, family.SelectedPerson.SiblingRelationships.Count, "Wrong sibling count");

            }
            else
            {                
            }
        }
Exemplo n.º 3
0
 private void SelectVictim_Finalized(PersonView person, PersonView victim)
 {
     // Create relationship                      
     CreateRelationship(6, person, victim, DateTime.Now, DateTime.Now);
 }
Exemplo n.º 4
0
 private void SelectAbuser_Finalized(PersonView person, PersonView abuser)
 {
     // Create relationship                      
     CreateRelationship(6, abuser, person, DateTime.Now, DateTime.Now);
 }
Exemplo n.º 5
0
        private void SelectChild_Finalized(PersonView person, PersonView child)
        {
            // Create relationships
            foreach (RelationshipView childRelationship in person.ChildRelationships)
            {
                PersonView sibling = childRelationship.PersonDestination;

                if (sibling.Id < person.Id)
                { CreateRelationship(3, sibling, person, person.DOB, null); }
                else
                { CreateRelationship(3, person, sibling, sibling.DOB, null); }
            }
            if (person.Gender == "Female") { CreateRelationship(1, person, child, child.DOB, null); }
            if (person.Gender == "Male") { CreateRelationship(2, person, child, child.DOB, null); }


        }
Exemplo n.º 6
0
 private void SelectPartner_Finalized(PersonView person, PersonView partner)
 {
     // Create relationship
     if (person.Id < partner.Id)
     { CreateRelationship(5, person, partner, DateTime.Now, null); }
     else
     { CreateRelationship(5, partner, person, DateTime.Now, null); }
 }
Exemplo n.º 7
0
 private void SelectFriend_Finalized(PersonView person, PersonView friend)
 {
     // Create relationship
     if (person.Id < friend.Id)
     { CreateRelationship(4, person, friend, DateTime.Now, null); }
     else
     { CreateRelationship(4, friend, person, DateTime.Now, null); }
 }
Exemplo n.º 8
0
        private void SelectFather_Finalized(PersonView person, PersonView father)
        {

            if (father.Gender != "Male") { return; }           
            // Create new relationships            
            foreach (RelationshipView childRelationship in father.ChildRelationships)
            {
                PersonView sibling = childRelationship.PersonDestination;

                if (sibling.Id < person.Id)
                { CreateRelationship(3, sibling, person, person.DOB, null); }
                else
                { CreateRelationship(3, person, sibling, sibling.DOB, null); }
            }
            CreateRelationship(2, father, person, person.DOB, null);
        }
Exemplo n.º 9
0
        public void AddVictim_Executed()
        {
            PersonView victim = new PersonView(FamilyView.Instance.GetNextID());
            victim.FirstName = "Victim Of " + FirstName;
            victim.LastName = "";
            victim.Gender = "Not Specified";
            victim.GenerationIndex = GenerationIndex + 1;

            FamilyView.Instance.AddPersonToFamily(victim);
            FamilyView.Instance.CreateRelationship(6, this, victim, DateTime.Now, DateTime.Now);
        }
Exemplo n.º 10
0
        public void AddAbuser_Executed()
        {
            PersonView abuser = new PersonView(FamilyView.Instance.GetNextID());
            abuser.FirstName = "Abuser Of " + FirstName;
            abuser.LastName = "";
            abuser.Gender = "Not Specified";
            abuser.GenerationIndex = GenerationIndex - 1;

            FamilyView.Instance.AddPersonToFamily(abuser);
            FamilyView.Instance.CreateRelationship(6, abuser, this, DateTime.Now, DateTime.Now);
        }
Exemplo n.º 11
0
        public void AddChild_Executed()
        {
            // Create new child
            PersonView newChild = new PersonView(FamilyView.Instance.GetNextID());
            newChild.FirstName = "Child Of " + FirstName;
            newChild.LastName = "";
            newChild.Gender = "Not Specified";
            newChild.GenerationIndex = GenerationIndex + 1;
            FamilyView.Instance.AddPersonToFamily(newChild);

            // Create relationships               
            if (Gender == "Female")
            {
                FamilyView.Instance.CreateRelationship(1, this, newChild, newChild.DOB, null);
            }
            if (Gender == "Male")
            {
                FamilyView.Instance.CreateRelationship(2, this, newChild, newChild.DOB, null);
            }

            foreach (RelationshipView childRelationship in ChildRelationships)
            {
                FamilyView.Instance.CreateRelationship(3, childRelationship.PersonDestination, newChild, newChild.DOB, null);
            }
        }
Exemplo n.º 12
0
        public void AddPartner_Executed()
        {
            PersonView partner = new PersonView(FamilyView.Instance.GetNextID());
            partner.FirstName = "Partner Of " + FirstName;
            partner.LastName = "";
            partner.Gender = "Not Specified";
            partner.GenerationIndex = GenerationIndex;

            FamilyView.Instance.AddPersonToFamily(partner);
            FamilyView.Instance.CreateRelationship(5, this, partner, DateTime.Now, null);
        }
Exemplo n.º 13
0
        public void AddFriend_Executed()
        {
            PersonView friend = new PersonView(FamilyView.Instance.GetNextID());
            friend.FirstName = "Friend Of " + FirstName;
            friend.LastName = "";
            friend.Gender = "Not Specified";
            friend.GenerationIndex = GenerationIndex;

            FamilyView.Instance.AddPersonToFamily(friend);
            FamilyView.Instance.CreateRelationship(4, this, friend, DateTime.Now, null);
        }
Exemplo n.º 14
0
        public void AddSiblingByFather_Executed()
        {
            // Create new sibling
            PersonView newSibling = new PersonView(FamilyView.Instance.GetNextID());
            newSibling.FirstName = "Sibling Of " + FirstName;
            newSibling.LastName = "";
            newSibling.Gender = "Not Specified";
            newSibling.GenerationIndex = GenerationIndex;
            FamilyView.Instance.AddPersonToFamily(newSibling);

            // Create new relationships

            // With me
            FamilyView.Instance.CreateRelationship(3, this, newSibling, newSibling.DOB, null);

            // With father & his children
            if (FatherRelationship != null)
            {
                PersonView dad = FatherRelationship.PersonSource;
                foreach (RelationshipView childRelationship in dad.ChildRelationships)
                {
                    FamilyView.Instance.CreateRelationship(3, childRelationship.PersonDestination, newSibling, newSibling.DOB, null);
                }
                FamilyView.Instance.CreateRelationship(2, dad, newSibling, newSibling.DOB, null);
            }

        }
Exemplo n.º 15
0
        public void AddSiblingUnknownParents_Executed()
        {
            // Create new sibling
            PersonView newSibling = new PersonView(FamilyView.Instance.GetNextID());
            newSibling.FirstName = "Sibling Of " + FirstName;
            newSibling.LastName = "";
            newSibling.Gender = "Not Specified";
            newSibling.GenerationIndex = GenerationIndex;
            FamilyView.Instance.AddPersonToFamily(newSibling);

            // Create new relationships

            // With me
            FamilyView.Instance.CreateRelationship(3, this, newSibling, newSibling.DOB, null);
            
        }
Exemplo n.º 16
0
        public FamilyView()
        {            
            Tree = new Tree();
            Members = new ObservableCollection<PersonView> { };
            Relationships = new ObservableCollection<RelationshipView> { };            
            SelectedPerson = new PersonView();
            RecordedFamilyModels = new ObservableCollection<FamilyModel> { };
            UndoDescriptions = new ObservableCollection<string> { };
            UndoneFamilyModels = new ObservableCollection<FamilyModel> { };
            RedoDescriptions = new ObservableCollection<string> { };
            InitiateCommands();
            PropertyChanged += new PropertyChangedEventHandler(PropertyChangedHandler);
            Members.CollectionChanged += new NotifyCollectionChangedEventHandler(CollectionChangedHandler);
            Relationships.CollectionChanged += new NotifyCollectionChangedEventHandler(CollectionChangedHandler);
            CreateNewFamily();

        }
Exemplo n.º 17
0
 private bool SelectFather_CanFinalize(PersonView person)
 {
     // Not in previous generation
     if (person.GenerationIndex != SelectCommandTargetPerson.GenerationIndex - 1) { return false; }
     // Not male
     if (person.Gender != "Male") { return false; }
     return true;
 }
Exemplo n.º 18
0
        private string GetAgeAtDate(PersonView person, DateTime? dateTime)
        {
            if (dateTime != null)
            {
                DateTime date = (DateTime)dateTime;

                int age = date.Year - person.DOB.Year;
                if (person.DOB > date.AddYears(-age) && age > 0) age--;
                if (age < 2)
                {
                    double days = (date - person.DOB).TotalDays;
                    double months = days / 30;                   
                    if (months <= 1)
                    {
                        if (Math.Floor(days) <= 0) { return "birth"; }
                        return Math.Floor(days).ToString() + " days";
                    }
                    return "approx " + Math.Floor(months).ToString() + " months";
                }
                return age.ToString() + " years";
            }
            else { return ""; }
        }
Exemplo n.º 19
0
 private bool SelectFriend_CanFinalize(PersonView person)
 {
     // Not itself
     if (person == SelectCommandTargetPerson) { return false; }
     // Not already a friend
     foreach (RelationshipView friendRelationship in person.FriendRelationships)
     {
         if (friendRelationship.PersonSource == SelectCommandTargetPerson) { return false; }
         if (friendRelationship.PersonDestination == SelectCommandTargetPerson) { return false; }
     }        
        
     return true;
 }
Exemplo n.º 20
0
        public void EnterSetCommandRelation(PersonView person)
        {

            switch (SelectCommandInProgressType)
            {
                case 0: // No command in progress
                    FamilyTreeCursor = Cursors.Arrow;                    
                    break;
                case 1: // Set mother
                    if (SelectMother_CanFinalize(person))
                    { FamilyTreeCursor = Cursors.Hand; }
                    else { FamilyTreeCursor = Cursors.No; }
                    break;
                case 2: // Set father
                    if (SelectFather_CanFinalize(person))
                    { FamilyTreeCursor = Cursors.Hand; }
                    else { FamilyTreeCursor = Cursors.No; }
                    break;
                case 3: // Set friend
                    if (SelectFriend_CanFinalize(person))
                    { FamilyTreeCursor = Cursors.Hand; }
                    else { FamilyTreeCursor = Cursors.No; }
                    break;
                case 4: // Set partner
                    if (SelectPartner_CanFinalize(person))
                    { FamilyTreeCursor = Cursors.Hand; }
                    else { FamilyTreeCursor = Cursors.No; }
                    break;
                case 5: // Set child
                    if (SelectChild_CanFinalize(person))
                    { FamilyTreeCursor = Cursors.Hand; }
                    else { FamilyTreeCursor = Cursors.No; }
                    break;
                case 6: // Set abuser
                    if (SelectAbuser_CanFinalize(person))
                    { FamilyTreeCursor = Cursors.Hand; }
                    else { FamilyTreeCursor = Cursors.No; }
                    break;
                case 7: // Set victim
                    if (SelectVictim_CanFinalize(person))
                    { FamilyTreeCursor = Cursors.Hand; }
                    else { FamilyTreeCursor = Cursors.No; }
                    break;
                default:
                    FamilyTreeCursor = Cursors.Arrow;
                    break;
            }
        }
Exemplo n.º 21
0
 private bool SelectPartner_CanFinalize(PersonView person)
 {
     // Not itself
     if (person == SelectCommandTargetPerson) { return false; }
     // Not already a partner
     foreach (RelationshipView partnerRelationship in person.PartnerRelationships)
     {
         if (partnerRelationship.PersonSource == SelectCommandTargetPerson) { return false; }
         if (partnerRelationship.PersonDestination == SelectCommandTargetPerson) { return false; }
     }
     return true;
 }
Exemplo n.º 22
0
        public void SelectPerson(PersonView person)

        {
            if (SelectedPerson != null)
            {
                SelectedPerson.Selected = false;
            }
            if (person != null)
            {
                SelectedPerson = person;
                SelectedPerson.Selected = true;
            }
            else
            {
                SelectedPerson = null;
            }            
        }
Exemplo n.º 23
0
 private bool SelectChild_CanFinalize(PersonView child)
 {
     // Not already a child
     foreach (RelationshipView childRelationship in SelectCommandTargetPerson.ChildRelationships)
     {                
         if (childRelationship.PersonDestination == child) { return false; }
     }
     // Not in the next generation
     if (SelectCommandTargetPerson.GenerationIndex + 1 != child.GenerationIndex) { return false; }
     return true;
 }
Exemplo n.º 24
0
 public void AddPersonToFamily(PersonView person)
 {
     if (Members == null)
     {
         Members = new ObservableCollection<PersonView> { };
     }
     Members.Add(person);
     OrderSiblings(person.GenerationIndex);
     RefreshTreeLayout();
     person.PropertyChanged += PersonPropertyChangedHandler;
     person.BasePropertyChanged += BasePropertyChangedHandler;
 }
Exemplo n.º 25
0
 private bool SelectAbuser_CanFinalize(PersonView person)
 {
     // Not already an abuser
     foreach (RelationshipView victimRelationship in person.VictimRelationships)
     {               
         if (victimRelationship.PersonDestination == SelectCommandTargetPerson) { return false; }
     }
     
     return true;
 }
Exemplo n.º 26
0
        public void CreateRelationship(int type, PersonView personSource, PersonView personDestination, DateTime? startDate, DateTime? endDate)
        {

            if (personSource == personDestination) { return; }
            int Id = type * (int)Math.Pow(10, 6) + personSource.Id * (int)Math.Pow(10, 3) + personDestination.Id;

            RelationshipView relationship = FamilyView.Instance.GetRelationship(Id);
            if (relationship != null)
            {
                relationship.Refresh();
            }
            else
            {
                RelationshipView newRelationship = new RelationshipView(Id, startDate, endDate);
                FamilyView.Instance.Relationships.Add(newRelationship);
                newRelationship.PropertyChanged += RelationshipPropertyChangedHandler;
                newRelationship.BasePropertyChanged += BasePropertyChangedHandler;

            }
        }
Exemplo n.º 27
0
 private bool SelectVictim_CanFinalize(PersonView person)
 {
     // Not already a victim
     foreach (RelationshipView abuserRelationship in person.AbuserRelationships)
     {
         if (abuserRelationship.PersonSource == SelectCommandTargetPerson) { return false; }
     }
     return true;
 }
Exemplo n.º 28
0
        private void RestoreFamilyModel(FamilyModel model)
        {
            
            disableChangeRecording = true;
            
            Settings.Instance.Person = new PersonSettings();
            if (model.PersonSettings != null) { Settings.Instance.Person.CopyProperties(model.PersonSettings); }

            Settings.Instance.Relationship = new RelationshipSettings();
            if (model.RelationshipSettings != null) { Settings.Instance.Relationship.CopyProperties(model.RelationshipSettings); }   
                    
            Members.Clear();
            if (model.Members != null)
            {
                foreach (PersonModel personModel in model.Members)
                {
                    PersonView personView = new PersonView(GetNextID());
                    personView.CopyBaseProperties(personModel);
                    Members.Add(personView);                                       
                }
            }

            Relationships.Clear();
            if (model.Relationships != null)
            {
                foreach (RelationshipModel relationshipModel in model.Relationships)
                {
                    RelationshipView relationshipView = new RelationshipView(relationshipModel.Id);
                    relationshipView.CopyBaseProperties(relationshipModel);
                    Relationships.Add(relationshipView);                                     
                }
            }
            Tree = new Tree();
            if (model.Tree != null)
            {
                Tree.CopyProperties(model.Tree);
            }
                 
            SelectedPerson = GetPerson(Tree.SelectedPersonId);
            if (SelectedPerson != null) { SelectedPerson.Selected = true; }

            SelectedRelationship = GetRelationship(Tree.SelectedRelationshipId);
            if (SelectedRelationship != null) { SelectedRelationship.Selected = true; }
            
            RefreshTreeLayout();
            SubscribeToEvents();
            CurrentFamilyModel = GetCurrentFamilyModel();            
            Undo.RaiseCanExecuteChanged();
            Redo.RaiseCanExecuteChanged();
            lastChangeTime = DateTime.Now;
            disableChangeRecording = false;

            FamilyTreeCursor = Cursors.Arrow;
            SelectCommandInProgressType = 0;
        }
Exemplo n.º 29
0
 public void FinalizeSetCommand(PersonView setCommandRelationPerson)
 {
     if (SelectCommandInProgress)
     {
         switch (SelectCommandInProgressType)
         {
             case 1: // Set mother
                 if (SelectMother_CanFinalize(setCommandRelationPerson))
                 { SelectMother_Finalized(SelectCommandTargetPerson, setCommandRelationPerson); }
                 break;
             case 2: // Set father
                 if (SelectFather_CanFinalize(setCommandRelationPerson))
                 { SelectFather_Finalized(SelectCommandTargetPerson, setCommandRelationPerson); }
                 break;
             case 3: // Set friend
                 if (SelectFriend_CanFinalize(setCommandRelationPerson))
                 { SelectFriend_Finalized(SelectCommandTargetPerson, setCommandRelationPerson); }
                 break;
             case 4: // Set partner
                 if (SelectPartner_CanFinalize(setCommandRelationPerson))
                 { SelectPartner_Finalized(SelectCommandTargetPerson, setCommandRelationPerson); }
                 break;
             case 5: // Set child
                 if (SelectChild_CanFinalize(setCommandRelationPerson))
                 { SelectChild_Finalized(SelectCommandTargetPerson, setCommandRelationPerson); }
                 break;
             case 6: // Set abuser
                 if (SelectAbuser_CanFinalize(setCommandRelationPerson))
                 { SelectAbuser_Finalized(SelectCommandTargetPerson, setCommandRelationPerson); }
                 break;
             case 7: // Set victim
                 if (SelectVictim_CanFinalize(setCommandRelationPerson))
                 { SelectVictim_Finalized(SelectCommandTargetPerson, setCommandRelationPerson); }
                 break;
             default:
                 break;
         }
     }
     EndSetCommand();
 }
Exemplo n.º 30
0
 private void SetPersonPosition(PersonView person)
 {
     person.X = Tree.Width / 2 + person.SiblingIndex * (Settings.Instance.Person.Width + Settings.Instance.Person.HorizontalSpace) - Settings.Instance.Person.Width / 2;
     person.Y = (person.GenerationIndex - Members.Min(m => m.GenerationIndex)) * (Settings.Instance.Person.Height + Settings.Instance.Person.VerticalSpace) + Settings.Instance.Person.Height / 2;
 }