📄 cdataenv.prg
字号:
#INCLUDE "INCLUDE\APPINCL.H"
DEFINE CLASS CDataEnvironment AS DataEnvironment
*-----------------
*-- Default values
*-----------------
AutoCloseTables = .T.
AutoOpenTables = .T.
*----------------------------------------
*-- InitialSelectedAlias is set in Init()
*----------------------------------------
Name = This.Class
*----------------------------------------------------------
*-- Custom property definitions
*----------------------------------------------------------
*-- nInitialSelectedAlias - stores the number of the cursor
*-- in the aCursors[] array that should be initially
*-- selected. NOTE: this number is vitally important
*-- to the behavior of the business object which uses
*-- this data environment. ALL behavioral operations
*-- i.e. Delete, Cancel, etc. for a business object
*-- operate on the cursor identified as the initially
*-- selected alias.
*-- cDefaultDatabaseName - the name of the default database.
*-- You should initialize this property when you subclass
*-- cDataEnvironment. This is the filename of the
*-- database container without the .DBC extention.
*-- cDefaultDatabase - The full path and file name of the
*-- default database. It is initialized in the
*-- GetDefaultDatabase() method.
*-- cDefaultLocalLocation - This is an enhancement to the
*-- native codebook that allows the developer to specify
*-- the actual location of the local tables on disk.
*-- An example entry is as follows ...
*-- CURDIR() + "EMPLOYEE\". If this information is
*-- provided, the new version skips the part in the
*-- processing where the default database location is
*-- retrieved from the application settings.
*-- cDefaultRemoteLocation - same as above except this is
*-- the location of the remote data.
*-- lUseLocalData - stores whether or not the application is
*-- using local data.
*-- aCursors[1] - An array of cursors to be loaded into this
*-- data environment
*-- aRelations[1] - an array of relations to be loaded into
*-- this data environment
*----------------------------------------------------------
nInitialSelectedAlias = 1
cDefaultDatabaseName = ""
cDefaultDatabase = ""
*** EGL: 2001.12.27 23:15 - Added support for Views database
cDefaultViewDatabaseName = ""
cDefaultViewDatabase = ""
cDefaultLocalLocation = ""
cDefaultRemoteLocation = ""
lUseLocalData = .T.
* Specifies the version number of this class.
cVersion = "6.01.0001"
DIMENSION aCursors[1], aRelations[1]
FUNCTION Init()
*-------------------- Location Section ---------------------
* Library: cDataEnv.PRG
* Class: cDataEnvironment
* Method: Init()
*--------------------- Usage Section -----------------------
*) Description:
*) Creates a data environment object:
*) 1. Getting the name and location of the default
*) database for this data environment.
*) 2. Loading all defined cursors into the dataenvironment.
*) 3. Determining the intially selected alias.
*) 4. Loading all defined relations into the dataenvironment.
*) 5. Open all of the cursors if requested.
* Scope: PUBLIC
* Parameters: None
*$ Usage: Used as a superclass definition for a business object
*$ data environment that is defined in ADATAENV.PRG
*$ by the software developer.
*% Example:
*% DEFINE CLASS LBSEnvironment AS CDataEnvironment
*% cDefaultDatabaseName = 'LBS'
*% ENDDEFINE
* Returns: LOGICAL .T. by default
*------------------ Maintenance Section --------------------
*@ Inputs: None at this level
* Outputs:
* 1. cDataEnvironment.cDefaultDatabase
* 2. DataEnvironment.AutoOpenTables
* Pre-condition Invariants:
* 1. This is an abstract class, therefore, this class
* cannot be used to directly create an object
* Post-condition Invariants: None
*? Notes: None
* Collaborating Methods:
* 1. IsAbstract() in UTILS.PRG
* 2. cDataEnvironment.GetDefaultDatabase()
* 3. cDataEnvironment.IsValidDefaultDatabase()
* 4. cDataEnvironment.LoadCursors()
* 5. cDataEnvironment.CreateCursors()
* 6. cDataEnvironment.SetInitiallySelectedAlias()
* 7. cDataEnvironment.LoadRelations()
* 8. cDataEnvironment.CreateRelations()
* 9. cDataEnvironment.OpenTables()
* 10. cDataEnvironment.SetDefaultDatabase()
*-- Process:
*-- 1. IF this is not an abstract object
*-- 2. Get the name of the default database
*-- ENDIF
*-- 3. Determine if the default database is valid
*-- 4. IF the default database is valid
*-- 5. Load the cursors for the data environment
*-- 6. Create the cursors of the data environment
*-- 7. Set the initially selected alias to the desired
*-- cursor
*-- 8. Load the relations of the data environment
*-- 9. Create the relations of the data environment
*-- 10. IF the developer wants the tables automatically opened
*-- 11. Open the tables
*-- 12. Set the default database but do not programmatically
*-- open it.
*-- ELSE
*-- 13. Set the default database and programmatically open it.
*-- 14. ENDIF
*-- 15. ENDIF
* Change Log:
* MODIFIED
*--------- (c) Flash Creative Management, Inc. -------------
*---------------- Commenting Provided By -------------------
* Software Assets of Virginia, Inc. (SAVI)
* Charles T. Blankenship, President
* Compuserve: 76132,2575
* Internet: www.savvysolutions.com
* eMail 1: ctb@savvysolutions.com
* eMail 2: 76132.2575@compuserve.com
* Voice: (757)853-4465
************************************************************
LPARAMETERS tlUseDefaultDatabasePaths
LOCAL llRetVal, ;
lnCursor, ;
lnRelation
llRetVal = .NOT. IsAbstract(This.Class, "CDataEnvironment")
IF llRetVal
IF .NOT. tlUseDefaultDatabasePaths
This.GetDatabasePaths()
ENDIF
This.cDefaultDatabase = This.GetDefaultDatabase(.F.)
This.cDefaultViewDatabase = This.GetDefaultDatabase(.T.)
ENDIF
IF .NOT. tlUseDefaultDatabasePaths
llRetVal = llRetVal AND This.IsValidDefaultDatabase()
ENDIF
IF llRetVal
This.LoadCursors()
This.CreateCursors()
This.SetInitiallySelectedAlias()
This.LoadRelations()
This.CreateRelations()
IF This.AutoOpenTables
This.OpenTables()
This.SetDefaultDatabase(.F.)
ELSE
This.SetDefaultDatabase(.T.)
ENDIF &&-This.AutoOpenTables()
ENDIF &&-llRetVal
ENDFUNC
FUNCTION GetDatabasePaths()
*-------------------- Location Section ---------------------
* Library: cDataEnv.PRG
* Class: cDataEnvironment
* Method: GetDatabasePaths()
*--------------------- Usage Section -----------------------
*) Description:
* Scope: Public
* Parameters:
*$ Usage:
*% Example:
* Returns:
*------------------ Maintenance Section --------------------
*@ Inputs:
* Outputs:
* Pre-condition Invariants:
* Post-condition Invariants:
*? Notes:
* Collaborating Methods: None
*-- Process:
* Change Log:
*----- (c) Software Assets of Virginia, Inc. 1998 ----------
*---------------- Commenting Provided By -------------------
* Software Assets of Virginia, Inc. (SAVI)
* Charles T. Blankenship, President
* Compuserve: 76132,2575
* Internet: www.savvysolutions.com
* eMail 1: ctb@savvysolutions.com
* eMail 2: 76132.2575@compuserve.com
* Voice: (757)853-4465
************************************************************
LOCAL lnOldWA , ;
llRetVal , ;
llOK2Close
*---------------------------------------------------
*-- If the DBPaths table does not exist, there is no
*-- special pathing information for this install of
*-- the application. Use the defaults defined in
*-- ADataEnv.PRG
*---------------------------------------------------
llRetVal = FILE("dbpaths.dbf") AND FILE("dbpaths.cdx")
IF llRetVal
lnOldWA = SELECT(0)
SELECT 0
IF .NOT. USED( 'dbpaths' )
llOK2Close = .T.
USE dbpaths SHARED
ELSE
llOK2Close = .F.
ENDIF
llRetVal = USED('dbpaths')
IF llRetVal
*** EGL: 12/06/1999 - Force the SEEK to UPPER()
***IF SEEK( This.cDefaultDatabaseName, "dbpaths", "cdb_name" )
IF SEEK( UPPER(This.cDefaultDatabaseName), "dbpaths", "cdb_name" )
This.cDefaultLocalLocation = ALLTRIM( dbpaths.cdb_local )
This.cDefaultRemoteLocation = ALLTRIM( dbpaths.cdb_remote )
This.lUseLocalData = dbpaths.lLocalData
ENDIF
ENDIF
IF llOK2Close AND USED('dbpaths')
USE IN dbpaths
ENDIF
SELECT ( lnOldWA )
ENDIF
RETURN llRetVal
ENDFUNC
FUNCTION SetDefaultDatabase()
*-------------------- Location Section ---------------------
* Library: cDataEnv.PRG
* Class: cDataEnvironment
* Method: SetDefaultDatabase()
*--------------------- Usage Section -----------------------
*) Description:
*) Select the database for the InitalSelectedAlias only if
*) it is NOT a free table. If you need to set the current
*) database when using a free table, set it in the business
*) object's oSessionEnvironment.cDatabase property.
* Scope: Public
* Parameters:
* 1. <lOpenDatabase> - allows the programmer to
* specify whether or not the database
* should be explicitely opened using code.
* .T. - programmatically open the database
* .F. - set an already opened database as the current one
*$ Usage:
*$ cDataEnvironment::SetDefaultDatabase([<lOpenDatabase>])
*% Example:
*% This.SetDefaultDatabase( .T. )
*% This.SetDefaultDatabase( .F. )
* Returns: LOGICAL .T. by default
*------------------ Maintenance Section --------------------
*@ Inputs:
*@ 1. cDataEnvironment.nInitialSelectedAlias
*@ 2. cDataEnvironment.InitialSelectedalias
*@ 3. cDataEnvironment.oCursorName.Database
*@ The cursor's Database property is populated in
*@ the CCursor::Init() method which is executed
*@ when this class definition calls its CreateCursors
*@ method.
* Outputs: None
* Pre-condition Invariants:
* 1. The cursors must have already been created
* 2. The cursor of the initially selected alias
* cannot be a CFREETABLECURSOR
* Post-condition Invariants:
* 1. The database that contains the initially selected
* cursor is now the current database.
*? Notes:
*? 1. Thanks go to Codebook for Mere Mortals for a fix
*? to this data environment. This fix was used in
*? a modified form to ensure the database is set
*? even if the AutoOpenTables property was set to .F.
* Collaborating Methods: None
*-- Process:
*-- 1. IF the initially selected alias contains a cursor definition
*-- 2. Determine the name of the parent class for the cursor
*-- that was designated as the initially selected alias
*-- 3. Condition the parent class name for the following test by
*-- changing it to upper case.
*-- 4. IF the parent class of the cursor is anything but a free table cursor
*-- 5. Ask it what the name of its database is
*-- 6. IF the developer determined that the database was not
*-- opened previously
*-- 7. OPEN the database (which also makes it the current database)
*-- ELSE
*-- 8. SET the already open DATABASE as the current database
*-- ENDIF
*-- ENDIF
*-- ENDIF
* Change Log:
* MODIFIED
*--------- (c) Flash Creative Management, Inc. -------------
*---------------- Commenting Provided By -------------------
* Software Assets of Virginia, Inc. (SAVI)
* Charles T. Blankenship, President
* Compuserve: 76132,2575
* Internet: www.savvysolutions.com
* eMail 1: ctb@savvysolutions.com
* eMail 2: 76132.2575@compuserve.com
* Voice: (757)853-4465
************************************************************
LPARAMETERS tlOpenDatabase
LOCAL lcDatabase, loCursor
IF TYPE("This.aCursors[This.nInitialSelectedAlias]") == "C"
loCursor = EVAL("This.o"+This.InitialSelectedAlias)
IF NOT IsA(loCursor, "CFreeTableCursor")
lcDatabase = EVAL("This.o" + This.InitialSelectedAlias + ".Database")
IF tlOpenDatabase
OPEN DATABASE ( lcDatabase )
ELSE
SET DATABASE TO ( lcDatabase )
ENDIF
ENDIF
ENDIF
ENDFUNC
FUNCTION IsValidDefaultDatabase()
*-------------------- Location Section ---------------------
* Library: cDataEnv.PRG
* Class: cDataEnvironment
* Method: IsValidDefaultDatabase()
*--------------------- Usage Section -----------------------
*) Description:
*) Ensure that the default database name was derived and
*) that it exists.
* Scope: Public
* Parameters: None
*$ Usage:
*$ cDataEnvironment::IsValidDefaultDatabase()
*% Example:
*% This.IsValidDefaultDatabase()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -