Implementing MVC architecture in Windows Form Application [Resolved]

Posted by Srikrishna777 under C# on 10/3/2009 | Views : 28452 | Status : [Member] | Replies : 18
Hi ,

I am Srikrishna Murthy.
I want to implement MVC architecture in a windows application.My application should have Model-View-Controller.While designing the application I am not very clear about how to make calls from the controller to the downlayers.How we can achieve this one.I hope we will have some interfaces and we have to implement them.But,I am not exactly sure how to do this.

My scenario:

Say for example,
1)I have a windows form with two text boxes and 4 buttons for ADD,SUB,MUL,DIV
2)so,when user clicks on any button,from here the data goes to controller.
3)From the controller,How to pass the data to the downlayers.

Please help me .Thanks Inadvance.

Thanks,
M.Srikrishna Murthy




Responses

Posted by: Pramodmca09 on: 10/4/2009 [Member] Starter | Points: 50

Up
0
Down

Resolved
Fisrt Create new project in C# windows. Take 1 button three text boxes .


Then right click on solution 'Your Project name ' select Add new project. then select class liabrary from Add New Project window Name it Business Layer.
Repeat same step and add another class liabrary Name it DataLayer.
and add one more liabrary name it Business Object.

You will see three class Liabrary in solution explorer.
and Class1 under each lib. Rename Class1 to Addition.cs for Addition opration.

double clik on Addition.cs under business object class lib. You will see class defination. define three int veriable. (type prop and press tab twise )
private int myVar; public int MyProperty { get { return myVar; } set { myVar = value; } }
code will apper. change MyVar to Num1
MyProperty to _Num1.
Repeat above step and Create NUM2

You have defined Business object wich wil interact with DL(Data Layer), BL(BusinessLayer), UI.

Now add refernces to project.
Right click on project name under Solution Expl. select Add References.
Under Add Reference selct project tab. Select Business Object(BO) and BL.
Right click on BL under Solution Expl. slect Add refernce slect DL,BO and enter.

Now double click on Button 1 at top form1.cs add namespace
using BusinessLayer;
using BusinessObject;

On button1 click event Create object of BusinessObject.Addtion,
BusinessObject.addition objAddition = new BusinessObject.addition();

set values for NUM1 and NUM2 from text boxes.
objAddition._NUM1 = Convert.ToInt32(textBox1.Text); objAddition._NUM2 = Convert.ToInt32(textBox2.Text);

Now create object of BusinessLayer.Addtion
call
int result = objAdditionBL.AddtionOfNumber(objAddition);
Now go to Addition.cs Under BL add namespace , BusinessObject and DataLayer.
define method

public int AddtionOfNumber(BusinessObject.addition objAddition) { return objAddition._NUM2+objAddition._NUM1; }
run the program


if any dought please let me know
 Download source file

Srikrishna777, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sshinde on: 11/3/2010 [Member] Starter | Points: 25

Up
0
Down
Dear M.Srikrishna Murthy

I am Swati Shinde.I want to know about MVC Design Pattern or Architecture in windows application.(Using VB.Net) I want to give seminar in the office for the same. so i want more info( PPT + Sample Application ) about the same. MVC is completely new topic for me. i don't know much about the same.
so plz Help me... Thanks in advance...

Srikrishna777, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pramodmca09 on: 11/3/2010 [Member] Starter | Points: 25

Up
0
Down
Hi Swati

I thing we can't have MVC implemention in windows but we can achieve it using n-tier architecture. At beginning of the post i have described how to implement n-tier architecture.
i assume that you want 3 Separate tiers and "group" modules by tier?

For e.g

Model View Controller

module A module A module A
module B module B module B

If that's it, then, yes it's possible.


Regards
Pramod V. Choudhari
Plz Refer attachments
 Download source file

Srikrishna777, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sshinde on: 11/4/2010 [Member] Starter | Points: 25

Up
0
Down

Hi Pramod,

Thanks for everything...

can u suggest another topics for seminar just for my friend.
if u have then pls send respective info and details (PPT + sample application)

thanks in advance..

Srikrishna777, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pramodmca09 on: 11/4/2010 [Member] Starter | Points: 25

Up
0
Down
Hi Swati..

I hope my previous post helped you.

Here by I am attaching ppt for WCF presentation go through all material and prepare .also the link will help to learn WCF.

All The Best and Happy Diwali.

If you come to know any opening for ASP.NET developer Pune location (1-2 Yrs) Plz let me know .

http://msdn.microsoft.com/en-us/netframework/first-steps-with-wcf.aspx

 Download source file

Srikrishna777, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dhaval.Mdk on: 6/5/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Pramod n all other guys,
I am very new to C# and need some good application of MVC in C#.
I downloaded Pramod's attachment but I found it very basic and just doing addition.
Pramod can you please send me some other good application of MVC in C#. And other guys, you too.
Thank you all very much.

Regards,
Dhavalkuamar

Srikrishna777, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 6/5/2012 [Member] Silver | Points: 25

Up
0
Down
http://www.c-sharpcorner.com/uploadfile/rmcochran/mvc_intro12122005162329pm/mvc_intro.aspx

Regards,
Singaravel M

Srikrishna777, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pjadhav on: 8/25/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,
Your explanation is too good. Now i want help to code MVC in windows forms application.
Do you know about populator and nhibernate. I like to learn these things.
Can you please help me????

Srikrishna777, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndhamu99 on: 1/20/2016 [Member] Starter | Points: 25

Up
0
Down
We can do Model-View-Controller for a Windows.Forms Application.
I found one the sample from http://www.ii.uni.wroc.pl/~wzychla/mvc.html
 Download source file

Srikrishna777, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Srikrishna777 on: 10/6/2009 [Member] Starter

Up
0
Down
Hi Pramod,

I am Sorry for the late reply.
Thankyou very much indeed for explaining me the concept very clearly and sending the code.Really,It has improved some confidence in me to develop MVC based windows applications.And I have a few doubts on MVC,which I hope you will clarify.They are..

Q 1)The application which you have sent me should be considered as three layer or four layer.

UI--->BL--->BO--->DL or UI--->BL---->DL

Q 2)If I want to develop a MVC based Windows Client server application(using .Net Remoting or Webservices),then how to maintain the interfaces.i.e Basically I heard about we use Interface programming while developing client server applications.And How to call the methods from the Controller.
As far as I know,I am following this architecture
UI-->Controller-->System Interface-->Business Interfae-->DA layers
Is this correct approach..?
If you have any sample piece of code,Can you please post that.


Thanks,
M.Srikrishna Murthy




Srikrishna777, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pramodmca09 on: 10/8/2009 [Member] Starter

Up
0
Down
Sorry for late reply basically I'm fresher and Whtever i learnt from my brother I explianed. I dont know about .net remoting If you are aware of it can you tell me in short or send me usefull links to learn .net remoting.
Ans For Q-1>
See Business Object is not treated as Layer. It's common to all the layer and through which the data is moving from one layer to other layer .

UI<-->BL<-->DL>

BO

is common to all.

Srikrishna777, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Srikrishna777 on: 10/9/2009 [Member] Starter

Up
0
Down

Thankyou very much for clarifying my doubts.
And as you said that,you are fresher and if we are looking out for a job on .Net,my advice would be better to learn some advanced concepts like .Net Remoting,MVC architecture in applications,Asynchronous programming with Delegates,Message Queues,Windows services etc.These concepts will add weightage to your resume and you can download some samples of all the above concepts and try with them.If you have any doubt like how to implement,how to start,or if you stuck any where in the middle,I will help you..I also read the materials by downloading.Just go through the simples ones first.And..Where are you from..?Where did you finish your MCA.

Thanks,
M.Srikrishna Murthy

Srikrishna777, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Srikrishna777 on: 10/9/2009 [Member] Starter

Up
0
Down

Thankyou very much for clarifying my doubts.
And as you said that,you are fresher and if we are looking out for a job on .Net,my advice would be better to learn some advanced concepts like .Net Remoting,MVC architecture in applications,Asynchronous programming with Delegates,Message Queues,Windows services etc.These concepts will add weightage to your resume and you can download some samples of all the above concepts and try with them.If you have any doubt like how to implement,how to start,or if you stuck any where in the middle,I will help you..I also read the materials by downloading.Just go through the simples ones first.And..Where are you from..?Where did you finish your MCA.

Thanks,
M.Srikrishna Murthy

Srikrishna777, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pramodmca09 on: 10/9/2009 [Member] Starter

Up
0
Down
I'm from Pune. I have completed my MCA from Pune University.
Right now I'm working with Mahindra Hinoday Industries Ltd. Bhosari Pune. in IT-Dept.
Actually I tried lost to get job in IT company but due this slow down I struggled bit. So I got oppertunity to work this company. And I'm not satisfied with the compony beacause I dont have any work to do so I'm tring to learn .Net so that when I will leave Company. I should able face Core IT Industries. I used to be seat Idle for three five days there is nothing to do and also my seniors also not asking me to do.

Still Im trying to devlope small application in .net. for manipulating Excel sheets which are the reports downloaded from SAP system. I'm feeling this will not be enough to show experince in .Net. So can you help me how can I go in next few month so that I will get knowlege of .net . I will be very thank full.

What are you doing ?And where are from.?
Thanks,
Pramod Vilasrao Choudhari.




Srikrishna777, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Srikrishna777 on: 10/12/2009 [Member] Starter

Up
0
Down
Hi Pramod,

since you want to be perfect(to face the interview) on .net,Be good at oops concepts and other topics which i have mentioned earlier like .Net Remoting etc..Because,We cant such topics in fresher or experienced resumes also mostly..If you can learn those concepts and if you add them to your resume,I hope you will have more chances to get into an IT firm.Concepts like ADO.NET,stored procedures are imp for intervews.prepare well...Since you are not engaged with much work,you can focus on these things.within 20 days ,uou will get an idea..Then you can try out in the market....All the best....
Feel free to contact if you have any quries..

Thanks,
M.Srikrishna Murthy,
Minvesta Infotech Limited,
Hyderabad.



Srikrishna777, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dark.wadia on: 11/18/2009 [Member] Starter

Up
0
Down
Hi,
Will you please explain Model View Architecture using Data Layer, Business Layer, GUI, Business Object.
I am little confused about it. how to use Data layer?
and one more thing I want to tell you that.
I have used MVC architecture in MFC..(View, mainframe, Doc, Application).
In that, Doc is working as Both Model and Controller.
Now I want to make separate in C#. windows application.
But I never used in C# .net (windows forms).
Now I have to shift my MFC project to .net(C#).
So I need help about same.

Srikrishna777, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Srikrishna777 on: 11/21/2009 [Member] Starter

Up
0
Down
Sure,with pleasure.
In C# windows applications,we can implement MVC architecture.

Role of View:
1) To display the data on the UI controls.
2) For Validations .
3) view should call the controller methods.
for example,assume Employee UI

Role of Controller
1)Controller will just forward the function calls to the further down layers.
(They can be System Interface or Business interface or DA layers) and get processed them.
2)Each entity Should have its own controller
Say for example,If Employee is an entity.Fot that we will write EmployeeController.

Role of Model
1)All database related operations will be taken place here

Developing MVC in Windows applications

Step1 : create a class library(Dll) for all the data classes.i.e
Include all the data classes in a single project.So,that it is easier for us to add this dll to other projects.(like to UIProject or Sys Interface or Biz Interface or DAProject)

step2 : create a class library project and write all data access functionalities
ex: InsertEmployee(Employee emp),UpdateEmployee(Employee emp) etc

Step 3:create an interface which should have the required functionalities from the DA layers.
i.e punlic interface IEmployee
{
void InsertEmployee(Employee emp);
Void UpdateEmployee(Employee emp)
}

step 4: Create a class controller which will implement this interface methods

Step 5:Call the controller methods from the userinterface.

In between,You can have Sys,Biz layers depending on the application.

Hope this info will helpful .
If any queries,feel free to contact.
Thanks,
M.Srikrishna Murthy











Srikrishna777, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dark.wadia on: 11/22/2009 [Member] Starter

Up
0
Down
Thanks a lot by explaining MVC architecture in detail.
Now I will try to implement the same using C#. I may contact you again if I have doubt(s).
Thanks a lot again.


Srikrishna777, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response