0

I am just starting to develop a C# winforms application which is to have a SQL back-end. I have classes for the user interface which allow the user to enter data. However there will also be validation, some options are conditional on other options, and on the forms there will be some read-only fields implemented using labels. A good example of the latter is when the user enters a discount rate and a price and it displays the discounted price.

I have business logic classes for the data objects. Would you:

  1. Instantiate these only at the point of saving and loading to/from the database, and hold state in the properties of the controls OR
  2. Keep the business logic objects constantly in memory and update them whenever the user enters/edits information?

Option 2 sounds like hard work as you have to handle everything changing on your forms. However, since you have an object in existence you can use that object to do the validation/calculations. You can call the DiscountedPrice property, for example.

Paul Richards
  • 1,181
  • 1
  • 10
  • 29
  • Is there any data binding you have done? Is this create only operation? You might want to add relevant code to your question. – danish May 05 '15 at 12:40
  • @danish I have not used data binding. At the moment its just a non-functional user-interface. Its not create only, they can update, view and delete. – Paul Richards May 05 '15 at 12:48
  • Create object when the user actually saves the new record. – danish May 05 '15 at 12:50
  • I am looking into this: http://stackoverflow.com/questions/5883282/binding-property-to-control-in-winforms – Paul Richards May 08 '15 at 10:59

1 Answers1

0

An object in the business logic layer will exist all the time, I have chosen option 2. I will bind the object to the controls like this:

textBox1.DataBindings.Add("Text", example, "Datum");

Where Text is the Text property of a text box, and example.Datum is the property of the object in the business logic layer.

Those read-only fields on the form can then be implemented via properties of the object in the business logic layer. This means I can keep the logic out of the UI layer.

Paul Richards
  • 1,181
  • 1
  • 10
  • 29