diff --git a/.gitignore b/.gitignore
index 7a39ba9..e3a1d00 100644
--- a/.gitignore
+++ b/.gitignore
@@ -360,4 +360,6 @@ MigrationBackup/
.ionide/
# Fody - auto-generated XML schema
-FodyWeavers.xsd
\ No newline at end of file
+FodyWeavers.xsd
+
+.history
\ No newline at end of file
diff --git a/App.xaml b/App.xaml
index fc1f6f4..d667cee 100644
--- a/App.xaml
+++ b/App.xaml
@@ -4,6 +4,9 @@
xmlns:local="clr-namespace:BD_empresa"
StartupUri="MainWindow.xaml">
-
+
+
+
+
diff --git a/BD_empresa.csproj b/BD_empresa.csproj
index defb4d1..c01d888 100644
--- a/BD_empresa.csproj
+++ b/BD_empresa.csproj
@@ -8,4 +8,11 @@
true
+
+
+
+
+
+
+
diff --git a/Converters.cs b/Converters.cs
new file mode 100644
index 0000000..2eb0955
--- /dev/null
+++ b/Converters.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Globalization;
+using System.Windows;
+using System.Windows.Data;
+
+namespace BD_empresa
+{
+ public class BoolToVisibilityConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value is bool b && b)
+ return Visibility.Visible;
+ return Visibility.Collapsed;
+ }
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ return (value is Visibility v && v == Visibility.Visible);
+ }
+ }
+
+ public class StringToVisibilityConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ return string.IsNullOrWhiteSpace(value as string) ? Visibility.Collapsed : Visibility.Visible;
+ }
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/Data/AccessService.cs b/Data/AccessService.cs
new file mode 100644
index 0000000..42af733
--- /dev/null
+++ b/Data/AccessService.cs
@@ -0,0 +1,85 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Data.OleDb;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace BD_empresa.Data
+{
+ public class AccessService(string connectionString) : IClienteRepository
+ {
+ private readonly string _connectionString = connectionString;
+
+ public async Task> SearchClientesAsync(string query)
+ {
+ return await Task.Run(() =>
+ {
+ var clientes = new List();
+ 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 ?";
+ 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
+ {
+ 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, retorna no máximo 3
+ return clientes
+ .GroupBy(c => c.CNPJ_CPF)
+ .Select(g => g.First())
+ .Take(3)
+ .ToList();
+ });
+ }
+
+ public async Task> GetAllClientesAsync()
+ {
+ return await Task.Run(() =>
+ {
+ var clientes = new List();
+ 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();
+ });
+ }
+ }
+}
diff --git a/Data/ClienteSmart.cs b/Data/ClienteSmart.cs
new file mode 100644
index 0000000..4245916
--- /dev/null
+++ b/Data/ClienteSmart.cs
@@ -0,0 +1,20 @@
+using System.ComponentModel;
+
+namespace BD_empresa.Data
+{
+ public class ClienteSmart : INotifyPropertyChanged
+ {
+ 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 event PropertyChangedEventHandler? PropertyChanged;
+ protected void OnPropertyChanged(string propertyName)
+ {
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ }
+ }
+}
diff --git a/Data/IClienteRepository.cs b/Data/IClienteRepository.cs
new file mode 100644
index 0000000..ef6ce08
--- /dev/null
+++ b/Data/IClienteRepository.cs
@@ -0,0 +1,11 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+
+namespace BD_empresa.Data
+{
+ public interface IClienteRepository
+ {
+ Task> SearchClientesAsync(string query);
+ Task> GetAllClientesAsync();
+ }
+}
diff --git a/MainWindow.xaml b/MainWindow.xaml
index ed01b74..d3f8fd7 100644
--- a/MainWindow.xaml
+++ b/MainWindow.xaml
@@ -8,5 +8,40 @@
Title="MainWindow" Height="450" Width="800">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index 61c9e62..4dc51c3 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -19,6 +19,10 @@ namespace BD_empresa
public MainWindow()
{
InitializeComponent();
+ // Caminho do banco de dados Access
+ string accessDbPath = "X:\\Middle\\Informativo Setorial\\Modelo Word\\BD1_dados cadastrais e faturas.accdb";
+ var accessService = new Data.AccessService($"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={accessDbPath};Jet OLEDB:Database Password=gds21");
+ DataContext = new ViewModels.MainWindowViewModel(accessService);
}
}
}
\ No newline at end of file
diff --git a/ViewModels/MainWindowViewModel.cs b/ViewModels/MainWindowViewModel.cs
new file mode 100644
index 0000000..af123fb
--- /dev/null
+++ b/ViewModels/MainWindowViewModel.cs
@@ -0,0 +1,122 @@
+using System;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.Runtime.CompilerServices;
+using System.Threading.Tasks;
+using System.Windows.Input;
+using BD_empresa.Data;
+
+namespace BD_empresa.ViewModels
+{
+ public class MainWindowViewModel : INotifyPropertyChanged
+ {
+ private readonly IClienteRepository _clienteRepository;
+ private string? _searchText;
+ private bool _isLoading;
+ private string? _errorMessage;
+
+ public ObservableCollection Clientes { get; } = [];
+
+ public string? SearchText
+ {
+ get => _searchText;
+ set
+ {
+ if (_searchText != value)
+ {
+ _searchText = value;
+ OnPropertyChanged();
+ _ = SearchAsync();
+ }
+ }
+ }
+
+ public bool IsLoading
+ {
+ get => _isLoading;
+ set { _isLoading = value; OnPropertyChanged(); }
+ }
+
+ public string? ErrorMessage
+ {
+ get => _errorMessage;
+ set { _errorMessage = value; OnPropertyChanged(); }
+ }
+
+ public ICommand RefreshCommand { get; }
+
+ public MainWindowViewModel(IClienteRepository clienteRepository)
+ {
+ _clienteRepository = clienteRepository;
+ RefreshCommand = new RelayCommand(async _ => await RefreshAsync());
+ _ = RefreshAsync();
+ }
+
+ public async Task SearchAsync()
+ {
+ 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)
+ Clientes.Add(cliente);
+ if (Clientes.Count == 0)
+ ErrorMessage = "Nenhum resultado encontrado.";
+ }
+ catch (Exception ex)
+ {
+ ErrorMessage = $"Erro: {ex.Message}";
+ }
+ finally
+ {
+ IsLoading = false;
+ }
+ }
+
+ public async Task RefreshAsync()
+ {
+ IsLoading = true;
+ ErrorMessage = null;
+ try
+ {
+ var results = await _clienteRepository.GetAllClientesAsync();
+ Clientes.Clear();
+ foreach (var cliente in results)
+ Clientes.Add(cliente);
+ }
+ catch (Exception ex)
+ {
+ ErrorMessage = $"Erro: {ex.Message}";
+ }
+ finally
+ {
+ IsLoading = false;
+ }
+ }
+
+ public event PropertyChangedEventHandler? PropertyChanged;
+ protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
+ {
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ }
+ }
+
+ // RelayCommand para ICommand
+ public class RelayCommand(Func