VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmMachine 
   BackColor       =   &H00808080&
   Caption         =   "Atendimento"
   ClientHeight    =   9645
   ClientLeft      =   900
   ClientTop       =   2220
   ClientWidth     =   7260
   ClipControls    =   0   'False
   ControlBox      =   0   'False
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   NegotiateMenus  =   0   'False
   ScaleHeight     =   9645
   ScaleWidth      =   7260
   Begin VB.PictureBox Picture1 
      Height          =   2895
      Left            =   3825
      Picture         =   "frmMachine.frx":0000
      ScaleHeight     =   2835
      ScaleWidth      =   2295
      TabIndex        =   19
      Top             =   3465
      Width           =   2355
   End
   Begin VB.PictureBox picHolder 
      Align           =   3  'Align Left
      Appearance      =   0  'Flat
      BackColor       =   &H00FFFFFF&
      BorderStyle     =   0  'None
      ForeColor       =   &H80000008&
      Height          =   9315
      Left            =   0
      ScaleHeight     =   621
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   112
      TabIndex        =   2
      Top             =   0
      Width           =   1680
      Begin VB.CheckBox chkAll 
         BackColor       =   &H00FFFFFF&
         Caption         =   "All"
         Height          =   195
         Left            =   1170
         TabIndex        =   14
         Top             =   90
         Width           =   465
      End
      Begin Synapsis.SimpleButton SbnCommands 
         Height          =   420
         Index           =   0
         Left            =   540
         TabIndex        =   3
         Top             =   315
         Width           =   960
         _ExtentX        =   2487
         _ExtentY        =   1931
         Picture         =   "frmMachine.frx":0C42
      End
      Begin Synapsis.SimpleButton SbnCommands 
         Height          =   420
         Index           =   1
         Left            =   540
         TabIndex        =   4
         Top             =   765
         Width           =   960
         _ExtentX        =   2487
         _ExtentY        =   1931
         Picture         =   "frmMachine.frx":12B0
      End
      Begin Synapsis.SimpleButton SbnCommands 
         Height          =   420
         Index           =   2
         Left            =   540
         TabIndex        =   5
         Top             =   1305
         Width           =   960
         _ExtentX        =   2487
         _ExtentY        =   1931
         Picture         =   "frmMachine.frx":1944
      End
      Begin Synapsis.SimpleButton SbnCommands 
         Height          =   420
         Index           =   3
         Left            =   540
         TabIndex        =   6
         Top             =   1755
         Width           =   960
         _ExtentX        =   2487
         _ExtentY        =   1931
         Picture         =   "frmMachine.frx":1FFC
      End
      Begin Synapsis.SimpleButton SbnCommands 
         Height          =   420
         Index           =   4
         Left            =   540
         TabIndex        =   7
         Top             =   2295
         Width           =   960
         _ExtentX        =   2487
         _ExtentY        =   1931
         Picture         =   "frmMachine.frx":26CA
      End
      Begin Synapsis.SimpleButton SbnCommands 
         Height          =   420
         Index           =   5
         Left            =   540
         TabIndex        =   8
         Top             =   3195
         Width           =   960
         _ExtentX        =   2487
         _ExtentY        =   1931
         Picture         =   "frmMachine.frx":2D1B
      End
      Begin Synapsis.SimpleButton SbnCommands 
         Height          =   420
         Index           =   6
         Left            =   540
         TabIndex        =   9
         Top             =   2745
         Width           =   960
         _ExtentX        =   2487
         _ExtentY        =   1931
         Picture         =   "frmMachine.frx":33B7
      End
      Begin Synapsis.SimpleButton SbnCommands 
         Height          =   420
         Index           =   7
         Left            =   540
         TabIndex        =   10
         Top             =   5535
         Width           =   960
         _ExtentX        =   2487
         _ExtentY        =   1931
         Picture         =   "frmMachine.frx":3B10
      End
      Begin Synapsis.SimpleButton SbnCommands 
         Height          =   420
         Index           =   8
         Left            =   540
         TabIndex        =   11
         Top             =   5985
         Width           =   960
         _ExtentX        =   2487
         _ExtentY        =   1931
         Picture         =   "frmMachine.frx":421E
      End
      Begin Synapsis.SimpleButton SbnCommands 
         Height          =   420
         Index           =   9
         Left            =   540
         TabIndex        =   15
         Top             =   3645
         Width           =   960
         _ExtentX        =   2487
         _ExtentY        =   1931
         Picture         =   "frmMachine.frx":495A
      End
      Begin Synapsis.SimpleButton SbnCommands 
         Height          =   420
         Index           =   10
         Left            =   540
         TabIndex        =   16
         Top             =   4185
         Width           =   960
         _ExtentX        =   2487
         _ExtentY        =   1931
         Picture         =   "frmMachine.frx":50AC
      End
      Begin Synapsis.SimpleButton SbnCommands 
         Height          =   420
         Index           =   11
         Left            =   540
         TabIndex        =   17
         Top             =   6435
         Width           =   960
         _ExtentX        =   2487
         _ExtentY        =   1931
         Picture         =   "frmMachine.frx":57F2
      End
      Begin Synapsis.SimpleButton SbnCommands 
         Height          =   420
         Index           =   12
         Left            =   540
         TabIndex        =   18
         Top             =   4635
         Width           =   960
         _ExtentX        =   2487
         _ExtentY        =   1931
         Picture         =   "frmMachine.frx":5F4A
      End
      Begin VB.Label lblDeco 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "User"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   240
         Index           =   1
         Left            =   90
         TabIndex        =   13
         Top             =   5265
         Width           =   435
      End
      Begin VB.Label lblDeco 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "Equipment"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   240
         Index           =   0
         Left            =   90
         TabIndex        =   12
         Top             =   45
         Width           =   1005
      End
   End
   Begin VB.Timer tmrCheckClient 
      Enabled         =   0   'False
      Interval        =   5000
      Left            =   2385
      Top             =   5715
   End
   Begin MSComctlLib.StatusBar stbMain 
      Align           =   2  'Align Bottom
      Height          =   330
      Left            =   0
      TabIndex        =   1
      Top             =   9315
      Width           =   7260
      _ExtentX        =   12806
      _ExtentY        =   582
      _Version        =   393216
      BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
         NumPanels       =   2
         BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Alignment       =   1
            AutoSize        =   1
            Object.Width           =   11033
            MinWidth        =   1058
         EndProperty
         BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Alignment       =   1
            Bevel           =   2
            Object.Width           =   1235
            MinWidth        =   1235
            Text            =   "Fechar"
            TextSave        =   "Fechar"
         EndProperty
      EndProperty
   End
   Begin MSComctlLib.ListView lstMachines 
      Height          =   5595
      Left            =   2160
      TabIndex        =   0
      Top             =   2205
      Width           =   6135
      _ExtentX        =   10821
      _ExtentY        =   9869
      LabelEdit       =   1
      MultiSelect     =   -1  'True
      LabelWrap       =   -1  'True
      HideSelection   =   0   'False
      FullRowSelect   =   -1  'True
      _Version        =   393217
      Icons           =   "imgLstServer"
      SmallIcons      =   "imgLstServer"
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      Appearance      =   0
      NumItems        =   6
      BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         Text            =   "ID"
         Object.Width           =   1587
      EndProperty
      BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   1
         Text            =   "Máquina"
         Object.Width           =   2469
      EndProperty
      BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   2
         Text            =   "Usuário"
         Object.Width           =   2469
      EndProperty
      BeginProperty ColumnHeader(4) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   3
         Text            =   "Início"
         Object.Width           =   1411
      EndProperty
      BeginProperty ColumnHeader(5) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   4
         Text            =   "Fim"
         Object.Width           =   1411
      EndProperty
      BeginProperty ColumnHeader(6) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   5
         Text            =   "Período"
         Object.Width           =   1411
      EndProperty
   End
   Begin MSComctlLib.ImageList imgLstServer 
      Left            =   1755
      Top             =   5715
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483643
      ImageWidth      =   32
      ImageHeight     =   32
      MaskColor       =   16777215
      _Version        =   393216
      BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
         NumListImages   =   5
         BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmMachine.frx":6645
            Key             =   ""
         EndProperty
         BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmMachine.frx":6E97
            Key             =   ""
         EndProperty
         BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmMachine.frx":76E9
            Key             =   ""
         EndProperty
         BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmMachine.frx":7F3B
            Key             =   ""
         EndProperty
         BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmMachine.frx":878D
            Key             =   ""
         EndProperty
      EndProperty
   End
   Begin VB.Image Image1 
      Height          =   1155
      Left            =   4275
      Picture         =   "frmMachine.frx":8FDF
      Stretch         =   -1  'True
      Top             =   495
      Width           =   1650
   End
End
Attribute VB_Name = "frmMachine"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub chkAll_Click()
On Error GoTo pschkAll_ClickErr 'EHCG.UID.pschkAll_Click

Dim lObjList As ListItem

    If Me.chkAll.Value <> 0 Then

        For Each lObjList In Me.lstMachines.ListItems
        lObjList.Selected = False
        Next lObjList

    End If

Exit Sub
pschkAll_ClickErr:
Err.Raise Err.number, Err.Source, "ps.chkAll_Click:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Sub LoadMachineList()
On Error GoTo sLoadMachineListErr 'EHCG.UID.sLoadMachineList

Dim lsSQL As String, loRS As ADODB.Recordset, lobjItem As ListItem, uStrVar As String, uPeriod As Date

lsSQL = "SELECT M.*, MS.lastchange, MS.user_timelimit, U.alias, U.Name, MSD.descr FROM [user] AS U RIGHT JOIN (machine_status_def AS MSD RIGHT JOIN (machine AS M LEFT JOIN machine_status AS MS ON M.ID = MS.MachineID) ON MSD.ID = MS.machine_status_defID) ON U.ID = MS.userID;"


Me.lstMachines.ListItems.Clear

Set loRS = Data.Database.Execute(lsSQL)

    Do While Not loRS.EOF
    Set lobjItem = Me.lstMachines.ListItems.Add
    lobjItem.Text = IIf(IsNull(loRS("sign")), "", loRS("sign"))
    lobjItem.Key = Replace(loRS("MACAddress"), ".", "")
    lobjItem.SubItems(1) = ValidStr(loRS("NetName"))
    lobjItem.SubItems(2) = ValidStr(loRS("alias"))

        If ValidStr(loRS("alias")) <> "" Then
        Send GetIP(loRS("MACAddress")), "USERINFO|" & ValidStr(loRS("alias"))
        End If

        If Not IsNull(loRS("lastchange")) Or (loRS("lastchange") <> "") Then
        lobjItem.SubItems(3) = Right$("0" & Hour(loRS("lastchange")), 2) & ":" & Right$("0" & Minute(loRS("lastchange")), 2)
        
        uPeriod = Time - CDate(lobjItem.SubItems(3))
        uStrVar = Right$("0" & Hour(uPeriod), 2) & ":" & Right$("0" & Minute(uPeriod), 2)
        lobjItem.SubItems(5) = uStrVar
        
        End If

        If Not IsNull(loRS("user_timelimit")) Or (loRS("user_timelimit") <> "") Then
        uStrVar = Right$("0" & Hour(loRS("user_timelimit")), 2) & ":" & Right$("0" & Minute(loRS("user_timelimit")), 2)
        lobjItem.SubItems(4) = uStrVar

            If CDate(uStrVar) < Time() Then
            lobjItem.ForeColor = &HFF
            lobjItem.Bold = True

            Else
            lobjItem.ForeColor = &H0
            lobjItem.Bold = False

            End If
            


        End If

    lobjItem.SmallIcon = 1
    lobjItem.Icon = 1

    loRS.MoveNext
    Loop

Set loRS = Nothing

Exit Sub
sLoadMachineListErr:
Err.Raise Err.number, Err.Source, "s.LoadMachineList:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub

Private Sub Form_Load()
On Error GoTo psForm_LoadErr 'EHCG.UID.psForm_Load

Data.MachineListLoaded = True
Call LoadMachineList
SendBroadcast "PING?"
SendBroadcast "SCHEDULEPING|5000"

Exit Sub
psForm_LoadErr:
Err.Raise Err.number, Err.Source, "ps.Form_Load:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Private Sub Form_Resize()
On Error GoTo psForm_ResizeErr 'EHCG.UID.psForm_Resize

Me.lstMachines.Left = Me.picHolder.Width
Me.lstMachines.Top = 0
Me.lstMachines.Width = Me.ScaleWidth - Me.picHolder.Width
Me.lstMachines.Height = Me.ScaleHeight - Me.stbMain.Height

Exit Sub
psForm_ResizeErr:
Err.Raise Err.number, Err.Source, "ps.Form_Resize:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error GoTo psForm_UnloadErr 'EHCG.UID.psForm_Unload

Data.MachineListLoaded = False

Exit Sub
psForm_UnloadErr:
Err.Raise Err.number, Err.Source, "ps.Form_Unload:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Private Sub lstMachines_Click()
On Error GoTo pslstMachines_ClickErr 'EHCG.UID.pslstMachines_Click

Me.chkAll.Value = 0

Exit Sub
pslstMachines_ClickErr:
Err.Raise Err.number, Err.Source, "ps.lstMachines_Click:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Private Sub lstMachines_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
On Error GoTo pslstMachines_ColumnClickErr 'EHCG.UID.pslstMachines_ColumnClick

    With Me.lstMachines
    .Sorted = True

        If (.SortKey = ColumnHeader.Index - 1) Then

            If .SortOrder <> lvwAscending Then
            .SortOrder = lvwAscending
            Else
            .SortOrder = lvwDescending
            End If

        Else
        .SortOrder = lvwAscending

        End If

    .SortKey = ColumnHeader.Index - 1
    End With

Exit Sub
pslstMachines_ColumnClickErr:
Err.Raise Err.number, Err.Source, "ps.lstMachines_ColumnClick:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Private Sub lstMachines_DragDrop(Source As Control, x As Single, y As Single)
On Error GoTo pslstMachines_DragDropErr 'EHCG.UID.pslstMachines_DragDrop

'On Error Resume Next
Dim Key As String

Key = Me.lstMachines.HitTest(x, y).Key

    If Err.number > 0 Then Exit Sub

    Select Case Source.Name
    Case "lstUsers"
    PutUserOnMachine Key, Data.UserOnDrag

    Case "lstMachines"

    End Select

Exit Sub
pslstMachines_DragDropErr:
Err.Raise Err.number, Err.Source, "ps.lstMachines_DragDrop:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub

Private Sub SbnCommands_Click(Index As Integer)

    Select Case Index
    Case 0 'Lock
        DoAction "LOCK"
        
    Case 1 'Unlock
        DoAction "UNLOCK"

    Case 2 'turn On
        TurnOnComputers
        
    Case 3 'turn Off
        DoAction "TURNOFF"
        
    Case 4 'Reboot
        DoAction "SHUTANDLOAD"
        
    Case 5 'Identify
        DoAction "UNLOCK"
        DoAction "QUERYID"

    Case 6 'Log Off
        DoAction "LOGOFF"
        
    Case 7 'Kick User
        DropUsers

    Case 8 'Transfer
    
    Case 9 'Adjust Video Settings
        DoAction "SETRESOLUTION|1280|1024|32"
    
    
    Case 10 'Kill Neuron
        DoAction "SHUTDOWN"
    
    Case 11 'Add Time
        AddTime
    
    Case 12 'Update Neuron
    
    End Select

End Sub

Private Sub stbMain_PanelClick(ByVal Panel As MSComctlLib.Panel)
On Error GoTo psstbMain_PanelClickErr 'EHCG.UID.psstbMain_PanelClick

    If Panel.Index = 2 Then
    Unload Me
    End If

Exit Sub
psstbMain_PanelClickErr:
Err.Raise Err.number, Err.Source, "ps.stbMain_PanelClick:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Private Sub tmrCheckClient_Timer()
On Error GoTo pstmrCheckClient_TimerErr 'EHCG.UID.pstmrCheckClient_Timer

Dim uListItem As ListItem

    For Each uListItem In Me.lstMachines.ListItems
    uListItem.SmallIcon = 1
    uListItem.Icon = 1
    Next uListItem

Data.Machines.CheckStatus

SendBroadcast "PING?"

Exit Sub
pstmrCheckClient_TimerErr:
Err.Raise Err.number, Err.Source, "ps.tmrCheckClient_Timer:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Sub UpdateMachineStatus(lsMACAddress As String, pIntStatus As Integer)
On Error GoTo sUpdateMachineStatusErr 'EHCG.UID.sUpdateMachineStatus

Dim uListItem As ListItem, lMAC As String
lMAC = Replace(lsMACAddress, ".", "")

Data.Machines.SeekMacaddress(lMAC).Status = pIntStatus

    For Each uListItem In Me.lstMachines.ListItems

        If uListItem.Key = lMAC Then

            If CStr(uListItem.SmallIcon) <> CStr(pIntStatus) Then
            uListItem.SmallIcon = pIntStatus
            uListItem.Icon = pIntStatus
            Call CheckPeriodStatus(lsMACAddress)
            End If

        End If

    Next uListItem

Exit Sub
sUpdateMachineStatusErr:
Err.Raise Err.number, Err.Source, "s.UpdateMachineStatus:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Private Sub DoAction(pStrParm)
On Error GoTo psDoActionErr 'EHCG.UID.psDoAction

Dim lObjLI As ListItem

    If Me.chkAll.Value = 0 Then

        For Each lObjLI In Me.lstMachines.ListItems

            If lObjLI.Selected Then
            Send GetIP(lObjLI.Key), pStrParm
            End If

        Next lObjLI

    Else
    SendBroadcast pStrParm

    End If

Exit Sub
psDoActionErr:
Err.Raise Err.number, Err.Source, "ps.DoAction:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Private Sub DropUsers()
On Error GoTo psDropUsersErr 'EHCG.UID.psDropUsers

Dim lObjLI As ListItem

    If Me.chkAll.Value = 0 Then

        For Each lObjLI In Me.lstMachines.ListItems

            If lObjLI.Selected Then
            DropUser GetIP(lObjLI.Key)
            End If

        Next lObjLI

    Else

        For Each lObjLI In Me.lstMachines.ListItems
        DropUser GetIP(lObjLI.Key)
        Next lObjLI

    End If

Me.LoadMachineList

Exit Sub
psDropUsersErr:
Err.Raise Err.number, Err.Source, "ps.DropUsers:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Sub DropUser(uIP)
On Error GoTo sDropUserErr 'EHCG.UID.sDropUser

Dim uSQL As String, uRS As Recordset, uID As Long

uSQL = "SELECT M.ID FROM machine AS M WHERE M.IPAddress='" & uIP & "'"
Set uRS = Data.Database.Execute(uSQL)

    If uRS.EOF Then Exit Sub

uID = uRS(0)

uSQL = "UPDATE machine_status AS MS SET MS.lastchange = null, MS.userID = null, MS.user_timelimit = null WHERE MS.MachineID=" & uID
Data.Database.Execute uSQL

Send uIP, "KILLUSER"
Send uIP, "LOCK"
SendBroadcast "PING?"

Exit Sub
sDropUserErr:
Err.Raise Err.number, Err.Source, "s.DropUser:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Private Sub AddTime()
On Error GoTo psAddTimeErr 'EHCG.UID.psAddTime

Dim lObjLI As ListItem, uPeriod As String

uPeriod = InputBox("Quanto tempo deseja adicionar? (formato HH:MM)" & vbCrLf & vbCrLf & "Inclua um sinal de menos (-) caso deseje retirar tempo deste usuário, como em -01:00 para retirar uma hora.")

    If uPeriod = "" Then Exit Sub
'    If Not IsDate(uPeriod) Then Exit Sub

    If Me.chkAll.Value = 0 Then

        For Each lObjLI In Me.lstMachines.ListItems

            If lObjLI.Selected Then
            AddTimeToUser GetIP(lObjLI.Key), uPeriod
            End If

        Next lObjLI

    Else

        For Each lObjLI In Me.lstMachines.ListItems
        AddTimeToUser GetIP(lObjLI.Key), uPeriod
        Next lObjLI

    End If

Me.LoadMachineList

Exit Sub
psAddTimeErr:
Err.Raise Err.number, Err.Source, "ps.AddTime:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Sub AddTimeToUser(uIP As String, uPeriod As String)
On Error GoTo sAddTimeToUserErr 'EHCG.UID.sAddTimeToUser

Dim uSQL As String, uRS As Recordset, uID As Long, TimeOpNeg As Boolean

uSQL = "SELECT * FROM machine_status MS WHERE MachineID In (SELECT M.ID FROM machine AS M WHERE M.IPAddress='" & uIP & "')"
Set uRS = Data.Database.Execute(uSQL)

    If uRS.EOF Then Exit Sub
    If ValidStr(uRS("user_timelimit")) = "" Then Exit Sub

uID = uRS(0)

uPeriod = Trim(uPeriod)
    
    If Left$(uPeriod, 1) = "-" Then
    TimeOpNeg = True
    uPeriod = Right$(uPeriod, Len(uPeriod) - 1)
    uPeriod = Trim(uPeriod)
    End If
    
If Not IsDate(uPeriod) Then Exit Sub
        
uSQL = "UPDATE machine_status AS MS SET MS.user_timelimit = #" & IIf(TimeOpNeg, (DateAdd("N", Minute(CDate(uPeriod)) * -1, DateAdd("H", Hour(CDate(uPeriod)) * -1, uRS("user_timelimit")))), (uRS("user_timelimit") + CDate(uPeriod))) & "# WHERE MS.ID=" & uID

Data.Database.Execute uSQL

SendBroadcast "PING?"

Exit Sub
sAddTimeToUserErr:
Err.Raise Err.number, Err.Source, "s.AddTimeToUser:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Sub CheckPeriodStatus(uMAC)
On Error GoTo sCheckPeriodStatusErr 'EHCG.UID.sCheckPeriodStatus

Dim uObjLI As ListItem, uPeriod As Date, uStrVar As String

Set uObjLI = Me.lstMachines.ListItems(Replace(uMAC, ".", ""))

    If uObjLI.SubItems(3) = "" Then Exit Sub

uPeriod = Time - CDate(uObjLI.SubItems(3))

uStrVar = Right$("0" & Hour(uPeriod), 2) & ":" & Right$("0" & Minute(uPeriod), 2)

uObjLI.SubItems(5) = uStrVar

    If IsDate(uObjLI.SubItems(4)) Then
    
        If CDate(uObjLI.SubItems(4)) < Time() Then
        
            If uObjLI.ForeColor <> &HFF Then
            Send GetIP(uMAC), "SAY|Seu tempo acabou."
            End If
        
        uObjLI.ForeColor = &HFF
        uObjLI.Bold = True
    
        Else
        uObjLI.ForeColor = &H0
        uObjLI.Bold = False
    
        End If
    
    End If

Exit Sub
sCheckPeriodStatusErr:
Err.Raise Err.number, Err.Source, "s.CheckPeriodStatus:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Private Sub TurnOnComputers()
On Error GoTo psTurnOnComputersErr 'EHCG.UID.psTurnOnComputers

Dim lObjLI As ListItem

    If Me.chkAll.Value = 0 Then

        For Each lObjLI In Me.lstMachines.ListItems

            If lObjLI.Selected Then
            SendMagicPacket lObjLI.Key
            End If

        Next lObjLI

    Else

        For Each lObjLI In Me.lstMachines.ListItems
        SendMagicPacket lObjLI.Key
        Next lObjLI

    End If

Me.LoadMachineList

Exit Sub
psTurnOnComputersErr:
Err.Raise Err.number, Err.Source, "ps.TurnOnComputers:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
