22Dec/057
Domino Document Locking Class 1.1
Updated version of Document Locking Class is now available.
Here is an update to the Document Locking Class:
Public Sub new( inDoc As Variant ) Public Sub SetCurrentUser( user As String ) Public Function hasDocument() Public Sub setDocument( inDoc As NotesDocument ) Public Sub setUIDocument( inUIDoc As NotesUIDocument ) Public Property Get toString As String Public Property Get ShowPrompts As Boolean Public Property Set ShowPrompts As Boolean Public Function LockingEnabled() As Boolean Public Function IsLockedByCurrentUser () As Boolean Public Function IsDocumentLockedByCurrentUser (doc As NotesDocument ) As Boolean Public Function IsUIDocumentLockedByCurrentUser ( uiDoc As NotesUIDocument ) As Boolean Public Function LockedBy ( ) As String Public Function IsLocked ( ) As Boolean Public Function IsDocumentLocked ( doc As NotesDocument ) As Boolean Public Function IsUIDocumentLocked (uiDoc As NotesUIDocument ) As Boolean Public Function Lock() As Boolean Public Function LockUIDocument (uiDoc As NotesUIDocument ) As Boolean Public Function LockDocument (doc As NotesDocument ) As Boolean Public Function UnLock () As Boolean Public Function UnLockUIDocument (uiDoc As NotesUIDocument ) As Boolean Public Function UnLockDocument (doc As NotesDocument ) As Boolean
Domino Document Locking
%INCLUDE "LSCONST.LSS" '/** ' * A rapper around the built-in document locking that is available in Notes/Domino 6. ' * The purpose is to provide a better more consistant way of locking and unlocking documents. ' * Will not lock a new document since it can not be locked. Will only show warnings once. ' * ' * @author Chad Schelfhout http://www.chadsmiley.com/ ' * @version 1.1 ' */ Class DominoDocumentLocking Private pUser As String Private pDoc As NotesDocument Private pToString As String Private pShowPrompts As Boolean Private pDatabase_Locking_Not_Enabled As String Private pDatabase_Locking_Not_Enabled_Title As String Private pDocument_Locked As String Private pDocument_Locked_Title As String Private pEnabled As Boolean Private pAlreadyLocked As Boolean 'Flag used so user is only informed once that database locking is not enabled Private pDatabasePrompted As Boolean '/** ' * Constructor ' */ Public Sub new( inDoc As Variant ) pDatabase_Locking_Not_Enabled = "Database locking has not been enabled." pDatabase_Locking_Not_Enabled_Title = "Locking Not Enabled" pDocument_Locked = "Unable to lock, currently locked by: " pDocument_Locked_Title = "Document Locked" pDatabasePrompted = False pAlreadyLocked = False pShowPrompts = True pToString = "" If Not inDoc Is Nothing Then If Typename( inDoc ) = "NOTESDOCUMENT" Then Set pDoc = inDoc Elseif Typename( inDoc ) = "NOTESUIDOCUMENT" Then Set pDoc = inDoc.Document End If End If Dim Session As New NotesSession pUser = Session.UserName If Session.CurrentDatabase.IsDocumentLockingEnabled Then pEnabled = True Else pEnabled = False End If End Sub '/** ' * Determines if the document is locked ' */ Private Function HasLock ( ) As Boolean If pDoc Is Nothing Then HasLock = True Else 'if there is no text then it is not locked HasLock = Len( pDoc.LockHolders(0) ) > 0 End If End Function '/** ' * Gets the current user ' */ Private Property Get CurrentUser As String CurrentUser = pUser End Property '/** ' * Gets the current user ' */ Public Sub SetCurrentUser( user As String ) pUser = user End Sub '/** ' * Determines if the document is locked but the current user. ' */ Private Function CurrentUserHasLock( ) As Boolean CurrentUserHasLock = HasLock () If CurrentUserHasLock Then If pDoc.LockHolders(0) = pUser Then CurrentUserHasLock = True Else 'Not the current user. CurrentUserHasLock = False End If End If End Function '/** ' * Determines if a document exists ' */ Public Function hasDocument() hasDocument = Not pDoc Is Nothing End Function '/** ' * Sets the Document ' */ Public Sub setDocument( inDoc As NotesDocument ) Set pDoc = inDoc End Sub '/** ' * Sets the document base on the UI document ' */ Public Sub setUIDocument( inUIDoc As NotesUIDocument ) If inUIDoc Is Nothing Then Call setDocument( inUIDoc.Document ) End If End Sub '/** ' * Returns string of any messages ' */ Public Property Get toString As String toString = pToString End Property '/** ' * Returns wether prompts are displayed ' */ Public Property Get ShowPrompts As Boolean ShowPrompts = pShowPrompts End Property '/** ' * Sets wether prompts are displayed ' */ Public Property Set ShowPrompts As Boolean pShowPrompts = ShowPrompts End Property '/** ' * Determines if database locking is enabled. ' */ Public Function LockingEnabled() As Boolean If Not pEnabled Then If Not pDatabasePrompted Then pToString = pDatabase_Locking_Not_Enabled If showPrompts Then Msgbox pToString , MB_ICONSTOP , pDatabase_Locking_Not_Enabled_Title End If pDatabasePrompted = True End If End If LockingEnabled = pEnabled End Function '/** ' * Determines if the current document is locked by the current user. ' */ Public Function IsLockedByCurrentUser () As Boolean IsLockedByCurrentUser = LockingEnabled() If IsLockedByCurrentUser Then IsLockedByCurrentUser = CurrentUserHasLock( ) Else 'Locking not enabled IsLockedByCurrentUser = False End If End Function '/** ' * Determines if the document is locked but the current user. ' */ Public Function IsDocumentLockedByCurrentUser (doc As NotesDocument ) As Boolean Call SetDocument( doc ) IsDocumentLockedByCurrentUser = IsLockedByCurrentUser End Function '/** ' * Determines if the UI document is locked but the current user. ' */ Public Function IsUIDocumentLockedByCurrentUser ( uiDoc As NotesUIDocument ) As Boolean Call setUIDocument( uiDoc ) IsUIDocumentLockedByCurrentUser = IsLockedByCurrentUser( ) End Function '/** ' * Returns who the document is locked by ' */ Public Function LockedBy ( ) As String If hasDocument() Then LockedBy = pDoc.LockHolders(0) Else LockedBy = "" End If End Function '/** ' * Determines if the currnet document is locked ' */ Public Function IsLocked ( ) As Boolean isLocked = LockingEnabled() If isLocked Then isLocked = HasLock( ) Else 'Locking is not enabled isLocked = False End If End Function '/** ' * Determines if the the document is locked ' */ Public Function IsDocumentLocked ( doc As NotesDocument ) As Boolean Call setDocument( doc ) isDocumentLocked = IsLocked() End Function '/** ' * Determines if the UI document is locked ' */ Public Function IsUIDocumentLocked (uiDoc As NotesUIDocument ) As Boolean 'Check to make sure that there is a document, If there is none it is a new document If ( uiDoc.Document Is Nothing ) Then IsUIDocumentLocked = False Else IsUIDocumentLocked= IsDocumentLocked( uiDoc.Document ) End If End Function '/** ' * Locks the current document ' */ Public Function Lock() As Boolean Me.Lock = LockingEnabled() If Me.Lock Then 'Check to make locking is enabled. If Not pAlreadyLocked Then 'Make sure that the document is not allready locked. If HasLock( ) Then If CurrentUserHasLock( ) Then 'Since the current user has the document locked then we don't need to. pAlreadyLocked = True Me.Lock = True Else 'Document is locked by someone else. Let's display the name pToString = pDocument_Locked + pDoc.LockHolders(0) If showPrompts Then Msgbox pToString , MB_ICONSTOP, pDocument_Locked_Title End If Me.Lock = False End If Else 'Make sure that there is a document to lock, New documents can not be locked. If Not pDoc.IsNewNote Then Call pdoc.Lock End If pAlreadyLocked = True Me.Lock = True End If End If End If End Function '/** ' * Locks the UI document ' */ Public Function LockUIDocument (uiDoc As NotesUIDocument ) As Boolean Call setUIDocument( uiDoc ) LockUIDocument = Me.Lock() End Function '/** ' * Locks the document ' */ Public Function LockDocument (doc As NotesDocument ) As Boolean Call setDocument ( doc ) LockDocument = Me.Lock() End Function '/** ' * Unlocks the current document ' */ Public Function UnLock () As Boolean Me.UnLock = False If Not pDoc Is Nothing Then If Not pDoc.IsNewNote Then If CurrentUserHasLock( ) Then 'Only unlock if the current user has it locked. pDoc.UnLock Me.UnLock = True End If End If End If End Function '/** ' * Unlocks the UI document ' */ Public Function UnLockUIDocument (uiDoc As NotesUIDocument ) As Boolean Call setUIDocument( uiDoc ) UnLockUIDocument = Me.UnLock() End Function '/** ' * Unlocks the document ' */ Public Function UnLockDocument (doc As NotesDocument ) As Boolean Call setDocument( doc ) UnLockDocument = Me.UnLock() End Function End Class