Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
FLOCK and Unique Sales Numbers
Message
De
24/06/2014 09:38:27
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Allemagne
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
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:
01602284
Vues:
59
FLOCK should do if there is just one system of unique data.

SET REPRO TO AUTO .. can end up in an endless loop. I would set to some seconds - display a wait statement - and fail out to some "come later again". Set at least this process runs.

I would advise against your construction of numbers. I would do something like SomeDateString'+running number. Running number as integer. This hard to fill in a day. You will not run out of uniqe numbers for long. :)

Use a new record each day starting with 1. The record mmust hold the date too.

The old system (unique per lane) would be as simple as Lane#+SomeDateString'+running number, but this needs more records with an extra column, possibly locked by RLOCK().

The good on storing the number per day is that the shop owner (and the tax office) may get information about the numbers used. I do not know what the requirements of sales number or with you (ask the tax advicer), but in germany the number must be unique per year. The examples above are possible too. But a reuse in the middle of the year - ouch. We would run in deep trouble with the VAT ....

Lutz

>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!
Words are given to man to enable him to conceal his true feelings.
Charles Maurice de Talleyrand-Périgord

Weeks of programming can save you hours of planning.

Off

There is no place like [::1]
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform