Beispiel #1
0
        /// <summary>
        /// Gets the type of the linkage.
        /// </summary>
        /// <param name="childXrefID">The child xref identifier.</param>
        /// <returns>
        /// Pedigree linkage type.
        /// </returns>
        public PedigreeLinkageType GetLinkageType(string childXrefID)
        {
            PedigreeLinkageType ret = PedigreeLinkageType.Unknown;

            if (linkageTypes != null && linkageTypes.ContainsKey(childXrefID))
            {
                ret = linkageTypes[childXrefID];
            }
            else
            {
                GedcomIndividualRecord child = (GedcomIndividualRecord)Database[childXrefID];
                if (child != null)
                {
                    GedcomFamilyLink link = null;
                    if (child.ChildInFamily(XrefId, out link))
                    {
                        ret = link.Pedigree;
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Child " + childXrefID + " is not in family " +
                                                           XrefId + " in GetLinkageType");
                    }
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Attempt to GetLinkageType of unknown child " +
                                                       childXrefID + " in " + XrefId);
                }
            }

            return(ret);
        }
Beispiel #2
0
        /// <summary>
        /// Add a child.
        /// </summary>
        /// <param name="indi">The child.</param>
        /// <returns>
        /// Returns True if a new child record is added; otherwise False.
        /// </returns>
        public bool AddChild(GedcomIndividualRecord indi)
        {
            bool added = false;

            if (indi != null && !Children.Contains(indi.XRefID))
            {
                if (string.IsNullOrEmpty(XRefID))
                {
                    XRefID = Database.GenerateXref("FAM");
                    Database.Add(XRefID, this);
                }

                if (!indi.ChildInFamily(XRefID))
                {
                    GedcomFamilyLink link = new GedcomFamilyLink();
                    link.Database   = Database;
                    link.Family     = XRefID;
                    link.Individual = indi.XRefID;
                    link.Level      = 1;
                    indi.ChildIn.Add(link);
                }

                Children.Add(indi.XRefID);

                added = true;
            }

            return(added);
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GedcomFamilyRecord" /> class.
        /// </summary>
        /// <param name="database">The database to associate with this record.</param>
        /// <param name="indi1">The first individual.</param>
        /// <param name="indi2">The second individual.</param>
        public GedcomFamilyRecord(GedcomDatabase database, GedcomIndividualRecord indi1, GedcomIndividualRecord indi2)
            : this()
        {
            Level    = 0;
            Database = database;
            XRefID   = database.GenerateXref("FAM");

            if (indi1 != null)
            {
                GedcomFamilyLink link = new GedcomFamilyLink();
                link.Database   = database;
                link.Family     = XRefID;
                link.Individual = indi1.XRefID;
                indi1.SpouseIn.Add(link);

                if (indi2 != null)
                {
                    link            = new GedcomFamilyLink();
                    link.Database   = database;
                    link.Family     = XRefID;
                    link.Individual = indi2.XRefID;
                    indi2.SpouseIn.Add(link);
                }

                switch (indi1.Sex)
                {
                case GedcomSex.Female:
                    Wife = indi1.XRefID;
                    if (indi2 != null)
                    {
                        Husband = indi2.XRefID;
                    }

                    break;

                default:
                    // got to put some where if not male or female,
                    // go with same as male
                    Husband = indi1.XRefID;
                    if (indi2 != null)
                    {
                        Wife = indi2.XRefID;
                    }

                    break;
                }
            }

            database.Add(XRefID, this);
        }
Beispiel #4
0
        /// <summary>
        /// Generates the XML.
        /// </summary>
        /// <param name="root">The root node.</param>
        public override void GenerateXML(XmlNode root)
        {
            XmlDocument doc = root.OwnerDocument;

            XmlNode      node;
            XmlAttribute attr;

            XmlNode famNode = doc.CreateElement("FamilyRec");

            attr       = doc.CreateAttribute("Id");
            attr.Value = XRefID;
            famNode.Attributes.Append(attr);

            if (!string.IsNullOrEmpty(Husband))
            {
                GedcomIndividualRecord husb = Database[Husband] as GedcomIndividualRecord;
                if (husb != null)
                {
                    node = doc.CreateElement("HusbFath");

                    XmlNode linkNode = doc.CreateElement("Link");

                    attr       = doc.CreateAttribute("Target");
                    attr.Value = "IndividualRec";
                    linkNode.Attributes.Append(attr);

                    attr       = doc.CreateAttribute("Ref");
                    attr.Value = Husband;
                    linkNode.Attributes.Append(attr);

                    node.AppendChild(linkNode);

                    famNode.AppendChild(node);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Pointer to non existant husband");
                }
            }

            if (!string.IsNullOrEmpty(Wife))
            {
                GedcomIndividualRecord wife = Database[Wife] as GedcomIndividualRecord;
                if (wife != null)
                {
                    node = doc.CreateElement("WifeMoth");

                    XmlNode linkNode = doc.CreateElement("Link");

                    attr       = doc.CreateAttribute("Target");
                    attr.Value = "IndividualRec";
                    linkNode.Attributes.Append(attr);

                    attr       = doc.CreateAttribute("Ref");
                    attr.Value = Wife;
                    linkNode.Attributes.Append(attr);

                    node.AppendChild(linkNode);

                    famNode.AppendChild(node);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Pointer to non existant wife");
                }
            }

            foreach (string child in Children)
            {
                GedcomIndividualRecord indi = Database[child] as GedcomIndividualRecord;
                if (indi != null)
                {
                    node = doc.CreateElement("Child");

                    XmlNode linkNode = doc.CreateElement("Link");

                    attr       = doc.CreateAttribute("Target");
                    attr.Value = "IndividualRec";
                    linkNode.Attributes.Append(attr);

                    attr       = doc.CreateAttribute("Ref");
                    attr.Value = child;
                    linkNode.Attributes.Append(attr);

                    node.AppendChild(linkNode);

                    // TODO: add in <ChildNbr>
                    GedcomFamilyLink link = null;

                    if (indi.ChildInFamily(XRefID, out link))
                    {
                        XmlNode relNode = doc.CreateElement("RelToFath");
                        string  relType = string.Empty;
                        switch (link.FatherPedigree)
                        {
                        case PedigreeLinkageType.Adopted:
                            relType = "adopted";
                            break;

                        case PedigreeLinkageType.Birth:
                            relType = "birth";
                            break;

                        case PedigreeLinkageType.Foster:
                            relType = "foster";
                            break;

                        case PedigreeLinkageType.Sealing:
                            relType = "sealing";
                            break;

                        default:
                            relType = "unknown";
                            break;
                        }

                        relNode.AppendChild(doc.CreateTextNode(relType));

                        relNode = doc.CreateElement("RelToMoth");
                        relType = string.Empty;
                        switch (link.MotherPedigree)
                        {
                        case PedigreeLinkageType.Adopted:
                            relType = "adopted";
                            break;

                        case PedigreeLinkageType.Birth:
                            relType = "birth";
                            break;

                        case PedigreeLinkageType.Foster:
                            relType = "foster";
                            break;

                        case PedigreeLinkageType.Sealing:
                            relType = "sealing";
                            break;

                        default:
                            relType = "unknown";
                            break;
                        }

                        relNode.AppendChild(doc.CreateTextNode(relType));
                    }

                    famNode.AppendChild(node);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Pointer to non existant child");
                }
            }

            XmlNode basedOnNode = doc.CreateElement("BasedOn");

            foreach (GedcomFamilyEvent famEvent in Events)
            {
                node = doc.CreateElement("Event");

                XmlNode linkNode = doc.CreateElement("Link");

                attr       = doc.CreateAttribute("Target");
                attr.Value = "EventRec";
                linkNode.Attributes.Append(attr);

                attr       = doc.CreateAttribute("Ref");
                attr.Value = famEvent.EventXRefID;
                linkNode.Attributes.Append(attr);

                node.AppendChild(linkNode);

                basedOnNode.AppendChild(node);
            }

            famNode.AppendChild(basedOnNode);

            GenerateNoteXML(famNode);
            GenerateCitationsXML(famNode);
            GenerateMultimediaXML(famNode);

            GenerateChangeDateXML(famNode);

            root.AppendChild(famNode);
        }
Beispiel #5
0
        /// <summary>
        /// Changes the wife.
        /// </summary>
        /// <param name="indi">The wife.</param>
        public void ChangeWife(GedcomIndividualRecord indi)
        {
            GedcomIndividualRecord husband = null;
            GedcomIndividualRecord wife    = null;

            if (!string.IsNullOrEmpty(this.husband))
            {
                husband = Database[this.husband] as GedcomIndividualRecord;
            }

            if (!string.IsNullOrEmpty(this.wife))
            {
                wife = Database[this.wife] as GedcomIndividualRecord;
            }

            if (string.IsNullOrEmpty(XRefID))
            {
                XRefID = Database.GenerateXref("FAM");
                Database.Add(XRefID, this);
            }

            if (wife != null)
            {
                GedcomFamilyLink link;
                if (wife.SpouseInFamily(XRefID, out link))
                {
                    wife.SpouseIn.Remove(link);
                }
            }

            wife      = indi;
            this.wife = string.Empty;

            if (husband != null)
            {
                this.husband = husband.XRefID;

                if (!husband.SpouseInFamily(XRefID))
                {
                    GedcomFamilyLink link = new GedcomFamilyLink();
                    link.Database   = Database;
                    link.Family     = XRefID;
                    link.Individual = this.husband;
                    husband.SpouseIn.Add(link);
                }
            }

            if (wife != null)
            {
                this.wife = wife.XRefID;

                if (!wife.SpouseInFamily(XRefID))
                {
                    GedcomFamilyLink link = new GedcomFamilyLink();
                    link.Database   = Database;
                    link.Family     = XRefID;
                    link.Individual = this.wife;
                    wife.SpouseIn.Add(link);
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Output GEDCOM format for this instance.
        /// </summary>
        /// <param name="sw">Where to output the data to.</param>
        public override void Output(TextWriter sw)
        {
            base.Output(sw);

            string levelPlusOne = Util.IntToString(Level + 1);

            if (RestrictionNotice != GedcomRestrictionNotice.None)
            {
                sw.Write(Environment.NewLine);
                sw.Write(levelPlusOne);
                sw.Write(" RESN ");
                sw.Write(RestrictionNotice.ToString().ToLower());
            }

            foreach (GedcomFamilyEvent familyEvent in events)
            {
                familyEvent.Output(sw);
            }

            if (!string.IsNullOrEmpty(husband))
            {
                sw.Write(Environment.NewLine);
                sw.Write(levelPlusOne);
                sw.Write(" HUSB ");
                sw.Write("@");
                sw.Write(husband);
                sw.Write("@");
            }

            if (!string.IsNullOrEmpty(wife))
            {
                sw.Write(Environment.NewLine);
                sw.Write(levelPlusOne);
                sw.Write(" WIFE ");
                sw.Write("@");
                sw.Write(wife);
                sw.Write("@");
            }

            string levelPlusTwo = Util.IntToString(Level + 2);

            foreach (string childID in children)
            {
                sw.Write(Environment.NewLine);
                sw.Write(levelPlusOne);
                sw.Write(" CHIL ");
                sw.Write("@");
                sw.Write(childID);
                sw.Write("@");

                GedcomIndividualRecord child = (GedcomIndividualRecord)Database[childID];
                if (child != null)
                {
                    // only output _FREL / _MREL value here,
                    // real PEDI goes on the FAMC on the INDI tag
                    GedcomFamilyLink link = null;
                    if (child.ChildInFamily(XrefId, out link))
                    {
                        switch (link.Pedigree)
                        {
                        case PedigreeLinkageType.FatherAdopted:
                            sw.Write(Environment.NewLine);
                            sw.Write(levelPlusTwo);
                            sw.Write("_FREL Adopted");
                            break;

                        case PedigreeLinkageType.MotherAdopted:
                            sw.Write(Environment.NewLine);
                            sw.Write(levelPlusTwo);
                            sw.Write("_MREL Adopted");
                            break;
                        }
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Missing child linkage for " + childID + " to family " + XrefId);
                    }
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Missing child " + childID + " when outputting family " + XrefId);
                }
            }

            if (numberOfChildren != 0)
            {
                sw.Write(Environment.NewLine);
                sw.Write(levelPlusOne);
                sw.Write(" NCHI ");
                sw.Write("@");
                sw.Write(Util.IntToString(numberOfChildren));
                sw.Write("@");
            }

            if (submitterRecords != null)
            {
                foreach (string submitter in SubmitterRecords)
                {
                    sw.Write(Environment.NewLine);
                    sw.Write(levelPlusOne);
                    sw.Write(" SUBM ");
                    sw.Write("@");
                    sw.Write(submitter);
                    sw.Write("@");
                }
            }

            if (StartStatus != MarriageStartStatus.Unknown)
            {
                sw.Write(Environment.NewLine);
                sw.Write(levelPlusOne);
                sw.Write(" _MSTAT ");
                sw.Write(StartStatus.ToString());
            }
        }