コード例 #1
0
        private static void AddRecordsIntoProductBatch(int lastId, ProductBatchQuery productBatchQuery)
        {
            bool flag = true;

            while (flag)
            {
                try
                {
                    Console.Write("Please, input corrrect existing product id: ");
                    int id = ConsoleInput.InputInt();
                    Console.Write("Please, input corrrect product product quantity: ");
                    int quantity = ConsoleInput.InputInt();

                    ProductBatch productBatch = new ProductBatch
                    {
                        BatchId_FK      = lastId,
                        ProductId_FK    = id,
                        ProductQuantity = quantity
                    };
                    productBatchQuery.AddNewRecord(productBatch);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                Console.Write("Add another one product to the batch? (y/n): ");
                string str = Console.ReadLine();
                if (str == "n")
                {
                    flag = false;
                }
            }
        }
コード例 #2
0
        public static void AddNewProduct(SqlConnection connection)
        {
            Product product = new Product();

            Console.WriteLine("Please, enter the product details: ");

            Console.Write("Name: ");
            product.Name = Console.ReadLine();

            Console.Write("UnitMeasure: ");
            product.UnitMeasure = Console.ReadLine();

            Console.Write("UnitPrice: ");
            product.UnitPrice = ConsoleInput.InputDouble();

            Console.Write("Quantity: ");
            product.Quantity = ConsoleInput.InputInt();

            ProductQuery productQuery = new ProductQuery(connection);
            int          result       = productQuery.AddNewRecord(product);

            Console.WriteLine($"Affected rows: {result}");
        }