📄 frmalarmquery.frm
字号:
SplitCount = 1
BeginProperty Split0
BeginProperty Column00
EndProperty
BeginProperty Column01
EndProperty
EndProperty
End
End
Attribute VB_Name = "frmAlarmQuery"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim m_EventCountRs As ADODB.Recordset
Property Get GrdColumns() As Object
Set GrdColumns = GrdEvent.Columns
End Property
Property Get DataType() As String
DataType = "Grid"
End Property
Property Get PrintCaption() As String
PrintCaption = "用 户 警 情"
End Property
Public Sub PrintMe(ByRef PrintObj As Object, Optional sRangeInfo As String)
If sRangeInfo = "" Then
PrintTable GrdEvent, DatEvent.Recordset, Me, True, PrintObj, False
Else
Dim nFromPage As Integer, nEndPage As Integer
Do While Len(sRangeInfo) > 0
GetFromToEndPageNo sRangeInfo, nFromPage, nEndPage '三个参数均传址调用
PrintTable GrdEvent, DatEvent.Recordset, Me, False, PrintObj, False, nFromPage, nEndPage
Loop
End If
End Sub
Public Sub PrintHeader(PrintObj As Object, LMargin As Integer, T_PWidth As Integer)
Dim sTemp As String
If MaskBeginDate.Text = MaskEndDate.Text Then
sTemp = MaskBeginDate.Text
Else
sTemp = MaskBeginDate.Text & " --- " & MaskEndDate.Text
End If
PrintObj.CurrentX = LMargin + (T_PWidth - PrintObj.TextWidth(sTemp)) / 2
PrintObj.Print sTemp
PrintObj.Print
sTemp = lblFindKey.Caption & ": "
If cobFindKey.ListIndex = 0 Then
sTemp = sTemp & cobFindKey.List(0)
ElseIf Trim(txtFindItem.Text) = "" Then
sTemp = sTemp & cobFindKey.List(0)
Else
sTemp = sTemp & cobFindKey.List(cobFindKey.ListIndex) & Space(4)
sTemp = sTemp & lblFindItem.Caption & ": " & txtFindItem.Text
End If
PrintObj.CurrentX = LMargin
PrintObj.Print sTemp;
PrintObj.CurrentX = LMargin + T_PWidth / 2
PrintObj.Print lblAccountSum.Caption;
sTemp = lblEventType.Caption & ": " & cobEventType.List(cobEventType.ListIndex)
PrintObj.CurrentX = LMargin + T_PWidth - PrintObj.TextWidth(sTemp) - 5
PrintObj.Print sTemp;
End Sub
Public Sub PrintTail(PrintObj As Object, LMargin As Integer, T_PWidth As Integer, T_PHeight As Integer, Row_Height As Integer, nCurPage As Integer, nTotalPage As Integer)
Dim sTailText As String
PrintObj.CurrentY = T_PHeight - Row_Height * Me.RowTailCount()
sTailText = "<高特技软件>"
PrintObj.CurrentX = LMargin + 5
PrintObj.Print sTailText;
sTailText = Format(Date, "打印日期:YYYY年MM月DD日") & " 第" & nCurPage & "/" & nTotalPage & "页"
PrintObj.CurrentX = LMargin + T_PWidth - PrintObj.TextWidth(sTailText) - 5
PrintObj.Print sTailText
End Sub
Property Get RowTailCount() As Integer
RowTailCount = 1
End Property
''/////////////////////////////////////////////
'//
Private Function GetFindCondition() As String
Dim sCondition As String, sFilter As String, sText As String
sCondition = " And Alarm.FAlarmDate >= #" & Format(MaskBeginDate.Text, "yyyy/mm/dd") & "# " & _
" And Alarm.FAlarmDate <= #" & Format(MaskEndDate.Text, "yyyy/mm/dd") & "# "
sText = txtFindItem.Text
Select Case cobFindKey.ListIndex
Case 0 '全部用户
sFilter = ""
Case 1 '指定用户编码
sFilter = GetFilterString(sText, "Alarm.FAccountId", 0)
Case 2 '指定用户名称
sFilter = GetFilterString(sText, "AccountInfo.FAccountName", 2)
Case 3 '指定用户类别
sFilter = GetFilterString(sText, "AccountInfo.FAccountType", 2)
End Select
If sFilter <> "" Then
sCondition = sCondition & " And " & sFilter
End If
Select Case cobEventType.ListIndex
Case 0 '全部事件
Case 1 '报警事件
sCondition = sCondition & " And Alarm.FEventType = 'A' "
Case 2 '布防事件
sCondition = sCondition & " And Alarm.FEventType = 'O' "
Case 3 '撤防事件
sCondition = sCondition & " And Alarm.FEventType = 'C' "
Case 4 '测试信号
sCondition = sCondition & " And Alarm.FEventType = 'T' And Left(Alarm.FZoneCode,1) = '0' "
Case 5 '故障信号
sCondition = sCondition & " And Alarm.FEventType = 'T' And Left(Alarm.FZoneCode,1) = 'F' "
Case 6 '未知警情
sCondition = sCondition & " And IsNull(Sign.FSignName) "
End Select
GetFindCondition = sCondition
End Function
Private Sub RefreshScreenDate(sOrderby As String)
Dim sSqlStr As String, sGrdWidth As String, sCondition As String
Dim i As Integer
sCondition = GetFindCondition()
sSqlStr = "Select FAlarmDate, FAlarmTime, Alarm.FAccountId, FAccountName, FAddress, FTelephone, FManager, FAccountType, " & _
" iif(IsNull(ZoneArea.FZoneDescribe), Alarm.FZoneCode, Alarm.FZoneCode & '(' & ZoneArea.FZoneDescribe & ')'), " & _
" iif(IsNull(Sign.FSignName), '未知警情', Sign.FSignName) " & _
" From ((Alarm Left Join AccountInfo On Alarm.FAccountId = AccountInfo.FAccountId) " & _
" Left Join ZoneArea On Alarm.FAccountId = ZoneArea.FAccountId And Alarm.FZoneCode = " & _
" ZoneArea.FZoneCode) Left Join Sign On ZoneArea.FSignCode = Sign.FSignCode " & _
" Where Alarm.FAccountId <> '0000' " & sCondition & sOrderby
If DatEvent.RecordSource = sSqlStr Then
Exit Sub
End If
DatEvent.RecordSource = sSqlStr
DatEvent.Refresh
Set m_EventCountRs = Nothing
Set m_EventCountRs = New ADODB.Recordset
sSqlStr = "Select Alarm.FAccountId, Count(Alarm.FAccountId) as SCount " & _
" From ((Alarm Left Join AccountInfo On Alarm.FAccountId = AccountInfo.FAccountId) " & _
" Left Join ZoneArea On Alarm.FAccountId = ZoneArea.FAccountId And Alarm.FZoneCode = " & _
" ZoneArea.FZoneCode) Left Join Sign On ZoneArea.FSignCode = Sign.FSignCode " & _
" Where Alarm.FAccountId <> '0000' " & sCondition & _
" Group by Alarm.FAccountId Order by Alarm.FAccountId"
m_EventCountRs.Open sSqlStr, m_gCnAlarm, adOpenStatic, adLockReadOnly
With m_EventCountRs
If .EOF And .BOF Then
lblAccountSum.Caption = "用户数合计: 0"
Else
.MoveLast
lblAccountSum.Caption = "用户数合计: " & .RecordCount
End If
End With
With GrdEvent
sGrdWidth = GetPrivateSetting(Me.Caption, "GrdWidth", "")
.RowHeight = GetPrivateSetting(Me.Caption, "GrdHeight", "275")
i = 0
.Columns(i).Caption = "报警日期"
.Columns(i).NumberFormat = "YYYY.MM.DD"
SetColumnWidth sGrdWidth, .Columns(i), 1050
i = i + 1
.Columns(i).Caption = "报警时间"
.Columns(i).NumberFormat = "Long Time"
SetColumnWidth sGrdWidth, .Columns(i), 850
i = i + 1
.Columns(i).Caption = "用户编码"
SetColumnWidth sGrdWidth, .Columns(i), 800
i = i + 1
.Columns(i).Caption = "用户名称"
SetColumnWidth sGrdWidth, .Columns(i), 1400
i = i + 1
.Columns(i).Caption = "用户地址"
SetColumnWidth sGrdWidth, .Columns(i), 1400
i = i + 1
.Columns(i).Caption = "电话"
SetColumnWidth sGrdWidth, .Columns(i), 850
i = i + 1
.Columns(i).Caption = "负责人"
SetColumnWidth sGrdWidth, .Columns(i), 700
i = i + 1
.Columns(i).Caption = "用户类别"
SetColumnWidth sGrdWidth, .Columns(i), 850
i = i + 1
.Columns(i).Caption = "防区"
SetColumnWidth sGrdWidth, .Columns(i), 1200
i = i + 1
.Columns(i).Caption = "警情"
SetColumnWidth sGrdWidth, .Columns(i), 1200
End With
DispCurAccountAlarmCount
End Sub
Private Sub cmdColse_Click()
Unload Me
End Sub
Private Sub cmdPrint_Click()
Let frmPrint.Initial(Me.Caption, GrdColumns()) = Me
frmPrint.Show vbModal
End Sub
Private Sub cmdView_Click()
cmdDateSort_Click
End Sub
Private Sub SetButtonsStatus(sCaption As String)
cmdDateSort.Enabled = IIf(cmdDateSort.Caption = sCaption, False, True)
cmdIdSort.Enabled = IIf(cmdIdSort.Caption = sCaption, False, True)
cmdNameSort.Enabled = IIf(cmdNameSort.Caption = sCaption, False, True)
cmdTelSort.Enabled = IIf(cmdTelSort.Caption = sCaption, False, True)
cmdTypeSort.Enabled = IIf(cmdTypeSort.Caption = sCaption, False, True)
End Sub
Private Sub cmdDateSort_Click()
RefreshScreenDate (" Order by Alarm.FAlarmDate, Alarm.FAlarmTime ")
SetButtonsStatus (cmdDateSort.Caption)
End Sub
Private Sub cmdIdSort_Click()
RefreshScreenDate (" Order by Alarm.FAccountId, Alarm.FAlarmDate, Alarm.FAlarmTime ")
SetButtonsStatus (cmdIdSort.Caption)
End Sub
Private Sub cmdNameSort_Click()
RefreshScreenDate (" Order by AccountInfo.FAccountName, Alarm.FAlarmDate, Alarm.FAlarmTime ")
SetButtonsStatus (cmdNameSort.Caption)
End Sub
Private Sub cmdTelSort_Click()
RefreshScreenDate (" Order by AccountInfo.FTelephone, Alarm.FAccountId, Alarm.FAlarmDate, Alarm.FAlarmTime ")
SetButtonsStatus (cmdTelSort.Caption)
End Sub
Private Sub cmdTypeSort_Click()
RefreshScreenDate (" Order by AccountInfo.FAccountType, Alarm.FAccountId, Alarm.FAlarmDate, Alarm.FAlarmTime ")
SetButtonsStatus (cmdTypeSort.Caption)
End Sub
Private Sub cobFindKey_Click()
Select Case cobFindKey.ListIndex
Case 0
lblFindItem.Visible = False
txtFindItem.Visible = False
txtFindItem.Text = ""
Case 1, 2, 3
lblFindItem.Visible = True
txtFindItem.Visible = True
txtFindItem.SetFocus
txtFindItem.Text = ""
End Select
End Sub
Private Sub DispCurAccountAlarmCount()
On Error Resume Next
Dim sAccountId As String, nAlarmCount As Integer
sAccountId = DatEvent.Recordset![FAccountId]
With m_EventCountRs
.MoveFirst
.Find "FAccountId = '" & sAccountId & "'"
nAlarmCount = ![SCount]
lblEventCount.Caption = "当前用户报警数: " & nAlarmCount
End With
End Sub
Private Sub DatEvent_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
DispCurAccountAlarmCount
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys "{Tab}"
End If
End Sub
Private Sub Form_Load()
SetForm Me, 9
DatEvent.ConnectionString = m_gsConnection
MaskBeginDate.Text = Format(Date, "YYYY年MM月DD日")
MaskEndDate.Text = Format(Date, "YYYY年MM月DD日")
cobFindKey.AddItem "全部用户"
cobFindKey.AddItem "用户编码"
cobFindKey.AddItem "用户名称"
cobFindKey.AddItem "用户类别"
cobFindKey.ListIndex = 0
cobEventType.AddItem "全部事件"
cobEventType.AddItem "报警事件" '事件码 A
cobEventType.AddItem "布防事件" '事件码 C
cobEventType.AddItem "撤防事件" '事件码 O
cobEventType.AddItem "测试信号" '事件码 T, 防区首位码 0
cobEventType.AddItem "故障信号" '事件码 T, 防区首位码 F
cobEventType.AddItem "未知警情"
cobEventType.ListIndex = 0
RefreshScreenDate (" Order by Alarm.FAlarmDate, Alarm.FAlarmTime ")
End Sub
Private Sub Form_Resize()
On Error Resume Next
With GrdEvent
.Left = 50
.Top = 50
.Width = Me.ScaleWidth - .Left * 2
.Height = Me.ScaleHeight - picButtons.Height - PicFind.Height - .Top - 20
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
Me.MousePointer = vbDefault
Set m_EventCountRs = Nothing
End Sub
Private Sub GrdEvent_ColResize(ByVal ColIndex As Integer, Cancel As Integer)
SaveGridColWidth Me.Caption, GrdEvent
End Sub
Private Sub GrdEvent_RowResize(Cancel As Integer)
SavePrivateSetting Me.Caption, "GrdHeight", GrdEvent.RowHeight
End Sub
Private Sub MaskBeginDate_Validate(Cancel As Boolean)
If Not IsDate(MaskBeginDate.Text) Then
Cancel = True
End If
End Sub
Private Sub MaskEndDate_Validate(Cancel As Boolean)
If Not IsDate(MaskEndDate.Text) Then
Cancel = True
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -