|
6#
楼主 |
发表于 2006-8-9 09:55:00
|
只看该作者
【购物车】
购物车是一个子窗体:
这里主要讲一下生成订单的事件过程:分成两个步骤:第一要给tab_salerecord的表相关记录加上订单号。第二要给订单表tab_salelist添加一条记录。而订单号的形成又是一个子过程。
'生成订单
Private Sub Command30_Click()
Dim id As Integer
Dim sqlstr As String
Dim listid As String
Dim msum As Double
DoCmd.RunCommand acCmdSaveRecord
If IsNumeric(Text20) = False Then Exit Sub '如果没有货物,就退出
DoCmd.GoToRecord , , acFirst
'生成订单id号,用日期加4位号码组成,其实可以生成更人性化的号码,这里只是示意
listid = Format(Date, "yyyymmdd") & Format(DLast("id", "tab_salelist") + 1, "0000")
'更新销售表里的订单号
For i = 1 To Me.Text20
On Error Resume Next
id = Me.[id]
If Me.yn = True Then
msum = msum + Me.[msum]
sqlstr = "UPDATE tab_salerecord SET state = 1, sdate = now(),lid =" & listid & " WHERE ID=" & id
DoCmd.RunSQL (sqlstr)
End If
DoCmd.GoToRecord , , acNext
Next
'生成订单到订单表
Dim sql As String
sql = "INSERT INTO tab_salelist ( uid ,listid,sdate,lstate,mcount) values (" _
& USERID & ",'" & listid & "', #" & Format(Now(), "yyyy-mm-dd hh:nn:ss") & "#, '未处理' ," & msum & " )"
DoCmd.RunSQL (sql) '之前可以不用format() ,后来不用就发生错误???
DoCmd.OpenForm "frm_userhome"
DoCmd.Close acForm, "frm_shopcar"
End Sub
子窗体的数据来自一个查询:
Private Sub Form_Load()
'加载数据
If USERID = "" Then
MsgBox "你还没有登录"
DoCmd.Close acForm, "frm_shopcar"
Else
Dim sqlstr As String
sqlstr = "SELECT tab_salerecord.uid, tab_Pinfo.pname, tab_Pinfo.pkind, tab_Pinfo.price, " & _
"tab_Pinfo.lprice, tab_salerecord.pcount, [lprice]*tab_salerecord!pcount AS msum, tab_salerecord.ID, tab_salerecord.yn " & _
"FROM tab_Pinfo INNER JOIN tab_salerecord ON tab_Pinfo.id = tab_salerecord.pid " & _
"WHERE tab_salerecord.uid=" & USERID & "and isnull(tab_salerecord.lid)"
Me.Form.RecordSource = sqlstr
End If
End Sub
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|