功能:形成WHERE子句,并更新语法框。
string hzcol, ywcol, sValue, sType //, sWhere
//sWhere 现为实例变量,在wroot_query中为局部变量.
string sOper, sLog, sLeft_kh,sRight_kh, tmpsValue
long left_kh,right_kh //左、右括号数
integer i, rownum, delnum //, typenum
dwItemStatus l_status
if ib_changed = true then
ib_changed = false
else
return 0
end if
rownum = dw_where.RowCount()
//去掉dw_where中MaxEditRow行以前所有中间为空或
//者输入不完整的行, 并更新MaxEditRow.
i = 1
delnum = 0
DO WHILE i <= MaxEditRow
l_status = dw_where.GetItemStatus(i,0, Primary!)
if l_status <> New! then
hzcol = GetItemString(i,"column1")
sValue = GetItemString(i,"value")
if (hzcol = "" or isnull(hzcol)) or (sValue = "" or isnull(sValue)) then
dw_where.DeleteRow(i)
delnum += 1
MaxEditRow += -1
Continue
end if
else
dw_where.DeleteRow(i)
delnum += 1
MaxEditRow += -1
Continue
end if
i += 1
LOOP
For i = 1 to DelNum
dw_where.InsertRow(0)
Next
//检查左右括号是否匹配, 即其数量是否一样多.
For i = 1 to MaxEditRow
l_status = dw_where.GetItemStatus(i,0, Primary!)
if l_status <> New! then
left_kh += inv_string.of_countoccurrences(GetItemString(i,"precol"),"(")
right_kh += inv_string.of_countoccurrences(GetItemString(i,"value"),")")
end if
Next
i = left_kh - right_kh
if i <> 0 then
if i > 0 then
sValue = "查询条件中左括号比右括号多了" + String(i) + "个"
else
sValue = "查询条件中左括号比右括号少了" + String(-i) + "个"
end if
if MessageBox("综合查询输入错误",sValue + ",请改正;" + &
"~r~n~r~n否则,所有查询条件将被忽略。",None!,OKCancel!,2)=1 then
return 1
else
dw_where.setfocus()
return 0
end if
end if
//形成WHERE子句,并更新语法框。
sWhere = ""
For i = 1 to MaxEditRow
hzcol = GetItemString(i,"column1")
sOper = space(1) + GetItemString(i,"operator") + space(1)
// 去掉空格键
sValue = Trim(GetItemString(i,"value"))
sLeft_kh = GetItemString(i,"precol") //保存左括号
if isNull(sLeft_kh) then sLeft_kh = ""
if Pos(sValue,")",1) > 0 then //保存右括号
sRight_kh = Right(sValue,(Len(sValue) - Pos(sValue,")",1) + 1))
else
sRight_kh = ""
end if
sValue = inv_string.of_globalreplace(sValue,"'","") //去掉sValue中的单引号.
sValue = inv_string.of_globalreplace(sValue,'"','') //去掉sValue中的双引号.
sValue = inv_string.of_globalreplace(sValue,")","") //去掉sValue中的右括号.
sLog = GetItemString(i,"logical")
if sLog = "" or isNull(sLog) then
sLog = "and"
dw_where.SetItem(i,"logical","and")
end if
ywcol = wf_getYwName(hzcol) //表名.列名
sType = lower(wf_getYwType(hzcol))
CHOOSE CASE sType
CASE "char","character","string","nchar","nvarchar","varchar","time"
if trim(sOper) = "like" or trim(sOper) = "not like" then
sWhere += " (" + sLeft_kh + ywcol + sOper + "'%" + sValue + "%') " + sRight_kh + sLog
else
sWhere += " (" + sLeft_kh + ywcol + sOper + "'" + sValue + "') " + sRight_kh + sLog
end if
CASE "numeric","decimal","decimaln","dec","double","integer","int","smallint",&
"number","long","real","uint","ulong","unsignedint","unsignedinteger","unsignedlong"
if trim(sOper) = "like" or trim(sOper) = "not like" then
if MessageBox("提示信息",hzcol + "不是字符型,不能使用<含有>或<不含有>操作符," + &
"~r~n~r~n请改正; 否则,所有查询条件将被忽略。",None!,OKCancel!,2)=1 then
return 1
else
dw_where.setfocus()
return 0
end if
end if
if isNumber(sValue) then
sWhere += " (" + sLeft_kh + ywcol + sOper + sValue + ") " + sRight_kh + sLog
else
if MessageBox("综合查询输入错误",hzcol + "的值应为数字型,请改正;" + &
"~r~n~r~n否则,所有查询条件将被忽略。",None!,OKCancel!,2)=1 then
Return 1
else
dw_where.setfocus()
return 0
end if
end if
CASE "date","datetime","datetimn","smalldatetime","timestamp"
if trim(sOper) = "like" or trim(sOper) = "not like" then
if MessageBox("提示信息",hzcol + "不是字符型,不能使用<含有>或<不含有>操作符," + &
"~r~n~r~n请改正; 否则,所有查询条件将被忽略。",None!,OKCancel!,2)=1 then
return 1
else
dw_where.setfocus()
return 0
end if
end if
if sType = "date" then
if not isdate(sValue) then
if MessageBox("综合查询输入错误",hzcol + "的值应为日期型,请改正;" + &
"~r~n~r~n否则,所有查询条件将被忽略.",None!,OKCancel!,2)=1 then
Return 1
else
dw_where.setfocus()
return 0
end if
end if
sValue = wf_dateconvert(sValue)
sWhere += " (" + sLeft_kh + ywcol + sOper + "'" + sValue + "') " + sRight_kh + sLog
else
//datetime型的字段在sybase中转换为字符串的类型
sValue = wf_datetime(sValue)
if sValue = "error" then
if MessageBox("综合查询输入错误",hzcol + "的值应为日期时间型,请改正;" + &
"~r~n~r~n否则,所有查询条件将被忽略。",None!,OKCancel!,2)=1 then
Return 1
else
dw_where.setfocus()
return 0
end if
end if
sWhere += " (" + sLeft_kh + "convert(varchar(8),"+ywcol+",112)" + sOper + " '"+sValue+"') " + sRight_kh +
sLog
end if
CASE ELSE
beep(1)
MessageBox("综合查询",sType + "这个数据类型未在本模块中定义。")
Return 0
END CHOOSE
Next
//去掉最后一个逻辑符。
Long pok, pp
pp = 0
DO WHILE True
pok = pp
pp = Pos(sWhere, ")", pp + 1)
if pp = 0 then Exit
LOOP
if pok > 0 then sWhere = Trim(Left(sWhere, pok))
return 1
//最后一个逻辑符去掉结束.
//至此, 用户的WHERE语句部分已经形成完毕于sWhere中.
9.6 DataWindow: dw_where的 ue_mousemove 事件
功能:控制鼠标的移动。
string s_object
s_object = This.GetObjectAtPointer()
if left(s_object,5) = "value" then
MainWindow.SetMicroHelp("此时按鼠标右键可粘贴现有值")
else
MainWindow.SetMicroHelp("准备好")
end if
9.7 DataWindow: dw_where的ue_retrieve事件
功能:对数据窗口进行查询,详细请见代码。
// 如果数据窗口dw_result上并无ue_action_refresh事件,
// 则用户必须重载本事件,编写自己的脚本.
// 如:
// dw_result.retrieve()
//
// 或者如果数据窗口dw_result有retrieve参数,
// 则用户也必须重载本事件,编写自己的脚本.
// 如:
// string ls_id
// ls_id = ...
// dw_result.retrieve(ls_id)
dw_result.triggerevent("ue_action_refresh")
文章来源于领测软件测试网 https://www.ltesting.net/