Exemple #1
0
        public Form1()
        {
            InitializeComponent();

#if DEBUG
            txtUserRCB.Text    = "FL47250";
            txtPassRCB.Text    = "BANCO@30";
            txtUserCICS.Text   = "x208430";
            txtPassCICS.Text   = "amor2525";
            txtUserSISCOB.Text = "301";
            txtPassSISCOB.Text = "flex2019";
#endif
            KillProcess("3CXPhone");
            KillProcess("cobdesk");
            WebDriverExtensions.KillChrome();
            UserCICSText = txtUserCICS.Text;
            PassCICSText = txtPassCICS.Text;

            //WebServiceSiscob.CallWebService();

            //Thread.Sleep(30000);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Qtdparc = listView1.CheckedItems.Count
                      | listView2.CheckedItems.Count
                      | listView3.CheckedItems.Count
                      | listView4.CheckedItems.Count
                      | listView5.CheckedItems.Count;


            if (Qtdparc > 0 && !String.IsNullOrEmpty(Tabulacao.Text) && !String.IsNullOrEmpty(ADDDEMO.Text) &&
                !String.IsNullOrEmpty(cmbMotivo.Text) && !String.IsNullOrEmpty(cmbMotivo.Text))
            {
                //    MessageBox.Show(
                //    "É necessário selecionar as parcelas para finalizar o acordo!!!",
                //    "Facilita",
                //    MessageBoxButtons.OK,
                //    MessageBoxIcon.Warning
                //    );

                //}
                //else
                //{



                //tabulacao CANC
                //populaTabulacaoCANC(contrato);

                //tabulação CTA - ok
                //populaTabulacaoCTA(contrato);


                DialogResult result1 = MessageBox.Show(
                    "Favor aguardar a finalização do processo automático!!!",
                    "Facilita",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                    );



                // obj form login
                Form1 FormFacilita = Application.OpenForms["Form1"] as Form1;
                FormFacilita.Focus();
                var CNPJ    = FormFacilita.txtCNPJRCB.Text;
                var UserRCB = FormFacilita.txtUserRCB.Text;
                var PassRCB = FormFacilita.txtPassRCB.Text;
                //var txtUserCICS = FormFacilita.txtUserCICS.Text;


                try
                {
                    if (!LoginRCB(CNPJ, UserRCB, PassRCB, ContratoCli.Text, Qtdparc.ToString(), QuitVlTotal.Text, tabControl2.SelectedTab.Text, CalcComissao.Text))
                    {
                        this.Enabled = true;
                        return;
                    }
                    else
                    {
                        //tabulacao CANC
                        //populaTabulacaoCANC(contrato);
                        this.Enabled = true;
                        return;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                    this.Enabled = true;
                    return;
                }
            }
            else
            {
                DialogResult result1 = MessageBox.Show(
                    "Preencha todos os campos e selecione as parcelas antes de continuar!!!",
                    "Facilita"
                    );
            }

            bool LoginRCB(string Cnpj, string UserRcb, string PassRcb, string Contrato, string QtdParcela, string ValorParc, string DataPagamento, string comissao, bool onlyLogin = false)
            {
                WebDriverExtensions.KillDriversAndBrowsers();
                ChromeOptions options = new ChromeOptions();/*FirefoxDriver(@"c:\");*/

                options.AddArguments("no-sandbox");
                options.AddArguments("disable-extensions");
                options.AddAdditionalCapability("useAutomationExtension", false);
                //string chromePath = @"C:\ProgramData\Microsoft\AppV\Client\Integration\8F06C98E - CE78 - 4FCF - B8E3 - 68C443159F3F\Root\VFS\ProgramFilesX86\Google\Chrome\Application\chrome.exe";
                driver = new ChromeDriver(options);

                driver.Url = "https://negocios.santander.com.br/RcbWeb";
                driver.Manage().Window.Maximize();
                driver.Navigate().Refresh();
                WebDriverExtensions.WaitForPageLoad(driver);

                WebDriverWait wait   = new WebDriverWait(driver, TimeSpan.FromSeconds(40));
                WebDriverWait wait1  = new WebDriverWait(driver, TimeSpan.FromSeconds(1));
                WebDriverWait wait5  = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
                WebDriverWait wait10 = new WebDriverWait(driver, TimeSpan.FromSeconds(10));


                wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("_id35:_id48")));
                driver.FindElement(By.Id("_id35:_id48")).SendKeys(Cnpj);
                Thread.Sleep(200);

                wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("_id35:_id52")));
                driver.FindElement(By.Id("_id35:_id52")).SendKeys(UserRcb);
                Thread.Sleep(200);

                wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Name("_id35:_id56")));
                driver.FindElement(By.Name("_id35:_id56")).SendKeys(PassRcb);
                Thread.Sleep(200);

                //js.ExecuteScript("iceSubmit(form,this,event);return false;");
                SendKeys.SendWait("{ENTER}");

                try
                {
                    // continua se estiver ja logado

                    wait5.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("_id411:_id431")));
                    IWebElement btconfirmar = driver.FindElement(By.Id("_id411:_id431"));
                    btconfirmar.Click();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }

                try
                {
                    //erro usuario ou senha
                    wait5.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Name("_id70:_id95")));
                    IWebElement btok = driver.FindElement(By.Name("_id70:_id95"));
                    Thread.Sleep(200);
                    driver.Close();
                    Logger.LoginRCBError();

                    DialogResult result2 = MessageBox.Show("ERRO SENHA NÃO CONFERE.", "Facilita", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    //Thread.Sleep(500);
                    return(false);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);

                    //inclusão acordo contrato valor e parcelas

                    var acordos = wait5.Until(ExpectedConditions.ElementExists(By.Id("mnu1:_id52")));
                    //IWebElement acordos = driver.FindElement(By.Id("mnu1:_id52"));
                    acordos.Click();

                    var inclusao = wait5.Until(ExpectedConditions.ElementExists(By.Id("mnu1:_id55")));
                    //IWebElement inclusao = driver.FindElement(By.Id("mnu1:_id55"));
                    inclusao.Click();
                    Thread.Sleep(200);

                    // pendente cta valores no mockup
                    var contrato = wait.Until(ExpectedConditions.ElementExists(By.Id("form:num_contrato")));
                    //driver.FindElement(By.Id("form:num_contrato")).SendKeys(Contrato);
                    contrato.SendKeys(Contrato);
                    Thread.Sleep(200);

                    var parcelas = wait.Until(ExpectedConditions.ElementExists(By.Id("form:qtd_parcelas_acordo")));
                    //driver.FindElement(By.Id("form:qtd_parcelas_acordo")).SendKeys(QtdParcela);
                    parcelas.SendKeys("1");
                    Thread.Sleep(200);

                    bool recalc = false;

                    do
                    {
                        recalc = false;

                        // pendente cta valores no mockup
                        var valor = wait.Until(ExpectedConditions.ElementExists(By.Name("form:valor_acordo")));
                        //driver.FindElement(By.Name("form:valor_acordo")).SendKeys(QuitVlTotal.Text);
                        valor.Clear();
                        valor.SendKeys(QuitVlTotal.Text);
                        Thread.Sleep(200);

                        var rdoAss = wait5.Until(ExpectedConditions.ElementExists(By.Id("form:origem_acordo:_1")));
                        //IWebElement Rbtnass = driver.FindElement(By.Id("form:origem_acordo:_1"));
                        rdoAss.Click();
                        Thread.Sleep(200);

                        String tipoAcordo = cmbTipoAcordo.Text.Trim();

                        String idTipoAcordo = "form:tipo_acordo:_1";

                        if (tipoAcordo.Equals("Quitação"))
                        {
                            idTipoAcordo = "form:tipo_acordo:_1";
                        }
                        else if (tipoAcordo.Equals("Atualização"))
                        {
                            idTipoAcordo = "form:tipo_acordo:_2";
                        }
                        else if (tipoAcordo.Equals("Eventual"))
                        {
                            idTipoAcordo = "form:tipo_acordo:_3";
                        }

                        var rdoAtu = wait5.Until(ExpectedConditions.ElementExists(By.Id(idTipoAcordo)));
                        //IWebElement Rbtnatu = driver.FindElement(By.Id("form:tipo_acordo:_2"));
                        rdoAtu.Click();
                        Thread.Sleep(200);

                        var rdoOut = wait5.Until(ExpectedConditions.ElementExists(By.Id("form:tipo_carteira:_3")));
                        //IWebElement Rbtnout = driver.FindElement(By.Id("form:tipo_carteira:_3"));
                        rdoOut.Click();
                        Thread.Sleep(200);

                        if (calculadora.pencentualDescontoConcedido == 0)
                        {
                            var rdoExcecao = wait5.Until(ExpectedConditions.ElementExists(By.Id("form:ic_excecao:_2")));
                            //IWebElement Rbtnexcecao = driver.FindElement(By.Id("form:ic_excecao:_2"));
                            rdoExcecao.Click();
                            Thread.Sleep(200);
                        }
                        else
                        {
                            var rdoExcecao = wait5.Until(ExpectedConditions.ElementExists(By.Id("form:ic_excecao:_1")));
                            //IWebElement Rbtnexcecao = driver.FindElement(By.Id("form:ic_excecao:_2"));
                            rdoExcecao.Click();
                            Thread.Sleep(200);
                        }

                        var btnContinuar = wait5.Until(ExpectedConditions.ElementExists(By.Id("form:checkAuthBtn_Continuar")));
                        //IWebElement btncont = driver.FindElement(By.Id("form:checkAuthBtn_Continuar"));
                        btnContinuar.Click();

                        // contrato ajuizado sempre não

                        var rdoAjuizado = wait5.Until(ExpectedConditions.ElementExists(By.Id("form:_id110:_2")));
                        //IWebElement Rbtnnao = driver.FindElement(By.Id("form:_id110:_2"));
                        rdoAjuizado.Click();
                        Thread.Sleep(200);

                        WebDriverExtensions.WaitForPageLoad(driver);

                        //Valida GCA

                        var txtGCA      = wait5.Until(ExpectedConditions.ElementExists(By.Id("form:_id131")));
                        var valorGCAWeb = decimal.Parse(txtGCA.Text);
                        txtgca = txtGCA.Text; //para formgcadivergente
                        if (calculadora.GCA != valorGCAWeb)
                        {
                            driver.Manage().Window.Minimize();
                            GCADivergente gca         = new GCADivergente();
                            var           autorizacao = gca.ShowDialog();
                            gca.BringToFront();

                            if (autorizacao == DialogResult.OK)
                            {
                                calculadora.GCA = valorGCAWeb;
                                calcula();

                                var btnVoltar = wait5.Until(ExpectedConditions.ElementExists(By.Id("form:_id162")));
                                btnVoltar.Click();
                                Thread.Sleep(200);

                                recalc = true;
                            }
                        }
                    } while (recalc);

                    driver.Manage().Window.Maximize();
                    Thread.Sleep(200);

                    //data pagamento vencimento
                    var txtDataPagamento = wait.Until(ExpectedConditions.ElementExists(By.Id("form:dataPagamento")));
                    txtDataPagamento.SendKeys(DataPagamento);
                    Thread.Sleep(200);

                    //qtd total parcelas
                    for (int p = 0; p < Qtdparc; p++)
                    {
                        var chkParcela = wait5.Until(ExpectedConditions.ElementExists(By.Id("form:_id139:" + p + ":_id141")));
                        //IWebElement Rbtnparcela = driver.FindElement(By.Id("form:_id139:0:_id141"));
                        chkParcela.Click();
                    }

                    Thread.Sleep(200);
                    var Rbtnnegociar = wait5.Until(ExpectedConditions.ElementExists(By.Id("form:checkAuthBtn_Negociar")));
                    //IWebElement Rbtnnegociar = driver.FindElement(By.Id("form:checkAuthBtn_Negociar"));
                    Rbtnnegociar.Click();


                    // motivo
                    Thread.Sleep(200);
                    wait.Until(ExpectedConditions.ElementExists(By.Id("form:numeroMotivo")));

                    String motivo = cmbMotivo.Text.Trim();

                    driver.FindElement(By.Id("form:numeroMotivo")).SendKeys(motivo);


                    // valor comissao
                    Thread.Sleep(200);
                    wait.Until(ExpectedConditions.ElementExists(By.Id("form:valorComissaoEscob")));
                    driver.FindElement(By.Id("form:valorComissaoEscob")).SendKeys(comissao);

                    //btn gravar acordo
                    Thread.Sleep(200);
                    var Rbtngravar = wait5.Until(ExpectedConditions.ElementExists(By.Id("form:checkAuthBtn_Gravar")));
                    //IWebElement Rbtngravar = driver.FindElement(By.Id("form:checkAuthBtn_Gravar"));
                    Rbtngravar.Click();

                    Thread.Sleep(200);

                    IWebElement element = (IWebElement)
                                          ((IJavaScriptExecutor)driver).ExecuteScript("javascript:window.scrollBy(0,document.body.scrollHeight-150)");


                    //btn confirmar acordo
                    Thread.Sleep(200);
                    var btnConf = wait5.Until(ExpectedConditions.ElementExists(By.Id("_id224:_id244")));
                    btnConf.Click();

                    //tabulação CTA - ok
                    populaTabulacaoCTA(Contrato);
                    //insereHistoricoSiscob();

                    String txtNumAcordo       = wait5.Until(ExpectedConditions.ElementExists(By.Id("form:_id154"))).Text;
                    String txtLinhaDigitalvel = wait5.Until(ExpectedConditions.ElementExists(By.Id("form:_id157"))).Text;

                    if (!txtLinhaDigitalvel.Equals("00000000000000000000000000000000000000000000000"))
                    {
                        WebDriverExtensions.KillDriversAndBrowsers();

                        //driver.Manage().Window.Minimize();
                        LinhaDigitavel formAcord = new LinhaDigitavel();
                        formAcord.Barcode.Text = txtLinhaDigitalvel;
                        formAcord.ShowDialog();
                        formAcord.Activate();
                    }
                    else
                    {
                        //driver.Manage().Window.Minimize();
                        //AcordoRealizado acordRealizado = new AcordoRealizado();
                        //acordRealizado.Show();
                        //acordRealizado.Activate();

                        //driver.Manage().Window.Maximize();

                        //driver.ExecuteScript("var form=formOf(this);form['mnu1:_idcl'].value='mnu1:_id68';return iceSubmit(form,this,event);");

                        var lamina = wait5.Until(ExpectedConditions.ElementExists(By.Id("mnu1:_id66")));
                        //IWebElement acordos = driver.FindElement(By.Id("mnu1:_id52"));
                        lamina.Click();

                        var consulta = wait5.Until(ExpectedConditions.ElementExists(By.Id("mnu1:_id68")));
                        //IWebElement inclusao = driver.FindElement(By.Id("mnu1:_id55"));
                        consulta.Click();
                        Thread.Sleep(200);

                        //Insere num contrato no campo de busca
                        var txtNumContrato = wait5.Until(ExpectedConditions.ElementExists(By.Id("form:num_contrato")));
                        txtNumContrato.Clear();
                        txtNumContrato.SendKeys(Contrato);

                        //Clica botão consultar
                        wait5.Until(ExpectedConditions.ElementExists(By.Id("form:checkAuthBtn_Consultar"))).Click();

                        WebDriverExtensions.WaitForPageLoad(driver);

                        var rows = wait5.Until(ExpectedConditions.ElementExists(By.Id("form:_id136"))).FindElements(By.CssSelector("tr"));

                        foreach (var row in rows)
                        {
                            if (row.Text.Contains(txtNumAcordo))
                            {
                                var cols = row.FindElements(By.CssSelector("td"));
                                cols[0].Click();
                            }
                        }

                        IWebElement btnOk = null;

                        do
                        {
                            btnOk = null;

                            Thread.Sleep(3000);

                            wait5.Until(ExpectedConditions.ElementExists(By.Id("form:checkAuthBtn_ConsultaLamina"))).Click();

                            WebDriverExtensions.WaitForPageLoad(driver);


                            try
                            {
                                btnOk = wait5.Until(ExpectedConditions.ElementExists(By.Id("_id170:_id195")));
                            }
                            catch (Exception)
                            {
                            }

                            if (btnOk != null)
                            {
                                btnOk.Click();
                            }
                        } while (btnOk != null);


                        //WebDriverExtensions.WaitForPageLoad(driver);


                        String txtLinhaDigitalvel2 = wait5.Until(ExpectedConditions.ElementExists(By.Id("form:_id127"))).Text;

                        WebDriverExtensions.KillDriversAndBrowsers();

                        //driver.Manage().Window.Minimize();

                        LinhaDigitavel formAcord = new LinhaDigitavel();
                        formAcord.Barcode.Text = txtLinhaDigitalvel2;
                        formAcord.ShowDialog();
                        formAcord.Activate();
                    }

                    //driver.Manage().Window.Maximize();


                    DialogResult dialogFinal = MessageBox.Show("Finalize o Atendimento no SISCOB", "Facilita", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    if (dialogFinal == DialogResult.OK)
                    {
                        //this.Dispose();
                    }

                    //driver.Close();
                    SiscobFocus();

                    //Siscob.RetornarLigacao();
                }
                return(true);
            }
        }
        bool LoginRCB(string Cnpj, string UserRcb, string PassRcb)
        {
            WebDriverExtensions.KillDriversAndBrowsers();
            ChromeOptions options = new ChromeOptions();/*FirefoxDriver(@"c:\");*/

            options.AddArguments("no-sandbox");
            options.AddArguments("disable-extensions");
            options.AddAdditionalCapability("useAutomationExtension", false);
            //string chromePath = @"C:\ProgramData\Microsoft\AppV\Client\Integration\8F06C98E - CE78 - 4FCF - B8E3 - 68C443159F3F\Root\VFS\ProgramFilesX86\Google\Chrome\Application\chrome.exe";
            driver = new ChromeDriver(options);

            driver.Url = "https://negocios.santander.com.br/RcbWeb";
            driver.Manage().Window.Maximize();
            driver.Navigate().Refresh();
            WebDriverExtensions.WaitForPageLoad(driver);

            WebDriverWait wait   = new WebDriverWait(driver, TimeSpan.FromSeconds(40));
            WebDriverWait wait1  = new WebDriverWait(driver, TimeSpan.FromSeconds(1));
            WebDriverWait wait5  = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
            WebDriverWait wait10 = new WebDriverWait(driver, TimeSpan.FromSeconds(10));


            wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("_id35:_id48")));
            driver.FindElement(By.Id("_id35:_id48")).SendKeys(Cnpj);
            Thread.Sleep(200);

            wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("_id35:_id52")));
            driver.FindElement(By.Id("_id35:_id52")).SendKeys(UserRcb);
            Thread.Sleep(200);

            wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Name("_id35:_id56")));
            driver.FindElement(By.Name("_id35:_id56")).SendKeys(PassRcb);
            Thread.Sleep(200);

            //js.ExecuteScript("iceSubmit(form,this,event);return false;");
            SendKeys.SendWait("{ENTER}");

            try
            {
                // continua se estiver ja logado

                wait5.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("_id411:_id431")));
                IWebElement btconfirmar = driver.FindElement(By.Id("_id411:_id431"));
                btconfirmar.Click();
            }
            catch { }

            try
            {
                //erro usuario ou senha
                wait5.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Name("_id70:_id95")));
                IWebElement btok = driver.FindElement(By.Name("_id70:_id95"));
                Thread.Sleep(500);
                driver.Close();
                Logger.LoginRCBError();

                DialogResult result2 = MessageBox.Show("ERRO SENHA NÃO CONFERE.", "Facilita", MessageBoxButtons.OK, MessageBoxIcon.Error);

                //Thread.Sleep(500);
                return(false);
            }
            catch { return(true); }
        }