Ejemplo n.º 1
0
        public string CreateOrderBusiness(OrderProduct order)
        {
            string result = "";

            if (data.CreateOrder(order))
            {
                result = "Su orden fue procesada. le llegará al lugar especificado y el día que usted designó. Gracias por preferirnos!";
            }
            else
            {
                result = "Lo sentimos, ha ocurrido un error. Intentelo más tarde.";
            }
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 在数据库中创建订单
        /// </summary>
        /// <param name="order">包含完整信息的Order实例</param>
        /// <returns>成功返回true,失败返回false</returns>
        public static Boolean CreateOrder(Order order)
        {
            Boolean result = false;

            if (isLegalOrder(order))
            {
                OrderData orderData = OrderData.GetNewInstance();
                result = orderData.CreateOrder(order);
            }
            else
            {
                result = false;
            }
            return(result);
        }
Ejemplo n.º 3
0
 private void btnCreateOrder_Click(object sender, EventArgs e)
 {
     try
     {
         if (Cart.Count != 0)
         {
             double total   = double.Parse(lbTotal.Text);
             int    orderID = orderData.CreateOrder(account.ID, total);
             if (orderID > 0)
             {
                 bool chk = false;
                 foreach (CartItem cartItem in Cart)
                 {
                     if (orderDetailData.InsertProductToOrder(orderID, cartItem.product.ProductID, cartItem.Quantity))
                     {
                         chk = true;
                     }
                 }
                 if (chk)
                 {
                     MessageBox.Show("Order created");
                     reloadForm();
                 }
                 else
                 {
                     MessageBox.Show("Failed when create order");
                 }
             }
         }
         else
         {
             MessageBox.Show("Empty cart");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Handles the prompting, input validation, and console output for a customer creating an order.
        /// </summary>
        private static void HandleRequestPlaceOrder()
        {
            Log.Information("Handling request placing order");
            int line = 0;
            Dictionary <int, int>             lineItemsParsed = new Dictionary <int, int>();
            Dictionary <BusinessProduct, int> lineItems       = new Dictionary <BusinessProduct, int>();

            Console.WriteLine("[?] What is the customer ID");
            string inputCustomerId = Console.ReadLine();

            Log.Information($"User entered '{inputCustomerId}' for customer id");
            if (!Int32.TryParse(inputCustomerId, out int customerId))
            {
                throw new FormatException($"[!] Input for customer ID is not an integer");
            }

            Console.WriteLine("[?] What is the location ID");
            string inputLocationId = Console.ReadLine();

            Log.Information($"User entered '{inputLocationId}' for location id");
            if (!Int32.TryParse(inputLocationId, out int locationId))
            {
                throw new FormatException($"[!] Input for location ID is not an integer");
            }

            while (++line > 0)
            {
                Console.WriteLine($"[?] Line {line} - Enter product ID or press enter to finish your order");
                string inputProductId = Console.ReadLine();
                Log.Information($"User entered '{inputProductId}' for product id on line {line}");
                if (inputProductId == "")
                {
                    Log.Information($"User entered nothing for product id on line {line}");
                    break;
                }
                if (!Int32.TryParse(inputProductId, out int productId))
                {
                    throw new FormatException($"[!] Input for product ID is not an integer");
                }

                Console.WriteLine($"[?] Line {line} - Enter quantity");
                string inputQuantity = Console.ReadLine();
                Log.Information($"User entered '{inputQuantity}' for quantity on line {line}");
                if (!Int32.TryParse(inputQuantity, out int quantity))
                {
                    throw new FormatException($"[!] Input for quantity is not an integer");
                }

                lineItemsParsed.Add(productId, quantity);
            }

            if (CustomerData.GetCustomerWithId(customerId) is null)
            {
                throw new BusinessCustomerException($"[!] Customer does not exist");
            }

            if (LocationData.GetLocationWithId(locationId) is null)
            {
                throw new BusinessLocationException($"[!] Location does not exist");
            }

            foreach (KeyValuePair <int, int> lineItemParsed in lineItemsParsed)
            {
                BusinessProduct bProduct = ProductData.GetProductWithId(lineItemParsed.Key);
                if (bProduct is null)
                {
                    throw new BusinessProductException($"[!] Product {lineItemParsed.Key} does not exist");
                }
                lineItems.Add(bProduct, lineItemParsed.Value);
            }

            BusinessCustomer bCustomer = CustomerData.GetCustomerWithId(customerId);
            BusinessLocation bLocation = LocationData.GetLocationWithId(locationId);

            BusinessOrder bOrder = new BusinessOrder()
            {
                StoreLocation = bLocation,
                Customer      = bCustomer,
                OrderTime     = DateTime.Now
            };

            bOrder.AddLineItems(lineItems);
            foreach (KeyValuePair <BusinessProduct, int> lineItem in lineItems)
            {
                bOrder.StoreLocation.DecrementStock(lineItem.Key, lineItem.Value);
            }
            OrderData.CreateOrder(bOrder);
        }