示例#1
0
        public int Insert(BLL.Cart c)
        {
            string        DBConnect = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
            SqlConnection myConn    = new SqlConnection(DBConnect);

            string sqlStmt = "INSERT INTO Cart (NAME, IMAGE, PRICE, QUANTITY,TOTAL,Username)" +
                             "VALUES (@paraName,@paraImage,@paraPrice,@paraQuantity,@paraTotal,@paraUsername)";

            int        result = 0; // Execute NonQuery return an integer value
            SqlCommand sqlCmd = new SqlCommand(sqlStmt, myConn);

            sqlCmd.Parameters.AddWithValue("@paraName", c.Name);
            sqlCmd.Parameters.AddWithValue("@paraImage", c.Image);
            sqlCmd.Parameters.AddWithValue("@paraPrice", c.Price);
            sqlCmd.Parameters.AddWithValue("@paraQuantity", c.Quantity);
            sqlCmd.Parameters.AddWithValue("@paraTotal", c.Total);
            sqlCmd.Parameters.AddWithValue("@paraUsername", c.Username);

            myConn.Open();
            result = sqlCmd.ExecuteNonQuery();

            myConn.Close();

            return(result);
        }
示例#2
0
        public int Delete(BLL.Cart c)
        {
            int        result = 0;
            SqlCommand sqlCmd = new SqlCommand();

            string        DBConnect = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
            SqlConnection myConn    = new SqlConnection(DBConnect);

            // Step 2 - Instantiate SqlCommand instance to add record
            //          with INSERT statement
            string sqlStmt = "DELETE Cart where Id = @paraID ";

            sqlCmd = new SqlCommand(sqlStmt, myConn);

            // Step 3 : Add each parameterised variable with value
            sqlCmd.Parameters.AddWithValue("@paraID", c.Id);
            //sqlCmd.Parameters.AddWithValue("@paraName", up.Name);
            //sqlCmd.Parameters.AddWithValue("@paraDesc", up.Desc);
            //sqlCmd.Parameters.AddWithValue("@paraPrice", up.Price);

            // Step 4 Open connection the execute NonQuery of sql command
            myConn.Open();
            result = sqlCmd.ExecuteNonQuery();

            // Step 5 :Close connection
            myConn.Close();

            return(result);
        }
示例#3
0
        private void BindCartList()
        {
            List <Model.Cart> cartList = new BLL.Cart().GetModelList(CurrentUser.Id);

            if (cartList.Count < 1)
            {
                Response.Redirect("/BookList.aspx");
                return;
            }

            StringBuilder sb         = new StringBuilder();
            decimal       totalMoney = 0;

            foreach (Model.Cart cartModel in cartList)
            {
                sb.Append("<tr class=\"align_Center\">");
                sb.Append("<td style=\"PADDING-BOTTOM: 5px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 5px\">" + cartModel.Book.Id + "</td>");
                sb.Append("<td class=align_Left><a onmouseover=\"\" onmouseout=\"\" onclick=\"\" href='#' target=\"_blank\" >" + cartModel.Book.Title + "</a></td>");

                sb.Append("<td><span class=\"price\">¥" + cartModel.Book.UnitPrice.ToString("0.00") + "</span></td>");
                sb.Append("<td>" + cartModel.Count + "</td></tr>");
                totalMoney = totalMoney + (cartModel.Count * cartModel.Book.UnitPrice);
            }
            StrHtml    = sb.ToString();
            TotalMoney = totalMoney;
        }
示例#4
0
        override protected void OnLoad(EventArgs e)
        {
            // Create an instance of the cart controller
            ProcessFlow.CartController cartController = new ProcessFlow.CartController();
            // Fetch the cart state from the controller
            myCart = cartController.GetCart(false);

            // If there is something in the cart then show the continue button
            link.Visible = myCart.Count > 0;
        }
示例#5
0
        private void GetProductList(string products)
        {
            if (!string.IsNullOrEmpty(products))
            {
                BLL.Cart cart = new BLL.Cart();
                string   productInfoAppend = "";
                string[] items             = products.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string item in items)
                {
                    string[] subItems = item.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    if (string.IsNullOrEmpty(subItems[0]))
                    {
                        continue;
                    }
                    cart.Add(subItems[0]);
                    //nIdAppend += string.Format("'{0}',", subItems[0]);
                    //Model.CartItemInfo model = new Model.CartItemInfo();
                    //model.Quantity = int.Parse(subItems[1]);
                    //model.Subtotal = decimal.Parse(subItems[2]);
                    ////productInfoAppend += string.Format("<td>{1}</td><td>{0}</td>", subItems[1], subItems[2]);
                }

                //if (!string.IsNullOrEmpty(nIdAppend))
                //{
                //    nIdAppend = nIdAppend.Trim(',');
                //    if (bll == null) bll = new BLL.OrderInfo();
                //    List<Model.Product> list = bll.GetProductInIds(nIdAppend);
                //    if (list != null)
                //    {
                //        foreach (Model.Product model in list)
                //        {
                //            productInfoAppend += string.Format("<tr><td>{1}</td><td>{0}</td>{2}</tr>",model.ProductName,model.PNum,productInfoAppend);
                //        }
                //    }
                //}

                foreach (Model.CartItemInfo model in cart.CartItems)
                {
                    productInfoAppend += string.Format("<tr><td><a href=\"../../Shares/ShowProduct.aspx?nId={3}\" target=\"_blank\">{0}</a> </td><td>{1}</td><td>{2}</td></tr>", model.ProductName, model.Subtotal, model.Quantity, model.ProductId);
                }

                if (rpData.Items.Count > 0)
                {
                    Literal ltrProducts = rpData.Items[0].FindControl("ltrProducts") as Literal;
                    if (ltrProducts != null)
                    {
                        ltrProducts.Text = productInfoAppend;
                    }
                }
            }
        }
示例#6
0
        public List <BLL.Cart> SelectAll()
        {
            //Step 1 -  Define a connection to the database by getting
            //          the connection string from web.config
            string        DBConnect = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
            SqlConnection myConn    = new SqlConnection(DBConnect);

            //Step 2 -  Create a DataAdapter to retrieve data from the database table
            string         sqlStmt = "Select * from Cart";
            SqlDataAdapter da      = new SqlDataAdapter(sqlStmt, myConn);

            //Step 3 -  Create a DataSet to store the data to be retrieved
            DataSet ds = new DataSet();

            //Step 4 -  Use the DataAdapter to fill the DataSet with data retrieved
            da.Fill(ds);

            //Step 5 -  Read data from DataSet to List
            List <BLL.Cart> cList   = new List <BLL.Cart>();
            int             rec_cnt = ds.Tables[0].Rows.Count;

            for (int i = 0; i < rec_cnt; i++)
            {
                DataRow row = ds.Tables[0].Rows[i];  // Sql command returns only one record
                //string idStr = row["Id"].ToString();
                //int id = Convert.ToInt32(idStr);
                string name  = row["NAME"].ToString();
                string image = row["IMAGE"].ToString();

                string quantityStr = row["QUANTITY"].ToString();
                int    quantity    = Convert.ToInt32(quantityStr);

                string price = row["PRICE"].ToString();
                //double price = Convert.ToDouble(priceStr);



                BLL.Cart obj = new BLL.Cart(name, image, quantity, price);
                cList.Add(obj);
            }

            return(cList);
        }
示例#7
0
        /// <summary>
        /// A method to return the current state of the cart
        /// </summary>
        /// <param name="create">Specifies whether a cart should be created if one does not exist</param>
        /// <returns>Cart object</returns>
        public Cart GetCart(bool create)
        {
            // Fetch the cart object from session state
            BLL.Cart myCart = (BLL.Cart)HttpContext.Current.Session[CART_KEY];

            if (myCart == null)
            {
                if (create)
                {
                    myCart = new BLL.Cart();
                }
                else
                {
                    HttpContext.Current.Server.Transfer(URL_NOCART);
                    return(null);
                }
            }

            return(myCart);
        }
示例#8
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //context.Response.Write("Hello World");
            //1.判断用户是否登陆
            Model.Users userModel = new BLL.Users().GetModel(context.Request.Cookies["cp1"].Value);
            if (Common.WebHelper.CheckCookie(userModel) == false)
            {
                context.Response.Write("no");
                return;
            }

            //2.检查该商品数据库中是否存在
            int bookId = int.Parse(context.Request["bookId"] ?? "0");

            Model.Books book = new BLL.Books().GetModel(bookId);
            if (book == null)
            {
                context.Response.Write("no");
                return;
            }

            //3.将商品添加到购物车
            Model.Users user       = (Model.Users)context.Session["userInfo"];
            BLL.Cart    cartServer = new BLL.Cart();
            Model.Cart  cart       = cartServer.GetCart(user.Id, bookId);
            if (cart != null)
            {
                cart.Count++;
                cartServer.Update(cart);
            }
            else
            {
                cart       = new Model.Cart();
                cart.Count = 1;
                cart.Book  = book;
                cart.User  = user;
                cartServer.Add(cart);
            }
            context.Response.Write("OK");
        }
示例#9
0
        /// <summary>
        /// A method to purchase the contents of the cart
        /// </summary>
        /// <returns>Order object with information about the new Order</returns>
        public OrderInfo PurchaseCart()
        {
            // Fetch the cart from session
            BLL.Cart myCart = (BLL.Cart)HttpContext.Current.Session[CART_KEY];

            // Make some checks on the cart
            if ((myCart == null) || (myCart.Count == 0))
            {
                HttpContext.Current.Server.Transfer(URL_NOCART);
                //HttpContext.Current.Response.Redirect(URL_NOCART, false);
                return(null);
            }
            else
            {
                // Build up the order
                OrderInfo newOrder = new OrderInfo();
                newOrder.UserId          = ((AccountInfo)HttpContext.Current.Session[ACCOUNT_KEY]).UserId;
                newOrder.CreditCard      = (CreditCardInfo)HttpContext.Current.Session[CREDITCARD_KEY];
                newOrder.BillingAddress  = (AddressInfo)HttpContext.Current.Session[BILLING_KEY];
                newOrder.ShippingAddress = (AddressInfo)HttpContext.Current.Session[SHIPPING_KEY];

                newOrder.LineItems = (LineItemInfo[])myCart.GetOrderLineItems().ToArray();

                newOrder.OrderTotal = myCart.Total;
                newOrder.Date       = DateTime.Now;

                // Send the order to the middle tier
                OrderInsertBO order = new OrderInsertBO();
                newOrder.OrderId = order.Insert(newOrder);

                // clear the session objects used
                HttpContext.Current.Session[CART_KEY]       = null;
                HttpContext.Current.Session[CREDITCARD_KEY] = null;
                HttpContext.Current.Session[BILLING_KEY]    = null;
                HttpContext.Current.Session[SHIPPING_KEY]   = null;

                return(newOrder);
            }
        }
示例#10
0
        override protected void OnLoad(EventArgs e)
        {
            // Create an instance of the cart controller
            ProcessFlow.CartController cartController = new ProcessFlow.CartController();

            myCart = cartController.GetCart(true);

            if (!Page.IsPostBack)
            {
                // Get the itemdId from the query string
                string itemId = Request["itemId"];

                if (itemId != null)
                {
                    // Clean the input string
                    itemId = WebComponents.CleanString.InputText(itemId, 50);
                    myCart.Add(itemId);
                    cartController.StoreCart(myCart);
                }
            }

            //Get an account controller
            ProcessFlow.AccountController accountController = new ProcessFlow.AccountController();

            //Get the user's favourite category
            string favCategory = accountController.GetFavouriteCategory();

            //If we have a favourite category, render the favourites list
            if (favCategory != null)
            {
                favorites.Visible       = true;
                ViewState[KEY_CATEGORY] = favCategory;
            }

            Refresh();
        }
示例#11
0
 /// <summary>
 /// A method to return the current state of the cart
 /// </summary>
 /// <param name="create">Specifies whether a cart should be created if one does not exist</param>
 /// <returns>Cart object</returns>
 public void StoreCart(BLL.Cart cart)
 {
     // Store the cart object in session state
     HttpContext.Current.Session[CART_KEY] = cart;
 }