本帖最后由 meteor0330 于 2014-8-12 08:59 编辑
我写了一个报纸查询采集的程序,如下图所示。
我需要实现的效果是点击日期控件选择日期后,检索数据库得到当天对应的版次(如A01,A02,B01等)并放到Combo1中,我使用WM_COMMAND好像不大行,望各位大师教教我!
感谢!!
就是我希望通过点击日期控件选择日期后,自动执行_MyBanCi()函数。
代码如下:
#Region ;**** 由 AccAu3Wrapper_GUI 创建指令 ****
#AccAu3Wrapper_OutFile=前卫网数据采集.exe
#AccAu3Wrapper_UseX64=n
#AccAu3Wrapper_Res_Language=2052
#AccAu3Wrapper_Res_requestedExecutionLevel=None
#AccAu3Wrapper_Antidecompile=y
#EndRegion ;**** 由 AccAu3Wrapper_GUI 创建指令 ****
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <DateTimeConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
_MyProExists();判断程序是否重复运行
Opt("GUIOnEventMode", 1);使用OnEvent模式
Opt("TrayAutoPause", 0);单击托盘不暂停
Opt("TrayMenuMode", 1);禁用托盘默认菜单
Opt("TrayIconDebug", 1);托盘显示调试信息
Global $SQL_IP, $SQL_UID, $SQL_PW, $BZ_Name, $BZ_Table, $BZ_Id, $BZ_RiQi, $BZ_BanCi, $BZ_ZhuBiao, $BZ_FuBiao, $BZ_TuPian, $BZ_ZhengWen, $BZ_ZuoZhe, $WZ_Name, $WZ_Table, $WZ_NodeID1, $WZ_NodeID2, $WZ_NodeID3, $WZ_NodeID4, $WZ_PubID, $WZ_ZhuBiao, $WZ_FuBiao, $WZ_TuPian, $WZ_ZhengWen, $WZ_ZuoZhe
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("前卫网数据采集程序", 750, 464, -1, -1)
$Label1 = GUICtrlCreateLabel("前卫网数据采集程序", 238, 12, 274, 33)
GUICtrlSetFont(-1, 22, 800, 0, "宋体")
$Date1 = GUICtrlCreateDate("", 16, 64, 154, 21)
GUICtrlSendMsg(-1, 0x1032, 0, "yyyy年MM月dd日") ;格式化日期控件中的日期,yyyy年MM月dd日 hh时mm分ss秒
$Label2 = GUICtrlCreateLabel("第", 184, 64, 20, 20)
GUICtrlSetFont(-1, 12, 400, 0, "新宋体")
$Combo1 = GUICtrlCreateCombo("", 216, 64, 65, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
$Label3 = GUICtrlCreateLabel("版", 295, 64, 20, 20)
GUICtrlSetFont(-1, 12, 400, 0, "新宋体")
$Button1 = GUICtrlCreateButton("查询", 326, 60, 83, 25)
GUICtrlSetFont(-1, 10, 400, 0, "新宋体")
GUICtrlSetOnEvent(-1, "Button1Click")
$Label4 = GUICtrlCreateLabel("采集到:", 464, 64, 60, 20)
GUICtrlSetFont(-1, 12, 400, 0, "新宋体")
$Combo2 = GUICtrlCreateCombo("新一版", 536, 64, 89, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
$Button2 = GUICtrlCreateButton("开始采集", 640, 60, 91, 25)
GUICtrlSetFont(-1, 10, 400, 0, "新宋体")
GUICtrlSetState(-1, $GUI_DISABLE) ;设置采集按钮为禁用模式
GUICtrlSetOnEvent(-1, "Button2Click")
$ListView1 = GUICtrlCreateListView("ID|日期|版次|标题|副标|图片|作者|内容", 16, 96, 720, 335)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 70)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 40)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 115)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 4, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 5, 80)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 6, 80)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 7, 150)
_GUICtrlListView_JustifyColumn(GUICtrlGetHandle($ListView1), 1, 2)
_GUICtrlListView_JustifyColumn(GUICtrlGetHandle($ListView1), 2, 2)
_GUICtrlListView_JustifyColumn(GUICtrlGetHandle($ListView1), 3, 2)
_GUICtrlListView_JustifyColumn(GUICtrlGetHandle($ListView1), 4, 2)
_GUICtrlListView_JustifyColumn(GUICtrlGetHandle($ListView1), 5, 2)
_GUICtrlListView_JustifyColumn(GUICtrlGetHandle($ListView1), 6, 2)
_GUICtrlListView_JustifyColumn(GUICtrlGetHandle($ListView1), 7, 2)
_GUICtrlListView_JustifyColumn(GUICtrlGetHandle($ListView1), 8, 2)
$StatusBar1 = _GUICtrlStatusBar_Create($Form1)
Dim $StatusBar1_PartsWidth[5] = [10, 80, 630, 740, -1]
_GUICtrlStatusBar_SetParts($StatusBar1, $StatusBar1_PartsWidth)
_GUICtrlStatusBar_SetText($StatusBar1, "", 0)
_GUICtrlStatusBar_SetText($StatusBar1, "当前状态:", 1)
_GUICtrlStatusBar_SetText($StatusBar1, "欢迎使用前卫网数据采集程序!!", 2)
_GUICtrlStatusBar_SetText($StatusBar1, "程序设计:流星", 3)
_GUICtrlStatusBar_SetText($StatusBar1, "", 4)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
_MyLoad();读取配置文件
While 1
Sleep(100)
WEnd
Func _MyProExists() ;此函数用来判断程序是否重复运行
Dim $my_Version = "qianweiwangshujucaiji"
If WinExists($my_Version) Then Exit
AutoItWinSetTitle($my_Version)
$my_Version = ""
EndFunc ;==>_MyProExists
Func Form1Close() ;关闭父窗口
Exit
EndFunc ;==>Form1Close
Func Button1Click();查询按钮
EndFunc ;==>Button1Click
Func Button2Click();采集按钮
EndFunc ;==>Button2Click
Func _MyFormatDate($sDate) ;格式化日期控件中的日期便于和数据库比较
Local $sFormatDate, $aDays
$aDays = StringSplit($sDate, "年月日")
$sFormatDate = $aDays[1] & $aDays[2] & $aDays[3]
Return $sFormatDate
$sFormatDate = ""
$aDays = ""
EndFunc ;==>_MyFormatDate
Func _MyLoad() ;读取配置文件,获得数据库配置信息
$SQL_IP = IniRead(@ScriptDir & '\SJCJsetting.ini', "PubSet", "SQL_IP", "0")
$SQL_UID = IniRead(@ScriptDir & '\SJCJsetting.ini', "PubSet", "SQL_UID", "0")
$SQL_PW = IniRead(@ScriptDir & '\SJCJsetting.ini', "PubSet", "SQL_PW", "0")
$BZ_Name = IniRead(@ScriptDir & '\SJCJsetting.ini', "BZSet", "BZ_Name", "0")
$BZ_Table = IniRead(@ScriptDir & '\SJCJsetting.ini', "BZSet", "BZ_Table", "0")
$BZ_Id = IniRead(@ScriptDir & '\SJCJsetting.ini', "BZSet", "BZ_Id", "0")
$BZ_RiQi = IniRead(@ScriptDir & '\SJCJsetting.ini', "BZSet", "BZ_RiQi", "0")
$BZ_BanCi = IniRead(@ScriptDir & '\SJCJsetting.ini', "BZSet", "BZ_BanCi", "0")
$BZ_ZhuBiao = IniRead(@ScriptDir & '\SJCJsetting.ini', "BZSet", "BZ_ZhuBiao", "0")
$BZ_FuBiao = IniRead(@ScriptDir & '\SJCJsetting.ini', "BZSet", "BZ_FuBiao", "0")
$BZ_TuPian = IniRead(@ScriptDir & '\SJCJsetting.ini', "BZSet", "BZ_TuPian", "0")
$BZ_ZhengWen = IniRead(@ScriptDir & '\SJCJsetting.ini', "BZSet", "BZ_ZhengWen", "0")
$BZ_ZuoZhe = IniRead(@ScriptDir & '\SJCJsetting.ini', "BZSet", "BZ_ZuoZhe", "0")
$WZ_Name = IniRead(@ScriptDir & '\SJCJsetting.ini', "WZSet", "WZ_Name", "0")
$WZ_Table = IniRead(@ScriptDir & '\SJCJsetting.ini', "WZSet", "WZ_Table", "0")
$WZ_NodeID1 = IniRead(@ScriptDir & '\SJCJsetting.ini', "WZSet", "WZ_NodeID1", "0")
$WZ_NodeID2 = IniRead(@ScriptDir & '\SJCJsetting.ini', "WZSet", "WZ_NodeID2", "0")
$WZ_NodeID3 = IniRead(@ScriptDir & '\SJCJsetting.ini', "WZSet", "WZ_NodeID3", "0")
$WZ_NodeID4 = IniRead(@ScriptDir & '\SJCJsetting.ini', "WZSet", "WZ_NodeID4", "0")
$WZ_PubID = IniRead(@ScriptDir & '\SJCJsetting.ini', "WZSet", "WZ_PubID", "0")
$WZ_ZhuBiao = IniRead(@ScriptDir & '\SJCJsetting.ini', "WZSet", "WZ_ZhuBiao", "0")
$WZ_FuBiao = IniRead(@ScriptDir & '\SJCJsetting.ini', "WZSet", "WZ_FuBiao", "0")
$WZ_TuPian = IniRead(@ScriptDir & '\SJCJsetting.ini', "WZSet", "WZ_TuPian", "0")
$WZ_ZhengWen = IniRead(@ScriptDir & '\SJCJsetting.ini', "WZSet", "WZ_ZhengWen", "0")
$WZ_ZuoZhe = IniRead(@ScriptDir & '\SJCJsetting.ini', "WZSet", "WZ_ZuoZhe", "0")
;出错设置
If Not FileExists(@ScriptDir & '\SJCJsetting.ini') Then
MsgBox(16, "错误", "程序配置文件SJCJsetting.ini不存在或不可读!" & @CRLF & "请检查并修改好配置文件再重新运行本程序!")
Exit
Else
If $SQL_IP == "0" Or $SQL_UID == "0" Or $SQL_PW == "0" Or $BZ_Name == "0" Or $BZ_Table == "0" Or $BZ_Id == "0" Or $BZ_RiQi == "0" Or $BZ_BanCi == "0" Or $BZ_ZhuBiao == "0" Or $BZ_FuBiao == "0" Or $BZ_TuPian == "0" Or $BZ_ZhengWen == "0" Or $BZ_ZuoZhe == "0" Or $WZ_Name == "0" Or $WZ_Table == "0" Or $WZ_NodeID1 == "0" Or $WZ_NodeID2 == "0" Or $WZ_NodeID3 == "0" Or $WZ_NodeID4 == "0" Or $WZ_PubID == "0" Or $WZ_ZhuBiao == "0" Or $WZ_FuBiao == "0" Or $WZ_TuPian == "0" Or $WZ_ZhengWen == "0" Or $WZ_ZuoZhe == "0" Then
MsgBox(16, "错误", "配置文件SJCJsetting.ini设置有误,请修改好配置文件再重新运行本程序!")
Exit
EndIf
EndIf
EndFunc ;==>_MyLoad
Func _MyBanCi() ;读取数据库中对应日期的版次信息
Local $conn, $RS, $Cb
$conn = ObjCreate("ADODB.Connection")
$conn.Open("driver={SQL Server};server=" & $SQL_IP & ";uid=" & $SQL_UID & ";pwd=" & $SQL_PW & ";database=" & $BZ_Name)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $conn
$RS.Open("Select [" & $BZ_BanCi & "] from " & $BZ_Table & " where " & $BZ_Id & " in (select MAX(" & $BZ_Id & ") from " & $BZ_Table & " where " & $BZ_RiQi & " = '" & _MyFormatDate(GUICtrlRead($Date1)) & "' group by " & $BZ_BanCi & ")") ;查夜数据库,注意group by用法
If @error = 0 Then ;判断数据库是否正常连接
If ($RS.Fields(0).value) <> "" Then
GUICtrlSetData($Combo1, "") ;清空Combo1控件
While Not $RS.eof And Not $RS.bof
If @error = 1 Then ExitLoop
$Cb = $Cb & "|" & $RS.Fields(0).value
$RS.movenext
WEnd
GUICtrlSetData($Combo1, StringTrimLeft($Cb, 1))
Else
_GUICtrlStatusBar_SetText($StatusBar1, GUICtrlRead($Date1) & "没有报纸。", 2)
EndIf
Else
_GUICtrlStatusBar_SetText($StatusBar1, "ERROR!!!!数据库打开错误。", 2)
EndIf
$conn.Close
$RS.close
$conn = ""
$RS = ""
$Cb = ""
EndFunc ;==>_MyBanCi
|