示例#1
0
        void StyleRows()
        {
            try
            {
                string currentRowText = "";
                bool   highlighted    = true;

                Font boldFont    = new Font(dgCensus.DefaultCellStyle.Font, FontStyle.Bold);
                Font regularFont = new Font(dgCensus.DefaultCellStyle.Font, FontStyle.Regular);
                int  sortColumn  = dgCensus.SortedColumn.Index;
                foreach (DataGridViewRow row in dgCensus.Rows)
                {
                    CensusIndividual cr = (CensusIndividual)row.DataBoundItem;
                    if (row.Cells[sortColumn].Value.ToString() != currentRowText)
                    {
                        currentRowText = row.Cells[sortColumn].Value.ToString();
                        highlighted    = !highlighted;
                    }
                    DataGridViewCellStyle style = new DataGridViewCellStyle(dgCensus.DefaultCellStyle)
                    {
                        BackColor = highlighted ? Color.LightGray : Color.White,
                        ForeColor = (cr.RelationType == Individual.DIRECT || cr.RelationType == Individual.DESCENDANT) ? Color.Red : Color.Black,
                        Font      = (cr.IsCensusDone(CensusDate) || (cr.IsAlive(CensusDate) && !cr.DeathDate.StartsBefore(CensusDate))) ? boldFont : regularFont
                    };
                    cr.CellStyle = style;
                }
            }
            catch (Exception) { }
        }
示例#2
0
 private void DgCensus_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex >= 0 && dgCensus.CurrentRow != null && !CensusDate.VALUATIONROLLS.Contains(CensusDate))
     {
         CensusIndividual ds = (CensusIndividual)dgCensus.CurrentRow.DataBoundItem;
         FamilyTree       ft = FamilyTree.Instance;
         if (Control.ModifierKeys.Equals(Keys.Shift))
         {
             Facts factForm = new Facts(ds);
             MainForm.DisposeDuplicateForms(factForm);
             factForm.Show();
         }
         else
         {
             try
             {
                 ft.SearchCensus(censusCountry, CensusDate.StartDate.Year, ds, cbCensusSearchProvider.SelectedIndex);
             }
             catch (CensusSearchException ex)
             {
                 MessageBox.Show(ex.Message);
             }
         }
     }
 }
        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}");
            }
        }
示例#4
0
 private void mnuViewFacts_Click(object sender, EventArgs e)
 {
     if (dgCensus.CurrentRow != null)
     {
         CensusIndividual ds       = (CensusIndividual)dgCensus.CurrentRow.DataBoundItem;
         Facts            factForm = new Facts(ds);
         MainForm.DisposeDuplicateForms(factForm);
         factForm.Show();
     }
 }
        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);
            }
        }
示例#6
0
 void DgCensus_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
 {
     if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
     {
         DataGridViewCell cell = dgCensus.Rows[e.RowIndex].Cells[e.ColumnIndex];
         CensusIndividual ind  = dgCensus.Rows[e.RowIndex].DataBoundItem as CensusIndividual;
         if (ind.CellStyle != null)
         {
             e.CellStyle      = ind.CellStyle;
             cell.ToolTipText = GetTooltipText(ind.CellStyle);
         }
     }
 }
示例#7
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.");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                outputText.Report($"\nFailed to save Lost Cousins record in database error was: {e.Message}");
            }
        }
        static bool AddIndividualToWebsite(CensusIndividual ind, IProgress <string> outputText)
        {
            if (ind is null)
            {
                return(false);
            }
            HttpWebResponse resp = null;

            try
            {
                string         formParams = BuildParameterString(ind);
                HttpWebRequest req        = WebRequest.Create(new Uri("https://www.lostcousins.com/pages/members/ancestors/add_ancestor.mhtml")) as HttpWebRequest;
                req.Referer         = "https://www.lostcousins.com/pages/members/ancestors/add_ancestor.mhtml";
                req.ContentType     = "application/x-www-form-urlencoded";
                req.Method          = "POST";
                req.Credentials     = Credentials;
                req.CookieContainer = new CookieContainer();
                req.CookieContainer.Add(CookieJar);
                byte[] bytes = Encoding.ASCII.GetBytes(formParams);
                req.ContentLength = bytes.Length;
                req.Timeout       = 10000;
                using (Stream os = req.GetRequestStream())
                {
                    os.Write(bytes, 0, bytes.Length);
                }
                resp = req.GetResponse() as HttpWebResponse;
                return(resp.ResponseUri.Query.Length > 0);
            }
            catch (Exception e)
            {
                if (e.Message.Contains("UNIQUE constraint failed:")) // already written so silently ignore adding to database.
                {
                    return(true);
                }
                outputText.Report($"Problem accessing Lost Cousins Website to send record below. Error message is: {e.Message}\n");
                return(false);
            }
            finally
            {
                resp?.Close();
            }
        }
示例#9
0
        private void tsBtnMapOSLocation_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            CensusIndividual ds  = dgCensus.CurrentRow == null ? null : (CensusIndividual)dgCensus.CurrentRow.DataBoundItem;
            FactLocation     loc = ds == null ? null : ds.CensusLocation;

            if (loc != null)
            {   // Do geo coding stuff
                BingOSMap frmBingMap = new BingOSMap();
                if (frmBingMap.SetLocation(loc, loc.Level))
                {
                    frmBingMap.Show();
                }
                else
                {
                    MessageBox.Show("Unable to find location : " + loc.ToString(), "FTAnalyzer");
                }
            }
            this.Cursor = Cursors.Default;
        }
        static string BuildParameterString(CensusIndividual ind)
        {
            StringBuilder output = new StringBuilder("stage=submit");
            string        newRef = GetCensusSpecificFields(ind);

            if (newRef == _previousRef)
            {
                output.Append("&similar=1");
            }
            else
            {
                output.Append("&similar=");
            }
            _previousRef = newRef;
            output.Append(newRef);
            output.Append($"&surname={ind.LCSurnameAtDate(ind.CensusDate)}");
            output.Append($"&forename={ind.LCForename}");
            output.Append($"&other_names={ind.LCOtherNames}");
            output.Append($"&age={ind.LCAge}");
            output.Append($"&relation_type={GetLCDescendantStatus(ind)}");
            if (!ind.IsMale && ind.LCSurname != ind.LCSurnameAtDate(ind.CensusDate))
            {
                output.Append($"&maiden_name={ind.LCSurname}");
            }
            else
            {
                output.Append("&maiden_name=");
            }
            output.Append($"&corrected_surname={ind.LCSurnameAtDate(ind.CensusDate)}&corrected_forename={ind.LCForename}&corrected_other_names={ind.LCOtherNames}");
            if (ind.BirthDate.IsExact)
            {
                output.Append($"&corrected_birth_day={ind.BirthDate.StartDate.Day}&corrected_birth_month={ind.BirthDate.StartDate.Month}&corrected_birth_year={ind.BirthDate.StartDate.Year}");
            }
            else
            {
                output.Append($"&corrected_birth_day=&corrected_birth_month=&corrected_birth_year=");
            }
            output.Append("&baptism_day=&baptism_month=&baptism_year=");
            output.Append($"&piece_number=&notes=Added_By_FTAnalyzer-{FamilyTree.Instance.Version}{Suffix()}");
            return(output.ToString());
        }
        public static bool LostCousinsExists(CensusIndividual ind)
        {
            if (InstanceConnection.State != ConnectionState.Open)
            {
                InstanceConnection.Open();
            }
            bool result = false;

            using (SqliteCommand cmd = new SqliteCommand("SELECT EXISTS(SELECT 1 FROM LostCousins where CensusYear=? and CensusCountry=? and CensusRef=? and IndID=?)", InstanceConnection))
            {
                SqliteParameter 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();
                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;
                using (SqliteDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleResult))
                {
                    if (reader.Read())
                    {
                        result = reader[0].ToString() == "1";
                    }
                }
            }
            return(result);
        }
        static string GetLCDescendantStatus(CensusIndividual ind)
        {
            switch (ind.RelationType)
            {
            case Individual.DIRECT:
                return($"Direct+ancestor&descent={ind.Ahnentafel}");

            case Individual.BLOOD:
            case Individual.DESCENDANT:
                return("Blood+relative&descent=");

            case Individual.MARRIAGE:
            case Individual.MARRIEDTODB:
                return("Marriage&descent=");

            case Individual.UNKNOWN:
            case Individual.UNSET:
            case Individual.LINKED:
                return("Unknown&descent=");

            default:
                return("Unknown&descent=");
            }
        }
        static string GetCensusSpecificFields(CensusIndividual ind)
        {
            CensusReference censusRef = ind.CensusReference;

            if (ind.CensusDate.Overlaps(CensusDate.EWCENSUS1841) && Countries.IsEnglandWales(ind.CensusCountry))
            {
                return($"&census_code=1841&ref1={censusRef.Piece}&ref2={censusRef.Book}&ref3={censusRef.Folio}&ref4={censusRef.Page}&ref5=");
            }
            if (ind.CensusDate.Overlaps(CensusDate.EWCENSUS1881) && Countries.IsEnglandWales(ind.CensusCountry))
            {
                return($"&census_code=RG11&ref1={censusRef.Piece}&ref2={censusRef.Folio}&ref3={censusRef.Page}&ref4=&ref5=");
            }
            if (ind.CensusDate.Overlaps(CensusDate.SCOTCENSUS1881) && ind.CensusCountry == Countries.SCOTLAND)
            {
                return($"&census_code=SCT1&ref1={censusRef.RD}&ref2={censusRef.ED}&ref3={censusRef.Page}&ref4=&ref5=");
            }
            if (ind.CensusDate.Overlaps(CensusDate.CANADACENSUS1881) && ind.CensusCountry == Countries.CANADA)
            {
                return($"&census_code=CAN1&ref1={censusRef.ED}&ref2={censusRef.SD}&ref3=&ref4={censusRef.Page}&ref5={censusRef.Family}");
            }
            //if (ind.CensusDate.Overlaps(CensusDate.IRELANDCENSUS1911) && ind.CensusCountry == Countries.IRELAND)
            //    return $"&census_code=0IRL&ref1=&ref2=&ref3=&ref4=&ref5=";
            if (ind.CensusDate.Overlaps(CensusDate.EWCENSUS1911) && Countries.IsEnglandWales(ind.CensusCountry))
            {
                return($"&census_code=0ENG&ref1={censusRef.Piece}&ref2={censusRef.Schedule}&ref3=&ref4=&ref5=");
            }
            if (ind.CensusDate.Overlaps(CensusDate.USCENSUS1880) && ind.CensusCountry == Countries.UNITED_STATES)
            {
                return($"&census_code=USA1&ref1={censusRef.Roll}&ref2={censusRef.Page}&ref3=&ref4=&ref5=");
            }
            if (ind.CensusDate.Overlaps(CensusDate.USCENSUS1940) && ind.CensusCountry == Countries.UNITED_STATES)
            {
                return($"&census_code=USA4&ref1={censusRef.Roll}&ref2={censusRef.ED}&ref3={censusRef.Page}&ref4=&ref5=");
            }
            return(string.Empty);
        }