Ejemplo n.º 1
0
        //methode pour verifier les informations avant les sauvgarder
        private bool SauvgarderContact(Contact obj)
        {
            try
            {
                if (Utilitaire.VerefierChampe(txtFnam))
                {
                    obj.Fname = txtFnam.Text;
                }
                if (Utilitaire.VerefierChampe(txtLnam))
                {
                    obj.Lname = txtLnam.Text;
                }

                obj.FirstAdd = txtAddress1.Text;
                obj.City     = txtCity.Text;
                obj.Country  = txtCountry.Text;


                if (Utilitaire.IsValidTel(txtPhone.Text))
                {
                    obj.Phone = txtPhone.Text;
                }
                if (Utilitaire.IsValidEmail(txtEmail.Text))
                {
                    obj.Email = txtEmail.Text;
                }
                if (Utilitaire.IsValidCodePostal(txtzip.Text))
                {
                    obj.Zip = txtzip.Text;
                }
                return(true);
            }

            catch (TxtVideException)
            {
                return(false);
            }
            catch (InvalidTelException)
            {
                return(false);
            }
            catch (InvalidEmailException)
            {
                return(false);
            }
            catch (InvalidCpException)
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        // sauvgarder Le changement si il y en a ou ajouter nouveu contact a la listBox et a la RegistreContact
        private void BtnSave_Click(object sender, EventArgs e)
        {
            //cree nouveu contact
            Contact ncontact = new Contact();

            //verifier si les information bien saisi
            if (SauvgarderContact(ncontact))
            {
                try
                {
                    //verifier si le nouveu contact existe deja
                    if (Utilitaire.VerefierDoublan(ncontact, Lste.LstPerson))
                    {
                        //verifier si pas de contact selectioné on l'ajoute
                        if (listBox.SelectedIndex <= -1)
                        {
                            Lste.AjouterContact(ncontact);
                            listBox.Items.Add(ncontact.ToString());
                            Clean();
                            StatuButton(false);
                            ReadOnly(true);
                            MessageBox.Show(" the Contact has been Added");
                        }
                        else
                        {
                            //si il y a contact selectionné on le modifie
                            Lste.LstPerson[listBox.SelectedIndex] = ncontact;
                            listBox.Items[listBox.SelectedIndex]  = Lste.LstPerson[listBox.SelectedIndex].ToString();
                            Clean();
                            btnDel.Enabled  = false;
                            btnEdit.Enabled = false;
                            ReadOnly(true);
                            MessageBox.Show("Le contact a été Modifié !");
                            listBox.ClearSelected();
                        }
                    }
                }
                catch (ContatExisteException) { }
            }
        }