public void AddFamily(Family family) { Requires.NotNull("family", family); family.Id = _document.Records.GetNextId(GEDCOMTag.FAM).ToString(); var record = new GEDCOMFamilyRecord(family.Id); if (!string.IsNullOrEmpty(family.HusbandId)) { //Add HUSB record.AddHusband(GEDCOMUtil.CreateId("I", family.HusbandId)); } if (!string.IsNullOrEmpty(family.WifeId)) { //Add WIFE record.AddWife(GEDCOMUtil.CreateId("I", family.WifeId)); } foreach (Individual child in family.Children) { //Add CHIL record.AddChild(GEDCOMUtil.CreateId("I", child.Id)); } _document.AddRecord(record); }
public void gt_bind_family_child(object familyPtr, object childPtr) { GEDCOMFamilyRecord fRec = familyPtr as GEDCOMFamilyRecord; if (fRec == null) { return; } GEDCOMIndividualRecord chRec = childPtr as GEDCOMIndividualRecord; fRec.AddChild(chRec); }
private void ParentAdd(GEDCOMSex needSex) { TreeChartPerson p = fView.TreeBox.Selected; if (p == null || p.Rec == null) { return; } bool needParent = false; bool familyExist = p.Rec.GetParentsFamily() != null; if (familyExist) { GEDCOMIndividualRecord mother, father; GEDCOMFamilyRecord fam = p.Rec.GetParentsFamily(); if (fam == null) { father = null; mother = null; } else { father = fam.GetHusband(); mother = fam.GetWife(); } needParent = (father == null && needSex == GEDCOMSex.svMale) || (mother == null && needSex == GEDCOMSex.svFemale); } if (!familyExist || needParent) { GEDCOMIndividualRecord child = p.Rec; GEDCOMFamilyRecord fam = (familyExist) ? p.Rec.GetParentsFamily() : fBase.Context.Tree.CreateFamily(); GEDCOMIndividualRecord parent = fBase.Context.SelectPerson(null, TargetMode.tmParent, needSex); if (parent != null) { fam.AddSpouse(parent); if (!familyExist) { fam.AddChild(child); } UpdateChart(); } } }
private void AddChild(GEDCOMIndividualRecord parent, int marrNum, GEDCOMIndividualRecord child) { if (marrNum <= 0) { marrNum = 1; } GEDCOMFamilyRecord family = GetFamilyByNum(parent, marrNum); if (family != null) { family.AddChild(child); } else { // ??? } }
private bool ProcessIndividualParents(bool redo) { GEDCOMIndividualRecord iRec = fObj as GEDCOMIndividualRecord; GEDCOMFamilyRecord familyRec = fNewVal as GEDCOMFamilyRecord; if (iRec == null || familyRec == null) { return(false); } if (fType == OperationType.otIndividualParentsDetach) { redo = !redo; } if (redo) { familyRec.AddChild(iRec); } else { familyRec.RemoveChild(iRec); } return(true); }
public static void FillContext(IBaseContext context) { // a null result if the record is not defined GEDCOMCustomEvent evt = context.CreateEventEx(null, "BIRT", "xxxxx", "xxxxx"); Assert.IsNull(evt); // first individual GEDCOMIndividualRecord iRec = context.CreatePersonEx("Ivan", "Ivanovich", "Ivanov", GEDCOMSex.svMale, true); Assert.IsNotNull(iRec); evt = iRec.FindEvent("BIRT"); Assert.IsNotNull(evt); evt.Date.ParseString("28 DEC 1990"); evt.Place.StringValue = "Ivanovo"; GEDCOMCustomEvent evtd = context.CreateEventEx(iRec, "DEAT", "28 DEC 2010", "Ivanovo"); Assert.IsNotNull(evtd); // second individual, wife GEDCOMIndividualRecord iRec2 = context.CreatePersonEx("Maria", "Petrovna", "Ivanova", GEDCOMSex.svFemale, true); evt = iRec2.FindEvent("BIRT"); Assert.IsNotNull(evt); evt.Date.ParseString("17 MAR 1990"); evt.Place.StringValue = "Ivanovo"; iRec.AddAssociation("spouse", iRec2); // third individual, child GEDCOMIndividualRecord iRec3 = context.CreatePersonEx("Anna", "Ivanovna", "Ivanova", GEDCOMSex.svFemale, true); evt = iRec3.FindEvent("BIRT"); Assert.IsNotNull(evt); evt.Date.ParseString("11 FEB 2010"); evt.Place.StringValue = "Ivanovo"; // their family GEDCOMFamilyRecord famRec = context.Tree.CreateFamily(); Assert.IsNotNull(famRec); famRec.AddSpouse(iRec); famRec.AddSpouse(iRec2); famRec.AddChild(iRec3); context.CreateEventEx(famRec, "MARR", "01 JAN 2000", "unknown"); // individual outside the family GEDCOMIndividualRecord iRec4 = context.CreatePersonEx("Alex", "", "Petrov", GEDCOMSex.svMale, true); evt = iRec4.FindEvent("BIRT"); Assert.IsNotNull(evt); evt.Date.ParseString("15 JUN 1989"); evt.Place.StringValue = "Far Forest"; evt = context.CreateEventEx(iRec4, "RESI", "12 FEB", "Far Forest"); Assert.IsNotNull(evt); // fifth GEDCOMIndividualRecord iRec5 = context.CreatePersonEx("Anna", "", "Jones", GEDCOMSex.svFemale, false); Assert.IsNotNull(iRec5); // group for tests GEDCOMGroupRecord groupRec = context.Tree.CreateGroup(); groupRec.GroupName = "GroupTest"; Assert.IsNotNull(groupRec, "group1 != null"); groupRec.AddMember(iRec); // location for tests GEDCOMLocationRecord 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 GEDCOMRepositoryRecord repoRec = context.Tree.CreateRepository(); repoRec.RepositoryName = "Test repository"; Assert.IsNotNull(repoRec, "repoRec != null"); // research for tests GEDCOMResearchRecord resRec = context.Tree.CreateResearch(); resRec.ResearchName = "Test research"; Assert.IsNotNull(resRec, "resRec != null"); // source for tests GEDCOMSourceRecord srcRec = context.Tree.CreateSource(); srcRec.FiledByEntry = "Test source"; Assert.IsNotNull(srcRec, "srcRec != null"); iRec.AddSource(srcRec, "p1", 0); // note for tests GEDCOMNoteRecord noteRec = context.Tree.CreateNote(); noteRec.SetNoteText("Test note"); Assert.IsNotNull(noteRec, "noteRec != null"); iRec.AddNote(noteRec); // task for tests GEDCOMTaskRecord tskRec = context.Tree.CreateTask(); tskRec.Goal = "Test task"; Assert.IsNotNull(tskRec, "tskRec != null"); // media for tests GEDCOMMultimediaRecord mediaRec = context.Tree.CreateMultimedia(); mediaRec.AddTag("FILE", "", null); GEDCOMFileReferenceWithTitle fileRef = mediaRec.FileReferences[0]; fileRef.Title = "Test multimedia"; fileRef.LinkFile("sample.png"); Assert.IsNotNull(mediaRec, "mediaRec != null"); iRec.AddMultimedia(mediaRec); // communication for tests GEDCOMCommunicationRecord commRec = context.Tree.CreateCommunication(); commRec.CommName = "Test communication"; Assert.IsNotNull(commRec, "commRec != null"); }
// 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; GEDCOMSourceRecord srcRec = null; if (!string.IsNullOrEmpty(srcName)) { srcRec = fBase.Context.FindSource(srcName); if (srcRec == null) { srcRec = fBase.Context.Tree.CreateSource(); srcRec.FiledByEntry = srcName; } } GEDCOMIndividualRecord iMain = null; int num = dataGridView1.Rows.Count; for (int r = 0; r < num; r++) { DataGridViewRow row = dataGridView1.Rows[r]; string lnk = (string)row.Cells[0].Value; string nm = (string)row.Cells[1].Value; string pt = (string)row.Cells[2].Value; string fm = (string)row.Cells[3].Value; string age = (string)row.Cells[4].Value; string comment = (string)row.Cells[5].Value; if (!string.IsNullOrEmpty(lnk)) { PersonLink link = GetLinkByName(lnk); GEDCOMSex sx = fBase.Context.DefineSex(nm, pt); GEDCOMIndividualRecord iRec = fBase.Context.CreatePersonEx(nm, pt, fm, sx, false); if (!string.IsNullOrEmpty(age) && SysUtils.IsDigits(age)) { int birthYear = srcYear - int.Parse(age); fBase.Context.CreateEventEx(iRec, "BIRT", "ABT " + birthYear.ToString(), ""); } if (!string.IsNullOrEmpty(place)) { GEDCOMCustomEvent evt = fBase.Context.CreateEventEx(iRec, "RESI", "", ""); evt.Place.StringValue = place; } if (!string.IsNullOrEmpty(comment)) { GEDCOMNoteRecord noteRec = fBase.Context.Tree.CreateNote(); noteRec.SetNoteText(comment); iRec.AddNote(noteRec); } if (srcRec != null) { iRec.AddSource(srcRec, srcPage, 0); } fBase.NotifyRecord(iRec, RecordAction.raAdd); GEDCOMFamilyRecord family = null; if (link == PersonLink.plPerson) { iMain = iRec; string evName = ""; if (rbSK_Met.Checked) { switch (cbEventType.SelectedIndex) { case 0: evName = "BIRT"; break; case 1: evName = "DEAT"; break; case 2: evName = "MARR"; break; } } if (evName == "BIRT" || evName == "DEAT") { GEDCOMCustomEvent evt = fBase.Context.CreateEventEx(iRec, evName, GEDCOMDate.CreateByFormattedStr(edEventDate.Text, false), ""); evt.Place.StringValue = place; } else if (evName == "MARR") { family = iRec.GetMarriageFamily(true); GEDCOMCustomEvent evt = fBase.Context.CreateEventEx(family, evName, GEDCOMDate.CreateByFormattedStr(edEventDate.Text, false), ""); evt.Place.StringValue = place; } } else if (link > PersonLink.plPerson) { 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(); }