Exemplo n.º 1
0
        private void Supprimer_Cmd_Button(object sender, EventArgs e)
        {
            string code = code_cmd_box.Text;

            if (string.IsNullOrWhiteSpace(code))
            {
                MessageBox.Show("Selectionnez une commande d'abord!", "Erreur");
            }
            else
            {
                string message = "Voulez vous vraiment supprimer cette Commande?";
                db.cmd = new SqlCommand("SELECT * FROM Commande where id_commande = '" + code + "'", db.conn);
                SqlDataAdapter da = new SqlDataAdapter(db.cmd);
                DataTable      dt = new DataTable();
                da.Fill(dt);
                if (dt.Rows.Count > 0 && dt.Rows[0].Field <string>("facture").Equals("Non facturé"))
                {
                    message = "Cette commande n'est pas facturé! Supprimer quand meme ?";
                }

                if (MessageBox.Show(message, "Supprimer commande", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    int id = int.Parse(code);
                    db.Supprimer_Cmd(id);
                    db.Afficher_Cmd(Commande_grid);
                    MessageBox.Show("Commande bien supprimée !!", "Succès");
                    ClearTextBoxes();
                }
                else
                {
                    MessageBox.Show("Commande non Supprimée !", "Annulation");
                }
            }
        }