#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>
#include <GUIConstants.au3>
#include <EditConstants.au3>
Global $nLabel[11] ;定义Label数量
Global $ninput[11] ;定义input数量
Global $tabmain = "tabmain"
Global $Dll, $name_1, $pass_1, $qq_1, $w, $arr, $tblname,$e = 0,$T = "*",$mdb_data_path = "BB.mdb",$mdb_data_pwd = ""
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("***XXXX报备系统***", 800, 600, 100, 50)
;查看是否有皮肤
If FileExists("SkinCrafterDll.dll") Then
$search = FileFindFirstFile("*.skf")
If $search <> -1 Then
_SkinGUI("SkinCrafterDll.dll", "Quadro.skf", $Form1)
EndIf
EndIf
GUICtrlCreateGroup("", 5, 0, 790, 325)
$ListView0 = GUICtrlCreateListView("ID | 表名 ", 10, 15, 142, 300)
$ListView1 = GUICtrlCreateListView(" | | | | | | | | | ", 155, 15, 635, 300) ;返回控件标识符(控件ID).
GUICtrlCreateGroup("", 5, 325, 790, 265)
GUICtrlCreateGroup("1、创建数据库", 5, 335, 260, 50)
GUICtrlCreateGroup("2、创建表及字段", 5, 390, 260, 190)
GUICtrlCreateGroup("3、添加、修改、删除数据", 270, 335, 525, 245)
$Button0 = GUICtrlCreateButton("创建数据库", 35, 355, 200, 25, 0)
$Button5 = GUICtrlCreateButton("添加数据", 350, 550, 100, 25, 0)
$Button2 = GUICtrlCreateButton("修改数据", 490, 550, 100, 25, 0)
$Button3 = GUICtrlCreateButton("删除数据", 630, 550, 100, 25, 0)
GUICtrlCreateLabel("输入表名:", 10, 410, 100, 20)
$tblname_1 = GUICtrlCreateInput("", 110, 410, 150, 20)
GUICtrlCreateLabel("输入字段及类型:", 10, 440, 100, 20)
$zdnameandtype_1 = GUICtrlCreateInput("", 10, 465, 250, 80,$ES_MULTILINE)
$Tips = GUICtrlCreateLabel("例如:name char,age int", 110, 440, 150, 20)
GUICtrlSetState($Tips, $GUI_DISABLE)
$Button6 = GUICtrlCreateButton("创建表及定段", 35, 550, 200, 25, 0)
If FileExists($mdb_data_path) Then
read_tabmain()
EndIf
;AdlibEnable("sendmsg",50)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ;为已知的Windows 消息代码(WM_MSG)注册一个用户自定义的函数
Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
If @error Then Return $GUI_RUNDEFMSG
$IDFrom = DllStructGetData($tagNMHDR, 2) ;返回数据结构(struct)元素的数据
$Event = DllStructGetData($tagNMHDR, 3)
$tagNMHDR = 0
Switch $IDFrom;选择产生事件的控件
Case $ListView1
Switch $Event; 选择产生的事件
Case $NM_CLICK ; 左击
Case $NM_DBLCLK ; 双击
$Strn = GUICtrlRead(GUICtrlRead($ListView1)) ;列表视图数据
$Strnspin = StringSplit($Strn, "|") ;以指定分隔符把字符串拆分成若干子串
If $Strnspin[0] > 0 Then
GUICtrlSetData($ninput[0], StringStripWS($Strnspin[2], 2)) ;StringStripWS()删去字符串中的"空白符".
GUICtrlSetData($ninput[1], StringStripWS($Strnspin[3], 2))
GUICtrlSetData($ninput[2], StringStripWS($Strnspin[4], 2))
GUICtrlSetData($ninput[3], StringStripWS($Strnspin[5], 2))
GUICtrlSetData($ninput[4], StringStripWS($Strnspin[6], 2))
GUICtrlSetData($ninput[5], StringStripWS($Strnspin[7], 2))
GUICtrlSetData($ninput[6], StringStripWS($Strnspin[8], 2))
GUICtrlSetData($ninput[7], StringStripWS($Strnspin[9], 2))
GUICtrlSetData($ninput[8], StringStripWS($Strnspin[10], 2))
GUICtrlSetData($ninput[9], StringStripWS($Strnspin[11], 2))
EndIf
Case $NM_RCLICK ; 右击
EndSwitch
Case $ListView0
Switch $Event; 选择产生的事件
Case $NM_CLICK ; 左击
Case $NM_DBLCLK ; 双击
$Strn = GUICtrlRead(GUICtrlRead($ListView0))
$Strnspin = StringSplit($Strn, "|")
If $Strnspin[1] > 0 Then
$tabname = $Strnspin[2]
du($tabname)
If $e = 0 Then
adds($w, $arr)
$e = $w
Else
dels($e)
adds($w, $arr)
$e = $w
EndIf
EndIf
Case $NM_RCLICK ; 右击
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func sendmsg()
$Strn = GUICtrlRead(GUICtrlRead($ListView1))
$Strnspin = StringSplit($Strn, "|")
If $Strnspin[1] > 0 Then
GUICtrlSetData($name_1, StringStripWS($Strnspin[2], 2))
GUICtrlSetData($pass_1, StringStripWS($Strnspin[3], 2))
GUICtrlSetData($qq_1, StringStripWS($Strnspin[4], 2))
EndIf
EndFunc ;==>sendmsg
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
Dim $tabname
$Strn = GUICtrlRead(GUICtrlRead($ListView0))
$Strnspin = StringSplit($Strn, "|")
If $Strnspin[1] > 0 Then
$tabname = $Strnspin[2]
EndIf
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Quit()
Case $Button0
data($mdb_data_path, $tabmain)
Case $Button5;写入
If $Strnspin[1] > 0 Then
sx($tabname)
du($tabname)
Else
MsgBox(0, "提示", "请输入相应的数据!")
EndIf
Case $Button2 ;更新
If $Strnspin[1] > 0 Then
up($tabname)
du($tabname)
Else
MsgBox(0, "提示", "请选择要更新的数据!")
EndIf
Case $Button3 ;删除
If $Strnspin[1] > 0 Then
del($tabname)
du($tabname)
Else
MsgBox(0, "提示", "请选择要删除的数据!")
EndIf
Case $Button6 ;创建新表
$tblname = GUICtrlRead($tblname_1) ;读取输入的表名
$zdnameandtype = GUICtrlRead($zdnameandtype_1) ;读取输入的字段
If $tblname <> "" Then
If $zdnameandtype <> "" Then
newtable($mdb_data_path, $tblname, $zdnameandtype)
read_tabmain()
Else
MsgBox(0, "提示", "请输入要创建表的字段及类型!")
EndIf
Else
MsgBox(0, "提示", "请输入要创建表的名称!")
EndIf
EndSwitch
WEnd
Func du_table($tblname)
GUICtrlSendMsg($ListView0, $LVM_DELETEALLITEMS, 0, 0)
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
$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, $ListView1)
; MsgBox(0, "", $RS.Fields (1).value);显示表第一个数据
$RS.movenext
WEnd
$RS.close
$addfld.Close
EndFunc ;==>du_table
Func adds($w, $arr) ;建立Label(数量)
For $i = 0 To $w - 1
$y = StringSplit($arr[$i + 1], " ") ;以指定分隔符把字符串拆分成若干子串,返回一个数组,第一个元素($array[0])保存拆分后子串的数量,其余元素($array[1],$array[2] 等等)则保存着拆分后的每个字符串
$nLabel[$i] = GUICtrlCreateLabel($y[1], 280, 355 + 20 * $i, 60, 20)
$ninput[$i] = GUICtrlCreateInput("", 340, 355 + 20 * $i, 450, 20)
Next
EndFunc ;==>adds
Func dels($w) ;清除Label(数量)
For $i = 0 To $w - 1
GUICtrlDelete($nLabel[$i])
GUICtrlDelete($ninput[$i])
Next
EndFunc ;==>dels
Func du($tabname)
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.Open("Select " & $T & " From " & $tabmain & " where name = '" & $tabname & "'")
$temp = StringStripWS($RS.Fields(2).value, 2) ;删去字符串中的所有"空白符"
$arr = StringSplit($temp, ",") ;以指定分隔符把字符串拆分成若干子串
$w = $arr[0]
GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.Open("Select " & $T & " From " & $tabname)
Dim $n
While Not $RS.eof And Not $RS.bof
If @error = 1 Then ExitLoop
For $i = 0 To $w
;MsgBox(0,"",StringStripWS($RS.Fields ($i).value,2))
$n = $n & StringStripWS($RS.Fields($i).value, 2) & "|"
Next
;MsgBox(0,"",StringTrimRight ($n, 1))
GUICtrlCreateListViewItem(StringTrimRight($n, 1), $ListView1)
$RS.movenext
$n = ""
WEnd
$RS.close
$addfld.Close
Dim $strs = "ID|"
For $x = 1 To $w
$y = StringSplit($arr[$x], " ")
$strs = $strs & $y[1] & "|"
Next
GUICtrlSetData($ListView1, " | | | | | | | | | ")
GUICtrlSetData($ListView1, $strs)
EndFunc ;==>du
Func del($tabname)
$Strn = GUICtrlRead(GUICtrlRead($ListView1))
$Strnspin = StringSplit($Strn, "|")
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
$sQuery = "DELETE FROM " & $tabname & " IN '" & $mdb_data_path & "' WHERE id" & " = " & $Strnspin[1]
; MsgBox(0,"",$sQuery)
$addfld.execute($sQuery)
$addfld.close
MsgBox(4096, "提示:", $Strnspin[1] & " 删除成功!!!")
EndFunc ;==>del
Func up($tabname)
$Strn = GUICtrlRead(GUICtrlRead($ListView1))
$Strnspin = StringSplit($Strn, "|")
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.Open("Select " & $T & " From " & $tabmain & " where name = '" & $tabname & "'")
$temp = StringStripWS($RS.Fields(2).value, 2)
$arr = StringSplit($temp, ",")
$w = $arr[0]
Dim $h
For $i = 1 To $w
$arrs = StringSplit($arr[$i], " ")
$h = $h & $arrs[1] & " = '" & GUICtrlRead($ninput[$i - 1]) & "',"
Next
$sQuery = "update " & $tabname & " set " & StringTrimRight($h, 2) & "' WHERE id" & " = " & $Strnspin[1]
;MsgBox(0,"",$sQuery)
$addfld.execute($sQuery)
$addfld.close
MsgBox(4096, "提示:", $Strnspin[1] & " 更新成功!!!")
EndFunc ;==>up
Func sx($tabname)
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.Open("Select " & $T & " From " & $tabmain & " where name = '" & $tabname & "'")
$temp = StringStripWS($RS.Fields(2).value, 2)
$arr = StringSplit($temp, ",")
$w = $arr[0]
Dim $k, $m
For $i = 1 To $w
$y = StringSplit($arr[$i], " ")
$k = $k & $y[1] & ","
$m = $m & GUICtrlRead($ninput[$i - 1]) & "','"
Next
;MsgBox(0,"","insert into "& $tabname &" ("& StringTrimRight ( $k,1) &") values('"& StringTrimRight ( $m,3) &"')")
$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("insert into " & $tabname & " (" & StringTrimRight($k, 1) & ") values('" & StringTrimRight($m, 3) & "')")
$addfld.close
MsgBox(4096, "提示:", " 成功写入数据库!")
EndFunc ;==>sx
Func read_tabmain()
GUICtrlSendMsg($ListView0, $LVM_DELETEALLITEMS, 0, 0) ;向指定控件发送消息
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.Open("Select * from tabmain")
While Not $RS.eof And Not $RS.bof
If @error = 1 Then ExitLoop
GUICtrlCreateListViewItem($RS.Fields(0).value & "|" & StringStripWS($RS.Fields(1).value, 2), $ListView0)
; MsgBox(0, "", $RS.Fields (1).value);显示表第一个数据
$RS.movenext
WEnd
$RS.close
$addfld.Close
EndFunc ;==>read_tabmain
Func data($mdb_data_path, $tabmain)
If Not FileExists($mdb_data_path) Then
$newMdb = ObjCreate("ADOX.Catalog")
$newMdb.Create("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
$newMdb.ActiveConnection.Close;建数据库
$addtbl = ObjCreate("ADODB.Connection")
$addtbl.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
$addtbl.Execute("CREATE TABLE " & $tabmain)
$addtbl.Close;建表
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
$addfld.Execute("ALTER TABLE " & $tabmain & " ADD id identity(1, 1) primary key,name char,zdnameandtype char");id identity(1, 1) primary key为自动编号和主键
$addfld.Close;建列表名
MsgBox(64, "提示", "建立数据库成功", 5)
Else
MsgBox(64, "提示", "你已经建立了一个数据库了", 5)
EndIf
EndFunc ;==>data
Func newtable($mdb_data_path, $tblname, $zdnameandtype)
$addtbl = ObjCreate("ADODB.Connection")
$addtbl.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
;添加表之前查一下是否表明存在
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addtbl
$RS.Open("select * from tabmain where name = '" & $tblname & "'")
If Not $RS.eof And Not $RS.bof Then
MsgBox(0, "提示", "新建失败,改表明已存在!")
Else
$addtbl.Execute("CREATE TABLE " & $tblname)
$addtbl.Close;建表
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
$addfld.Execute("ALTER TABLE " & $tblname & " ADD id identity(1, 1) primary key," & $zdnameandtype) ;id identity(1, 1) primary key为自动编号和主键
$addfld.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("insert into tabmain (name,zdnameandtype) values('" & $tblname & "','" & $zdnameandtype & "')")
$addfld.close;新建的表放到该表中
EndIf
EndFunc ;==>newtable
Func _SkinGUI($SkincrafterDll, $SkincrafterSkin, $Handle)
$Dll = DllOpen($SkincrafterDll)
DllCall($Dll, "int:cdecl", "InitLicenKeys", "wstr", "1", "wstr", "", "wstr", "1@1.com", "wstr", "1")
DllCall($Dll, "int:cdecl", "InitDecoration", "int", 1)
DllCall($Dll, "int:cdecl", "LoadSkinFromFile", "wstr", $SkincrafterSkin)
DllCall($Dll, "int:cdecl", "DecorateAs", "int", $Handle, "int", 25)
DllCall($Dll, "int:cdecl", "ApplySkin")
EndFunc ;==>_SkinGUI
Func Quit()
GUISetState(@SW_HIDE)
DllCall($Dll, "int:cdecl", "DeInitDecoration")
DllCall($Dll, "int:cdecl", "RemoveSkin")
DllClose($Dll)
;DirRemove(@AppDataDir&"\skin",1)
Exit
EndFunc ;==>Quit
研究了一下,未找到原因,提示第319行“$addfld.Execute("ALTER TABLE " & $tblname & " ADD id identity(1, 1) primary key," & $zdnameandtype) ;id identity(1, 1) ”这行出错,请高手帮助解决下!