购物网第四阶段总结笔记2:订单页面 order_modify.aspx, order_confirm.aspx,order_ok.aspx页面

流程:当点击购物车页面中的进入收银台==》进入此页面,在此页面中填写表单,此时表单内容还不存储到数据库中,而是把表单内容传递给订单确认页面==》把order_modify.aspx页面的表单值传递给==》order_confirm.aspx页面,在此页面中点击完成的时候在把order_modify.aspx页面表单内容和商品信息存储到数据库中。

【一】: order_modify.aspx页面

确认订单按钮

知识点:页面之间的值传递:利用Session进行页面的多值传递:

在此处,Session中存放订单的实体类Model.Order,这样,Session中就存放了多个值,然后利用Session进行页面值传递。

 

        //确认订单
        protected void btnOrder_Click(object sender, EventArgs e)
        {
            string name = txtname.Text.Trim();
            string sex = ddlsex.SelectedValue;
            string address = txtaddress.Text.Trim();
            string email = txtemail.Text.Trim();
            string postcode = txtpostcode.Text.Trim();
            string phone = txtphone.Text.Trim();
            string sendtype = radsendtype.SelectedValue;
            string paytype = radpaytype.SelectedValue;

            if (name.Length==0||sex.Length==0||address.Length==0||email.Length==0||postcode.Length==0||phone.Length==0||sendtype.Length==0||paytype.Length==0)
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "MsgBox", "<script>alert('请把信息填写完整!')</script>");
                return;
            }
            //把表单中的值放在order中,然后把order放在Session中,页面间值传递,存取方便
            MyShop.Model.Order order = new MyShop.Model.Order() { 
            recname=name,
            sex=sex,
            address=address,
            email=email,
            postcode=postcode,
            phone=phone,
            sendtype=sendtype,
            paytype=paytype          
            };

            Session["order"] = order;//利用Session存储order
            Response.Redirect("order_confirm.aspx");

        }

【二】:order_confirm.aspx页面

(1):当进入此页面时候,在此页面中取出上个页面中的Session内容,并显示出来

                //显示传入的Session内容
                if (Session["order"]!=null)
                {
                    MyShop.Model.Order order = Session["order"] as MyShop.Model.Order;//把Session转换为Model类型
                    litname.Text = order.recname + "["+order.sex+"]";
                    litpostcode.Text = order.postcode;
                    litaddress.Text = order.address;
                    litphone.Text = order.phone;
                    litemail.Text = order.email;
                    litsendtype.Text = order.sendtype;
                    litpaytype.Text = order.paytype;

                    litsendmoney.Text = GetSendMoney(order.sendtype).ToString("c2");
                    litAllmoney.Text = (GetSendMoney(order.sendtype) + sc.GetTotlePrice()).ToString("c2");
                    
                }
                else
                {
                    Response.Write("订单信息为空,请重新购买!");
                    Response.End();
                    return;
                }


        //计算送货费用
        private decimal GetSendMoney(string p)
        {
            int sendmoney = 0;
            if (p == "特快专递(EMS)")
            {
                sendmoney = 150;
            }
            else if (p=="普通平邮")
            {
                sendmoney = 80;
            }
            return sendmoney;
        }

(2):订单完成:把上个页面传递过来的Session内容插入到数据库中:

        //订单完成
        protected void btnOk_Click(object sender, EventArgs e)
        {
            //购物车为空
            if (Session["shopcart"] == null)//如果Session["shopcart"]不存在
            {
                Session["shopcart"] = new Model.ShopCart();
            }
            Model.ShopCart sc = Session["shopcart"] as Model.ShopCart;
            if (sc.GetItemCount()==0)
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "MsgBox", "<script>alert('购物车为空!')</script>");
                return;
            }
            //订单信息为空
            if (Session["order"] == null)
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "MsgBox", "<script>alert('订单信息为空!')</script>");
                return;
            }


            
            MyShop.Model.Order order = Session["order"] as MyShop.Model.Order;//把Session转换为Model类型
            order.fp = chkfp.Checked ? 1 : 0;
            order.detailsmoney = sc.GetTotlePrice();
            order.sendmoney = GetSendMoney(order.sendtype);
            order.username = User.Identity.Name;
            string bh = DateTime.Now.ToString("yyyyMMdd") + sc.GetTotlePrice();
            order.orderbh=bh;//订单编号:当前日前+商品总价格
            order.remark = txtremark.Text.Trim();


            int orderid = new MyShop.DAL.OrderDAO().Add(order);


            if (orderid > 0)
            {


                //d订单插入成功,可以插入订单明细orderdetails
                MyShop.DAL.OrderdetailsDAO orderdetail = new MyShop.DAL.OrderdetailsDAO();
                foreach (Model.ShopItem item in sc.GetItemList())
                {
                    orderdetail.Add(new MyShop.Model.Orderdetails() { 
                    createDate=DateTime.Now,
                    orderid=orderid,
                    price=item.Price,
                    proid=item.Proid,
                    quantity=item.Quantity
                    });
                }
                
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "MsgBox", "<script>alert('下单成功!');location.href='order_ok.aspx?orderbh="+bh+"'</script>");
                Session["order"] = null;//订单清空
                Session["shopcart"] =null;//购物车清空
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "MsgBox", "<script>alert('订单添加失败,请联系管理员!')</script>");
                return;
            }


        }

【三】:order_ok.aspx页面:把上一级页面order_confirm.aspx页面传入的订单编号显示出来

           if (!IsPostBack)
            {
                string orderbh=Request.QueryString["orderbh"];
                if (!string.IsNullOrEmpty(orderbh))
                {
                    litorderbh.Text = orderbh;//显示订单编号
                }
            }



 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值