示例#1
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;
        }