Esempio n. 1
0
        private void ListaImovelButton_Click(object sender, EventArgs e)
        {
            ImovelForm fImovel = new ImovelForm();

            fImovel.Imoveis = _Imoveis;
            if (fImovel.ShowDialog() == DialogResult.OK)
            {
                ImovelDTO imovel = fImovel.Imovel;
                if (imovel != null)
                {
                    AdicionarAba(fImovel.Imovel);
                }
            }
        }
Esempio n. 2
0
        private void AdicionarAba(ImovelDTO imovel, bool doLogin = true)
        {
            TabPage     tab       = new TabPage("OLX(" + imovel.IdImovel.ToString() + ")");
            NavegadorUC navegador = new NavegadorUC();

            navegador.Dock = DockStyle.Fill;
            tab.Controls.Add(navegador);
            BrowserTabs.TabPages.Add(tab);
            BrowserTabs.SelectTab(tab);
            navegador.Usuario = OlxUsuarioText.Text;
            navegador.Senha   = OlxSenhaText.Text;
            navegador.Imovel  = imovel;
            if (doLogin)
            {
                navegador.abrirLoginOlx();
            }
            else
            {
                navegador.abrirInserirOlx();
            }
        }
Esempio n. 3
0
        private void doOlxInserir(ImovelDTO imovel, bool Automatico = true)
        {
            Thread thread = new Thread(() =>
            {
                if (Automatico)
                {
                    this.BeginInvoke((MethodInvoker) delegate
                    {
                        string idTipo    = "1000";
                        StringBuilder js = new StringBuilder();
                        js.AppendLine("if (document.getElementById('" + idTipo + "')) {");
                        js.AppendLine("   var cn = document.getElementById('" + idTipo + "').className;");
                        js.AppendLine("   if (!(cn == 'item item-has-children selected' || cn == 'item item-has-children active'))");
                        js.AppendLine("       document.getElementById('" + idTipo + "').click();");
                        js.AppendLine("}");
                        oBrowser.StringByEvaluatingJavaScriptFromString(js.ToString());
                    });
                    Thread.Sleep(3000);

                    //js.Clear();

                    this.BeginInvoke((MethodInvoker) delegate
                    {
                        string idTipo    = null;
                        StringBuilder js = new StringBuilder();
                        if (string.Compare(_Imovel.Tipo, "Apartamento", true) == 0)
                        {
                            idTipo = "1020";
                        }
                        else if (string.Compare(_Imovel.Tipo, "Casa", true) == 0)
                        {
                            idTipo = "1040";
                        }

                        if (idTipo != null)
                        {
                            js.AppendLine("if (document.getElementById('" + idTipo + "')) {");
                            js.AppendLine("   var cn = document.getElementById('" + idTipo + "').className;");
                            js.AppendLine("   if (!(cn == 'item item-has-children selected' || cn == 'item item-has-children active'))");
                            js.AppendLine("       document.getElementById('" + idTipo + "').click();");
                            js.AppendLine("}");
                            oBrowser.StringByEvaluatingJavaScriptFromString(js.ToString());
                        }
                    });
                    Thread.Sleep(7000);

                    this.BeginInvoke((MethodInvoker) delegate
                    {
                        string idTipo    = "1";
                        StringBuilder js = new StringBuilder();
                        js.AppendLine("if (document.getElementById('" + idTipo + "')) {");
                        js.AppendLine("   var cn = document.getElementById('" + idTipo + "').className;");
                        js.AppendLine("   if (!(cn == 'item item-has-children selected' || cn == 'item item-has-children active'))");
                        js.AppendLine("       document.getElementById('" + idTipo + "').click();");
                        js.AppendLine("}");
                        oBrowser.StringByEvaluatingJavaScriptFromString(js.ToString());
                    });
                    Thread.Sleep(3000);
                }

                this.BeginInvoke((MethodInvoker) delegate
                {
                    StringBuilder js = new StringBuilder();
                    if (imovel.Quartos > 0)
                    {
                        js.AppendLine("if (document.getElementById('rooms'))");
                        switch (imovel.Quartos)
                        {
                        case 1:
                            js.AppendLine("document.getElementById('rooms').selectedIndex = 1;");
                            break;

                        case 2:
                            js.AppendLine("document.getElementById('rooms').selectedIndex = 2;");
                            break;

                        case 3:
                            js.AppendLine("document.getElementById('rooms').selectedIndex = 3;");
                            break;

                        case 4:
                            js.AppendLine("document.getElementById('rooms').selectedIndex = 4;");
                            break;

                        default:
                            js.AppendLine("document.getElementById('rooms').selectedIndex = 5;");
                            break;
                        }
                    }
                    //if (!string.IsNullOrEmpty(GaragensText.Text))
                    //    js.AppendLine("document.getElementById('garage_spaces').value = '" + GaragensText.Text + "';");
                    //if (!string.IsNullOrEmpty(PrecoText.Text))
                    //    js.AppendLine("document.getElementById('price').value = '" + PrecoText.Text + "';");
                    if (!string.IsNullOrEmpty(imovel.Titulo))
                    {
                        string titulo = imovel.Titulo;
                        if (IsAllUpper(titulo))
                        {
                            CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
                            TextInfo textInfo       = cultureInfo.TextInfo;
                            titulo = textInfo.ToTitleCase(titulo.ToLower());
                        }
                        if (!string.IsNullOrEmpty(imovel.Codigo))
                        {
                            titulo = titulo + " - " + imovel.Codigo;
                        }
                        js.AppendLine("if (document.getElementById('subject'))");
                        js.AppendLine("document.getElementById('subject').value = " + JsonConvert.SerializeObject(titulo) + ";");
                    }
                    if (imovel.AreaUtil > 0)
                    {
                        js.AppendLine("if (document.getElementById('size'))");
                        js.AppendLine("document.getElementById('size').value = '" + imovel.AreaUtil.ToString() + "';");
                    }
                    if (imovel.Preco > 0)
                    {
                        js.AppendLine("if (document.getElementById('price'))");
                        js.AppendLine("document.getElementById('price').value = '" + imovel.Preco.ToString() + "';");
                    }

                    /*
                     * if (!string.IsNullOrEmpty(EnderecoText.Text))
                     * {
                     *  js.AppendLine("if (document.getElementById('address'))");
                     *  js.AppendLine("document.getElementById('address').value = '" + EnderecoText.Text + "';");
                     * }
                     */
                    if (imovel.Garagens > 0)
                    {
                        js.AppendLine("if (document.getElementById('garage_spaces'))");
                        js.AppendLine("document.getElementById('garage_spaces').value = '" + imovel.Garagens.ToString() + "';");
                    }

                    if (!string.IsNullOrEmpty(CEPText.Text))
                    {
                        js.AppendLine("if (document.getElementById('zipcode'))");
                        js.AppendLine("document.getElementById('zipcode').value = '" + formatarCep(CEPText.Text) + "';");
                        js.AppendLine("document.getElementById('zipcode').focus();");
                        js.AppendLine("document.getElementById('zipcode').blur();");
                    }
                    oBrowser.StringByEvaluatingJavaScriptFromString(js.ToString());
                });

                if (!string.IsNullOrEmpty(DescricaoText.Text))
                {
                    this.BeginInvoke((MethodInvoker) delegate
                    {
                        StringBuilder js = new StringBuilder();
                        js.AppendLine("if (document.getElementById('body'))");
                        js.Append("document.getElementById('body').value = " + JsonConvert.SerializeObject(DescricaoText.Text) + ";");
                        oBrowser.StringByEvaluatingJavaScriptFromString(js.ToString());
                    });
                }
                _TipoPagina = TipoPaginaEnum.Nenhum;
            });

            thread.Start();
        }
Esempio n. 4
0
        public IList <ImovelDTO> carregarImoveis(byte[] buffer)
        {
            IList <ImovelDTO> imoveis = new List <ImovelDTO>();

            try
            {
                MemoryStream stream = new MemoryStream(buffer);
                XmlDocument  xml    = new XmlDocument();
                xml.Load(stream);
                XmlNodeList userNodes = xml.SelectNodes("//imoveis/imovel");
                ImovelDTO   imovel    = null;
                foreach (XmlNode nodeImovel in userNodes)
                {
                    imovel = new ImovelDTO();
                    foreach (XmlNode node in nodeImovel.ChildNodes)
                    {
                        switch (node.Name)
                        {
                        case "id_imovel":
                            imovel.IdImovel = Convert.ToInt32(node.InnerText);
                            break;

                        case "slug":
                            imovel.Slug = node.InnerText;
                            break;

                        case "codigo":
                            imovel.Codigo = node.InnerText;
                            break;

                        case "negocio":
                            imovel.Negocio = node.InnerText;
                            break;

                        case "titulo":
                            imovel.Titulo = node.InnerText;
                            break;

                        case "tipo":
                            imovel.Tipo = node.InnerText;
                            break;

                        case "cep":
                            imovel.Cep = node.InnerText;
                            break;

                        case "uf":
                            imovel.Uf = node.InnerText;
                            break;

                        case "cidade":
                            imovel.Cidade = node.InnerText;
                            break;

                        case "bairro":
                            imovel.Bairro = node.InnerText;
                            break;

                        case "endereco":
                            imovel.Endereco = node.InnerText;
                            break;

                        case "complemento":
                            imovel.Complemento = node.InnerText;
                            break;

                        case "quartos":
                            imovel.Quartos = Convert.ToInt32(node.InnerText);
                            break;

                        case "suites":
                            imovel.Suites = Convert.ToInt32(node.InnerText);
                            break;

                        case "banheiros":
                            imovel.Banheiros = Convert.ToInt32(node.InnerText);
                            break;

                        case "garagens":
                            imovel.Garagens = Convert.ToInt32(node.InnerText);
                            break;

                        case "area_util":
                            imovel.AreaUtil = Convert.ToDouble(node.InnerText);
                            break;

                        case "preco":
                            imovel.Preco = Convert.ToDouble(node.InnerText);
                            break;

                        case "descricao":
                            imovel.Descricao = node.InnerText;
                            break;

                        case "olx_situacao":
                            imovel.OlxSituacao = (node.InnerText == "1");
                            break;

                        case "fotos":
                            foreach (XmlNode nodeFoto in node.ChildNodes)
                            {
                                imovel.Fotos.Add(nodeFoto.InnerText);
                            }
                            break;
                        }
                    }
                    imoveis.Add(imovel);
                }
            }
            catch (Exception e) {
                MessageBox.Show(e.ToString());
            }
            return(imoveis);
        }