Click here to Skip to main content
15,881,413 members
Home / Discussions / C#
   

C#

 
GeneralRe: User Control function C# Pin
Ralf Meier1-Aug-20 22:49
mveRalf Meier1-Aug-20 22:49 
Questioncall a jquery function inside html returned by ajax Pin
Peq 227-Jul-20 21:36
Peq 227-Jul-20 21:36 
AnswerRe: call a jquery function inside html returned by ajax Pin
OriginalGriff27-Jul-20 22:02
mveOriginalGriff27-Jul-20 22:02 
QuestionAdd a listview cell Pin
ago248627-Jul-20 1:34
ago248627-Jul-20 1:34 
AnswerRe: Add a listview cell Pin
OriginalGriff27-Jul-20 2:28
mveOriginalGriff27-Jul-20 2:28 
GeneralRe: Add a listview cell Pin
ago248627-Jul-20 2:31
ago248627-Jul-20 2:31 
GeneralRe: Add a listview cell Pin
OriginalGriff27-Jul-20 2:59
mveOriginalGriff27-Jul-20 2:59 
GeneralRe: Add a listview cell Pin
ago248627-Jul-20 3:18
ago248627-Jul-20 3:18 
thank you sir I followed your advice and I saw that the problem came from the fact that at the first addition my variables total_achat and i always remain 0. Frankly I do not know why?.



C#
private void BtnAjouter_Click(object sender, EventArgs e)
        {
            double total;
            decimal total_achat;
           
            //si les champs sont vides
            if (Lbl_Affich_Designation.Text == "" || Lbl_Affich_PrixUnitaire.Text == "" || TxtQteCmd.Text == "" || Lbl_affich_TxtQteStock.Text == "" || CmbRef_Produit.Text == "")
            {
                MessageBox.Show("Rassurez vous que tous les champs ont bien été rempli.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                //Vérifier si la valeur saisie est numeric
                if (CmbRef_Produit.Text != "")
                {
                    //Vérifier si la commande est inferieur ou egale au stock
                    double a = 0;
                    double b = 0;
                    double c;
                    int nbprod;
                    //Convertire les textBox en int
                    double.TryParse(TxtQteCmd.Text.Trim(), out a);
                    double.TryParse(Lbl_affich_TxtQteStock.Text.Trim(), out b);
                    double.TryParse(Lbl_Affich_PrixUnitaire.Text.Trim(), out c);

                    if (a <= b)
                    {
                        total = a * c;
                        total_achat = 0;
                        nbprod = 0;
                        //ADDITIONNER UNE COLONNE DU DATAGRIDVIEW
                       

                        try
                        {
            
                            

                            using (OleDbCommand cmd = d.sql_con.CreateCommand())
                            {
                                cmd.CommandText = "INSERT INTO Detail_temp (ref_det, qute_det, Designation, Prix_unitaire_HT, Prix_total_HT) VALUES (@ref_det,@qute_det,@Designation,@Prix_unitaire_HT,@Prix_total_HT)";
                                cmd.Parameters.AddWithValue("@ref_det", CmbRef_Produit.Text);
                                cmd.Parameters.AddWithValue("@qute_det", TxtQteCmd.Text);
                                cmd.Parameters.AddWithValue("@Designation", Lbl_Affich_Designation.Text);
                                cmd.Parameters.AddWithValue("@Prix_unitaire_HT", Lbl_Affich_PrixUnitaire.Text);
                                cmd.Parameters.AddWithValue("@Prix_total_HT", total);
                              
                                d.sql_con.Open();

                                cmd.ExecuteNonQuery();
            
                                dataGridView1.DataSource = d.DT;
                                cmd.Dispose();
                                d.sql_con.Close();
                            }

                            
                           
                        }
                        catch(Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                       
                        try
                        {

                           LoadDB();

                            //ADDITIONNER UNE COLONNE DU DATAGRIDVIEW
                            for (int i = 0; i < listView1.Items.Count; i++) //Car tu fais une infériorité stricte
                            {
                                total_achat += Convert.ToDecimal(listView1.Items[i].SubItems[4].Text);
                                nbprod++;
                                LblNbProd.Text = nbprod.ToString();

                            }



                            //label3.Text = total.ToString();
                            Lbl_Affich_TotalCmd.Text = total_achat.ToString();//convertir total_achat en string pour pouvoir l'afficher dans le textbox
                            Ajouter(CmbRef_Produit.Text, TxtQteCmd.Text, Lbl_Affich_Designation.Text, Lbl_Affich_PrixUnitaire.Text, total.ToString()); //AFficher dans la listView
                            Vider();
                            TxtQteCmd.Text = "1";
                            //SupDetail_Temp();
                           
                            
                        }
                       
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                            d.sql_con.Close();
                        }

                    }
                    else
                    {
                        MessageBox.Show("Veuillez verifier le stock du produit!!!", "Problème avec le stock", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("Caractères non autorisés", "Problème de saisie", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }

        }



with the datagridview I have no problem.


C#
private void BtnAjouter_Click(object sender, EventArgs e)
        {
            double total;
            decimal total_achat;
           
            //si les champs sont vides
            if (Lbl_Affich_Designation.Text == "" || Lbl_Affich_PrixUnitaire.Text == "" || TxtQteCmd.Text == "" || Lbl_affich_TxtQteStock.Text == "" || CmbRef_Produit.Text == "")
            {
                MessageBox.Show("Rassurez vous que tous les champs ont bien été rempli.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                //Vérifier si la valeur saisie est numeric
                if (CmbRef_Produit.Text != "")
                {
                    //Vérifier si la commande est inferieur ou egale au stock
                    double a = 0;
                    double b = 0;
                    double c;
                    int nbprod;
                    //Convertire les textBox en int
                    double.TryParse(TxtQteCmd.Text.Trim(), out a);
                    double.TryParse(Lbl_affich_TxtQteStock.Text.Trim(), out b);
                    double.TryParse(Lbl_Affich_PrixUnitaire.Text.Trim(), out c);

                    if (a <= b)
                    {
                        total = a * c;
                        total_achat = 0;
                        nbprod = 0;
                        //ADDITIONNER UNE COLONNE DU DATAGRIDVIEW
                       

                        try
                        {
            
                            

                            using (OleDbCommand cmd = d.sql_con.CreateCommand())
                            {
                                cmd.CommandText = "INSERT INTO Detail_temp (ref_det, qute_det, Designation, Prix_unitaire_HT, Prix_total_HT) VALUES (@ref_det,@qute_det,@Designation,@Prix_unitaire_HT,@Prix_total_HT)";
                                cmd.Parameters.AddWithValue("@ref_det", CmbRef_Produit.Text);
                                cmd.Parameters.AddWithValue("@qute_det", TxtQteCmd.Text);
                                cmd.Parameters.AddWithValue("@Designation", Lbl_Affich_Designation.Text);
                                cmd.Parameters.AddWithValue("@Prix_unitaire_HT", Lbl_Affich_PrixUnitaire.Text);
                                cmd.Parameters.AddWithValue("@Prix_total_HT", total);
                              
                                d.sql_con.Open();

                                cmd.ExecuteNonQuery();
            
                                dataGridView1.DataSource = d.DT;
                                cmd.Dispose();
                                d.sql_con.Close();
                            }

                            
                           
                        }
                        catch(Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                       
                        try
                        {

                           LoadDB();

                            //ADDITIONNER UNE COLONNE DU DATAGRIDVIEW
                           for (int i = 0; i < dataGridView1.Rows.Count; i++) //Car tu fais une infériorité stricte
                            {
                                total_achat += Convert.ToDecimal(dataGridView1.Rows[i].Cells[4].Value);
                                nbprod++;
                                LblNbProd.Text = nbprod.ToString();

                            }



                            //label3.Text = total.ToString();
                            Lbl_Affich_TotalCmd.Text = total_achat.ToString();//convertir total_achat en string pour pouvoir l'afficher dans le textbox
                            Ajouter(CmbRef_Produit.Text, TxtQteCmd.Text, Lbl_Affich_Designation.Text, Lbl_Affich_PrixUnitaire.Text, total.ToString()); //AFficher dans la listView
                            Vider();
                            TxtQteCmd.Text = "1";
                            //SupDetail_Temp();
                           
                            
                        }
                       
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                            d.sql_con.Close();
                        }

                    }
                    else
                    {
                        MessageBox.Show("Veuillez verifier le stock du produit!!!", "Problème avec le stock", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("Caractères non autorisés", "Problème de saisie", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }

        }

GeneralRe: Add a listview cell Pin
OriginalGriff27-Jul-20 3:37
mveOriginalGriff27-Jul-20 3:37 
GeneralRe: Add a listview cell Pin
ago248627-Jul-20 4:08
ago248627-Jul-20 4:08 
GeneralRe: Add a listview cell Pin
OriginalGriff27-Jul-20 4:38
mveOriginalGriff27-Jul-20 4:38 
GeneralRe: Add a listview cell Pin
ago248627-Jul-20 4:45
ago248627-Jul-20 4:45 
GeneralRe: Add a listview cell Pin
ago248627-Jul-20 4:53
ago248627-Jul-20 4:53 
Questionsaving a Word Doc from address bar in .net/C# Pin
Pita3225-Jul-20 5:50
Pita3225-Jul-20 5:50 
AnswerRe: saving a Word Doc from address bar in .net/C# Pin
Gerry Schmitz25-Jul-20 7:19
mveGerry Schmitz25-Jul-20 7:19 
GeneralRe: saving a Word Doc from address bar in .net/C# Pin
DerekT-P25-Jul-20 9:22
professionalDerekT-P25-Jul-20 9:22 
GeneralRe: saving a Word Doc from address bar in .net/C# Pin
Gerry Schmitz25-Jul-20 9:58
mveGerry Schmitz25-Jul-20 9:58 
GeneralRe: saving a Word Doc from address bar in .net/C# Pin
DerekT-P25-Jul-20 11:38
professionalDerekT-P25-Jul-20 11:38 
AnswerRe: saving a Word Doc from address bar in .net/C# Pin
Richard MacCutchan25-Jul-20 21:59
mveRichard MacCutchan25-Jul-20 21:59 
GeneralRe: saving a Word Doc from address bar in .net/C# Pin
Pita3226-Jul-20 6:37
Pita3226-Jul-20 6:37 
GeneralRe: saving a Word Doc from address bar in .net/C# Pin
Richard MacCutchan26-Jul-20 6:46
mveRichard MacCutchan26-Jul-20 6:46 
GeneralRe: saving a Word Doc from address bar in .net/C# Pin
Richard Deeming26-Jul-20 23:50
mveRichard Deeming26-Jul-20 23:50 
GeneralRe: saving a Word Doc from address bar in .net/C# Pin
Richard MacCutchan27-Jul-20 0:03
mveRichard MacCutchan27-Jul-20 0:03 
AnswerRe: saving a Word Doc from address bar in .net/C# Pin
Richard Deeming26-Jul-20 23:51
mveRichard Deeming26-Jul-20 23:51 
QuestionGet List Of SQL Foreign Keys Using C# Pin
Kevin Marois24-Jul-20 6:46
professionalKevin Marois24-Jul-20 6:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.