protected void btnEditSave_Click(object sender, EventArgs e) { Person person = new Person(Convert.ToInt32(hfEditPerson.Value)); PersonAddress address = person.Addresses.FindByType(Convert.ToInt32(hfEditType.Value)); PersonAddressCollection pac = new PersonAddressCollection(); // // Verify valid data. // if (address.AddressID == -1) { throw new System.Exception("Invalid address type during edit."); } // // Make sure this is the only person using this address, otherwise create a new one. // pac.LoadByAddressID(address.AddressID); if (pac.Count > 1) { person.Addresses.Remove(address); address = new PersonAddress(); address.PersonID = person.PersonID; address.Address = new Address(); address.AddressType = new Lookup(Convert.ToInt32(hfEditType.Value)); person.Addresses.Add(address); } // // Set the address information. // address.Address.StreetLine1 = tbEditStreetAddress1.Text.Trim(); address.Address.StreetLine2 = tbEditStreetAddress2.Text.Trim(); address.Address.City = tbEditCity.Text.Trim(); address.Address.State = tbEditState.Text.Trim(); address.Address.PostalCode = tbEditPostal.Text.Trim(); address.Address.Country = ddlEditCountry.SelectedValue; // // If this address is becoming primary (and wasn't already) make sure it is the // only one. // if (cbEditPrimary.Checked && address.Primary == false) { foreach (PersonAddress pa in person.Addresses) { pa.Primary = false; } } address.Primary = cbEditPrimary.Checked; // // Standardize and save. // address.Address.Standardize(); person.SaveAddresses(person.OrganizationID, CurrentUser.Identity.Name); LoadFamilyAddresses(family_id); cbSelectAll.Checked = false; }
private void UpdateAddressAreas(bool reGeoCode) { Arena.DataLayer.Organization.OrganizationData oData = new Arena.DataLayer.Organization.OrganizationData(); AreaCollection areas = new AreaCollection(OrganizationId); SqlDataReader rdr = new Arena.DataLayer.Core.AddressData().GetAddresses(); while (rdr.Read()) { Address address = new Address((int)rdr["address_id"]); if (address != null && address.AddressID != -1) { if (reGeoCode && !address.StreetLine1.ToUpper().StartsWith("PO BOX") && address.Latitude == 0 && address.Longitude == 0 && address.Standardized && address.DateGeocoded.AddDays(30) < DateTime.Today) { bool active = false; PersonAddressCollection pac = new PersonAddressCollection(); pac.LoadByAddressID(address.AddressID); foreach (PersonAddress pa in pac) { Person person = new Person(pa.PersonID); if (person.RecordStatus == Arena.Enums.RecordStatus.Active) { active = true; break; } } if (active) { status.Text = address.ToString().Replace("\n", " "); address.Geocode("ImportMapPointAreas", true); string breakstring = address.StreetLine1; } } else if (address.Latitude != 0 && address.Longitude != 0) { status.Text = address.ToString().Replace("\n", " "); address.UpdateArea(areas); } System.Windows.Forms.Application.DoEvents(); } } rdr.Close(); status.Text = string.Empty; MessageBox.Show("Addresses have been updated", "Import Complete"); }
public Contracts.GenericListResult <Contracts.PersonReference> GetPersonMatch(string email, string firstname, string lastname, string gender, string maritalstatus, string campus, string street1, string street2, string city, string state, string postalcode, string phonehome, string phonecell, string birthdate, string matchpercentminimum, string sessionid) { Contracts.GenericListResult <Contracts.PersonReference> personReferenceList = new Contracts.GenericListResult <Contracts.PersonReference>(); personReferenceList.Items = new List <Contracts.PersonReference>(); // Load PersonReference object with the provided values Contracts.PersonReference personReferenceOriginal = new Contracts.PersonReference(); personReferenceOriginal.BirthDate = birthdate.Trim(); personReferenceOriginal.Campus = campus.Trim(); personReferenceOriginal.City = city.Trim(); personReferenceOriginal.Emails = new Contracts.GenericListResult <Contracts.EmailReference>(); personReferenceOriginal.Emails.Items = new List <Contracts.EmailReference>(); personReferenceOriginal.Emails.Items.Add(new Contracts.EmailReference(1, email.Trim(), "True", "1")); personReferenceOriginal.FirstName = firstname.Trim(); personReferenceOriginal.LastName = lastname.Trim(); personReferenceOriginal.Gender = gender.Trim(); personReferenceOriginal.MaritalStatus = maritalstatus.Trim(); personReferenceOriginal.NickName = firstname.Trim(); personReferenceOriginal.PhoneNumbers = new Contracts.GenericListResult <Contracts.PhoneReference>(); personReferenceOriginal.PhoneNumbers.Items = new List <Contracts.PhoneReference>(); // Phone numbers are optional if (!String.IsNullOrEmpty(phonehome)) { personReferenceOriginal.PhoneNumbers.Items.Add(new Contracts.PhoneReference(PersonPhone.FormatPhone(phonehome.Trim()), "", "main/home")); } if (!String.IsNullOrEmpty(phonecell)) { personReferenceOriginal.PhoneNumbers.Items.Add(new Contracts.PhoneReference(PersonPhone.FormatPhone(phonecell.Trim()), "", "cell")); } personReferenceOriginal.PostalCode = postalcode.Trim(); personReferenceOriginal.State = state.Trim(); personReferenceOriginal.Street1 = street1.Trim(); personReferenceOriginal.Street2 = street2.Trim(); // What is the minimum matching percent of a person that we will return from the function int matchPercentMinimum = String.IsNullOrEmpty(matchpercentminimum) ? 0 : Convert.ToInt32(matchpercentminimum); // Let's determine the provided gender or stop int genderId = -1; switch (gender.ToLower()) { case "male": genderId = 0; break; case "female": genderId = 1; break; } if (genderId == -1) { throw new Exception("Please specify a valid gender."); } // Let's use the first 2 characters in order to limit results and do more auto-matching string firstNameInitial = (firstname.Length > 1 ? firstname.Substring(0, 2) : firstname.Substring(0, 1)); // Get persons by first initial, last name, gender and birthdate CorePersonService cps = new CorePersonService(); List <core_person> persons = cps.GetList(firstNameInitial, lastname, false); PersonCollection pc; List <Person> personList = new List <Person>(); // Get persons with this e-mail address pc = new PersonCollection(); pc.LoadByEmail(email); personList.AddRange((from pcbe in pc select pcbe).ToList()); // Get persons with this phone number if (!String.IsNullOrEmpty(phonehome)) { phonehome = PersonPhone.FormatPhone(phonehome); pc = new PersonCollection(); pc.LoadByPhone(phonehome); personList.AddRange((from pcbe in pc select pcbe).ToList()); } if (!String.IsNullOrEmpty(phonecell)) { phonecell = PersonPhone.FormatPhone(phonecell); pc = new PersonCollection(); pc.LoadByPhone(phonecell); personList.AddRange((from pcbe in pc select pcbe).ToList()); } // Get persons with this address and first initial Address address = new Address(street1, street2, city, state, postalcode); CoreAddressService cas = new CoreAddressService(); List <int> addressIdList = cas.GetList(address.StreetLine1, address.StreetLine2, address.PostalCode); Person person = new Person(); // TODO: enhance Arena with LoadByAddressIDs function to improve performance foreach (int addressId in addressIdList) { PersonAddressCollection pac = new PersonAddressCollection(); pac.LoadByAddressID(addressId); foreach (PersonAddress pa in pac) { person = new Person(pa.PersonID); if ((person.FirstName.ToLower().StartsWith(firstNameInitial.ToLower()) || person.NickName.ToLower().StartsWith(firstNameInitial.ToLower()))) { personList.Add(person); } } } // Remove duplicates personList = (from p in personList select p).Distinct().ToList(); // Load persons over the Match Percent Minimum threshold List <int> personIdList = new List <int>(); Contracts.PersonReference personReference = new Contracts.PersonReference(); string mapMatch = String.Empty; int counter = 0; foreach (Person p in personList) { if ((from prl in personIdList where prl == p.PersonID select prl).Count() == 0) { counter++; personReference = ConvertPersonToPersonReference(p); personReference.MatchPercent = CalculateMatchPercent(personReferenceOriginal, personReference, out mapMatch); personReference.MatchMap = mapMatch; personReference.IsExact = "false"; // If Person is greater than Match Percent Minimum then check for exact match and add to if (Convert.ToInt32(personReference.MatchPercent) >= matchPercentMinimum) { string domain = String.Empty; personReference.IsExact = IsPersonQualifiedForExact(p, (personReference.MaritalStatus == personReferenceOriginal.MaritalStatus ? true : false), birthdate, email, firstname, lastname, gender, street1, street2, city, state, postalcode, phonehome, phonecell, out domain).ToString(); personReference.IsExactPrimaryEmailDomain = domain; personReferenceList.Items.Add(personReference); personIdList.Add(personReference.PersonId); } } } foreach (core_person cp in persons) { if ((from prl in personIdList where prl == cp.person_id select prl).Count() == 0) { counter++; person = new Person(cp.person_id); personReference = ConvertPersonToPersonReference(person); personReference.IsExact = "false"; personReference.MatchPercent = CalculateMatchPercent(personReferenceOriginal, personReference, out mapMatch); personReference.MatchMap = mapMatch; // If Person is greater than Match Percent Minimum then check for exact match if (Convert.ToInt32(personReference.MatchPercent) >= matchPercentMinimum) { string domain = String.Empty; personReference.IsExact = IsPersonQualifiedForExact(person, (personReference.MaritalStatus == personReferenceOriginal.MaritalStatus ? true : false), birthdate, email, firstname, lastname, gender, street1, street2, city, state, postalcode, phonehome, phonecell, out domain).ToString(); personReference.IsExactPrimaryEmailDomain = domain; personReferenceList.Items.Add(personReference); personIdList.Add(personReference.PersonId); } } } // Order filtered persons by Match Percent Contracts.GenericListResult <Contracts.PersonReference> personsSorted = new Contracts.GenericListResult <Contracts.PersonReference>(); personsSorted.Items = new List <Contracts.PersonReference>(); personsSorted.Items = (from prl in personReferenceList.Items orderby Convert.ToInt32(prl.MatchPercent) descending select prl).ToList(); personsSorted.Max = counter; personsSorted.Total = personReferenceList.Items.Count(); return(personsSorted); }
public Contracts.GenericListResult<Contracts.PersonReference> GetPersonMatch(string email, string firstname, string lastname, string gender, string maritalstatus, string campus, string street1, string street2, string city, string state, string postalcode, string phonehome, string phonecell, string birthdate, string matchpercentminimum, string sessionid) { Contracts.GenericListResult<Contracts.PersonReference> personReferenceList = new Contracts.GenericListResult<Contracts.PersonReference>(); personReferenceList.Items = new List<Contracts.PersonReference>(); // Load PersonReference object with the provided values Contracts.PersonReference personReferenceOriginal = new Contracts.PersonReference(); personReferenceOriginal.BirthDate = birthdate.Trim(); personReferenceOriginal.Campus = campus.Trim(); personReferenceOriginal.City = city.Trim(); personReferenceOriginal.Emails = new Contracts.GenericListResult<Contracts.EmailReference>(); personReferenceOriginal.Emails.Items = new List<Contracts.EmailReference>(); personReferenceOriginal.Emails.Items.Add(new Contracts.EmailReference(1, email.Trim(), "True", "1")); personReferenceOriginal.FirstName = firstname.Trim(); personReferenceOriginal.LastName = lastname.Trim(); personReferenceOriginal.Gender = gender.Trim(); personReferenceOriginal.MaritalStatus = maritalstatus.Trim(); personReferenceOriginal.NickName = firstname.Trim(); personReferenceOriginal.PhoneNumbers = new Contracts.GenericListResult<Contracts.PhoneReference>(); personReferenceOriginal.PhoneNumbers.Items = new List<Contracts.PhoneReference>(); // Phone numbers are optional if (!String.IsNullOrEmpty(phonehome)) { personReferenceOriginal.PhoneNumbers.Items.Add(new Contracts.PhoneReference(PersonPhone.FormatPhone(phonehome.Trim()), "", "main/home")); } if (!String.IsNullOrEmpty(phonecell)) { personReferenceOriginal.PhoneNumbers.Items.Add(new Contracts.PhoneReference(PersonPhone.FormatPhone(phonecell.Trim()), "", "cell")); } personReferenceOriginal.PostalCode = postalcode.Trim(); personReferenceOriginal.State = state.Trim(); personReferenceOriginal.Street1 = street1.Trim(); personReferenceOriginal.Street2 = street2.Trim(); // What is the minimum matching percent of a person that we will return from the function int matchPercentMinimum = String.IsNullOrEmpty(matchpercentminimum) ? 0 : Convert.ToInt32(matchpercentminimum); // Let's determine the provided gender or stop int genderId = -1; switch (gender.ToLower()) { case "male": genderId = 0; break; case "female": genderId = 1; break; } if (genderId == -1) { throw new Exception("Please specify a valid gender."); } // Let's use the first 2 characters in order to limit results and do more auto-matching string firstNameInitial = (firstname.Length > 1 ? firstname.Substring(0, 2) : firstname.Substring(0, 1)); // Get persons by first initial, last name, gender and birthdate CorePersonService cps = new CorePersonService(); List<core_person> persons = cps.GetList(firstNameInitial, lastname, false); PersonCollection pc; List<Person> personList = new List<Person>(); // Get persons with this e-mail address pc = new PersonCollection(); pc.LoadByEmail(email); personList.AddRange((from pcbe in pc select pcbe).ToList()); // Get persons with this phone number if (!String.IsNullOrEmpty(phonehome)) { phonehome = PersonPhone.FormatPhone(phonehome); pc = new PersonCollection(); pc.LoadByPhone(phonehome); personList.AddRange((from pcbe in pc select pcbe).ToList()); } if (!String.IsNullOrEmpty(phonecell)) { phonecell = PersonPhone.FormatPhone(phonecell); pc = new PersonCollection(); pc.LoadByPhone(phonecell); personList.AddRange((from pcbe in pc select pcbe).ToList()); } // Get persons with this address and first initial Address address = new Address(street1, street2, city, state, postalcode); CoreAddressService cas = new CoreAddressService(); List<int> addressIdList = cas.GetList(address.StreetLine1, address.StreetLine2, address.PostalCode); Person person = new Person(); // TODO: enhance Arena with LoadByAddressIDs function to improve performance foreach (int addressId in addressIdList) { PersonAddressCollection pac = new PersonAddressCollection(); pac.LoadByAddressID(addressId); foreach (PersonAddress pa in pac) { person = new Person(pa.PersonID); if ((person.FirstName.ToLower().StartsWith(firstNameInitial.ToLower()) || person.NickName.ToLower().StartsWith(firstNameInitial.ToLower()))) { personList.Add(person); } } } // Remove duplicates personList = (from p in personList select p).Distinct().ToList(); // Load persons over the Match Percent Minimum threshold List<int> personIdList = new List<int>(); Contracts.PersonReference personReference = new Contracts.PersonReference(); string mapMatch = String.Empty; int counter = 0; foreach (Person p in personList) { if ((from prl in personIdList where prl == p.PersonID select prl).Count() == 0) { counter++; personReference = ConvertPersonToPersonReference(p); personReference.MatchPercent = CalculateMatchPercent(personReferenceOriginal, personReference, out mapMatch); personReference.MatchMap = mapMatch; personReference.IsExact = "false"; // If Person is greater than Match Percent Minimum then check for exact match and add to if (Convert.ToInt32(personReference.MatchPercent) >= matchPercentMinimum) { string domain = String.Empty; personReference.IsExact = IsPersonQualifiedForExact(p, (personReference.MaritalStatus == personReferenceOriginal.MaritalStatus ? true : false), birthdate, email, firstname, lastname, gender, street1, street2, city, state, postalcode, phonehome, phonecell, out domain).ToString(); personReference.IsExactPrimaryEmailDomain = domain; personReferenceList.Items.Add(personReference); personIdList.Add(personReference.PersonId); } } } foreach (core_person cp in persons) { if ((from prl in personIdList where prl == cp.person_id select prl).Count() == 0) { counter++; person = new Person(cp.person_id); personReference = ConvertPersonToPersonReference(person); personReference.IsExact = "false"; personReference.MatchPercent = CalculateMatchPercent(personReferenceOriginal, personReference, out mapMatch); personReference.MatchMap = mapMatch; // If Person is greater than Match Percent Minimum then check for exact match if (Convert.ToInt32(personReference.MatchPercent) >= matchPercentMinimum) { string domain = String.Empty; personReference.IsExact = IsPersonQualifiedForExact(person, (personReference.MaritalStatus == personReferenceOriginal.MaritalStatus ? true : false), birthdate, email, firstname, lastname, gender, street1, street2, city, state, postalcode, phonehome, phonecell, out domain).ToString(); personReference.IsExactPrimaryEmailDomain = domain; personReferenceList.Items.Add(personReference); personIdList.Add(personReference.PersonId); } } } // Order filtered persons by Match Percent Contracts.GenericListResult<Contracts.PersonReference> personsSorted = new Contracts.GenericListResult<Contracts.PersonReference>(); personsSorted.Items = new List<Contracts.PersonReference>(); personsSorted.Items = (from prl in personReferenceList.Items orderby Convert.ToInt32(prl.MatchPercent) descending select prl).ToList(); personsSorted.Max = counter; personsSorted.Total = personReferenceList.Items.Count(); return personsSorted; }