예제 #1
0
        void AddParentAndChildrenFacts(Individual child, Individual parent, ParentalRelationship.ParentalRelationshipType prType)
        {
            if (parent != null)
            {
                string parentComment;
                string childrenComment;
                if (prType == ParentalRelationship.ParentalRelationshipType.UNKNOWN)
                {
                    parentComment   = $"Child of {parent.IndividualID}: {parent.Name}";
                    childrenComment = $"Parent of {child.IndividualID}: {child.Name}";
                }
                else
                {
                    string titlecase = EnhancedTextInfo.ToTitleCase(prType.ToString().ToLower());
                    parentComment   = $"{titlecase}  child of {parent.IndividualID}: {parent.Name}";
                    childrenComment = $"{titlecase} parent of {child.IndividualID}: {child.Name}";
                }

                Fact parentFact = new Fact(parent.IndividualID, Fact.PARENT, child.BirthDate, child.BirthLocation, parentComment, true, true);
                child.AddFact(parentFact);

                Fact childrenFact = new Fact(child.IndividualID, Fact.CHILDREN, child.BirthDate, child.BirthLocation, childrenComment, true, true);
                parent.AddFact(childrenFact);
            }
        }
예제 #2
0
        public static void StoreLostCousinsFact(CensusIndividual ind, IProgress <string> outputText)
        {
            try
            {
                if (InstanceConnection.State != ConnectionState.Open)
                {
                    InstanceConnection.Open();
                }
                SqliteParameter param;

                using (SqliteCommand cmd = new SqliteCommand("insert into LostCousins (CensusYear, CensusCountry, CensusRef, IndID, FullName) values(?,?,?,?,?)", InstanceConnection))
                {
                    param        = cmd.CreateParameter();
                    param.DbType = DbType.Int32;
                    cmd.Parameters.Add(param);
                    param        = cmd.CreateParameter();
                    param.DbType = DbType.String;
                    cmd.Parameters.Add(param);
                    param        = cmd.CreateParameter();
                    param.DbType = DbType.String;
                    cmd.Parameters.Add(param);
                    param        = cmd.CreateParameter();
                    param.DbType = DbType.String;
                    cmd.Parameters.Add(param);
                    param        = cmd.CreateParameter();
                    param.DbType = DbType.String;
                    cmd.Parameters.Add(param);
                    cmd.Prepare();

                    if (ind.CensusReference != null)
                    {
                        cmd.Parameters[0].Value = ind.CensusDate.BestYear;
                        cmd.Parameters[1].Value = ind.CensusCountry;
                        cmd.Parameters[2].Value = ind.CensusReference;
                        cmd.Parameters[3].Value = ind.IndividualID;
                        cmd.Parameters[4].Value = ind.Name;

                        int rowsaffected = cmd.ExecuteNonQuery();
                        if (rowsaffected != 1)
                        {
                            outputText.Report($"\nProblem updating record in database update affected {rowsaffected} records.");
                        }
                        else
                        {
                            FactLocation location = FactLocation.GetLocation(ind.CensusCountry);
                            Fact         f        = new Fact(ind.CensusRef, Fact.LC_FTA, ind.CensusDate, location, string.Empty, true, true);
                            Individual   person   = FamilyTree.Instance.GetIndividual(ind.IndividualID); // get the individual not the census indvidual
                            person?.AddFact(f);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                outputText.Report($"\nFailed to save Lost Cousins record in database error was: {e.Message}");
            }
        }
        static void AddLostCousinsFact(CensusIndividual ind)
        {
            FactLocation location = FactLocation.GetLocation(ind.CensusCountry);
            Fact         f        = new Fact(ind.CensusRef, Fact.LC_FTA, ind.CensusDate, location, string.Empty, true, true);
            Individual   person   = FamilyTree.Instance.GetIndividual(ind.IndividualID); // get the individual not the census indvidual

            if (person != null && !person.HasLostCousinsFactAtDate(ind.CensusDate))
            {
                person.AddFact(f);
            }
        }
예제 #4
0
        public static int AddLostCousinsFacts()
        {
            int count = 0;

            if (InstanceConnection.State != ConnectionState.Open)
            {
                InstanceConnection.Open();
            }
            using (SqliteCommand cmd = new SqliteCommand("select CensusYear, CensusCountry, CensusRef, IndID, FullName from LostCousins", InstanceConnection))
            {
                using (SqliteDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        string     indID    = reader["IndID"].ToString();
                        string     fullName = reader["FullName"].ToString();
                        Individual ind      = FamilyTree.Instance.GetIndividual(indID);
                        if (ind?.Name == fullName) // only load if individual exists in this tree.
                        {
                            string CensusYear    = reader["CensusYear"].ToString();
                            string CensusCountry = reader["CensusCountry"].ToString();
                            string CensusRef     = reader["CensusRef"].ToString();
                            if (!ind.IsLostCousinsEntered(CensusDate.GetLostCousinsCensusYear(new FactDate(CensusYear), true)))
                            {
                                FactLocation location = FactLocation.GetLocation(CensusCountry);
                                Fact         f        = new Fact(CensusRef, Fact.LOSTCOUSINS, new FactDate(CensusYear), location, string.Empty, true, true);
                                ind?.AddFact(f);
                            }
                            count++;
                        }
                        else
                        {
                            Console.Write("name wrong");
                            // UpdateFullName(reader, ind.Name); needed during testing
                        }
                    }
                }
            }
            return(count);
        }