找回密码
 加入
搜索
查看: 5531|回复: 18

[AU3基础] 关于AU3查找access数据库制定数据并导出该行的问题,发现无法导出数据【已解决】

[复制链接]
发表于 2020-5-10 10:12:50 | 显示全部楼层 |阅读模式
本帖最后由 锋城未逾年 于 2020-5-15 14:36 编辑

最近在学习用au3操作数据库,我想在问本输入框输入5,按下button按钮后,实现查找数据库中sjkd这一列为5的這一行把数据输出到程序的表格中,实现上图的结果。但是发现没有结果输出。郁闷一天了,希望大佬们指导一下,感激不尽!!
源代码:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
Global $mdb_data_path = "D:\M.mdb"
Global $Main
#region ### START Koda GUI section ### Form=
Global $Form2 = GUICreate("Form2", 549, 446, 237, 149)
Global $Input1 = GUICtrlCreateInput("", 64, 40, 265, 21)
Global $Button1 = GUICtrlCreateButton("Button1", 352, 32, 145, 41)
Global $ListView1 = GUICtrlCreateListView("好|里|问", 32, 104, 489, 305)
Global $ab = GUICtrlRead($Input1)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 150)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 150)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 150)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

_Ma()
Exit

Func _Ma()
        While 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                        Case $GUI_EVENT_CLOSE
                                Exit
                        Case $Input1
                                If $Button1 Then
                                        Global $am = GUICtrlRead($Input1)
                                        $Main
                                        _Main()
                                Else
                                        Exit
                                EndIf
                EndSwitch
        WEnd
EndFunc   ;==>_Main
Func _Main()
        $addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=")
        $RS = ObjCreate("ADODB.Recordset")
        $RS.ActiveConnection = $addfld
        $RS.Open("Select * From table WHERE sjkd ='" & $am & "'")
        
        While (Not $RS.eof And Not $RS.bof)
                If @error = 1 Then ExitLoop
                GUICtrlSetData($ListView1, $RS.Fields(0).value)
                $RS.movenext
        WEnd
        $RS.close
        $addfld.Close
        

EndFunc   ;==>_Main


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2020-5-10 16:34:51 | 显示全部楼层
己建<M.mdb>数据库有问题。
重建一个试试
 楼主| 发表于 2020-5-10 16:47:32 | 显示全部楼层
代码没有问题?谢谢大佬
 楼主| 发表于 2020-5-10 16:56:15 | 显示全部楼层
chzj589 发表于 2020-5-10 16:34
己建数据库有问题。
重建一个试试

我重建了数据库还是没有数据显示
发表于 2020-5-10 19:07:56 | 显示全部楼层
锋城未逾年 发表于 2020-5-10 16:56
我重建了数据库还是没有数据显示

有问题,但查不出数据库的问题。
你下载试试看




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2020-5-10 19:33:46 | 显示全部楼层
chzj589 发表于 2020-5-10 19:07
有问题,但查不出数据库的问题。
你下载试试看

谢谢大佬,太感激了解决了我的问题
 楼主| 发表于 2020-5-11 09:22:56 | 显示全部楼层
chzj589 发表于 2020-5-10 19:07
有问题,但查不出数据库的问题。
你下载试试看

老师您好,我昨天按照你的给的代码有写了一个程序是多个选项卡的也是提取指定数据的行输入到listview中但是发现listview一直在闪动而且没有数据输出,麻烦老师指导一下,谢谢您。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2020-5-11 09:23:34 | 显示全部楼层
chzj589 发表于 2020-5-10 19:07
有问题,但查不出数据库的问题。
你下载试试看

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <Excel.au3>
#include <Date.au3>
;~ FileInstall("Data.mdb", @WindowsDir & "\Data.mdb", 1)
Global $mdb_data_path = @ScriptDir & "\Data.mdb"
Global $mdb_data_pwd = ""
Global $Cahuanzx = "table1"
Global $Cahuanzy = "table2"
Global $Cahuanzz = "table3"
Global $Cahuanzu = "table4"
Global $Cahuanzv = "table5"
Dim $main
Dim $jccx
Dim $ldcx
Dim $clcx
Dim $xhps
Dim $jclength
Dim $oExcel
Dim $time
Dim $time1
Dim $time2
Dim $timearray1
Dim $timearray2
Dim $nMs
#region ### START Koda GUI section ### Form=D:\我的文件\Documents\软著\交通运输工程大数据管理\Form2.kxf
Global $Form2 = GUICreate("交通运输工程大数据管理", 775, 677, 170, 138)
Global $MenuItem4 = GUICtrlCreateMenu("数据输出(&X)")
Global $MenuItem6 = GUICtrlCreateMenuItem("输出到Excel", $MenuItem4)
Global $MenuItem5 = GUICtrlCreateMenuItem("输出到Excel并打印", $MenuItem4)
Global $MenuItem1 = GUICtrlCreateMenu("数据处理(&Y)")
Global $MenuItem2 = GUICtrlCreateMenuItem("备份数据库", $MenuItem1)
Global $MenuItem7 = GUICtrlCreateMenu("退出(&Z)")
;~ GUICtrlCreateTab(40, 48, 660, 560)
Global $main = GUICtrlCreateTab(40, 48, 660, 560)
Global $TabSheet1 = GUICtrlCreateTabItem("交叉口查询")
Global $Group2 = GUICtrlCreateGroup("交叉口查询", 56, 136, 633, 89)
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
Global $Input2 = GUICtrlCreateInput("", 240, 168, 329, 23)
Global $Button2 = GUICtrlCreateButton("查询", 592, 168, 75, 25)
Global $Label1 = GUICtrlCreateLabel("请输入交叉口名称", 96, 168, 132, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $Group3 = GUICtrlCreateGroup("查询结果", 56, 280, 625, 273)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
Global $ListView1 = GUICtrlCreateListView("交叉口名称|道路等级|相位", 96, 312, 553, 201, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 200)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 150)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 200)
_GUICtrlListView_JustifyColumn(GUICtrlGetHandle($ListView1), 1, 2)
_GUICtrlListView_JustifyColumn(GUICtrlGetHandle($ListView1), 2, 2)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $TabSheet2 = GUICtrlCreateTabItem("路段查询")
Global $Group5 = GUICtrlCreateGroup("路段查询", 54, 88, 633, 89)
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
Global $Button4 = GUICtrlCreateButton("查询", 590, 120, 75, 25)
Global $Label3 = GUICtrlCreateLabel("请输入路段名称", 94, 120, 116, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
Global $Input4 = GUICtrlCreateInput("Input4", 240, 120, 337, 23)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $ListView4 = GUICtrlCreateListView("路段名称|车道数|道路交通量", 72, 200, 601, 401, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 200)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 200)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 200)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
Global $TabSheet3 = GUICtrlCreateTabItem("车辆查询")
Global $Group7 = GUICtrlCreateGroup("车辆查询", 46, 100, 633, 89)
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
Global $Button1 = GUICtrlCreateButton("查询", 582, 132, 75, 25)
Global $Label7 = GUICtrlCreateLabel("请输入交叉口名称", 86, 132, 132, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
Global $Input6 = GUICtrlCreateInput("Input6", 232, 128, 337, 23)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $ListView2 = GUICtrlCreateListView("交叉口名称|进口1|进口2|进口3|进口4", 48, 200, 633, 385, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 200)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 4, 150)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
Global $TabSheet4 = GUICtrlCreateTabItem("信号配时查询")
Global $Group4 = GUICtrlCreateGroup("交叉口查询", 61, 100, 633, 89)
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
Global $Button3 = GUICtrlCreateButton("查询", 605, 124, 75, 25)
Global $Label2 = GUICtrlCreateLabel("请输入交叉口名称", 101, 132, 132, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
Global $Input3 = GUICtrlCreateInput("Input3", 248, 128, 337, 23)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $ListView5 = GUICtrlCreateListView("交叉口名称|绿灯时长|黄灯时长|红灯时长|周期", 64, 208, 625, 401, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 200)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 4, 150)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
Global $TabSheet5 = GUICtrlCreateTabItem("交叉口排队长度查询")
Global $Group6 = GUICtrlCreateGroup("交叉口查询", 61, 88, 633, 89)
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
Global $Button5 = GUICtrlCreateButton("查询", 605, 120, 75, 25)
Global $Label4 = GUICtrlCreateLabel("请输入交叉口名称", 101, 120, 132, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
Global $Input5 = GUICtrlCreateInput("Input5", 240, 120, 353, 23)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $ListView3 = GUICtrlCreateListView("交叉口名称|排队长度|延误时长", 56, 184, 633, 417, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 200)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 240)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 200)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlCreateTabItem("")
Global $Group1 = GUICtrlCreateGroup("浏览", 96, 0, 569, 49)
Global $Label5 = GUICtrlCreateLabel("当前数据库", 112, 16, 84, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
Global $Input1 = GUICtrlCreateInput($mdb_data_path, 200, 16, 249, 21)
Global $Button6 = GUICtrlCreateButton("请选择数据库", 464, 16, 177, 25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###



While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                       
                Case $GUI_EVENT_CLOSE
                        ex()
                Case $MenuItem7
                        ex()
                Case $MenuItem2
                        backup()
                Case $MenuItem6
                        print()
                Case $MenuItem5
                        print()
                        Send("^p")
                Case $Button6
                        choose_data()
                Case $Button2
                        Global $am = GUICtrlRead($Input2)
                        jccx()
                Case $Button4
                        ldcx()
                Case $Button1
                        clcx()
                Case $Button3
                        xhps()
                Case $Button5
                        jclength()


        EndSwitch
WEnd

Func choose_data()
        $datadir = FileOpenDialog("请选择数据库文件", @WindowsDir & "\", "ACCESS数据库文件(*.mdb)", 3)
        If Not FileExists($mdb_data_path) Or StringRight($datadir, 3) <> "mdb" Then
                MsgBox(64, "提示", "所选择的文件错误,请重新选择.后缀名需为(.mdb)")
                $mdb_data_path = "database\交通.mdb"
                GUICtrlSetData($Input1, $mdb_data_path)
        EndIf
        GUICtrlSetData($Input1, $mdb_data_path)

EndFunc   ;==>choose_data

Func print()
        Switch GUICtrlRead($main)
                Case 1
                        $listview = $ListView1
                Case 2
                        $listview = $ListView2
                Case 3
                        $listview = $ListView3
                Case 4
                        $listview = $ListView4
                Case Else
                        $listview = $ListView5
        EndSwitch
        $excnum = _GUICtrlListView_GetItemCount($listview)
        If $excnum = 0 Then
                MsgBox(64, "提示", "没有记录可被输出.")
        Else
                Local $oExcel = _ExcelBookNew(1)
                For $y = 0 To $excnum
                        $excret = _GUICtrlListView_GetItemTextString($listview, $y)
                        $excarray = StringSplit($excret, "|")
                        For $x = 0 To $excarray[0]
                                _ExcelWriteCell($oExcel, $excarray[$x], $y + 2, $x)
                        Next
                Next
        EndIf
EndFunc   ;==>print

Func jccx()
        GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)
           $addfld = ObjCreate("ADODB.Connection")
           $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
           $RS = ObjCreate("ADODB.Recordset")
           $RS.ActiveConnection = $addfld
           $RS.Open("Select * From " & $Cahuanzx & " WHERE name ='" & $am & "'")
           While (Not $RS.eof And Not $RS.bof)
                   If @error = 1 Then ExitLoop
                   GUICtrlCreateListViewItem($RS.Fields(0).value & "|" & $RS.Fields(1).value & "|" & $RS.Fields(2).value, $ListView1)
                   $RS.movenext
           WEnd
           $RS.close
           $addfld.Close

   EndFunc   ;==>jccx


Func ldcx()
                GUICtrlSendMsg($ListView4, $LVM_DELETEALLITEMS, 0, 0)
                $addfld = ObjCreate("ADODB.Connection")
                $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
                $RS = ObjCreate("ADODB.Recordset")
                $RS.ActiveConnection = $addfld
                $RS.Open("Select * From " & $Cahuanzy & " WHERE section ='" & $Input4 & "'")
                While (Not $RS.eof And Not $RS.bof)
                        If @error = 1 Then ExitLoop
                        GUICtrlCreateListViewItem($RS.Fields(0).value & "|" & $RS.Fields(1).value & "|" & $RS.Fields(2).value, $ListView4)
                        $RS.movenext
                WEnd
                $RS.close
                $addfld.Close

EndFunc   ;==>ldcx

Func clcx()
                GUICtrlSendMsg($ListView2, $LVM_DELETEALLITEMS, 0, 0)
                $addfld = ObjCreate("ADODB.Connection")
                $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
                $RS = ObjCreate("ADODB.Recordset")
                $RS.ActiveConnection = $addfld
                $RS.Open("Select * From " & $Cahuanzz & " WHERE name ='" & $Input6 & "'")
                While (Not $RS.eof And Not $RS.bof)
                        If @error = 1 Then ExitLoop
                        GUICtrlCreateListViewItem($RS.Fields(0).value & "|" & $RS.Fields(1).value & "|" & $RS.Fields(2).value, $ListView2)
                        $RS.movenext
                WEnd
                $RS.close
                $addfld.Close

EndFunc   ;==>clcx


Func xhps()
                GUICtrlSendMsg($ListView5, $LVM_DELETEALLITEMS, 0, 0)
                $addfld = ObjCreate("ADODB.Connection")
                $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
                $RS = ObjCreate("ADODB.Recordset")
                $RS.ActiveConnection = $addfld
                $RS.Open("Select * From " & $Cahuanzu & " WHERE name ='" & $Input3 & "'")
                While (Not $RS.eof And Not $RS.bof)
                        If @error = 1 Then ExitLoop
                        GUICtrlCreateListViewItem($RS.Fields(0).value & "|" & $RS.Fields(1).value & "|" & $RS.Fields(2).value, $ListView5)
                        $RS.movenext
                WEnd
                $RS.close
                $addfld.Close
EndFunc   ;==>xhps

Func jclength()
                GUICtrlSendMsg($ListView3, $LVM_DELETEALLITEMS, 0, 0)
                $addfld = ObjCreate("ADODB.Connection")
                $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
                $RS = ObjCreate("ADODB.Recordset")
                $RS.ActiveConnection = $addfld
                $RS.Open("Select * From " & $Cahuanzv & " WHERE name ='" & $Input5 & "'")
                While (Not $RS.eof And Not $RS.bof)
                        If @error = 1 Then ExitLoop
                        GUICtrlCreateListViewItem($RS.Fields(0).value & "|" & $RS.Fields(1).value & "|" & $RS.Fields(2).value, $ListView3)
                        $RS.movenext
                WEnd
                $RS.close
                $addfld.Close

EndFunc   ;==>jclength

Func ex()
        $answer = MsgBox(1, "提示", "确定要退出本程序吗?")
        If $answer = 1 Then
                FileDelete($mdb_data_path)
                Exit
        Else
        EndIf
EndFunc   ;==>ex

Func backup()
        $answer = MsgBox(1, "提示", "确定要备份数据库吗?")
        If $answer = 1 Then
                $time1 = _NowCalcDate()
                $time2 = _NowTime()
                $timearray1 = StringSplit($time1, "/")
                $timearray2 = StringSplit($time2, ":")
                $time = $timearray1[1] & $timearray1[2] & $timearray1[3] & $timearray2[1] & $timearray2[2]
                DirCreate(@ScriptDir & "\dbback\")
                FileCopy($mdb_data_path, @ScriptDir & "\dbback\" & $time & "\公交.mdb", 8)
                MsgBox(0, "提示", "数据库已被备份到DBBACK目录下" & $time & "文件中.")
        Else
        EndIf
EndFunc   ;==>backup


发表于 2020-5-11 10:01:04 | 显示全部楼层
锋城未逾年 发表于 2020-5-11 09:23
#include
#include
#include

数据库没建全,看不出问题
 楼主| 发表于 2020-5-11 10:02:18 | 显示全部楼层
chzj589 发表于 2020-5-11 10:01
数据库没建全,看不出问题

好的谢谢老师
发表于 2020-5-11 11:08:46 | 显示全部楼层

就你的處理方式 來說  首先

1. 資料庫存在是  5 2 0 但是你抓取的時候 GUICtrlSetData($ListView1, $RS.Fields(0).value)  

$RS.Fields(0).value 只是 5   我記得 LISTVIEW   賦直 是要   $item1 = GUICtrlCreateListViewItem ("项目 2|列22|列23", $listview)

至少也是 5|2|0  吧
发表于 2020-5-11 11:09:42 | 显示全部楼层

後來的語法就對了
  GUICtrlCreateListViewItem($RS.Fields(0).value & "|" & $RS.Fields(1).value & "|" & $RS.Fields(2).value, $ListView1)

所以你現在最後遇到的問題是???

 楼主| 发表于 2020-5-11 13:19:19 来自手机 | 显示全部楼层
kk_lee69 发表于 2020-5-11 11:09
後來的語法就對了
  GUICtrlCreateListViewItem($RS.Fields(0).value & "|" & $RS.Fields(1).value & "| ...

老师,我现在运行这个程序是怎么发现那个listview框一直在闪动,没有数据显示我很晕,数据库也重建了
发表于 2020-5-11 14:00:53 | 显示全部楼层
锋城未逾年 发表于 2020-5-11 13:19
老师,我现在运行这个程序是怎么发现那个listview框一直在闪动,没有数据显示我很晕,数据库也重建了

你的数据库里没数据,怎么读取???
只有表 "table1"里有三行数据
发表于 2020-5-11 14:08:39 | 显示全部楼层
锋城未逾年 发表于 2020-5-11 13:19
老师,我现在运行这个程序是怎么发现那个listview框一直在闪动,没有数据显示我很晕,数据库也重建了


#AutoIt3Wrapper_UseX64 = n
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <Excel.au3>
#include <Date.au3>
;~ FileInstall("Data.mdb", @WindowsDir & "\Data.mdb", 1)
Global $mdb_data_path = @ScriptDir & "\Data.mdb"
Global $mdb_data_pwd = ""
Global $Cahuanzx = "table1";"table1"
Global $Cahuanzy = "table2"
Global $Cahuanzz = "table3"
Global $Cahuanzu = "table4"
Global $Cahuanzv = "table5"
Dim $main
Dim $jccx
Dim $ldcx
Dim $clcx
Dim $xhps
Dim $jclength
Dim $oExcel
Dim $time
Dim $time1
Dim $time2
Dim $timearray1
Dim $timearray2
Dim $nMs
#Region ### START Koda GUI section ### Form=D:\我的文件\Documents\软著\交通运输工程大数据管理\Form2.kxf
Global $Form2 = GUICreate("交通运输工程大数据管理", 775, 677, 170, 138)
Global $MenuItem4 = GUICtrlCreateMenu("数据输出(&X)")
Global $MenuItem6 = GUICtrlCreateMenuItem("输出到Excel", $MenuItem4)
Global $MenuItem5 = GUICtrlCreateMenuItem("输出到Excel并打印", $MenuItem4)
Global $MenuItem1 = GUICtrlCreateMenu("数据处理(&Y)")
Global $MenuItem2 = GUICtrlCreateMenuItem("备份数据库", $MenuItem1)
Global $MenuItem7 = GUICtrlCreateMenu("退出(&Z)")
;~ GUICtrlCreateTab(40, 48, 660, 560)
Global $main = GUICtrlCreateTab(40, 48, 660, 560)
Global $TabSheet1 = GUICtrlCreateTabItem("交叉口查询")
Global $Group2 = GUICtrlCreateGroup("交叉口查询", 56, 136, 633, 89)
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
Global $Input2 = GUICtrlCreateInput("", 240, 168, 329, 23)
Global $Button2 = GUICtrlCreateButton("查询", 592, 168, 75, 25)
Global $Label1 = GUICtrlCreateLabel("请输入交叉口名称", 96, 168, 132, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $Group3 = GUICtrlCreateGroup("查询结果", 56, 280, 625, 273)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
Global $ListView1 = GUICtrlCreateListView("交叉口名称|道路等级|相位", 96, 312, 553, 201, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 200)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 150)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 200)
_GUICtrlListView_JustifyColumn(GUICtrlGetHandle($ListView1), 1, 2)
_GUICtrlListView_JustifyColumn(GUICtrlGetHandle($ListView1), 2, 2)
GUICtrlCreateGroup("", -99, -99, 1, 1)

Global $TabSheet2 = GUICtrlCreateTabItem("路段查询")
Global $Group5 = GUICtrlCreateGroup("路段查询", 54, 88, 633, 89)
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
Global $Button4 = GUICtrlCreateButton("查询", 590, 120, 75, 25)
Global $Label3 = GUICtrlCreateLabel("请输入路段名称", 94, 120, 116, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
Global $Input4 = GUICtrlCreateInput("Input4", 240, 120, 337, 23)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $ListView4 = GUICtrlCreateListView("路段名称|车道数|道路交通量", 72, 200, 601, 401, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 200)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 200)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 200)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
Global $TabSheet3 = GUICtrlCreateTabItem("车辆查询")
Global $Group7 = GUICtrlCreateGroup("车辆查询", 46, 100, 633, 89)
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
Global $Button1 = GUICtrlCreateButton("查询", 582, 132, 75, 25)
Global $Label7 = GUICtrlCreateLabel("请输入交叉口名称", 86, 132, 132, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
Global $Input6 = GUICtrlCreateInput("Input6", 232, 128, 337, 23)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $ListView2 = GUICtrlCreateListView("交叉口名称|进口1|进口2|进口3|进口4", 48, 200, 633, 385, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 200)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 4, 150)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
Global $TabSheet4 = GUICtrlCreateTabItem("信号配时查询")
Global $Group4 = GUICtrlCreateGroup("交叉口查询", 61, 100, 633, 89)
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
Global $Button3 = GUICtrlCreateButton("查询", 605, 124, 75, 25)
Global $Label2 = GUICtrlCreateLabel("请输入交叉口名称", 101, 132, 132, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
Global $Input3 = GUICtrlCreateInput("Input3", 248, 128, 337, 23)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $ListView5 = GUICtrlCreateListView("交叉口名称|绿灯时长|黄灯时长|红灯时长|周期", 64, 208, 625, 401, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 200)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 4, 150)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
Global $TabSheet5 = GUICtrlCreateTabItem("交叉口排队长度查询")
Global $Group6 = GUICtrlCreateGroup("交叉口查询", 61, 88, 633, 89)
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
Global $Button5 = GUICtrlCreateButton("查询", 605, 120, 75, 25)
Global $Label4 = GUICtrlCreateLabel("请输入交叉口名称", 101, 120, 132, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
Global $Input5 = GUICtrlCreateInput("Input5", 240, 120, 353, 23)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $ListView3 = GUICtrlCreateListView("交叉口名称|排队长度|延误时长", 56, 184, 633, 417, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 200)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 240)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 200)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlCreateTabItem("")
Global $Group1 = GUICtrlCreateGroup("浏览", 96, 0, 569, 49)
Global $Label5 = GUICtrlCreateLabel("当前数据库", 112, 16, 84, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
Global $Input1 = GUICtrlCreateInput($mdb_data_path, 200, 16, 249, 21)
Global $Button6 = GUICtrlCreateButton("请选择数据库", 464, 16, 177, 25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###



While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg

                Case $GUI_EVENT_CLOSE
                        ex()
                Case $MenuItem7
                        ex()
                Case $MenuItem2
                        backup()
                Case $MenuItem6
                        print()
                Case $MenuItem5
                        print()
                        Send("^p")
                Case $Button6
                        choose_data()
                Case $Button2
                        Global $am = GUICtrlRead($Input2)
                        jccx()
                Case $Button4
                        ldcx()
                Case $Button1
                        clcx()
                Case $Button3
                        xhps()
                Case $Button5
                        jclength()


        EndSwitch
WEnd

Func choose_data()
        $datadir = FileOpenDialog("请选择数据库文件", @ScriptDir & "\", "ACCESS数据库文件(*.mdb)", 3);@WindowsDir &
        If Not FileExists($mdb_data_path) Or StringRight($datadir, 3) <> "mdb" Then
                MsgBox(64, "提示", "所选择的文件错误,请重新选择.后缀名需为(.mdb)")
                $mdb_data_path = "database\交通.mdb"
                GUICtrlSetData($Input1, $datadir)
        EndIf
        GUICtrlSetData($Input1, $datadir)

EndFunc   ;==>choose_data

Func print()
        Switch GUICtrlRead($main)
                Case 1
                        $listview = $ListView1
                Case 2
                        $listview = $ListView2
                Case 3
                        $listview = $ListView3
                Case 4
                        $listview = $ListView4
                Case Else
                        $listview = $ListView5
        EndSwitch
        $excnum = _GUICtrlListView_GetItemCount($listview)
        If $excnum = 0 Then
                MsgBox(64, "提示", "没有记录可被输出.")
        Else
                ;Local $oExcel = _ExcelBookNew(1)
                For $y = 0 To $excnum
                        $excret = _GUICtrlListView_GetItemTextString($listview, $y)
                        $excarray = StringSplit($excret, "|")
                        For $x = 0 To $excarray[0]
                                ;_ExcelWriteCell($oExcel, $excarray[$x], $y + 2, $x)
                        Next
                Next
        EndIf
EndFunc   ;==>print

Func jccx()
        $am = GUICtrlRead($Input2)
        GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)
        $addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $RS = ObjCreate("ADODB.Recordset")
        $RS.ActiveConnection = $addfld
        $RS.Open("Select * From " & $Cahuanzx & " WHERE AA1='" & $am & "'")
        While (Not $RS.eof And Not $RS.bof)
                If @error = 1 Then ExitLoop
                GUICtrlCreateListViewItem($RS.Fields(0).value & "|" & $RS.Fields(1).value & "|" & $RS.Fields(2).value, $ListView1)
                $RS.movenext
        WEnd
        $RS.close
        $addfld.Close

EndFunc   ;==>jccx


Func ldcx()
        $am = GUICtrlRead($Input4)
        GUICtrlSendMsg($ListView4, $LVM_DELETEALLITEMS, 0, 0)
        $addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $RS = ObjCreate("ADODB.Recordset")
        $RS.ActiveConnection = $addfld
        $RS.Open("Select * From " & $Cahuanzx & " WHERE AA1='" & $am & "'")
        ;$RS.Open("Select * From " & $Cahuanzy & " WHERE section ='" & $Input4 & "'")
        While (Not $RS.eof And Not $RS.bof)
                If @error = 1 Then ExitLoop
                GUICtrlCreateListViewItem($RS.Fields(0).value & "|" & $RS.Fields(1).value & "|" & $RS.Fields(2).value, $ListView4)
                $RS.movenext
        WEnd
        $RS.close
        $addfld.Close

EndFunc   ;==>ldcx

Func clcx()
        $am = GUICtrlRead($Input6)
        GUICtrlSendMsg($ListView2, $LVM_DELETEALLITEMS, 0, 0)
        $addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $RS = ObjCreate("ADODB.Recordset")
        $RS.ActiveConnection = $addfld
        $RS.Open("Select * From " & $Cahuanzx & " WHERE AA1='" & $am & "'")
        ;$RS.Open("Select * From " & $Cahuanzz & " WHERE name ='" & $Input6 & "'")
        While (Not $RS.eof And Not $RS.bof)
                If @error = 1 Then ExitLoop
                GUICtrlCreateListViewItem($RS.Fields(0).value & "|" & $RS.Fields(1).value & "|" & $RS.Fields(2).value, $ListView2)
                $RS.movenext
        WEnd
        $RS.close
        $addfld.Close

EndFunc   ;==>clcx


Func xhps()
        $am = GUICtrlRead($Input3)
        GUICtrlSendMsg($ListView5, $LVM_DELETEALLITEMS, 0, 0)
        $addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $RS = ObjCreate("ADODB.Recordset")
        $RS.ActiveConnection = $addfld
        $RS.Open("Select * From " & $Cahuanzx & " WHERE AA1='" & $am & "'")
        ;$RS.Open("Select * From " & $Cahuanzu & " WHERE name ='" & $Input3 & "'")
        While (Not $RS.eof And Not $RS.bof)
                If @error = 1 Then ExitLoop
                GUICtrlCreateListViewItem($RS.Fields(0).value & "|" & $RS.Fields(1).value & "|" & $RS.Fields(2).value, $ListView5)
                $RS.movenext
        WEnd
        $RS.close
        $addfld.Close
EndFunc   ;==>xhps

Func jclength()
        $am = GUICtrlRead($Input5)
        GUICtrlSendMsg($ListView3, $LVM_DELETEALLITEMS, 0, 0)
        $addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $RS = ObjCreate("ADODB.Recordset")
        $RS.ActiveConnection = $addfld
        $RS.Open("Select * From " & $Cahuanzx & " WHERE AA1='" & $am & "'")
        ;$RS.Open("Select * From " & $Cahuanzv & " WHERE name ='" & $Input5 & "'")
        While (Not $RS.eof And Not $RS.bof)
                If @error = 1 Then ExitLoop
                GUICtrlCreateListViewItem($RS.Fields(0).value & "|" & $RS.Fields(1).value & "|" & $RS.Fields(2).value, $ListView3)
                $RS.movenext
        WEnd
        $RS.close
        $addfld.Close

EndFunc   ;==>jclength

Func ex()
        $answer = MsgBox(1, "提示", "确定要退出本程序吗?")
        If $answer = 1 Then
                ;FileDelete($mdb_data_path)
                Exit
        Else
        EndIf
EndFunc   ;==>ex
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-26 11:41 , Processed in 0.095182 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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