Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Ayuda en mi programacion
Message
From
09/07/2006 22:14:45
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
09/07/2006 20:55:21
Luis Parada
Prosoft´s de Venezuela, C.A.
Valencia, Venezuela
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows NT
Database:
MS SQL Server
Miscellaneous
Thread ID:
01134828
Message ID:
01134831
Views:
21
>Muy buenas noches.
>Muchas gracias de antemano.
>
>Quisiera que me orientaran como hacer una subrutina para grabar el numero de factura que le corresponda segun el correlativo de la tabla, estoy trabajando multiusuario.

Lo más conveniente es guardar los números de secuencia en una tabla aparte, de secuencias. (De paso, yo uso la misma tabla para las claves primarias de las diferentes tablas, claves que no ve el usuario.)

Como el usuario ve el número, sólo se lo debe asignar al momento de guardar el registro; y para mayor seguridad, usar una transacción. Eso, por si el usuario cancela el registro (TableRevert()), o por si hay un problema al guardar - para que no falten números en la secuencia.

He aquí mi versión de esta función.
**********************************************************************
FUNCTION SerialNumber(tcSequence)
	* Get serial number. Used mainly to generate primary keys.
	* The easiest way to achieve this is to call this function from a fields default value.
	* Example: default value for primary key "Client" of table "Client" = SerialNumber("Client")
	* This function accesses table SerialNumber. Fields: Sequence C(30), NextNum I.
	tcSequence = lower(tcSequence)
	local lnSelect
	lnSelect = select()
	if used("serialnumber")
		select serialnumber
	else
		select 0
		use serialnumber
	endif
	set order to "sequence"
	seek padr(tcSequence, len(sequence))
	if not found()
		append blank
		replace sequence with tcSequence, nextnum with 1
	endif
	local lnReturnValue
	if lock()
		lnReturnValue = nextnum
		replace nextnum with nextnum + 1
	else
		lnReturnValue = -1
	endif
	unlock
	select (lnSelect)
	return lnReturnValue
ENDFUNC
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Reply
Map
View

Click here to load this message in the networking platform