public static void SearchByReference() { Console.Title = "Par référence | Rechercher"; Console.Clear(); Console.WriteLine(FiggleFonts.Slant.Render(" Rechercher")); Console.Write("Référence de l'article: "); int searchByNumber; bool input = int.TryParse(Console.ReadLine(), out searchByNumber); if (input) { for (int i = 0; i < Stock.Count; i++) { if (Stock[i].Number.Equals(searchByNumber)) { ConsoleMenu.DisplayTable(Stock[i].Number, Stock[i].Name, Stock[i].Price, Stock[i].Quantity); } } } else { ConsoleMenu.DisplayError("La valeur peut seulement être un chiffre, veuillez réessayer."); } Console.ReadKey(); }
public static void AddArticle() { Console.Clear(); Console.WriteLine(FiggleFonts.Slant.Render(" Ajouter")); Console.Write("Numéro [0 = auto]: "); int number = int.Parse(Console.ReadLine()); Console.Write("Nom: "); string name = Console.ReadLine(); Console.Write("Prix: "); float price = float.Parse(Console.ReadLine()); Console.Write("Quantité: "); int quantity = int.Parse(Console.ReadLine()); bool numberExist = true; if (number == 0) { number = GenerateId(); Stock.Add(new Article(number, name, price, quantity)); } else { foreach (Article article in Stock) { if (article.Number.Equals(number)) { ConsoleMenu.DisplayError("Ce numéro existe déjà, veuiller en saisir un nouveau."); numberExist = false; } } if (numberExist == true) { Stock.Add(new Article(number, name, price, quantity)); // TEST EXECUTION BDD try { using (var db = new Database()) { db.Connection.Open(); using (var cmd = db.Connection.CreateCommand()) { cmd.CommandText = @"INSERT INTO article VALUES (number, name, price, quantity)"; cmd.ExecuteNonQuery(); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } } } ConsoleMenu.DisplayTable(number, name, price, quantity); Console.ReadKey(); }
public static void SearchByName() { Console.Title = "Par Nom | Rechercher"; Console.Clear(); Console.WriteLine(FiggleFonts.Slant.Render(" Rechercher")); Console.Write("Nom de l'article: "); string nameInput = Console.ReadLine(); for (int i = 0; i < Stock.Count; i++) { if (Stock[i].Name.Equals(nameInput)) { ConsoleMenu.DisplayTable(Stock[i].Number, Stock[i].Name, Stock[i].Price, Stock[i].Quantity); } else { ConsoleMenu.DisplayError("Erreur WIP."); } } Console.ReadKey(); }