#Region ;**** 参数创建于 ACNWrapper_GUI ****
#PRE_UseX64=n
#PRE_Res_requestedExecutionLevel=None
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#Region ;**** 由 AccAu3Wrapper_GUI 创建指令 ****
#AccAu3Wrapper_OutFile=Client.exe
#AccAu3Wrapper_UseUpx=Y
#AccAu3Wrapper_UseX64=n
#AccAu3Wrapper_Res_Comment=
#AccAu3Wrapper_Res_Description=
#AccAu3Wrapper_Res_Fileversion=1.0
#AccAu3Wrapper_Res_LegalCopyright=
#AccAu3Wrapper_Res_Language=2052
#AccAu3Wrapper_Res_requestedExecutionLevel=None
#EndRegion ;**** 由 AccAu3Wrapper_GUI 创建指令 ****
#include <array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <GuiTreeView.au3>
#include <TreeViewConstants.au3>
#include <GuiImageList.au3>
#include <GuiButton.au3>
#include <String.au3>
;~ #include <Constants.au3>;响应托盘事件 UDF
; 定义变量
Global $DbPath, $DbPass, $TableGroup, $TableServer, $TableUsers, $Conn
Global $TrItem[1], $iS = 0 ; itemsquence 分组序数
$Form1 = GUICreate("控制台", 960, 615)
; 创建 TreeView
$TreeView = GUICtrlCreateTreeView(10, 50, 235, 508, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$Group = GUICtrlCreateTreeViewItem("已分组服务器列表", $TreeView) ;创建TreeView项目
GUICtrlSetColor(-1, 0xff0000)
GUICtrlSetState(-1, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
; 读取 分组列表
ConnectDB()
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $Conn
$RS.Open("Select * From " & $TableGroup & " Order By GroupName")
While Not $RS.eof And Not $RS.bof
If @error Then ExitLoop
ReDim $TrItem[$iS+1] ; 数组大小 +1
$TrItem[$iS] = GUICtrlCreateTreeViewItem($RS.Fields(1).value, $Group)
;~ MsgBox(0, "", _GUICtrlTreeView_GetText($TreeView, $TrItem[$iS]))
$iS += 1
$RS.movenext
WEnd
$RS.close
$Conn.Close
_GUICtrlTreeView_Expand($TreeView, $Group)
_GUICtrlTreeView_SelectItemByIndex($TreeView, $Group, 0)
; 创建 ListView
$ListView = GUICtrlCreateListView("", 250, 50, 700, 310)
_GUICtrlListView_AddColumn($ListView, "名称", 140) ;创建列
_GUICtrlListView_AddColumn($ListView, "隶属分组", 120) ;创建列
_GUICtrlListView_AddColumn($ListView, "IP", 110) ;创建列
_GUICtrlListView_AddColumn($ListView, "端口", 60) ;创建列
_GUICtrlListView_AddColumn($ListView, "备注", 240) ;创建列
_GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES)) ;设置ListView样式
GUISetState(@SW_SHOW)
#cs
; $TrItem[$nMsg - 5] 为什么要减 5 ?
; 每个GUI创建的第一个控件ID都是 3
, 这个GUI里就是 $TreeView = GUICtrlCreateTreeView ,也就是说 $TreeView = 3
; 下一控件就是 4 , $Group = GUICtrlCreateTreeViewItem $Group = 4
; 接着的控件ID 5 .... 就是 $TrItem[$iS] = GUICtrlCreateTreeViewItem($RS.Fields(1).value, $Group) 这些
; 示例一共是10个, 也就是 5 to 14 ; $TrItem[0] = 5 , $TrItem[9] = 14
; 响应 $TrItem[0]的点击时, $nMsg = 5, 为了保证下句操作的正确性,(也就是取出数组对应值),所以必须要 $nMsg - 5
$RS.Open("Select * From " & $TableServer & " Where Groups='" & _GUICtrlTreeView_GetText($TreeView, $TrItem[$nMsg - 5]) & "'") ;
#ce
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $TrItem[0] To $TrItem[UBound($TrItem) - 1] ; 点击任意 treeviewitem 时 ,进行以下操作
_GUICtrlListView_DeleteAllItems($ListView)
ConnectDB()
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $Conn
$RS.Open("Select * From " & $TableServer & " Where Groups='" & _GUICtrlTreeView_GetText($TreeView, $TrItem[$nMsg - 5]) & "'") ;
While Not $RS.eof And Not $RS.bof
If @error = 1 Then ExitLoop
GUICtrlCreateListViewItem($RS.Fields(1).value & "|" & $RS.Fields(7).value & "|" & $RS.Fields(2).value & "|" & $RS.Fields(3).value & "|" & $RS.Fields(9).value, $ListView )
$RS.movenext
WEnd
$RS.close
$Conn.Close
EndSwitch
WEnd
;=============== 函数 - 定义 ===============
Func ConnectDB() ;连接数据库
$DbPath = @ScriptDir & "" & "Data.mdb"
;~ $mdbpass = "traveler@)!^"
$DbPass = "123"
$TableGroup = "TB_Group"
$TableServer = "TB_Server"
$TableUsers = "TB_Users"
$Conn = ObjCreate("ADODB.Connection")
$Conn.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $DbPath & "; Jet OLEDB:Database Password=" & $DbPass)
EndFunc ;==>ConnectDB