September 2019 Update

New! We're moving to the new forum!

ALL new Blog posts will be on the forum.

Please join us there.

This Blog will no longer be updated...

Monday, June 10, 2019

C# - let's look sharp!

The windows desktop program is only a couple days old, and it's already getting to be a mess...  Sometimes I get a little excited when first trying something out, and I don't always take time to do things the right way, I tend to take shortcuts.

I need to clean it up before I get too far gone! 

I need to think about the architecture before it's too mangled...

First job is to create a proper Data Access Layer. Keep in mind, my knowledge of best practices is over 10 years old, so I'm not familiar with newer methodologies, nor am I interested in learning them... (famous last words)

I was a big fan of tableAdapters, however, the MySql connector for Visual Studio causes an error when you try to create tableadapters using the wizard.

So, next best thing, I'm creating data access classes, one per table (or object, like  Plant) These will be separate dll's and present methods which return data in various ways, encompassed in a DataSet, DataTable, or DataRow.

To get a data table containing all plants, with all fields, simply instantiate the Plant class, and call the getPlants() method:







This saves the repeated overhead of managing database connections in the main program whenever it needs to load data. The Plant class will also provide data resulting from views combining Pant data with other tables, such as mapping which sensor is used, where the plant is located, etc, so different methods can provide different table schemas, but they are all strongly typed.

No comments:

Post a Comment

Any comments deemed off topic or offensive will be removed