Exemple #1
0
        public static ReadOnlyCollection <Person> GetMatches(PersonData data)
        {
            if (data.IsEmpty())
            {
                return(EmptyCollection <Person> .Instance);
            }

            if (!String.IsNullOrEmpty(data.FullName))
            {
                if (String.IsNullOrEmpty(data.LastName))
                {
                    var lastNameStart = data.FullName.LastIndexOf(' ');
                    if (lastNameStart > 0)
                    {
                        data.LastName = data.FullName.Substring(lastNameStart);
                    }
                }
            }

            var initialMatches = GetInitialMatches(data).ToArray();

            if (!initialMatches.Any())
            {
                return(EmptyCollection <Person> .Instance);
            }

            var retVal = FilterName(initialMatches, data).ToArray();

            if (retVal.Length == 0)
            {
                return(new ReadOnlyCollection <Person>(initialMatches));
            }
            return(new ReadOnlyCollection <Person>(retVal));
        }
Exemple #2
0
        ///<summary>Gets an AllPeople row from this instance's AllPeopleDataTable for the specified person.</summary>
        ///<param name="data">The data about the person.</param>
        ///<remarks>This function will attempt to find a person in AllPeople that matches whatever data was provided.
        ///If there are no matches, or if the parameter is empty, the user is prompted to add a new person.
        ///If there are multiple matches, the user is prompted to select the person to update or add a new one.</remarks>
        public ResolvedPerson Resolve(PersonData data)
        {
            if (data.IsEmpty())
            {
                return(null);
            }
            var retVal = new ResolvedPerson(this, data, GetMatches(data));

            if (retVal.Matches.Count == 0)                                                                              //If there aren't any matches,
            {
                retVal.SetAddNew(retVal.Data);

                //using (var form = new Forms.ResolveAdd(retVal))
                //    form.ShowDialog();
                return(retVal);
            }
            else if (retVal.Matches.All(m =>
                                        (!String.IsNullOrEmpty(m.Zip) && !String.IsNullOrEmpty(data.Zip) && m.Zip != data.Zip)
                                        //|| (!String.IsNullOrEmpty(m.City) && !String.IsNullOrEmpty(data.City) && m.Zip != data.City)
                                        || (!String.IsNullOrEmpty(m.State) && !String.IsNullOrEmpty(data.State) && m.State != data.State)
                                        ))
            {
                retVal.SetAddNew(retVal.Data);
                if (String.IsNullOrEmpty(retVal.Data.FullName))
                {
                    retVal.ResolvedRow.FullName = retVal.ResolvedRow.VeryFullName;
                }

                //using (var form = new Forms.ResolveAdd(retVal))
                //    form.ShowDialog();
                return(retVal);
            }
            else if (retVal.Matches.Count == 1)                                                         //If there was exactly one match,
            {
                if (retVal.Data.IsUnequal(retVal.Matches[0]))                                           //If the match isn't the same as the data,
                {
                    retVal.SetUseExisting(retVal.Matches[0]);                                           //Use the existing match from AllPeople
                }
                else                                                                                    //If it's a perfect match,
                {
                    retVal.SetUpdateExisting(retVal.Matches[0]);                                        //Use the existing match
                    return(retVal);                                                                     //And return without disambiguation.
                }
            }
            else
            {
                //using (var form = new Forms.Disambiguator(retVal)) {
                //    form.Action = ResolveAction.UseExisting;

                //    form.ShowDialog();
                //}
            }
            return(retVal);
        }