locked
Problem for multi environment form RRS feed

  • Question

  • Hi 

    I am developing multi environment Invoicing Billing Software. I am having problem with Invoice No. Because other user also generating same invoice. How can I get the Last Invoice No. when we save record. And Prevent Other user on to save record in table. Because Invoice no. is Unique.

    thanks

    jasvee

    Saturday, September 19, 2020 11:57 AM

All replies

  • Hi 

    I am developing multi environment Invoicing Billing Software. I am having problem with Invoice No. Because other user also generating same invoice. How can I get the Last Invoice No. when we save record. And Prevent Other user on to save record in table. Because Invoice no. is Unique.

    thanks

    jasvee

    The Invoice number would be the ID, a primary key, for the Invoice record assigned by the database engine that can be done using MS SQL Server with Identity. Database servers hace the ability to use auto incremented column assigned by the database engine. You could also generate a GUID in VB code and use it as an invoice id.

    https://www.sqlservertutorial.net/sql-server-basics/sql-server-identity/

    https://betterexplained.com/articles/the-quick-guide-to-guids/

    https://www.techrepublic.com/article/generating-guids-with-vbnet/#:~:text=GUIDs%20identify%20objects%20such%20as,group%20of%2012%20hexadecimal%20digits.&text=In%20the%20example%2C%20I%20define,GUID%20that%20I%20will%20generate.

    Saturday, September 19, 2020 3:11 PM
  • Hello,

    Using a database with tables for customer (who is placing an order) and a table for remembering the last invoice number. This way it's very unlikely that a customer will be placing two orders at once and each customer sequence is separated from other customers. 

    In the screenshots below I used SQL-Server but this will work with any database.

    The following method will take a string such as CC0002 and increment it to CC0003 and when (in this case) CC can not be incremented the code will increment to compensate or reset the sequence each year but that needs more code logic.

    Generator code found here, front end sample project found here. Note that I did not code the database update as this would be dependent on the database but that simple, same with the read operation which uses mocked data.

    Click the button to create a new sequence for the customer. For your app this would be done when finalizing placing an order so if they were to cancel you don't assign a sequence number. If they cancel after placing an order that sequence is gone and with that in the orders table you could have IsDeleted column for performing a soft delete so later to see deleted orders you can.

    In closing I've given you enough to generate invoice numbers which you can use as is or modify.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Sunday, September 20, 2020 11:15 AM
  • thanks all
    Monday, September 21, 2020 6:42 AM
  • Hi jasvee,

    If your question has been answered then please click the "Mark as Answer" Link at the bottom of the correct post(s), so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 22, 2020 7:31 AM