Example #1
0
        /// <summary>
        /// Lecture du fichier txt qui sert de BDD et alimente Liste.Registre
        /// </summary>
        /// <param name="liste">Liste à alimenter</param>
        public static void Lecture(ListeContact liste)
        {
            StreamReader reader = null;

            if (!File.Exists("database.txt"))
            {
                File.Create("database.txt");
            }
            try
            {
                reader = new StreamReader("database.txt");
                string data = null;
                while ((data = reader.ReadLine()) != null)
                {
                    Contact cont = Utilitaire.ParseLigne(data);
                    liste.AjouterContact(cont);
                }
            }
            catch (IOException e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
Example #2
0
 /// <summary>
 /// Méthode IO pour écrire le fichier database.txt
 /// </summary>
 /// <param name="liste">Liste à écrire dans le fichier</param>
 public static void Ecriture(ListeContact liste)
 {
     using (StreamWriter writer = new StreamWriter("database.txt"))
     {
         foreach (Contact contact in liste.Registre)
         {
             writer.WriteLine(Utilitaire.FormerLigne(contact));
         }
     }
 }
Example #3
0
 /// <summary>
 /// Méthode pour vérifier la présence du contact dans le registre
 /// </summary>
 /// <param name="contact">Contact à vérifier</param>
 /// <returns>Booléen</returns>
 public bool VerifierContact(Contact contact)
 {
     for (int i = 0; i < Registre.Count; i++)
     {
         if (Registre[i].Equals(contact))
         {
             throw new ContactDejaPresentException("Contact déjà présent", Registre[i], i);
         }
     }
     if (!Utilitaire.ValiderEmail(contact.Email))
     {
         throw new EmailInvalideException("Mauvais format d'email", contact.Email);
     }
     if (!Utilitaire.ValiderCP(contact.Codepostal))
     {
         throw new CodePostalException("Mauvais format de code postal", contact.Codepostal);
     }
     if (!Utilitaire.ValiderNoTel(contact.NoTel))
     {
         throw new TelephoneInvalideException("Mauvais numéro de téléphone", contact.NoTel);
     }
     return(true);
 }