コード例 #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            FirstName.Text = Profile.FirstName;
            LastName.Text  = Profile.LastName;
        }

        List <List <string> > datasource = new List <List <string> >();
        var cart = (List <long>)(Session[User.Identity.Name + "-cart"]);

        if (cart != null)
        {
            SqlConnection sql   = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnectionStringLibraria"].ConnectionString);
            string        query = "SELECT Id, Author, Title, CoverUrl FROM Books WHERE ";

            foreach (var id in cart)
            {
                query += "Id = '" + id.ToString() + "' OR ";
            }
            query  = query.Substring(0, query.Length - 3);
            query += "ORDER BY Author";

            try
            {
                sql.Open();

                SqlCommand    cmd    = new SqlCommand(query, sql);
                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    datasource.Add(
                        new List <string>()
                    {
                        (string)reader["Author"],
                        (string)reader["Title"],
                        (string)reader["CoverUrl"]
                    }
                        );
                }
            }
            catch (SqlException)
            { }
            finally
            {
                sql.Close();
            }

            ShoppingCartRepeater.DataSource = datasource;
            ShoppingCartRepeater.DataBind();
        }
    }
コード例 #2
0
    public void bindCart()
    {
        shoppingCart = (Cart)Session["ShoppingCart"];

        if (shoppingCart == null)
        {
            ShoppingCartRepeater.DataSource = null;
        }
        else
        {
            cartTotal = shoppingCart.Total;
            ShoppingCartRepeater.DataSource = shoppingCart.CartItems;
        }

        ShoppingCartRepeater.DataBind();
    }
コード例 #3
0
        protected void DrawShoppingCart()
        {
            List <CustomerWares> customerWareses = new List <CustomerWares>();

            if (Session["CustomerWares"] != null)
            {
                customerWareses      = Session["CustomerWares"] as List <CustomerWares>;
                showItemsInCart.Text = customerWareses.Count.ToString();
            }
            else
            {
                Session["CustomerWares"] = null;
                showItemsInCart.Text     = "0";
            }

            ShoppingCartRepeater.DataSource = customerWareses;
            ShoppingCartRepeater.DataBind();
        }
コード例 #4
0
    public void bindCart()
    {
        shoppingCart = (Cart)Session["ShoppingCart"];

        if (shoppingCart == null)
        {
            ShoppingCartRepeater.DataSource = null;
            messageLabel.Text = "Your Shopping Cart Is Empty";
        }
        else
        {
            cartTotal = shoppingCart.Total;
            ShoppingCartRepeater.DataSource = shoppingCart.CartItems;
            messageLabel.Text = "My Cart";
        }



        ShoppingCartRepeater.DataBind();
    }