zoukankan      html  css  js  c++  java
  • asp.net购物车,订单以及模拟支付宝支付(三)---提交订单

    在设计完订单表之后,就要整理一下订单处理的流程了

    首先,用户在购物车界面点击结算的时候,跳到一个结算确认页面(这时候只是确认,让用户填写收货地址等,没有真正的下订单),显示用户的地址等信息和要买的物品,总价等,当用户点击确定的时候,调用存储过程下订单(向订单表和订单明细表插入数据,并删除相应的购物车项,这里用到事务和批量插入的sql语句),去网上支付

    存储过程如下,mssql2005:

    create proc pro_pay
    @orderId nvarchar(200),--订单号,这里是根据当前时间(精确到毫秒)+用户Id
    @userId int,           --用户Id
    @address nvarchar(200),--收货地址
    @totalPrice decimal(10, 2) output--输出参数,总金额
    as
    --记录错误信息的变量
    declare @error int
    set @error=0
    --计算总价格
    select @totalPrice=sum(UnitPrice*[Count]) from T_Car inner join T_Books on T_Car.BookId=T_Books.Id
    where UserId=@UserId
    --开始事务
    begin transaction
    --插入主表
    insert into T_Orders(Id,OrderDate,UserId,TotalPrice,[Address]) values(@orderId,getdate(),@UserId,@totalPrice,@address)
    set @error=@error+@@error
    --插入明细表
    insert into T_OrderBook(OrderId,BookId,[Count],UnitPrice) select @orderId,BookId,[Count],UnitPrice
    from T_Car inner join T_Books on T_Car.BookId=T_Books.Id where UserId=@userId
    set @error=@error+@@error
    --删除购物车选项
    delete from T_Car where UserId=@userId
    set @error=@error+@@error
    --完成事务
    if(@error>0)
     begin
      rollback transaction
     end
    else
     begin
      commit transaction
     end 
    调用完存储过程之后,就是跳转到支付宝支付了,需要说明的是,使用ado.net调用存储过程的时候会遇到一些问题,主要是要将SqlCommand的CommandType属性设置为CommandType.StoredProcedure,然后将存储过程名传入(之前不懂以为是要写exec+存储过程名,结果只要存储过程名就好了,是不是我太天真了= =。。。)


  • 相关阅读:
    android之AlertDialog 点击其它区域自己主动消失
    leetCode191/201/202/136 -Number of 1 Bits/Bitwise AND of Numbers Range/Happy Number/Single Number
    CEF 框架使用集锦
    Qt WebEngine Debugging and Profiling
    Qt内置浏览器引擎WebEngine调试和分析方法
    QWebEngine踩坑记录
    带外(out of band)数据
    碰撞检测算法:点和矩形碰撞、点和圆形碰撞、矩形碰撞、圆形碰撞
    windows 7 安装visual studio 2019 闪退问题解决
    最小二乘法
  • 原文地址:https://www.cnblogs.com/jchubby/p/4429760.html
Copyright © 2011-2022 走看看