lotus notes 開發中BS下實現組合查詢的方法

          在進行系統設計的時候用戶要求對各文件能夠實現組合條件的查詢和統計,開發之初我選擇了notes自身提供的綜合查詢表單$$Search Form來實現,但在用戶使用了一段時間發現,采用$$Search Form來進行組合條件查詢時常常會搜索到許多并不滿足條件的文檔或者搜索到的文檔根本就不知道是什么,為了解決這個問題,我決定寫代碼來實現組合條件查詢,下面就來講講實現的過程。   首先建立一個表單(Fsearch),主要用來現實和選擇查詢條件,表單的域元素如下表所示:

          編號
           域名
           含義
           類型
           說明
           
          01
           SaveOptions
           防止使用該表單創建文檔
           文本域
           該域是系統域當值為”0”的時候當前表單不會創建文檔,因為這里使用該表單僅僅是為了選擇查詢條件,不需要創建文檔,所以該域的值為“0”
           
          02
           biaoti
           發文標題
           文本域
            
          03
           zhutici
           主題詞
           文本域
            
          04
           laiwenhao
           發文號
           文本域
            
          05
           nigaoren
           擬稿人
           文本域
            
          06
           danwei
           擬稿人單位
           文本域
            
          07
           syear
           文檔所屬年度
           文本域
            
          08
           smonth
           文檔所屬月份
           文本域
            

          在表單上按照用戶要求和使用習慣利用表格布局好上述元素后,在表單上創建一個熱點按鈕“現在查找“,執行@Command([ToolsRunMacro];"(wFaWenSearch)") 的公式命令,其中wFaWenSearch 是一個共享代理,代碼如下:Sub Initialize    ‘//定義變量 Dim session As New NotesSession Dim cDoc As NotesDocument Dim db As NotesDatabase Dim sResult , Set sResultemp  As NotesDocumentCollection Dim sql As String   Set db=session.currentDatabase  ‘//獲得當前數據庫 Set cDoc=session.DocumentContext() ‘//獲得當前文檔,即用戶打開的選擇條件的表單Fsearch Set view=db.getView("($UNID)") ‘//獲得($UNID)視圖,該視圖里現實所有文件 ‘//============獲取查詢條件=========// sYear=cDoc.syear(0) sMonth=cDoc.smonth(0) biaoti=cDoc.biaoti(0) zhutici=cDoc.zhutici(0)  laiwenhao=cDoc.laiwenhao(0) danwei=cDoc.danwei(0) nigaoren=cDoc.nigaoren(0)  ‘//================END================//‘//=====組合查詢條件======//sql="form=""fwmain"""+"&(@Contains(biaoti;"""+biaoti+""")"+"|@Contains(zhutici;"""+zhutici''>|@Contains(zhutici;"""+zhutici+""")"+_"|@Contains(t1+""[""+@text(t2)+""]""+@text(t3''>|@Contains(t1+""[""+@text(t2)+""]""+@text(t3)+ ""號""+;"""+laiwenhao+""")"+"|@contains(danwei">|@contains(danwei; """+danwei+""")"+_"|@Contains(nigaoren;"""+nigaoren+""")"+"|@Contains(sYear;"""+sYear''>|@Contains(nigaoren;"""+nigaoren+""")"+"|@Contains(sYear;"""+sYear+""")"+"| @Contains(sMonth;"""+sMonth+"""))"Set  sResultemp= db.search(sql,Nothing,0)  ‘//在數據庫中搜索滿足上述條件的所有文檔,獲得該文檔集;但是由于使用search語法會把當前操’//作者沒有閱讀權限的文檔也搜索到,所以先把搜索到的文檔集賦予臨時變量sResultemp 再進行處理 Set  sResult=db.search("@Contains(sYear;''1'')",Nothing,0) ‘//初始化一個文檔集sResul,這文檔集中沒有文件的‘//========下面這循環主要是利用視圖對文檔讀者權限的限制功能把sResultemp====//‘//========這個文檔集中當前用戶有閱讀權限的文檔添加到文檔集sResul中去=====// For i=1 To  sResultemp.count  Set  sDoc=sResultemp.getNthDocument(i)  key=sDoc.bh(0)  Set  Sview=db.getView("default")  Set  sDoc=Sview.Getdocumentbykey(key,True)  If  Not  sDoc  Is  Nothing Then   Set  sDoctmp=sResult.Getdocument(sDoc)   If  sDoctmp Is  Nothing Then    Call sResult.Adddocument(sDoc)   End If  End If Next If  sResult.count=0  Then  Print "沒有找到您要查找的文件"  Exit Sub End  If  ''//=========創建網頁來顯示查詢結果=======// Print "<html>" Print "<head>" Print "<link rel=stylesheet type=text/css href=ViewCss.css>" Print "</script>" Print "</head>"Print "<body>" Print "<table width=100%>" Print "<tr>" Print "<td colspan=6 align=right style=border-style:solid;border-width:0 0 2px;border-color:#669933>查找到&nbsp;"+Cstr(jjj)+"&nbsp;份文件&nbsp;<br>" Print "</td>" Print "</tr>" Print "<tr>" Print "<td width=5% class=td1></td>" Print "<td width=10% class=td1>年度</td>" Print "<td width=10% class=td1>月份</td>" Print "<td width=40% class=td1>標題</td>" Print "<td width=20% class=td1>主辦部門</td>" Print "<td width=15% class=td1>擬稿人</td>" Print "</tr>" For i=1 To sResult.count  Set sDoc=sResult.getNthDocument(i)  Set sDoc=view.getDocumentByKey(sDoc.bh(0),True)  If Not sDoc Is Nothing Then      Print "<tr>"    Print "<td class=tdx><a href=/"+sDoc.DBPath(0)+"/merit_gwgl.nsf/($UNID)/"+sDoc.UniversalID+"?opendocument target=_blank><img src=01.gif border=0 ></a></td>"   Print "<td class=tdx>"+sDoc.sYear(0)+"</td>"   Print "<td class=tdx>"+sDoc.sMonth(0)+"</td>"   Print "<td class=tdx>"+sDoc.biaoti(0)+"</td>"   Print "<td class=tdx>"+sDoc.danwei(0)+"</td>"   Print "<td class=tdx>"+sDoc.nigaoren(0)+"</td>"   Print "</tr>"  End If Next Print "</table>"  Print "</body>" Print "</html>" End Sub

          posted on 2010-04-09 09:20 明高 閱讀(398) 評論(0)  編輯  收藏 所屬分類: Lotus

          <2010年4月>
          28293031123
          45678910
          11121314151617
          18192021222324
          2526272829301
          2345678

          導航

          統計

          常用鏈接

          留言簿

          隨筆分類

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 双柏县| 富裕县| 南宁市| 黄龙县| 凯里市| 凤阳县| 聂拉木县| 平度市| 疏附县| 准格尔旗| 荥阳市| 灵宝市| 丰城市| 通渭县| 大宁县| 黄龙县| 金昌市| 大竹县| 吉安市| 普宁市| 嘉定区| 安多县| 德保县| 台安县| 花莲县| 会昌县| 格尔木市| 彭州市| 太仆寺旗| 壤塘县| 呼和浩特市| 上杭县| 个旧市| 哈巴河县| 芜湖县| 扶沟县| 保康县| 鹤庆县| 北京市| 板桥市| 堆龙德庆县|