예제 #1
0
 public Commande()
 {
     InitializeComponent();
     db = new DBConnect();
     if (db.conn.State != ConnectionState.Open)
     {
         db.conn.Open();
     }
     db.Fill_Categorie(categorie_box);
     db.Fill_Table(filtre_combobox);
     db.Fill_Table_2(id_table_box);
     db.Fill_Table(facture_box);
     db.Afficher_Cmd(Commande_grid);
 }
예제 #2
0
        private void Confirmer_Click(object sender, EventArgs e)
        {
            try
            {
                string nom_plat = "";
                int    quantite = 0;
                float  prix     = 0;
                int    id_table = 0;

                if (string.IsNullOrWhiteSpace(plat_box.Text))
                {
                    throw new Ex("Veuillez selectionner un plat !!");
                }
                else
                {
                    nom_plat = plat_box.Text;
                }
                if (quantite_num.Value == 0)
                {
                    throw new Ex("Veuillez choisir une quantité !!");
                }
                else
                {
                    quantite = Convert.ToInt32(quantite_num.Value);
                }
                if (id_table_box.SelectedIndex == -1 || string.IsNullOrWhiteSpace(id_table_box.SelectedItem.ToString()))
                {
                    throw new Ex("Selectionnez une table !!");
                }
                else
                {
                    id_table = int.Parse(id_table_box.SelectedItem.ToString());
                }


                if (db.check_Existence("Commande", code_cmd_box.Text))
                {
                    MessageBox.Show("La Commande du code " + code_cmd_box.Text + " existe deja \n pour la modifier cliquer sur Modifier !");
                }
                else
                {
                    db.cmd = new SqlCommand("SELECT * FROM Plat where nom_plat = '" + nom_plat + "'", db.conn);
                    SqlDataAdapter da = new SqlDataAdapter(db.cmd);
                    DataTable      dt = new DataTable();
                    da.Fill(dt);
                    if (dt.Rows.Count == 1)
                    {
                        prix = dt.Rows[0].Field <float>("prix");
                        db.Ajouter_Cmd(nom_plat, quantite, prix, id_table);
                        MessageBox.Show("Commande bien ajoutée !!", "Succès");
                        db.Afficher_Cmd(Commande_grid);
                    }
                    ClearTextBoxes();
                    db.Fill_Table(filtre_combobox);
                    db.Fill_Table(facture_box);
                }
            }
            catch (Exception ex)
            {
            }
        }