在PB中如何實現數據模糊查詢(五)
9.5 DataWindow: dw_where的 ue_where 事件
功能:形成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
0條評論