示例#1
0
        public ProductListTable(List <Product> products)
        {
            // set this up for printing tables of data
            table = new List <Dictionary <string, string> >();

            // pagination setup, start with page 0
            int start = 0 + (CurrentPage * ItemsPerPage);
            int end   = start + ItemsPerPage - 1;

            NumPages = (int)Math.Ceiling((decimal)products.Count() / ItemsPerPage);

            for (int i = start; i <= end; i++)
            {
                Product product;

                // this will certainly throw IndexOutOfRangeException when there are less than 5 items
                // if it happens, just simply break the loop
                try { product = products.ElementAt(i); }
                catch (Exception e) { break; }

                // add cells to rows, then add them to table
                Dictionary <string, string> row = new Dictionary <string, string>();
                row.Add("ID", product.Id.ToString());
                row.Add("Product", product.Name);
                row.Add("Current Stock", product.StockLevel.ToString());
                row.Add("Unit Price", String.Format("{0:C2}", product.Price));
                table.Add(row);
            }



            Console.WriteLine("INVENTORY ({0} of {1})", CurrentPage + 1, NumPages);
            TableHelper.PrintTable(table);
            if (products.Count() - start < ItemsPerPage)
            {
                for (int i = 0; i < ItemsPerPage - (products.Count() - start); i++)
                {
                    Console.WriteLine();
                }
            }

            Console.WriteLine();
        }
示例#2
0
        public NewInventoryItemTable(List <Product> excluded)
        {
            // print new items
            List <Dictionary <string, string> > table = new List <Dictionary <string, string> >();

            foreach (Product p in excluded)
            {
                Dictionary <string, string> row = new Dictionary <string, string>();
                row.Add("ID", p.Id.ToString());
                row.Add("Product name", p.Name);
                row.Add("Stock Level", p.StockLevel.ToString());
                row.Add("Price", String.Format("{0:C2}", p.Price));
                table.Add(row);
            }

            Console.WriteLine("NEW ITEMS");
            TableHelper.PrintTable(table);
            Console.WriteLine();
        }
        public ProductLinesTable(List <Product> inventory)
        {
            List <Dictionary <string, string> > table = new List <Dictionary <string, string> >();

            foreach (Product item in inventory)
            {
                Dictionary <string, string> row = new Dictionary <string, string>();
                row.Add("ID", item.Id.ToString());
                row.Add("Name", item.Name);
                row.Add("Stock Level", item.StockLevel.ToString());
                row.Add("Unit Price", String.Format("{0:C2}", item.Price));
                table.Add(row);
            }
            Console.Clear();
            Console.WriteLine();
            Console.WriteLine("INVENTORY");
            TableHelper.PrintTable(table);
            Console.WriteLine();
        }
示例#4
0
        public InventoryTable(List <Product> products, int threshold)
        {
            // prepare inventory for printing
            List <Dictionary <string, string> > table = new List <Dictionary <string, string> >();

            foreach (Product p in products)
            {
                Dictionary <string, string> row = new Dictionary <string, string>();
                row.Add("ID", p.Id.ToString());
                row.Add("Name", p.Name);
                row.Add("Current Stock", p.StockLevel.ToString());
                row.Add("Re-Stock", (p.StockLevel < threshold).ToString());
                table.Add(row);
            }

            Console.WriteLine("INVENTORY");
            TableHelper.PrintTable(table);
            Console.WriteLine();
            Console.WriteLine();
        }
        public WorkshopsTable(List <Workshop> workshops)
        {
            List <Dictionary <string, string> > table = new List <Dictionary <string, string> >();

            foreach (Workshop workshop in workshops)
            {
                Dictionary <string, string> row = new Dictionary <string, string>();
                row.Add("ID", workshop.ID.ToString());
                row.Add("Location", workshop.Location);
                row.Add("Runs on", workshop.Type);
                row.Add("Remaining Spaces", workshop.SpacesAvailable().ToString());
                row.Add("Available?", workshop.IsAvailable() ? "Yes" : "No");

                table.Add(row);
            }

            Console.WriteLine("WORKSHOPS");
            TableHelper.PrintTable(table);
            Console.WriteLine();
        }
        public TransactionSummaryTable(Orders order, Booking booking = null)
        {
            List <Dictionary <string, string> > table = new List <Dictionary <string, string> >();

            foreach (OrderLine line in order.orderLines)
            {
                Dictionary <string, string> row = new Dictionary <string, string>();
                row.Add("Product Name", line.ProductName);
                row.Add("Quantity", line.Qty.ToString());
                row.Add("Unit Price", string.Format("{0:C2}", line.UnitPrice));
                row.Add("Total Price", string.Format("{0:C2}", line.UnitPrice * line.Qty));

                table.Add(row);
            }

            Console.WriteLine();
            Console.WriteLine("Thank you for shopping at Marvellous Magic");
            Console.WriteLine("Your order has been processed.");
            Console.WriteLine();
            if (booking != null)
            {
                Console.WriteLine("You are booked to {0} {1}", booking.Location, booking.Type);
                Console.WriteLine("Your reference number is: {0}", booking.ReferenceNumber);
            }
            Console.WriteLine();
            Console.WriteLine("YOUR TRANSACTION SUMMARY");
            TableHelper.PrintTable(table);
            Console.WriteLine();
            Console.WriteLine("Subtotal: {0:C2}", order.SubTotal);
            Console.WriteLine("Discount: {0:C2} ({1} %)", order.DiscountPrice, order.DiscountRate);
            Console.WriteLine(string.Format("Grand Total: {0:C2}", order.GrandTotal));
            Console.WriteLine();
            if (booking != null)
            {
                Console.WriteLine("You have choose to book into {0} {1} workshop", booking.Location, booking.Type);
            }
            Console.WriteLine();
            Console.WriteLine();
        }
示例#7
0
        public StockRequestsTable(List <StockRequest> requests, List <Product> ownerInventory)
        {
            // create list of key-value pair, we'll pass it to a helper function 'PrintTable()'
            // see the last lines of code
            List <Dictionary <string, string> > table = new List <Dictionary <string, string> >();

            foreach (StockRequest sr in requests)
            {
                Dictionary <string, string> row = new Dictionary <string, string>();



                // use ownerInventory items decide
                // whether or not we'll refill the stores inventory
                int currentstock = (from inv in ownerInventory
                                    where inv.Name.ToLower() == sr.ProductName.ToLower()
                                    select inv).First().StockLevel;

                row.Add("ID", sr.Id.ToString());
                row.Add("Store", sr.StoreName);
                row.Add("Product", sr.ProductName);
                row.Add("Quantity", sr.Quantity.ToString());
                row.Add("Stock Level", currentstock.ToString());
                row.Add("Stock Availability", (sr.Quantity <= currentstock).ToString());

                table.Add(row);
            }

            Console.WriteLine("STOCK REQUESTS");
            Console.WriteLine();

            // we'll use a helper called 'TableHelper' to help me print nice tables
            // TableHelper is located inside the Helpers folder
            TableHelper.PrintTable(table);

            Console.WriteLine();
            Console.WriteLine();
        }
        public ShoppingCartTable(List <OrderLine> OrderLines, Workshop workshop = null)
        {
            List <Dictionary <string, string> > table = new List <Dictionary <string, string> >();

            Console.WriteLine("YOUR ORDER BASKET");
            if (OrderLines == null || OrderLines.Count() == 0)
            {
                Console.WriteLine("Basket is empty");
            }
            else
            {
                double GrandTotal = 0.0;
                foreach (OrderLine line in OrderLines)
                {
                    Dictionary <string, string> row = new Dictionary <string, string>();
                    row.Add("Product Name", line.ProductName);
                    row.Add("Quantity", line.Qty.ToString());
                    row.Add("Unit Price", String.Format("{0:C2}", line.UnitPrice));
                    row.Add("Total Price", String.Format("{0:C2}", line.UnitPrice * line.Qty));

                    GrandTotal += line.UnitPrice * line.Qty;

                    table.Add(row);
                }


                TableHelper.PrintTable(table);
                Console.WriteLine();
                Console.WriteLine(string.Format("Grand Total: {0:C2}", GrandTotal));
                if (workshop != null)
                {
                    Console.WriteLine("You have choose to bookinto {0} {1} workshop", workshop.Location, workshop.Type);
                }
                Console.WriteLine();
                Console.WriteLine();
            }
        }