Alpha Con
Alpha Con

Reputation: 15

Invoice Numbers In a networked application

I have a .NET application written in C#, as well as i am using mysql database,

the application is installed on multiple devices all these devices connected to MySQL database server, here is what i am facing:

Two users opened the application on the screen they have same invoice number like 123 ONCE they save their order the application will check if the number already stored before, if yes the 123 will be incremented by 1 other wise the application will keep the same number,

the problem is that when the users click the save button somehow in the same time, both invoices will have the 123 at the same time with different data.. how can i solve this once and forever. ? thanks for your help.

the code that checks the invoice sequence:

                if (accounts_transactionsTableAdapter.getLastTransNumber(4) != null)
                {
                    textBox1.Text = ((long)(accounts_transactionsTableAdapter.getLastTransNumber(4) + 1)).ToString();
                }
                else
                {
                    textBox1.Text = "1";
                }

4 is the transaction type which represent sale invoice, getLastTransNumber() is a stored procedure that checks the last invoice number of type (4) which is sales

Upvotes: 0

Views: 79

Answers (1)

lifeisfoo
lifeisfoo

Reputation: 16294

Probably you need to implement an Optimistic Locking strategy.

Upvotes: 1

Related Questions