Click here to Skip to main content
14,741,685 members
Home » Discussions » C#
   

C#

 
GeneralRe: User Control function C# Pin
Ralf Meier1-Aug-20 23:49
professionalRalf Meier1-Aug-20 23:49 
Questioncall a jquery function inside html returned by ajax Pin
taiielmehdi00127-Jul-20 22:36
Membertaiielmehdi00127-Jul-20 22:36 
AnswerRe: call a jquery function inside html returned by ajax Pin
OriginalGriff27-Jul-20 23:02
mveOriginalGriff27-Jul-20 23:02 
QuestionAdd a listview cell Pin
ago248627-Jul-20 2:34
Memberago248627-Jul-20 2:34 
AnswerRe: Add a listview cell Pin
OriginalGriff27-Jul-20 3:28
mveOriginalGriff27-Jul-20 3:28 
GeneralRe: Add a listview cell Pin
ago248627-Jul-20 3:31
Memberago248627-Jul-20 3:31 
GeneralRe: Add a listview cell Pin
OriginalGriff27-Jul-20 3:59
mveOriginalGriff27-Jul-20 3:59 
GeneralRe: Add a listview cell Pin
ago248627-Jul-20 4:18
Memberago248627-Jul-20 4: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?.



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.


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 4:37
mveOriginalGriff27-Jul-20 4:37 
GeneralRe: Add a listview cell Pin
ago248627-Jul-20 5:08
Memberago248627-Jul-20 5:08 
GeneralRe: Add a listview cell Pin
OriginalGriff27-Jul-20 5:38
mveOriginalGriff27-Jul-20 5:38 
GeneralRe: Add a listview cell Pin
ago248627-Jul-20 5:45
Memberago248627-Jul-20 5:45 
GeneralRe: Add a listview cell Pin
ago248627-Jul-20 5:53
Memberago248627-Jul-20 5:53 
Questionsaving a Word Doc from address bar in .net/C# Pin
Pita3225-Jul-20 6:50
MemberPita3225-Jul-20 6:50 
AnswerRe: saving a Word Doc from address bar in .net/C# Pin
Gerry Schmitz25-Jul-20 8:19
mveGerry Schmitz25-Jul-20 8:19 
GeneralRe: saving a Word Doc from address bar in .net/C# Pin
DerekT-P25-Jul-20 10:22
professionalDerekT-P25-Jul-20 10:22 
GeneralRe: saving a Word Doc from address bar in .net/C# Pin
Gerry Schmitz25-Jul-20 10:58
mveGerry Schmitz25-Jul-20 10:58 
GeneralRe: saving a Word Doc from address bar in .net/C# Pin
DerekT-P25-Jul-20 12:38
professionalDerekT-P25-Jul-20 12:38 
AnswerRe: saving a Word Doc from address bar in .net/C# Pin
Richard MacCutchan25-Jul-20 22:59
mveRichard MacCutchan25-Jul-20 22:59 
GeneralRe: saving a Word Doc from address bar in .net/C# Pin
Pita3226-Jul-20 7:37
MemberPita3226-Jul-20 7:37 
GeneralRe: saving a Word Doc from address bar in .net/C# Pin
Richard MacCutchan26-Jul-20 7:46
mveRichard MacCutchan26-Jul-20 7:46 
GeneralRe: saving a Word Doc from address bar in .net/C# Pin
Richard Deeming27-Jul-20 0:50
mveRichard Deeming27-Jul-20 0:50 
GeneralRe: saving a Word Doc from address bar in .net/C# Pin
Richard MacCutchan27-Jul-20 1:03
mveRichard MacCutchan27-Jul-20 1:03 
AnswerRe: saving a Word Doc from address bar in .net/C# Pin
Richard Deeming27-Jul-20 0:51
mveRichard Deeming27-Jul-20 0:51 
QuestionGet List Of SQL Foreign Keys Using C# Pin
Kevin Marois24-Jul-20 7:46
professionalKevin Marois24-Jul-20 7: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.