private int Keys; public SocieteDictionary() { this.SocD =new Dictionary<int, Personne>(); this.Keys = 1; } public delegate bool DelegVerif(Personne p); public delegate int DelegCount(); public delegate int DelegKeys(Personne p);
public void AddPersonneDictionary(Personne p)
{ DelegVerif d = new DelegVerif(Verification); if (d(p)) { throw new SocieteExecption("Erreur: Valeur Existe !!!"); } else { this.SocD.Add(this.Keys, p); this.Keys++; } } public void DisplayDictionary() { DelegCount d = new DelegCount(CountDectionary); if (d()==0) { throw new SocieteExecption("Erreur: Societer vide"); } else { foreach (KeyValuePair<int ,Personne> kvp in this.SocD) { Console.WriteLine("Cl� : {0}, Personne : {1}", kvp.Key, kvp.Value); } } } public void Identification(Personne p) { DelegVerif d = new DelegVerif(Verification); if (d(p)) { if (p is Homme) { Homme m = (Homme)p; Console.WriteLine("Homme !!!"); Console.WriteLine(m.GetJobs()); } else { Femme f = (Femme)p; Console.WriteLine("Femme !!!"); Console.WriteLine(f.GetNbrEnfant()); } } else { throw new SocieteExecption("Erreur: Donne n'existe pas"); } } public Personne SearchPersonne(Personne p) { DelegVerif d = new DelegVerif(Verification); if (d(p)) { foreach (KeyValuePair<int, Personne> kvp in this.SocD) { if (kvp.Value.Equals(p)) { return kvp.Value; } } } return null; } public void UpdatePersonneDictionary(Personne p1,Personne p2) { int cle = 0; DelegVerif d = new DelegVerif(Verification); if (d(p1)) { foreach (KeyValuePair<int, Personne> kvp in this.SocD) { if (kvp.Value.Equals(p1)) { cle = kvp.Key; } } this.SocD.Remove(cle); this.SocD.Add(cle, p2); } else { throw new SocieteExecption("Erreur: Donn� n'existe pas !!!"); } } public bool Verification(Personne p) { if (this.SocD.ContainsValue(p)) { return true; } return false; } public void DeletePersonneDictionary(Personne p) { DelegKeys d =new DelegKeys(RecupKeyPersonne); DelegVerif d1 = new DelegVerif(Verification); if (d1(p)) { this.SocD.Remove(d(p)); } } public int RecupKeyPersonne(Personne p) { foreach (KeyValuePair<int, Personne> kvp in this.SocD) { if (kvp.Value.Equals(p)) { return kvp.Key; } } return 0; }