📄 frmcaichan.frm
字号:
Select Case SSTab1.Tab
Case 0
DataGrid1.AllowAddNew = True
DataGrid1.AllowUpdate = True '设定datagrid可以增加记录
bm = DataGrid1.Bookmark
Case 1
DataGrid2.AllowAddNew = True
DataGrid2.AllowUpdate = True '设定datagrid可以增加记录
bm = DataGrid2.Bookmark
Case 2
DataGrid3.AllowAddNew = True
DataGrid3.AllowUpdate = True '设定datagrid可以增加记录
bm = DataGrid2.Bookmark
Case 3
DataGrid4.AllowAddNew = True
DataGrid4.AllowUpdate = True '设定datagrid可以增加记录
bm = DataGrid2.Bookmark
End Select
Else
Select Case SSTab1.Tab
Case 0
If Not IsNull(DataGrid1.Bookmark) Then
If Not IsDate(Trim(DataGrid1.Columns("登记日期").CellText(DataGrid1.Bookmark))) Then
MsgBox "请按照格式yyyy-mm-dd输入登记日期", vbOKOnly + vbExclamation, ""
Exit Sub
End If
If Trim(DataGrid1.Columns("财产编号").CellText(DataGrid1.Bookmark)) = "" Then
MsgBox "财产编号不能为空!", vbOKOnly + vbExclamation, ""
Exit Sub
End If
rs_dengji.Update
MsgBox "添加信息成功!", vbOKOnly + vbExclamation, ""
DataGrid1.AllowAddNew = False
DataGrid1.AllowUpdate = False
Else
MsgBox "没有添加信息!", vbOKOnly + vbExclamation, ""
End If
Case 1
If Not IsNull(DataGrid2.Bookmark) Then
If Not IsDate(Trim(DataGrid2.Columns("请修日期").CellText(DataGrid2.Bookmark))) Then
MsgBox "请按照格式yyyy-mm-dd输入请修日期", vbOKOnly + vbExclamation, ""
Exit Sub
End If
If Trim(DataGrid2.Columns("财产编号").CellText(DataGrid2.Bookmark)) = "" Then
MsgBox "财产编号不能为空!", vbOKOnly + vbExclamation, ""
Exit Sub
End If
rs_weixiu.Update
MsgBox "添加信息成功!", vbOKOnly + vbExclamation, ""
DataGrid2.AllowAddNew = False
DataGrid2.AllowUpdate = False
Else
MsgBox "没有添加信息!", vbOKOnly + vbExclamation, ""
End If
Case 2
If Not IsNull(DataGrid3.Bookmark) Then
If Trim(DataGrid3.Columns("财产编号").CellText(DataGrid3.Bookmark)) = "" Then
MsgBox "财产编号不能为空!", vbOKOnly + vbExclamation, ""
Exit Sub
End If
rs_toubao.Update
MsgBox "添加信息成功!", vbOKOnly + vbExclamation, ""
DataGrid3.AllowAddNew = False
DataGrid3.AllowUpdate = False
Else
MsgBox "没有添加信息!", vbOKOnly + vbExclamation, ""
End If
Case 3
If Not IsNull(DataGrid4.Bookmark) Then
If Trim(DataGrid4.Columns("产品编号").CellText(DataGrid4.Bookmark)) = "" Then
MsgBox "财产编号不能为空!", vbOKOnly + vbExclamation, ""
Exit Sub
End If
rs_zengjian.Update
MsgBox "添加信息成功!", vbOKOnly + vbExclamation, ""
DataGrid4.AllowAddNew = False
DataGrid4.AllowUpdate = False
Else
MsgBox "没有添加信息!", vbOKOnly + vbExclamation, ""
End If
End Select
cmdadd.Caption = "增加记录" '按钮名称改为“增加记录”
cmddel.Enabled = True '删除与修改按钮可用
cmdmodify.Enabled = True
cmdcancel.Enabled = False
End If
Exit Sub
adderror:
MsgBox Err.Description
End Sub
Private Sub cmdcancel_Click()
On Error GoTo cancelerror
If cmdadd.Caption = "确定" Then
cmdadd.Caption = "增加记录"
cmddel.Enabled = True
cmdmodify.Enabled = True
cmdcancel.Enabled = False
Select Case SSTab1.Tab
Case 0
rs_dengji.CancelUpdate
DataGrid1.Refresh
DataGrid1.AllowAddNew = False
DataGrid1.AllowUpdate = False
Case 1
rs_weixiu.CancelUpdate
DataGrid2.Refresh
DataGrid2.AllowAddNew = False
DataGrid2.AllowUpdate = False
Case 2
rs_toubao.CancelUpdate
DataGrid3.Refresh
DataGrid3.AllowAddNew = False
DataGrid3.AllowUpdate = False
Case 3
rs_zengjian.CancelUpdate
DataGrid4.Refresh
DataGrid4.AllowAddNew = False
DataGrid4.AllowUpdate = False
End Select
ElseIf cmdmodify.Caption = "确定" Then
cmdmodify.Caption = "修改记录"
cmdadd.Enabled = True
cmddel.Enabled = True
cmdcancel.Enabled = False
Select Case SSTab1.Tab
Case 0
rs_dengji.CancelUpdate
DataGrid1.Refresh
DataGrid1.AllowUpdate = False
Case 1
rs_weixiu.CancelUpdate
DataGrid2.Refresh
DataGrid2.AllowUpdate = False
Case 2
rs_toubao.CancelUpdate
DataGrid3.Refresh
DataGrid3.AllowUpdate = False
Case 3
rs_zengjian.CancelUpdate
DataGrid4.Refresh
DataGrid4.AllowUpdate = False
End Select
End If
cancelerror:
If Err.Number <> 0 Then
MsgBox Err.Description
End If
End Sub
Private Sub cmddel_Click()
Dim i As Integer
Dim answer As String
On Error GoTo delerror
answer = MsgBox("确定要删除吗?", vbYesNo, "")
If answer = vbYes Then
Select Case SSTab1.Tab
Case 0
DataGrid1.AllowDelete = True
rs_dengji.Delete
rs_dengji.Update
DataGrid1.Refresh
MsgBox "成功删除!", vbOKOnly + vbExclamation, ""
DataGrid1.AllowDelete = False
Case 1
DataGrid2.AllowDelete = True
rs_weixiu.Delete
rs_weixiu.Update
DataGrid2.Refresh
MsgBox "成功删除!", vbOKOnly + vbExclamation, ""
DataGrid2.AllowDelete = False
Case 2
DataGrid3.AllowDelete = True
rs_toubao.Delete
rs_toubao.Update
DataGrid3.Refresh
MsgBox "成功删除!", vbOKOnly + vbExclamation, ""
DataGrid3.AllowDelete = False
Case 3
DataGrid4.AllowDelete = True
rs_zengjian.Delete
rs_zengjian.Update
DataGrid4.Refresh
MsgBox "成功删除!", vbOKOnly + vbExclamation, ""
DataGrid4.AllowDelete = False
End Select
Else
Exit Sub
End If
delerror:
If Err.Number <> 0 Then
MsgBox Err.Description
End If
End Sub
Private Sub cmdmodify_Click()
Dim i As Integer
On Error GoTo modifyerror
If cmdmodify.Caption = "修改记录" Then '当此按钮的状态为为“增加记录”时
cmdmodify.Caption = "确定" '按钮名称改为“确定”
cmddel.Enabled = False '删除与修改按钮不可用
cmdadd.Enabled = False
cmdcancel.Enabled = True
Select Case SSTab1.Tab
Case 0
DataGrid1.AllowUpdate = True '设定datagrid可以增加记录
Case 1
DataGrid2.AllowUpdate = True '设定datagrid可以增加记录
Case 2
DataGrid3.AllowUpdate = True '设定datagrid可以增加记录
Case 3
DataGrid4.AllowUpdate = True '设定datagrid可以增加记录
End Select
Else
Select Case SSTab1.Tab
Case 0
If Not IsNull(DataGrid1.Bookmark) Then
If Not IsDate(Trim(DataGrid1.Columns("登记日期").CellValue(DataGrid1.Bookmark))) Then
MsgBox "请按照格式yyyy-mm-dd输入登记日期", vbOKOnly + vbExclamation, ""
Exit Sub
End If
If Trim(DataGrid1.Columns("财产编号").CellText(DataGrid1.Bookmark)) = "" Then
MsgBox "财产编号不能为空!", vbOKOnly + vbExclamation, ""
Exit Sub
End If
rs_dengji.Update
MsgBox "修改信息成功!", vbOKOnly + vbExclamation, ""
DataGrid1.AllowUpdate = False
Else
MsgBox "没有修改信息!", vbOKOnly + vbExclamation, ""
End If
Case 1
If Not IsNull(DataGrid2.Bookmark) Then
If Not IsDate(Trim(DataGrid2.Columns("请修日期").CellValue(DataGrid2.Bookmark))) Then
MsgBox "请按照格式yyyy-mm-dd输入请修日期", vbOKOnly + vbExclamation, ""
Exit Sub
End If
If Trim(DataGrid2.Columns("财产编号").CellText(DataGrid2.Bookmark)) = "" Then
MsgBox "财产编号不能为空!", vbOKOnly + vbExclamation, ""
Exit Sub
End If
rs_weixiu.Update
MsgBox "修改信息成功!", vbOKOnly + vbExclamation, ""
DataGrid2.AllowUpdate = False
Else
MsgBox "没有修改信息!", vbOKOnly + vbExclamation, ""
End If
Case 2
If Not IsNull(DataGrid3.Bookmark) Then
If Trim(DataGrid3.Columns("财产编号").CellValue(DataGrid3.Bookmark)) = "" Then
MsgBox "财产编号不能为空!", vbOKOnly + vbExclamation, ""
Exit Sub
End If
rs_toubao.Update
MsgBox "修改信息成功!", vbOKOnly + vbExclamation, ""
DataGrid3.AllowUpdate = False
Else
MsgBox "没有修改信息!", vbOKOnly + vbExclamation, ""
End If
Case 3
If Not IsNull(DataGrid4.Bookmark) Then
If Trim(DataGrid4.Columns("产品编号").CellText(DataGrid4.Bookmark)) = "" Then
MsgBox "财产编号不能为空!", vbOKOnly + vbExclamation, ""
Exit Sub
End If
rs_zengjian.Update
MsgBox "修改信息成功!", vbOKOnly + vbExclamation, ""
DataGrid4.AllowUpdate = False
Else
MsgBox "没有修改信息!", vbOKOnly + vbExclamation, ""
End If
End Select
cmdmodify.Caption = "修改记录" '按钮名称改为“增加记录”
cmddel.Enabled = True '删除与修改按钮可用
cmdadd.Enabled = True
cmdcancel.Enabled = False
End If
modifyerror:
If Err.Number <> 0 Then
MsgBox Err.Description
End If
End Sub
Private Sub Form_Load()
Dim sql As String
On Error GoTo loaderror
If userpow = "guest" Then '权限相关
Frame1.Enabled = False
End If
cmdcancel.Enabled = False
Select Case select_menu
Case "caichandengji"
SSTab1.Tab = 0
Case "caichanweixiu"
SSTab1.Tab = 1
Case "caichantoubao"
SSTab1.Tab = 2
Case "caichanzengjian"
SSTab1.Tab = 3
End Select
'打开财产登记数据库
sql = "select * from 财产登记"
rs_dengji.CursorLocation = adUseClient
rs_dengji.Open sql, conn, adOpenKeyset, adLockPessimistic '打开数据库
'设定datagrid控件属性
DataGrid1.AllowAddNew = False '不可增加
DataGrid1.AllowDelete = False '不可删除
DataGrid1.AllowUpdate = False
If rs_dengji.EOF = False Then
rs_dengji.MoveFirst
End If
'打开财产维修数据库
sql = "select * from 财产维修"
rs_weixiu.CursorLocation = adUseClient
rs_weixiu.Open sql, conn, adOpenKeyset, adLockPessimistic '打开数据库
'设定datagrid控件属性
DataGrid2.AllowAddNew = False '不可增加
DataGrid2.AllowDelete = False '不可删除
DataGrid2.AllowUpdate = False
If rs_weixiu.EOF = False Then
rs_weixiu.MoveFirst
End If
'打开财产投保数据库
sql = "select * from 财产投保"
rs_toubao.CursorLocation = adUseClient
rs_toubao.Open sql, conn, adOpenKeyset, adLockPessimistic '打开数据库
'设定datagrid控件属性
DataGrid3.AllowAddNew = False '不可增加
DataGrid3.AllowDelete = False '不可删除
DataGrid3.AllowUpdate = False
If rs_toubao.EOF = False Then
rs_toubao.MoveFirst
End If
'打开财产增减数据库
sql = "select * from 财产增减"
rs_zengjian.CursorLocation = adUseClient
rs_zengjian.Open sql, conn, adOpenKeyset, adLockPessimistic '打开数据库
'设定datagrid控件属性
DataGrid4.AllowAddNew = False '不可增加
DataGrid4.AllowDelete = False '不可删除
DataGrid4.AllowUpdate = False
If rs_zengjian.EOF = False Then
rs_zengjian.MoveFirst
End If
Set DataGrid1.DataSource = rs_dengji
Set DataGrid2.DataSource = rs_weixiu
Set DataGrid3.DataSource = rs_toubao
Set DataGrid4.DataSource = rs_zengjian
Exit Sub
loaderror:
MsgBox Err.Description
End Sub
Private Sub Form_Unload(Cancel As Integer)
'关闭数据库
Set DataGrid1.DataSource = Nothing
Set DataGrid2.DataSource = Nothing
Set DataGrid3.DataSource = Nothing
Set DataGrid4.DataSource = Nothing
rs_dengji.Close
rs_weixiu.Close
rs_toubao.Close
rs_zengjian.Close
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -