Adicionar arquivos de projeto.

This commit is contained in:
Adriano Serighelli 2025-03-28 16:04:12 -03:00
parent 8f5851d9d0
commit 1d19408581
3 changed files with 159 additions and 0 deletions

15
BD_empresa.csproj Normal file
View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0-windows7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Data.OleDb" Version="9.0.3" />
</ItemGroup>
</Project>

25
BD_empresa.sln Normal file
View File

@ -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

119
Program.cs Normal file
View File

@ -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<string> caminhos = new List<string>();
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;
}
}