public JsonResult PesquisaCEP_Javascript(String cep, int tipoEnd)
        {
            // Chama servico ECT
            //FILIAL cli = baseApp.GetItemById((Int32)Session["IdVolta"]);

            ZipCodeLoad zipLoad = new ZipCodeLoad();
            ZipCodeInfo end     = new ZipCodeInfo();
            ZipCode     zipCode = null;

            cep = CrossCutting.ValidarNumerosDocumentos.RemoveNaoNumericos(cep);
            if (ZipCode.TryParse(cep, out zipCode))
            {
                end = zipLoad.Find(zipCode);
            }

            // Atualiza
            var hash = new Hashtable();

            if (tipoEnd == 1)
            {
                hash.Add("FILI_NM_ENDERECO", end.Address + "/" + end.Complement);
                hash.Add("FILI_NM_BAIRRO", end.District);
                hash.Add("FILI_NM_CIDADE", end.City);
                hash.Add("UF_CD_ID", baseApp.GetUFBySigla(end.Uf).UF_CD_ID);
                hash.Add("FILI_NR_CEP", cep);
            }

            // Retorna
            Session["VoltaCEP"] = 2;
            return(Json(hash));
        }
Ejemplo n.º 2
0
 private void I5_CEP_Leave(object sender, EventArgs e)
 {
     try
     {
         MaskedTextBox MaskedTextBox = (MaskedTextBox)sender;
         ZipCodeInfo   zipCodeInfo   = ZipLoad.Find(MaskedTextBox.Text);
         if (zipCodeInfo.Erro == false)
         {
             if (MaskedTextBox == I5_ORG_CEP)
             {
                 I5_ORG_LOGRADOURO.Text = zipCodeInfo.Address.ToUpper();
                 I5_ORG_BAIRRO.Text     = zipCodeInfo.District.ToUpper();
                 I5_ORG_UF.Text         = zipCodeInfo.Uf.ToUpper();
                 I5_ORG_MUN.Text        = zipCodeInfo.City.ToUpper();
             }
             else
             {
                 I5_DEST_LOGRADOURO.Text = zipCodeInfo.Address.ToUpper();
                 I5_DEST_BAIRRO.Text     = zipCodeInfo.District.ToUpper();
                 I5_DEST_UF.Text         = zipCodeInfo.Uf.ToUpper();
                 I5_DEST_MUN.Text        = zipCodeInfo.City.ToUpper();
             }
             return;
         }
         else
         {
             MessageBox.Show("CEP Não Localizado!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     catch
     {
         MessageBox.Show("Falha na busca do Cep!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 3
0
        public static ModelEndereco BuscaEnd(string cep)
        {
            ZipCodeLoad load = new ZipCodeLoad();

            try
            {
                ModelEndereco end      = new ModelEndereco();
                ZipCodeInfo   endereco = load.Find(cep); // BUSCA DE CEP

                if (endereco.Erro == false)
                {
                    end.Rua         = endereco.Address;
                    end.Complemento = endereco.Complement;
                    end.Bairro      = endereco.District;
                    end.Cidade      = endereco.City;
                    end.Estado      = endereco.Uf;
                    end.Resultado   = 1;
                }
                else
                {
                    end.Resultado = 0;
                }
                return(end);
            }
            catch (ZipCodeException ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds the zip code handler.
        /// </summary>
        /// <param name="newZipCode">The new zip code.</param>
        public void AddZipCodeHandler(ZipCodeInfo newZipCode)
        {
            if (newZipCode == null)
            {
                return;
            }

            this.ZipCodes.Add(newZipCode);
        }
Ejemplo n.º 5
0
        private async void ExecuteItemTappedCommand(ZipCodeInfo obj)
        {
            if (obj == null)
            {
                return;
            }

            await Shell.Current.GoToAsync($"{nameof(ItemDetailPage)}?{nameof(ItemDetailViewModel.ItemId)}={obj.CEP}");
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Deletes the zip code handler.
        /// </summary>
        /// <param name="zipCode">The zip code.</param>
        public void DeleteZipCodeHandler(ZipCodeInfo zipCode)
        {
            if (zipCode == null)
            {
                return;
            }

            this.ZipCodes.Remove(zipCode);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the current weather conditions for the given zip code
        /// </summary>
        /// <param name="zipCode"></param>
        /// <returns></returns>
        public CurrentConditions GetCurrentConditions(string zipCode)
        {
            ZipCodeInfo zipCodeObject = this.zipCodeService.GetZipCode(zipCode);


            NoaaWeatherClient noaaClient = new NoaaWeatherClient();
            NoaaResponse      response   = noaaClient.GetWeatherConditions(zipCodeObject.Latitude.Value, zipCodeObject.Longitude.Value);

            return(this.MapResponseObject(response));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Clones the zip code.
 /// </summary>
 /// <param name="zipCodeInfo">The zip code info.</param>
 private void CloneZipCode(ZipCodeInfo zipCodeInfo)
 {
     _zipInfo.City               = zipCodeInfo.City;
     _zipInfo.Class              = zipCodeInfo.Class;
     _zipInfo.Description        = zipCodeInfo.Description;
     _zipInfo.Latitude           = zipCodeInfo.Latitude;
     _zipInfo.Longitude          = zipCodeInfo.Longitude;
     _zipInfo.StateAbbereviation = zipCodeInfo.StateAbbereviation;
     _zipInfo.StateCode          = zipCodeInfo.StateCode;
     _zipInfo.StateName          = zipCodeInfo.StateName;
     _zipInfo.ZipCode            = zipCodeInfo.ZipCode;
 }
Ejemplo n.º 9
0
        public void TestZipCodeFactoryWorks()
        {
            // Act
            InMemoryZipCodeService provider = ZipCodeProviderFactory.ZipCodeProvider;

            // assert
            Assert.NotNull(provider);

            ZipCodeInfo appletonZip = provider.GetZipCode("54911");

            Assert.NotNull(appletonZip);
            Assert.Equal("APPLETON", appletonZip.City);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ManipulatorViewModel"/> class.
        /// </summary>
        /// <param name="zipCodeInfo">The zip code info.</param>
        /// <param name="isInEdit">if set to <c>true</c> [is in edit].</param>
        public ManipulatorViewModel(ZipCodeInfo zipCodeInfo, bool isInEdit)
        {
            _isInEdit         = isInEdit;
            SaveCommand       = new DelegateCommand <ZipCodeInfo>(this.Save, this.CanSave);
            SaveButtonContent = isInEdit ? "Save" : "Add";
            CloneZipCode(zipCodeInfo);

            if (_isInEdit)
            {
                Validate();
            }

            this.PropertyChanged += OnPropertyChanged;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Updates the zip code handler.
        /// </summary>
        /// <param name="newZipCode">The new zip code.</param>
        public void UpdateZipCodeHandler(ZipCodeInfo newZipCode)
        {
            if (newZipCode == null)
            {
                return;
            }

            _selectedZipCode.City               = newZipCode.City;
            _selectedZipCode.Class              = newZipCode.Class;
            _selectedZipCode.Description        = newZipCode.Description;
            _selectedZipCode.Latitude           = newZipCode.Latitude;
            _selectedZipCode.Longitude          = newZipCode.Longitude;
            _selectedZipCode.StateAbbereviation = newZipCode.StateAbbereviation;
            _selectedZipCode.StateCode          = newZipCode.StateCode;
            _selectedZipCode.StateName          = newZipCode.StateName;
            _selectedZipCode.ZipCode            = newZipCode.ZipCode;
        }
Ejemplo n.º 12
0
            /// <summary>
            /// Validates the address as well as resolves the state from zip code, if needed.
            /// </summary>
            /// <param name="context">Instance of <see cref="RequestContext"/>.</param>
            /// <param name="addressToValidate">Address to be validated and resolved.</param>
            /// <param name="validationFailures">The list to hold all exceptions.</param>
            private static void ValidateAndResolveAddress(RequestContext context, Address addressToValidate, List <DataValidationFailure> validationFailures)
            {
                if (addressToValidate != null)
                {
                    // Validates the address
                    ValidateAddressDataRequest  validateAddressRequest = new ValidateAddressDataRequest(addressToValidate);
                    ValidateAddressDataResponse response = context.Runtime.Execute <ValidateAddressDataResponse>(validateAddressRequest, context);

                    if (!response.IsAddressValid)
                    {
                        validationFailures.Add(new DataValidationFailure(response.ErrorCode, new Collection <string> {
                            response.InvalidAddressComponentName
                        }, response.ErrorMessage));
                        return;
                    }

                    // If zip code is provided but not the state, resolve the state from zipcode.
                    if (string.IsNullOrWhiteSpace(addressToValidate.State) && !string.IsNullOrWhiteSpace(addressToValidate.ZipCode))
                    {
                        GetFromZipPostalCodeServiceRequest zipPostalCodeRequest = new GetFromZipPostalCodeServiceRequest(addressToValidate.ThreeLetterISORegionName, addressToValidate.ZipCode)
                        {
                            QueryResultSettings = QueryResultSettings.AllRecords
                        };

                        GetFromZipPostalCodeServiceResponse zipPostalCodeResponse
                            = context.Runtime.Execute <GetFromZipPostalCodeServiceResponse>(zipPostalCodeRequest, context);

                        if (zipPostalCodeResponse.Results != null)
                        {
                            ZipCodeInfo zipCodeResult = zipPostalCodeResponse.Results.Results.GetEnumerator().Current;
                            if (zipCodeResult != null)
                            {
                                addressToValidate.State = zipCodeResult.StateId;
                            }
                        }
                    }
                }
            }
Ejemplo n.º 13
0
 private void I0_CEP_Leave(object sender, EventArgs e)
 {
     try
     {
         ZipCodeInfo zipCodeInfo = ZipLoad.Find(I0_CEP.Text);
         if (zipCodeInfo.Erro == false)
         {
             I0_LOGRADOURO.Text = zipCodeInfo.Address.ToUpper();
             I0_BAIRRO.Text     = zipCodeInfo.District.ToUpper();
             I0_UF.Text         = zipCodeInfo.Uf.ToUpper();
             I0_MUN.Text        = zipCodeInfo.City.ToUpper();
             return;
         }
         else
         {
             MessageBox.Show("CEP Não Localizado!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     catch
     {
         MessageBox.Show("Falha na busca do Cep!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 14
0
    [WebMethod]                                // anotação que faz com que este método seja reconhecido no web service
    public ZipCodeInfo searchByCep(string cep) // searchByCep é um método do web service que iremos utilizar para fazer a pesquisa pelo cep informado como parâmetro.
    {
        try
        {
            //Observação
            //Formato válido para o CEP: 01414000 ou 01414-000 ou 01.414-000

            ZipCodeLoad zipLoad     = new ZipCodeLoad(); // instanciando o objeto de um serviço externo de cep
            ZipCodeInfo zipCodeInfo = null;              // criando variável e atribuindo um valor nulo para ela

            ZipCode zipCode = null;                      // criando variável e atribuindo um valor nulo para ela
            if (ZipCode.TryParse(cep, out zipCode))      // converte o cep e atribui seu valor ao objeto zipCode criado anteriormente
            {
                zipCodeInfo = zipLoad.Find(zipCode);     // faz o consumo do serviço para retornar um endereço que corresponda ao cep informado
            }

            return(zipCodeInfo);    // retorna o endereço encontrado
        }
        catch (ZipCodeException ex) // em caso de algum erro no código acima, uma exceção é lançada e o erro é retornado, em forma de xml
        {
            throw ex;
        }
    }
Ejemplo n.º 15
0
 /// <summary>
 /// Determines whether this instance [can add zip code] the specified new zip code.
 /// </summary>
 /// <param name="newZipCode">The new zip code.</param>
 /// <returns>
 ///     <c>true</c> if this instance [can add zip code] the specified new zip code; otherwise, <c>false</c>.
 /// </returns>
 bool CanAddZipCode(ZipCodeInfo newZipCode)
 {
     return(true);
 }
Ejemplo n.º 16
0
    protected void txt_cepOrigem_TextChanged(object sender, EventArgs e)
    {
        string cep = txt_cepOrigem.Text;

        if (cep.Length == 9)
        {
            try
            {
                //Formato válido para o CEP: 01414000 ou 01414-000 ou 01.414-000
                ZipCodeLoad zipLoad = new ZipCodeLoad();

                ZipCode zipCode = null;
                ddl_estadoOrigem.Enabled = true;
                ddl_cidadeOrigem.Enabled = true;
                if (ZipCode.TryParse(cep, out zipCode))
                {
                    ZipCodeInfo zipCodeInfo = zipLoad.Find(zipCode);
                    txt_ruaOrigem.Text = zipCodeInfo.Address;
                    string estado = zipCodeInfo.Uf;
                    if (estado.Equals("SP") || estado.Equals("RJ") || estado.Equals("MG") || estado.Equals("ES"))
                    {
                        switch (estado)
                        {
                        case "SP":
                            ddl_estadoOrigem.SelectedValue = "São Paulo";
                            break;

                        case "RJ":
                            ddl_estadoOrigem.SelectedValue = "Rio de Janeiro";
                            break;

                        case "MG":
                            ddl_estadoOrigem.SelectedValue = "Minas Gerais";
                            break;

                        case "ES":
                            ddl_estadoOrigem.SelectedValue = "Espírito Santo";
                            break;
                        }
                        ddl_estadoOrigem_SelectedIndexChanged(this, EventArgs.Empty);
                        ddl_cidadeOrigem.SelectedValue = zipCodeInfo.City;

                        txt_bairroOrigem.Text    = zipCodeInfo.District;
                        ddl_estadoOrigem.Enabled = false;
                        ddl_cidadeOrigem.Enabled = false;
                    }
                    else
                    {
                        ltl_status.Text = "<script type = 'text/javascript'> toastr.error('Erro 7: Endereço fora da região sudeste') </script>";
                    }
                }
            }
            catch (ZipCodeException)
            {
                ltl_status.Text = "<script type = 'text/javascript' > toastr.error('Erro 0: Desconhecido') </ script >";
            }
        }
        else if (string.IsNullOrEmpty(cep))
        {
            ddl_estadoOrigem.Enabled = true;
            ddl_cidadeOrigem.Enabled = true;
            txt_bairroOrigem.Enabled = true;
            txt_ruaOrigem.Enabled    = true;

            txt_ruaOrigem.Text    = "";
            txt_bairroOrigem.Text = "";
        }
    }
Ejemplo n.º 17
0
 /// <summary>
 /// Determines whether this instance [can delete zip code] the specified new zip code.
 /// </summary>
 /// <param name="newZipCode">The new zip code.</param>
 /// <returns>
 ///     <c>true</c> if this instance [can delete zip code] the specified new zip code; otherwise, <c>false</c>.
 /// </returns>
 bool CanDeleteZipCode(ZipCodeInfo newZipCode)
 {
     return(this.SelectedZipCode != null);
 }
Ejemplo n.º 18
0
        private TrieNode <List <ZipCodeInfo> > ParseXMLDatabaseToTrie(string xmlFilePath)
        {
            TrieNode <List <ZipCodeInfo> > header = new TrieNode <List <ZipCodeInfo> >(null);

            XPathDocument  xmlDocument  = new XPathDocument(xmlFilePath);
            XPathNavigator xmlNavigator = xmlDocument.CreateNavigator();

            xmlNavigator.MoveToRoot();

            if (xmlNavigator.HasChildren)
            {
                xmlNavigator.MoveToFirstChild();

                if (xmlNavigator.HasChildren)
                {
                    xmlNavigator.MoveToFirstChild();

                    do
                    {
                        xmlNavigator.MoveToFirstChild();
                        uint zipCode = uint.Parse(xmlNavigator.Value);

                        xmlNavigator.MoveToNext();
                        string cityName = xmlNavigator.Value;

                        xmlNavigator.MoveToNext();
                        string state = xmlNavigator.Value;

                        ZipCodeInfo zipCodeInfo = new ZipCodeInfo(zipCode, cityName, state);

                        TrieNode <List <ZipCodeInfo> > currentNode = header;
                        for (int i = 0; i < cityName.Length; i++)
                        {
                            TrieNode <List <ZipCodeInfo> > findNode = null;
                            if (!currentNode.Children.TryGetValue(cityName[i], out findNode))
                            {
                                if (i == cityName.Length - 1)
                                {
                                    currentNode.Children.Add(cityName[i], new TrieNode <List <ZipCodeInfo> >(new List <ZipCodeInfo> {
                                        zipCodeInfo
                                    }));
                                }
                                else
                                {
                                    findNode = new TrieNode <List <ZipCodeInfo> >(new List <ZipCodeInfo>());
                                    currentNode.Children.Add(cityName[i], findNode);
                                    currentNode = findNode;
                                }
                            }
                            else
                            {
                                if (i == cityName.Length - 1)
                                {
                                    findNode.Value.Add(zipCodeInfo);
                                }
                                else
                                {
                                    currentNode = findNode;
                                }
                            }
                        }

                        xmlNavigator.MoveToParent();
                    }while (xmlNavigator.MoveToNext());
                }
            }

            return(header);
        }