2009年12月17日 星期四

巧妙的運用 AfterPositionChange 事件 來達到透過上一筆、下一筆來瀏覽RDB資料。

以下範例,是透過LSXODBC 將RDB 資料顯示在表單的表格中,且巧妙的使用AfterPositionChange 事件 來達到與一般設計介面一樣,在表單上使用「下一筆」、「上一筆」按鈕來輕鬆瀏覽RDB後端資料 ;可達到將AP資料完全存放在Oraclec或是其它可與Domino一起應用的資料庫軟體上,目前我是將他與Oracle一起應用。

Uselsx "*LSXODBC"
Dim con As ODBCConnection
Dim qry As ODBCQuery
Dim result As ODBCResultSet
Sub Postopen(Source As Notesuidocument)
  Set con = New ODBCConnection
  Set qry = New ODBCQuery
  Set result = New ODBCResultSet
  Set qry.Connection = con
  Set result.Query = qry
  On Event AfterFirstRow From result Call
  AfterPositionChange
  On Event AfterLastRow From result Call AfterPositionChange
  On Event AfterNextRow From result Call AfterPositionChange
  On Event AfterPrevRow From result Call AfterPositionChange
  con.ConnectTo("ATDB")
  qry.SQL = "SELECT * FROM STUDENTS ORDER BY LASTNAME"
  result.Execute
  If Not source.EditMode Then
    source.EditMode = True
  End If
  result.FirstRow
  Call source.FieldSetText("Student_No", _
  Cstr(result.GetValue("STUDENT_NO")))
  Call source.FieldSetText("FirstName", _
  result.GetValue("FIRSTNAME"))
  Call source.FieldSetText("LastName", _
  result.GetValue("LASTNAME"))
  Call source.FieldSetText("Address", _
  result.GetValue("ADDRESS"))
  Call source.FieldSetText("City", _
  result.GetValue("CITY"))
  Call source.FieldSetText("State", _
  result.GetValue("STATE"))
  Call source.FieldSetText("Zip", _
  result.GetValue("ZIP"))
  Call source.FieldSetText("Phone", _
  result.GetValue("PHONE"))
  Call source.FieldSetText("Cr_to_date", _
  Cstr(result.GetValue("CR_TO_DATE")))
End Sub
Sub Click(Source As Button)
REM Action to get the next row
  Dim workspace As New NotesUIWorkspace
  Dim uidoc As NotesUIDocument
  Set uidoc = workspace.CurrentDocument
  If Not result.IsEndOfData Then result.NextRow
  Call uidoc.FieldSetText("Student_No", _
  Cstr(result.GetValue("STUDENT_NO")))
  Call uidoc.FieldSetText("FirstName", _
  result.GetValue("FIRSTNAME"))
  Call uidoc.FieldSetText("LastName", _
  result.GetValue("LASTNAME"))
  Call uidoc.FieldSetText("Address", _
  result.GetValue("ADDRESS"))
  Call uidoc.FieldSetText("City", result.GetValue("CITY"))
  Call uidoc.FieldSetText("State", result.GetValue("STATE"))
  Call uidoc.FieldSetText("Zip", result.GetValue("ZIP"))
  Call uidoc.FieldSetText("Phone", result.GetValue("PHONE"))
  Call uidoc.FieldSetText("Cr_to_date", _
  Cstr(result.GetValue("CR_TO_DATE")))
End Sub
Sub Click(Source As Button)
REM Action to get the previous row
  Dim workspace As New NotesUIWorkspace
  Dim uidoc As NotesUIDocument
  Set uidoc = workspace.CurrentDocument
  If Not result.IsBeginOfData Then result.PrevRow
  Call uidoc.FieldSetText("Student_No", _
  Cstr(result.GetValue("STUDENT_NO")))
  Call uidoc.FieldSetText("FirstName", _
  result.GetValue("FIRSTNAME"))
  Call uidoc.FieldSetText("LastName", _
  result.GetValue("LASTNAME"))
  Call uidoc.FieldSetText("Address", _
  result.GetValue("ADDRESS"))
  Call uidoc.FieldSetText("City", result.GetValue("CITY"))
  Call uidoc.FieldSetText("State", result.GetValue("STATE"))
  Call uidoc.FieldSetText("Zip", result.GetValue("ZIP"))
  Call uidoc.FieldSetText("Phone", result.GetValue("PHONE"))
  Call uidoc.FieldSetText("Cr_to_date", _
  Cstr(result.GetValue("CR_TO_DATE")))
End Sub
Sub Queryclose(Source As Notesuidocument, Continue As Variant)
  result.Close(DB_CLOSE)
  con.Disconnect
End Sub
Sub AfterPositionChange(res As ODBCResultSet)
  Dim ws As New NotesUIWorkspace
  Dim source As NotesUIDocument
  Set source = ws.CurrentDocument
  Call source.FieldSetText("RowNumber", Cstr(res.CurrentRow))
End Sub

引用自Domino Designer 6.5 Help

沒有留言: