feat!: Funcionalidades adicionadas para atualizações automáticas de versão e rolagem dos itens de Empresa e Unidade.
This commit is contained in:
parent
22d308a397
commit
5149d429ab
@ -6,8 +6,19 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UseWPF>true</UseWPF>
|
||||
<ApplicationIcon>marca.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="marca.png" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="marca.ico">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Data.OleDb" Version="9.0.7" />
|
||||
</ItemGroup>
|
||||
@ -15,4 +26,8 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="System.Data.OleDb" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Resource Include="marca.png" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@ -11,74 +11,34 @@ namespace BD_empresa.Data
|
||||
{
|
||||
private readonly string _connectionString = connectionString;
|
||||
|
||||
public async Task<List<ClienteSmart>> SearchClientesAsync(string query)
|
||||
public async Task<List<UnidadeSmart>> GetAllClientesAsync()
|
||||
{
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
var clientes = new List<ClienteSmart>();
|
||||
var unidades = new List<UnidadeSmart>();
|
||||
using (var connection = new OleDbConnection(_connectionString))
|
||||
{
|
||||
connection.Open();
|
||||
string sql = @"SELECT Gestao, Cliente, Unidade, CNPJ_CPF, Codigo_Instalacao, Razao_Social FROM Dados_cadastrais WHERE CNPJ_CPF LIKE ? OR Codigo_Instalacao LIKE ? OR Razao_Social LIKE ? OR Cliente LIKE ?";
|
||||
string sql = "SELECT Cod_Smart_cliente, Cod_Smart_unidade, Gestao, Cliente, Unidade, CNPJ_CPF, Codigo_Instalacao, Razao_Social, Caminho_NFs FROM Dados_cadastrais";
|
||||
using var cmd = new OleDbCommand(sql, connection);
|
||||
string likeQuery = $"%{query}%";
|
||||
cmd.Parameters.AddWithValue("?", likeQuery);
|
||||
cmd.Parameters.AddWithValue("?", likeQuery);
|
||||
cmd.Parameters.AddWithValue("?", likeQuery);
|
||||
cmd.Parameters.AddWithValue("?", likeQuery);
|
||||
using var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
clientes.Add(new ClienteSmart
|
||||
unidades.Add(new UnidadeSmart
|
||||
{
|
||||
Cod_Smart_cliente = long.Parse(reader["Cod_Smart_cliente"].ToString() ?? "0"),
|
||||
Cod_Smart_unidade = long.Parse(reader["Cod_Smart_unidade"].ToString() ?? "0"),
|
||||
Gestao = reader["Gestao"].ToString(),
|
||||
Cliente = reader["Cliente"].ToString(),
|
||||
Unidade = reader["Unidade"].ToString(),
|
||||
CNPJ_CPF = reader["CNPJ_CPF"].ToString(),
|
||||
Codigo_Instalacao = reader["Codigo_Instalacao"].ToString(),
|
||||
Razao_Social = reader["Razao_Social"].ToString()
|
||||
Razao_Social = reader["Razao_Social"].ToString(),
|
||||
Caminho_NFs = reader["Caminho_NFs"].ToString()
|
||||
});
|
||||
}
|
||||
}
|
||||
// Unifica clientes por CNPJ, retorna no máximo 3
|
||||
return clientes
|
||||
.GroupBy(c => c.CNPJ_CPF)
|
||||
.Select(g => g.First())
|
||||
.Take(3)
|
||||
.ToList();
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<List<ClienteSmart>> GetAllClientesAsync()
|
||||
{
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
var clientes = new List<ClienteSmart>();
|
||||
using (var connection = new OleDbConnection(_connectionString))
|
||||
{
|
||||
connection.Open();
|
||||
string sql = "SELECT Gestao, Cliente, Unidade, CNPJ_CPF, Codigo_Instalacao, Razao_Social FROM Dados_cadastrais";
|
||||
using var cmd = new OleDbCommand(sql, connection);
|
||||
using var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
clientes.Add(new ClienteSmart
|
||||
{
|
||||
Gestao = reader["Gestao"].ToString(),
|
||||
Cliente = reader["Cliente"].ToString(),
|
||||
Unidade = reader["Unidade"].ToString(),
|
||||
CNPJ_CPF = reader["CNPJ_CPF"].ToString(),
|
||||
Codigo_Instalacao = reader["Codigo_Instalacao"].ToString(),
|
||||
Razao_Social = reader["Razao_Social"].ToString()
|
||||
});
|
||||
}
|
||||
}
|
||||
// Unifica clientes por CNPJ
|
||||
return clientes
|
||||
.GroupBy(c => c.CNPJ_CPF)
|
||||
.Select(g => g.First())
|
||||
.Take(3)
|
||||
.ToList();
|
||||
return unidades;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,7 +5,6 @@ namespace BD_empresa.Data
|
||||
{
|
||||
public interface IClienteRepository
|
||||
{
|
||||
Task<List<ClienteSmart>> SearchClientesAsync(string query);
|
||||
Task<List<ClienteSmart>> GetAllClientesAsync();
|
||||
Task<List<UnidadeSmart>> GetAllClientesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,14 +2,17 @@ using System.ComponentModel;
|
||||
|
||||
namespace BD_empresa.Data
|
||||
{
|
||||
public class ClienteSmart : INotifyPropertyChanged
|
||||
public class UnidadeSmart : INotifyPropertyChanged
|
||||
{
|
||||
public long Cod_Smart_cliente { get; set; }
|
||||
public long Cod_Smart_unidade { get; set; }
|
||||
public string? Gestao { get; set; }
|
||||
public string? Cliente { get; set; }
|
||||
public string? Unidade { get; set; }
|
||||
public string? CNPJ_CPF { get; set; }
|
||||
public string? Codigo_Instalacao { get; set; }
|
||||
public string? Razao_Social { get; set; }
|
||||
public string? Caminho_NFs { get; set; }
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
protected void OnPropertyChanged(string propertyName)
|
||||
@ -5,36 +5,57 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:BD_empresa"
|
||||
mc:Ignorable="d"
|
||||
Title="MainWindow" Height="450" Width="800">
|
||||
Title="Pesquisar Unidades" Height="650" Width="800">
|
||||
<Grid>
|
||||
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Orientation="Horizontal" Margin="10" Grid.Row="0">
|
||||
<TextBox Width="400"
|
||||
Margin="0,0,10,0"
|
||||
VerticalAlignment="Center"
|
||||
Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}" />
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid Margin="10" Grid.Row="0" Grid.Column="0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image Source="/marca.png"
|
||||
Grid.Row="0" Grid.Column="0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
Margin="10"
|
||||
Height="50" />
|
||||
<Button Content="Refresh"
|
||||
Margin="10"
|
||||
Grid.Column="1"
|
||||
Command="{Binding RefreshCommand}"
|
||||
VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
<TextBox
|
||||
Margin="0,0,10,0"
|
||||
VerticalAlignment="Center"
|
||||
Grid.Column="2"
|
||||
Text="{Binding SearchEmpresaText, UpdateSourceTrigger=PropertyChanged}" />
|
||||
</Grid>
|
||||
<TextBlock Text="{Binding ErrorMessage}"
|
||||
Foreground="Red"
|
||||
Margin="10,5,10,0"
|
||||
Grid.Row="1"
|
||||
Visibility="{Binding ErrorMessage, Converter={StaticResource StringToVisibilityConverter}}" />
|
||||
<Grid Grid.Row="2">
|
||||
<ListView ItemsSource="{Binding Clientes}" Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Text="Empresas:" Margin="10,0,10,0" FontWeight="Bold" Grid.Row="0"/>
|
||||
<ListView ItemsSource="{Binding Clientes}" Margin="10" SelectedItem="{Binding SelectedCliente, Mode=TwoWay}" Grid.Row="1">
|
||||
<ListView.View>
|
||||
<GridView>
|
||||
<GridViewColumn Header="CNPJ" DisplayMemberBinding="{Binding CNPJ_CPF}" Width="120" />
|
||||
<GridViewColumn Header="Unidade" DisplayMemberBinding="{Binding Codigo_Instalacao}" Width="120" />
|
||||
<GridViewColumn Header="Razão Social" DisplayMemberBinding="{Binding Razao_Social}" Width="200" />
|
||||
<GridViewColumn Header="Nome" DisplayMemberBinding="{Binding Cliente}" Width="200" />
|
||||
<GridViewColumn Header="Gestão" DisplayMemberBinding="{Binding Gestao}" Width="70" />
|
||||
<GridViewColumn Header="Cliente" DisplayMemberBinding="{Binding Cliente}" Width="400" />
|
||||
</GridView>
|
||||
</ListView.View>
|
||||
</ListView>
|
||||
@ -43,5 +64,41 @@
|
||||
<ProgressBar IsIndeterminate="True" Height="30" Width="200" VerticalAlignment="Center" HorizontalAlignment="Center" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid Grid.Row="3">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid Margin="10" Grid.Row="0" Grid.Column="0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBox
|
||||
Margin="0,0,10,0"
|
||||
VerticalAlignment="Center"
|
||||
Grid.Column="2"
|
||||
Text="{Binding SearchUnidadeText, UpdateSourceTrigger=PropertyChanged}" />
|
||||
</Grid>
|
||||
<TextBlock Text="Unidades da empresa selecionada (Duplo-clique para abrir pasta):" Margin="10,0,10,0" FontWeight="Bold" Grid.Row="1"/>
|
||||
<ListView ItemsSource="{Binding UnidadesSelecionadas}" Margin="10" Grid.Row="2">
|
||||
<ListView.View>
|
||||
<GridView>
|
||||
<GridViewColumn Header="Unidade" DisplayMemberBinding="{Binding Unidade}" Width="200" />
|
||||
<GridViewColumn Header="Instalação" DisplayMemberBinding="{Binding Codigo_Instalacao}" Width="120" />
|
||||
<GridViewColumn Header="CNPJ" DisplayMemberBinding="{Binding CNPJ_CPF}" Width="120" />
|
||||
<GridViewColumn Header="Razão Social" DisplayMemberBinding="{Binding Razao_Social}" Width="Auto" />
|
||||
</GridView>
|
||||
</ListView.View>
|
||||
<ListView.ItemContainerStyle>
|
||||
<Style TargetType="ListViewItem">
|
||||
<EventSetter Event="MouseDoubleClick" Handler="UnidadeListView_MouseDoubleClick" />
|
||||
<EventSetter Event="KeyDown" Handler="UnidadeListView_EnterKeyDown" />
|
||||
</Style>
|
||||
</ListView.ItemContainerStyle>
|
||||
</ListView>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Window>
|
||||
@ -24,5 +24,34 @@ namespace BD_empresa
|
||||
var accessService = new Data.AccessService($"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={accessDbPath};Jet OLEDB:Database Password=gds21");
|
||||
DataContext = new ViewModels.MainWindowViewModel(accessService);
|
||||
}
|
||||
|
||||
private void UnidadeListView_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
||||
{
|
||||
if (sender is ListViewItem listViewItem && listViewItem.Content is Data.UnidadeSmart unidade && !string.IsNullOrWhiteSpace(unidade.Caminho_NFs))
|
||||
{
|
||||
try
|
||||
{
|
||||
System.Diagnostics.Process.Start("explorer.exe", unidade.Caminho_NFs);
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Não foi possível abrir a pasta: {ex.Message}", "Erro", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void UnidadeListView_EnterKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Key.Enter && sender is ListViewItem listViewItem && listViewItem.Content is Data.UnidadeSmart unidade && !string.IsNullOrWhiteSpace(unidade.Caminho_NFs))
|
||||
{
|
||||
try
|
||||
{
|
||||
System.Diagnostics.Process.Start("explorer.exe", unidade.Caminho_NFs);
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Não foi possível abrir a pasta: {ex.Message}", "Erro", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -11,22 +11,55 @@ namespace BD_empresa.ViewModels
|
||||
public class MainWindowViewModel : INotifyPropertyChanged
|
||||
{
|
||||
private readonly IClienteRepository _clienteRepository;
|
||||
private string? _searchText;
|
||||
private string? _searchEmpresaText;
|
||||
private string? _searchUnidadeText;
|
||||
private bool _isLoading;
|
||||
private string? _errorMessage;
|
||||
private UnidadeSmart? _selectedCliente;
|
||||
private List<UnidadeSmart> _allUnidades = [];
|
||||
|
||||
public ObservableCollection<ClienteSmart> Clientes { get; } = [];
|
||||
public ObservableCollection<UnidadeSmart> Clientes { get; } = [];
|
||||
public ObservableCollection<UnidadeSmart> UnidadesSelecionadas { get; } = [];
|
||||
|
||||
public string? SearchText
|
||||
public string? SearchEmpresaText
|
||||
{
|
||||
get => _searchText;
|
||||
get => _searchEmpresaText;
|
||||
set
|
||||
{
|
||||
if (_searchText != value)
|
||||
if (_searchEmpresaText != value)
|
||||
{
|
||||
_searchText = value;
|
||||
_searchEmpresaText = value;
|
||||
OnPropertyChanged();
|
||||
_ = SearchAsync();
|
||||
FiltrarClientes();
|
||||
AtualizarUnidadesSelecionadas();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string? SearchUnidadeText
|
||||
{
|
||||
get => _searchUnidadeText;
|
||||
set
|
||||
{
|
||||
if (_searchUnidadeText != value)
|
||||
{
|
||||
_searchUnidadeText = value;
|
||||
OnPropertyChanged();
|
||||
AtualizarUnidadesSelecionadas();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public UnidadeSmart? SelectedCliente
|
||||
{
|
||||
get => _selectedCliente;
|
||||
set
|
||||
{
|
||||
if (_selectedCliente != value)
|
||||
{
|
||||
_selectedCliente = value;
|
||||
OnPropertyChanged();
|
||||
AtualizarUnidadesSelecionadas();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -52,32 +85,55 @@ namespace BD_empresa.ViewModels
|
||||
_ = RefreshAsync();
|
||||
}
|
||||
|
||||
public async Task SearchAsync()
|
||||
private void FiltrarClientes()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(SearchText))
|
||||
{
|
||||
await RefreshAsync();
|
||||
return;
|
||||
}
|
||||
IsLoading = true;
|
||||
ErrorMessage = null;
|
||||
try
|
||||
{
|
||||
var results = await _clienteRepository.SearchClientesAsync(SearchText);
|
||||
Clientes.Clear();
|
||||
foreach (var cliente in results)
|
||||
ErrorMessage = null;
|
||||
var _search = SearchEmpresaText;
|
||||
if (string.IsNullOrWhiteSpace(_search))
|
||||
{
|
||||
_search = string.Empty;
|
||||
}
|
||||
var filtrados = _allUnidades
|
||||
.Where(c => (c.CNPJ_CPF?.Contains(_search, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
|| (c.Codigo_Instalacao?.Contains(_search, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
|| (c.Razao_Social?.Contains(_search, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
|| (c.Unidade?.Contains(_search, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
|| (c.Cliente?.Contains(_search, StringComparison.OrdinalIgnoreCase) ?? false))
|
||||
.GroupBy(c => c.Cod_Smart_cliente)
|
||||
.Select(g => g.First())
|
||||
.ToList();
|
||||
foreach (var cliente in filtrados)
|
||||
Clientes.Add(cliente);
|
||||
if (Clientes.Count == 0)
|
||||
ErrorMessage = "Nenhum resultado encontrado.";
|
||||
else
|
||||
SelectedCliente = Clientes.First();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
private void AtualizarUnidadesSelecionadas()
|
||||
{
|
||||
ErrorMessage = $"Erro: {ex.Message}";
|
||||
}
|
||||
finally
|
||||
UnidadesSelecionadas.Clear();
|
||||
ErrorMessage = null;
|
||||
var _search = SearchUnidadeText;
|
||||
if (string.IsNullOrWhiteSpace(_search))
|
||||
{
|
||||
IsLoading = false;
|
||||
_search = "";
|
||||
}
|
||||
var cliente = SelectedCliente;
|
||||
if (Clientes.Count > 0)
|
||||
{
|
||||
cliente ??= Clientes.First();;
|
||||
var unidades = _allUnidades.Where(c => c.Cod_Smart_cliente == cliente.Cod_Smart_cliente)
|
||||
.Where(c => (c.CNPJ_CPF?.Contains(_search, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
|| (c.Codigo_Instalacao?.Contains(_search, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
|| (c.Unidade?.Contains(_search, StringComparison.OrdinalIgnoreCase) ?? false))
|
||||
.ToList();
|
||||
foreach (var unidade in unidades)
|
||||
UnidadesSelecionadas.Add(unidade);
|
||||
}
|
||||
if (UnidadesSelecionadas.Count == 0)
|
||||
ErrorMessage = "Nenhum resultado encontrado.";
|
||||
}
|
||||
|
||||
public async Task RefreshAsync()
|
||||
@ -87,9 +143,9 @@ namespace BD_empresa.ViewModels
|
||||
try
|
||||
{
|
||||
var results = await _clienteRepository.GetAllClientesAsync();
|
||||
Clientes.Clear();
|
||||
foreach (var cliente in results)
|
||||
Clientes.Add(cliente);
|
||||
_allUnidades = [.. results.OrderBy(u => u.Gestao).ThenBy(c => c.Cliente).ThenBy(g => g.Unidade)];
|
||||
FiltrarClientes();
|
||||
AtualizarUnidadesSelecionadas();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user