Question

i'm going to write a wpf-application and i think i need some advices. I have a database that provids some records. These records are shown in a ListView. The user can insert, delete or modify records. Each of these operations calls the appropriate method of a class that provids methods to work on my database. If the operation on the database suceeded i fire an event. This event is caught by the ui which displays the changes the user made. If the operation on the database fails, a message is displayed.

The database is observed by a method running in a thread. This method checks once per minute, whether the data have changed in the database (e.g. by other users who also work with these data). If changes are detected, an event is also triggered that contains the changed records.

In the ui-class i'm working with a local data stored in a DataTable.

Is there a better way to build that application than my approach? I think my approach is not as good...

Was it helpful?

Solution

Frankly I don't see anything wrong with the design as it is, I would only recommend that maybe bringing in Entity Framework to do some of the database access should be considered.

Other than that, if you are combining the editor and this database change checker, design the database checker first and then work the editor around any possible changes or lockouts the database checker may report. Putting in that plumbing to an existing system would be a nightmare; if you build it in upfront it is quite manageable.

Stick with an MVVM system and make sure you have one VM which the UI will access as well as the thread checker. Put in boolean flags which will allow for styles and controls to turn on/off in the Xaml.

Even though it is not a Silverlight project, design all data accesses in asynchronous fashion with the ability to lock the shared data. If you design with multi-threading up front it will pay off in the long run. I show a basic way of such asynchronous operations and MVVM on my blog article Xaml: ViewModel Main Page Instantiation and Loading Strategy for Easier Binding as a basic reference.

Consider using C# interfaces for the primary operations and data you are processing. That will give you the ability to test them stand alone and provide dependency injection where needed to make your classes testable and reusable in the long run.

Finally use the latest version of .Net. Don't hamstring yourself by using an older version when you don't have to.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top