程序代码:
Dim cnn As ADODB.Connection Dim rs As ADODB.Recordset Dim qw As ADODB.Recordset Dim cmm As Private Sub Command1_Click() '查询按钮 Static a, b, c As Single Dim cn As New ADODB.Connection Dim rss As New ADODB.Recordset Dim rsss As New ADODB.Recordset rsss.CursorLocation = adUseClient ConnectionString = "Provider=SQLOLEDB.1;Password=1234;Persist Security Info=True;User ID=sa;Initial Catalog=csjxcglxt;Data Source=TANGJIANQIAO-PC" cn.Open ConnectionString If Text1.Text = "" Then MsgBox "输入信息不完全,请重新输入", , "提示" Exit Sub Else rss.Open "select * from 商品信息表 where 条形码 = " & Text1.Text & "", cn, adOpenKeyset, adLockOptimistic If rss.EOF Then MsgBox "没有这个商品!" rss.Close Exit Sub Else qw.AddNew qw.Fields("销售单编号") = c + 1 qw.Fields("销售日期") = Date qw.Fields("商品名称") = rss!商品名称 qw.Fields("商品单价") = rss!销售价格 qw.Fields("计量单位") = rss!计量单位 qw.Fields("商品数量") = 1 qw.Fields("总价") = Val(qw!商品单价) * Val(qw!商品数量) a = Val(qw!总价) b = a + b qw.Update End If End If Text1.Text = "" Text1.SetFocus Label3.Caption = b'显示在label3的是的总金额。 rsss.Open "select * from 商品库存表 where 商品名称 = '" & qw!商品名称 & "' ", cn, adOpenKeyset, adLockOptimistic If rsss.RecordCount = 0 Then MsgBox "没有这个商品库存!" Else rsss!商品库存量 = rsss!商品库存量 - 1 rsss.Update End If End Sub Private Sub Command2_Click()'结账按钮 If Val(Text2.Text) < Val(Label3.Caption) Then MsgBox "输入金额有误!请核实!" Exit Sub End If jzck.Show End Sub Private Sub Form_Load() Set cnn = New ADODB.Connection cnn.CursorLocation = adUseClient cnn.Open "Provider=SQLOLEDB.1;Password=1234;Persist Security Info=True;User ID=sa;Initial Catalog=csjxcglxt;Data Source=TANGJIANQIAO-PC" Set qw = New ADODB.Recordset 'datagrid显示,并隐藏部分列 Set qw.ActiveConnection = cnn qw.Open "select * from 商品销售表", cnn, adOpenDynamic, adLockBatchOptimistic Set DataGrid1.DataSource = qw DataGrid1.Columns("销售单编号").Visible = False DataGrid1.Columns("销售日期").Visible = False DataGrid1.Columns("商品编号").Visible = False DataGrid1.Columns("商品数量").Width = 1400 DataGrid1.Columns("商品单价").Width = 1300 Label3.Caption = "0" End Sub
[ 本帖最后由 t469116416 于 2014-2-11 19:06 编辑 ]