基本上有2種方式這個數據是在你所描述的數據模型聯繫起來。如果數據通過響應文檔層次結構鏈接,則與基於關鍵字的文檔結構略有不同。
向您的開發人員顯示此信息,他應該能夠插入代碼以啓用您所談論的「移動參與者」要求。
有幾件事要注意。
- 我假設你需要操縱的所有數據都在一個數據庫中。
- 我把你的圖表從字面上提供。
對於基於關鍵字的文檔結構,您需要檢查使用的視圖和鍵值o查找與會者文檔。具體地檢查這些2行中的 「MoveAttendeesKeyBased」 子:
集vwAttendeesByCourseID = db.GetView( 「(LkupAllAttendeesByCourseID)」)
集dcAttendees = vwAttendeesbyCourseID.GetAllDocumentsByKey(docCourseFrom.CourseID(0),真)
該代碼旨在查看名爲「CourseID」,「狀態」和「等待列出」的值,以獲取要移動的與會者的狀態值。
編寫這個函數的兩個版本花了大約20分鐘。
對於基於響應文檔結構
Sub MoveAttendeesResponseBased(docCourseFrom As notesDocument, docCourseTo As NotesDocument)
%REM
A simple move attendees function if the relationship between courses and attendees is based on
response document hierarchies
%END REM
On Error Goto errHandle
Dim dcAttendees As notesDocumentCollection
Dim docAttendee As notesDocument
Dim iAvailablePlaces As Integer
Dim bMoved As Boolean
If Not (docCourseFrom Is Nothing Or docCourseTo Is Nothing) Then
iAvailablePlaces = docCourseTo.availablePlaces(0)
If 0 < iAvailablePlaces Then
bMoved = False
Set dcAttendees = docCourseFrom.Responses
Set docAttendee = dcAttendees.GetFirstDocument
While Not docAttendee Is Nothing And 0 < iAvailablePlaces
If Ucase(Trim(docAttendee.Status(0)))= "WAIT LISTED" Then
Call docAttendee.MakeResponse(docCourseTo)
If docAttendee.Save(True,True) Then
iAvailablePlaces = iAvailablePlaces - 1
bMoved = True
End If
End If
Set docAttendee = dcAttendees.GetNextDocument(docAttendee)
Wend
If bMoved Then
docCourseTo.availablePlaces = iAvailablePlaces
Call docCourseTo.Save(True,False)
End If
End If
End If
Exit Sub
errHandle:
Messagebox Lsi_info(2) + " - " + Str(Err) + " : " + Error(Err) + ", at line " + Str(Erl)
Exit Sub
End Sub
對於基於關鍵文檔結構
Sub MoveAttendeesKeyBased(docCourseFrom As notesDocument, docCourseTo As notesDocument)
%REM
A simple move attendees function if the relationship between courses and attendees uses
(non-response) key based documents
%END REM
On Error Goto errHandle
Dim session As New notesSession
Dim dcAttendees As notesDocumentCollection
Dim docAttendee As notesDocument
Dim iAvailablePlaces As Integer
Dim bMoved As Boolean
' a view that lists attendees by Course ID
Dim vwAttendeesByCourseID As notesView
Dim db As notesDatabase
If Not (docCourseFrom Is Nothing Or docCourseTo Is Nothing) Then
iAvailablePlaces = docCourseTo.availablePlaces(0)
If 0 < iAvailablePlaces Then
Set db = session.CurrentDatabase
' do a lookup of all attendees based on the CourseFrom document course id
Set vwAttendeesByCourseID = db.GetView("(LkupAllAttendeesByCourseID)")
' this is the collection of all attendees under the CourseFrom document
Set dcAttendees = vwAttendeesbyCourseID.GetAllDocumentsByKey(docCourseFrom.CourseID(0), True)
bMoved = False
Set docAttendee = dcAttendees.GetFirstDocument
' While there are attendee documents to process and there are available places to goto
While Not docAttendee Is Nothing And 0 < iAvailablePlaces
' if the attendee's status is "Wait Listed" then move them
If Ucase(Trim(docAttendee.Status(0)))= "WAIT LISTED" Then
' Update the course ID for the Attendee
docAttendee.CourseID = docCourseTo.CourseID(0)
If docAttendee.Save(True,True) Then
' decrement the available places
iAvailablePlaces = iAvailablePlaces - 1
bMoved = True
End If
End If
Set docAttendee = dcAttendees.GetNextDocument(docAttendee)
Wend
If bMoved Then
' available places may be >= 0. Just update the available places so you don't over book the course
docCourseTo.availablePlaces = iAvailablePlaces
Call docCourseTo.Save(True,False)
End If
End If
End If
Exit Sub
errHandle:
Messagebox Lsi_info(2) + " - " + Str(Err) + " : " + Error(Err) + ", at line " + Str(Erl)
Exit Sub
End Sub
基於密鑰文件的更多一點的工作,但我認爲是一個更好的結構,因爲你可以很容易地在數據庫中移動文檔並從備份中恢復,複製和粘貼。有了回覆文件,您可能會遇到恢復備份的問題,因爲回覆文件使用父母文件UNID來關聯自己,而且如果您偶然移動了與會者,就不可能知道哪個課程沒有原始課程信息而讓與會者重新回到上面,因此引導您回到基於文檔的關鍵結構(但這只是我的觀點).....
我有時間思考技術問題,並想出了2種方法可以實現此功能。請看下面的答案 – giulio