Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Update Trigger
Message
 
 
À
29/12/2005 10:34:35
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Versions des environnements
Visual FoxPro:
VFP 6
OS:
Windows XP
Network:
Novell 4.x
Database:
Visual FoxPro
Divers
Thread ID:
01081658
Message ID:
01081688
Vues:
30
>I guess this is possible since I am new using vfp. How can I set the update trigger so that whenever a user updates a record, the network loggin Username plus date is automatically updated onto the field of the table. The filed names of the tables are: staff_mod (c20) and date_mod(d8) respectively.

Here is our code, substitute field names with your field names. This should be a table rule. Make sure to run ALTER TABLE command with NOVALIDATE clause, so the existing records would not be affected.
**************************************************************************************************
FUNCTION UpdateUserAndTime()
*  Function..........: UpdateUserAndTime
*  Author............: Gregory Adam thread #988451 / Nadya Nosonovsky / James Weil
*  Project...........: Visual Collections
*  Created...........: 02/02/2005  15:17:53
*  Copyright.........: (c) Jzanus, LTD, 2005
*  Major change list.:

IF (VARTYPE(m.glDontUpdateUserAndTime) = "L" AND m.glDontUpdateUserAndTime) ;
		OR (TYPE(ALIAS()+".tLast_Updated_Date")="T" ;
		AND OLDVAL("tLast_Updated_Date")<> tLast_Updated_Date) && the new date was passed as part of replace command
ELSE
	LOCAL lcFieldState, lnOccurrence, lnPos
	lcFieldState = SUBSTR(GETFLDSTATE(-1),2) && The first character returns deletion status
	lnOccurrence = 1

	lnPos = AT('2', m.lcFieldState, m.lnOccurrence)

	DO WHILE m.lnPos > 0
		IF FieldChanged(FIELD(m.lnPos))
			REPLACE cLast_Updated_User WITH ;
				IIF(TYPE("m.goApp.cUserID") = "C", m.goApp.cUserID, getUserID()), ;
				tLast_Updated_Date WITH DATETIME()
			lnPos = 0
		ENDIF
		IF m.lnPos > 0
			lnOccurrence = m.lnOccurrence + 1
			lnPos = AT('2', m.lcFieldState, m.lnOccurrence)
		ENDIF
	ENDDO
ENDIF
ENDFUNC
*--------------------------------------------------------------------------

FUNCTION FieldChanged(tcFieldName)

LOCAL llReturn

DO CASE
CASE ISNULL(OLDVAL(m.tcFieldName)) OR ISNULL(EVALUATE(m.tcFieldName))
	llReturn = (ISNULL(OLDVAL(m.tcFieldName)) <> ISNULL(EVALUATE(m.tcFieldName)) )
OTHERWISE
	llReturn = (OLDVAL(m.tcFieldName) <> EVALUATE(m.tcFieldName))
ENDCASE

RETURN m.llReturn

ENDFUNC
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform