我想用vb做个商品折损模块,如图
把折损的数量输入后,首先把这个折损单写入折损表,然后查询折损的商品编号,在库存表中减去折损的数量,并显示在每个表的datagrid上。
程序代码:
Private Sub Command1_Click() '确定添加按钮 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 = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Or Text5.Text = "" Or Text6.Text = "" Or Text7.Text = "" Then MsgBox "输入信息不完全,请重新输入", , "提示" Exit Sub Else rss.Open "select * from 商品库存表 where 商品编号 = str(" & Text1.Text & ")", cn, adOpenKeyset, adLockOptimistic rsss.Open "select * from 商品折损表 ", cn, adOpenDynamic, adLockBatchOptimistic rsss.AddNew rsss.Fields("折损单编号") = Text1.Text rsss.Fields("折损商品编号") = Text2.Text rsss.Fields("折损商品名称") = Text3.Text rsss.Fields("数量") = Text4.Text rsss.Fields("折损原因") = Text6.Text rsss.Fields("日期") = Text7.Text rsss.Fields("金额") = Text5.Text rsss.Update rss!商品库存量 = rss!商品库存量 - Val(Text4.Text) rss.Update MsgBox "已添加" End If spzsglck.Adodc1.Refresh '表格马上更新 Set spzsglck.DataGrid1.DataSource = spzsglck.Adodc1 spzsglck.DataGrid1.Refresh spzsglck.Show Unload Me End Sub Private Sub Command2_Click() Unload Me End Sub Private Sub Form_Load() Text6.Text = "过期" Text7.Text = Date End Sub