Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
FLOCK and Unique Sales Numbers
Message
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
FLOCK and Unique Sales Numbers
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP3
Network:
Windows 2003 Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01602280
Message ID:
01602280
Vues:
72
Hi Gang!

We used to have a record in a table for EACH lane of a drug store (each register, that is). Each record had a field to track the sales number for THAT register (lane). So, you could have multiple duplicate sales numbers in the drug store over a period of time.

They didn't like that ( I didn't either ), so I was tasked to code up a solution so there would be UNIQUE sales numbers at that location (store). The registerrs would no longer look at the previous table, but would call a function to get a UNIQUE sales number for the store at THAT MOMENT in time. Here is what I came up with, ...

SET REPROCESS TO AUTO is globally set at the beginning of the program.....
FUNCTION GetNextSaleNumber
LOCAL lnNextSaleNumber

IF NOT USED('sales_no')
	USE IN 0 sales_no
ENDIF 
*Lock the sales_no table to allow no one else to modifiy the last_sale value while I am updating it....
IF FLOCK('sales_no')
	SELECT sales_no
	IF sales_no.last_sale = 999999
		REPLACE sales_no.last_sale WITH 1
	ELSE 
		REPLACE sales_no.last_sale WITH sales_no.last_sale + 1
	ENDIF 
	lnNextSaleNumber = sales_no.last_sale
ELSE
	lnNextSaleNumber = -1	 
ENDIF
SELECT sales_no
UNLOCK    
RETURN lnNextSaleNumber
Sales_no is a simple table with ONE record and ONE field in it. ( sales_no.last_sale ).

And you would call it this way.... lnSaleNo = GetNextSaleNumber()

Does this look ok? Should I do some error trapping in case something goes wroing ( a pc locks up during the function and LOCKS the sales_no table ) ??

What else would you do?

Thanks!
Tommy Tillman A+ NetWork+ MCP
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform