示例#1
0
        public static BLOrder RetrieveFromDB(string databaseConnectionString, int id)
        {
            SqlConnection sqlConnection       = new SqlConnection(databaseConnectionString);
            SqlCommand    sqlGetOrder         = new SqlCommand($"SELECT AccountID, TotalPrice, Postage, Address, PostalCode, City, Country, Email, Telephone, PaymentOptions, DeliveryOptions, Name, Surname FROM Orders WHERE ID = {id}", sqlConnection);
            SqlCommand    sqlGetOrderProducts = new SqlCommand($"SELECT ProductID, Quantity FROM OrderProducts WHERE OrderID = {id}", sqlConnection);
            SqlDataReader sqlReader           = null;
            BLOrder       order = null;

            try
            {
                sqlConnection.Open();

                sqlReader = sqlGetOrder.ExecuteReader();
                while (sqlReader.Read())
                {
                    order = new BLOrder(postage: double.Parse(sqlReader["Postage"].ToString()),
                                        totalPrice: double.Parse(sqlReader["TotalPrice"].ToString()),
                                        address: sqlReader["Address"].ToString(), postalCode: sqlReader["PostalCode"].ToString(),
                                        city: sqlReader["City"].ToString(), country: sqlReader["Country"].ToString(),
                                        email: sqlReader["Email"].ToString(), telephone: sqlReader["Telephone"].ToString(),
                                        paymentOptions: sqlReader["PaymentOptions"].ToString(),
                                        deliveryOptions: sqlReader["DeliveryOptions"].ToString(), name: sqlReader["Name"].ToString(),
                                        surname: sqlReader["Surname"].ToString(), cartProducts: new List <BLCartProduct>())
                    {
                        Id = id
                    };
                    int accountId;
                    if (int.TryParse(sqlReader["AccountID"].ToString(), out accountId))
                    {
                        order.AccountId = accountId;
                    }
                }
                sqlReader.Close();
                sqlReader.Dispose();
                if (order == null)
                {
                    return(null);
                }

                sqlReader = sqlGetOrderProducts.ExecuteReader();
                while (sqlReader.Read())
                {
                    order.CartProducts.Add(new BLCartProduct(id: int.Parse(sqlReader["ProductID"].ToString()),
                                                             quantity: int.Parse(sqlReader["Quantity"].ToString())));
                }

                return(order);
            }
            finally
            {
                if (sqlReader != null)
                {
                    sqlReader.Close();
                    sqlReader.Dispose();
                }
                sqlConnection.Close();
                sqlConnection.Dispose();
                sqlGetOrder.Dispose();
            }
        }
示例#2
0
        public static BLOrder RetrieveFromDB(string databaseConnectionString, int id)
        {
            SqlConnection sqlConnection = new SqlConnection(databaseConnectionString);
            SqlCommand sqlGetOrder = new SqlCommand($"SELECT AccountID, TotalPrice, Postage, Address, PostalCode, City, Country, Email, Telephone, PaymentOptions, DeliveryOptions, Name, Surname FROM Orders WHERE ID = {id}", sqlConnection);
            SqlCommand sqlGetOrderProducts = new SqlCommand($"SELECT ProductID, Quantity FROM OrderProducts WHERE OrderID = {id}", sqlConnection);
            SqlDataReader sqlReader = null;
            BLOrder order = null;
            try
            {
                sqlConnection.Open();

                sqlReader = sqlGetOrder.ExecuteReader();
                while (sqlReader.Read())
                {
                    order = new BLOrder(postage: double.Parse(sqlReader["Postage"].ToString()),
                        totalPrice: double.Parse(sqlReader["TotalPrice"].ToString()),
                        address: sqlReader["Address"].ToString(), postalCode: sqlReader["PostalCode"].ToString(),
                        city: sqlReader["City"].ToString(), country: sqlReader["Country"].ToString(),
                        email: sqlReader["Email"].ToString(), telephone: sqlReader["Telephone"].ToString(),
                        paymentOptions: sqlReader["PaymentOptions"].ToString(),
                        deliveryOptions: sqlReader["DeliveryOptions"].ToString(), name: sqlReader["Name"].ToString(),
                        surname: sqlReader["Surname"].ToString(), cartProducts: new List<BLCartProduct>()) {Id = id};
                    int accountId;
                    if (int.TryParse(sqlReader["AccountID"].ToString(), out accountId))
                        order.AccountId = accountId;
                }
                sqlReader.Close();
                sqlReader.Dispose();
                if (order == null)
                    return null;

                sqlReader = sqlGetOrderProducts.ExecuteReader();
                while (sqlReader.Read())
                    order.CartProducts.Add(new BLCartProduct(id: int.Parse(sqlReader["ProductID"].ToString()),
                        quantity: int.Parse(sqlReader["Quantity"].ToString())));

                return order;
            }
            finally
            {
                if (sqlReader != null)
                {
                    sqlReader.Close();
                    sqlReader.Dispose();
                }
                sqlConnection.Close();
                sqlConnection.Dispose();
                sqlGetOrder.Dispose();
            }
        }
 protected void SubmitOrder_Click(object sender, EventArgs e)
 {
     if (Page.IsValid && cartList != null)
     {
         double shippingCost;
         string shippingMethod = ShippingDrowdown(out shippingCost);
         BLOrder order = new BLOrder(postage: shippingCost, totalPrice: totalCartPrice, address: customer_address.Text, postalCode: customer_postalcode.Text, city: customer_city.Text, country: customer_country.Text, email: customer_email.Text, telephone: customer_phone.Text, paymentOptions: PaymentDropdown(), deliveryOptions: shippingMethod, name: customer_name.Text, surname: customer_surname.Text, cartProducts: cartList);
         order.InsertIntoDB(connectionString);
         Session["orderId"] = order.Id;
         Session["cartList"] = null;
         Session["cartCount"] = null;
         Response.Redirect("/ReceiptPage.aspx");
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     order = BLOrder.RetrieveFromDB(connectionString, (int)Session["orderId"]);
     ShowOrderInfo();
     ShowOrderProducts();
 }