Click here to Skip to main content
15,884,960 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi all,

I don't know how to handle to sell same stock from different Counter.
How can i check that stock is in store or not because that can sell from different Counter at the same time.

e.g.
I have an Item 001.
I keep Stock In record of an Item by Batch No. .

Stock In
          Item Code      Batch No.        Qty
             001             1               10
             001             2               30

And also keep Sales record of an Item by Batch No. .

Sales 
          Sales ID    Item Code      Batch No.        Qty
             1            001             1            5


I wanna know how can i check which batch is how many left qty in store.

* **Main point is i can't handle of Stock Checking from different Counter. When 'CounterA' insert 5 qty of Item 001 to sell, at the same time 'CounterB' insert 5 qty of Item 001 to sell.

When 'CounterA' check that Item of Store Qty, Store returns batch no. 1 is 5 left because 'CounterB' is not Complete in sales issued. And also When 'CounterB' check that Item of Store Qty, Store return batch no. 1 is 5 left because 'CounterA' is not Complete in sales issued.

A Counter insert an item to sell, I just check and insert sales qty on DataTable of each Form.

After insert all sales items then i add that DataTable to MS SQL DB. So I got Two Sales Records with Batch No.1 .
Sales 
          Sales ID     Item Code      Batch No.        Qty
          2             001             1               5
          3             001             1               5


The fact is there's only 5 qty of Batch No.1 because i've already sold 5 qty.

Hope you all can give me an advice on my post.

regards,
nway nge
Posted
Updated 3-Dec-11 23:13pm
v6
Comments
DaveAuld 4-Dec-11 3:41am    
Sorry, you are not making much sense with that question. please explain a little more.
[no name] 4-Dec-11 4:09am    
agree indeed
nwayynge 4-Dec-11 4:13am    
i don't know really how to explain more ..
thanks ..

1 solution

As I understood your problem, the race that occurs between counters ran you into a trouble.
To solve this problem you need to bundle all operations into a transaction and set its type to a serializable one.
It will guarantee for you that client operations do not coincide with each other and no further race will happen.

You can do the transaction in application level or SQL level. so its up to you to decide.
If you prefer SQL then write a stored procedure that get the parameters and do its operation in begin and commit transaction block.
so you will have something like this :

begin transaction 
  see how much items have remained
  save its sale quntity if its possible 
commit transaction


to learn more about transaction read these resources :
http://msdn.microsoft.com/en-us/library/ms188929.aspx[^]

http://msdn.microsoft.com/en-us/library/ms173763.aspx[^]

http://msdn.microsoft.com/en-us/library/2k2hy99x%28v=vs.71%29.aspx[^]


Hope it helps.
 
Share this answer
 
Comments
nwayynge 5-Dec-11 5:27am    
Hello Sir,

Can you tell me a little more of using SQL Transaction.
I can't do different function to the same table coz of Transaction.

I need to Delete first the record of the Table.
Then Save record to the Table again with the same ID.

Hope u can help me.

reagards,
nway nge
Amir Mahfoozi 5-Dec-11 6:38am    
Please provide the code that you have written so far. Thanks.
nwayynge 6-Dec-11 22:46pm    
Thanks Sir, I got it now.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900