Ejemplo n.º 1
0
        public void LoadXML(XmlDocument xmlDocument)
        {
            maxfamilyid = 0;
            maxindividualid = 0;

            XmlNodeList individualnodes = xmlDocument.SelectNodes("//quatre/individuals/individual");
            foreach (XmlNode node in individualnodes)
            {
                Individual individual = new Individual();
                individual.ID = Convert.ToInt16(node.Attributes["id"].Value);
                if (individual.ID > maxindividualid) maxindividualid = individual.ID;

                if(node.Attributes["fromfamilyid"]!=null){
                    individual.FromFamily = getFamily(Convert.ToInt16(node.Attributes["fromfamilyid"].Value));
                }
                individual.Name = node.SelectSingleNode("name").InnerText;
                individual.Givenname = node.SelectSingleNode("givenname").InnerText;
                individual.Surname = node.SelectSingleNode("surname").InnerText;
                individual.DOB = node.SelectSingleNode("dob").InnerText;
                individual.PlaceOfBirth = node.SelectSingleNode("placeofbirth").InnerText;
                individual.DOD = node.SelectSingleNode("dod").InnerText;
                individual.Profession = node.SelectSingleNode("profession").InnerText;
                individual.Notes = node.SelectSingleNode("notes").InnerText;
                string sex = node.SelectSingleNode("sex").InnerText;
                if (sex.Equals("M")) individual.Sex = enums.Sex.Male;
                if (sex.Equals("F")) individual.Sex = enums.Sex.Female;
                XmlNodeList subfamilynodes = node.SelectNodes("families/family");
                foreach (XmlNode subfamilynode in subfamilynodes)
                {
                    Family subfamily = getFamily(Convert.ToInt16(subfamilynode.Attributes["id"].Value));
                    individual.AddFamily(subfamily.ID, subfamily);
                }
                individuals.Add(individual.ID, individual);
            }

            XmlNodeList familynodes = xmlDocument.SelectNodes("//quatre/families/family");
            foreach (XmlNode node in familynodes)
            {
                int famid = Convert.ToInt16(node.Attributes["id"].Value);
                Family family = getFamily(famid);
                if (famid > maxfamilyid) maxfamilyid = famid;

                if (node.Attributes["husbandid"] != null)
                {
                    int husbandid = Convert.ToInt16(node.Attributes["husbandid"].Value);
                    family.Husband = (Individual)individuals[husbandid];
                }

                if (node.Attributes["wifeid"] != null)
                {
                    int wifeid = Convert.ToInt16(node.Attributes["wifeid"].Value);
                    family.Wife = (Individual)individuals[wifeid];
                }

                family.DateMarried = node.SelectSingleNode("datemarried").InnerText;
                family.PlaceMarried = node.SelectSingleNode("placemarried").InnerText;
                family.DateDivorsed = node.SelectSingleNode("datedivorsed").InnerText;
                family.Notes = node.SelectSingleNode("notes").InnerText;

                XmlNodeList childrennodes = node.SelectNodes("children/child");
                foreach (XmlNode childnode in childrennodes)
                {
                    int childid = Convert.ToInt16(childnode.Attributes["id"].Value);
                    Individual child = (Individual)individuals[childid];
                    family.addChild(child);
                }
            }
        }
Ejemplo n.º 2
0
        public GEDReader(String filePath)
        {
            StreamReader file = new StreamReader(filePath);
            Boolean donereading = false;

            int linecount = 0;

            String line = file.ReadLine();
            linecount++;

            while(!donereading){

                if (line != null)
                {
                    if (line.EndsWith("INDI"))
                    {
                        Individual indi = new Individual();
                        indi.ID = Convert.ToInt16(line.Substring(2, line.Length - 7).Replace("@", "").Replace("I", ""));
                        if (indi.ID > maxindividualid) maxindividualid = indi.ID;
                        String indiline = "";
                        while (!indiline.Trim().Equals("1 CHAN"))
                        {
                            indiline = file.ReadLine();
                            linecount++;

                            if (indiline.StartsWith("1 NAME")) indi.Name = indiline.Substring(7);
                            if (indiline.StartsWith("2 SURN")) indi.Surname = indiline.Substring(7);
                            if (indiline.StartsWith("2 GIVN")) indi.Givenname = indiline.Substring(7);
                            if (indiline.StartsWith("1 SEX")){
                                if(indiline.Substring(6).Trim().Equals("F")) indi.Sex = enums.Sex.Female;
                                if(indiline.Substring(6).Trim().Equals("M")) indi.Sex = enums.Sex.Male;
                            }
                            if (indiline.StartsWith("2 DATE")) indi.DOB = indiline.Substring(7);
                            if (indiline.StartsWith("1 FAMS"))
                            {
                                Family fam = getFamily(ConvertToID(indiline.Substring(7)));
                                indi.AddFamily(fam.ID, fam);
                            }
                            if (indiline.StartsWith("1 FAMC"))
                            {
                                Family fromfam = getFamily(ConvertToID(indiline.Substring(7)));
                                indi.FromFamily = fromfam;
                            }
                        }

                        individuals.Add(indi.ID, indi);

                        file.ReadLine(); //read date
                        linecount++;
                        file.ReadLine(); //read time
                        linecount++;

                        line = file.ReadLine();
                        linecount++;

                    }
                    else if (line.Trim().EndsWith("FAM"))
                    {
                        int famid = ConvertToID(line.Substring(2, line.Length - 5));
                        if (famid > maxfamilyid) maxfamilyid = famid;

                        Family fam = getFamily(famid);
                        String famline = "";

                        while (famline!=null && !famline.Trim().EndsWith("FAM"))
                        {
                        //1 DIV
                            if (famline.StartsWith("1 HUSB")) fam.Husband = (Individual)individuals[ConvertToID(famline.Substring(7))];
                            if (famline.StartsWith("1 WIFE")) fam.Wife = (Individual)individuals[ConvertToID(famline.Substring(7))];
                            if (famline.StartsWith("1 CHIL")) fam.addChild((Individual)individuals[ConvertToID(famline.Substring(7))]);

                            if (famline.EndsWith("1 DIV"))
                            {
                                famline = file.ReadLine();
                                linecount++;
                                if (famline.StartsWith("2 DATE")) fam.DateDivorsed = famline.Substring(7);
                            }

                            if (famline.StartsWith("1 MARR"))
                            {
                                famline = file.ReadLine();
                                linecount++;
                                if (famline.StartsWith("2 DATE")) fam.DateMarried = famline.Substring(7);
                                if (famline.StartsWith("2 PLAC")) fam.PlaceMarried = famline.Substring(7);
                            }

                            famline = file.ReadLine();
                            linecount++;
                        }

                        line = famline;

                    }
                    else if (line.EndsWith("0 TRLR"))
                    {
                        donereading = true;
                    }
                    else
                    {
                        line = file.ReadLine();
                        linecount++;
                    }
                }
                else
                {
                    donereading = true;
                }

            }

            file.Close();
        }