Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have created student management system project in c#,which contain windows forms,and every form have their own database connection and database queries etc.I want to divide my project into different layers,business lyr,presentation lyer,data logic lyr etc.How can i do this please guide me.I want that sql related data contains sql class and other class contains other data.how can i divide my project into different classes,into layers.
Thanks in advance
Posted

If you've already written it, it's going to be difficult - it's a lot easier to start from a clean slate with a new solution, and add three projects: PL, BL, and DL and then to design the interfaces between them.

Starting with a "finished item" and trying to separate it is like trying to rebuild a bungalow into a 3 story house with the same floor size while you are still living in it! :laugh:
It's a lot easier if you start constructing the new building at the other end of the garden and only demolish the bungalow when it's finished.
 
Share this answer
 
Comments
Hameed Khan 15-Jan-16 8:42am    
Don't provide me real life examples?I ask tell me the process that how can i create different class .for exmple.if i create classes which contain sql data then in windows forms how can i access sql classes data
F-ES Sitecore 15-Jan-16 9:11am    
I struggle to see how you have written a student management system yet you don't know how classes work or how to create them. Google "n-tier system c#" and you'll find examples of how the classes (or projects if you choose to split your app into multiple projects) work and interact. It's not a particularly trivial task and it is already well-documented so look for the examples that already exist. Part of being a student is being academic, so if you can't use google then you're going to struggle with your course in general.
Vijay Gill 15-Jan-16 9:42am    
To me it seems, he is not asking for an n-tier design but separation of concerns. He mentions he has forms with each one of those having their own ADO connections, queries and possibly other duplication of code / logic. This can be achieved in an iterative process on a per-form basis and is tedious but not impossible.
OriginalGriff 15-Jan-16 10:04am    
I'd agree - tedious, but not impossible.
The trouble is that it generally doesn't produce a "good" result - it ends up with a mishmash of design / concern / layer which is harder to maintain and support than either the original or a "true" n-layer solution.
Given it's a homework exercise, I'd start again! :laugh:
Vijay Gill 15-Jan-16 10:40am    
There is no harm in trying though. Re-factoring is an important part of a developer's job. One never joins a job and says "ah the only way to improve this project is to re-write it!". Even if it is a homework, it will teach him how to work on a project which was written ages ago and needs major heart surgery.
Couple of useful links -
Understand 3- Tier Architecture in C#[^]
Walkthrough: Creating an N-Tier Data Application[^]

As mentioned earlier, these will work best in a new solution (not in one that has already been created).
 
Share this answer
 
Comments
Hameed Khan 15-Jan-16 14:19pm    
Thanks for answering my question,but I have a problem.Actually i have 9,10 windows forms,all are forms and every form have their own sql connection string and query etc..Every form have their own code.Can you tell me which part of code replace in which folder/layer etc.I want that all sql forms code replace in SQL layer,,and other forms layer replace in other layer etc.How can i do this?Thanks
Create desired layers in their own project and move code as appropriate one part a a time. If your code is not well structured, then you might some some intermediate steps...

One such step might be to make some moved code public first so that you don't have to change every thing at once. Then when caller is updated to use layer interface make the implementation internal.

Use source revision control and do checkins often. Test a lot. Do small steps. Do unit testing.

For complex project without proper unit testing, it might be hard to update code without breaking it too much if the code is not well enough designed.
 
Share this answer
 
Comments
Hameed Khan 15-Jan-16 14:02pm    
@Philippe Thanks for answering my question,but I have a problem.Actually i have 9,10 windows forms,all are forms and every form have their own sql connection string and query etc..Every form have their own code.Can you tell me which part of code replace in which folder/layer etc.I want that all sql forms code replace in SQL layer,,and other forms layer replace in other layer etc.How can i do this?Thanks
Philippe Mori 15-Jan-16 14:39pm    
Connections strings and queries should be moved to the data layers. Any low level database related stuff.

Thus if you have a lot of logic, create a business layer in between (another project) and move those functions.

One thing that is sure is that the database layer should not have any UI related stuff.
Hameed Khan 16-Jan-16 1:18am    
How can i move my conncetion strings and queries of every form in data layers?I mean i have buttons in windows forms and every button contains sql connection and sql quries etc in individual form?Then how can i do this?
Philippe Mori 16-Jan-16 8:57am    
Well, if given all the advices you still have no idea of what to do, then you should search for tutorials or books at your level.

There is no such thing as a few changes and suddently your application is multi layers. Quite the contrary, it can be a very hard job and in your case it will probably be very hard since it seems that you have no architecture or code sharing at all. If so, it would be probably be best to learn how it should work and then restart the application from stratch using distinct projects for each layer.

Question like how do I move connection string does not make much sense. You create a new class and move stuff into it and then use it. If you cannot understand even that, then you are not ready to make such changes anyway.

Even for expert, it can take a lot of time to refactor an existing application properly using the right tools (Visual Studio Enterprise could help here). If you application is poorly designed, is complex and large, then it might even take more time to refactor it or rewrite it than it took to write it the first time...

It depends a lot on the existing code. Does all your functions and classes respect the "Single Responsability Principle"? If your code do everything in the same function from the connection string to the UI updating including all business logic, you will have a lot of works.

It is not possible to give you much more advice if we don't know what your code look like and you seem to not understand any of the answer or comment. At that point, it is up to you to learn how it works.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900