Aggiungi la lista personalizzata di codici nella fase 2
In alternativa al file del gestionale si possono digitare i codici uno alla volta (Invio/Aggiungi, Canc per togliere). Tutto a valle legge solo _righeCorrenti, quindi basta una nuova sorgente; la selezione della griglia mantiene il colore verde/rosso della verifica. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ccfa00ff52
commit
6d1e36a2ae
5 files changed
+138
-11
No files matched your search
+125
-8
@@ -12,6 +12,11 @@ public partial class Form1 : Form
|
||||
private readonly Button _btnTrovaPrt = new();
|
||||
private readonly Button _btnVerifica = new();
|
||||
private readonly FlowLayoutPanel _rigaVerifica = new();
|
||||
private readonly FlowLayoutPanel _rigaFile = new();
|
||||
private readonly FlowLayoutPanel _rigaCustom = new();
|
||||
private readonly RadioButton _rbFile = new() { Text = "Da file del gestionale", Checked = true, AutoSize = true };
|
||||
private readonly RadioButton _rbCustom = new() { Text = "Lista personalizzata", AutoSize = true };
|
||||
private readonly TextBox _txtCodice = new() { Width = 220, Margin = new Padding(0, 3, 8, 0) };
|
||||
private readonly ListView _lstAnteprimaAsm = new();
|
||||
private readonly Label _lblStatus = new();
|
||||
private readonly Label _lblDb = new();
|
||||
@@ -50,7 +55,7 @@ public partial class Form1 : Form
|
||||
|
||||
private string? _dbPath;
|
||||
private string? _cartellaLavoro;
|
||||
private string? _percorsoInputCorrente;
|
||||
private bool _ripristinoModalita;
|
||||
private List<(string Componente, string Descrizione)>? _righeCorrenti;
|
||||
private Dictionary<string, List<string>>? _ultimaVerifica;
|
||||
private string? _ultimaCartellaRaw;
|
||||
@@ -266,7 +271,12 @@ public partial class Form1 : Form
|
||||
return;
|
||||
}
|
||||
|
||||
_percorsoInputCorrente = null;
|
||||
AzzeraDistinta();
|
||||
VaiAllaFase(1);
|
||||
}
|
||||
|
||||
private void AzzeraDistinta()
|
||||
{
|
||||
_righeCorrenti = null;
|
||||
_ultimaCartellaRaw = null;
|
||||
_ultimaVerifica = null;
|
||||
@@ -275,8 +285,68 @@ public partial class Form1 : Form
|
||||
_lstAnteprimaAsm.Items.Clear();
|
||||
ImpostaStatoImport("", Color.Black);
|
||||
_rigaVerifica.Visible = false;
|
||||
}
|
||||
|
||||
VaiAllaFase(1);
|
||||
private void CambiaModalitaDistinta()
|
||||
{
|
||||
if (_ripristinoModalita)
|
||||
return;
|
||||
if (_gridImport.Rows.Count > 0 && MessageBox.Show(this,
|
||||
"Cambiando modalità la distinta corrente viene azzerata. Continuare?", "Distinta",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
||||
{
|
||||
_ripristinoModalita = true;
|
||||
(_rbCustom.Checked ? _rbFile : _rbCustom).Checked = true;
|
||||
_ripristinoModalita = false;
|
||||
return;
|
||||
}
|
||||
AzzeraDistinta();
|
||||
_rigaFile.Visible = _rbFile.Checked;
|
||||
_rigaCustom.Visible = _rbCustom.Checked;
|
||||
AggiornaStatoAvanti();
|
||||
}
|
||||
|
||||
private void AggiungiCodice()
|
||||
{
|
||||
string codice = _txtCodice.Text.Trim();
|
||||
if (codice.Length == 0)
|
||||
return;
|
||||
_righeCorrenti ??= new();
|
||||
if (_righeCorrenti.Any(r => string.Equals(r.Componente, codice, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
_txtCodice.SelectAll();
|
||||
return;
|
||||
}
|
||||
_righeCorrenti.Add((codice, ""));
|
||||
_gridImport.Rows.Add(codice, "");
|
||||
InvalidaVerifica();
|
||||
_txtCodice.Clear();
|
||||
_txtCodice.Focus();
|
||||
}
|
||||
|
||||
private void RimuoviCodiceSelezionato()
|
||||
{
|
||||
if (_gridImport.CurrentRow is not { } riga || _righeCorrenti is null)
|
||||
return;
|
||||
_righeCorrenti.RemoveAt(riga.Index); // griglia e lista hanno lo stesso ordine
|
||||
_gridImport.Rows.Remove(riga);
|
||||
InvalidaVerifica();
|
||||
}
|
||||
|
||||
/// <summary>La lista è cambiata: la verifica presenza e il raw già creato non valgono più.</summary>
|
||||
private void InvalidaVerifica()
|
||||
{
|
||||
_ultimaVerifica = null;
|
||||
_ultimaCartellaRaw = null;
|
||||
_gridRaw.Rows.Clear();
|
||||
foreach (DataGridViewRow r in _gridImport.Rows)
|
||||
{
|
||||
r.DefaultCellStyle.BackColor = Color.Empty;
|
||||
r.DefaultCellStyle.SelectionBackColor = Color.Empty;
|
||||
r.DefaultCellStyle.SelectionForeColor = Color.Empty;
|
||||
}
|
||||
_rigaVerifica.Visible = _righeCorrenti is { Count: > 0 };
|
||||
AggiornaStatoAvanti();
|
||||
}
|
||||
|
||||
private Panel BuildFaseDatabase()
|
||||
@@ -400,12 +470,51 @@ public partial class Form1 : Form
|
||||
};
|
||||
contenuto.Controls.Add(lblIstruzioni);
|
||||
|
||||
var rigaImporta = new FlowLayoutPanel
|
||||
var rigaModalita = new FlowLayoutPanel
|
||||
{
|
||||
AutoSize = true,
|
||||
FlowDirection = FlowDirection.LeftToRight,
|
||||
Margin = new Padding(0, 0, 0, 8),
|
||||
};
|
||||
rigaModalita.Controls.Add(_rbFile);
|
||||
rigaModalita.Controls.Add(_rbCustom);
|
||||
_rbCustom.CheckedChanged += (_, _) => CambiaModalitaDistinta();
|
||||
contenuto.Controls.Add(rigaModalita);
|
||||
|
||||
_rigaCustom.AutoSize = true;
|
||||
_rigaCustom.FlowDirection = FlowDirection.LeftToRight;
|
||||
_rigaCustom.Margin = new Padding(0, 0, 0, 8);
|
||||
_rigaCustom.Visible = false;
|
||||
var btnAggiungi = new Button { Text = "Aggiungi", Margin = new Padding(0, 0, 8, 0) };
|
||||
UiStile.Secondario(btnAggiungi);
|
||||
btnAggiungi.Click += (_, _) => AggiungiCodice();
|
||||
_txtCodice.KeyDown += (_, e) =>
|
||||
{
|
||||
if (e.KeyCode != Keys.Enter)
|
||||
return;
|
||||
e.SuppressKeyPress = true;
|
||||
AggiungiCodice();
|
||||
};
|
||||
_rigaCustom.Controls.Add(_txtCodice);
|
||||
_rigaCustom.Controls.Add(btnAggiungi);
|
||||
_rigaCustom.Controls.Add(new Label
|
||||
{
|
||||
AutoSize = true,
|
||||
ForeColor = SystemColors.GrayText,
|
||||
Margin = new Padding(0, 9, 0, 0),
|
||||
Text = "Digita un codice e premi Invio (Canc sulla riga per toglierlo)",
|
||||
});
|
||||
contenuto.Controls.Add(_rigaCustom);
|
||||
_gridImport.KeyDown += (_, e) =>
|
||||
{
|
||||
if (e.KeyCode == Keys.Delete && _rbCustom.Checked)
|
||||
RimuoviCodiceSelezionato();
|
||||
};
|
||||
|
||||
var rigaImporta = _rigaFile;
|
||||
rigaImporta.AutoSize = true;
|
||||
rigaImporta.FlowDirection = FlowDirection.LeftToRight;
|
||||
rigaImporta.Margin = new Padding(0, 0, 0, 8);
|
||||
var btnSfoglia = new Button
|
||||
{
|
||||
Text = "Scegli file distinta...",
|
||||
@@ -646,10 +755,15 @@ public partial class Form1 : Form
|
||||
|
||||
private void ImportaDistinta(string percorso)
|
||||
{
|
||||
if (_rbCustom.Checked)
|
||||
{
|
||||
_rbFile.Checked = true; // chiede conferma se c'è una lista; se rifiuta resta in custom
|
||||
if (_rbCustom.Checked)
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
var (_, righe) = DistintaBaseImporter.ConvertiInCsv(percorso, _cartellaLavoro!);
|
||||
_percorsoInputCorrente = percorso;
|
||||
_righeCorrenti = righe;
|
||||
|
||||
_gridImport.Rows.Clear();
|
||||
@@ -666,7 +780,6 @@ public partial class Form1 : Form
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_percorsoInputCorrente = null;
|
||||
_righeCorrenti = null;
|
||||
_gridImport.Rows.Clear();
|
||||
ImpostaStatoImport($"Errore durante la conversione: {ex.Message}", Color.DarkRed);
|
||||
@@ -694,16 +807,20 @@ public partial class Form1 : Form
|
||||
foreach (DataGridViewRow riga in _gridImport.Rows)
|
||||
{
|
||||
string componente = (string)riga.Cells["componente"].Value!;
|
||||
riga.DefaultCellStyle.BackColor = trovati.ContainsKey(componente)
|
||||
var colore = trovati.ContainsKey(componente)
|
||||
? Color.FromArgb(198, 239, 206)
|
||||
: Color.FromArgb(255, 199, 206);
|
||||
// la selezione mantiene il colore verde/rosso, altrimenti il blu nasconde l'esito
|
||||
riga.DefaultCellStyle.BackColor = colore;
|
||||
riga.DefaultCellStyle.SelectionBackColor = colore;
|
||||
riga.DefaultCellStyle.SelectionForeColor = Color.Black;
|
||||
}
|
||||
AggiornaStatoAvanti();
|
||||
}
|
||||
|
||||
private void CreaCartellaRaw()
|
||||
{
|
||||
if (_percorsoInputCorrente is null || _righeCorrenti is null)
|
||||
if (_righeCorrenti is null)
|
||||
return;
|
||||
|
||||
// L'assieme generale è già una riga di _righeCorrenti (aggiunta da
|
||||
|
||||
Reference in new issue
Block a user