#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.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>
#Region ### START Koda GUI section ### Form=C:\Users\qinshiyong\Desktop\图书管理\图书管理主框.kxf
Global $Form1 = GUICreate("图书管理", 620, 293, -1, -1)
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
; 这里添加 ---------------------------
Local $sText = _GUICtrlListView_GetItemTextString($ListView1, $n_id - 1)
Local $string = StringSplit($sText, '|')
;------------------------------------
xiugai($string); $string
EndIf
EndSwitch
WEnd
Func xiugai($strID)
#Region ### START Koda GUI section ### Form==========================================================修改框
;~ Global $Form2 = GUICreate("修改信息", 321, 203, -1, -1)
Global $Form2 = GUICreate("修改信息", 321, 203, -1, -1, -1, -1, $Form1) ;这样比较好
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, 217, 21)
Global $Input2 = GUICtrlCreateInput("", 80, 81, 217, 21)
Global $Combo1 = GUICtrlCreateCombo("", 80, 106, 129, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "一年级|二年级|三年级|四年级", "")
Global $Date2 = GUICtrlCreateDate("", 80, 129, 130, 21)
Global $Date1 = GUICtrlCreateDate(" ", 80, 56, 130, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
; 这里添加 ---------------------------
GUICtrlSetData($Input1, $strID[2])
GUICtrlSetData($Date1, StringTrimRight(StringRegExpReplace(StringRegExpReplace($strID[3], "[年月日]", "/"), "(?<=/)(\d)(?=/|$)", "0\1"), 1))
GUICtrlSetData($Input2, $strID[4])
GUICtrlSetData($Combo1, $strID[5])
GUICtrlSetData($Date2, StringTrimRight(StringRegExpReplace(StringRegExpReplace($strID[6], "[年月日]", "/"), "(?<=/)(\d)(?=/|$)", "0\1"), 1))
;------------------------------------
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
GUIDelete($Form2)
ExitLoop
Case $Button1
;xie()
EndSwitch
WEnd
EndFunc ;==>xiugai
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