• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

在PB中如何实现数据模糊查询(五)

发布: 2008-2-22 16:06 | 作者: 张爱生  | 来源: tech.ddvip.com | 查看: 73次 | 进入软件测试论坛讨论

领测软件测试网 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
    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/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网