Need a demo or tutorial of a simple SQL Database with a 3 Layer modell
-
First please excuse my bad english. As you can asume it's not my native language.... I'm using SQL Server Compact Edition and Visual Basic 2015 and i did a few programs with SQL-Databas-Access so far. This programs where quite simple. They read the whole table at the beginning into a Dataset, work with this and write it back when the application is closed. Now i need some more secure access and found some information that it's better to cut the database Acces from the gui and the business logic - all three called layer. What i need or what i'm asking for is a small sample application with just one Database-Table - let's name it "Persons" with the fiels "Person-Id" (the key), "Person-Firstname", "Person-Lastname", "Person-DateOfBirth". GUI should have separate fields for each of the given fields. Acces should be Record by Record. (Input the Id, if exist show the related data in the gui, if not show empty fields, with a save button to change values / write the changes to tha database.) Business logic may just check if the DateOfBirth is in a range from 1.1.1900 to 31.12.2099. How should my class look like to build all three layers? Maybe this is to much described in detail... I just want to see a class representing all 3 layers to handle some persons data ... Is this possible? Whould someone be so kind? This would help me so much in understanding!!! Thank you very, very much!
-
First please excuse my bad english. As you can asume it's not my native language.... I'm using SQL Server Compact Edition and Visual Basic 2015 and i did a few programs with SQL-Databas-Access so far. This programs where quite simple. They read the whole table at the beginning into a Dataset, work with this and write it back when the application is closed. Now i need some more secure access and found some information that it's better to cut the database Acces from the gui and the business logic - all three called layer. What i need or what i'm asking for is a small sample application with just one Database-Table - let's name it "Persons" with the fiels "Person-Id" (the key), "Person-Firstname", "Person-Lastname", "Person-DateOfBirth". GUI should have separate fields for each of the given fields. Acces should be Record by Record. (Input the Id, if exist show the related data in the gui, if not show empty fields, with a save button to change values / write the changes to tha database.) Business logic may just check if the DateOfBirth is in a range from 1.1.1900 to 31.12.2099. How should my class look like to build all three layers? Maybe this is to much described in detail... I just want to see a class representing all 3 layers to handle some persons data ... Is this possible? Whould someone be so kind? This would help me so much in understanding!!! Thank you very, very much!
-
First please excuse my bad english. As you can asume it's not my native language.... I'm using SQL Server Compact Edition and Visual Basic 2015 and i did a few programs with SQL-Databas-Access so far. This programs where quite simple. They read the whole table at the beginning into a Dataset, work with this and write it back when the application is closed. Now i need some more secure access and found some information that it's better to cut the database Acces from the gui and the business logic - all three called layer. What i need or what i'm asking for is a small sample application with just one Database-Table - let's name it "Persons" with the fiels "Person-Id" (the key), "Person-Firstname", "Person-Lastname", "Person-DateOfBirth". GUI should have separate fields for each of the given fields. Acces should be Record by Record. (Input the Id, if exist show the related data in the gui, if not show empty fields, with a save button to change values / write the changes to tha database.) Business logic may just check if the DateOfBirth is in a range from 1.1.1900 to 31.12.2099. How should my class look like to build all three layers? Maybe this is to much described in detail... I just want to see a class representing all 3 layers to handle some persons data ... Is this possible? Whould someone be so kind? This would help me so much in understanding!!! Thank you very, very much!
I think you have misunderstood a little how the three-tier model works. You don't need to re-invent your model for each tier. There are different approaches on how to handle this, but most modern approaches are based on the Model-View-Something(MV*) architecture (MVC, MVVM, MVP...there seem to be new ones daily). Each of these map to the three-tier architecture in slightly different ways, but there are consistent points. A Model is a an object that is solely a data container. It should implement no business logic, and in your case will represent a single record from the database. It's basically just a data container. The other consistent element is the View, or UI. Any UI interaction logic should live here, to include wiring for UI event handlers and any UI-specific logic. This is where it can become easy to get lost and break the pattern, but play with it a little and you'll start to get it. The last part of the MV* architecture is how the business layer is implemented. Ideally, the business layer should server as an intermediary between the DAL and the UI, and depending on implementation there can be a varying level of success with that. I suggest you have a look around at some resources regarding these patterns; there is a lot available. Which one you start with depends a lot on what sort of applications you are writing: web apps almost invariably fall to the MVC side while Windows desktop apps generally end up in an MVVM world. Just don't let yourself get confused by MVC.NET, that's a specific implementation from MicroSoft.
"There are three kinds of lies: lies, damned lies and statistics." - Benjamin Disraeli
-
I think you have misunderstood a little how the three-tier model works. You don't need to re-invent your model for each tier. There are different approaches on how to handle this, but most modern approaches are based on the Model-View-Something(MV*) architecture (MVC, MVVM, MVP...there seem to be new ones daily). Each of these map to the three-tier architecture in slightly different ways, but there are consistent points. A Model is a an object that is solely a data container. It should implement no business logic, and in your case will represent a single record from the database. It's basically just a data container. The other consistent element is the View, or UI. Any UI interaction logic should live here, to include wiring for UI event handlers and any UI-specific logic. This is where it can become easy to get lost and break the pattern, but play with it a little and you'll start to get it. The last part of the MV* architecture is how the business layer is implemented. Ideally, the business layer should server as an intermediary between the DAL and the UI, and depending on implementation there can be a varying level of success with that. I suggest you have a look around at some resources regarding these patterns; there is a lot available. Which one you start with depends a lot on what sort of applications you are writing: web apps almost invariably fall to the MVC side while Windows desktop apps generally end up in an MVVM world. Just don't let yourself get confused by MVC.NET, that's a specific implementation from MicroSoft.
"There are three kinds of lies: lies, damned lies and statistics." - Benjamin Disraeli
I heared about MVC so far. This is what a mean. Sorry if i asked my question the wrong way. My goal is a windows desktop app using win forms. Of course a want to learn it from the basics but i wasn't able to find some tutorials about that and on the other hand i often lerned by having a closer look on an ready example... Do you know a basic tutorial or example about mvc or mvvm? Many, many thanks in advance.
-
I heared about MVC so far. This is what a mean. Sorry if i asked my question the wrong way. My goal is a windows desktop app using win forms. Of course a want to learn it from the basics but i wasn't able to find some tutorials about that and on the other hand i often lerned by having a closer look on an ready example... Do you know a basic tutorial or example about mvc or mvvm? Many, many thanks in advance.
Generally you're looking at MVVM then, which is more commonly associated with WPF, which may be the path you want to take. WinForms is a supposedly deprecated technology and MS may remove support for it "someday", but WPF is still in wide use. There are many, many examples and tutorials available on CP. Just searching the articles will give you a abundance of choice: [CP MVVM Search](https://www.codeproject.com/search.aspx?q=mvvm+tutorial&x=0&y=0&sbo=kw) You can likely safely ignore the articles that directly address specific controls and technologies until you get the gist.
"There are three kinds of lies: lies, damned lies and statistics." - Benjamin Disraeli
-
I heared about MVC so far. This is what a mean. Sorry if i asked my question the wrong way. My goal is a windows desktop app using win forms. Of course a want to learn it from the basics but i wasn't able to find some tutorials about that and on the other hand i often lerned by having a closer look on an ready example... Do you know a basic tutorial or example about mvc or mvvm? Many, many thanks in advance.