From 1d19408581cca86eae4597c0653caec72c037953 Mon Sep 17 00:00:00 2001 From: Adriano Serighelli Date: Fri, 28 Mar 2025 16:04:12 -0300 Subject: [PATCH] Adicionar arquivos de projeto. --- BD_empresa.csproj | 15 ++++++ BD_empresa.sln | 25 ++++++++++ Program.cs | 119 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 BD_empresa.csproj create mode 100644 BD_empresa.sln create mode 100644 Program.cs diff --git a/BD_empresa.csproj b/BD_empresa.csproj new file mode 100644 index 0000000..d0d136f --- /dev/null +++ b/BD_empresa.csproj @@ -0,0 +1,15 @@ + + + + Exe + net9.0-windows7.0 + enable + enable + x64 + + + + + + + diff --git a/BD_empresa.sln b/BD_empresa.sln new file mode 100644 index 0000000..04ae9b4 --- /dev/null +++ b/BD_empresa.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.32014.148 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BD_empresa", "BD_empresa.csproj", "{AF7C4BDC-57FB-4277-8D9D-4F863B11538E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AF7C4BDC-57FB-4277-8D9D-4F863B11538E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AF7C4BDC-57FB-4277-8D9D-4F863B11538E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AF7C4BDC-57FB-4277-8D9D-4F863B11538E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AF7C4BDC-57FB-4277-8D9D-4F863B11538E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {142A299C-80F0-4D68-B366-3891F4D5C9BB} + EndGlobalSection +EndGlobal diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..a6215e3 --- /dev/null +++ b/Program.cs @@ -0,0 +1,119 @@ +using System.Data.OleDb; +using System.Diagnostics; + +class Download_BD +{ + static void Main() + { + string nome_entrada; + string strQRY; + string[] charsToRemove = new string[] { "@", ",", ".", ";", "'", "-", "/" }; + + nome_entrada = "aaa"; + while (nome_entrada.Length != 0) + { + Console.WriteLine("Digite 'c' - caso que queira pesquisar por CNPJ ou 'u' - caso que queira pesquisar por UC e pressione Enter"); + Console.WriteLine("Para pesquisar por Razao Social/Nome, escreva o nome da empresa a ser procurada (min: 4 digitos) e pressione Enter - deixe em branco para sair:"); + nome_entrada = Console.ReadLine(); + switch (nome_entrada.ToUpper()) + { + case "U": + Console.WriteLine("Digite a UC a ser procurada (completa) e pressione Enter:"); + nome_entrada = Console.ReadLine(); + + if (nome_entrada.Length >= 4) + { + strQRY = "SELECT DISTINCT Gestao, Cliente, razao_social, Caminho_NFs FROM Dados_cadastrais WHERE Codigo_Instalacao = " + "\"" + nome_entrada + "\""; + strQRY += " ORDER BY gestao, cliente, razao_social"; + Acessar_BD(strQRY); + } + break; + + case "C": + Console.WriteLine("Digite o CNPJ a ser procurado (14 dig) e pressione Enter:"); + nome_entrada = Console.ReadLine(); + + foreach (var c in charsToRemove) + { + nome_entrada = nome_entrada.Replace(c, string.Empty); + } + + while (nome_entrada.Length < 14) + { + nome_entrada = "0" + nome_entrada; + } + + strQRY = "SELECT DISTINCT Gestao, Cliente, razao_social, Caminho_NFs FROM Dados_cadastrais WHERE CNPJ_CPF = " + "\"" + nome_entrada + "\""; + strQRY += " ORDER BY gestao, cliente, razao_social"; + //Console.WriteLine(strQRY); + Acessar_BD(strQRY); + break; + + default: + if (nome_entrada.Length >= 4) + { + strQRY = "SELECT DISTINCT Gestao, Cliente, razao_social, Caminho_NFs FROM Dados_cadastrais WHERE Cliente ALike " + "\"" + "%" + nome_entrada + "%" + "\""; + strQRY += " UNION " + " SELECT DISTINCT Gestao, Cliente, razao_social, Caminho_NFs FROM Dados_cadastrais WHERE Razao_social ALike " + "\"" + "%" + nome_entrada + "%" + "\""; + strQRY += " ORDER BY gestao, cliente, razao_social"; + Acessar_BD(strQRY); + } + break; + } + } + Console.WriteLine("Programa encerrado."); + return; + } + static void Acessar_BD(string strSQL) + { + int cont_result; + string prt_str; + int n_pasta; + bool teste_par; + string teste_cli = ""; + + List caminhos = new List(); + + OleDbConnection conn = new("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=X:/Middle/Informativo Setorial/Modelo Word/BD1_dados cadastrais e faturas.accdb;Jet OLEDB:Database Password=gds21"); + conn.Open(); + OleDbCommand tbEmpresas = new(strSQL, conn); + OleDbDataReader reader = tbEmpresas.ExecuteReader(); + + prt_str = "\n" + String.Format("{0,-4} | {1,-8} | {2,-25}| {3,-30}", "N", "Gestao", "Nome cliente", "Razao social"); + cont_result = 0; + while (reader.Read() && cont_result < 11) + { + if (reader["Cliente"].ToString() != teste_cli) + { + teste_cli = reader["Cliente"].ToString(); + cont_result++; + prt_str += "\n" + String.Format("{0,-4} | {1,-8} | {2,-25}| {3,-30}", cont_result, reader["gestao"].ToString(), reader["Cliente"].ToString(), reader["Razao_Social"].ToString()); + caminhos.Add(reader["Caminho_NFs"].ToString()); + } + } + prt_str += "\n\n"; + conn.Close(); + + if (cont_result >= 10) + { + Console.WriteLine("\nForam encontrados mais de {0} resultados para o nome pesquisado, buscou-se por razao social e nome do cliente.\n", cont_result - 1); + Console.WriteLine("Especificar melhor o nome pesquisado para que os resultados possam sem exibidos.\n"); + } + else if (cont_result > 0) + { + Console.WriteLine("\nForam encontrados {0} resultados para os parametros procurados.\n", cont_result); + Console.WriteLine(prt_str); + Console.WriteLine("Digite um numero da lista para acessar a pasta do cliente (só funcionará se possuir acesso):"); + teste_par = Int32.TryParse(Console.ReadLine(), out n_pasta); + if (teste_par && n_pasta <= cont_result) + { + //Console.WriteLine(caminhos[n_pasta - 1]); + Process.Start("explorer.exe", caminhos[n_pasta - 1]); + } + else + { + Console.WriteLine("Numero invalido"); + } + } + return; + } +}