Ejemplo n.º 1
0
        public static List <YF.Model.Shopping> Dotolist(DataTable dt)
        {
            List <YF.Model.Shopping> list = new List <Model.Shopping>();//空的泛型对象  转换

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                YF.Model.Shopping shopping = new Model.Shopping();//空对象

                shopping.Id = int.Parse(dt.Rows[i]["id"].ToString());

                //当前商品
                YF.Model.Goods goods = YF.DAL.Goods.GetGoods(int.Parse(dt.Rows[i]["goodsid"].ToString())); //通过id 得到商品实列对象
                shopping.Goods = goods;                                                                    //商品赋值=上面的goods

                //当前用户
                YF.Model.User user = YF.DAL.User.GetUser(int.Parse(dt.Rows[i]["userid"].ToString())); //通过id 得到用户实列对象
                shopping.User = user;                                                                 //商品赋值=上面的user

                shopping.Num    = int.Parse(dt.Rows[i]["num"].ToString());
                shopping.State  = int.Parse(dt.Rows[i]["state"].ToString());
                shopping.Addate = DateTime.Parse(dt.Rows[i]["addate"].ToString());
                list.Add(shopping); //空的泛型对象+数据
            }
            return(list);
        }
Ejemplo n.º 2
0
        public static bool add(YF.Model.Goods goods)
        {
            bool   result = false;
            string strsql = "insert into t_goods(title,price,num,img,detail,state,addate) values('" + goods.Title + "'," + goods.Price + "," + goods.Num + ",'" + goods.Img + "','" + goods.Detail + "'," + goods.State + ",'" + goods.Addate + "')";
            int    i      = 0;

            i = YF.MsSqlHelper.YFMsSqlHelper.ExecuteSql(strsql);
            if (i > 0)
            {
                result = true;
            }
            return(result);
        }
Ejemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //获取id
            string id = Request["id"];

            YF.Model.Goods goods = YF.BLL.Goods.GetGoods(int.Parse(id));
            this.title.Text   = goods.Title;
            this.price.Text   = goods.Price.ToString();
            this.num.Text     = goods.Num.ToString();
            this.detail.Text  = goods.Detail.ToString();
            this.img.ImageUrl = " .. / admin / +goods.Img.ToString()";
            this.img.Width    = 180;
        }
Ejemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //向后台数据库加入记录,点击购买,购物车加
            YF.Model.User myuser = new YF.Model.User();
            myuser = (YF.Model.User)YF.SessionHelper.GetSesstion("user");//读取当前用户信息  //强制转
            if (myuser != null)
            {
                YF.Model.Shopping shopping = new YF.Model.Shopping();                         //1,声明空的购物车对象
                int            id          = int.Parse(Request.QueryString["id"].ToString()); //通过id查询,传过来的,转化数字
                YF.Model.Goods goods       = YF.BLL.Goods.GetGoods(id);                       ////4,声明一个商品对象,通过id查询
                //5,空对象赋值
                shopping.Goods  = goods;
                shopping.User   = myuser;//等于当前用户
                shopping.Num    = 1;
                shopping.State  = 0;
                shopping.Addate = DateTime.Now;

                if (YF.BLL.Shopping.list(goods.Id, myuser.Id, 0).Count > 0)      //查询商品是否是第一次,,不是第一次,已经存在之前有添加,则修改数量
                {
                    YF.BLL.Shopping.updatenum(goods.Id, myuser.Id, 0);           //修改数量
                    YF.JsHelper.AlertAndRedirect("添加成功", "/user/shopping.aspx"); //3,添加成功返回购物车页面
                }
                else
                {
                    if (YF.BLL.Shopping.add(shopping))                               //2,调用业务类,判断逻辑。真,操作成功//第一次
                    {
                        YF.JsHelper.AlertAndRedirect("操作成功", "/user/shopping.aspx"); //3,返回购物车页面
                    }
                    else
                    {
                        YF.JsHelper.AlertAndRedirect("操作失败", "/user/shopping.aspx");//不成功购物,失败
                    }
                }
            }
            else
            {
                YF.JsHelper.AlertAndRedirect("尚未登录", "/login.aspx");
            }
        }