VB+ACCESS小区物业管理系统 第9页
其中添加,修改,删除按包的源码设计同上,重点分析保存按钮的源码如下:
Private Sub cmdSave_Click()
'检测数据是否完整
If Text1(0).Text = "" Then
MsgBox "设备编号不可为空!", vbOKOnly + vbInformation, "注意"
Text1(0).SetFocus
Exit Sub
ElseIf Text1(1).Text = "" Then
MsgBox "设备名称不可为空!", vbOKOnly + vbInformation, "注意"
Text1(1).SetFocus
Exit Sub
ElseIf IsDate(Text1(5).Text) = False Then
MsgBox "购买日期书写不对,应为2009-1-1这样的格式!", vbOKOnly + vbInformation, "注意"
Text1(5).SetFocus
Exit Sub
End If
'添加数据后保存
If add = 1 Then
'检测房间编号这个主键是否已经在表中存在
Dim rs_check As New ADODB.Recordset
Dim sqlCheck As String
sqlCheck = "select * from Equipment where 设备编号= '" & (Text1(0).Text) & "'"
rs_check.Open sqlCheck, conn, adOpenStatic, adLockOptimistic
If Not rs_check.EOF And Not rs_check.BOF Then
MsgBox "该设备编号已经存在,请重填一个!", vbOKOnly + vbInformation, "注意"
rs_check.Close
Text1(0).SetFocus
Text1(0).Text = ""
Exit Sub
End If
rs_check.Close
'主键不重复,可以加入表中
rs_equip.AddNew
For i = 0 To 6
rs_equip.Fields(i) = Text1(i).Text
Next i
rs_equip.Update
'添加之后显示总共条数信息加 1
Text2.Text = Val(Text2.Text) + 1
'修改数据后的保存
Else
rs_equip.Update
End If
MsgBox "保存数据成功!", vbOKOnly + vbInformation, "祝贺"
'保存后需要设置其他按钮可用,以及各个text框不可写
cmdAdd.Enabled = True
cmdEdit.Enabled = True
cmdDel.Enabled = True
cmdSave.Enabled = False
cmdCancel.Enabled = False
cmdFirst.Enabled = True
cmdPrev.Enabled = True
cmdNext.Enabled = True
cmdLast.Enabled = True
cmdQuery.Enabled = True
For i = 0 To 6
Text1(i).Enabled = False
Next i
End Sub
(该模块其它几个窗体的设计跟此窗体的设计雷同)
4.3.4数据报表统计的设计
物业设备统计
其中排序按钮的源码如下:
Private Sub cmdOrder_Click()
Dim sql As String
If rs_order.State = adStateOpen Then
rs_order.Close
End If
sql = "select * from Equipment order by " & Combo1.Text
rs_order.CursorLocation = adUseClient
rs_order.Open sql, conn, adOpenStatic, adLockOptimistic
'设置DataGrid1的数据源
Set DataGrid1.DataSource = rs_order
DataGrid1.Refresh
'使用分组统计,并显示在DataGrid2中
'首先需要设置DataGrid2可见
DataGrid2.Visible = True
'设置网格不可写
DataGrid2.AllowAddNew = False
DataGrid2.AllowDelete = False
DataGrid2.AllowUpdate = False
Dim sql2 As String
'下面的sql语句已用户选择的combo1.text分组、排序,并且统计同一个combo1.text的数量
sql2 = "select " & Combo1.Text & ", count( " & Combo1.Text & _
" ) as 数量统计 from Equipment group by " & Combo1.Text & " order by " & Combo1.Text
If rs_tg.State = adStateOpen Then
rs_tg.Close
End If
rs_tg.CursorLocation = adUseClient
rs_tg.Open sql2, conn, adOpenStatic, adLockOptimistic
'设置DataGrid2的数据源
Set DataGrid2.DataSource = rs_tg
DataGrid2.Refresh
End Sub
其它几个窗同的设计与该窗体设计雷同.排序按钮的设计参照物业设备统计按钮的设计.
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] 下一页