Aggiunta configurazione e gestione del dataset Inventario
Sono stati aggiunti nuovi file di configurazione e progetto per l'applicazione "Inventario", inclusi `App.config` per la connessione al database Access e `Inventario.csproj` per la struttura del progetto. È stata creata una soluzione di Visual Studio con configurazioni per diverse piattaforme. In `InventarioDataSet.Designer.cs`, sono state definite classi per gestire le entità dell'inventario, inclusi articoli e fornitori, con metodi per operazioni di database. È stata implementata una nuova interfaccia utente per la gestione degli articoli, con funzionalità per aggiungere, modificare ed eliminare articoli, e migliorata la gestione degli errori con messaggi informativi.
This commit is contained in:
236
Inventario/Form/Articoli/ModificaArticoli.cs
Normal file
236
Inventario/Form/Articoli/ModificaArticoli.cs
Normal file
@@ -0,0 +1,236 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Inventario
|
||||
{
|
||||
public partial class ModificaArticoli : Form
|
||||
{
|
||||
static int STATO_BROWSE = 0;
|
||||
static int STATO_NUOVO = 1;
|
||||
static int STATO_MODIFICA = 2;
|
||||
|
||||
//Default
|
||||
int Stato = STATO_BROWSE;
|
||||
|
||||
public ModificaArticoli()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void SetControls()
|
||||
{
|
||||
if(Stato == STATO_BROWSE)
|
||||
{
|
||||
ButtonSalva.Enabled = false;
|
||||
ButtonAnnulla.Enabled = false;
|
||||
ButtonNuovo.Enabled = true;
|
||||
ButtonModifica.Enabled = true;
|
||||
ButtonElimina.Enabled = true;
|
||||
|
||||
ButtonPrimo.Enabled = true;
|
||||
ButtonAvanti.Enabled = true;
|
||||
ButtonIndietro.Enabled = true;
|
||||
ButtonUltimo.Enabled = true;
|
||||
|
||||
TextCodice.Enabled = false;
|
||||
TextDescrizione.Enabled = false;
|
||||
NumericPrezzoAcquisto.Enabled = false;
|
||||
ComboFornitore.Enabled = false;
|
||||
NumericPrezzoVendita.Enabled = false;
|
||||
ComboCondizione.Enabled = false;
|
||||
TextNote.Enabled = false;
|
||||
}
|
||||
else if (Stato == STATO_NUOVO)
|
||||
{
|
||||
ButtonSalva.Enabled = true;
|
||||
ButtonAnnulla.Enabled = true;
|
||||
ButtonNuovo.Enabled = false;
|
||||
ButtonModifica.Enabled = false;
|
||||
ButtonElimina.Enabled = false;
|
||||
|
||||
ButtonPrimo.Enabled = false;
|
||||
ButtonAvanti.Enabled = false;
|
||||
ButtonIndietro.Enabled = false;
|
||||
ButtonUltimo.Enabled = false;
|
||||
|
||||
TextCodice.Enabled = true;
|
||||
TextDescrizione.Enabled = true;
|
||||
NumericPrezzoAcquisto.Enabled = true;
|
||||
ComboFornitore.Enabled = true;
|
||||
NumericPrezzoVendita.Enabled = true;
|
||||
ComboCondizione.Enabled = true;
|
||||
TextNote.Enabled = true;
|
||||
|
||||
TextCodice.Clear();
|
||||
TextDescrizione.Clear();
|
||||
NumericPrezzoAcquisto.ResetText();
|
||||
ComboFornitore.ResetText();
|
||||
NumericPrezzoVendita.ResetText();
|
||||
TextNote.Clear();
|
||||
|
||||
TextCodice.Focus();
|
||||
}
|
||||
else if (Stato == STATO_MODIFICA)
|
||||
{
|
||||
ButtonSalva.Enabled = true;
|
||||
ButtonAnnulla.Enabled = true;
|
||||
ButtonNuovo.Enabled = false;
|
||||
ButtonModifica.Enabled = false;
|
||||
ButtonElimina.Enabled = false;
|
||||
|
||||
ButtonPrimo.Enabled = false;
|
||||
ButtonAvanti.Enabled = false;
|
||||
ButtonIndietro.Enabled = false;
|
||||
ButtonUltimo.Enabled = false;
|
||||
|
||||
TextCodice.Enabled = true;
|
||||
TextDescrizione.Enabled = true;
|
||||
NumericPrezzoAcquisto.Enabled = true;
|
||||
ComboFornitore.Enabled = true;
|
||||
NumericPrezzoVendita.Enabled = true;
|
||||
ComboCondizione.Enabled = true;
|
||||
TextNote.Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void Articoli_Load(object sender, EventArgs e)
|
||||
{
|
||||
Stato = STATO_BROWSE;
|
||||
|
||||
SetControls();
|
||||
}
|
||||
|
||||
private void ButtonNuovo_Click(object sender, EventArgs e)
|
||||
{
|
||||
Stato = STATO_NUOVO;
|
||||
|
||||
SetControls();
|
||||
}
|
||||
|
||||
private void ButtonModifica_Click(object sender, EventArgs e)
|
||||
{
|
||||
Stato = STATO_MODIFICA;
|
||||
|
||||
SetControls();
|
||||
}
|
||||
|
||||
private void ButtonAnnulla_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
//Mi metto sull'ultimo record
|
||||
articoliBindingSource.MoveLast();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
articoliBindingSource.ResetBindings(false);
|
||||
}
|
||||
|
||||
Stato = STATO_BROWSE;
|
||||
|
||||
SetControls();
|
||||
}
|
||||
|
||||
private void ButtonSalva_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (Stato == STATO_NUOVO)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.articoliTableAdapter.Insert(TextCodice.Text.ToString(),
|
||||
TextDescrizione.Text.ToString(),
|
||||
TextNote.Text.ToString(),
|
||||
0,
|
||||
NumericPrezzoAcquisto.Value,
|
||||
NumericPrezzoVendita.Value,
|
||||
null, //ComboFornitore.Text.ToString(),
|
||||
ComboCondizione.Text.ToString());
|
||||
|
||||
MessageBox.Show("Salvataggio avvenuto con successo.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message + "\n Errore al salvataggio dei dati.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
articoliBindingSource.ResetBindings(false);
|
||||
}
|
||||
}
|
||||
else if (Stato == STATO_MODIFICA)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.articoliTableAdapter.Update(this.inventarioDataSet.Articoli);
|
||||
|
||||
MessageBox.Show("Modifica avvenuta con successo.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message + "\n Errore al salvataggio dei dati.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
articoliBindingSource.ResetBindings(false);
|
||||
}
|
||||
}
|
||||
|
||||
//ResettoStato
|
||||
Stato = STATO_BROWSE;
|
||||
|
||||
SetControls();
|
||||
}
|
||||
|
||||
private void ButtonPrimo_Click(object sender, EventArgs e)
|
||||
{
|
||||
articoliBindingSource.MoveFirst();
|
||||
this.articoliTableAdapter.Fill(this.inventarioDataSet.Articoli);
|
||||
}
|
||||
|
||||
private void ButtonIndietro_Click(object sender, EventArgs e)
|
||||
{
|
||||
articoliBindingSource.MovePrevious();
|
||||
this.articoliTableAdapter.Fill(this.inventarioDataSet.Articoli);
|
||||
}
|
||||
|
||||
private void ButtonAvanti_Click(object sender, EventArgs e)
|
||||
{
|
||||
articoliBindingSource.MoveNext();
|
||||
this.articoliTableAdapter.Fill(this.inventarioDataSet.Articoli);
|
||||
}
|
||||
|
||||
private void ButtonUltimo_Click(object sender, EventArgs e)
|
||||
{
|
||||
articoliBindingSource.MoveLast();
|
||||
this.articoliTableAdapter.Fill(this.inventarioDataSet.Articoli);
|
||||
}
|
||||
|
||||
private void ButtonElimina_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.articoliTableAdapter.Delete(TextCodice.Text.ToString(),
|
||||
TextDescrizione.Text.ToString(),
|
||||
0,
|
||||
NumericPrezzoAcquisto.Value,
|
||||
NumericPrezzoVendita.Value,
|
||||
ComboFornitore.Text.ToString(),
|
||||
ComboCondizione.Text.ToString());
|
||||
|
||||
MessageBox.Show("Modifica avvenuta con successo.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message + "\n Errore al salvataggio dei dati.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
articoliBindingSource.ResetBindings(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void TextNote_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user