Introduction

Rocket Framework is a .Net framework 4.0 open source library. This article will demonstrate using 'RocketFramework' to develop a windows form based master record administrative application very fast.

Start by Creating your Data Access Layer (DAL)

  • Create a Class Library project called ‘Rocket.Data’ and add the RocketRepository.cs to it.
  • Get the 'Rocket.Windows.Framework.dll' and have it referenced to this newly created ‘Rocket.Data’ project.
  • Add a new item of type ‘Entity Data Model’ and load your database to it. It order to do that you need to right click on the project and select to add 'New Item'.
  • In the popup screen select the ‘ADO.NET Entity Data Model’ as given below

CreateModel.PNG

  • Select ‘Generate From Database’ and proceed.

CreateModel1.PNG

  • Give required details to point this program to your database. This include giving the connection details and also asking the system to include the DB connection details in the application configuration file.
  • In the next prompted screen, select the tables that you wanted to interact with or include in this program. In general you select all the tables of the database. However for this demo I have only select three tables from my database.
  • Once everything is completed you will come to the screen given below.

CreateModel11.PNG

  • What I have here is a simple but promising enough data model to demonstrate the capability of this framework.
  • Now you need to configure the generic repository class with the name ‘RocketRepository’ that you find inside the ‘Rocket.Data’ project, to point to the Entity Model you just created. In order to do this you need to modify the two places where it specify the entity model name. (name it with the name of the entity data model you just created)
  • Now without much hussel, you just completed creating your generic DAL or so called data access layer.
  • See how I have done it below

CreateModel111.PNG

Create the Business Logic Layer (BLL)

  • Add a new ‘Class Library’ type project named ‘Rocket.Bll’.
  • Add references to
    • Rocket.Windows.Framework dll
    • System.ComponentModel.DataAnnotations’ library
    • System.Entity.Data library
    • AutoMapper dll
    • System.Configuration library
  • Add three handler classes named 'HandlerQuestion', 'HandlerReaderApplication' and 'HandlerReaderApplicationQuestion'.
  • Create a new folder called 'Models' and follow-up to add few model classes to represent our data models.
  • Once you complete everything, you will see your project like the one shown below.

Bll1.PNG

Note: When you create your model classes, make sure to use the respective mapping table's attributes (Column names) to name the properties. As an example, if you have a field called ‘UserName’ in a table called ‘UserData’ then first create the model class (deriving from the BaseObject) with the same name but with a 'View' suffix. So it will be ‘UserDataView’. Then have the ‘UserName’ defined as a property of the view class. Whenever you are not following this rule, you still can use the framework but then you have to explicitly map the properties of the objects back and forth using automapper mapping expressions (We will be coming to that part of the code in a minute).
  • Additionally you have to use the ‘Id’ property of the ‘BaseObject’ to map the primary key of the respective table
  • One of such model class that I have created is given below for your reference.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rocket.Windows.Framework;
using Rocket.Bll.Models;

namespace Rocket.Bll.Models
{
public class ReaderApplicationView : BaseObject
{
private string _Code;
public string Code
{
get { return _Code; }
set { _Code = value; }
}
private string _Name;
public string Name
{
get { return _Name; }
set { _Name = value; }
}

private List<ReaderApplicationQuestionView> _QuestionList;
public List<ReaderApplicationQuestionView> QuestionList
{
get { return _QuestionList; }
set { _QuestionList = value; }
}
}
}


  • Now let’s see how we can develop a handler class for this view model. The respective handler class implementation is pretty simple. The one I have created for managing the ‘ReaderApplicationView’ is given below.
  • As you can see, I have implented the 'BaseHandler' and have manuver the concrete handler in a way so that it create the generic ‘BaseHandler’ instance to operate with the respective 'ReaderApplicationView' view class and the data object (also called data entity).
  • Finally I also have passed the respective 'RocketRepository' object via the constructor too. Defining the mapping expression is optional except for mapping the table primary key to 'Id' property of the business object.
  • If you want more details about auto-mapper please refer the link here>>.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rocket.Data;
using Rocket.Bll.Models;
using Rocket.Windows.Framework;
namespace Rocket.Bll
{
public class HandlerReaderApplication : BaseHandler<ReaderApplicationView
, ReaderApplication>
{
public HandlerReaderApplication()
: base(RocketRepository<ReaderApplication>.Instance)
{
}
protected override Type LogPrefix
{
get { return this.GetType(); }
}
public override void ForwardMap(AutoMapper.IMappingExpression<ReaderApplicationView
, ReaderApplication> mappingExpression)
{
mappingExpression
.ForMember(dest => dest.ReaderApplicationId, opt => opt.MapFrom(src => src.Id));
}
public override void BackwardMap(AutoMapper.IMappingExpression<ReaderApplication
, ReaderApplicationView> mappingExpression)
{
mappingExpression
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.ReaderApplicationId));

}
}
}

 

  • Noticed that I have mapped the ‘ReaderApplicationId’, which is the primary key of the ‘ReaderApplication’ table to the ‘Id’ property of the ‘Read’rApplicationView'.
  • Once you complete the coding for both business objects, you are done with the BLL (Business Logic Layer) development too.

Create the User-Interface (UI) Layer

  • Create a new ‘WindowsFormApplication’ project.
  • Add reference to the above two projects you just created and also to the ‘Rocket Framework’ dll.
  • Add a folder called ‘Child Controls’ and follow up to add the following two classes.
  • ReaderApplicationDataGridView
  • ReaderApplicationManager
  • Add an ‘User Control’ called ‘ReaderApplicationData’.
  • Once all these done you will see your project as bellow.

UI1.PNG

  • Now just like it was with the Business Logic Layer, you need to create your generic instances to support the required operations.
  • Check the images below understand the few lines of code that you need to write to complete the UI layer development.

ReaderApplicationDataGridView Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rocket.Windows.Framework;
using Rocket.Bll;
using Rocket.Bll.Models;

namespace MainForm.ChildControls
{
public class ReaderApplicationDataGridView : BaseGridView<HandlerReaderApplication
, ReaderApplicationView>
{
public ReaderApplicationDataGridView()
: base(new HandlerReaderApplication())
{
}
}
}

ReaderApplicationManager Class:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rocket.Windows.Framework;
using RocketTest.Bll;
using RocketTest.Bll.Models;
using RocketTest.Data;

namespace RocketTest.ChildControls
{
public class ReaderApplicationManager :
BaseManager<HandlerReaderApplication,ReaderApplicationView,
ReaderApplicationData, ReaderApplicationDataGridView>
{
public ReaderApplicationManager()
: this(new HandlerReaderApplication())
{


}
public ReaderApplicationManager(HandlerReaderApplication handerReaderApplication)
: base(handerReaderApplication, new ReaderApplicationData(),
new ReaderApplicationDataGridView())
{

}


}


}

 

Let ‘generics’ code. You just have to trust the framework and need to follow 
this pattern and continue to code any number of business objects.
  • Things become relatively harder, as you comes to conding of the business object's editting panel.
  • Open the 'ReaderApplicationData' user control
  • Find the IDE 'tool bar' item where it allows managing ‘Data Sources’
  • Select to add a new data source
  • Select ‘Object’ as your data source select the ReaderApplicationView to create the binding source.
  • Once everything is completed, you need to de-select some of the properties that you do not want to see in your Form-View.
  • Once the object's detail view (not the list view) is created, drag and drop it on to the newly created ‘ReaderApplicationData’ user control.
  • Delete the auto created top navigation panel of the form view.
  • Check the screen below to see how I have done it

UIAddSourceObj1.PNG

  • Now the hard part if over. As the next step open the source code of this user control and edit to derived it from the 'BaseData' class, once you are completely implement the 'Data' user control.
  • As you can see below, do not forget to pass the reference of the ‘Bindingviewsource’ to the generic base class.

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Rocket.Windows.Framework;
using Rocket.Bll.Models;



namespace MainForm.ChildControls
{
public partial class ReaderApplicationData : BaseData
{

private ReaderApplicationQuestionManager readerAppQuestionManager;
public ReaderApplicationData()
{
InitializeComponent();
}

public override void SetBindingSource(ref BindingSource raptorBindingSource)
{
raptorBindingSource = this.ReaderApplicationViewBindingSource;
}

protected override void _raptorBindingSource_DataSourceChanged(object sender,
EventArgs e)
{
if (this.BindedView != null)
{
readerAppQuestionManager = new ReaderApplicationQuestionManager(
this
.BindedView.Code);
}
}

public override V MapIt<V>(int Id, V bindedView)
{

BaseObject appView = bindedView;

appView = bindedView;

if (Id == 0)
{
appView = new ReaderApplicationView();
}
appView.Id = Id;
((ReaderApplicationView)appView).Code = this.codeTextBox.Text;

((ReaderApplicationView)appView).Name = this.nameTextBox.Text;
return (V)appView;
}

private void buttonManageQuestions_Click(object sender, EventArgs e)
{
ChildForm<ReaderApplicationView> newForm = new ChildForm<
ReaderApplicationView>(this.BindedView);
readerAppQuestionManager.Dock = DockStyle.Fill;
newForm.Controls.Add(readerAppQuestionManager);
newForm.ShowDialog();
}
}
}

 

  • Now our code is coming to an end..
  • As the final step, make your main form derived from the BaseForm of the 'Rocket Framework'.
  • Then create a new instance of the 'ReaderApplicationManager’ class and add it to the main form.
  • Since Visual Studio 2003 there is a bug reported about IDE not support working with generic user controls, and that bug is still there in VS-2010. Microsoft is afraid on generics and goes wild when the IDE see '<' mark in any User controls. Hence even in VS-2010 you do not have the option of dragging and dropping this manager on to the form.
  • Run the application to see something like this poping-up.

UIFInal.PNG

Final Version

CompleteProduct.PNG

Last edited Jan 31, 2011 at 2:34 PM by rahulshukla, version 7

Comments

kanaida Jul 12, 2011 at 6:09 PM 
A good example be the way is Intuit Quickbooks. You need .net framework to run, guess what, a Winforms app.

kanaida Jul 12, 2011 at 6:08 PM 
WinForms is not dead at all. It's actually what you want to use to build real applications in a company, WPF is prettier, but it's silly eye candy not usually needed inside a business and tossed aside. I've yet to see any company use WPF at all, in fact most do vb6, or .net winforms only.

RocketFramework Apr 8, 2011 at 7:56 AM 
You may be right but...

I first satisfy my needs and then if that is what others also needed then I release it for others too.. so far this is what I need :-)

However, I think I will conver this using Visual Studio Light Switch soon..

GerhardKreuzer Mar 18, 2011 at 5:05 PM 
Hi,
WinForms is dead, so please came up with a WPF or Silverlight application and probably port this app to WinPhone 7.

With best regards

Gerhard