/// <summary> /// Return a value from an address field that is adjusted to meet the associated requirements. /// </summary> /// <param name="value"></param> /// <param name="requirementLevel"></param> /// <returns></returns> private string GetLocationFieldValue(string value, DataEntryRequirementLevelSpecifier requirementLevel) { if (requirementLevel == DataEntryRequirementLevelSpecifier.Unavailable) { // If the field is unavailable, do not store the value. return(null); } return(value); }
/// <summary> /// Load the address field settings for the specified country. /// </summary> /// <param name="countryCode"></param> private void LoadCountryConfiguration(string countryCode) { var countryValue = DefinedTypeCache.Get(new Guid(SystemGuid.DefinedType.LOCATION_COUNTRIES)) .DefinedValues .Where(v => v.Value.Equals(countryCode, StringComparison.OrdinalIgnoreCase)) .FirstOrDefault(); if (countryValue == null) { _CityLabel = null; _LocalityLabel = null; _StateLabel = null; _PostalCodeLabel = null; } else { _CityLabel = countryValue.GetAttributeValue(SystemKey.CountryAttributeKey.AddressCityLabel); _LocalityLabel = countryValue.GetAttributeValue(SystemKey.CountryAttributeKey.AddressLocalityLabel); _StateLabel = countryValue.GetAttributeValue(SystemKey.CountryAttributeKey.AddressStateLabel); _PostalCodeLabel = countryValue.GetAttributeValue(SystemKey.CountryAttributeKey.AddressPostalCodeLabel); var requirementField = new DataEntryRequirementLevelFieldType(); _AddressLine1Requirement = requirementField.GetDeserializedValue(countryValue.GetAttributeValue(SystemKey.CountryAttributeKey.AddressLine1Requirement), DataEntryRequirementLevelSpecifier.Optional); _AddressLine2Requirement = requirementField.GetDeserializedValue(countryValue.GetAttributeValue(SystemKey.CountryAttributeKey.AddressLine2Requirement), DataEntryRequirementLevelSpecifier.Optional); _CityRequirement = requirementField.GetDeserializedValue(countryValue.GetAttributeValue(SystemKey.CountryAttributeKey.AddressCityRequirement), DataEntryRequirementLevelSpecifier.Optional); _LocalityRequirement = requirementField.GetDeserializedValue(countryValue.GetAttributeValue(SystemKey.CountryAttributeKey.AddressLocalityRequirement), DataEntryRequirementLevelSpecifier.Optional); _StateRequirement = requirementField.GetDeserializedValue(countryValue.GetAttributeValue(SystemKey.CountryAttributeKey.AddressStateRequirement), DataEntryRequirementLevelSpecifier.Optional); _PostalCodeRequirement = requirementField.GetDeserializedValue(countryValue.GetAttributeValue(SystemKey.CountryAttributeKey.AddressPostalCodeRequirement), DataEntryRequirementLevelSpecifier.Optional); } _CityLabel = _CityLabel.ToStringOrDefault("City"); _LocalityLabel = _LocalityLabel.ToStringOrDefault("Locality"); _StateLabel = _StateLabel.ToStringOrDefault("State"); _PostalCodeLabel = _PostalCodeLabel.ToStringOrDefault("Postal Code"); // Hide Address Line 2 if it is not required, and not specified to show in the control settings. if (_AddressLine2Requirement == DataEntryRequirementLevelSpecifier.Optional && !this.ShowAddressLine2) { _AddressLine2Requirement = DataEntryRequirementLevelSpecifier.Unavailable; } // Hide Locality if specified in the control settings and it is not required. // The ShowCounty property is probably not necessary now because this setting can be specified per-country. if (_LocalityRequirement == DataEntryRequirementLevelSpecifier.Optional && !this.ShowCounty) { _LocalityRequirement = DataEntryRequirementLevelSpecifier.Unavailable; } }