public WebCEP GetCepFromCorreios(WebCEP modelCEP)
        {
            WebCEP _WebCEP = new WebCEP();
            var    ret     = _WebCEP.GetCepFromCorreios(modelCEP);

            return(ret);
        }
        private void mtxtCEP_Leave(object sender, EventArgs e)
        {
            WebCEP cep = new WebCEP(mtxtCEP.Text);

            txtStreet.Text   = cep.Logradouro;
            txtDistrict.Text = cep.Bairro;
            txtCity.Text     = cep.Cidade;
            txtState.Text    = cep.UF;
        }
        private void SearchCEP()
        {
            if (!string.IsNullOrWhiteSpace(mktEmployeeCEP.Text))
            {
                WebCEP webCEP = new WebCEP(mktEmployeeCEP.Text);

                txtEmployeeCity.Text     = webCEP.City;
                txtEmployeeStreet.Text   = webCEP.Street;
                txtEmployeeDistrict.Text = webCEP.District;
            }
        }
Beispiel #4
0
        private void btnSearchCEP_Click(object sender, EventArgs e)
        {
            if (!validatorSearchCEP.Validate())
            {
                return;
            }

            tfCep.SelectAll();

            try
            {
                if (Util.isConnectedWeb() && (tfCep.EditValue != null && !String.IsNullOrEmpty(tfCep.EditValue.ToString())))
                {
                    SplashScreenManager.ShowForm(desk, typeof(PleaseWaitForm), false, false, false);
                    WebCEP wcep = new WebCEP(tfCep.EditValue.ToString(), WebCEP.TypeCase.Upper);

                    ((address)bdgAddress.Current).state_id = 0;
                    cbStateAddress.EditValue = 0;
                    ((address)bdgAddress.Current).city_id = 0;
                    cbCity.EditValue = 0;
                    ((address)bdgAddress.Current).district = "";
                    tfDistrict.EditValue = "";
                    ((address)bdgAddress.Current).name = "";
                    tfAddress.EditValue = "";

                    if (wcep.RESULTADO == 0)
                    {
                        ((address)bdgAddress.Current).cep = "";
                        tfCep.EditValue = "";

                        SplashScreenManager.CloseForm(false);
                        XtraMessageBox.Show("O CEP informado não foi encontrado!\nVerifique e tente novamente ou informe o endereço manualmente.",
                                            "CADORE TECNOLOGIA");
                        return;
                    }
                    else
                    {
                        state s = state.SingleOrDefault("WHERE symbol ILIKE @0", state.Concat(wcep.UF));
                        if (s != null)
                        {
                            ((address)bdgAddress.Current).state_id = s.id;
                            cbStateAddress.EditValue = s.id;
                        }

                        Console.WriteLine(wcep.CIDADE);
                        city c = city.SingleOrDefault("WHERE remove_character(name) ILIKE remove_character(@0)", city.Concat(wcep.CIDADE));
                        if (c != null)
                        {
                            ((address)bdgAddress.Current).city_id = c.id;
                            cbCity.EditValue = c.id;
                        }

                        if (wcep.RESULTADO == 1)
                        {
                            ((address)bdgAddress.Current).district = wcep.BAIRRO;
                            tfDistrict.EditValue = wcep.BAIRRO;

                            string street = String.Format("{0} {1}", wcep.TIPOLAGRADOURO, wcep.LAGRADOURO);
                            ((address)bdgAddress.Current).name = street;
                            tfAddress.EditValue = street;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(String.Format("Ocorreu um erro\n\n{0}\n{1}", ex.Message, ex.InnerException));
            }
            finally
            {
                SplashScreenManager.CloseForm(false);
            }
        }