Ejemplo n.º 1
0
        public static void SobStatus()
        {
            Gomnet.Settings();
            Chrome.Initializer();
            Gomnet.Login();

            Chrome.driver.Navigate().GoToUrl(Gomnet.urlConsulta);

            var pastaTrabalho = Gomnet.pasta.Worksheets.First();
            var linhas        = pastaTrabalho.Dimension.End.Row;

            for (int linha = 2; linha <= linhas; linha++)
            {
                string x = pastaTrabalho.Cells[linha, 3].Value.ToString();
                if (x != null)
                {
                    string doisZeros  = Regex.Replace(x, @"\A131|\A100", "00$&");        // Para sobs iniciadas em "100" ou "131", acrescenta dois zeros no início da mesma.
                    string cincoZeros = Regex.Replace(doisZeros, @"\A[1-4]", "00000$&"); // Para sobs iniciadas em 1-4, acrescenta cinco zeros no início da mesma.
                    string sobFinal   = Regex.Split(cincoZeros, @"[\s\.]")[0];           // Delimita espaço quando há duas sobs na mesma célula.

                    try
                    {
                        Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_TextBox_NumSOB")).Clear();
                        var sob = Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_TextBox_NumSOB"));
                        sob.SendKeys(sobFinal);
                        Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_ImageButton_Enviar")).Click();

                        try
                        {
                            var numSob = Chrome.driver.FindElement(By.XPath("//*[@id='ctl00_ContentPlaceHolder1_Gridview_GomNet1']/tbody/tr[2]/td[8][contains(text(), '" + sobFinal + "' )]"));
                            if (numSob.Displayed)
                            {
                                var numSobArquivo    = Chrome.driver.FindElement(By.XPath("//*[@id='ctl00_ContentPlaceHolder1_Gridview_GomNet1']/tbody/tr[2]/td[8]")).Text;
                                var numStatusArquivo = Chrome.driver.FindElement(By.XPath("//*[@id='ctl00_ContentPlaceHolder1_Gridview_GomNet1']/tbody/tr[2]/td[3]")).Text;

                                //using (StreamWriter sw = File.AppendText(Gomnet.OutSobStatus))
                                //{
                                //    sw.WriteLine(numSobArquivo + " " + numStatusArquivo);
                                //}
                                Console.WriteLine(numSobArquivo + numStatusArquivo);
                            }
                        }
                        catch (NoSuchElementException)
                        {
                            Console.WriteLine(sobFinal + " não encontrada.");
                            continue;
                        }
                    }
                    catch (NullReferenceException)
                    {
                        Console.WriteLine("Não há mais sob para verificar...");
                        continue;
                    }
                }
            }
            // Fecha o chromedriver
            Chrome.driver.Close();
        }
Ejemplo n.º 2
0
        public static void VincSupervisor()
        {
            Gomnet.Settings();
            Chrome.Initializer();
            Gomnet.Login();
            Chrome.driver.Navigate().GoToUrl(Gomnet.urlVincSup);
            Console.Clear();
            Console.WriteLine("Linking Supervisors...\n");

            string       line;
            StreamReader file = new StreamReader(Gomnet.InSobSup);

            while ((line = file.ReadLine()) != null)
            {
                Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_TextBox_SOB")).Clear();
                var sob = Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_TextBox_SOB"));
                sob.SendKeys(line);
                Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_ImageButton_Pesquisar")).Click();

                try
                {
                    var supervisor = Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_gridViewTarefas_ctl02_ddlSupervisor"));
                    var opcao      = new SelectElement(supervisor);
                    opcao.SelectByText("MESSIAS JOSE DE FARIA");
                    Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_Button_VincularSupervisor")).Click();
                    Chrome.driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1);
                    try
                    {
                        Chrome.driver.SwitchTo().Alert().Accept();
                        Console.WriteLine(line + " linked");
                    }
                    catch (NoAlertPresentException)
                    {
                        continue;
                    }
                } catch (NoSuchElementException)
                {
                    Console.WriteLine(line + " not linked.");
                    continue;
                }
            }
        }
Ejemplo n.º 3
0
        public static void SobTrabalho()
        {
            Gomnet.Settings();
            Chrome.Initializer();
            Gomnet.Login();

            Chrome.driver.Navigate().GoToUrl(Gomnet.urlConsulta);

            string       line;
            StreamReader file = new StreamReader(Gomnet.InSobTrab);

            while ((line = file.ReadLine()) != null)
            {
                Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_TextBox_NumSOB")).Clear();
                var sob = Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_TextBox_NumSOB"));
                sob.SendKeys(line);
                Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_ImageButton_Enviar")).Click();

                try
                {
                    var numSob = Chrome.driver.FindElement(By.XPath("//*[@id='ctl00_ContentPlaceHolder1_Gridview_GomNet1']/tbody/tr[2]/td[8][contains(text(), '" + line + "' )]"));
                    if (numSob.Displayed)
                    {
                        var numSobArquivo  = Chrome.driver.FindElement(By.XPath("//*[@id='ctl00_ContentPlaceHolder1_Gridview_GomNet1']/tbody/tr[2]/td[8]")).Text;
                        var numTrabArquivo = Chrome.driver.FindElement(By.XPath("//*[@id='ctl00_ContentPlaceHolder1_Gridview_GomNet1']/tbody/tr[2]/td[4]")).Text;

                        using (StreamWriter sw = File.AppendText(Gomnet.OutSobTrab))
                        {
                            sw.WriteLine(numSobArquivo + " " + numTrabArquivo);
                        }
                    }
                }
                catch (NoSuchElementException)
                {
                    Console.WriteLine(line + " not found.");
                    continue;
                }
            }
            // Fecha o chromedriver
            Chrome.driver.Close();
        }
Ejemplo n.º 4
0
        public static void SGD() //TODO: Exibir um bloco de texto para inserção das sobs, além de uma caixa com escolha de data para baixar DWG (mais atual) + SGD (da data específica)
        {
            Gomnet.Settings();
            Chrome.Initializer();
            Gomnet.Login();

            //string month = DateTime.Now.ToString("MM");
            Console.Write("Month Value: ");
            string       month = Console.ReadLine();
            string       line;
            StreamReader file = new StreamReader(Gomnet.InSobSGD);

            while ((line = file.ReadLine()) != null)
            {
                Chrome.driver.Navigate().GoToUrl(Gomnet.urlUpload + line);
                try
                {
                    try
                    {
                        var pdfs = Chrome.driver.FindElements(By.PartialLinkText("-" + month + "-18")).Count;
                        for (int pdf = 0; pdf < pdfs; pdf++)
                        {
                            Chrome.driver.FindElements(By.PartialLinkText("-" + month + "-18"))[pdf].Click();
                            Gomnet.FechaJanela();
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                }
                catch (NoSuchElementException)
                {
                }
            }
            Console.Write("End of execution.");
        }
Ejemplo n.º 5
0
        public static void GeraPedSAP()
        {
            // TODO: Implementar criação de pedido de materiais no SAP
            // TODO: Alterar quantidade de material solicitado de acordo com valores contidos numa planilha xls. Gerar erro caso a quantidade solicitada seja maior que orçada.
            Gomnet.Settings();
            Chrome.Initializer();
            Gomnet.Login();

            // Abre e lê o arquivo xlsx.
            using (Gomnet.pacoteTrabalho)
            {
                if (Gomnet.pasta.Worksheets.Count > 0)
                {
                    var pastaTrabalho = Gomnet.pasta.Worksheets.First();
                    var linhas        = pastaTrabalho.Dimension.End.Row;

                    for (int linha = 2; linha <= linhas; linha++)
                    {
                        var    cell_in    = (double)pastaTrabalho.Cells[linha, 7].Value;
                        var    cell_fin   = (double)pastaTrabalho.Cells[linha, 8].Value;
                        var    hr_in      = DateTime.FromOADate(cell_in).TimeOfDay.ToString().Split(':');
                        var    hr_fin     = DateTime.FromOADate(cell_fin).TimeOfDay.ToString().Split(':');
                        string x          = pastaTrabalho.Cells[linha, 3].Value.ToString();
                        string doisZeros  = Regex.Replace(x, @"\A131|\A100", "00$&");        // Para sobs iniciadas em "100" ou "131", acrescenta dois zeros no início da mesma.
                        string cincoZeros = Regex.Replace(doisZeros, @"\A[1-4]", "00000$&"); // Para sobs iniciadas em 1-4, acrescenta cinco zeros no início da mesma.
                        string sobFinal   = Regex.Split(cincoZeros, @"[\s\.]")[0];           // Delimita espaço quando há duas sobs na mesma célula.

                        try
                        {
                            Chrome.driver.Navigate().GoToUrl(Gomnet.urlConsulta);
                            var consultaStatusSob = Chrome.driver.FindElement(By.Name("ctl00$ContentPlaceHolder1$TextBox_NumSOB"));
                            consultaStatusSob.SendKeys(sobFinal);
                            Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_ImageButton_Enviar")).Click();

                            IWebElement sobDespachada = Chrome.wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.XPath("/html/body/form/table/tbody/tr[4]/td/div[3]/table/tbody/tr[2]/td[8][contains(text(), '" + sobFinal + "')]")));
                            if (sobDespachada.Displayed)
                            {
                                string numTrab = Chrome.driver.FindElement(By.XPath("//*[@id='ctl00_ContentPlaceHolder1_Gridview_GomNet1']/tbody/tr[2]/td[4]")).Text;
                                Chrome.driver.Navigate().GoToUrl(Gomnet.urlSolicitaMaterial + numTrab);
                                var pedidosLista = new SelectElement(Chrome.driver.FindElement(By.Id("dropNumPedido"))).Options.Count;
                                //var opcoes = pedidosLista.Options.Count;

                                for (var opcao = 1; opcao <= pedidosLista - 1; opcao++)
                                {
                                    var opcoes = new SelectElement(Chrome.driver.FindElement(By.Id("dropNumPedido")));
                                    opcoes.SelectByIndex(opcao);
                                    Chrome.driver.FindElement(By.Id("ImageButton_Enviar")).Click();
                                    System.Threading.Thread.Sleep(2000);
                                    Chrome.wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.Id("GridView_Consulta_ctl02_ImageButton_Enviar_SAP"))).Click();
                                    System.Threading.Thread.Sleep(2000);
                                    try
                                    {
                                        IAlert alert = Chrome.driver.SwitchTo().Alert();
                                        alert.Accept();
                                        System.Threading.Thread.Sleep(2000);
                                        alert.Accept();
                                        System.Threading.Thread.Sleep(2000);
                                        try
                                        {
                                            string retornoPedido = Chrome.driver.FindElement(By.XPath("//*[@id='GridViewSap']/tbody/tr[2]/td[2]")).Text;
                                            Console.WriteLine(sobFinal + " - 00" + opcao.ToString() + " " + retornoPedido + ".");
                                        }
                                        catch (NoSuchElementException)
                                        {
                                            Console.WriteLine(sobFinal + " - Pedido interno 00" + opcao.ToString() + " já existente.");
                                        }
                                    }
                                    catch (NoAlertPresentException)
                                    {
                                        Console.WriteLine(sobFinal + " - Pedido interno 00" + opcao.ToString() + " - verificação necessária.");
                                    }
                                }
                            }
                        }
                        catch (NoSuchElementException e)
                        {
                            Console.WriteLine(e);
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public static void Vistoria()
        {
            Gomnet.Settings();
            Chrome.Initializer();
            Gomnet.Login();

            // Abre e lê o arquivo xlsx.
            using (Gomnet.pacoteTrabalho)
            {
                if (Gomnet.pasta.Worksheets.Count > 0)
                {
                    var pastaTrabalho = Gomnet.pasta.Worksheets.First();
                    var linhas        = pastaTrabalho.Dimension.End.Row;

                    for (int linha = 2; linha <= linhas; linha++)
                    {
                        var    cell_in  = (double)pastaTrabalho.Cells[linha, 7].Value;
                        var    cell_fin = (double)pastaTrabalho.Cells[linha, 8].Value;
                        var    hr_in    = DateTime.FromOADate(cell_in).TimeOfDay.ToString().Split(':');
                        var    hr_fin   = DateTime.FromOADate(cell_fin).TimeOfDay.ToString().Split(':');
                        string x        = pastaTrabalho.Cells[linha, 3].Value.ToString();
                        if (x != null)
                        {
                            string doisZeros  = Regex.Replace(x, @"\A131|\A100", "00$&");        // Para sobs iniciadas em "100" ou "131", acrescenta dois zeros no início da mesma.
                            string cincoZeros = Regex.Replace(doisZeros, @"\A[1-4]", "00000$&"); // Para sobs iniciadas em 1-4, acrescenta cinco zeros no início da mesma.
                            string sobFinal   = Regex.Split(cincoZeros, @"[\s\.]")[0];           // Delimita espaço quando há duas sobs na mesma célula.
                            try
                            {
                                // Verifica o status da Sob antes de programar
                                Chrome.driver.Navigate().GoToUrl(Gomnet.urlConsulta);
                                var consultaStatusSob = Chrome.driver.FindElement(By.Name("ctl00$ContentPlaceHolder1$TextBox_NumSOB"));
                                consultaStatusSob.SendKeys(sobFinal);
                                Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_ImageButton_Enviar")).Click();

                                IWebElement sobDespachada = Chrome.wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.XPath("/html/body/form/table/tbody/tr[4]/td/div[3]/table/tbody/tr[2]/td[8][contains(text(), '" + sobFinal + "')]")));
                                if (sobDespachada.Displayed)
                                {
                                    // Se o status for diferente de "Vistoria", informa a sob já programada e pula para a próxima. Do contrário, acessa a página referente à programação para dar prosseguimento.
                                    string statusSob = Chrome.driver.FindElement(By.XPath("//*[@id='ctl00_ContentPlaceHolder1_Gridview_GomNet1']/tbody/tr[2]/td[3]")).Text;
                                    if (statusSob != "Vistoria")
                                    {
                                        Console.WriteLine(sobFinal + " já programada.");
                                        continue;
                                    }
                                    else
                                    {
                                        //Acessa a página de programação
                                        Chrome.driver.Navigate().GoToUrl(Gomnet.urlProgObraVist);
                                        var sob = Chrome.driver.FindElement(By.Name("ctl00$ContentPlaceHolder1$TextBox_NumSOB"));
                                        // Envia a variável apenas quando há dados na célula, do contrário, informa que não há mais Sobs.
                                        try
                                        {
                                            sob.SendKeys(sobFinal);
                                        }
                                        catch (NullReferenceException)
                                        {
                                            // Se não houver mais célula com dados na Programação Filtrada, informa a mensagem abaixo e finaliza o programa.
                                            Console.WriteLine("Não há mais nada a programar.");
                                            break;
                                        }
                                        Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_ImageButton_Enviar")).Click();
                                        // Reconhece a linha onde foi despachado para a COMPEL, através do XPATH, e clica no ícone de programação da mesma. Se não houver, retorna a sob com erro.
                                        try
                                        {
                                            IWebElement parceiraCompel = Chrome.wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.XPath("//*[text() = 'COMPEL CONSTRUÇÕES MONTAGENS E']/following::td[17]")));
                                            if (parceiraCompel.Displayed)
                                            {
                                                parceiraCompel.Click();
                                            }
                                        }
                                        catch (WebDriverTimeoutException)
                                        {
                                            Console.WriteLine(sobFinal + " não há registro. Favor verificar.");
                                            continue;
                                        }

                                        //Insere o valor da variável na textbox utilizando Javascript, otimizando a velocidade de exdecução
                                        IWebElement turma = Chrome.driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_txtBoxTurma"));
                                        Chrome.js.ExecuteScript("arguments[0].value = 'COMP12'", turma);

                                        IWebElement servico = Chrome.driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_txtBoxRespServico"));
                                        Chrome.js.ExecuteScript("arguments[0].value = 'A3279'", servico);

                                        IWebElement servicoSup = Chrome.driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_txtBoxServicoSuplente"));
                                        Chrome.js.ExecuteScript("arguments[0].value = 'A3279'", servicoSup);

                                        IWebElement dataInicial = Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_Control_DataHora_InicioPrevisto_TextBox6"));
                                        Chrome.js.ExecuteScript("arguments[0].value = '" + DateTime.Now.ToString("dd/MM/yyyy ").ToString() + hr_in[0] + ":" + hr_in[1] + "'", dataInicial);

                                        IWebElement dataFinal = Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_Control_DataHora_TerminoPrevisto_TextBox6"));
                                        Chrome.js.ExecuteScript("arguments[0].value = '" + DateTime.Now.ToString("dd/MM/yyyy ").ToString() + hr_fin[0] + ":" + hr_fin[1] + "'", dataFinal);

                                        // Adiciona técnicos à tarefa
                                        Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_imgBtnGravarTecnicos")).Click();
                                        Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_gridViewTecnicos_ctl01_ChkBoxAll")).Click();
                                        Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_Button1")).Click();
                                        Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_btnVoltar")).Click();

                                        // Identifica o menu "Tipo de Programação" e seleciona a opção "Execução de Obra" utilizando Javascript
                                        IWebElement tipoProg = Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_DropDownList_TipoProgramacao"));
                                        Chrome.js.ExecuteScript("arguments[0].value = 'N'", tipoProg);

                                        // Identifica o menu "Necessita Linha Viva" e seleciona a opção "Não" utilizando Javascript
                                        IWebElement linhaViva = Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_DropDownList_linhaViva"));
                                        Chrome.js.ExecuteScript("arguments[0].value = 'N'", linhaViva);

                                        // Identifica o menu "Necessita Desligamento" e seleciona a opção "Não" utilizando Javascript
                                        IWebElement desliga = Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_DropDownList_Desliga"));
                                        Chrome.js.ExecuteScript("arguments[0].value = 'N'", desliga);

                                        // Clica no botão "Programar"
                                        Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_Button_ProgramarTarefa")).Click();

                                        // Preenche o campo "Atividade" com o número da SOB utilizando Javascript
                                        IWebElement atividade = Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_txtBoxAtividade"));

                                        // atividade.send_keys(sob_tratada)
                                        Chrome.js.ExecuteScript("arguments[0].value = '" + sobFinal + "'", atividade);

                                        // Identifica o menu "Horas" e insere o valor "01" utilizando Javascript
                                        IWebElement hora = Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_DropDownList_Hora"));
                                        Chrome.js.ExecuteScript("arguments[0].value = '01'", hora);

                                        // Identifica o menu "Minutos" e insere o valor "00" utilizando Javascript
                                        IWebElement minuto = Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_DropDownList_Minuto"));
                                        Chrome.js.ExecuteScript("arguments[0].value = '00'", minuto);

                                        // Identifica o menu "Viagem" e insere o valor "Não" utilizando Javascript
                                        IWebElement viagem = Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_DropDownList_Viagem"));
                                        Chrome.js.ExecuteScript("arguments[0].value = 'N'", viagem);

                                        // Clica no botão "Adicionar Programação"
                                        Chrome.driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_btnAdicionarProgramacao")).Click();

                                        // Insere pelo menos um baremo/material e confirma a programação
                                        foreach (var valor in BaremosModelo.baremo.Zip(BaremosModelo.qtd, Tuple.Create))
                                        {
                                            try
                                            {
                                                IWebElement bar    = Chrome.driver.FindElement(By.XPath("*//tr/td[contains(text(), '" + valor.Item1 + "')]/preceding-sibling::td/input"));
                                                IWebElement barQtd = Chrome.driver.FindElement(By.XPath("*//tr/td[text() = '" + valor.Item1 + "']/following::td[2]/input[@type='text']"));
                                                if (bar.Displayed)
                                                {
                                                    bar.Click();
                                                    barQtd.Clear();
                                                    barQtd.SendKeys(valor.Item2);
                                                    break;
                                                }
                                            }
                                            catch (NoSuchElementException)
                                            {
                                                continue;
                                            }
                                            continue;
                                        }
                                        // Ao fim do loop de inserção de baremos, clica no botão "registrar programação"
                                        //Chrome.driver.FindElement(By.XPath("//*[@id='ctl00_ContentPlaceHolder1_btnEnviarItens']")).Click();
                                        Console.WriteLine(sobFinal + " programada com êxito.");
                                    }
                                }
                            }
                            catch (WebDriverTimeoutException)
                            {
                                Console.WriteLine(sobFinal + " ainda não vistoriada. Impossível programá-la.");
                                continue;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public static void Arquivos()
        {
            Gomnet.Settings();
            Chrome.Initializer();
            Gomnet.Login();

            var files = Directory.GetFiles(Gomnet.folder, "*.*", SearchOption.TopDirectoryOnly)
                        .Where(s => s.EndsWith(".pdf") || s.EndsWith(".PDF"));

            foreach (string file in files)
            {
                string f   = Path.GetFileNameWithoutExtension(file);
                string ext = Path.GetExtension(file);
                if (f.StartsWith("SG_QUAL_"))
                {
                    var s2        = file.Split('_');
                    var s3        = String.Join("_", s2.Skip(1).Take(3));
                    int lastIndex = s3.LastIndexOf('_');
                    if (Char.IsDigit(s3[lastIndex + 1]))
                    {
                        string result = s3.Remove(lastIndex, "_".Length).Insert(lastIndex, "-");
                        Chrome.driver.Navigate().GoToUrl(Gomnet.urlUpload + result);
                    }
                    else
                    {
                        Chrome.driver.Navigate().GoToUrl(Gomnet.urlUpload + String.Join("_", s2.Skip(1).Take(2)));
                    }
                }
                else if (f.StartsWith("SG_REF") || f.StartsWith("SG_QUAL") || f.StartsWith("SG_INTER") || f.StartsWith("SG_RNT"))
                {
                    var s2 = file.Split('_');
                    Chrome.driver.Navigate().GoToUrl(Gomnet.urlUpload + String.Join("_", s2.Skip(1).Take(2)));
                }
                else if (f.StartsWith("SG_PQ"))
                {
                    var s2 = file.Split('_');
                    Chrome.driver.Navigate().GoToUrl(Gomnet.urlUpload + String.Join("_", s2.Skip(1).Take(3)));
                }
                else if (f.StartsWith("SG_RRC_"))
                {
                    var s2 = file.Split('_');
                    Chrome.driver.Navigate().GoToUrl(Gomnet.urlUpload + String.Join("_", s2.Skip(1).Take(2)));
                }
                else if (f.StartsWith("SG_RRC"))
                {
                    var s2 = file.Split('_');
                    Chrome.driver.Navigate().GoToUrl(Gomnet.urlUpload + String.Join("_", s2.Skip(1).Take(2)).Replace("_", "-"));
                }
                else if (f.StartsWith("SG_"))
                {
                    var s2 = file.Split('_');
                    Chrome.driver.Navigate().GoToUrl(Gomnet.urlUpload + String.Join("_", s2.Skip(1).Take(1)));
                }

                try //Verifica se a sob foi digitada corretamente
                {
                    var erro = Chrome.driver.FindElement(By.XPath("*//tr/td[contains(text(), 'Não existem dados para serem exibidos.')]"));
                    if (erro.Displayed)
                    {
                        Console.WriteLine("{0} not found.", f);
                    }
                }
                catch (NoSuchElementException)
                {
                    try //Verifica se o arquivo já foi anexado
                    {
                        var anexo = Chrome.driver.FindElement(By.XPath("*//a[contains(text(), '" + f + "')]"));
                        if (anexo.Displayed)
                        {
                            Console.WriteLine("{0} already attached. ", f);
                        }
                    }
                    catch (NoSuchElementException)
                    {
                        if (f.Contains("FORM_FISC"))
                        {
                            SelectElement selectCat = new SelectElement(Chrome.driver.FindElement(By.Id("drpCategoria")));
                            selectCat.SelectByText("ENCERRAMENTO");
                            SelectElement selectDoc = new SelectElement(Chrome.driver.FindElement(By.Id("DropDownList1")));
                            selectDoc.SelectByText("FORMULARIO DE FISCALIZACAO DE OBRA");
                        }
                        else if (f.Contains("AS_BUILT"))
                        {
                            SelectElement selectCat = new SelectElement(Chrome.driver.FindElement(By.Id("drpCategoria")));
                            selectCat.SelectByText("ENCERRAMENTO");
                            SelectElement selectDoc = new SelectElement(Chrome.driver.FindElement(By.Id("DropDownList1")));
                            selectDoc.SelectByText("AS BUILT");
                        }
                        else if (f.Contains("APOIO_TRANSITO"))
                        {
                            SelectElement selectCat = new SelectElement(Chrome.driver.FindElement(By.Id("drpCategoria")));
                            selectCat.SelectByText("PROJETO");
                            SelectElement selectDoc = new SelectElement(Chrome.driver.FindElement(By.Id("DropDownList1")));
                            selectDoc.SelectByText("CARTAS/OFICIOS");
                        }
                        else if (f.Contains("CCR"))
                        {
                            SelectElement selectCat = new SelectElement(Chrome.driver.FindElement(By.Id("drpCategoria")));
                            selectCat.SelectByText("PROJETO");
                            SelectElement selectDoc = new SelectElement(Chrome.driver.FindElement(By.Id("DropDownList1")));
                            selectDoc.SelectByText("CARTAS/OFICIOS");
                        }
                        else if (f.Contains("_SGD_"))
                        {
                            SelectElement selectCat = new SelectElement(Chrome.driver.FindElement(By.Id("drpCategoria")));
                            selectCat.SelectByText("EXECUCAO");
                            SelectElement selectDoc = new SelectElement(Chrome.driver.FindElement(By.Id("DropDownList1")));
                            selectDoc.SelectByText("SGD/TET");
                        }
                        else if (f.Contains("CLIENTE_VITAL"))
                        {
                            SelectElement selectCat = new SelectElement(Chrome.driver.FindElement(By.Id("drpCategoria")));
                            selectCat.SelectByText("PROJETO");
                            SelectElement selectDoc = new SelectElement(Chrome.driver.FindElement(By.Id("DropDownList1")));
                            selectDoc.SelectByText("CARTAS/OFICIOS");
                        }
                        else if (f.Contains("_LOCACAO_") || f.Contains("_APR_") || f.Contains("_DESENHO_"))
                        {
                            SelectElement selectCat = new SelectElement(Chrome.driver.FindElement(By.Id("drpCategoria")));
                            selectCat.SelectByText("EXECUCAO");
                            SelectElement selectDoc = new SelectElement(Chrome.driver.FindElement(By.Id("DropDownList1")));
                            selectDoc.SelectByText("LOCACAO");
                        }
                        else
                        {
                            SelectElement selectCat = new SelectElement(Chrome.driver.FindElement(By.Id("drpCategoria")));
                            selectCat.SelectByText("EXECUCAO");
                            SelectElement selectDoc = new SelectElement(Chrome.driver.FindElement(By.Id("DropDownList1")));
                            selectDoc.SelectByText("PONTO DE SERVICO");
                        }
                        try
                        {
                            // Anexa o arquivo e clica no botão "Enviar..."
                            Chrome.driver.FindElement(By.Id("fileUPArquivo")).SendKeys(Gomnet.folder + @"\" + f + ext);
                            Chrome.driver.FindElement(By.Id("Button_Anexar")).Click();
                        }
                        catch (System.InvalidOperationException)
                        {
                            Console.WriteLine("{0} not found in folder.", f);
                            continue;
                        }
                        try
                        {
                            var status = Chrome.driver.FindElement(By.XPath("*//a[contains(text(), '" + f + ext + "')]"));
                            if (status.Displayed)
                            {
                                Console.WriteLine("File {0}  attached sucessfully.", f);
                                Screenshot ss = ((ITakesScreenshot)Chrome.driver).GetScreenshot();
                                ss.SaveAsFile(f + ".png", ScreenshotImageFormat.Tiff);
                            }
                        }
                        catch (NoSuchElementException)
                        {
                            using (StreamWriter sw = File.AppendText(Gomnet.OutUpload))
                            {
                                sw.WriteLine(f);
                                sw.Close();
                            }
                        }
                    }
                }
            }
            //driver.Close();
            Console.ReadKey();
        }
Ejemplo n.º 8
0
        public static void DWG()
        {
            Gomnet.Settings();
            Chrome.Initializer();
            Gomnet.Login();

            string       line;
            StreamReader file = new StreamReader(Gomnet.InSobDWG);

            while ((line = file.ReadLine()) != null)
            {
                Chrome.driver.Navigate().GoToUrl(Gomnet.urlUpload + line);
                try //Busca pela versão mais atual do DWG da Sob
                {
                    try
                    {
                        var rev_09 = Chrome.driver.FindElement(By.PartialLinkText("REV.09.dwg"));
                        if (rev_09.Displayed)
                        {
                            rev_09.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var rev_08 = Chrome.driver.FindElement(By.PartialLinkText("REV.08.dwg"));
                        if (rev_08.Displayed)
                        {
                            rev_08.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var rev_07 = Chrome.driver.FindElement(By.PartialLinkText("REV.07.dwg"));
                        if (rev_07.Displayed)
                        {
                            rev_07.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var rev_06 = Chrome.driver.FindElement(By.PartialLinkText("REV.06.dwg"));
                        if (rev_06.Displayed)
                        {
                            rev_06.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var rev_05 = Chrome.driver.FindElement(By.PartialLinkText("REV.05.dwg"));
                        if (rev_05.Displayed)
                        {
                            rev_05.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var rev_04 = Chrome.driver.FindElement(By.PartialLinkText("REV.04.dwg"));
                        if (rev_04.Displayed)
                        {
                            rev_04.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var rev_03 = Chrome.driver.FindElement(By.PartialLinkText("REV.03.dwg"));
                        if (rev_03.Displayed)
                        {
                            rev_03.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var rev_02 = Chrome.driver.FindElement(By.PartialLinkText("REV.02.dwg"));
                        if (rev_02.Displayed)
                        {
                            rev_02.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var rev_01 = Chrome.driver.FindElement(By.PartialLinkText("REV.01.dwg"));
                        if (rev_01.Displayed)
                        {
                            rev_01.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var revObra9 = Chrome.driver.FindElement(By.PartialLinkText("REVOBRA_09.dwg"));
                        if (revObra9.Displayed)
                        {
                            revObra9.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var revObra8 = Chrome.driver.FindElement(By.PartialLinkText("REVOBRA_08.dwg"));
                        if (revObra8.Displayed)
                        {
                            revObra8.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var revObra7 = Chrome.driver.FindElement(By.PartialLinkText("REVOBRA_07.dwg"));
                        if (revObra7.Displayed)
                        {
                            revObra7.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var revObra6 = Chrome.driver.FindElement(By.PartialLinkText("REVOBRA_06.dwg"));
                        if (revObra6.Displayed)
                        {
                            revObra6.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var revObra5 = Chrome.driver.FindElement(By.PartialLinkText("REVOBRA_05.dwg"));
                        if (revObra5.Displayed)
                        {
                            revObra5.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var revObra4 = Chrome.driver.FindElement(By.PartialLinkText("REVOBRA_04.dwg"));
                        if (revObra4.Displayed)
                        {
                            revObra4.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var revObra3 = Chrome.driver.FindElement(By.PartialLinkText("REVOBRA_03.dwg"));
                        if (revObra3.Displayed)
                        {
                            revObra3.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var revObra2 = Chrome.driver.FindElement(By.PartialLinkText("REVOBRA_02.dwg"));
                        if (revObra2.Displayed)
                        {
                            revObra2.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var revObra1 = Chrome.driver.FindElement(By.PartialLinkText("REVOBRA_01.dwg"));
                        if (revObra1.Displayed)
                        {
                            revObra1.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var revObra = Chrome.driver.FindElement(By.PartialLinkText("REVOBRA.dwg"));
                        if (revObra.Displayed)
                        {
                            revObra.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var rev9 = Chrome.driver.FindElement(By.PartialLinkText("REV09.dwg"));
                        if (rev9.Displayed)
                        {
                            rev9.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var rev8 = Chrome.driver.FindElement(By.PartialLinkText("REV08.dwg"));
                        if (rev8.Displayed)
                        {
                            rev8.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var rev7 = Chrome.driver.FindElement(By.PartialLinkText("REV07.dwg"));
                        if (rev7.Displayed)
                        {
                            rev7.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var rev6 = Chrome.driver.FindElement(By.PartialLinkText("REV06.dwg"));
                        if (rev6.Displayed)
                        {
                            rev6.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var rev5 = Chrome.driver.FindElement(By.PartialLinkText("REV05.dwg"));
                        if (rev5.Displayed)
                        {
                            rev5.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var rev4 = Chrome.driver.FindElement(By.PartialLinkText("REV04.dwg"));
                        if (rev4.Displayed)
                        {
                            rev4.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var rev3 = Chrome.driver.FindElement(By.PartialLinkText("REV03.dwg"));
                        if (rev3.Displayed)
                        {
                            rev3.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var rev2 = Chrome.driver.FindElement(By.PartialLinkText("REV02.dwg"));
                        if (rev2.Displayed)
                        {
                            rev2.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var rev1 = Chrome.driver.FindElement(By.PartialLinkText("REV01.dwg"));
                        if (rev1.Displayed)
                        {
                            rev1.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                    try
                    {
                        var dwg = Chrome.driver.FindElement(By.PartialLinkText("dwg"));
                        if (dwg.Displayed)
                        {
                            dwg.Click();
                            Gomnet.FechaJanela();
                            continue;
                        }
                    }
                    catch (NoSuchElementException)
                    {
                    }
                }
                catch (NoSuchElementException)
                {
                }
            }
            Console.WriteLine("End of execution.");
        }