商品销售管理系统 第7页
Public rs2 As New ADODB.Recordset
Private Sub Command2_Click(Index As Integer)
Select Case Index
Case 0
'添加记录
Adodc1.RecordSource = "select * from 商品信息表 order by 商品编号"
a = MsgBox("是否进行添加", vbOKCancel + vbInformation)
If a = vbOK Then
DataGrid1.AllowAddNew = True
DataGrid1.AllowUpdate = True
End If
Command2(0).Enabled = False
Command2(1).Enabled = True
Command2(2).Enabled = False
Command2(3).Enabled = True
Command2(4).Enabled = True
Command2(5).Enabled = True
find_cmd.Enabled = False
Combo1.Enabled = False
Combo2.Enabled = False
Case 1
'修改记录
Adodc1.RecordSource = "select * from 商品信息表 order by 商品编号"
b = MsgBox("是否进行修改", vbOKCancel + vbInformation)
If b = vbOK Then
DataGrid1.AllowUpdate = True
End If
Command2(0).Enabled = True
Command2(1).Enabled = False
Command2(2).Enabled = False
Command2(3).Enabled = True
Command2(4).Enabled = True
Command2(5).Enabled = True
find_cmd.Enabled = True
Combo1.Enabled = True
Combo2.Enabled = True
Case 2
'删除记录
Adodc1.RecordSource = "select * from 商品信息表 order by 商品编号"
c = MsgBox("是否进行删除", vbOKCancel + vbInformation)
If c = vbOK Then
Dim varbmk As Variant
For Each varbmk In DataGrid1.SelBookmarks
Adodc1.Recordset.Bookmark = varbmk
Adodc1.Recordset.Delete
Adodc1.Recordset.UpdateBatch
Next
End If
Command2(0).Enabled = True
Command2(1).Enabled = False
Command2(2).Enabled = False
Command2(3).Enabled = True
Command2(4).Enabled = True
Command2(5).Enabled = True
find_cmd.Enabled = True
Combo1.Enabled = True
Combo2.Enabled = True
Case 3
'保存记录
Adodc1.RecordSource = "select * from 商品信息表 order by 商品编号"
d = MsgBox("是否进行保存", vbOKCancel + vbInformation)
If d = vbOK Then
DataGrid1.AllowUpdate = True
End If
St1.Panels(1).Text = "记录数: " & DataGrid1.ApproxCount & " " & "条" & " " & "当前记录为:"
Command2(2).Enabled = True
Command2(3).Enabled = False
Command2(4).Enabled = False
find_cmd.Enabled = False
Combo1.Enabled = False
Combo2.Enabled = False
Case 4
'取消记录
Adodc1.RecordSource = "select * from 商品信息表 order by 商品编号"
e = MsgBox("是否进行取消", vbOKCancel + vbInformation)
If e = vbOK Then
Adodc1.Recordset.CancelBatch
Adodc1.Recordset.CancelUpdate
End If
Command2(0).Enabled = True
Command2(1).Enabled = True
Command2(2).Enabled = True
Command2(3).Enabled = False
Command2(4).Enabled = False
find_cmd.Enabled = False
Combo1.Enabled = False
Combo2.Enabled = False
Case 5
'退出
Call cmdend(Me)
End Select
End Sub
'以回车键辅助输入数据
Private Sub DataGrid1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
If DataGrid1.Col < 8 Then
DataGrid1.Col = DataGrid1.Col + 1
DataGrid1.Scroll 1, 1
Else
If DataGrid1.Row > DataGrid1.Row - 1 Then
On Error Resume Next
DataGrid1.Row = DataGrid1.Row + 1
DataGrid1.Scroll DataGrid1.VisibleCols - 9, DataGrid1.Row + 1
DataGrid1.Col = 0
End If
End If
End If
End Sub
'更新记录
Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
Label1.Caption = DataGrid1.Row
St1.Panels(2).Text = Label1.Caption
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>