public void SupprimerLigneFacture()
        {
            if (dataGridView1.Rows.Count == 0)
            {
                MessageBox.Show("Liste vide!", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                DialogResult rsl = MessageBox.Show("Voulez-vous vraiment éliminer ce produit de la facture?", "Supprimer Produit", MessageBoxButtons.YesNo);
                if (rsl == DialogResult.Yes)
                {
                    int          numero_ligneFacture = Convert.ToInt16(dataGridView1.CurrentRow.Cells[0].Value.ToString());
                    LigneFacture L = new LigneFacture(numero_ligneFacture);
                    L.SupprimerLigneFacture();
                    this.lignefactureTableAdapter.Fill(this.gestioncommercialeDataSet1.lignefacture);

                    Selection();
                }
            }
        }
        private void pictureBox9_Click(object sender, EventArgs e)
        {
            if (textBox2.Text == "" || textBox7.Text == "")
            {
                MessageBox.Show("Vous devez remplir les champs vides!", "Champs vides", MessageBoxButtons.OK);
                label1.ForeColor = Color.Black;
                label2.ForeColor = Color.Black;
                if (textBox2.Text == "")
                {
                    label7.ForeColor = Color.Red;
                }
                if (textBox7.Text == "")
                {
                    label8.ForeColor = Color.Red;
                }
            }
            else
            {
                Produit_codeProduit = textBox2.Text;
                // string libelle_produit;
                //double TVA_produit;
                //double remise_produit;
                quantite        = Convert.ToInt16(textBox7.Text);
                montant_Produit = quantite * prix_vente_produit;


                LigneFacture L = new LigneFacture(numero_ligneFacture);
                L.ModifierLigneFacture(Produit_codeProduit, quantite, montant_Produit, Facture_numeroFacture);
                this.lignefactureTableAdapter.Fill(this.gestioncommercialeDataSet1.lignefacture);

                textBox2.Text  = "";
                textBox7.Text  = "";
                panel1.Visible = false;

                Selection();
            }
        }
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox8.Text == "")
            {
                MessageBox.Show("Vous devez remplir les champs vides!", "Champs vides", MessageBoxButtons.OK);
                label1.ForeColor = Color.Black;
                label2.ForeColor = Color.Black;
                label9.ForeColor = Color.Black;
                label4.ForeColor = Color.Black;
                label5.ForeColor = Color.Black;
                label6.ForeColor = Color.Black;
                label8.ForeColor = Color.Black;
                label9.ForeColor = Color.Black;
                if (textBox1.Text == "")
                {
                    label1.ForeColor = Color.Red;
                }
                if (textBox8.Text == "")
                {
                    label9.ForeColor = Color.Red;
                }
            }
            else
            {
                if (textBox5.Text == "")
                {
                    textBox5.Text = "0";
                }
                if (textBox6.Text == "")
                {
                    textBox6.Text = "0";
                }



                int numero_Facture = Convert.ToInt16(textBox1.Text);

                string date_Facture = dateTimePicker1.Value.ToString("dd / MM / yyyy");

                double timbre_Facture = Convert.ToDouble(textBox5.Text);
                double remise_Facture = Convert.ToDouble(textBox6.Text);


                double montantHT_Facture  = Convert.ToDouble(textBox3.Text);
                double montantTTC_Facture = Convert.ToDouble(textBox4.Text);

                int Client_codeClient = Convert.ToInt16(textBox8.Text);

                string statut_Facture;
                if (radioButton1.Checked == true)
                {
                    statut_Facture = radioButton1.Text;
                }
                else
                {
                    statut_Facture = radioButton2.Text;
                }

                Facture F = new Facture(numero_Facture, date_Facture, timbre_Facture, remise_Facture, montantHT_Facture, montantTTC_Facture, statut_Facture, Client_codeClient);
                F.creerFacture();
                f.factureTableAdapter.Fill(f.gestioncommercialeDataSet1.facture);

                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    //numero_ligneFacture : numero de la ligne_factue dans la base

                    string          MyConString = "SERVER=localhost;" + "DATABASE=gestioncommerciale;" + "UID=root;" + "PASSWORD=freedomity;";
                    MySqlConnection connection  = new MySqlConnection(MyConString);
                    MySqlCommand    cmd         = connection.CreateCommand();
                    cmd.CommandText = "select count(*) from lignefacture"; //where Facture_numeroFacture = " + Facture_numeroFacture;
                    connection.Open();
                    int num = Convert.ToInt32(cmd.ExecuteScalar());
                    connection.Close();
                    if (num != 0)
                    {
                        cmd.CommandText = "select max(numero_ligneFacture) from lignefacture;"; //where Facture_numeroFacture = " + Facture_numeroFacture;
                        connection.Open();
                        numero_ligneFacture = Convert.ToInt32(cmd.ExecuteScalar()) + 1;
                        connection.Close();
                    }
                    else
                    {
                        numero_ligneFacture = 1;
                    }
                    dataGridView1.Rows[i].Cells[8].Value = numero_ligneFacture;
                    numero_ligneFacture   = Convert.ToInt16(dataGridView1.Rows[i].Cells[8].Value);
                    Produit_codeProduit   = dataGridView1.Rows[i].Cells[1].Value.ToString();
                    quantite              = Convert.ToInt16(dataGridView1.Rows[i].Cells[6].Value);
                    montant_Produit       = Convert.ToDouble(dataGridView1.Rows[i].Cells[7].Value);
                    Facture_numeroFacture = numero_Facture;

                    LigneFacture L = new LigneFacture(numero_ligneFacture, Produit_codeProduit, quantite, montant_Produit, Facture_numeroFacture);
                    L.AjouterLigneFacture();
                }

                //this.lignefactureTableAdapter.Fill(this.gestioncommercialeDataSet1.lignefacture);

                Hide();
                ac.Enabled = true;
            }
        }
        private void pictureBox6_Click_1(object sender, EventArgs e)
        {
            if (textBox2.Text == "" || textBox7.Text == "")
            {
                MessageBox.Show("Vous devez remplir les champs vides!", "Champs vides", MessageBoxButtons.OK);
                label7.ForeColor = Color.Black;
                label8.ForeColor = Color.Black;
                if (textBox2.Text == "")
                {
                    label7.ForeColor = Color.Red;
                }
                if (textBox7.Text == "")
                {
                    label8.ForeColor = Color.Red;
                }
            }
            else
            {
                //numero_ligneFacture
                int numero_ligneFacture;
                if (dataGridView1.Rows.Count == 0)
                {
                    numero_ligneFacture = 1;
                }
                else
                {
                    string          MyConString = "SERVER=localhost;" + "DATABASE=gestioncommerciale;" + "UID=root;" + "PASSWORD=freedomity;";
                    MySqlConnection connection  = new MySqlConnection(MyConString);
                    MySqlCommand    cmd         = connection.CreateCommand();
                    cmd.CommandText = "select max(numero_ligneFacture) from lignefacture";
                    connection.Open();
                    numero_ligneFacture = Convert.ToInt32(cmd.ExecuteScalar()) + 1;
                    connection.Close();
                }


                string Produit_codeProduit = textBox2.Text;


                //selectionner le prix produit
                string          MyConString2 = "SERVER=localhost;" + "DATABASE=gestioncommerciale;" + "UID=root;" + "PASSWORD=freedomity;";
                MySqlConnection connection2  = new MySqlConnection(MyConString2);
                MySqlCommand    cmd2         = connection2.CreateCommand();
                cmd2.CommandText = "select prix_vente_produit from produit where code_produit ='" + Produit_codeProduit + "';";
                connection2.Open();
                prix_vente_produit = Convert.ToInt32(cmd2.ExecuteScalar());
                connection2.Close();
                //selectionner le TVA produit
                cmd2.CommandText = "select TVA_produit from produit where code_produit ='" + Produit_codeProduit + "';";
                connection2.Open();
                TVA_produit = Convert.ToInt32(cmd2.ExecuteScalar());
                connection2.Close();
                //selectionner le remise produit
                cmd2.CommandText = "select remise_produit from produit where code_produit ='" + Produit_codeProduit + "';";
                connection2.Open();
                remise_produit = Convert.ToInt32(cmd2.ExecuteScalar());
                connection2.Close();


                int    quantite              = Convert.ToInt16(textBox7.Text);
                double montant_Produit       = quantite * prix_vente_produit;
                int    Facture_numeroFacture = Convert.ToInt16(textBox1.Text);

                //recuperer le montant HT de la facture
                montantHT_Facture += montant_Produit;
                textBox3.Text      = montantHT_Facture.ToString();
                //recuperer le montant TTC
                montantTTC_Facture = montantHT_Facture + ((TVA_produit * montantHT_Facture) / 100);
                textBox4.Text      = montantTTC_Facture.ToString();



                LigneFacture L = new LigneFacture(numero_ligneFacture, Produit_codeProduit, quantite, montant_Produit, Facture_numeroFacture);
                L.AjouterLigneFacture();
                this.lignefactureTableAdapter.Fill(this.gestioncommercialeDataSet1.lignefacture);

                textBox2.Text  = "";
                textBox7.Text  = "";
                panel1.Visible = false;

                Selection();
            }
        }