public static Don MenuRechercheDonMode <T>(bool demanderChoix) where T : Materiel { Recherche.FonctionRecherche <Don> modeDeRechercheChoisi = InteractionUtilisateur.DemanderChoixObjet <Recherche.FonctionRecherche <Don> >("Choisir le mode de recherche :", new Recherche.FonctionRecherche <Don>[] { Recherche.RechercheDonParStatutType <T>, Recherche.RechercheDonParMoisType <T>, }, new string[] { $"Recherche par statut des dons de {typeof(T).Name}", $"Recherche par mois des dons de {typeof(T).Name}" } ); //on obtient la fonction de recherche correspondant au choix utilisateur //On recherche des dons avec. return(InteractionUtilisateur.RechercherUnElement <Don>(modeDeRechercheChoisi, demanderChoix)); }
public static T MenuRecherchePersonneMode <T>(bool demanderChoix) where T : Personne { Recherche.FonctionRecherche <T> modeDeRechercheChoisi = InteractionUtilisateur.DemanderChoixObjet <Recherche.FonctionRecherche <T> >("Choisir le mode de recherche :", new Recherche.FonctionRecherche <T>[] { Recherche.RechercheParNomPersonneTypee <T>, Recherche.RechercheParNumTelPersonneTypee <T> }, new string[] { "Recherche par nom", "Recherche par numéro de téléphone" } ); //on obtient la fonction de recherche correspondant au choix utilisateur //On lance une recherche avec cette fonction de recherche choisie. return(InteractionUtilisateur.RechercherUnElement <T>(modeDeRechercheChoisi, demanderChoix)); }
/// <summary> /// Demande à l'utilisateur une entrée pour une recherche, et lui permet de choisir un objet parmi les résultats de cette recherche. /// </summary> /// <typeparam name="T">Type des objets choisis à retourner</typeparam> /// <param name="fonctionDeRecherche">Fonction de recherche prenant une entrée en argument .</param> /// <param name="demanderChoix">booléen indiquant si un choix est requis ou non. Si non, la fonction retourne toujours une valeur nulle/par défaut</param> /// <param name="nomArgumentRecherche">nom de l'argument de recherche. Doit renseigner l'utilisateur sur l'entrée qui lui est demandée, par exemple, recherche par "titre", par "ville", etc. </param> /// <returns></returns> public static T RechercherUnElement <T>(Recherche.FonctionRecherche <T> fonctionDeRecherche, bool demanderChoix = true, string nomArgumentRecherche = null) { T instanceChoisie = default(T); bool valid; string lecture; List <T> resultats; do { Console.Write($"Recherche d'une instance de {typeof(T).Name} "); if (nomArgumentRecherche != null) { Console.WriteLine($"par {nomArgumentRecherche}"); } Console.Write(">"); do { valid = true; lecture = Console.ReadLine(); resultats = fonctionDeRecherche(lecture); if (resultats.Count < 1) { Console.WriteLine($"Aucun résultat trouvé. Veuillez réessayer avec une autre entrée"); valid = false; } } while (!valid); if (demanderChoix) { instanceChoisie = DemanderChoixObjet <T>("Quel résultat choisir ?", resultats.ToArray()); Console.WriteLine($"Vous avez choisi {instanceChoisie}"); } else {//Si on n'exige pas que l'utilisateur fasse un choix, on affiche juste la liste ListerObjets <T>($"Voici les {resultats.Count} résultats", resultats); } } while (!ObtenirConfirmation("Continuer et quitter la recherche ? (Si vous choissisez non, vous pourrez relancer une recherche.)"));//On relance une recherche si l'utilisateur n'a pas reconfirmé son choix return(instanceChoisie); }