Esempio n. 1
0
        public void gt_bind_family_child(object familyPtr, object childPtr)
        {
            GDMFamilyRecord fRec = familyPtr as GDMFamilyRecord;

            if (fRec == null)
            {
                return;
            }

            GDMIndividualRecord chRec = childPtr as GDMIndividualRecord;

            fRec.AddChild(chRec);
        }
        private void ParentAdd(GDMSex needSex)
        {
            TreeChartPerson p = fView.TreeBox.Selected;

            if (p == null || p.Rec == null)
            {
                return;
            }

            bool needParent  = false;
            bool familyExist = p.Rec.GetParentsFamily() != null;

            if (familyExist)
            {
                GDMIndividualRecord mother, father;
                GDMFamilyRecord     fam = p.Rec.GetParentsFamily();
                if (fam == null)
                {
                    father = null;
                    mother = null;
                }
                else
                {
                    father = fam.Husband.Individual;
                    mother = fam.Wife.Individual;
                }

                needParent = (father == null && needSex == GDMSex.svMale) ||
                             (mother == null && needSex == GDMSex.svFemale);
            }

            if (!familyExist || needParent)
            {
                GDMIndividualRecord child  = p.Rec;
                GDMFamilyRecord     fam    = (familyExist) ? p.Rec.GetParentsFamily() : fBase.Context.Tree.CreateFamily();
                GDMIndividualRecord parent = fBase.Context.SelectPerson(null, TargetMode.tmParent, needSex);
                if (parent != null)
                {
                    fam.AddSpouse(parent);
                    if (!familyExist)
                    {
                        fam.AddChild(child);
                    }

                    UpdateChart();
                }
            }
        }
Esempio n. 3
0
        private void AddChild(GDMIndividualRecord parent, int marrNum, GDMIndividualRecord child)
        {
            if (marrNum <= 0)
            {
                marrNum = 1;
            }

            GDMFamilyRecord family = GetFamilyByNum(parent, marrNum);

            if (family != null)
            {
                family.AddChild(child);
            }
            else
            {
                // ???
            }
        }
        // TODO: refactor
        private void ParentAdd(GDMSex needSex)
        {
            TreeChartPerson p = fView.TreeBox.Selected;

            if (p == null || p.Rec == null)
            {
                return;
            }

            bool needParent;

            GDMFamilyRecord fam         = fBase.Context.Tree.GetParentsFamily(p.Rec);
            bool            familyExist = fam != null;

            if (familyExist)
            {
                GDMIndividualRecord father, mother;
                fBase.Context.Tree.GetSpouses(fam, out father, out mother);

                needParent = (father == null && needSex == GDMSex.svMale) ||
                             (mother == null && needSex == GDMSex.svFemale);
            }
            else
            {
                needParent = true;
            }

            if (needParent)
            {
                GDMIndividualRecord parent = fBase.Context.SelectPerson(p.Rec, TargetMode.tmChild, needSex);
                if (parent != null)
                {
                    if (!familyExist)
                    {
                        fam = fBase.Context.Tree.CreateFamily();
                        fam.AddChild(p.Rec);
                    }

                    fam.AddSpouse(parent);

                    UpdateChart();
                }
            }
        }
Esempio n. 5
0
        private bool ProcessIndividualParents(bool redo)
        {
            GDMIndividualRecord iRec      = fObj as GDMIndividualRecord;
            GDMFamilyRecord     familyRec = fNewVal as GDMFamilyRecord;

            if (iRec == null || familyRec == null)
            {
                return(false);
            }

            if (fType == OperationType.otIndividualParentsDetach)
            {
                redo = !redo;
            }
            if (redo)
            {
                familyRec.AddChild(iRec);
            }
            else
            {
                familyRec.RemoveChild(iRec);
            }
            return(true);
        }
Esempio n. 6
0
        // TODO: rollback changes when exception!
        private void ParseSource()
        {
            int srcYear;

            if (!int.TryParse(edSourceYear.Text, out srcYear))
            {
                ShowError(fLangMan.LS(FLS.LSID_SourceYearInvalid));
                return;
            }

            string srcName = cbSource.Text;
            string srcPage = edPage.Text;
            string place   = edPlace.Text;

            GDMSourceRecord srcRec = null;

            if (!string.IsNullOrEmpty(srcName))
            {
                srcRec = fBase.Context.FindSource(srcName);
                if (srcRec == null)
                {
                    srcRec            = fBase.Context.Tree.CreateSource();
                    srcRec.ShortTitle = srcName;
                }
            }

            GDMIndividualRecord iMain = null;

            int num = dataGridView1.Rows.Count;

            for (int r = 0; r < num; r++)
            {
                DataGridViewRow row = dataGridView1.Rows[r];

                string lnk     = CheckStr((string)row.Cells[0].Value);
                string nm      = CheckStr((string)row.Cells[1].Value);
                string pt      = CheckStr((string)row.Cells[2].Value);
                string fm      = CheckStr((string)row.Cells[3].Value);
                string age     = CheckStr((string)row.Cells[4].Value);
                string comment = CheckStr((string)row.Cells[5].Value);

                if (!string.IsNullOrEmpty(lnk))
                {
                    PersonLink link = GetLinkByName(lnk);
                    if (link == PersonLink.plNone)
                    {
                        continue;
                    }

                    GDMSex sx = fBase.Context.DefineSex(nm, pt);
                    GDMIndividualRecord iRec = fBase.Context.CreatePersonEx(nm, pt, fm, sx, false);

                    if (!string.IsNullOrEmpty(age) && ConvertHelper.IsDigits(age))
                    {
                        int birthYear = srcYear - int.Parse(age);
                        fBase.Context.CreateEventEx(iRec, GEDCOMTagName.BIRT, "ABT " + birthYear.ToString(), "");
                    }

                    if (!string.IsNullOrEmpty(place))
                    {
                        GDMCustomEvent evt = fBase.Context.CreateEventEx(iRec, GEDCOMTagName.RESI, "", "");
                        evt.Place.StringValue = place;
                    }

                    if (!string.IsNullOrEmpty(comment))
                    {
                        GDMNoteRecord noteRec = fBase.Context.Tree.CreateNote();
                        noteRec.SetNoteText(comment);
                        iRec.AddNote(noteRec);
                    }

                    if (srcRec != null)
                    {
                        iRec.AddSource(srcRec, srcPage, 0);
                    }

                    fBase.NotifyRecord(iRec, RecordAction.raAdd);

                    GDMFamilyRecord family = null;

                    if (link == PersonLink.plPerson)
                    {
                        iMain = iRec;
                        string evName = "";

                        if (rbSK_Met.Checked)
                        {
                            switch (cbEventType.SelectedIndex)
                            {
                            case  0:
                                evName = GEDCOMTagName.BIRT;
                                break;

                            case  1:
                                evName = GEDCOMTagName.DEAT;
                                break;

                            case  2:
                                evName = GEDCOMTagName.MARR;
                                break;
                            }
                        }

                        if (evName == GEDCOMTagName.BIRT || evName == GEDCOMTagName.DEAT)
                        {
                            GDMCustomEvent evt = fBase.Context.CreateEventEx(iRec, evName, GDMDate.CreateByFormattedStr(edEventDate.Text, false), "");
                            evt.Place.StringValue = place;
                        }
                        else if (evName == GEDCOMTagName.MARR)
                        {
                            family = iRec.GetMarriageFamily(true);
                            GDMCustomEvent evt = fBase.Context.CreateEventEx(family, evName, GDMDate.CreateByFormattedStr(edEventDate.Text, false), "");
                            evt.Place.StringValue = place;
                        }
                    }
                    else
                    {
                        if (iMain == null)
                        {
                            throw new PersonScanException(fLangMan.LS(FLS.LSID_BasePersonInvalid));
                        }
                        else
                        {
                            switch (link)
                            {
                            case PersonLink.plFather:
                            case PersonLink.plMother:
                                family = iMain.GetParentsFamily(true);
                                family.AddSpouse(iRec);
                                break;

                            case PersonLink.plGodparent:
                                iMain.AddAssociation(fLangMan.LS(FLS.LSID_PLGodparent), iRec);
                                break;

                            case PersonLink.plSpouse:
                                family = iMain.GetMarriageFamily(true);
                                family.AddSpouse(iRec);
                                break;

                            case PersonLink.plChild:
                                family = iMain.GetMarriageFamily(true);
                                family.AddChild(iRec);
                                break;
                            }
                        }
                    }
                }
            }

            InitSourceControls();
        }
Esempio n. 7
0
        protected override void LoadFromReader(Stream fileStream, StreamReader reader, string streamCharset = null)
        {
            fTree.State = GDMTreeState.osLoading;
            try {
                ProgressEventHandler progressHandler = fTree.OnProgress;

                long fileSize = fileStream.Length;
                int  progress = 0;

                GDMIndividualRecord lastIndividual = null;
                FXTag            lastTagType       = FXTag.Unknown;
                RelationshipType relationshipType  = RelationshipType.None;
                var families   = new List <FamilyRec>();
                var children   = new List <ChildRec>();
                var indiIdents = new Dictionary <string, GDMIndividualRecord>();

                XmlReaderSettings settings = new XmlReaderSettings();
                settings.DtdProcessing = DtdProcessing.Ignore;
                using (XmlReader xr = XmlReader.Create(fileStream, settings)) {
                    while (xr.Read())
                    {
                        if (xr.NodeType == XmlNodeType.Element && !xr.IsEmptyElement)
                        {
                            string nodeType = xr.Name;
                            if (nodeType == "Person")
                            {
                                lastIndividual = fTree.CreateIndividual();
                                var persName = new GDMPersonalName();
                                lastIndividual.AddPersonalName(persName);

                                // add an empty birth event
                                AddEvent(lastIndividual, GEDCOMTagName.BIRT);

                                lastIndividual.UID = xr.GetAttribute("Id");
                                indiIdents.Add(lastIndividual.UID, lastIndividual);
                            }
                            else if (nodeType == "Gender")
                            {
                                lastTagType = FXTag.Gender;
                            }
                            else if (nodeType == "Restriction")
                            {
                                lastTagType = FXTag.Restriction;
                            }
                            else if (nodeType == "FirstName")
                            {
                                lastTagType = FXTag.FirstName;
                            }
                            else if (nodeType == "LastName")
                            {
                                lastTagType = FXTag.LastName;
                            }
                            else if (nodeType == "Suffix")
                            {
                                lastTagType = FXTag.Suffix;
                            }
                            else if (nodeType == "IsLiving")
                            {
                                lastTagType = FXTag.IsLiving;
                            }
                            else if (nodeType == "Note")
                            {
                                lastTagType = FXTag.Note;
                            }
                            else if (nodeType == "BirthDate")
                            {
                                lastTagType = FXTag.BirthDate;
                            }
                            else if (nodeType == "BirthPlace")
                            {
                                lastTagType = FXTag.BirthPlace;
                            }
                            else if (nodeType == "DeathDate")
                            {
                                lastTagType = FXTag.DeathDate;
                            }
                            else if (nodeType == "DeathPlace")
                            {
                                lastTagType = FXTag.DeathPlace;
                            }
                            else if (nodeType == "RelationshipType")
                            {
                                lastTagType = FXTag.Relationship;
                            }
                            else if (nodeType == "PersonId")
                            {
                                switch (relationshipType)
                                {
                                case RelationshipType.Spouse:
                                    lastTagType = FXTag.SpouseLink;
                                    break;

                                case RelationshipType.Child:
                                    lastTagType = FXTag.ChildLink;
                                    break;

                                default:
                                    lastTagType = FXTag.Unknown;
                                    break;
                                }
                                relationshipType = RelationshipType.None;
                            }
                        }
                        else if (xr.NodeType == XmlNodeType.Text)
                        {
                            string nodeValue = xr.Value;
                            if (!string.IsNullOrEmpty(nodeValue))
                            {
                                switch (lastTagType)
                                {
                                case FXTag.Gender:
                                    if (nodeValue == "Male")
                                    {
                                        lastIndividual.Sex = GDMSex.svMale;
                                    }
                                    else if (nodeValue == "Female")
                                    {
                                        lastIndividual.Sex = GDMSex.svFemale;
                                    }
                                    break;

                                case FXTag.Restriction:
                                    // FIXME: parse from nodeValue
                                    lastIndividual.Restriction = GDMRestriction.rnNone;
                                    break;

                                case FXTag.FirstName:
                                    lastIndividual.PersonalNames[0].FirstPart = nodeValue;
                                    break;

                                case FXTag.LastName:
                                    lastIndividual.PersonalNames[0].Surname = nodeValue;
                                    break;

                                case FXTag.Suffix:
                                    lastIndividual.PersonalNames[0].LastPart = nodeValue;
                                    break;

                                case FXTag.IsLiving:
                                    bool isLiving = string.Equals(nodeValue, "true", StringComparison.InvariantCultureIgnoreCase);
                                    if (!isLiving)
                                    {
                                        AddEvent(lastIndividual, GEDCOMTagName.DEAT);
                                    }
                                    break;

                                case FXTag.BirthDate:
                                case FXTag.BirthPlace:
                                    var birthEvent = lastIndividual.FindEvent("BIRT");
                                    if (lastTagType == FXTag.BirthDate)
                                    {
                                        SetEventDate(birthEvent, nodeValue);
                                    }
                                    else
                                    {
                                        birthEvent.Place.StringValue = nodeValue;
                                    }
                                    break;

                                case FXTag.DeathDate:
                                case FXTag.DeathPlace:
                                    var deathEvent = lastIndividual.FindEvent("DEAT");
                                    // IsLiving may be wrong
                                    if (deathEvent == null)
                                    {
                                        deathEvent = AddEvent(lastIndividual, GEDCOMTagName.DEAT);
                                    }
                                    if (lastTagType == FXTag.DeathDate)
                                    {
                                        SetEventDate(deathEvent, nodeValue);
                                    }
                                    else
                                    {
                                        deathEvent.Place.StringValue = nodeValue;
                                    }
                                    break;

                                case FXTag.Note:
                                    AddNote(lastIndividual, nodeValue);
                                    break;

                                case FXTag.Relationship:
                                    if (nodeValue == "Spouse")
                                    {
                                        relationshipType = RelationshipType.Spouse;
                                    }
                                    else if (nodeValue == "Child")
                                    {
                                        relationshipType = RelationshipType.Child;
                                    }
                                    break;

                                case FXTag.SpouseLink:
                                    ProcessSpouse(families, lastIndividual, nodeValue);
                                    break;

                                case FXTag.ChildLink:
                                    ProcessChild(children, lastIndividual, nodeValue);
                                    break;
                                }
                                lastTagType = FXTag.Unknown;
                            }
                        }

                        if (progressHandler != null)
                        {
                            int newProgress = (int)Math.Min(100, (fileStream.Position * 100.0f) / fileSize);
                            if (progress != newProgress)
                            {
                                progress = newProgress;
                                progressHandler(fTree, progress);
                            }
                        }
                    }
                }

                foreach (var fam in families)
                {
                    GDMIndividualRecord husbRec;
                    indiIdents.TryGetValue(fam.HusbandId, out husbRec);

                    GDMIndividualRecord wifeRec;
                    indiIdents.TryGetValue(fam.WifeId, out wifeRec);

                    GDMFamilyRecord famRec = fTree.CreateFamily();
                    famRec.AddSpouse(husbRec);
                    famRec.AddSpouse(wifeRec);
                }

                foreach (var child in children)
                {
                    GDMIndividualRecord fathRec;
                    indiIdents.TryGetValue(child.FatherId, out fathRec);

                    GDMIndividualRecord mothRec;
                    indiIdents.TryGetValue(child.MotherId, out mothRec);

                    GDMIndividualRecord childRec;
                    indiIdents.TryGetValue(child.ChildId, out childRec);

                    GDMFamilyRecord famRec = GetParentsFamily(fathRec, mothRec);
                    famRec.AddChild(childRec);
                }
            } finally {
                fTree.State = GDMTreeState.osReady;
            }
        }
Esempio n. 8
0
        public static void FillContext(IBaseContext context)
        {
            // a null result if the record is not defined
            GDMCustomEvent evt = context.CreateEventEx(null, GEDCOMTagName.BIRT, "xxxxx", "xxxxx");

            Assert.IsNull(evt);

            // first individual (I1)
            GDMIndividualRecord iRec = context.CreatePersonEx("Ivan", "Ivanovich", "Ivanov", GDMSex.svMale, true);

            Assert.IsNotNull(iRec);

            evt = iRec.FindEvent(GEDCOMTagType.BIRT);
            Assert.IsNotNull(evt);
            evt.Date.ParseString("28 DEC 1990");
            evt.Place.StringValue = "Ivanovo";

            GDMCustomEvent evtd = context.CreateEventEx(iRec, GEDCOMTagName.DEAT, "28 DEC 2010", "Ivanovo");

            Assert.IsNotNull(evtd);

            // second individual, wife (I2)
            GDMIndividualRecord iRec2 = context.CreatePersonEx("Maria", "Petrovna", "Ivanova", GDMSex.svFemale, true);

            evt = iRec2.FindEvent(GEDCOMTagType.BIRT);
            Assert.IsNotNull(evt);
            evt.Date.ParseString("17 MAR 1991");
            evt.Place.StringValue = "Ivanovo";

            iRec.AddAssociation("spouse", iRec2);

            // third individual, child (I3)
            GDMIndividualRecord iRec3 = context.CreatePersonEx("Anna", "Ivanovna", "Ivanova", GDMSex.svFemale, true);

            evt = iRec3.FindEvent(GEDCOMTagType.BIRT);
            Assert.IsNotNull(evt);
            evt.Date.ParseString("11 FEB 2010");
            evt.Place.StringValue = "Ivanovo";

            // their family
            GDMFamilyRecord famRec = context.Tree.CreateFamily();

            Assert.IsNotNull(famRec);
            famRec.AddSpouse(iRec);
            famRec.AddSpouse(iRec2);
            famRec.AddChild(iRec3);

            context.CreateEventEx(famRec, GEDCOMTagName.MARR, "01 JAN 2000", "unknown");

            // individual outside the family (I4)
            GDMIndividualRecord iRec4 = context.CreatePersonEx("Alex", "", "Petrov", GDMSex.svMale, true);

            evt = iRec4.FindEvent(GEDCOMTagType.BIRT);
            Assert.IsNotNull(evt);
            evt.Date.ParseString("15 JUN 1989");
            evt.Place.StringValue = "Far Forest";

            evt = context.CreateEventEx(iRec4, GEDCOMTagName.RESI, "12 FEB", "Far Forest");
            Assert.IsNotNull(evt);

            // fifth (I5)
            GDMIndividualRecord iRec5 = context.CreatePersonEx("Anna", "", "Jones", GDMSex.svFemale, false);

            Assert.IsNotNull(iRec5);

            // sixth (I6)
            GDMIndividualRecord iRec6 = context.CreatePersonEx("Mary", "", "Jones", GDMSex.svFemale, false);

            Assert.IsNotNull(iRec6);
            evt = context.CreateEventEx(iRec6, GEDCOMTagName.BIRT, "12 FEB 1650", "Far Forest");

            GDMFamilyRecord famRec2 = context.Tree.CreateFamily();

            Assert.IsNotNull(famRec2);
            famRec2.AddSpouse(iRec3);
            //famRec2.AddSpouse(iRec4);
            famRec2.AddChild(iRec5);
            famRec2.AddChild(iRec6);

            // group for tests
            GDMGroupRecord groupRec = context.Tree.CreateGroup();

            groupRec.GroupName = "GroupTest";
            Assert.IsNotNull(groupRec, "group1 != null");
            groupRec.AddMember(iRec);

            // location for tests
            GDMLocationRecord locRec = context.Tree.CreateLocation();

            locRec.LocationName = "Test Location";
            locRec.Map.Lati     = 5.11111;
            locRec.Map.Long     = 7.99999;
            Assert.IsNotNull(locRec, "locRec != null");

            // repository for tests
            GDMRepositoryRecord repoRec = context.Tree.CreateRepository();

            repoRec.RepositoryName = "Test repository";
            Assert.IsNotNull(repoRec, "repoRec != null");

            // research for tests
            GDMResearchRecord resRec = context.Tree.CreateResearch();

            resRec.ResearchName = "Test research";
            Assert.IsNotNull(resRec, "resRec != null");

            // source for tests
            GDMSourceRecord srcRec = context.Tree.CreateSource();

            srcRec.ShortTitle = "Test source";
            Assert.IsNotNull(srcRec, "srcRec != null");
            iRec.AddSource(srcRec, "p1", 0);

            // note for tests
            GDMNoteRecord noteRec = context.Tree.CreateNote();

            noteRec.SetNoteText("Test note");
            Assert.IsNotNull(noteRec, "noteRec != null");
            iRec.AddNote(noteRec);

            // task for tests
            GDMTaskRecord tskRec = context.Tree.CreateTask();

            tskRec.Goal = "Test task";
            Assert.IsNotNull(tskRec, "tskRec != null");

            // media for tests
            GDMMultimediaRecord mediaRec = context.Tree.CreateMultimedia();

            mediaRec.FileReferences.Add(new GDMFileReferenceWithTitle());
            GDMFileReferenceWithTitle fileRef = mediaRec.FileReferences[0];

            fileRef.Title = "Test multimedia";
            fileRef.LinkFile("sample.png");
            Assert.IsNotNull(mediaRec, "mediaRec != null");
            iRec.AddMultimedia(mediaRec);

            // communication for tests
            GDMCommunicationRecord commRec = context.Tree.CreateCommunication();

            commRec.CommName = "Test communication";
            Assert.IsNotNull(commRec, "commRec != null");
        }