Generate sequencial number in a BO


Author
Message
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Greg,

This kind of data will be usually in use by a single user, since it is just the Line order for the records that will be shown as a lookup in a combo, so these forms will not be use by multiple users.  That's why I used the data in the BO to get the last one used, even though I think a better approach is to use the database with a view or SP to get the MAX() + 1.

Thanks for the explanation.

Edhy Rijo

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
This will work in a single user scenario, but if you have multiple users, especially if they are all adding new records, you'll get dups pretty quick. The BO is disconnected from the db, so if another user adds a new record after the user has filled the BO, they won't know about the newly added record from the other user. There are a few of solutions for this:



- If possible, just use an AutoIncrement field. The down side is that it is hard to have no holes (in some cases holes are a problem if the field is audited) and it will by a system number, not one that necessarily makes any sense in the context of the business domain.

- Query the db for the last LineOrder number and increment it. I've used this when it is very unlikely that two people are going to be adding records at the same time (in fact, it is a bad idea in these scenarios). Pretty much what you are doing, but if someone else adds new records while the user is in their BO, they'll see the changes.

- Use a table to hand out the LineOrder numbers. I.e. you query this table to get the next line order number. This is more complex because you have to deal with canceled adds, etc.



The long and sort of it is to use the DB to handle this, since the disconnected BO won't know about other users changes in a timely enough fashion (usually). I'm sure there are other ways to do this too, but thought I'd offer some ideas.
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi All,

I have several form which will show a list with a sequential order number like 1,2,3,4, etc.  (See picture below).  I want this field LineOrder to be autogenerated with the next unused value when a new record is created, so if the last one used is 5, then when clicking New, the value will be 6.

I added the following code in the PaymentMethodBO.vb:

Private Sub PaymentMethod_SetDefaultValues()

     ' --- Calculate the next LineOrder number to be added as a default value for Me.LineOrder field.

     Me.MoveLast() ' This will move the record pointer to the last record, in this case the new one.

     Me.MovePrevious() ' Go back to the previous record which should be the last one.

     Dim nextLineOrder As Integer = 0

     nextLineOrder = Me.LineOrder + 1 ' Increment 1 to get the next default value.

     If nextLineOrder = 0 Then

          nextLineOrder = 1

     End If

     Me.MoveLast() ' Go back to the new record

     ' Set the default Value here

     Me.LineOrder = nextLineOrder

End Sub

So far this is working fine, but I would like to make sure this is the proper way to get this done when working with data in the BO.  I guess I may have another BO with a SELECT MAX() statement to get the last value used and then increment this value.  So I would appreciate any recommendation in this regard.

Thanks!Smile

Edhy Rijo

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search