下面是更新应用程序的一些代码。每次刷新都会发生这种情况。
- Sub UpdateOutages()
- Dim rsTemp As DAO.Recordset
- Dim rsSSTemp As DAO.Recordset
- Dim strSQL As String
- Dim MyOutage As clsOutageLocation
- Dim strDev As String
- Dim ndLocation As MSComctlLib.Node
- Dim ndDevice As MSComctlLib.Node
- Dim ndBucket As MSComctlLib.Node
- Dim intcnt As Integer
- On Error GoTo Err_Control
- 'STATUS Field Values and Description
- '1 Active Record(Power Is Off)
- '2 Power Restored
- '3 Call Back
- '4 No Response
- '5 Still Out of Power
- '6 Undialable
- '7 Error
- '8 Max Dial
-
-
- strSQL = "Select * from VIEW_RECORDS WHERE [STATUS] = 1 OR [STATUS] = 5 Order by [SUBSTATION],[CIRCUIT],[MAPNUM]"
- Set rsTemp = OpenRSPorche(strSQL)
- 'Add Outages to the collection
- Do Until rsTemp.EOF
- Set MyOutage = New clsOutageLocation
- If IsNull(rsTemp.Fields("MAPNUM")) = False Then
- MyOutage.Location = rsTemp.Fields("MAPNUM")
- If Len(rsTemp.Fields("DEVICE")) > 10 Then
- strDev = Left(rsTemp.Fields("DEVICE"), 3) & "-" & Mid(rsTemp.Fields("DEVICE"), 4, 2) & "-" & Mid(rsTemp.Fields("DEVICE"), 6, Len(rsTemp.Fields("DEVICE")) - 5)
- Else
- strDev = IIf(rsTemp.Fields("DEVICE") = " ", "Unknown", rsTemp.Fields("DEVICE"))
- End If
- MyOutage.Device = strDev
- MyOutage.SubCir = IIf(Len(rsTemp.Fields("SUBSTATION")) = 2, rsTemp.Fields("SUBSTATION") & "-0" & rsTemp.Fields("CIRCUIT"), "0" & rsTemp.Fields("SUBSTATION") & "-0" & rsTemp.Fields("CIRCUIT"))
- If IsNull(rsTemp.Fields("BUCKET_NAME")) = False Then
- MyOutage.Bucket = rsTemp.Fields("BUCKET_NAME")
- Else
- MyOutage.Bucket = ""
- End If
- AddOutageToCollection MyOutage, colOutages
- End If
- rsTemp.MoveNext
- Loop
- 'check to see if any need to be deleted
- If colOutages Is Nothing Then
- ResetBlockScale
- Timer2.Enabled = False
- Else
- Timer2.Enabled = True
- For Each MyOutage In colOutages
- rsTemp.FindFirst "MAPNUM = '" & MyOutage.Location & "'"
- If rsTemp.NoMatch = True Then
- RemoveOutage MyOutage
- colOutages.Remove MyOutage.Location
- End If
- Next
- End If
-
- If cmdView.Caption = "Click to View Buckets" Then
- TreeView1(0).Visible = True
- If TreeView1(1).Nodes.Count > 0 Then
- cmdView.Enabled = True
- ClearBuckets
- InsertBuckets
- HideBuckets
- Else
- cmdView.Enabled = False
- End If
- Else
- If TreeView1(1).Nodes.Count > 0 Then
- cmdView.Enabled = True
- TreeView1(1).Visible = True
- ClearBuckets
- InsertBuckets
- ShowBuckets
- Else
- cmdView.Enabled = False
- cmdView.Caption = "Click to View Buckets"
- TreeView1(0).Visible = True
- End If
- End If
-
- Exit_Here:
- Exit Sub
-
- Err_Control:
- Select Case Err.Number
- Case Else
- LogError Err.Number, Err.Description, "UpdateOutages", "OutageTree.ctl"
- Resume Next
- End Select
- End Sub
- Private Function AddOutageToCollection(Outage As clsOutageLocation, col As Collection) As Boolean
- Dim bKeyExists As Boolean
- Dim tempOutage As clsOutageLocation
- On Error GoTo addOutageToCollection_Error
-
- bKeyExists = False
- col.Add Outage, Outage.Location ' "" Then
- 'Propably need to Add the Blocks in the AddNodeToTree Sub
- AddNodeToTree 1, Outage.Bucket, Outage.Device, Outage.Location, Outage
- Else
- 'Propably need to Add the Blocks in the AddNodeToTree Sub
- AddNodeToTree 0, Outage.SubCir, Outage.Device, Outage.Location, Outage
- End If
- Else
- Set tempOutage = col.Item(Outage.Location)
- If tempOutage.Bucket Outage.Bucket Then
- 'delete the old outage in the tree add it to the correct tree and bucket
- RemoveOutage tempOutage
- tempOutage.Bucket = Outage.Bucket
- tempOutage.Device = Outage.Device
- tempOutage.SubCir = Outage.SubCir
- If tempOutage.Bucket "" Then
- AddNodeToTree 1, tempOutage.Bucket, tempOutage.Device, tempOutage.Location, Outage
|