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>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<UseWPF>true</UseWPF>
|
<UseWPF>true</UseWPF>
|
||||||
|
<ApplicationIcon>marca.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="marca.png" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="marca.ico">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="System.Data.OleDb" Version="9.0.7" />
|
<PackageReference Include="System.Data.OleDb" Version="9.0.7" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@ -15,4 +26,8 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System.Data.OleDb" />
|
<Reference Include="System.Data.OleDb" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Resource Include="marca.png" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -11,74 +11,34 @@ namespace BD_empresa.Data
|
|||||||
{
|
{
|
||||||
private readonly string _connectionString = connectionString;
|
private readonly string _connectionString = connectionString;
|
||||||
|
|
||||||
public async Task<List<ClienteSmart>> SearchClientesAsync(string query)
|
public async Task<List<UnidadeSmart>> GetAllClientesAsync()
|
||||||
{
|
{
|
||||||
return await Task.Run(() =>
|
return await Task.Run(() =>
|
||||||
{
|
{
|
||||||
var clientes = new List<ClienteSmart>();
|
var unidades = new List<UnidadeSmart>();
|
||||||
using (var connection = new OleDbConnection(_connectionString))
|
using (var connection = new OleDbConnection(_connectionString))
|
||||||
{
|
{
|
||||||
connection.Open();
|
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);
|
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();
|
using var reader = cmd.ExecuteReader();
|
||||||
while (reader.Read())
|
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(),
|
Gestao = reader["Gestao"].ToString(),
|
||||||
Cliente = reader["Cliente"].ToString(),
|
Cliente = reader["Cliente"].ToString(),
|
||||||
Unidade = reader["Unidade"].ToString(),
|
Unidade = reader["Unidade"].ToString(),
|
||||||
CNPJ_CPF = reader["CNPJ_CPF"].ToString(),
|
CNPJ_CPF = reader["CNPJ_CPF"].ToString(),
|
||||||
Codigo_Instalacao = reader["Codigo_Instalacao"].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 unidades;
|
||||||
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();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,6 @@ namespace BD_empresa.Data
|
|||||||
{
|
{
|
||||||
public interface IClienteRepository
|
public interface IClienteRepository
|
||||||
{
|
{
|
||||||
Task<List<ClienteSmart>> SearchClientesAsync(string query);
|
Task<List<UnidadeSmart>> GetAllClientesAsync();
|
||||||
Task<List<ClienteSmart>> GetAllClientesAsync();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,14 +2,17 @@ using System.ComponentModel;
|
|||||||
|
|
||||||
namespace BD_empresa.Data
|
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? Gestao { get; set; }
|
||||||
public string? Cliente { get; set; }
|
public string? Cliente { get; set; }
|
||||||
public string? Unidade { get; set; }
|
public string? Unidade { get; set; }
|
||||||
public string? CNPJ_CPF { get; set; }
|
public string? CNPJ_CPF { get; set; }
|
||||||
public string? Codigo_Instalacao { get; set; }
|
public string? Codigo_Instalacao { get; set; }
|
||||||
public string? Razao_Social { get; set; }
|
public string? Razao_Social { get; set; }
|
||||||
|
public string? Caminho_NFs { get; set; }
|
||||||
|
|
||||||
public event PropertyChangedEventHandler? PropertyChanged;
|
public event PropertyChangedEventHandler? PropertyChanged;
|
||||||
protected void OnPropertyChanged(string propertyName)
|
protected void OnPropertyChanged(string propertyName)
|
||||||
@ -5,36 +5,57 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:local="clr-namespace:BD_empresa"
|
xmlns:local="clr-namespace:BD_empresa"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="MainWindow" Height="450" Width="800">
|
Title="Pesquisar Unidades" Height="650" Width="800">
|
||||||
<Grid>
|
<Grid>
|
||||||
|
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="*" />
|
<RowDefinition Height="*" />
|
||||||
|
<RowDefinition Height="*" />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<StackPanel Orientation="Horizontal" Margin="10" Grid.Row="0">
|
<Grid.ColumnDefinitions>
|
||||||
<TextBox Width="400"
|
<ColumnDefinition Width="*" />
|
||||||
Margin="0,0,10,0"
|
</Grid.ColumnDefinitions>
|
||||||
VerticalAlignment="Center"
|
<Grid Margin="10" Grid.Row="0" Grid.Column="0">
|
||||||
Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}" />
|
<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"
|
<Button Content="Refresh"
|
||||||
|
Margin="10"
|
||||||
|
Grid.Column="1"
|
||||||
Command="{Binding RefreshCommand}"
|
Command="{Binding RefreshCommand}"
|
||||||
VerticalAlignment="Center" />
|
VerticalAlignment="Center" />
|
||||||
</StackPanel>
|
<TextBox
|
||||||
|
Margin="0,0,10,0"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Grid.Column="2"
|
||||||
|
Text="{Binding SearchEmpresaText, UpdateSourceTrigger=PropertyChanged}" />
|
||||||
|
</Grid>
|
||||||
<TextBlock Text="{Binding ErrorMessage}"
|
<TextBlock Text="{Binding ErrorMessage}"
|
||||||
Foreground="Red"
|
Foreground="Red"
|
||||||
Margin="10,5,10,0"
|
Margin="10,5,10,0"
|
||||||
Grid.Row="1"
|
Grid.Row="1"
|
||||||
Visibility="{Binding ErrorMessage, Converter={StaticResource StringToVisibilityConverter}}" />
|
Visibility="{Binding ErrorMessage, Converter={StaticResource StringToVisibilityConverter}}" />
|
||||||
<Grid Grid.Row="2">
|
<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>
|
<ListView.View>
|
||||||
<GridView>
|
<GridView>
|
||||||
<GridViewColumn Header="CNPJ" DisplayMemberBinding="{Binding CNPJ_CPF}" Width="120" />
|
<GridViewColumn Header="Gestão" DisplayMemberBinding="{Binding Gestao}" Width="70" />
|
||||||
<GridViewColumn Header="Unidade" DisplayMemberBinding="{Binding Codigo_Instalacao}" Width="120" />
|
<GridViewColumn Header="Cliente" DisplayMemberBinding="{Binding Cliente}" Width="400" />
|
||||||
<GridViewColumn Header="Razão Social" DisplayMemberBinding="{Binding Razao_Social}" Width="200" />
|
|
||||||
<GridViewColumn Header="Nome" DisplayMemberBinding="{Binding Cliente}" Width="200" />
|
|
||||||
</GridView>
|
</GridView>
|
||||||
</ListView.View>
|
</ListView.View>
|
||||||
</ListView>
|
</ListView>
|
||||||
@ -43,5 +64,41 @@
|
|||||||
<ProgressBar IsIndeterminate="True" Height="30" Width="200" VerticalAlignment="Center" HorizontalAlignment="Center" />
|
<ProgressBar IsIndeterminate="True" Height="30" Width="200" VerticalAlignment="Center" HorizontalAlignment="Center" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</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>
|
</Grid>
|
||||||
</Window>
|
</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");
|
var accessService = new Data.AccessService($"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={accessDbPath};Jet OLEDB:Database Password=gds21");
|
||||||
DataContext = new ViewModels.MainWindowViewModel(accessService);
|
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
|
public class MainWindowViewModel : INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
private readonly IClienteRepository _clienteRepository;
|
private readonly IClienteRepository _clienteRepository;
|
||||||
private string? _searchText;
|
private string? _searchEmpresaText;
|
||||||
|
private string? _searchUnidadeText;
|
||||||
private bool _isLoading;
|
private bool _isLoading;
|
||||||
private string? _errorMessage;
|
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
|
set
|
||||||
{
|
{
|
||||||
if (_searchText != value)
|
if (_searchEmpresaText != value)
|
||||||
{
|
{
|
||||||
_searchText = value;
|
_searchEmpresaText = value;
|
||||||
OnPropertyChanged();
|
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();
|
_ = 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();
|
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);
|
Clientes.Add(cliente);
|
||||||
if (Clientes.Count == 0)
|
if (Clientes.Count == 0)
|
||||||
ErrorMessage = "Nenhum resultado encontrado.";
|
ErrorMessage = "Nenhum resultado encontrado.";
|
||||||
|
else
|
||||||
|
SelectedCliente = Clientes.First();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
|
private void AtualizarUnidadesSelecionadas()
|
||||||
{
|
{
|
||||||
ErrorMessage = $"Erro: {ex.Message}";
|
UnidadesSelecionadas.Clear();
|
||||||
}
|
ErrorMessage = null;
|
||||||
finally
|
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()
|
public async Task RefreshAsync()
|
||||||
@ -87,9 +143,9 @@ namespace BD_empresa.ViewModels
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var results = await _clienteRepository.GetAllClientesAsync();
|
var results = await _clienteRepository.GetAllClientesAsync();
|
||||||
Clientes.Clear();
|
_allUnidades = [.. results.OrderBy(u => u.Gestao).ThenBy(c => c.Cliente).ThenBy(g => g.Unidade)];
|
||||||
foreach (var cliente in results)
|
FiltrarClientes();
|
||||||
Clientes.Add(cliente);
|
AtualizarUnidadesSelecionadas();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user