Exemple #1
0
        private void btValiderModif_Click(object sender, EventArgs e)
        {
            Plat p = (Plat)lbPlats.SelectedItem;

            if (p == null)
            {
                MessageBox.Show("Veuillez choisir un plat svp");
                return;
            }

            Categorie categorie = (Categorie)cbCat.SelectedItem;
            string    prix      = tbPrix.Text;
            string    cal       = tbCal.Text;

            if (!string.IsNullOrEmpty(tbNom.Text))
            {
                MessageBox.Show("Vous ne pouvez pas modifier le nom d'un plat");
                return;
            }

            if (!string.IsNullOrEmpty(prix))
            {
                p.SetPrix(Convert.ToInt16(prix));
            }

            if (!string.IsNullOrEmpty(cal))
            {
                p.SetNbCalories(Convert.ToInt16(cal));
            }

            if (cbVegan.Checked)
            {
                p.SetVegan(true);
            }
            else
            {
                p.SetVegan(false);
            }

            if (cbGlutenFree.Checked)
            {
                p.SetGlutenFree(true);
            }
            else
            {
                p.SetGlutenFree(false);
            }

            p.SetCategorie(categorie);
            listePlatsModif.Add(p);
            MessageBox.Show("Les modifications sont bien prises en compte");
        }
        public static Plat GetPlatMoinsCher()
        {
            MySqlCommand cmd = conn.CreateCommand();

            cmd.CommandText = "SELECT * FROM plat WHERE prix = (SELECT MIN(prix) FROM plat)";
            MySqlDataReader rdr = cmd.ExecuteReader();
            Plat            p   = new Plat();

            if (rdr.Read())
            {
                p.SetNom((string)rdr["nom"]);
                p.SetCategorie((Categorie)Enum.Parse(typeof(Categorie), (string)rdr["categorie"]));
                p.SetPrix((int)rdr["prix"]);
                p.SetNbCalories((int)rdr["nbcalories"]);
                p.SetGlutenFree((bool)rdr["glutenFree"]);
                p.SetVegan((bool)rdr["vegan"]);
            }
            rdr.Close();
            return(p);
        }