#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
$mdb = @ScriptDir & "\db1.mdb"
$Table = "db1"
$T = "*"
$Form1_1 = GUICreate("Form1", 880, 442, 183, 114)
$ListView1 = GUICtrlCreateListView("编号 |品名|类型|数量|单价|总价|经办人|单位或个人|货款|日期", 56, 24, 673, 297)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 80)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 4, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 5, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 6, 70)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 7, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 8, 60)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 9, 50)
$Label1 = GUICtrlCreateLabel("合计:元", 64, 344, 120, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
dumdb()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func dumdb()
GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.Open("Select " & $T & " From " & $Table)
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 & "|" & $RS.Fields(3).value & "|" & $RS.Fields(4).value & "|" & $RS.Fields(5).value & "|" & $RS.Fields(6).value & "|" & $RS.Fields(7).value & "|" & $RS.Fields(8).value & "|" & $RS.Fields(9).value, $ListView1)
$RS.movenext
WEnd
$RS.close
$addfld.Close
Local $iTotal = 0
For $i = 0 To _GUICtrlListView_GetItemCount($ListView1) - 1
$iTotal += _GUICtrlListView_GetItemText($ListView1, $i, 4)
Next
GUICtrlSetData($Label1, '合计:' & $iTotal & ' 元')
EndFunc ;==>dumdb
|