本帖最后由 amxi 于 2011-11-21 20:00 编辑
上图为数据库表.
我想实现的是在combo中选择CPU型号,然后edit控件自动显示对应的价格,这个谁指点一下,我卡住了..谢谢
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.6.1
Author: myName
Script Function:
Template AutoIt script.
#ce ----------------------------------------------------------------------------
; Script Start - Add your code below here
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <windowsconstants.au3>
#include <comboconstants.au3>
$mdb_path=""
$mdb_name="da.mdb"
$mdb_pwd=""
;$mdb_table_name="MyPC"
$mdb_cpu_table="CPU"
$mdb_hdd_table="硬盘"
$mdb_mb_table="主板"
$mdb_nc_table="内存"
$star="*"
$nform=guicreate("price list of inner market",500,500)
$ListView1 = GUICtrlCreateListView(" 品名 | 价格 | 日期 ", 288, 24, 200, 161)
$nCPU=GUICtrlCreateLabel(" CPU",6,150,50,20)
$CPU_comb=GUICtrlCreateCombo(" CPU",60,150,120,20)
$cpu_price=GUICtrlCreateEdit(" ",190,150,80,20)
$nCPU=GUICtrlCreateLabel(" 主板 ",6,180,50,20)
$MB_comb=GUICtrlCreateCombo(" 主板 ",60,180,120,20)
$nCPU=GUICtrlCreateLabel(" 内存 ",6,210,50,20)
$NC_comb=GUICtrlCreateCombo(" 内存",60,210,120,20)
$nCPU=GUICtrlCreateLabel(" 硬盘 ",6,240,50,20)
$HDD_comb=GUICtrlCreateCombo(" ",60,240,120,20)
_getcpu()
_getmb()
_gethdd()
GUISetState(@sw_show)
while 1
$msg=GUIGetMsg()
Switch $msg
case $gui_event_close
Exit
case $button1
_getcpu()
case $button2
_read()
case $cpu_comb
$conn=objcreate("ADODB.Connection")
$rs=ObjCreate("ADODB.Recordset")
$conn.open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & $mdb_name & ";Jet Oledb:Database Password=" & $mdb_pwd)
$rs.Activeconnection=$conn
$rs.Open ("Select "&$star & " From " &$mdb_cpu_table )
while not $rs.eof and not $rs.bof
if @error then ExitLoop
GUICtrlSetData($cpu_price,$rs.fields(2).value)
$rs.movenext
WEnd
$rs.close
$conn.close
;MsgBox("",$rs.fields(2).value,$guictrlread($cpu_combo))
EndSwitch
WEnd
func _read()
GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)
$obj=ObjCreate("ADODB.Connection")
;连接数据库
$obj.open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &$mdb_name)
;打开数据库
$rs=ObjCreate("ADODB.Recordset")
; 建立记录
$rs.ActiveConnection =$obj
$rs.Open ("Select "&$star & " From " &$mdb_cpu_table)
while Not $RS.eof And Not $RS.bof
if @error then ExitLoop
;
GUICtrlCreateListViewItem( $rs.fields(1).value&"|"& $rs.fields(2).value ,$listview1)
$rs.movenext
WEnd
$rs.close
$obj.close
EndFunc
Func _GetCPU()
$conn=objcreate("ADODB.Connection")
$rs=ObjCreate("ADODB.Recordset")
$conn.open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & $mdb_name & ";Jet Oledb:Database Password=" & $mdb_pwd)
$rs.Activeconnection=$conn
$rs.Open ("Select "&$star & " From " &$mdb_cpu_table )
while not $rs.eof and not $rs.bof
if @error then ExitLoop
GUICtrlSetData($cpu_comb,$rs.fields(1).value)
$rs.movenext
WEnd
$rs.close
$conn.close
EndFunc
;func _getmb()
;endFunc
|