功能:形成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_countoclearcase/" target="_blank" >ccurrences(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")