feat: implement reimport and analysis functionality for XLSX files
- Added `reimportar_e_analisar` method to `App` struct to handle reimporting and analyzing files. - Preserved previous analysis results to restore in case of errors or empty imports. - Updated UI to include a button for reanalyzing the current file. - Enhanced file selection logic to allow direct processing if a compatible preset is selected. - Refactored import logic to streamline the analysis process for both CSV and XLSX files. - Improved user feedback with appropriate error and success messages during file operations.
This commit is contained in:
+36
-14
@@ -10,7 +10,7 @@ use egui::{Context, Ui};
|
||||
const OPCOES_PAGINA: &[usize] = &[50, 100, 200, 1000];
|
||||
|
||||
/// Renderiza a tela de resultados.
|
||||
pub fn renderizar(ui: &mut Ui, _ctx: &Context, app: &mut App) {
|
||||
pub fn renderizar(ui: &mut Ui, ctx: &Context, app: &mut App) {
|
||||
// Extrair resultado do estado (sem mover)
|
||||
let resultado = match &app.estado {
|
||||
EstadoApp::ExibindoResultado(r) => r.clone(),
|
||||
@@ -34,6 +34,15 @@ pub fn renderizar(ui: &mut Ui, _ctx: &Context, app: &mut App) {
|
||||
return;
|
||||
}
|
||||
|
||||
let pode_reanalisar = app.caminho_arquivo.is_some();
|
||||
if ui
|
||||
.add_enabled(pode_reanalisar, egui::Button::new("🔄 Reanalisar Arquivo"))
|
||||
.on_hover_text("Reimporta o arquivo do disco com o layout atual e reanalisa")
|
||||
.clicked()
|
||||
{
|
||||
app.reimportar_e_analisar(ctx);
|
||||
}
|
||||
|
||||
if ui.button("📄 Exportar PDF").clicked() {
|
||||
exportar_para_pdf(app, &resultado);
|
||||
}
|
||||
@@ -138,8 +147,16 @@ fn renderizar_faltantes(ui: &mut Ui, app: &mut App, resultado: &ResultadoAnalise
|
||||
total_esperado,
|
||||
percentual,
|
||||
));
|
||||
if ui.button("📋 Copiar").on_hover_text("Copiar todos os números faltantes").clicked() {
|
||||
let texto = faltantes.iter().map(|n| n.to_string()).collect::<Vec<_>>().join(", ");
|
||||
if ui
|
||||
.button("📋 Copiar")
|
||||
.on_hover_text("Copiar todos os números faltantes")
|
||||
.clicked()
|
||||
{
|
||||
let texto = faltantes
|
||||
.iter()
|
||||
.map(|n| n.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
ui.ctx().copy_text(texto);
|
||||
}
|
||||
});
|
||||
@@ -183,12 +200,9 @@ fn renderizar_faltantes(ui: &mut Ui, app: &mut App, resultado: &ResultadoAnalise
|
||||
fn renderizar_duplicatas(ui: &mut Ui, app: &mut App, resultado: &ResultadoAnalise) {
|
||||
let total_dup = resultado.total_duplicatas();
|
||||
ui.label(
|
||||
egui::RichText::new(format!(
|
||||
"Notas Duplicadas ({} grupo(s))",
|
||||
total_dup
|
||||
))
|
||||
.heading()
|
||||
.strong(),
|
||||
egui::RichText::new(format!("Notas Duplicadas ({} grupo(s))", total_dup))
|
||||
.heading()
|
||||
.strong(),
|
||||
);
|
||||
ui.add_space(4.0);
|
||||
|
||||
@@ -212,7 +226,11 @@ fn renderizar_duplicatas(ui: &mut Ui, app: &mut App, resultado: &ResultadoAnalis
|
||||
chave.label(),
|
||||
duplicatas.len()
|
||||
));
|
||||
if ui.button("📋 Copiar").on_hover_text("Copiar números duplicados").clicked() {
|
||||
if ui
|
||||
.button("📋 Copiar")
|
||||
.on_hover_text("Copiar números duplicados")
|
||||
.clicked()
|
||||
{
|
||||
let texto = duplicatas
|
||||
.iter()
|
||||
.map(|(n, c)| format!("{} ({}x)", n, c))
|
||||
@@ -222,8 +240,7 @@ fn renderizar_duplicatas(ui: &mut Ui, app: &mut App, resultado: &ResultadoAnalis
|
||||
}
|
||||
});
|
||||
|
||||
let total_paginas =
|
||||
(duplicatas.len() + app.itens_por_pagina - 1) / app.itens_por_pagina;
|
||||
let total_paginas = (duplicatas.len() + app.itens_por_pagina - 1) / app.itens_por_pagina;
|
||||
if app.pagina_duplicatas >= total_paginas {
|
||||
app.pagina_duplicatas = 0;
|
||||
}
|
||||
@@ -234,7 +251,9 @@ fn renderizar_duplicatas(ui: &mut Ui, app: &mut App, resultado: &ResultadoAnalis
|
||||
for (numero, count) in &duplicatas[inicio..fim] {
|
||||
ui.label(format!(
|
||||
" • NF {} / Série {} — {} ocorrências",
|
||||
numero, chave.label(), count
|
||||
numero,
|
||||
chave.label(),
|
||||
count
|
||||
));
|
||||
}
|
||||
|
||||
@@ -277,7 +296,10 @@ fn exportar_para_pdf(app: &mut App, resultado: &ResultadoAnalise) {
|
||||
&caminho,
|
||||
) {
|
||||
Ok(_) => {
|
||||
app.exibir_aviso("Sucesso", format!("PDF exportado para: {}", caminho.display()));
|
||||
app.exibir_aviso(
|
||||
"Sucesso",
|
||||
format!("PDF exportado para: {}", caminho.display()),
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
app.exibir_erro(format!("Erro ao exportar PDF: {}", e));
|
||||
|
||||
Reference in New Issue
Block a user