Example #1
0
        private void btAjouter_Click(object sender, EventArgs e)
        {
            string nom       = txtNom.Text;
            string prenom    = txtPren.Text;
            string telephone = txtTel.Text;
            int    id        = this.id;

            if (!AttributNullTropLong(nom, "nom", 30) && !AttributNullTropLong(prenom, "prenom", 30) && !AttributNullTropLong(telephone, "telephone", 20))
            {
                if (this.estModification)
                {
                    if (BdD.MettreAjour(id, nom, prenom, telephone))
                    {
                        MessageBox.Show("Le contact a été mis-à-jour avec succès !", "Opération réussie", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Impossible de mettre à jour  le contact d'identifiant " + id, "Operation a échouée", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    BdD.ajouterContact(txtNom.Text, txtPren.Text, txtTel.Text);
                    MessageBox.Show("Le contact a été enregistré avec succès !", "Opération réussie", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
        private void btnSupprimer_Click(object sender, EventArgs e)
        {
            bool possibleSupprimer = true;

            if (lstIdentite.SelectedItems.Count == 0)
            {
                MessageBox.Show("Merci de sélectionner un élément à supprimer", "Aucune sélection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                possibleSupprimer = false;
            }


            if (possibleSupprimer && DialogResult.Yes == MessageBox.Show("êtes vous sûr de vouloir supprimer ce contact ?", "suppression", MessageBoxButtons.YesNo))
            {
                int id = lesId[lstIdentite.SelectedIndex];
                if (BdD.supprimerContact(id))
                {
                    MettreAJourListe();
                    lesId.Clear();
                    MessageBox.Show("Contact d'identifiant " + id + " a été supprimer avec succès ! ", "Operation réussie", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Impossible de supprimer le contact d'identifiant " + id, "Operation a échouée", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private void MettreAJourListe()
        {
            List <Contact> lc = BdD.lireContacts(); //appel du modèle

            RemplirListeContacts(lc);               // appel de la vue
            lc.Clear();
        }
Example #4
0
        private void afficherFormulaireContact(Contact contact)
        {
            FormulaireContact formulaireContact = new FormulaireContact(contact);

            DialogResult result = formulaireContact.ShowDialog();

            if (result == DialogResult.OK)
            {
                mettreAJourListe();
                if (!formulaireContact.Ajout)
                {
                    //on selectionne le contact mis à jour dans la liste
                    Contact contactMisAJour = BdD.lireContact(contact.Id);
                    if (contactMisAJour != null)
                    {
                        lstIdentite.SelectedIndex = lesId.IndexOf(contactMisAJour.Id);
                    }
                }
                else
                {
                    //on selectionne le nouveau contact dans le liste
                    lstIdentite.SelectedIndex = lesId.IndexOf(BdD.lireDernierIdDeContactCrée());
                }
            }
            else if (result == DialogResult.Abort)
            {
                MessageBox.Show(
                    "Le contact n'a pas pu être " + (formulaireContact.Ajout ? "crée" : "mis à jour"),
                    "Erreur",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );
            }
        }
Example #5
0
        private void modifierButton_Click(object sender, EventArgs e)
        {
            if (lstIdentite.SelectedIndex < 0)
            {
                return;
            }
            int     contactId = lesId[lstIdentite.SelectedIndex];
            Contact contact   = BdD.lireContact(contactId);

            afficherFormulaireContact(contact);
        }
Example #6
0
 static void Main()
 {
     if (BdD.seConnecterALaBase() == false)
     {
         MessageBox.Show("Impossible de se connecter à la base de données !",
                         "ExempleBdD",
                         MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
         return;
     }
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     Application.Run(new FenetreRepertoire());
     BdD.seDeconnecterDeLaBase();
 }
        private void btnMetteAjour_Click(object sender, EventArgs e)
        {
            int numero = SiPossible("modifier");

            if (numero >= 0)
            {
                int     id = lesId[numero];
                Contact c  = BdD.lireContact(id);
                if (c != null)
                {
                    this.Hide();
                    FenetreRepertoire fenetreRepertoire = new FenetreRepertoire(c.Id, c.Nom, c.Prenom, c.Telephone);
                    fenetreRepertoire.ShowDialog();
                    fenetreRepertoire.Closed += (s, args) => this.Close();
                }
            }
        }
        private void btnDetail_Click(object sender, EventArgs e)
        {
            int numero = SiPossible("afficher les détails");

            if (numero >= 0)
            {
                int     id = lesId[numero];
                Contact c  = BdD.lireContact(id);
                if (c != null)
                {
                    this.Hide();
                    Detail detail = new Detail(c.Id, c.Nom, c.Prenom, c.Telephone);
                    detail.ShowDialog();
                    detail.Closed += (s, args) => this.Close();
                }
            }
        }
Example #9
0
        private void lstIdentite_SelectedIndexChanged(object sender, EventArgs e)
        {
            int numero = lstIdentite.SelectedIndex;

            effacerDetails();
            if (numero >= 0)
            {
                int     id = lesId[numero];
                Contact c  = BdD.lireContact(id);
                if (c != null)
                {
                    modifierDetails(c.Nom, c.Prenom, c.Telephone);
                    activerModifierSupprimer();
                }
            }
            else
            {
                desactiverModifierSupprimer();
            }
        }
Example #10
0
        private void supprimerButton_Click(object sender, EventArgs e)
        {
            if (lstIdentite.SelectedIndex < 0)
            {
                return;
            }

            if (MessageBox.Show(
                    "Souhaitez-vous supprimer " + txtNom.Text + " " + txtPren.Text + " du répertoire ?",
                    "Supprimer un contact",
                    MessageBoxButtons.OKCancel,
                    MessageBoxIcon.Warning
                    ) == DialogResult.OK
                )
            {
                int contactId = lesId[lstIdentite.SelectedIndex];
                BdD.supprimerContact(contactId);
                mettreAJourListe();
                effacerDetails();
                desactiverModifierSupprimer();
            }
        }