|
|
|
@ -7,122 +7,119 @@ using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
using Model;
|
|
|
|
|
|
|
|
|
|
namespace ConsoleApp
|
|
|
|
|
namespace ConsoleApp.Menu
|
|
|
|
|
{
|
|
|
|
|
public partial class ConsoleMenu : Manager
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// An utility to find a recipe.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class SearcherRecipe : SelectMenu<Recipe>
|
|
|
|
|
{
|
|
|
|
|
#region Attribute
|
|
|
|
|
private RecipeCollection _recipeOnSearch;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// An utility to find a recipe.
|
|
|
|
|
/// A collection of recipe where the title contain the search string
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class SearcherRecipe : SelectMenu<Recipe>
|
|
|
|
|
{
|
|
|
|
|
#region Attribute
|
|
|
|
|
private RecipeCollection _recipeOnSearch;
|
|
|
|
|
#endregion
|
|
|
|
|
public RecipeCollection SearchResult { get; private set; }
|
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A collection of recipe where the title contain the search string
|
|
|
|
|
/// </summary>
|
|
|
|
|
public RecipeCollection SearchResult { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The search string
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string ResearchStr { get; set; }
|
|
|
|
|
#endregion
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The search string
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string ResearchStr { get; set; }
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructor of the SearcherRecipe utility.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="recipeOnSearch">The collection of recipe where to search</param>
|
|
|
|
|
public SearcherRecipe(RecipeCollection recipeOnSearch)
|
|
|
|
|
{
|
|
|
|
|
_recipeOnSearch = recipeOnSearch;
|
|
|
|
|
SearchResult = _recipeOnSearch;
|
|
|
|
|
ResearchStr = "";
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructor of the SearcherRecipe utility.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="recipeOnSearch">The collection of recipe where to search</param>
|
|
|
|
|
public SearcherRecipe(RecipeCollection recipeOnSearch)
|
|
|
|
|
{
|
|
|
|
|
_recipeOnSearch = recipeOnSearch;
|
|
|
|
|
SearchResult = _recipeOnSearch;
|
|
|
|
|
ResearchStr = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Methodes
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Launch a search by name request in the collection of Recipe with with a string.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="researchStr">The string for search</param>
|
|
|
|
|
/// <returns>True if the result of the search gave at least 1 element. False otherwise.</returns>
|
|
|
|
|
public bool ComputeSearch(string researchStr = "")
|
|
|
|
|
{
|
|
|
|
|
ResearchStr = researchStr;
|
|
|
|
|
SearchResult = _recipeOnSearch.ResearchByName(ResearchStr.ToLower());
|
|
|
|
|
_maxLines = SearchResult.Count - 1;
|
|
|
|
|
#region Methodes
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Launch a search by name request in the collection of Recipe with with a string.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="researchStr">The string for search</param>
|
|
|
|
|
/// <returns>True if the result of the search gave at least 1 element. False otherwise.</returns>
|
|
|
|
|
public bool ComputeSearch(string researchStr = "")
|
|
|
|
|
{
|
|
|
|
|
ResearchStr = researchStr;
|
|
|
|
|
SearchResult = _recipeOnSearch.ResearchByName(ResearchStr.ToLower());
|
|
|
|
|
_maxLines = SearchResult.Count - 1;
|
|
|
|
|
|
|
|
|
|
return SearchResult.Count > 0;
|
|
|
|
|
}
|
|
|
|
|
return SearchResult.Count > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void UpdateDisplay()
|
|
|
|
|
public override void UpdateDisplay()
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sb.AppendLine("---------------------------------------------------------");
|
|
|
|
|
sb.AppendLine($" Research: {ResearchStr}");
|
|
|
|
|
sb.AppendLine("---------------------------------------------------------");
|
|
|
|
|
for (int i = 0; i < SearchResult.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sb.AppendLine("---------------------------------------------------------");
|
|
|
|
|
sb.AppendLine($" Research: {ResearchStr}");
|
|
|
|
|
sb.AppendLine("---------------------------------------------------------");
|
|
|
|
|
for (int i = 0; i < SearchResult.Count; i++)
|
|
|
|
|
if (i == CurrentLine)
|
|
|
|
|
{
|
|
|
|
|
if (i == CurrentLine)
|
|
|
|
|
{
|
|
|
|
|
CurrentSelected = SearchResult[i];
|
|
|
|
|
sb.Append($">");
|
|
|
|
|
}
|
|
|
|
|
sb.AppendLine($" [ {SearchResult[i].Id} ]:\t{SearchResult[i].Title} ");
|
|
|
|
|
CurrentSelected = SearchResult[i];
|
|
|
|
|
sb.Append($">");
|
|
|
|
|
}
|
|
|
|
|
Console.Clear();
|
|
|
|
|
Console.WriteLine(sb);
|
|
|
|
|
sb.AppendLine($" [ {SearchResult[i].Id} ]:\t{SearchResult[i].Title} ");
|
|
|
|
|
}
|
|
|
|
|
Console.Clear();
|
|
|
|
|
Console.WriteLine(sb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Launch and pilot the search menu.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="recipeOnSearch">The collection of recipe where to search</param>
|
|
|
|
|
/// <returns>The recipe selected</returns>
|
|
|
|
|
public static Recipe? ResearchOn(RecipeCollection recipeOnSearch)
|
|
|
|
|
{
|
|
|
|
|
SearcherRecipe sr = new SearcherRecipe(recipeOnSearch);
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sr.ComputeSearch();
|
|
|
|
|
sr.UpdateDisplay();
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Launch and pilot the search menu.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="recipeOnSearch">The collection of recipe where to search</param>
|
|
|
|
|
/// <returns>The recipe selected</returns>
|
|
|
|
|
public static Recipe? ResearchOn(RecipeCollection recipeOnSearch)
|
|
|
|
|
{
|
|
|
|
|
SearcherRecipe sr = new SearcherRecipe(recipeOnSearch);
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sr.ComputeSearch();
|
|
|
|
|
sr.UpdateDisplay();
|
|
|
|
|
|
|
|
|
|
ConsoleKeyInfo cki;
|
|
|
|
|
ConsoleKeyInfo cki;
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
cki = Console.ReadKey(true);
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
cki = Console.ReadKey(true);
|
|
|
|
|
|
|
|
|
|
switch (cki.Key)
|
|
|
|
|
{
|
|
|
|
|
case ConsoleKey.UpArrow:
|
|
|
|
|
sr.SelectPrevioustLine();
|
|
|
|
|
break;
|
|
|
|
|
case ConsoleKey.DownArrow:
|
|
|
|
|
sr.SelectNextLine();
|
|
|
|
|
break;
|
|
|
|
|
case ConsoleKey.Backspace:
|
|
|
|
|
if (sb.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
sb.Remove(sb.Length - 1, 1);
|
|
|
|
|
sr.ComputeSearch(sb.ToString());
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
sb.Append(cki.KeyChar);
|
|
|
|
|
switch (cki.Key)
|
|
|
|
|
{
|
|
|
|
|
case ConsoleKey.UpArrow:
|
|
|
|
|
sr.SelectPrevioustLine();
|
|
|
|
|
break;
|
|
|
|
|
case ConsoleKey.DownArrow:
|
|
|
|
|
sr.SelectNextLine();
|
|
|
|
|
break;
|
|
|
|
|
case ConsoleKey.Backspace:
|
|
|
|
|
if (sb.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
sb.Remove(sb.Length - 1, 1);
|
|
|
|
|
sr.ComputeSearch(sb.ToString());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
sb.Append(cki.KeyChar);
|
|
|
|
|
sr.ComputeSearch(sb.ToString());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sr.UpdateDisplay();
|
|
|
|
|
sr.UpdateDisplay();
|
|
|
|
|
|
|
|
|
|
} while (cki.Key != ConsoleKey.Enter);
|
|
|
|
|
} while (cki.Key != ConsoleKey.Enter);
|
|
|
|
|
|
|
|
|
|
return sr.CurrentSelected;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
return sr.CurrentSelected;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|