Code:
#include <GUIConstants.au3>
#include <GuiTreeView.au3>
;Opt("TrayMenuMode",1)
; Script Start - Add your code below here
$SettingsLocation = "S:\BlockIE\"
$SettingsFile = "Global.txt"
$ReadSettings = FileOpen(($SettingsLocation & $SettingsFile), 0)
$SettingsLineOne = FileReadLine($ReadSettings)
$SettingsLineTwo = FileReadLine($ReadSettings)
$NumberOfRooms = StringLeft($SettingsLineOne,2)
$LastUpdated = 9999
$LastUpdatedRoom = 9999
$TotalComputers = 0
$CurrenSelection = 9999
Dim $RoomTreeItems [$NumberOfRooms]
Dim $ComputersPerRoom [$NumberOfRooms]
Dim $SaveRoom [$NumberOfRooms]
$RoomNames = StringSplit($SettingsLineTwo,"|")
$LeftCount = 2
$RightCount = (($NumberOfRooms * 2) - 2)
For $a = 1 to $NumberOfRooms
$ComputersPerRoom[$a-1] = StringTrimLeft(StringTrimRight($SettingsLineOne, $RightCount),$LeftCount)
$LeftCount = $LeftCount + 2
$RightCount = $RightCount - 2
;MsgBox (0, $a, $ComputersPerRoom[$a-1])
Next
Dim $ComputerTreeItems[150]
; Create GUI
$MainGui = GUICreate("Control Internet Access", 400, 600)
$Tree = GUICtrlCreateTreeView(10, 10, 190, 550)
For $a = 1 To $NumberOfRooms
$RoomTreeItems[$a-1] = GUICtrlCreateTreeViewItem($RoomNames[$a], $Tree)
For $b = $TotalComputers to ($TotalComputers + $ComputersPerRoom[$a-1])-1
$ComputerTreeItems[$b] = GUICtrlCreateTreeViewItem($RoomNames[$a]& "-" &(($b-$TotalComputers)+1), $RoomTreeItems[$a-1])
Next
$TotalComputers = $TotalComputers + $ComputersPerRoom[$a-1]
Next
Dim $ComputerStatus [$TotalComputers]
For $a = 0 to $TotalComputers - 1
$ComputerStatus[$a] = "Allow"
Next
$Group = GUICtrlCreateGroup ("Action", 210, 60, 140, 90)
$BlockRadio = GUICtrlCreateRadio ("Block", 220, 75, 50, 20)
$AllowRadio = GUICtrlCreateRadio ("Allow", 220, 95, 60, 20)
$SetButton = GUICtrlCreateButton ("Set", 260, 115, 60)
GUICtrlSetState ($SetButton, $GUI_Hide)
$SetRoomButton = GUICtrlCreateButton ("Set Room", 260, 115, 60)
GUICtrlSetState ($SetRoomButton, $GUI_Hide)
GUICtrlCreateGroup ("",-99,-99,1,1)
$SaveButton = GUICtrlCreateButton("Save Changes", 255, 550, 90)
GUICtrlSetState ($SaveButton, $GUI_DISABLE)
$SaveLabel = GUICtrlCreateLabel ("Changes will not be applied until they are saved.", 210, 150,180, 40)
GUICtrlSetState ($SaveLabel, $GUI_Hide)
$SaveGroup = GUICtrlCreateGroup("Room to Save Changes to.", 210, 210, 180, ($NumberOfRooms+2) * 20)
For $a = 0 To $NumberOfRooms-1
$SaveRoom[$a] = GUICtrlCreateRadio($RoomNames[$a+1], 220, (230 + ($a*20)))
Next
GUICtrlCreateGroup ("",-99,-99,1,1)
GUISetState(@SW_SHOW, $MainGui)
; Event Handler
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
;Case $msg = $GUI_EVENT_MINIMIZE
; GUISetState(@SW_HIDE, $MainGui)
Case $msg = $SetButton
;If $LastUpdated < 9999 Then
;MsgBox(0, "Clicked", $LastUpdated)
Select
Case BitAnd(GUICtrlRead($AllowRadio),$GUI_CHECKED)
$ComputerStatus[$LastUpdated] = "Allow"
Case BitAnd(GUICtrlRead($BlockRadio),$GUI_CHECKED)
$ComputerStatus[$LastUpdated] = "Block"
;MsgBox(0, "Clicked", "Blocked")
EndSelect
GUICtrlSetState ($SaveButton, $GUI_ENABLE)
GUICtrlSetState ($SaveLabel, $GUI_Show)
;EndIf
Case $msg = $SetRoomButton
$ComputerCount = 0
$LastUpdated = 9999
For $a = 0 to $NumberOfRooms
If $a = $LastUpdatedRoom Then
For $b = $ComputerCount To ($ComputersPerRoom[$a]+$ComputerCount-1)
Select
Case BitAnd(GUICtrlRead($AllowRadio),$GUI_CHECKED)
$ComputerStatus[$b] = "Allow"
Case BitAnd(GUICtrlRead($BlockRadio),$GUI_CHECKED)
$ComputerStatus[$b] = "Block"
;MsgBox(0, "Clicked", "Blocked")
EndSelect
Next
ExitLoop
Else
$ComputerCount = $ComputerCount + $ComputersPerRoom[$a]
EndIf
Next
GUICtrlSetState ($SaveButton, $GUI_ENABLE)
GUICtrlSetState ($SaveLabel, $GUI_Show)
Case $msg = $SaveButton
GUICtrlSetState ($SaveButton, $GUI_DISABLE)
GUICtrlSetState ($SaveLabel, $GUI_Hide)
_SaveChanges()
EndSelect
For $c = 0 to $NumberOfRooms-1
If $msg = $RoomTreeItems[$c] Then
;ExitLoop
GUICtrlSetData($Group, (_GUICtrlTreeViewGetText($Tree, $RoomTreeItems[$c])& " Set Room"))
GUICtrlSetState ($SetButton, $GUI_Hide)
GUICtrlSetState ($SetRoomButton, $GUI_Show)
$LastUpdatedRoom = $c
GUICtrlSetState ($AllowRadio, $GUI_UNCHECKED)
GUICtrlSetState ($BlockRadio, $GUI_UNCHECKED)
;MsgBox(0, "Clicked", "You Clicked a room")
EndIf
Next
For $d = 0 To $TotalComputers - 1
If $msg = $ComputerTreeItems[$d] Then
;If _GUICtrlTreeViewGetState($Tree, $ComputerTreeItems[$d]) = 2 Then
If $LastUpdated <> $d Then
;MsgBox(0, "Clicked", GUICtrlGetHandle ( $ComputerTreeItems[$d] ))
GUICtrlSetData($Group, _GUICtrlTreeViewGetText($Tree, $ComputerTreeItems[$d]))
If $ComputerStatus[$d] = "Allow" Then
GUICtrlSetState ($AllowRadio, $GUI_CHECKED)
Else
GUICtrlSetState ($BlockRadio, $GUI_CHECKED)
EndIf
$LastUpdated = $d
GUICtrlSetState ($SetRoomButton, $GUI_Hide)
GUICtrlSetState ($SetButton, $GUI_Show)
EndIf
ExitLoop
EndIf
Next
WEnd
Func _SaveChanges()
$StartPoint = 0
For $a = 0 to $NumberOfRooms-1
If BitAnd(GUICtrlRead($SaveRoom[$a]),$GUI_CHECKED) Then
$File = FileOpen(($SettingsLocation & $RoomNames[$a+1]&".txt"), 2)
For $b = 0 to ($ComputersPerRoom[$a]-1)
If $b < 9 Then
FileWriteLine ($File, ("0"&$b+1&":"&$ComputerStatus[$b+$StartPoint]))
Else
FileWriteLine ($File, ($b+1&":"&$ComputerStatus[$b+$StartPoint]))
EndIf
Next
FileClose($File)
EndIf
$StartPoint = $StartPoint + $ComputersPerRoom[$a]
Next
EndFunc