Beispiel #1
0
    ///用户点击购买食物,处理订单(购物车)
    protected void FoodListView_OnItemCommand(object sender, DataListCommandEventArgs e)
    {
        //未登录
        if (Session["UserName"] == null)
        {
            Page.Response.Write("<script>alert('请登录!')</script>");
            return;
        }

        //从Session获取userId,从ItemIndex获取foodId,调用逻辑层的购物车

        //从DataList中选择,得到foodid
        int foodselectindex = FoodListView.SelectedIndex = e.Item.ItemIndex;
        int foodid = foodlist.ElementAt(foodselectindex).FoodId;
        int userId = Convert.ToInt32(Session["UserId"].ToString());

        //调用逻辑层实现加入购物车
        OrderControl oc = new OrderControl();
        oc.ProductCarAddFood(userId, foodid);
        Response.Write("<script language=javascript>window.location.href='index.aspx';</script>");
    }