Example #1
0
        private void btnAjouter_Click(object sender, EventArgs e)
        {
            fou.nom     = textBoxNom.Text;
            fou.email   = textBoxEmail.Text;
            fou.adresse = richTextBoxAdresse.Text;
            fou.phone   = textBoxTel.Text;

            if (btnAjouter.Text == "Ajouter" && fou.id_fournisseur == 0)
            {
                if (textBoxEmail.Text == "" || textBoxNom.Text == "" || textBoxTel.Text == "" || richTextBoxAdresse.Text == "")
                {
                    MessageBox.Show("Vous devez  remplir tous les champs !!");
                }
                else
                {
                    if (fou.id_fournisseur > 0)
                    {
                        Fournisseurs frr = new Fournisseurs();
                        fou.id_fournisseur = frr.id_four;
                        f.add(fou);
                        MessageBox.Show("Fournisseur est ajouté !!");
                        frr.dataGridView1.DataSource = f.findAll();
                    }
                }
            }
            else
            {
                f.modifier(fou);
                MessageBox.Show("Fournisseur est modifié ");
                frr.dataGridView1.DataSource = f.findAll();
            }
        }
        private void btnSupprimer_Click(object sender, EventArgs e)
        {
            Fournisseur f = new Fournisseur();
            FournisseurServiceWCFClient client = new FournisseurServiceWCFClient();

            f.id_fournisseur = Convert.ToInt32(dataGridView1.CurrentRow.Cells[2].Value.ToString());
            if (f.id_fournisseur > 0)
            {
                DialogResult answer = MessageBox.Show("Voulez vous vraiment supprimer le fournisseur ?",
                                                      "Supprimer fournisseur", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                switch (answer)
                {
                case DialogResult.Yes:
                    f.nom     = dataGridView1.CurrentRow.Cells[3].Value.ToString();
                    f.phone   = dataGridView1.CurrentRow.Cells[4].Value.ToString();
                    f.email   = dataGridView1.CurrentRow.Cells[1].Value.ToString();
                    f.adresse = dataGridView1.CurrentRow.Cells[0].Value.ToString();
                    client.delete(f.id_fournisseur);
                    MessageBox.Show("Fournisseur est supprimé");
                    dataGridView1.DataSource = client.findAll();
                    break;

                case DialogResult.No:
                    break;
                }
            }
        }
        private void Fournisseurs_Load(object sender, EventArgs e)
        {
            this.dataGridView1.SelectionMode  = DataGridViewSelectionMode.FullRowSelect;
            this.dataGridView1.MultiSelect    = false;
            dataGridView1.AutoGenerateColumns = false;
            FournisseurServiceWCFClient f = new FournisseurServiceWCFClient();

            dataGridView1.DataSource = f.findAll();
            Clear();
        }
        private void btnRechercher_Click(object sender, EventArgs e)
        {
            FournisseurServiceWCFClient client = new FournisseurServiceWCFClient();
            string nom = textBoxRecherche.Text;

            dataGridView1.DataSource = client.findNom(nom);
            if (textBoxRecherche.Text == " ")
            {
                dataGridView1.DataSource = client.findAll();
            }
        }