局域网图书资料查询系统
图5-5 组合(条件)查询窗口
控件:dw_2 事件(event):Itemchanged Script of Itemchanged
string item,status,edit,result,modify_string,cur_string,c,operator1this.accepttext()
choose case dwo.name case'column_name' item=dw_2.getitemstring(dw_2.getrow()
,'column_name')//根据查询项目改变操作符的显示If item='publishing_date' or item=
'buy_date' then dw_2.setrow(dw_2.getrow()) dw_2.setitem(row,'content','') dw_2
.setvalue('operator',1,'等于~t=') dw_2.setvalue('operator',2,'不等于~t<>') dw_2.
setvalue('operator',3,'小于~t<') dw_2.setvalue('operator',4,'大于~t>') dw_2.
SetValue('operator', 5, '小于等于~t<=') dw_2.SetValue('operator', 6, '大于等于~t>=
') Status = dw_2.GetValue('operator',4)else dw_2.setrow(dw_2.getrow()) dw_2.
setitem(row,'content','') dw_2.setvalue('operator',1,'等于~t=') dw_2.setvalue(
'operator',2,'不等于~t<>') dw_2.SetValue('operator', 3, '包含~tlike') dw_2.
SetValue('operator', 4, '不包含~tnot') Status = dw_2.GetValue('operator',4)end
if//case 'operator'//防止操作符的显示改变 operator1=dw_2.getitemstring(dw_2.getrow()
,'operator') choose case operator1 case 'like' dw_2.setitem(dw_2.getrow()
,'operator','包含') case 'not' dw_2.setitem(dw_2.getrow(),'operator','不包含')end
chooseend choose
控件:pb_2 “插入” 事件(event):Clicked Script of Clicked
int row,new_row,istring queryrow=dw_2.getrow()//将当前行的行号赋值给变量//允许插入一
行的条件 if (isnull(dw_2.getitemstring(row,'column_name')) or & isnull(dw_2.
getitemstring(row,'operator')) or & isnull(dw_2.getitemstring(row,'content')) or &
isnull(dw_2.getitemstring(row,'join'))) then query='no' else query='yes' end if//如
果允许插入,则在当前行后插入一条新记录if query='yes' thennew_row=dw_2.insertrow(0
)////将光标定位在新的一行“资料名称”列dw_2.scrolltorow(new_row)dw_2.setrow(new_row)
dw_2.setcolumn(1)//else messagebox('警告',"请输入完整的查询条件",stopsign!)end if
控件:pb_3“删除” 事件(event):Clicked Script of Clicked
int row//如果当前行不为第一行,则允许删除if dw_2.getrow()<>1 then row=dw_2.getrow
()//将当前行行号赋值给变量 dw_2.deleterow(row)//删除当前行else returnend if
控件:pb_4“检索” 事件(event):Clicked Script of Clicked
Long row_count,rowstring new_condition,itemstring condition[100]
,column_name,operator,content,join,operator1int i//将当前行行号赋值给变量row=dw_2.
getrow()//将当前行列名赋值给变量column_name=dw_2.getitemstring(row,'column_name')//将
当前行操作符赋值给变量operator=dw_2.getitemstring(row,'operator')//将当前行查询内容赋
值给变量content=dw_2.getitemstring(row,'content')//将当前行连接符赋值给变量(and or)
join=dw_2.getitemstring(row,'join')//将查询条件窗口的空行删掉if row<>1 then if (
isnull(column_name) or & isnull(operator) or & isnull(content)) then dw_2.
deleterow(row) end if end if ////将查询条件窗口的总行数赋值给变量row_count=dw_2.
rowcount()//where后的表达式for i=1 to row_count item=dw_2.getitemstring(
i,'column_name') operator1=dw_2.getitemstring(i,'operator') choose case item//查询项
为字符型 case 'name','author','publishing_house','sort','isbn','keeper','memo' if
i<> row_count then//查询条件有多行时 choose case operator1 case 'not'//操作符为不
包含 condition[i]=dw_2.getitemstring(i,'column_name')+" "+& dw_2.
getitemstring(i,'operator')+" "+"like"+& "'"+'%'+dw_2.getitemstring(
i,'content')+'%'+"'"+dw_2.getitemstring(i,'join')+" " case 'like'//操作符为包含
condition[i]=dw_2.getitemstring(i,'column_name')+" "+& dw_2.
getitemstring(i,'operator')+" "+& "'"+'%'+dw_2.getitemstring(
i,'content')+'%'+"'"+dw_2.getitemstring(i,'join')+" " case '=','<>'//操作符为等于
或不等于 condition[i]=dw_2.getitemstring(i,'column_name')+" "+&
dw_2.getitemstring(i,'operator')+" "+& "'"+dw_2.getitemstring(
i,'content')+"'"+dw_2.getitemstring(i,'join')+" " end choose else//查询条件只有一
行 choose case operator1 case 'not'//操作符为不包含 condition[i]=dw_2.
getitemstring(i,'column_name')+" "+& dw_2.getitemstring(i,'operator')+"
"+"like"+& "'"+'%'+dw_2.getitemstring(i,'content')+'%'+"'" case
'like'//操作符为包含 condition[i]=dw_2.getitemstring(i,'column_name')+" "+&
dw_2.getitemstring(i,'operator')+" "+& "'"+'%'+dw_2.
getitemstring(i,'content')+'%'+"'" case '=','<>'//操作符为等于或不等于
condition[i]=dw_2.getitemstring(i,'column_name')+" "+& dw_2.
getitemstring(i,'operator')+" "+& "'"+dw_2.getitemstring(i,'content')
+"'" end choose end if//查询项为日期类型case 'publishing_date','buy_date' if i<>
row_count then//查询条件有多行时 condition[i]=item+" "+dw_2.getitemstring(
i,'operator')+" "+& "date('"+dw_2.getitemstring(i,'content')+"')"+dw_2.
getitemstring(i,'join')+" " else//查询条件只有一行 condition[i]=item+" "+dw_2.
getitemstring(i,'operator')+" "+& "date('"+dw_2.getitemstring(
i,'content')+"')" end ifend choosenext//最终的where后的表达式new_condition=''for i= 1
to row_count new_condition=new_condition+condition[i]nextold_sql1=dw_1.getsqlselect
()new_sql1=old_sql1+ " where " + new_condition//对原有数据窗口进行新的查询 dw_1.
reset()if dw_1.setsqlselect(new_sql1) = -1 then beep(3) messagebox("警告", "检
索失败",stopsign!) else dw_1.settransobject(sqlca) dw_1.retrieve() dw_1
.setsqlselect(old_sql1) end if
5.3.3 更新打印模块实现
图5-6 更新打印窗口
控件:pb_7“修改” 事件(event):Clicked Script of Clicked
file://取消亮条显示一行,便于进行编辑dw_1.selectrow(dw_1.getrow(),false)//将数据窗口
属性设为可以修改dw_1.Object.DataWindow.ReadOnly="no"dw_1.settransobject(sqlca)//将焦
点设置在数据窗口控件上dw_1.setfocus()//触发dw_1的Getfocus事件dw_1.TriggerEvent(
Getfocus!)//将插入、删除、存盘、打印按钮全部设为可以使用pb_8.enabled = truepb_9.
enabled = truepb_10.enabled = truepb_11.enabled = true//
控件:pb_8“插入” 事件(event):Clicked Script of Clicked
string statuslong row//在当前行后插入一行dw_1.ScrollToRow (dw_1.insertrow(dw_1.
getrow()))//设置焦点在数据窗口dw_1.setfocus()//触发数据窗口事件dw_1.TriggerEvent(
Getfocus!)
控件:pb_9“删除” 事件(event):Clicked Script of Clicked
int answer//将当前行亮条显示dw_1.selectrow(dw_1.getrow(),true)answer=messagebox("提示
!","确实删除此记录?",Question!,YesNoCancel!)choose case answer case 1 file://删
除当前记录 dw_1.deleterow(dw_1.getrow()) file://触发dw_1的getfocus事件 dw_1.
triggerevent(getfocus!) case 2,3 file://取消当前行亮条显示 dw_1.selectrow(dw_1
.getrow(),false) file://将光标定位在dw_1 dw_1.setfocus() file://触发dw_1的
getfocus事件 dw_1.TriggerEvent(Getfocus!)end choose
控件:pb_9“删除” 事件(event):Clicked Script of Clicked
int answerlong del_count// 将数据窗口删除记录标记值赋值给变量del_count=dw_1.
deletedcount()//判断数据窗口是否有记录标记为删除或者否有列被修改if (modifiedcount(
dw_1)<>0) or (del_count<>0) then//若数据窗口中记录被改动询问是否存盘 answer=
messagebox("提示!","是否存盘?",Question!,YesNoCancel!) choose case answer case 1if
dw_1.update()=1 then//如果数据窗口具有UPDATE属性 messagebox('提示','存盘成功!')
commit; end if case 2//数据窗口不具有UPDATE属性则回滚 rollback;
dw_1.ResetUpdate ( ) dw_1.reset()//清空数据窗口 dw_1.retrieve()//刷新数据窗口
dw_1.setfocus()//设置焦点在dw_1 dw_1.TriggerEvent(Getfocus!)//触发dw_1的
getfocus事件 case 3 dw_1.setfocus() dw_1.TriggerEvent(Getfocus!) end
chooseend if
控件:dw_1 事件(event):Getfocus Script of Getfocus
this.setrow(this.getrow())this.setcolumn('name')//设置当前列为“资料名称”this.
accepttext()
控件:dw_1 事件(event):Lostfocus Script of Lostfocus
file://在编辑状态,接收输入的字符this.accepttext()
控件:dw_1 事件(event): Clicked Script of Clicked
string cur_row//将当前行赋值给变量cur_row=string(dw_1.getclickedrow())//如果数据窗口
为只读、或至少有一条记录则亮条显示当前焦点所在记录if dw_1.object.datawindow.readonly
='yes' and cur_row<>'0' then dw_1.selectrow(getrow(),true)end if//
控件:dw_1 事件(event):Rowfocuschanged Script of rowfocuschanged
string cur_row//将鼠标单击选中的行号赋值给变量cur_row=string(dw_1.getclickedrow())//
数据窗口只读或当前行号不为零,则亮条显示选中记录if dw_1.object.datawindow.readonly=
'yes' and cur_row<>'0' then dw_1.selectrow(dw_1.getrow(),true)end if//
控件:dw_1 事件(event):Rowfocuschanging Script of rowfocuschanging
file://焦点改变时将旧焦点的亮条显示取消dw_1.selectrow(dw_1.getrow(),false)
控件:dw_1 事件(event):DoubleClicked Script of DoubleClicked
integer cur_row,sjstring new_sort,cur_column,cur_textif sj_check=0 then sj=0//表示按
升序排序else sj=1//表示按降序排序end if//取消当前行亮条显示dw_1.selectrow(dw_1.
getrow(),false)if sj=0 then cur_text=dwo.name//将当前双击对象名赋值给变量//表示只有
双击列标题才实现排序cur_column=left(cur_text,len(cur_text)-2)//去掉列标题的_t//按升序
排序 new_sort=string(cur_column)+' A' dw_1.setsort(new_sort) dw_1.sort()//
sj_check=1//再次双击变成降序排序else cur_text=dwo.name//将当前双击对象名赋值给变量//
表示只有双击列标题才实现排序 cur_column=left(cur_text,len(