Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can I tell how many users are in my application
Message
 
 
À
20/11/2000 16:59:00
Stephen Hunt
Admit Computer Services Inc.
Farmingdale, New York, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00443854
Message ID:
00443987
Vues:
20
In my framework I have several functions to count and manage active users in the app.Main problem is with users leaving the program accidentally.
Follows my decision for this (I can publish this package in case of interest from universalthread members):

1. Write a function or method RegisterOper_IN (call it when user starts the app) which:
- opens or creates a table in data or program folder Usertab with fields: computer C(15), user C(15), session N(3), userid I, groupid I, operator C(30), datetin T, datetout T, post C(1), work C(1). Use funcytion GetCompUser below to get computer and user name.
- create a record for the user and fill fields with proper information
- LOCK the record and leave record locked and table opened all the time.
- Never use in your code commands CLOSE DATABASE ALL or CLOSE DATABASE in case if no database is opened, also UNLOCK ALL – they will unlock locked record.
2. Write a function or method RegisterOper_OUT (call it when user leaves the app) which fills field datetout and closes the table.
3. Write a function or method ActiveOper to count or browse active users of the app (for example I use it prior to index or pack, to send messages and other) which:
- open table Usertab AGAIN.
- create a cursor to hold active users.
- SCAN Usertab and for every active user transfer data to cursor. To determine active user use function OthrLocked below.
- Count records in the cursor or browse it.

***
* Returns name of the computer and username in the network
*
FUNCTION GetCompUser
LPARAMETERS lcComputerName, lcUserName
STORE '' TO lcComputerName, lcUserName
LOCAL lcSys0, lnPoz
lcSys0 = SYS(0)
lnPoz = AT('#',m.lcSys0)
IF m.lnPoz=0
RETURN .f.
ENDIF
lcComputerName = ALLTRIM(SUBSTR(m.lcSys0,1,m.lnPoz-1))
lcUserName = ALLTRIM(SUBSTR(m.lcSys0,m.lnPoz+1))
RETURN .t.

***
* Returns .t. if current record is LOCKED from other user in the network
*
FUNCTION OthrLocked
LOCAL llOtherLocked
IF EOF() OR ISRLOCKED()
llOtherLocked = .f.
ELSE
LOCAL lnOldRepro, lnError, lcOldOnErr
lnOldRepro = SET('REPROCESS')
lnError = 0
lcOldOnErr = ON('ERROR')
ON ERROR lnError=ERROR()
SET REPROCESS TO 1
*
* force AUTOMATIC LOCKING without changing anything
IF DELETED()
DELETE
ELSE
RECALL
ENDIF
* in case of error - other user locked the record
llOtherLocked = m.lnError<>0
*
SET REPROCESS TO (m.lnOldRepro)
ON ERROR &lcOldOnErr
ENDIF
RETURN m.llOtherLocked
Nikolay Petkov, nik@osf.bg
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform