1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
public MySqlConnection maconnexion;
public DataSet dataset_commande = new DataSet();
private void liste_Load(object sender, EventArgs e)
{
try
{
timer_reload.Enabled = true;
// Connexion à la base de données
string connexion = "Server=IP;Port=3306;Database=db_commande;Uid=PSEUDO;Pwd=MDP;";
maconnexion = new MySqlConnection(connexion);
maconnexion.Open(); // Ouverture
MySqlDataAdapter adapter_commande = new MySqlDataAdapter("SELECT co_ref, co_fich, co_dat, co_qte, co_del, co_com, co_sta, co_fac, co_imp, for_nom, gra_nom, pro_nom FROM commande,forma,grammage,produit WHERE co_for=for_id AND co_gra=gra_id AND co_pro=pro_id AND co_sta=0 ORDER BY co_dat DESC", maconnexion);
MySqlCommand cmd = maconnexion.CreateCommand();
cmd.CommandText = "UPDATE commande SET co_sta=@co_sta WHERE co_ref=@co_ref";
cmd.Parameters.Add("@co_sta", MySqlDbType.Int32, 0, "co_sta");
cmd.Parameters.Add("@co_ref", MySqlDbType.String, 0, "co_ref");
adapter_commande.UpdateCommand = cmd;
adapter_commande.Fill(dataset_commande, "commande");
DataView dataView_attente = new DataView(dataset_commande.Tables["commande"], "co_sta = 0", null, DataViewRowState.CurrentRows);
dataGridView_attente.DataSource = dataView_attente;
DataView dataView_termine = new DataView(dataset_commande.Tables["commande"], "co_sta = 1", null, DataViewRowState.CurrentRows);
dataGridView_termine.DataSource = dataView_termine;
}
catch (Exception)
{
MessageBox.Show("Connexion impossible avec le serveur, veuillez vérifier son état !", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void dataGridView_attente_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0 && e.ColumnIndex == details.Index)
{
MySqlDataAdapter adapter_commande = new MySqlDataAdapter("SELECT co_ref, co_fich, co_dat, co_qte, co_del, co_com, co_fac, co_imp, for_nom, gra_nom, pro_nom, co_sta FROM commande,forma,grammage,produit WHERE co_for=for_id AND co_gra=gra_id AND co_pro=pro_id AND co_sta=0 ORDER BY co_dat DESC", maconnexion);
adapter_commande.Fill(dataset_commande, "commande");
// obtenir la DataRow correspondant à la ligne courante du DataGridView
DataRowView drv = dataGridView_attente.CurrentRow.DataBoundItem as DataRowView;
drv.Row["co_sta"] = 1;
adapter_commande.Update(dataset_commande, "commande");
MessageBox.Show("Commande terminée !", "Validation", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
} |
Partager