The application is split into 3 layers:
- User Interface
- Business Logic
- Data Access
This is an industry standard way of structuring things. the layers are separated as projects.
The User Interface (UI) layer should only contain code that relates to the user interface - how form elements are structured. Its generally just talks to the Business Logic Layer.
The Business Logic (BL) layer contains the smarts of the application. It shouldn't connect to any datastore, strictly, it shouldn't even care where the data is coming from eg, SQLServer, MSAccess, Oracle, Or even XML Files. If it wants data it just talks to the Data Access Layer.
The Data Access (DL) layer talks to the database- whatever it may be.
However to begin with at least the lines between these layers will be a little blurred.
I've rewritten the DAL to have non static members so to access them you must instantiate it.
FYI: If a class has a static method (function) or property it can be called like this:
SomeClass.SomeMethod();
However to access the non static methods and properties of a class you will need to instantiate it first.
SomeClass someClass = new SomeClass();
someClass.SomeMethod();
So anyway the startup form is the Dashboard. however the login form is called before it is shown.
When the dal is instantiated it requires a connection string as a parameter to the constructor.
However it also contains a method to change the connection string if required - which is what we do when selecting a new datasource from the Environment form.
You'll notice I've created a User class in the BLL. The idea here is anything you need to do with a user you use this class.
EG.
User user = new User(dal); //we pass to it an instance of the DAL class.
//There is also an overload for the constructor of this class to specify the userLogin.
User user = new User(dal, "john");
//Specifying a userLogin should then load the properties of the User object from the dal using the Load() method.
//so now we can retrieve properties of the user EG:
txtFirstName.Text = user.FirstName;
txtLastName.Text = user.LastName;
//Later we need to create other methods for this User class like Save() and Delete();
EG:
user.FirstName = txtFirstName.Text;
user.LastName = txtLastName.Text;
user.Save();
Take a look at the Load() method on the User class it shows how you would interact with the dal.
No comments:
Post a Comment