牛腩购物网30:用户中心其他功能制作(获取购物的总金额,判断用户是 普通会员还是VIP会员,用户申请VIP)

1:获取购物的总金额

 //积分

     litIntegral.Text = u.integral.ToString() ;



    //购物总金额

     litALLTotalPrice.Text = new DAL.OrderDAO().CalcCount("username='" + User.Identity.Name + "' and state=5 and isdel=0 ").ToString();





   //收藏的商品数

    LitFavCount.Text = new DAL.FavoriteDAO().CalcCount("username='" + User.Identity.Name +"'").ToString(); 

 

 

2:判断用户的类别

//在登陆的窗口这里,如果登陆后,显示是什么会员类型

            if (Page.User.Identity.IsAuthenticated)

            {

                Model.User u = new DAL.UserDAO().GetModel(Page.User.Identity.Name);

                if (u!=null)

                {

                    Literal litIsVip = LoginView1.FindControl("litIsVip") as Literal;

                    litIsVip.Text = u.type == "normal" ? "普通会员" : "VIP会员";

                    

                }

            }

 

3:申请VIP

//申请VIP

        protected void btnSqVip_Click(object sender, EventArgs e)

        {

            Model.User u = new DAL.UserDAO().GetModel(User.Identity.Name);



            if (u != null)

            {

                if (u.type == "vip")

                {

                    Utility.Tool.alert("您已经是VIP会员", this.Page);

                    return;

                }

                else

                {

                    if (u.integral < 10000)

                    {

                        Utility.Tool.alert("您的积分不足10000分,不能申请VIP", this.Page);

                        return;

                    }

                    else

                    {

                        new DAL.UserDAO().UpdateType(User.Identity.Name, "vip");

                        Utility.Tool.alert("vip会员申请成功", Request.Url.ToString(), this.Page);

                        return;

                    }

                }

            }

        }

 

//修改会员为 VIP会员

        public void UpdateType(string username, string type)

        {



            string sql = "update shop_user set integral=integral-10000,type=@type where username=@username";



            Database db = DatabaseFactory.CreateDatabase();

            DbCommand dbcommand=db.GetSqlStringCommand(sql);

            db.AddInParameter(dbcommand, "type", DbType.String, type);

            db.AddInParameter(dbcommand, "username", DbType.String, username);

            db.ExecuteNonQuery(dbcommand);

        }

你可能感兴趣的:(vi)