GoTodelerror
answer=MsgBox("确定要删除吗?",vbYesNo,"")
Ifanswer=vbYesThen
rs_loupan.MoveFirst
DimiAsInteger
Fori=0Tors_loupan.RecordCount-1
IfTrim(rs_loupan.Fields(0))=Trim(txtnum.Text)Then
rs_loupan.Delete
rs_loupan.Update
MsgBox"删除成功!",vbOKOnly+vbExclamation,""
WithgrdLoupan
.RemoveItemgetrow
EndWith
ExitSub
EndIf
rs_loupan.MoveNext
Nexti
Else
ExitSub
EndIf
ExitSub
delerror:
MsgBoxErr.Description
EndSub
(4)"退出"按钮的"Click"事件代码
PrivateSubcmdexit_Click()
UnloadMe
EndSub
4.3.3建立户型查询窗体(frmBuildingstyleFind)
主要用来对户型资料进行查询。在查询条件中选择某一种查询方式,然后输入查询的关键字,即可按照要求找出符合条件的数据,并在下面的列表中显示结果。
1、界面设计
添加一个窗体,在窗体上放置1个Frame控件、2个Label控件、3个CommandButton控件、1个ComboBox控件和3个OptionButton控件。设置完成以后的窗体如图7所示。
图7"户型查询"窗体效果图
2、工作流程
窗体加载时在表格中显示所有的数据。在查询条件部分选择某一种查询方式,然后输入查询的关键字,再单击'查询'按钮,开始执行查询,将查询的结果在表格中显示出来。
3、添加代码
绑定菜单、加载窗体、显示表格、卸载窗体等部分的代码和户型登记部分的都相似,下面主要介绍查询功能的实现。
(1)双击"查询"按钮,添加代码以实现查询的功能。
首先通过单选按钮控件Value值判断所选择的查询条件,然后对不同的查询条件使用不同的SQL语句。根据户型编号查询的代码如下:
PrivateSubcmdfind_Click()
GoTofinderror
DimsqlAsString
grdHuxing.Clear'显示查询结果前将表格中原有记录清除
IfOption1.Value=TrueThen'选择户型编号作为查询条件
sql="select*from户型资料表whereHst_ID='"&Trim(txthuxingnum.Text)&"'"
rs_huxing.CursorLocation=adUseClient
rs_huxing.Opensql,conn,adOpenKeyset,adLockPessimistic
setgrid
setgridhead
displaygrid
rs_huxing.Close
ExitSub
EndIf
IfOption2.Value=TrueThen'选择建筑面积作为查询条件
sql="select*from户型资料表whereHst_buildareabetween"&CInt(Trim(txtmianji1.Text))&"and"&CInt(Trim(txtmianji2.Text))
rs_huxing.CursorLocation=adUseClient
rs_huxing.Opensql,conn,adOpenKeyset,adLockPessimistic
setgrid
setgridhead
displaygrid
rs_huxing.Close
ExitSub
EndIf
IfOption3.Value=TrueThen'选择户型结构作为查询条件
sql="select*from户型资料表whereHst_type='"&Trim(Combo1.Text)&"'"
rs_huxing.CursorLocation=adUseClient
rs_huxing.Opensql,conn,adOpenKeyset,adLockPessimistic
setgrid
setgridhead
displaygrid
rs_huxing.Close
ExitSub
EndIf
ExitSub
finderror:
MsgBoxErr.Description
EndSub
(2)当用户单击"全部"按钮时,表格显示所有的户型信息,这和窗体加载时的情况是一样的,所以直接调用Form_Load事件就可以了。
PrivateSubcmdall_Click()
DimsqlAsString
sql="select*from户型资料表"
rs_huxing.CursorLocation=adUseClient
rs_huxing.Opensql,conn,adOpenKeyset,adLockPessimistic
Combo1.AddItem"二室二厅"
Combo1.AddItem"一室二厅"
Combo1.AddItem"一室二厅"
Combo1.AddItem"复式"
Combo1.AddItem"三室二厅"
setgrid
setgridhead
displaygrid
rs_huxing.Close
EndSub
4.3.4建立楼盘查询窗体(frmBuildingFind)
本窗体主要用来对楼盘资料进行查询。在查询条件中选择某一种查询方式,然后输入查询的关键字,即可按照要求找出符合条件的数据,并在下面的列表中显示结果。
1、界面设计
在工程中添加一个窗体,将其命名为frmBuildingFind。在这个窗体中添加1个Frame控件、1个Label控件、5个Text控件、3个CommandButton控件、1个ComboBox控件个5个Option控件。设置完成的frmBuildingFind窗口如图8所示。
图8"楼盘查询"窗体效果图
2、工作流程
窗体加载时在表格控件中显示所有的数据。在查询条件部分选择某一种查询方式,然后输入查询的关键字,再单击"查询"按钮,开始执行查询,查询的结果将在表格中显示出来。
3、添加代码
OptionExplicit
Dimrs_huxingAsNewADODB.Recordset'户型
Dimrs_loupanAsNewADODB.Recordset'楼盘
(1)"查询"按钮的"Click"事件代码:
PrivateSubcmdfind_Click()
DimsqlAsString
GoToloaderror
grdLoupan.Clear
IfOptionnum.Value=TrueThen
sql="select楼盘资料表.hos_id,楼盘资料表.hos_hstid,楼盘资料表.hos_price,"&_
"户型资料表.Hst_ID,户型资料表.Hst_buildarea,户型资料表.Hst_usearea,户型资料表.Hst_type,"&_
"户型资料表.Hst_memo,户型资料表.Hst_picturefrom楼盘资料表,户型资料表where楼盘资料表.hos_hstid=户型资料表.Hst_ID"&_
"and楼盘资料表.hos_id='"&txtnum.Text&"'"
rs_loupan.CursorLocation=adUseClient
rs_loupan.Opensql,conn,adOpenKeyset,adLockPessimistic'打开数据库
setgrid
setgridhead
displaygrid
rs_loupan.Close
ExitSub
EndIf
'按照楼号查询
IfOptionlouhao.Value=TrueThen
sql="select楼盘资料表.hos_id,楼盘资料表.hos_hstid,楼盘资料表.hos_price,"&_
"户型资料表.Hst_ID,户型资料表.Hst_buildarea,户型资料表.Hst_usearea,户型资料表.Hst_type,"&_
"户型资料表.Hst_memo,户型资料表.Hst_picturefrom楼盘资料表,户型资料表where楼盘资料表.hos_hstid=户型资料表.Hst_ID"&_
"and楼盘资料表.hos_idlike'"&Trim(txtlouhao.Text)&"%'"
rs_loupan.CursorLocation=adUseClient
rs_loupan.Opensql,conn,adOpenKeyset,adLockPessimistic'打开数据库
setgrid
setgridhead
displaygrid
rs_loupan.Close
ExitSub
EndIf
'按照楼层查询
IfOptionlouceng.Value=TrueThen
sql="select楼盘资料表.hos_id,楼盘资料表.hos_hstid,楼盘资料表.hos_price,"&_
"户型资料表.Hst_ID,户型资料表.Hst_buildarea,户型资料表.Hst_usearea,户型资料表.Hst_type,"&_
"户型资料表.Hst_memo,户型资料表.Hst_picturefrom楼盘资料表,户型资料表where楼盘资料表.hos_hstid=户型资料表.Hst_ID"&_
"and楼盘资料表.hos_idlike'____"&Trim(txtlouceng.Text)&"__'"
rs_loupan.CursorLocation=adUseClient
rs_loupan.Opensql,conn,adOpenKeyset,adLockPessimistic'打开数据库
DimaAsInteger
a=rs_loupan.RecordCount
setgrid
setgridhead
displaygrid
rs_loupan.Close
ExitSub
EndIf
'按照单位报价查询
IfOptionpri.Value=TrueThen
sql="select楼盘资料表.hos_id,楼盘资料表.hos_hstid,楼盘资料表.hos_price,"&_
"户型资料表.Hst_ID,户型资料表.Hst_buildarea,户型资料表.Hst_usearea,户型资料表.Hst_type,"&_
"户型资料表.Hst_memo,户型资料表.Hst_picturefrom楼盘资料表,户型资料表where楼盘资料表.hos_hstid=户型资料表.Hst_ID"&_
"and楼盘资料表.hos_pricebetween"&CCur(Trim(txtpri1.Text))&"and"&CCur(Trim(txtpri2.Text))
rs_loupan.
上一篇:
VBACCTI电话语音应答系统(论文和程序)
下一篇:
骨科病房开展优质护理服务的措施与体会