About This Code
Brief Description:
clsNotesFactory class. This class encapsulates the most common used LS functions
Contributor:
Ricardo L Silva
Notes Version:
R5.x, R6.x
Last Modified:
11 Feb 2004
OpenNTF Disclaimer
All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.
Code / Description
The clsNotesFactory class intends to help developers to make shorter, simplier and clearer LS codes.
It incorporates the most common used LS functions (at least used by me).
The main target of this class is to perform common tasks, for example, to find a document in a view using the GetDocumentByKey method of NotesView, without the need of instantiate a NotesSession, NotesDatabase and a NotesView object.
Segue abaixo a relação das funções:
'***Methods of release 1.0
'MessageBox with stop icon. If title argumet is "" (blank), shows DB.Title
FailMsg ( Message, Title )
'MessageBox with exclamation icon. If title argumet is "" (blank), shows DB.Title
AttentionMsg ( Message, Title )
'MessageBox with information icon. If title argumet is "" (blank), shows DB.Title
InformationMsg ( Message, Title )
'MessageBox with question icon that returns an integer value corresponding to NF_YES or NF_NO constans.
'If title argumet is "" (blank), shows DB.Title
QuestionMsg ( Message, Title ) As Integer
'LS @Name function
ConvertNotesName ( NotesName, ConvertTo ) As String
'Returns the current NotesSession
GetSession () As NotesSession
'Returns the NotesDatabase that is being processed by clsNotesFactory
GetDatabase () As NotesDatabase
'Allows to change the NotesDatabase that is being processed by clsNotesFactory
SetDatabase ( Db )
'GetView method of NotesDatabase class
GetView ( ViewName ) As NotesView
'CreateDocument method of NotesDatabase class plus a form name argument
CreateDocument( Form ) As NotesDocument
'GetDocumentByUNID method of NotesDatabase class
GetDocByUNID( UNID ) As NotesDocument
'LS @GetDocField function
GetDocField( UNID, FieldName ) As Variant
'GetDocumentByKey method of NotesView class
GetDocumentByKey ( ViewName, Key ) As NotesDocument
'GetAllDocumentsByKey method of NotesView class
GetAllDocumentsByKey ( ViewName, Key ) As NotesDocumentCollection
'GetProfileDocument method of NotesDatabase class
GetProfile ( ProfileName ) As NotesDocument
'LS @GetProfileField function
GetProfileField ( ProfileName, FieldName ) As Variant
'GetProfileDocument method of NotesDatabase class, using username parameter
GetUserProfile ( ProfileName, User ) As NotesDocument
'LS @GetProfileField function, using username parameter
GetUserProfileField ( ProfileName, User, FieldName ) As Variant
'***Methods of release 1.2
'AdjustYear method of NotesDateTime class
AdjustYear( Date, Years ) As Variant
'AdjustMonth method of NotesDateTime class
AdjustMonth( Date, Months ) As Variant
'AdjustDay method of NotesDateTime class
AdjustDay( Date, Days ) As Variant
'AdjustHour method of NotesDateTime class
AdjustHour( Date, Hours ) As Variant
'AdjustMinute method of NotesDateTime class
AdjustMinute( Date, Minutes ) As Variant
'AdjustSecond method of NotesDateTime class
AdjustSecond( Date, Seconds ) As Variant
'***Methods of release 1.4
'Clear all cached objects
ClearCachedObjects()
Usage / Example
'Example (without using clsNotesFactory class):
Dim Session As New NotesSession
Dim Db As NotesDatabase
Dim View As NotesView
Dim Col As NotesDocumentCollection
Set Db = Session.CurrentDatabase
Set View = Db.GetView( "NomeView" )
Set Col = View.GetAllDocumentsByKey( "Chave", True )
'Example (using clsNotesFactory class):
Dim objFac As clsNotesFactory
Dim Col As NotesDocumentCollection
Set objFac = CreateFactory()
Set Col = objFac.GetAllDocumentsByKey( "NomeView", "Chave" )
You cannot instantiate a clsNotesFactory object directy using New constructor. Instead, you must use one of the functions bellow:
CreateFactory() '--> Create an instance of clsNotesFactory pointing to the current database
'--> Create an instance of clsNotesFactory pointing to a specific database
CreateFactoryWithDbPath ( Servidor As String, Path As String )
CreateFactoryWithReplicaID ( Servidor As String, ReplicaID As String )
CreateFactoryWithDb ( Db As NotesDatabase )
An important characteristic of this class is that it makes a cache of last used instance of objects. It means that if you call a method that uses internally an object like a NotesView for example, the class will not try to get the NotesView using GetView method of NotesDatabase if you have called a method that uses the same view before.
It makes the process a little fast.
Code Attachments