本帖最后由 邪恶海盗 于 2012-9-25 17:28 编辑
回复 6# kk_lee69
#include <Date.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <ListviewConstants.au3>
#Include <GuiListView.au3>
#Include <GuiImageList.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
#Include <GuiButton.au3>
#include <GuiComboBox.au3>
$main=GUICreate("XX",400,200)
$btn5=GUICtrlCreateButton('保存至数据库', 18,22,100,22, $SS_center)
GUICtrlSetFont(-1, 10.5, 500, 0, "", 18)
$combo2=GUICtrlCreateCombo("请刷新后选择", 124, 22, 100,11)
$btn22=GUICtrlCreateButton('刷新', 235,22,60,21)
GUICtrlSetFont(-1, 10.5, 500, 0, "", 18)
$btn24=GUICtrlCreateButton('读取数据', 305,22,80,21)
GUICtrlSetFont(-1, 10.5, 500, 0, "", 18)
GUICtrlSetFont(-1, 13, 500, 0, "", 18)
$list2=GUICtrlCreateListView("33|22|11", 10, 64, 780, 200,"")
GUICtrlCreateListViewItem("xx|dd|xx",$list2)
$List3 = GUICtrlCreateListView("11111|22222|3333", 10, 104, 780, 200,"")
_GUICtrlListView_SetExtendedListViewStyle($list3, $LVS_EX_GRIDLINES)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
;DirRemove($Temp, 1)
Exit
Case $btn5;保存至数据库
Global $Msg, $hQuery, $aRow
Global $Temp, $a1, $a2, $a3
$SQLite_Data = @ScriptDir&"\SQLite\"&@YEAR&@MON&@MDAY&".db"
_SQLite_Startup () ;加载 SQLite.dll
If Not FileExists($SQLite_Data) Then
SQLCreate()
EndIf;如果数据库不存大则创建
SQLiteInsert(_GUICtrlListView_GetItemText($list2,0,0),_GUICtrlListView_GetItemText($list2,0,1),_GUICtrlListView_GetItemText($list2,0,2))
Case $btn22
_searchfile(@ScriptDir&"\SQLite\*.db")
Case $btn24;读取数据库
Global $Msg, $hQuery, $aRow
Global $Temp, $a1, $a2, $a3
SQLiteRead()
;
;---------------------------------
EndSwitch
WEnd
Func SQLCreate();打开或创建数据库
_SQLite_Open ($SQLite_Data)
_SQLite_Exec(-1, "Create Table IF NOT Exists TestTable (IDs Text PRIMARY KEY, wb Text, bs Text);")
;SQLite数据库中创建列表
_SQLite_Close ()
EndFunc
Func SQLiteInsert($a1, $a2, $a3);插入数据
_SQLite_Open ($SQLite_Data)
_SQLite_QuerySingleRow(-1, "SELECT IDs FROM TestTable WHERE IDs = '" & $a1 & "';", $aRow)
$Temp = $aRow[0]
If $Temp = "" Then
_SQLite_Exec(-1, "Insert into TestTable (IDs) values ('" & $a1 & "');")
EndIf
_SQLite_Exec(-1, "UPDATE TestTable SET wb = '" & $a2 & "' WHERE IDs = '" & $a1 & "';")
_SQLite_Exec(-1, "UPDATE TestTable SET bs = '" & $a3 & "' WHERE IDs = '" & $a1 & "';")
_SQLite_Close ()
EndFunc
Func SQLiteRead();读取数据
;_GUICtrlListView_DeleteAllItems ( GUICtrlGetHandle ($list3) )
_SQLite_Open (@ScriptDir&"\SQLite\"&GUICtrlRead($combo2));打开所选择的数据库
_SQLite_Query(-1, "SELECT * FROM TestTable ORDER BY IDs DESC;",$hQuery)
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
_GUICtrlListView_AddItem($list3, $aRow[0])
_GUICtrlListView_AddSubItem($list3, _GUICtrlListView_FindInText($list3, $aRow[0]), $aRow[1], 1)
_GUICtrlListView_AddSubItem($list3, _GUICtrlListView_FindInText($list3, $aRow[0]), $aRow[2], 2)
WEnd
_SQLite_Close ()
EndFunc
Func _searchfile($path);搜索文件
GUICtrlSetData($combo2,"")
Local $search = FileFindFirstFile($path)
If Not @error Then
While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop
_GUICtrlComboBox_AddString($combo2, $file)
WEnd
EndIf
EndFunc
精简了一下,还是这个问题,新打开之后要读取必需先保存一下,无法直接读取上次已经保存的内容...
指点一下看哪里有问题....
另外发现执行_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($list3))清除列表数据之后再读取数据库ListView3中也是不显示的,但再执行一次保存操作后又可以显示出前面的数据了... |