Implementing the Next ID Function


Author
Message
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
When implementing the next ID for a non-primary key field, I would like to retrieve that incremental number during the save rather than at the SetDefaultValues (see thread).  Here is what I did in my CustomersBO:

public override MicroFour.StrataFrame.Data.SaveUndoResult Save()
{
   
this.CustID = NextIDBO.GetNextID("CM");
   
return base.Save();
}

Is that right?

Then, within the NextIDBO, I am attempting to implement the function that will return the next ID based on the ID type passed in the argument.  I am running into a syntax hurdle.  For some reason, a public method in my NextIDBO cannot be seen by the CustomersBO.  The function looks like this (full implementation code stripped for simplicity):

public int GetNextID(string pRecordType)
{
   
int mNextID = 0;
   
return mNextID;
}

Within this function I would run the appropriate stored procedure that returns a scalar value representing the next ID for the new record.  Perhaps I have not had enough coffee this morning.  What am I missing in the BOs so that the one can see the public method of the other?

Thanks,
Bill


Replies
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
In my CustomersBO I have the following:

public override MicroFour.StrataFrame.Data.SaveUndoResult Save()
{
   
NextIDBO mNextIDBO = new NextIDBO();
   
this.CustID = mNextIDBO.GetNextID("CM");
   
return base.Save();
}

The NextIDBO derives from my NextID table that stores the numbering for various entities.  The GetNextID function executes a scalar command that fires off a stored procedure that both grabs the appropriate value and then updates the NextID table.  The function returns this value to the CustID property as the new ID immediately before saving.

This is not working.  The Save() override never fires.  Any thoughts?

Thanks,
Bill


Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
This is the method to run:

private void CustomersBO_BeforeSave(MicroFour.StrataFrame.Data.BeforeSaveUndoEventArgs e)
{
   
NextIDBO mNextIDBO = new NextIDBO();
   
this.CustID = mNextIDBO.GetNextID("CM");
}

Now, I just need to get my ExecuteScalar syntax correct.


Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Just to wrap this up and put a nice bow on it, I found that this approach to the GetNextID function worked best:

public int GetNextID(string pRecordType)
{
   
SqlCommand mSQL = new SqlCommand();
    mSQL.CommandType =
CommandType.StoredProcedure;
    mSQL.CommandText =
"spx_GetNextID";
    mSQL.Parameters.Add(
"@pRecordType", SqlDbType.Char);
    mSQL.Parameters[0].Value = pRecordType;
   
int mNextID = (int)ExecuteScalar(mSQL);
   
return mNextID;
}

The save function on the customer works like a charm, now!!  w00tw00tw00t  This is quite a simple approach to assigning an ID that auto-increments, yet is not a PK.  In addition, since I am assigning the ID immediately before the save (rather than on the Add()), the numbers aren't being gobbled up without cause.  I know one auditor who is going to like this.

Wonderful framework, gents!  Excellent work.  It really has saved me a ton of hours.  I have actually converted months into days using this framework.

Happy New Year!
Bill


Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Bill Cunnien (12/28/2007)

private void CustomersBO_BeforeSave(MicroFour.StrataFrame.Data.BeforeSaveUndoEventArgs e)
{
   
NextIDBO mNextIDBO = new NextIDBO();
   
this.CustID = mNextIDBO.GetNextID("CM");
}

Crying

Alas!  This works even when editing an old customer record, too!!  Very scary!  I was in a demo to my manager when this reared its ugly head.  How do I check to make sure that I am actually in Add mode as opposed to Edit mode while in the BO?

Thanks,
Bill

Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
'Twas an easy fix.  The custid field has a default value of 0, so I just checked to see if the value was zero.  If true, then grab the next ID.  Whew!  Major crisis quickly melts into a very minor code change.

Tongue

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Bill Cunnien - 18 Years Ago
Bill Cunnien - 18 Years Ago
Bill Cunnien - 18 Years Ago
Trent L. Taylor - 18 Years Ago
Bill Cunnien - 18 Years Ago
                         [quote]When a user clicks 'Add', is a new record created in the...
Trent L. Taylor - 18 Years Ago
                             [quote][b]Trent L. Taylor (12/20/2007)[/b][hr]In this case DO NOT use...
Bill Cunnien - 18 Years Ago
                                 In my CustomersBO I have the following: public override...
Bill Cunnien - 18 Years Ago
                                     This is the method to run: private void...
Bill Cunnien - 18 Years Ago
                                         Just to wrap this up and put a nice bow on it, I found that this...
Bill Cunnien - 18 Years Ago
                                         [quote][b]Bill Cunnien (12/28/2007)[/b][hr] private void...
Bill Cunnien - 17 Years Ago
                                             'Twas an easy fix. The custid field has a default value of 0, so I...
Bill Cunnien - 17 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search