/// <summary>
        /// Displays information found by a person search.
        /// </summary>
        /// <param name="searchResults">Result state of a SearchForPersons search.</param>
        private void DisplayPersonSearchResults(PersonSearchResultsState searchResults)
        {
            //Declare a person.
            PersonState person;

            //Clear ResultBox.
            ResultBox.Items.Clear();

            //See remark (1) at the bottom of this file.

            //Search through the result list.
            foreach (Entry singleEntry in searchResults.Results.Entries ?? new List <Entry>())
            {
                //Get a person.
                person = searchResults.ReadPerson(singleEntry);

                //Person could be null, it does happen.
                if (person.Person != null)
                {
                    //Display some person info.
                    ResultBox.Items.Add(person.Person.DisplayExtension.Name + " "
                                        + person.Person.Id);
                }
                else
                {
                    //Show off the rare occasion of a null person.
                    ResultBox.Items.Add("null");
                }
                //Display it right away, we are inpatient.
                ResultBox.Update();
            }
        }
Exemplo n.º 2
0
        public void TestReadNextPageOfSearchResults()
        {
            GedcomxPersonSearchQueryBuilder query = new GedcomxPersonSearchQueryBuilder()
                .Name("John Smith")
                .BirthDate("1 January 1900")
                .FatherName("Peter Smith");

            PersonSearchResultsState results = collection.SearchForPersons(query);

            var state = (PersonSearchResultsState)results.ReadNextPage();
            Assert.DoesNotThrow(() => state.IfSuccessful());
            PersonState person = state.ReadPerson(results.Results.Entries.FirstOrDefault());

            Assert.IsNotNull(person);
            Assert.DoesNotThrow(() => person.IfSuccessful());
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            //Remember cursor and change to wait-cursor.
            var cursorState = Cursor;

            Cursor = Cursors.WaitCursor;

            lblErrorMessage.Text = "No Error.";

            try
            {
                //Put together a search query.
                GedcomxPersonSearchQueryBuilder query = new GedcomxPersonSearchQueryBuilder()

                                                        //Set all on the form available Parameter for query.
                                                        //Note: This is just a sample of available Parameters.
                                                        .GivenName(txtGivenName.Text)
                                                        .Surname(txtSurname.Text)
                                                        .BirthDate(txtBirthDate.Text)
                                                        .FatherGivenName(txtFatherGivenName.Text)
                                                        .FatherSurname(txtFatherSurname.Text)
                                                        .FatherBirthDate(txtFatherBirthDate.Text)
                                                        .MotherGivenName(txtMotherGivenName.Text)
                                                        .MotherSurname(txtMotherSurname.Text)
                                                        .MotherBirthDate(txtMotherBirthDate.Text);

                //Search the collection.
                PersonSearchResultsState resultsSearchPersons = FamilyTree.SearchForPersons(query);

                //Show results on Form.
                DisplayPersonSearchResults(resultsSearchPersons);
            }
            catch (Exception myError)
            {
                //report error to error label
                lblErrorMessage.Text = myError.Message.ToString();
            }
            finally
            {
                // Restore Cursor.
                Cursor = cursorState;
            }
        }