none
Purchase Order Number Generator

    Question

  • I'm designing the forms for our business, and am currently working on a Purchase Order form.  The aim is to create a form that, when opened, creates a new PO number that runs in sequence.

    IE: I open it one time and I have GH-0001, but next time it's opened, we have GH-0002.  I'd like to avoid anything based on date and time because those make for very long PO Numbers, and slightly weird.

    Any suggestions or redirections are welcome.
    Thursday, December 08, 2005 6:37 PM

Answers

  • This ID could be inserted in a database. What you'll have to watch is when 2 people open an order for at the same time, you don't want them to have the same ID.
    Thursday, December 08, 2005 6:47 PM
  • If I were you I would keep a set of unique & used PONumbers in a database table.  This solution will work on any machine, and it does not require modifying a user's registry. 

    I would then write a shared method called GetNextPONumber that returns an unused PONumber.  This method internally is implemented using an algoritm of your choice.  You could for example have two colunns: ID (an int set as uniqueidentifyer) and PONumber (calculated column = "PO" & ID).  To be efficient you can create a Sproc or another table that precalculates the next available number.

    hth,

    Paul
    Thursday, December 08, 2005 9:55 PM

All replies

  • This ID could be inserted in a database. What you'll have to watch is when 2 people open an order for at the same time, you don't want them to have the same ID.
    Thursday, December 08, 2005 6:47 PM
  • Questions I'd ask before answering.

    1. As ThE_lOtUs suggested, behaviour will be different if more than one user is able to access the form at any given time. Will your form app run seperately on multiple machines?
    2. Do you have more than one user?

    If you answer no to these questions then answer is simple, store either the current or last PO number in the registry and have it reset it to the next one each time your form loads.

    Randy
    Thursday, December 08, 2005 8:18 PM
  • While I'm pretty well versed in software itself, I'm not so well versed in registry and back end issues.
    We intend to have only one purchasing agent working from one machine.  So the answer is no to both questions.

    How do you store the last PO number in the registry and set it to reset to the next one?  I'm sorry if this is a stupid question, but I suppose I just don't understand what registry you're talking about. 
    The actual registry for all my different software? 
    Thursday, December 08, 2005 8:30 PM
  • The registry is like a big database of settings for windows.
    You could also write your information in an xml config file you could also load this config file using a dataset (is this is easyer for you). I also suggest not writing in the app.config, keep it read only.


    http://www.codeproject.com/vb/net/registry_with_vb.asp

    http://www.codeproject.com/vb/net/ConfigOpt.asp
    Thursday, December 08, 2005 9:40 PM
  • If I were you I would keep a set of unique & used PONumbers in a database table.  This solution will work on any machine, and it does not require modifying a user's registry. 

    I would then write a shared method called GetNextPONumber that returns an unused PONumber.  This method internally is implemented using an algoritm of your choice.  You could for example have two colunns: ID (an int set as uniqueidentifyer) and PONumber (calculated column = "PO" & ID).  To be efficient you can create a Sproc or another table that precalculates the next available number.

    hth,

    Paul
    Thursday, December 08, 2005 9:55 PM
  • The only reason to store POnumbers in a database is if they do not exit in any other database as a referance. In using POs, numbers are given sequentially. As long as you know what the last one or current one is (Depending on your logic) you can continue to generate them sequentially. PO are logged in a book known as a log book and all numbers prexisting should be readily available to anyone. The code for the form to give out the next available PO does not need to be as complex as needing it's own database.

    ryansingleton ,

    If getting and setting a registry entry is too complicated or you have other reasons not to use it, You can very easily save the current number to a text file. Xml is nice, but for one single external piece of data (A number no less) need not be so complicated to store and update beyond this.

    Simply break up the string and seperate the numeric part and the alphabet part. Unless you need to prefix the PO in any other way you can hard code that part.

    Dim POPrefix as string ="GH-"

    Then Merge the actual number with it.

    Private PO as int32

    textbox1.text=POPrefix & PO.ToString

    then calculate the math for the next

    PO +=1 or is it PO 1+=? (Late day brain here)

    Then write your new number to a file to be read back the next time you need to generate the next number.

    If there's anything else you can tell us, then perhaps a better solution can be expressed. Otherwise it looks this simple to me.

    Edit to Add: Sample code


    Public Class Form3
        Dim LastPO As String

        Private Sub Form3_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            NextPO()
        End Sub
        Private Sub NextPO()
            Dim NextPO As Integer
            Dim ThisPO As String
            On Error Resume Next
            'ThisPO = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\POapp", "POnumber", "GH-0001")
            'Uncomment the above and comment below....
            If My.Computer.FileSystem.FileExists("PO.txt") Then
                ThisPO = My.Computer.FileSystem.ReadAllText("PO.txt")
            Else
                ThisPO = Me.lbPODisplay.Text
            End If
            'through to here to switch to using the registry
            LastPO = ThisPO
            NextPO = CInt(ThisPO.Substring(4))
            NextPO += 1
            ThisPO = "GH-" & Format(NextPO, "0000").ToString
            Me.lbPODisplay.Text = ThisPO
            'My.Computer.Registry.SetValue("HKEY_CURRENT_USER\POapp", "POnumber", ThisPO)
            'Uncomment above and comment below to switch to using the registry
            My.Computer.FileSystem.WriteAllText("PO.txt", ThisPO, False)
        End Sub

        Private Sub lbPODisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbPODisplay.Click
            Me.lbPODisplay.Text = LastPO
        End Sub

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            NextPO()
        End Sub
    End Class

     


    Randy
    Thursday, December 08, 2005 11:18 PM
  • Ryan,

    Doing the exact same thing right now, but don't have time to develop. Was looking for an office template when I saw your post. Would you be willing to share your final template with the generator?

    Mikeg

    Thursday, January 05, 2006 3:19 AM