Ejemplo n.º 1
0
        protected bool readArticleType(string message, Article article, string quitValue = IOUtility.DEFAULT_QUIT_VALUE,
            string piecewiseValue = "kom", string granulatedValue = "kg")
        {
            while (true)
            {
                bool success = true;
                try
                {
                    Console.Write(message);
                    var str = Console.ReadLine();
                    if (str == quitValue) { return false; }
                    else if (str == piecewiseValue) { article.Type = ArticleType.Piecewise; break; }
                    else if (str == granulatedValue) { article.Type = ArticleType.Granulated; break; }
                    else { success = false; }
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine(e.Message);
                }
                catch (Exception)
                {
                    success = false;
                }

                if (!success)
                {
                    Console.WriteLine(ConsoleMessages.INVALID_ENTRY);
                }
            }
            return true;
        }
Ejemplo n.º 2
0
        public override bool Run()
        {
            Display();
            var article = new Article();
            article.Id = ArticleRepository.Instance.NextId;

            var test = readArticleName(ConsoleMessages.READ_ARTICLE_NAME, article);
            if (test) { test = readArticlePrice(ConsoleMessages.READ_ARTICLE_PRICE, article); }
            if (test) { test = readArticleVAT(ConsoleMessages.READ_ARTCLE_VAT, article); }
            if (test) { test = readArticleType(ConsoleMessages.READ_ARTICLE_TYPE, article); }

            if (test) { ArticleRepository.Instance.Add(article); }

            return true;
        }
Ejemplo n.º 3
0
 protected bool readArticleName(string message, Article article, string quitValue = IOUtility.DEFAULT_QUIT_VALUE)
 {
     while (true)
     {
         try
         {
             Console.Write(message);
             var str = Console.ReadLine();
             if (str == quitValue) { return false; }
             article.Name = str;
             break;
         }
         catch (ArgumentException e)
         {
             Console.WriteLine(e.Message);
         }
     }
     return true;
 }
Ejemplo n.º 4
0
 protected bool readArticlePrice(string message, Article article, string quitValue = IOUtility.DEFAULT_QUIT_VALUE)
 {
     while (true)
     {
         try
         {
             Console.Write(message);
             var str = Console.ReadLine();
             if (str == quitValue) { return false; }
             article.Price = Math.Round(double.Parse(str, CultureInfo.InvariantCulture), 2);
             break;
         }
         catch (ArgumentException e)
         {
             Console.WriteLine(e.Message);
         }
         catch (Exception)
         {
             Console.WriteLine(ConsoleMessages.INVALID_ENTRY);
         }
     }
     return true;
 }
Ejemplo n.º 5
0
 public static bool ValidQuantity(Article article, double quantity)
 {
     return article.Type == ArticleType.Granulated || ((quantity % 1) < 0.00001);
 }
Ejemplo n.º 6
0
 protected bool readArticleVAT(string message, Article article, string quitValue = IOUtility.DEFAULT_QUIT_VALUE)
 {
     while (true)
     {
         try
         {
             Console.Write(message);
             var str = Console.ReadLine();
             if (str == quitValue) { return false; }
             article.VAT = int.Parse(str);
             break;
         }
         catch (ArgumentException e)
         {
             Console.WriteLine(e.Message);
         }
         catch (Exception)
         {
             Console.WriteLine(ConsoleMessages.INVALID_ENTRY);
         }
     }
     return true;
 }