Пример #1
0
        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();
        }
Пример #2
0
        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();
        }
Пример #3
0
        public static void ShowAll()
        {
            Console.Clear();
            Console.WriteLine(FiggleFonts.Slant.Render("  Articles"));

            foreach (Article article in Stock)
            {
                ConsoleMenu.DisplayTable(article.Number, article.Name, article.Price, article.Quantity);
            }
            Console.ReadKey();
        }
Пример #4
0
        public static void DeleteArticle()
        {
            Console.Clear();
            Console.WriteLine(FiggleFonts.Slant.Render("  Supprimer"));
            Console.Write("Référence de l'article à supprimer: ");

            int articleToDeleteById = int.Parse(Console.ReadLine());

            for (int i = 0; i < Stock.Count; i++)
            {
                if (Stock[i].Number.Equals(articleToDeleteById))
                {
                    ConsoleMenu.DisplayTable(Stock[i].Number, Stock[i].Name, Stock[i].Price, Stock[i].Quantity);
                    Stock.RemoveAt(i);
                }
            }
            Console.WriteLine("Vous avez supprimé l'article");
            Console.ReadKey();
        }
Пример #5
0
        public static void SearchByPriceInterval()
        {
            Console.Title = "Par Prix | Rechercher";
            Console.Clear();
            Console.WriteLine(FiggleFonts.Slant.Render("  Rechercher"));

            Console.Write("Montant minimum: ");
            float startPrice = float.Parse(Console.ReadLine());

            Console.Write("Montant maximum: ");
            float endPrice = float.Parse(Console.ReadLine());

            //boucle for sur le nombre de ligne
            foreach (Article article in Stock)
            { // if prix minimum  entre prix max
                if (article.Price >= (startPrice) && article.Price <= (endPrice))
                {
                    ConsoleMenu.DisplayTable(article.Number, article.Name, article.Price, article.Quantity);
                }
            }
            Console.ReadKey();
        }
Пример #6
0
        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();
        }