Help with logic creating an Invoice Wizard

Help with logic creating an Invoice Wizard

Old forum URL: forums.lhotka.net/forums/t/3995.aspx


white911 posted on Thursday, December 06, 2007

Hi,

I am having difficulties figuring out the classes I need to implement for a scenario.

Let me explain...

I have an Invoice Business Base Object which it's behavior is to create (or edit) an Invoice. In my windows application I created an AddInvoice Wizard screen which walks you through the creation of a new invoice. However, an Invoice needs to be associated with a customer, so in the Invoice object I have the CustomerID to which the Invoice is associated. In the first screen of the wizard I did as following: 

Users Options 

1) Select an existing customer - which allows the user to select an existing customer from a combo box

2) Create new customer - I have some text boxes where the user can add the customer info

  1. First Name
  2. Last Name
  3. Address
  4. City
  5. State
  6. Zip

 

Now the new customer is not created yet. It gets created when I complete the wizard.

The Business Object behind the wizard screen is the above Invoice object. In a case when the user selected an existing customer from the combo, the Customer ID binds with the CustomerID field in the Invoice object. However, when the user decided to create a new customer, I need a customer business object to create the new customer information and get the new create CustomerID (Auto Identity) and save it to the Invoice object, and once it's done I can save the Invoice object.

So my question is, where should I put the logic for the above? Do I add two Business Objects to the wizard CustomerBO and InvoiceBO, and in the user interface code, I decide which to call first (if customer is new save customer first, otherwise just save invoice). The problem with this case is that I add too much logic and rules now in the user interface code.
Maybe I can add the customer class into an Invoice and in the invoice save I can see if the customer object is new, so save it first. But this means the invoice object has a behavior to create a new customer (in some scenarios)
Or maybe I can create a new object which handles the above.

Please help...

 

JoeFallon1 replied on Thursday, December 06, 2007

I typically create a 3rd object to hold the Customer and Invoice objects.

This 3rd object is a Root BO so it can fetch itself, have rules and save itself.

It is commonly called a Use Case Controller and is designed to handle the one specific use case you have outlined. The benefit is that this controller object contains all the logic that you may have been putting in your screens. This allows different UIs to call the same controller and get the same result - without having to make the UIs "smart". No code duplication across UIs.

So in this ase you fetch an instance of the 3rd BO and depending on what you pass in, you can decide to fetch an existing customer or not. This 3rd BO knows which path you took and can save the data accordingly.

Joe

white911 replied on Thursday, December 06, 2007

Thanks alot. This sounds the righ way to do it.

So in my scenario I would create the following BO

InvoiceBO
CustomerBO

and InvoiceWizardBO - which would have the following Properties
    -- Invoice (InvoiceBO)
    -- Customer (CustomerBO)

and when I call the save it would do some checking if the CustomerBO needs to be saved.

I am not clear with how the binding would work? Should I bind my wizard form to InvoiceWizardBO.Invoice?

Also where can I find more information?

 

 

pandelaras replied on Friday, December 07, 2007

how about creating a blank transicive database entry for customers, and then using that to process in ur business logic. Then when the user finishes the wizard to save the customer first, replace the transicive customer with the proper one?

Copyright (c) Marimer LLC