public List <CpoBox> get_pobox_by_nfact_or_fourniss(string nfacture, string fournisseur) { List <CpoBox> llpb = new List <CpoBox>();//declaration de la list pour stockage des pobox,puis return de liste string sql = ""; if (nfacture == "" && fournisseur != "") { sql = "select * from Tpo_box where fournisseur ='" + fournisseur + "' "; } //sinfacture est vide if (fournisseur == "" && nfacture != "") { sql = "select * from Tpo_box where Nfacture='" + nfacture + "' "; } //si fournisseur est vide if (fournisseur != "" && nfacture != "") { sql = "select * from Tpo_box where fournisseur ='" + fournisseur + "' and Nfacture='" + nfacture + "' "; /*recherche par nfacture ou fournisseur*/ } cnn.Open(); commande = new SqlCommand(sql, cnn); //string bb=""; dr = commande.ExecuteReader(); while (dr.Read()) { //int i = 0; CpoBox pb = new CpoBox(); //stock what we got from database to the class pobox long l = Convert.ToInt64(dr.GetValue(10).ToString()); //get as string then turn it to long double mt = Convert.ToDouble(dr.GetValue(6).ToString()); //get as string then turn it to double pb.SetPobox(dr.GetValue(0).ToString(), dr.GetValue(1).ToString(), dr.GetValue(2).ToString(), dr.GetValue(3).ToString(), dr.GetValue(4).ToString(), dr.GetValue(5).ToString(), mt, dr.GetValue(7).ToString(), dr.GetValue(8).ToString(), dr.GetValue(9).ToString(), l, dr.GetValue(11).ToString(), dr.GetValue(12).ToString(), dr.GetValue(13).ToString(), dr.GetValue(14).ToString(), dr.GetValue(15).ToString(), dr.GetValue(16).ToString()); llpb.Add(pb);//add the pobox to the list //bb += llpb[i].direction.ToString() + "#"; } //MessageBox.Show(output); cnn.Close(); //MessageBox.Show(bb); return(llpb);//return the list }
private void bt_ajouter_Click(object sender, EventArgs e) {/*obligatoire : Fournisseur, n facture, n commande ,date facture, date recepetion, montant, devise */ string datereception = date_reception.Text.ToString(); cb_direction.Text = cb_direction.SelectedText.ToString(); string direction = cb_direction.Text; string emeteur = tb_emeteur.Text; string poboxpp = lb_poboxp2p.Text; cb_fournisseur.Text = cb_fournisseur.SelectedText.ToString(); string fourniseur = cb_fournisseur.Text; string datefacture = date_facture.Text.ToString(); double montant; //if (tb_montant.Text == "") { montant = 0; }else { montant = Convert.ToDouble(tb_montant.Text); }//si il la laisse vide long ncomande; string devise = tb_devise.Text.ToString(); string objectfact = tb_objetFacture.Text.ToString(); string nfacture = tb_nFacture.Text.ToString(); //if (tb_nComande.Text == "") { ncomande = 0; } else { ncomande = Convert.ToInt32(tb_nComande.Text); }//si il la laisse vide string dateenvoifedosa = date_envoi_fedosa.Text.ToString(); cb_restitution_fedosa.Text = cb_restitution_fedosa.SelectedText.ToString(); string restitution = cb_restitution_fedosa.Text; cb_envoi_dfi_paiement.Text = cb_envoi_dfi_paiement.SelectedText.ToString(); string envoidfi = cb_envoi_dfi_paiement.Text; string remarque = tb_remarque.Text.ToString(); string pole = tb_pole.Text.ToString(); string dateenvoidfi = date_envoi_dfi.Text.ToString(); if (datereception == "") { lb_dtReception.ForeColor = Color.Red; if (fourniseur == "") { lb_fournisseur.ForeColor = Color.Red; } if (datefacture == "") { lb_dtFacture.ForeColor = Color.Red; } if (tb_montant.Text == "") { lb_montant.ForeColor = Color.Red; } if (devise == "") { lb_devise.ForeColor = Color.Red; } if (nfacture == "") { lb_nfacture.ForeColor = Color.Red; } if (tb_nComande.Text == "") { lb_Ncomand.ForeColor = Color.Red; } MessageBox.Show("certain case essentielle sont vide", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); }//date reception vide else { if (fourniseur == "") { lb_fournisseur.ForeColor = Color.Red; if (datefacture == "") { lb_dtFacture.ForeColor = Color.Red; } if (tb_montant.Text == "") { lb_montant.ForeColor = Color.Red; } if (devise == "") { lb_devise.ForeColor = Color.Red; } if (nfacture == "") { lb_nfacture.ForeColor = Color.Red; } if (tb_nComande.Text == "") { lb_Ncomand.ForeColor = Color.Red; } MessageBox.Show("certain case essentielle sont vide", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); }//fournisseur vide else { if (datefacture == "") { lb_dtFacture.ForeColor = Color.Red; if (tb_montant.Text == "") { lb_montant.ForeColor = Color.Red; } if (devise == "") { lb_devise.ForeColor = Color.Red; } if (nfacture == "") { lb_nfacture.ForeColor = Color.Red; } if (tb_nComande.Text == "") { lb_Ncomand.ForeColor = Color.Red; } MessageBox.Show("certain case essentielle sont vide", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); }//date facture vide else { if (tb_montant.Text == "") { lb_montant.ForeColor = Color.Red; if (devise == "") { lb_devise.ForeColor = Color.Red; } if (nfacture == "") { lb_nfacture.ForeColor = Color.Red; } if (tb_nComande.Text == "") { lb_Ncomand.ForeColor = Color.Red; } MessageBox.Show("certain case essentielle sont vide", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); }//montant vide else { montant = Convert.ToDouble(tb_montant.Text); if (devise == "") { lb_devise.ForeColor = Color.Red; if (nfacture == "") { lb_nfacture.ForeColor = Color.Red; } if (tb_nComande.Text == "") { lb_Ncomand.BackColor = Color.Red; } MessageBox.Show("certain case essentielle sont vide", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); }//devise vide else { if (nfacture == "") { lb_nfacture.BackColor = Color.Red; if (tb_nComande.Text == "") { lb_Ncomand.ForeColor = Color.Red; } MessageBox.Show("certain case essentielle sont vide", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); }//nfacture vide else { if (tb_nComande.Text == "") { lb_Ncomand.ForeColor = Color.Red; MessageBox.Show("certain case essentielle sont vide", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); } //ncomande vide else { ncomande = Convert.ToInt64(tb_nComande.Text); table.Rows.Add("", datereception, direction, emeteur, poboxpp, fourniseur, datefacture, montant, devise, objectfact, nfacture, ncomande, dateenvoifedosa, restitution, envoidfi, remarque, pole, dateenvoidfi); dataGridView1.DataSource = table; if (string.Equals(envoidfi, "OUI")) { dataGridView1.Rows[tt_rows].Cells[0].Style.BackColor = Color.Green; //set column to green if envoie dfi est oui } dataGridView1.Columns[0].Width = 30; //size of acc dfi clear_textbox(); clearColor(); //clear all textbox and back to normal colors //sett objet po box pb.SetPobox(datereception, direction, emeteur, poboxpp, fourniseur, datefacture, montant, devise, objectfact, nfacture, ncomande, dateenvoifedosa, restitution, envoidfi, remarque, pole, dateenvoidfi); cc.ajout_pobox(pb);//stokage dans bas donne tt_rows++; } } } } } } } clearColor(); }