protected void Button1_Click(object sender, EventArgs e) { //订单信息保存到后台 //正式下单 //获取当前用户 YF.Model.User myuser = new YF.Model.User();//获取当前用户信息 myuser = (YF.Model.User)YF.SessionHelper.GetSesstion("user"); //1.生成订单编号,上传商品封面有写过, string dingdanbianhao = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString(); //声明空的订单对象 YF.Model.Order myorder = new YF.Model.Order(); //声明空的订单对象 //给订单对象赋值 myorder.Id = dingdanbianhao; //赋值订单编号 myorder.User = myuser; //赋值当前用户信息 myorder.Amount = int.Parse(this.zongjia.Text); //赋值总价 myorder.State = 1; //订单状态,表示未付款 myorder.Addate = DateTime.Now; //订单时间 if (YF.BLL.Order.add(myorder)) //把订单对象,调用业务层,插入数据 { //更新购物车 YF.BLL.Shopping.updateshopping(dingdanbianhao, myuser.Id, 0);//清空购物车,通过updateshopping YF.JsHelper.AlertAndRedirect("下单成功", "/user/order.aspx"); } else { YF.JsHelper.AlertAndRedirect("下单失败", "/user/order.aspx"); } }
/// <summary> /// 把订单对象,调用数据库访问层,插入数据 /// </summary> /// <param name="order">订单实体</param> /// <returns></returns> public static bool add(YF.Model.Order order)//添加订单数据 { bool result = false; //插入 string strsql = "insert into t_order (id,userid,amount,state,adddate) values(" + order.Id + "," + order.User.Id + "," + order.Amount + "," + order.State + ",'" + order.Adddate + "')"; //执行 int i = YF.MsSqlHelper.YFMsSqlHelper.ExecuteSql(strsql); if (i > 0) { result = true; } return(result); }
/// <summary> /// 把订单对象,调用数据库访问层,插入数据 /// </summary> /// <param name="order"></param> /// <returns></returns> public static bool add(YF.Model.Order order) { return(YF.DAL.Order.add(order)); }