#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <GuiTab.au3>
#include <GuiButton.au3>
#include <Date.au3>
#include <DateTimeConstants.au3>
#include <ListViewConstants.au3>
#include <GuiImageList.au3>
#include <GuiMenu.au3>
Opt("GUIOnEventMode",1)
Opt('GUIResizeMode', 802)
Dim $databaseIp = '192.168.1.221', $databaseName = 'sa', $databasePwd ='abc123'
Global $nameEdit3,$nameEdit,$mainGUI,$mainGUIHeight,$mainGUIWidth,$addUserPage,$Conn,$userListView,$feesListView,$kaizhiListView,$goodsListView,$listViewLeft,$listViewTop,$listViewWidth,$listViewHeight
main()
Func main() ;主窗口
$mainGUI = GUICreate("技术部", 623, 442, 192, 124, BitOR($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_MAXIMIZE,$WS_TABSTOP))
$mainGUIWidth = WinGetPos($mainGUI)[2] ;获取宽度
$mainGUIHeight = WinGetPos($mainGUI)[3] ;获取高度
$listViewLeft=7
$listViewTop=45
$listViewWidth=$mainGUIWidth-22
$listViewHeight=$mainGUIHeight-85
GUICtrlCreateTab(0,0,$mainGUIWidth-10,$mainGUIHeight-35)
$searchButton=GUICtrlCreateButton("搜索", 10, 23,100,20,$WS_MAXIMIZEBOX)
$searchButton1=GUICtrlCreateButton("删除", 110, 23,100,20,$WS_MAXIMIZEBOX)
GUICtrlCreateTabItem("人员")
$userListView = GUICtrlCreateListView('编号|名字|年龄|性别|职位|名族|学历|婚姻状态|籍贯|毕业院校|生分证号码|联系电话',$listViewLeft,$listViewTop,$listViewWidth,$listViewHeight)
_GUICtrlListView_SetExtendedListViewStyle($userListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
Local $buttoncontext = GUICtrlCreateContextMenu($userListView)
Local $addUserBut = GUICtrlCreateMenuItem("添加员工", $buttoncontext)
GUICtrlSetOnEvent($addUserBut,"addUserInfoPage") ;(添加按钮的)右键关联菜单
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; 显示 GUI 之前注册 WM_DRAWITEM, 否则初始绘制不能完成,(双击事件)
Local $addUserBut1 = GUICtrlCreateMenuItem("修改信息", $buttoncontext)
GUICtrlSetOnEvent($addUserBut1, "upUserdo"); 修改信息的右键关联菜单
Local $addUserBut2 = GUICtrlCreateMenuItem("删除员工", $buttoncontext)
GUICtrlSetOnEvent($addUserBut2, "_delUserDo");删除按钮的右键关联菜单
GUICtrlCreateTabItem("物品管理")
$userListView1 = GUICtrlCreateListView('领用人|物品名字|数量|领用时间',$listViewLeft,$listViewTop,$listViewWidth,$listViewHeight)
_GUICtrlListView_SetExtendedListViewStyle($userListView1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUICtrlCreateTabItem("开支管理")
$userListView2 = GUICtrlCreateListView('部门|提交人|数额|审核人',$listViewLeft,$listViewTop,$listViewWidth,$listViewHeight)
_GUICtrlListView_SetExtendedListViewStyle($userListView2, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUISetOnEvent($GUI_EVENT_CLOSE, "_GUICloseEvent")
GUISetState(@SW_SHOW)
test()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE ; 循环,直到用户关闭。
EndFunc
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)
$Event = DllStructGetData($tagNMHDR, 3)
$tagNMHDR = 0
Switch $IDFrom;选择产生事件的控件
Case $userListView
Switch $Event; 选择产生的事件
Case $NM_CLICK ; 左击
;~ ...
Case $NM_DBLCLK ; 双击
$Index = _GUICtrlListView_GetSelectedIndices($userListView)
If Not StringLen($Index) Then; 这里用以判断是否选定了ListViewItem
MsgBox(64,"没有选中数据","请重新选择")
Return
EndIf
$a = _GUICtrlListView_GetSelectedIndices($userListView)
$b = _GUICtrlListView_GetItemTextString($userListView, Number($a))
$chaifen = StringSplit($b, "|")
MsgBox(0, '第' & $index & '行数据如下:', "编号:" & $chaifen[1] & @CRLF & @CRLF & "名字:" & $chaifen[2]& @CRLF & @CRLF & "年龄:" & $chaifen[3]& @CRLF & @CRLF & "性别:" & $chaifen[4]& @CRLF & @CRLF & "职位:" & $chaifen[5]& @CRLF & @CRLF & "名族:" & $chaifen[6]& @CRLF & @CRLF & "学历:" & $chaifen[7]& @CRLF & @CRLF & "婚姻状态:" & $chaifen[8]& @CRLF & @CRLF & "籍贯:" & $chaifen[9]& @CRLF & @CRLF & "毕业院校:" & $chaifen[10]& @CRLF & @CRLF & "身份证号码:" & $chaifen[11]& @CRLF & @CRLF & "联系电话:" & $chaifen[12])
Case $NM_RCLICK ; 右击
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func test() ;连接数据库并返回内容
_databaseOpen() ;连接数据库
_GUICtrlListView_DeleteAllItems($userListView); 移除全部listview
$RS = ObjCreate("ADODB.Recordset");创建记录集对象
$RS.ActiveConnection= $Conn;设置记录集的激活链接属性来自$Conn
$RS.Open("Select * from aaa");执行Sql语句,查询名为aaa的表
While (Not $RS.eof And Not $RS.bof)
GUICtrlCreateListViewItem($RS.Fields("id").Value & "|" & $RS.Fields("name").Value & "|" & $RS.Fields("age").Value & "|" & $RS.Fields("sex").Value & "|" & $RS.Fields("zhiwei").Value & "|" & $RS.Fields("mz").Value & "|" & $RS.Fields("xl").Value & "|" & $RS.Fields("hy").Value & "|" & $RS.Fields("jg").Value & "|" & $RS.Fields("byyx").Value & "|" & $RS.Fields("sfzhm").Value & "|" & $RS.Fields("lxdh").Value,$userListView)
$RS.movenext
WEnd
_databaseclose()
EndFunc
Func _databaseclose() ;关闭数据库 (操作完数据库后加上)
$Conn.close()
EndFunc
Func _databaseOpen() ;连接数据库
$Conn=ObjCreate("ADODB.Connection")
$Conn.open("DRIVER={SQL Server};SERVER="& $databaseIp & ";UID="& $databaseName & ";PWD="& $databasePwd & ";")
$Conn.Execute("use test1")
EndFunc
Func _GUICloseEvent() ; 结束
Switch @GUI_CtrlId;根据宏@GUI_CtrlId来判断消息
Case $GUI_EVENT_CLOSE
Switch @GUI_WinHandle;根据宏@GUI_WinHandle来判断产生关闭消息的窗口消息
Case $mainGUI
Exit
Case $addUserPage
GUIDelete($addUserPage)
EndSwitch
EndSwitch
EndFunc
Func addUserInfoPage() ;右键弹出框(添加员工的)
$addUserPage=GUICreate("添加员工:", 800, 400, -1,-1, -1, -1,$mainGUI)
GUISetOnEvent($GUI_EVENT_CLOSE,"_GUICloseEvent")
GUISetState()
GUICtrlCreateGroup("员工信息", 5, 5 ,790, 390)
GUICtrlCreateLabel("姓名:", 15, 30, 40, 20)
$nameEdit=GUICtrlCreateInput("", 60, 25, 115, 20)
GUICtrlCreateLabel("性别:", 225, 30, 40, 20)
Global $sexEdit = GUICtrlCreateCombo("", 275, 25, 115, 20)
GUICtrlSetData($sexEdit, "男|女", "男")
GUICtrlCreateLabel("民族:", 15, 70, 40, 20)
Global $mz = GUICtrlCreateCombo("", 60, 65, 115, 20)
GUICtrlSetData($mz, "汉族|藏族", "汉族")
GUICtrlCreateLabel("籍贯:", 225, 70, 40, 20)
Global $jg = GUICtrlCreateCombo("", 275, 65, 115, 20)
GUICtrlSetData($jg, "成都|莆田", "成都")
GUICtrlCreateLabel("婚姻:", 15, 110, 40, 20)
Global $hy = GUICtrlCreateCombo("", 60, 105, 115, 20)
GUICtrlSetData($hy, "已婚|未婚", "未婚")
GUICtrlCreateLabel("学历:", 225, 110, 40, 20)
Global $xl = GUICtrlCreateCombo("", 275, 105, 115, 20)
GUICtrlSetData($xl, "小学|中学|大学", "大学")
GUICtrlCreateLabel("毕业院校:", 10, 155, 60, 20)
Global $byyx=GUICtrlCreateInput("", 80, 150, 280, 20)
GUICtrlCreateLabel("身份证号码:", 10, 195, 80, 20)
Global $sfzhm=GUICtrlCreateInput("", 80, 190, 280, 20)
GUICtrlCreateLabel("联系电话:", 10, 235, 60, 20)
Global $lxdh=GUICtrlCreateInput("", 80, 230, 280, 20)
GUICtrlCreateLabel("职位:", 10, 275, 60, 20)
Global $nameEdit4=GUICtrlCreateInput("", 80, 270, 100, 20)
GUICtrlCreateLabel("年龄:", 225,275, 40, 20)
Global $age = GUICtrlCreateInput("", 275, 270 ,115, 20)
GUICtrlCreateEdit("",400,25,390,265)
$addButton=GUICtrlCreateButton("添加员工", 250, 330,300,50)
GUICtrlSetOnEvent($addButton,"addUserInfoDo") ; 关联到下面的添加函数
EndFunc
Func addUserInfoDo() ; 添加到数据库
_databaseOpen()
$conn.Execute("insert into aaa (name,sex,mz,jg,hy,xl,byyx,sfzhm,lxdh,zhiwei,age) values ('" & GUICtrlRead($nameEdit) & "','" & GUICtrlRead($sexEdit) & "','" & GUICtrlRead($mz) & "','" & GUICtrlRead($jg) & "','" & GUICtrlRead($hy) & "','" & GUICtrlRead($xl) & "','" & GUICtrlRead($byyx) & "','" & GUICtrlRead($sfzhm) & "','" & GUICtrlRead($lxdh) & "','" & GUICtrlRead($nameEdit4) & "','" & GUICtrlRead($age) & "')")
test()
GUIDelete($addUserPage)
EndFunc
Func upUser() ;修改信息的右键弹出框
$addUserPage=GUICreate("修改信息:", 800, 400, -1,-1, -1, -1,$mainGUI)
GUISetOnEvent($GUI_EVENT_CLOSE,"_GUICloseEvent")
GUISetState()
GUICtrlCreateGroup("员工信息", 5, 5 ,790, 390)
GUICtrlCreateLabel("姓名:", 15, 30, 40, 20)
$nameEdit=GUICtrlCreateInput("", 60, 25, 115, 20)
GUICtrlCreateLabel("性别:", 225, 30, 40, 20)
Global $sexEdit = GUICtrlCreateCombo("", 275, 25, 115, 20)
GUICtrlSetData($sexEdit, "男|女", "男")
GUICtrlCreateLabel("民族:", 15, 70, 40, 20)
Global $mz = GUICtrlCreateCombo("", 60, 65, 115, 20)
GUICtrlSetData($mz, "汉族|藏族", "汉族")
GUICtrlCreateLabel("籍贯:", 225, 70, 40, 20)
Global $jg = GUICtrlCreateCombo("", 275, 65, 115, 20)
GUICtrlSetData($jg, "成都|莆田", "成都")
GUICtrlCreateLabel("婚姻:", 15, 110, 40, 20)
Global $hy = GUICtrlCreateCombo("", 60, 105, 115, 20)
GUICtrlSetData($hy, "已婚|未婚", "未婚")
GUICtrlCreateLabel("学历:", 225, 110, 40, 20)
Global $xl = GUICtrlCreateCombo("", 275, 105, 115, 20)
GUICtrlSetData($xl, "小学|中学|大学", "大学")
GUICtrlCreateLabel("毕业院校:", 10, 155, 60, 20)
Global $byyx=GUICtrlCreateInput("", 80, 150, 280, 20)
GUICtrlCreateLabel("身份证号码:", 10, 195, 80, 20)
Global $sfzhm=GUICtrlCreateInput("", 80, 190, 280, 20)
GUICtrlCreateLabel("联系电话:", 10, 235, 60, 20)
Global $lxdh=GUICtrlCreateInput("", 80, 230, 280, 20)
GUICtrlCreateLabel("职位:", 10, 275, 60, 20)
Global $nameEdit4=GUICtrlCreateInput("", 80, 270, 100, 20)
GUICtrlCreateLabel("年龄:", 225,275, 40, 20)
Global $age = GUICtrlCreateInput("", 275, 270 ,115, 20)
GUICtrlCreateEdit("",400,25,390,265)
$addButton=GUICtrlCreateButton("修改信息", 250, 330,300,50)
GUICtrlSetOnEvent($addButton,"upUserdo") ; 关联到下面的修改函数
EndFunc
Func upUserdo() ;修改信息
_databaseOpen()
Local $id=_GUICtrlListView_GetItemText($userListView,_GUICtrlListView_GetSelectionMark ($userListView),0)
If $id < 1 Then
MsgBox(64,"错误","请选择需要修改的信息")
Return
EndIf
_databaseclose()
test()
EndFunc
Func _delUserDo() ;删除员工
_databaseOpen()
Local $id=_GUICtrlListView_GetItemText($userListView,_GUICtrlListView_GetSelectionMark ($userListView),0)
If $id < 1 Then
MsgBox(64,"错误","请选择需要删除员工")
Else
MsgBox(0,"删除员工","确定删除" & $id & _GUICtrlListView_GetItemText($userListView,_GUICtrlListView_GetSelectionMark ($userListView),1))
EndIf
$sql="delete from aaa where id='"& $id & "'"
$Conn.Execute($sql)
_databaseclose()
test()
EndFunc
求教怎么把查询到的资料填充到弹出的GUI窗口里面。