Exemple #1
0
        public static void PrintOrders(
            int width, int counter, StockMarketOrders orders,
            StockMarketOrders previous
            )
        {
            int colWidth = (width / 3) - 4;

            Console.Clear();
            var actualColor = Console.ForegroundColor;

            var lines = orders
                        .Select(order => {
                var existingOrder = previous
                                    .SingleOrDefault(x => x.Title == order.Title) ?? order;

                return(new
                {
                    order.Title,
                    order.Price,
                    Previous = (order.Price == existingOrder.Price)
                                    ? " * "
                                    : existingOrder.Price.ToString()
                });
            })
                        .Select(order =>
                                "| " + order.Title?.PadRight(colWidth)
                                + " | " + order.Price.ToString().PadRight(colWidth)
                                + " | " + order.Previous.PadRight(colWidth)
                                + "  |");

            Console.ForegroundColor = ConsoleColor.Green;

            Console.WriteLine(
                new string('-', width - 1) + Environment.NewLine
                + "| " + "Title".PadRight(colWidth)
                + " | " + "Price".PadRight(colWidth)
                + " | " + "Previous".PadRight(colWidth)
                + "  |");

            Console.WriteLine(
                new string('-', width - 1) + Environment.NewLine
                + string.Join(Environment.NewLine, lines));

            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine(
                new string('-', width - 1) + Environment.NewLine
                + "| " + "Total".PadRight(colWidth)
                + " | " + orders.GetTotal().ToString().PadRight(colWidth)
                + " | " + previous.GetTotal().ToString().PadRight(colWidth)
                + "  |" + Environment.NewLine
                + new string('-', width - 1) + Environment.NewLine);

            Console.ForegroundColor = actualColor;
            Console.WriteLine("Updated {0} times at {1}", counter, DateTime.Now);
        }