示例#1
0
        protected virtual void EntityAddressZipCode_OnTextChanged(Object sender, EventArgs e)
        {
            if (MercuryApplication == null)
            {
                return;
            }

            if (EntityAddressZipCode.Text == null)
            {
                return;
            }

            if (EntityAddressZipCode.Text == String.Empty)
            {
                return;
            }

            if (EntityAddressZipCode.Text.Length < 5)
            {
                return;
            }

            String fiveDigitZipCode = EntityAddressZipCode.Text.Substring(0, 5);

            String stateFromZipCode = MercuryApplication.StateReferenceByZipCode(fiveDigitZipCode);

            if (!EntityAddressState.Items.Contains(new Telerik.Web.UI.RadComboBoxItem(stateFromZipCode, stateFromZipCode)))
            {
                InitializeState();
            }

            EntityAddressState.SelectedValue = stateFromZipCode;

            String countyFromZipCode = MercuryApplication.CountyReferenceByZipCode(fiveDigitZipCode);

            if (!EntityAddressCounty.Items.Contains(new Telerik.Web.UI.RadComboBoxItem(countyFromZipCode, countyFromZipCode)))
            {
                EntityAddressCounty.Items.Add(new Telerik.Web.UI.RadComboBoxItem(countyFromZipCode, countyFromZipCode));

                EntityAddressCounty.SelectedValue = countyFromZipCode;;
            }

            String cityFromZipCode = MercuryApplication.CityReferenceByZipCode(fiveDigitZipCode);

            if (!EntityAddressCity.Items.Contains(new Telerik.Web.UI.RadComboBoxItem(cityFromZipCode, cityFromZipCode)))
            {
                EntityAddressCity.Items.Clear();

                foreach (Mercury.Server.Application.CityStateZipCodeView currentCity  in MercuryApplication.CityReferenceByState(EntityAddressState.SelectedValue, true))
                {
                    EntityAddressCity.Items.Add(new Telerik.Web.UI.RadComboBoxItem(currentCity.City, currentCity.City));
                } /* END FOREACH */
            }

            EntityAddressCity.SelectedValue = cityFromZipCode;

            return;
        }