Beispiel #1
0
        private static bool OrderAddParsed(int idCustomer, int idProduct, int quantity, string adress)
        {
            var listIdProduct = new List <int>
            {
                idProduct
            };

            var product = Dependencies.ProductLogic.Get(idProduct);

            decimal sum = product.Price * quantity;

            var order = new Entities.Order(idCustomer, DateTime.Now, adress, listIdProduct, sum);

            if (Dependencies.OrderLogic.Add(ref order))
            {
                AddProductsToOrder(order);

                Message = "Заказ создан";
            }
            else
            {
                Message = $"Ошибка создания заказа, id покупателя - '{idCustomer}'!";
            }

            return(true);
        }
Beispiel #2
0
        private static void AddProductsToOrder(Entities.Order order)
        {
            foreach (var productId in order.ListIdProduct)
            {
                if (!Dependencies.OrderProductLogic.Add(new OrderProduct(order.Id, productId)))
                {
                    Message = $"Ошибка. Товар id '{productId}' не был добавлен в заказ id '{order.Id}'";

                    return;
                }
            }
        }
Beispiel #3
0
        //Returns a list of all orders placed in textboxes
        private ArrayList GetOrders()
        {
            ContentPlaceHolder cph = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
            ControlFinder<TextBox> cF = new ControlFinder<TextBox>();
            cF.FindChildControlsRecursive(cph);
            IEnumerable<TextBox> textBoxList = cF.FoundControls;
            ArrayList orderList = new ArrayList();

            foreach (TextBox textBox in textBoxList)
            {
                if (textBox.Text != "")
                {
                    int amountOfOrders = Convert.ToInt32(textBox.Text);
                    if (amountOfOrders > 0)
                    {
                        Coffee coffee = ConnectionClass.GetCoffeeByID(Convert.ToInt32(textBox.ID));
                        Order order = new Order(Session["login"].ToString(), coffee.Name, amountOfOrders, coffee.Price,
                                                DateTime.Now, false);
                        orderList.Add(order);
                    }
                }
            }
            return orderList;
        }
 public decimal CalculateSalesTax(Order order)
 {
     return order.LineItems.Sum(x => x.LineTotal) * DefaultTaxRate;
 }
 public void NewlyConstructedOrderHasNoLineItems()
 {
     Order order = new Order();
     Assert.AreEqual(0, order.LineItems.Count());
 }
 public void LineItemsInInitializedDuringConstruction()
 {
     Order order = new Order();
     Assert.IsNotNull(order.LineItems);
 }
Beispiel #7
0
 //задание №5.1
 public IEnumerable<Order> GetStats_CustOrderHist(int customerID)
 {
     var result = new List<Order>();
     using (var connection = new SqlConnection(ConnectionString))
     {
         var command = new SqlCommand(
             @"CREATE PROCEDURE CustOrderHist @CustomerID nchar(5)
                 AS SELECT ProductName, Total=SUM(Quantity)
                     FROM Products P, [Order Details] OD, Orders O, Customers C
                     WHERE C.CustomerID = @CustomerID
                         AND C.CustomerID = O.CustomerID AND O.OrderID = OD.OrderID AND OD.ProductID = P.ProductID
                     GROUP BY ProductName", connection);
         command.Parameters.AddWithValue("@CustomerID", customerID);
         connection.Open();
         using (var reader = command.ExecuteReader())
         {
             while (reader.Read())
             {
                 var order = new Order(
                     reader.GetInt32(0),
                     reader.GetInt32(1),
                     reader.GetDateTime(2),
                     reader.GetDateTime(3),
                     reader.GetInt32(4),
                     reader.GetDouble(5),
                     reader.GetString(6),
                     reader.GetString(7),
                     reader.GetString(8),
                     reader.GetString(9),
                     reader.GetString(10),
                     reader.GetString(11)
                     );
                 result.Add(order);
             }
         }
     }
     return result;
 }
Beispiel #8
0
 //задание №1. Показывать список введенных заказов
 public IEnumerable<Entities.Order> ShowListOfOrders()
 {
     var result = new List<Order>();
     using (var connection = new SqlConnection(ConnectionString))
     {
         var command = new SqlCommand(
             @"SELECT
              CASE
                 WHEN OrderDate IS NULL THEN 'New (unshipped)'
                 WHEN ShippedDate IS NULL THEN 'Working (unfulfilled)' ELSE 'Fulfilled'
              END  AS[Order Status], *FROM Northwind.Orders", connection);
         connection.Open();
         using (var reader = command.ExecuteReader())
         {
             while (reader.Read())
             {
                 var order = new Order(
                     reader.GetInt32(0),
                     reader.GetInt32(1),
                     reader.GetDateTime(2),
                     reader.GetDateTime(3),
                     reader.GetInt32(4),
                     reader.GetDouble(5),
                     reader.GetString(6),
                     reader.GetString(7),
                     reader.GetString(8),
                     reader.GetString(9),
                     reader.GetString(10),
                     reader.GetString(11)
                     );
                 result.Add(order);
             }
         }
     }
     return result;
 }
Beispiel #9
0
 //задание №2. Показывать подробные сведения о конкретном заказе
 public IEnumerable<Entities.Order> ShowInformationAboutOrder(Guid orderID)
 {
     var result = new List<Entities.Order>();
     using (var connection = new SqlConnection(ConnectionString))
     {
         var command = new SqlCommand(
             @"SELECT * FROM Northwind.Orders AS ord, Northwind.[Order Details] AS ordDet, Northwind.Products AS pr
                 WHERE @orderID = ordDet.OrderID AND ordDet.ProductID = pr.ProductID
                     AND pr.ProductName = @productName", connection);
         command.Parameters.AddWithValue("@orderId", orderID);
         connection.Open();
         using (var reader = command.ExecuteReader())
         {
             while (reader.Read())
             {
                 var order = new Order(
                     reader.GetInt32(0),
                     reader.GetInt32(1),
                     reader.GetDateTime(2),
                     reader.GetDateTime(3),
                     reader.GetInt32(4),
                     reader.GetDouble(5),
                     reader.GetString(6),
                     reader.GetString(7),
                     reader.GetString(8),
                     reader.GetString(9),
                     reader.GetString(10),
                     reader.GetString(11)
                     );
                 result.Add(order);
             }
         }
     }
     return result;
 }
Beispiel #10
0
 //задание №5.2
 public IEnumerable<Order> GetStats_CustOrdersDetail(int OrderID)
 {
     var result = new List<Order>();
     using (var connection = new SqlConnection(ConnectionString))
     {
         var command = new SqlCommand(
             @"CREATE PROCEDURE CustOrdersDetail @OrderID int
                 AS SELECT ProductName,
                     UnitPrice=ROUND(Od.UnitPrice, 2),
                     Quantity, Discount=CONVERT(int, Discount * 100),
                     ExtendedPrice=ROUND(CONVERT(money, Quantity * (1 - Discount) * Od.UnitPrice), 2)
                 FROM Products P, [Order Details] Od
                     WHERE Od.ProductID = P.ProductID and Od.OrderID = @OrderID", connection);
         command.Parameters.AddWithValue("@CustomerID", OrderID);
         connection.Open();
         using (var reader = command.ExecuteReader())
         {
             while (reader.Read())
             {
                 var order = new Order(
                     reader.GetInt32(0),
                     reader.GetInt32(1),
                     reader.GetDateTime(2),
                     reader.GetDateTime(3),
                     reader.GetInt32(4),
                     reader.GetDouble(5),
                     reader.GetString(6),
                     reader.GetString(7),
                     reader.GetString(8),
                     reader.GetString(9),
                     reader.GetString(10),
                     reader.GetString(11)
                     );
                 result.Add(order);
             }
         }
     }
     return result;
 }