#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_Icon=C:\Windows\system32\SHELL32.dll
#AutoIt3Wrapper_Outfile=C:\Users\Administrator\Desktop\qiandao3306.exe
#AutoIt3Wrapper_UseUpx=n
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>
#include "mysql.au3"
;#include <Date.au3>
;#include <Timers.au3>
#include <FTPEx.au3>
;FTP服务器参数
Global $FTP244_IP = "192.168.0.2"
Global $FTP244_Port = 21
Global $FTP244_User = "abc1"
Global $FTP244_PW = "abc1"
Local $FTP244_Open = 0
Local $FTP244_Connect = 0
Global $FTP244_RemoteFile = "" & @OSArch & "\libmysql.dll";判断本机OS位数,分别定向于X86或X64文件夹
Global $FTP244_LocalFile = "C:\Windows\System32\libmysql.dll"
;管理服务器参数
Global $serverIP = "192.168.0.3"
Global $conname = "2021"
Global $userID = "abc2"
Global $userPD = "abc2"
Global $DBname = "abc2"
Local $Ver = "V0.0.0.0"
Local $pc_ip = ""
Local $pc_name = ""
Local $Input1 = ""
Local $Input2 = ""
Local $login = 0
Global $stu_num = ""
Global $stu_name
Global $stu_college = ""
Global $stu_class = ""
Global $order_code = ""
;================环境检测,核实是否存在必要的libmysql.dll,没有就FTP服务器去下载一个,直至成功==================OK!
If Not FileExists($FTP244_LocalFile) Then
getdll()
EndIf
#Region ### START Koda GUI section ### Form=d:\au3\教学运行管理系统\签到登陆.kxf
$Form1_1 = GUICreate("计算机实验室签到系统", 610, 238, 192, 124)
$Label1 = GUICtrlCreateLabel("计算机实验室签到系统", 42, 32, 524, 36)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("请输入学号", 64, 120, 64, 17)
$Input1 = GUICtrlCreateInput("", 144, 118, 121, 21)
;$Label3 = GUICtrlCreateLabel("请输入预约码", 52, 160, 76, 17)
;$Input2 = GUICtrlCreateInput("", 144, 158, 121, 21)
$Button1 = GUICtrlCreateButton("确定", 416, 116, 75, 25)
$Button2 = GUICtrlCreateButton("重置", 416, 156, 75, 25)
$Label4 = GUICtrlCreateLabel($Ver, 496, 208, 102, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
MsgBox(0, "来自服务器消息", "本次签到操作并未被服务器记录!", 6)
;TheEnd()
Exit
Case $Button1
GUISetState(@SW_HIDE)
;收集本机信息
myPC()
;将学号传去服务器,在stu_info表中校验身份
$query = "SELECT * FROM stu_info where stu_num ='" & $stu_num & "'";需要查询的语句;Mysql命令行
readdb($query)
If $login = 1 Then
;MsgBox(0,"来自服务器消息","欢迎 " & $stu_name & $stu_college & "(" & $stu_num & ")" & "同学,签到成功!机号:"& $pc_name,6)
;================去服务器新【stu_login】表建一条记录,上报:学号,预约码,机器名,机器IP(同时数据库自动记录登录时间)===================OK!
$query = "INSERT INTO stu_login(stu_num,pc_name,pc_ip) VALUES('" & $stu_num & "','" & $pc_name & "','" & $pc_ip & "' )"
;MsgBox(0,"待写入MySQL的语句测试",$query)
writedb($query)
MsgBox(0, "来自服务器消息", "欢迎 " & $stu_name & "(" & $stu_num & ")" & "同学,签到成功!" & @CRLF & @CRLF & "当前机号:" & $pc_name, 6)
Exit
EndIf
Case $Button2
GUICtrlSetData($Input1, "")
GUICtrlSetData($Input2, "")
EndSwitch
WEnd
Func myPC()
$stu_num = GUICtrlRead($Input1)
$order_code = GUICtrlRead($Input2)
$pc_ip = @IPAddress1;获取本机IP
$pc_name = @ComputerName;获取本机机器名
EndFunc ;==>myPC
Func getdll();检验本地system32有无“libmysql.dll”文件,若无,则根据X86或X64,从FTP服务器分别下载相应版本的libmysql.dll文件
Do
$FTP244_Open = _FTP_Open("MY_FTP");创建一个FTP会话
If $FTP244_Open = 0 Then;判断创建会话是否成功
MsgBox(0, "错误", "本机创建会话失败!")
ContinueLoop
EndIf;结束判断
$FTP244_Connect = _FTP_Connect($FTP244_Open, $FTP244_IP, $FTP244_User, $FTP244_PW, $FTP244_Port)
If $FTP244_Connect = 0 Then;连接失败
Beep(80, 100)
MsgBox(64, "连接服务器失败", "发生此错误的可能性:" & @CRLF & @CRLF & " 1、服务器IP是否正确?" & @CRLF & " 2、用户名/密码是否不匹配?" & @CRLF & " 3、线路故障?" & @CRLF & @CRLF & "请核对后重试...")
EndIf;判断结束
$File244_found = _FTP_FileGet($FTP244_Connect, $FTP244_RemoteFile, $FTP244_LocalFile)
_FTP_Close($FTP244_Open)
If FileExists($FTP244_LocalFile) Then;检测文件是否已下载成功
;MsgBox(4096, "环境检测", $FTP244_LocalFile &"下载已成功")
Else
If MsgBox(4, "环境检测", $FTP244_LocalFile & "没有初始化成功,是否继续尝试?") = 7 Then Exit
EndIf
Sleep(3000);延迟3秒再次尝试打开文件
Until $File244_found = 1;直到文件被读取到,否则在此循环
EndFunc ;==>getdll
Func writedb($query);写数据库
;连接远程电脑Mysql数据库
_MySQL_InitLibrary()
$MysqlConn = _MySQL_Init()
$connected = _MySQL_Real_Connect($MysqlConn, $serverIP, $userID, $userPD, $DBname,3306);(,服务器名,ID,密码,数据库名)
If $connected = 0 Then Exit MsgBox(16, 'Connection Error', _MySQL_Error($MysqlConn));<<<---------------------------学生机卡在这里了,弹出报错,且窗体内无错误代码
;执行Mysql语句————向指定记录写入数据
;~ _mysql_set_character_set($MysqlConn,"gbk");经测试,utf-8不行,gbk亦对中文支持不佳——建议不写入中文字符!
_MySQL_Query($MysqlConn, "set names gb2312")
_MySQL_Real_Query($MysqlConn, $query);具体执行上述命令行
$res = _MySQL_Store_Result($MysqlConn)
;关闭数据库
_MySQL_Data_Seek($res, 0)
_MySQL_Free_Result($res)
_MySQL_Close($MysqlConn)
_MySQL_EndLibrary()
EndFunc ;==>writedb
Func readdb($query);完成---------
;连接远程电脑Mysql数据库
_MySQL_InitLibrary()
$MysqlConn = _MySQL_Init()
$connected = _MySQL_Real_Connect($MysqlConn, $serverIP, $userID, $userPD, $DBname,3306);(,服务器名,ID,密码,数据库名)
If $connected = 0 Then Exit MsgBox(16, '数据库连接失败!Connection Error', _MySQL_Error($MysqlConn))
;执行Mysql语句————读取表中数据
_mysql_set_character_set($MysqlConn, "GBK");_mysql_real_query($MysqlConn,"set names `gbk`") ;设置mysql的输出编辑为 'gbk'
_MySQL_Real_Query($MysqlConn, $query);具体执行上述命令行
$res = _MySQL_Store_Result($MysqlConn)
;获取表的列、行数
$fields = _MySQL_Num_Fields($res)
$rows = _MySQL_Num_Rows($res)
If $rows = 0 Then
MsgBox(0, "来自服务器消息", "搜遍了服务器竟然未找到你刚才输入的学号...???", 6)
GUISetState(@SW_SHOW)
Else
$login = 1
;读取数据,写入数组,并将列表显示出来
Dim $array[$rows][$fields]
For $k = 1 To $rows
$mysqlrow = _MySQL_Fetch_Row($res, $fields)
$lenthsStruct = _MySQL_Fetch_Lengths($res)
For $i = 1 To $fields
$length = DllStructGetData($lenthsStruct, 1, $i)
$fieldPtr = DllStructGetData($mysqlrow, 1, $i)
$data = DllStructGetData(DllStructCreate("char[" & $length & "]", $fieldPtr), 1)
$array[$k - 1][$i - 1] = $data
Next
Next
;显示搜索结果
;_ArrayDisplay($array)
$stu_name = $array[0][2]
$stu_college = $array[0][3]
$stu_class = $array[0][4]
;MsgBox(0,"Test-服务器读取到的学生姓名",$stu_name,2)
EndIf
;关闭数据库
_MySQL_Data_Seek($res, 0)
_MySQL_Free_Result($res)
_MySQL_Close($MysqlConn)
_MySQL_EndLibrary()
EndFunc ;==>readdb
Func TheEnd()
Exit
EndFunc ;==>TheEnd