Beispiel #1
0
 private void submit_Click(object sender, EventArgs e)
 {
     using (MySqlConnection cn = new MySqlConnection(Program._cn))
     {
         cn.Open();
         if (dataGridViewOptions.SelectedCells.Count > 0)
         {
             for (int i = 0; i < dataGridViewOptions.SelectedCells.Count; i++)
             {
                 WCFUtils.Option option = new WCFUtils.Option();
                 MySqlCommand    cmd    = new MySqlCommand("select caracteristique, prix from toption where NOM_OPTION = '" + dataGridViewOptions.SelectedCells[i].Value.ToString() + "'", cn);
                 MySqlDataReader dr     = cmd.ExecuteReader();
                 if (dr.Read())
                 {
                     option.Nom             = dataGridViewOptions.SelectedCells[i].Value.ToString();
                     option.Prix            = Convert.ToInt32(dr["prix"].ToString());
                     option.Caracteristique = dr["caracteristique"].ToString();
                 }
                 dr.Close();
                 CreateVoiture.listeOptions.Add(option);
             }
         }
     }
     this.Close();
 }
        private void Submit_Click(object sender, EventArgs e)
        {
            if (!comboBoxTypes.Text.Equals("") && !comboBoxMarques.Text.Equals("") && !comboBoxModeles.Text.Equals("") && listeOptions != null && listeOptions.Count > 0)
            {
                WCFUtils.ServiceClient client   = new WCFUtils.ServiceClient();
                WCFUtils.Option[]      options  = new WCFUtils.Option[listeOptions.Count];
                WCFUtils.Vehicule      vehicule = new WCFUtils.Vehicule();

                if (listeOptions.Count > 0)
                {
                    using (MySqlConnection cn = new MySqlConnection(Program._cn))
                    {
                        cn.Open();
                        for (int i = 0; i < listeOptions.Count; i++)
                        {
                            MySqlCommand    cmd = new MySqlCommand("select caracteristique, prix, NOM_OPTION from toption where NOM_OPTION = '" + listeOptions[i].Nom + "'", cn);
                            MySqlDataReader dr  = cmd.ExecuteReader();
                            while (dr.Read())
                            {
                                options[i] = new WCFUtils.Option {
                                    Caracteristique = dr["caracteristique"].ToString(), Nom = dr["NOM_OPTION"].ToString(), Prix = Convert.ToInt32(dr["prix"])
                                };
                                vehicule.Options = options;
                            }
                            dr.Close();
                        }
                    }
                }
                vehicule.Marque    = comboBoxMarques.Text;
                vehicule.Categorie = comboBoxTypes.Text;
                vehicule.Model     = comboBoxModeles.Text;
                SelectClient select = new SelectClient(vehicule);
                select.Show();
                this.Dispose();
            }
            else
            {
                MessageBox.Show("Veuillez remplir tous les champs", "Erreur",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }