|
发表于 2014-5-14 16:45:36
|
显示全部楼层
还是没有获取到ListView里面的信息
qsy666888 发表于 2014-5-14 16:41
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
Global $Input1, $Input2, $Combo1, $Date1, $Date2, $ListView1, $Form2, $Form1
#region ### START Koda GUI section ### Form=C:\Users\qinshiyong\Desktop\图书管理\图书管理主框.kxf
Global $Form1 = GUICreate("图书管理", 620, 293, -1, -1)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFYup")
Global $ListView1 = GUICtrlCreateListView("序号|图书名称|借出时间|学生姓名|班级|归还时间", 0, 0, 617, 289)
Local $buttoncontext = GUICtrlCreateContextMenu($ListView1)
Local $tj = GUICtrlCreateMenuItem("添加信息...", $buttoncontext)
Local $bj = GUICtrlCreateMenuItem("编辑信息...", $buttoncontext)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
$mdb_data_path = @ScriptDir & "\msq.mdb"
$mdb_data_pwd = ""
$T = "*"
$tblname = "mydb"
new()
If FileExists($mdb_data_path) Then du()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $bj
Local $n_id = _GUICtrlListView_GetItemText($ListView1, Number(_GUICtrlListView_GetSelectedIndices($ListView1)));选中行的第一列
If $n_id = 0 Then
MsgBox(48, '提示:', '请选择要修改的条目!')
Else
xiugai($bj)
EndIf
EndSwitch
WEnd
Func WM_NOTIFYup($hWnd, $iMsg, $iwParam, $ilParam);弹出修改
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListBox, $tInfo
Local $iIndex
$hWndListView = $ListView1
If Not IsHWnd($ListView1) Then $hWndListView = GUICtrlGetHandle($ListView1)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_DBLCLK
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$iIndex = DllStructGetData($tInfo, "Index")
If $iIndex >= 0 Then xiugaia()
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFYup
Func xiugaia()
xiugai(1)
$Strn1 = GUICtrlRead(GUICtrlRead($ListView1, ""))
$Strnspin1 = StringSplit($Strn1, "|")
If $Strnspin1[1] = '0' Then
MsgBox(48, '提示', '请选择要修改的条目')
Else
$Strnspin1 = StringSplit($Strn1, "|")
If ($Strn1 = 0) Then
MsgBox(48, '提示', '不能修改!')
Else
$Strn1 = GUICtrlRead(GUICtrlRead($ListView1))
$Strnspin1 = StringSplit($Strn1, "|")
GUICtrlSetData($Input1, '')
GUICtrlSetData($Date1, '')
GUICtrlSetData($Input2, '')
GUICtrlSetData($Combo1, '')
GUICtrlSetData($Date2, '')
$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 " & $T & " From " & $tblname & " WHERE xh" & " = " & $Strnspin1[1]) ;$t : 表示一个连接  $adtables :表示的是这个表的名称
GUICtrlSetData($Input1, $RS.Fields(1).value)
GUICtrlSetData($Date1, $RS.Fields(2).value)
GUICtrlSetData($Input2, $RS.Fields(3).value)
GUICtrlSetData($Combo1, $RS.Fields(4).value)
GUICtrlSetData($Date2, $RS.Fields(5).value)
$RS.movenext
$RS.close
$addfld.Close
EndIf
EndIf
EndFunc   ;==>xiugaia
Func xiugai($strID)
#region ### START Koda GUI section ### Form==========================================================修改框
Global $Form2 = GUICreate("修改信息", 321, 203, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "GForm2Close")
Global $Label1 = GUICtrlCreateLabel("图书名称:", 16, 37, 64, 17)
Global $Label2 = GUICtrlCreateLabel("借出时间:", 16, 61, 64, 17)
Global $Label3 = GUICtrlCreateLabel("学    生:", 16, 81, 64, 17)
Global $Label4 = GUICtrlCreateLabel("年级(班):", 16, 109, 64, 17)
Global $Label5 = GUICtrlCreateLabel("归还时间:", 14, 133, 64, 17)
Global $Button1 = GUICtrlCreateButton("修    改", 240, 160, 64, 25)
Global $Group1 = GUICtrlCreateGroup("图书管理信息编辑", 8, 3, 305, 193)
Global $Input1 = GUICtrlCreateInput("", 80, 33, 130, 21)
Global $Input2 = GUICtrlCreateInput("", 80, 81, 130, 21)
Global $Combo1 = GUICtrlCreateInput("", 80, 106, 130, 21);, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
;GUICtrlSetData(-1, "一年级|二年级|三年级|四年级", "")
Global $Date2 = GUICtrlCreateInput("", 80, 129, 130, 21)
Global $Date1 = GUICtrlCreateInput(" ", 80, 56, 130, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW, $Form2)
#endregion ### END Koda GUI section ###
EndFunc   ;==>xiugai
Func GForm2Close()
GUISetState(@SW_HIDE, $Form2)
GUISetState(@SW_SHOW, $Form1)
EndFunc   ;==>GForm2Close
Func new()
$newMdb = ObjCreate('ADOX.Catalog')
$newMdb.Create("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
$newMdb.ActiveConnection.Close
$addtbl = ObjCreate("ADODB.Connection")
$addtbl.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
$addtbl.Execute("CREATE TABLE " & $tblname)
$addtbl.Close;
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
$addfld.Execute("ALTER TABLE " & $tblname & " ADD xh identity(1, 1) primary key,tsmc text(255) ,jcsj text(80),xsxm text(100),bj text(50),ghsj text(50)");id identity(1, 1) primary key为自动编号和主键
$addfld.Close
EndFunc   ;==>new
Func du()
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 " & $T & " From " & $tblname)
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, $ListView1)
$RS.movenext
WEnd
$RS.close
$addfld.Close
EndFunc   ;==>du
Func _clearInput()
GUICtrlSetData($Input1, '')
GUICtrlSetData($Date1, '')
GUICtrlSetData($Input2, '')
GUICtrlSetData($Combo1, '')
GUICtrlSetData($Date2, '')
GUICtrlSetState($Input1, $GUI_FOCUS)
EndFunc   ;==>_clearInput
Func _setInput($strID)
Dim $addfld, $RS
$addtbl = ObjCreate("ADODB.Connection")
$addtbl.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
$RS = ObjCreate('ADOX.Catalog')
$RS.ActiveConnection = $addfld
$RS.Open("Select " & $T & " From " & $tblname & " WHERE 序号" & " = " & $strID)
$id = $RS.Fields(0).value
GUICtrlSetData($Input1, $RS.Fields(1).value)
GUICtrlSetData($Date1, $RS.Fields(2).value)
GUICtrlSetData($Input2, $RS.Fields(3).value)
GUICtrlSetData($Combo1, $RS.Fields(4).value)
GUICtrlSetData($Date2, $RS.Fields(5).value)
$RS.movenext
$RS.close
$addfld.Close
EndFunc   ;==>_setInput |
|