Skip to content

February 14, 2007

2

Building a “Stupid Client” … Part 2

 

So now that we have the basic idea down, we should be ready for some code. We will start by looking at the front end application.

The front end app will have to maintain( or build ) a dataset with the properties of our object. To do this we will need a builder object. This builder object will have to maintain the dataset, allow us to extract it, and add “properties”. The class below should provide a clearer picture.

Cient Builder

 

So what does this mean? The class will have a main method which will add properties to the dataset being maintained. When the Builder object is instantiated it calls the BuildDataSet() method which creates the dataset and so on. So… on with it ! You want to see some code.

==============================================
CODE:: Builder.cs
==============================================

Pardon the link to another file but WordPress was hating on embeded code. At any rate, the first part of the builder is fairly simple. The AddProperty may confuse some. It first creates a string array with as many columns ( properties ) as the column count in the datatable. We then see a rather long if statement. If we are adding the first property ( column ) then we want to just add it, otherwise we recreate the row with the new column. This means that the property set grows lateraly, as such:
————————————————————————
Property 1Property 2 | Property 3 | ……….>
————————————————————————
Value 1       |   Value 2      | Value 3        |   ……….>
————————————————————————
 

So we will always have 1 DataSet, containing 1 DataTable with one growing DataRow. Now I know that some will complain about having to maintain this set, however I urge you to take the following into consideration 1) The client side code and 2) the fact that looping through columns and moving some values around is relatively inexpensive. So let’s start with #1:

1. The client side code.
   ( in this instance we want to add a new truck to our database, the truck has four
      attributes: Name, Make, MaxSpeed, and MaxTowing)

private void btnSave_Click(object sender, EventArgs e)
{
Builder b = new Builder();

b.AddProperty("Name", this.txtName.Text);
b.AddProperty("Make", this.txtMake.Text);
b.AddProperty("MaxSpeed", this.txtMaxSpeed.Text);
b.AddProperty("MaxTowing", this.txtMaxTowing.Text);

//-- TAP WEBSERVICE AND INSERT -- 
s.InsertTruck(b.pDataSet);

}

( s being the webservice refference )

So what are the benefits? First off you know exactly what value is assigned to what property. Second, you don’t have to deal with passing 10+ parameters to one method. Third, you can run your DataSet against a dynamic business rule engine before making the call( that may be another series ). Last but not least the code is just cleaner. Click the link below to download the Windows Application containing the above code:

============================
CODE DOWNLOAD: FrontEnd_Builder.zip
============================

So now that you have some idea of what the front end is doing we can concentrate on the backend. That will be our Part 3. We will pass the DataSet to the backend, hydrate a new Truck business object and invoke the InsertTruck() business method. Stay tuned…

Read more from Random Rants
2 Comments Post a comment
  1. Feb 14 2007

    cool.

    you’ve obviously stolen these ideas from a previous employer’s I.T. vendor. how long till they sue you for it?

    hahahahahahaha.

    Reply
  2. Feb 15 2007

    LOL! Yeah, there is no way that I thought of some kind of framework or had an idea of my own. Developers cannot think for themselves or have independed thought. I must have ganked it from a company that has almost no experience with Win Apps, and doesn’t have a mature framework. But they own the web, anything they look at, or touch is theirs… guess they best go sue DNN for using their own CBO Hydrator after they looked at it. Maybe if they sprinkled some C# on their apps they could write some original content and release it to the community. Just thinking about that crap pisses me right off.

    Reply

Share your thoughts, post a comment.

(required)
(required)

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments