feat: Migração de app console para WPF

This commit is contained in:
Giuliano Paschoalino 2025-07-31 17:11:05 -03:00
parent 1d19408581
commit f592470406
10 changed files with 81 additions and 201 deletions

63
.gitattributes vendored
View File

@ -1,63 +0,0 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
## Ignore Visual Studio temporary files, build results, and
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

9
App.xaml Normal file
View File

@ -0,0 +1,9 @@
<Application x:Class="BD_empresa.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:BD_empresa"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

14
App.xaml.cs Normal file
View File

@ -0,0 +1,14 @@
using System.Configuration;
using System.Data;
using System.Windows;
namespace BD_empresa
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

10
AssemblyInfo.cs Normal file
View File

@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

View File

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

View File

@ -1,9 +1,9 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.32014.148
VisualStudioVersion = 17.12.35527.113 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BD_empresa", "BD_empresa.csproj", "{AF7C4BDC-57FB-4277-8D9D-4F863B11538E}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BD_empresa", "BD_empresa.csproj", "{8A5C3F7B-3694-45AA-BAF0-5A3A7C2F23D4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -11,15 +11,12 @@ Global
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
{8A5C3F7B-3694-45AA-BAF0-5A3A7C2F23D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8A5C3F7B-3694-45AA-BAF0-5A3A7C2F23D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8A5C3F7B-3694-45AA-BAF0-5A3A7C2F23D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8A5C3F7B-3694-45AA-BAF0-5A3A7C2F23D4}.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

12
MainWindow.xaml Normal file
View File

@ -0,0 +1,12 @@
<Window x:Class="BD_empresa.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BD_empresa"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
</Grid>
</Window>

24
MainWindow.xaml.cs Normal file
View File

@ -0,0 +1,24 @@
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace BD_empresa
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}

View File

@ -1,119 +0,0 @@
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;
}
}