找回密码
 加入
搜索
查看: 5090|回复: 0

[AU3基础] 请指教---数据库查询后的数据如何填充GUI input

[复制链接]
发表于 2014-6-16 21:50:10 | 显示全部楼层 |阅读模式
请指教如下代码何如实现数据库查询后的数据填充进INPUT里面,感激不尽
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("会员积分查询 v1.0 by jeric", 623, 442, 192, 124)
$Label1 = GUICtrlCreateLabel("***超市---会员积分查询",  100, 10, 500, 50)
GUICtrlSetFont(-1, 24, 800, 0, "微软雅黑")
$Label2 = GUICtrlCreateLabel("请输入会员卡号:", 33, 100, 250, 33)
GUICtrlSetFont(-1, 20, 800, 0, "黑体")
$Label2 = GUICtrlCreateLabel("会员姓名:", 60, 180, 250, 33)
GUICtrlSetFont(-1, 20, 800, 0, "黑体")
$Label2 = GUICtrlCreateLabel("会员卡号:", 60, 230, 250, 33)
GUICtrlSetFont(-1, 20, 800, 0, "黑体")
$Label2 = GUICtrlCreateLabel("可用积分:", 60, 280, 250, 33)
GUICtrlSetFont(-1, 20, 800, 0, "黑体")
$Label2 = GUICtrlCreateLabel("卡状态:", 60, 330, 250, 33)
GUICtrlSetFont(-1, 20, 800, 0, "黑体")
$Input1 = GUICtrlCreateInput("请扫描", 264, 96, 321, 37)
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
$Input2 = GUICtrlCreateInput("", 192, 170, 345, 45)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_DISABLE)
$Input3 = GUICtrlCreateInput("", 192, 220, 345, 45)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_DISABLE)
$Input4 = GUICtrlCreateInput("", 192, 270, 345, 45)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_DISABLE)
$Input5 = GUICtrlCreateInput("", 192, 320, 345, 45)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_DISABLE)
$Button1 = GUICtrlCreateButton("查询", 268, 376, 95, 35)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xC0DCC0)
GUICtrlSetCursor (-1, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Dim $Input1=1,$Input2=1,$Input3=1,$Input4=1,$Input5=1
Dim $AccelKeys[1][2] = [["{Enter}", $Button1]]
GUISetAccelerators($AccelKeys)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        MsgBox(0, "", "Tool was closed")
                        Exit
                        
                Case ;$Button1;读取
                        If ControlGetFocus($Form1) = 'Edit1' Then find()
                        
                                
                EndSwitch
WEnd
 

Func find()
                $Strn = GUICtrlRead($Input1)
                $conn = ObjCreate( "ADODB.Connection" ) 
                $DSN = "DRIVER={SQL Server};SERVER="ip地址";DATABASE="数据库名称";UID=sa;PWD="密码";"
                ;数据库连接
                $conn.Open($DSN) 
                $rs = ObjCreate( "ADODB.RecordSet" ) 
                        $rs.Open( "select memname,cardid,point2,status from v_mem_card where cardid = '"& $Strn &"'", $conn ) 
                                While Not $RS.eof And Not $RS.bof
                        If @error = 1 Then ExitLoop
                                                                ;MsgBox(0, "", $RS.Fields($i).value);显示表第一个数据
                        For $i=0 To $rs.Fields.count-1
                                Switch $rs.Fields($i).name
                                                                                Case "memname"
                                                GUICtrlSetData ($Input2,$RS.Fields($i).value)
                                        Case "cardid"
                                                GUICtrlSetData ($Input3,$RS.Fields($i).value)
                                        Case "point2"
                                                GUICtrlSetData ($Input4,$RS.Fields($i).value)
                                                                                Case "status"
                                                                                        If $rs.Fields($i).value == "4" Then;数字翻译成汉字的例子
                                                      GUICtrlSetData ($Input5,"作废")
                                                                                                Else
                                                      GUICtrlSetData ($Input5,$RS.Fields($i).value)       
                                                                                        EndIf                                      
                                EndSwitch
                        Next
                        $RS.movenext
                                WEnd
                        $RS.close
                $conn.close
                GUICtrlSetData ($Input1,"")
EndFunc   ;==>find
        
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-2 03:49 , Processed in 0.077349 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表