Click here to Skip to main content
15,885,127 members
Articles / Desktop Programming / Windows Forms

Three-tier .NET Application Utilizing Three ORM Technologies

Rate me:
Please Sign up or sign in to vote.
4.95/5 (118 votes)
30 Jan 2010CPOL109 min read 163.8K   4.4K   437  
LINQ to SQL, Entity Framework, and NHibernate used in a parallel fashion in a three-tier WinForms application.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ui=UIInterface;
using uib=UIInterface;
//using sch = Schema;
using s = System;
using cu = ClientUtil;
//using ddal = DomainDAL;
using du = DomainUtil;
using u = Util;
using ns = Presenter;
using si=ServiceInterface;

namespace Presenter
{
	public class WinUI : C, ui.WinUI.IPresenter
	{
		si.IService _Service;
		ui.WinUI.IView _view;
		uib.IViewFactory _ViewFactory;
		string _strDBInitString;
		protected override UIInterface.IView GetView(){return _view;}
		public WinUI(ui.WinUI.IView aView, uib.IViewFactory theViewFactory, si.IService theService, string strDBInitString)
		{
			_strDBInitString= strDBInitString;
			_view = aView;
			_Service = theService;
			_view.SetPresenter(this);
			_ViewFactory = theViewFactory;
		}
		
		Presenter.DltAllocAccnts CreateDltAllocAccntsPresenter	(){return new Presenter.DltAllocAccnts	(	_ViewFactory, _Service);}
		Presenter.DltAllocs		 CreateShowDltAllocPresenter	(){return new Presenter.DltAllocs		(	_ViewFactory, _Service);}
		Presenter.Items			 CreateShowItemsPresenter		(){return new Presenter.Items			(	_ViewFactory, _Service);}
		Presenter.NWAccntDlts	 CreateNWAccntDltsPresenter		(){return new Presenter.NWAccntDlts		(	_ViewFactory, _Service);}
		Presenter.NWAccnts		 CreateNWAccntsPresenter		(){return new Presenter.NWAccnts		(	_ViewFactory, _Service);}
		Presenter.Ownership		 CreateOwnershipPresenter		(){return new Presenter.Ownership		(	_ViewFactory, _Service);}
		Presenter.Participants	 CreateParticipantsPresenter	(){return new Presenter.Participants	(	_ViewFactory, _Service);}
		Presenter.Summary		 CreateSummaryPresenter			(){return new Presenter.Summary			(	_ViewFactory, _Service);}
		Presenter.Transactions   CreateTransactionsPresenter	(){return new Presenter.Transactions	(	_ViewFactory, _Service);}

		public void ShowDltAllocAccntsForm(			)
		{
			u.FuncCommand<DltAllocAccnts> cmd = new Util.FuncCommand<DltAllocAccnts>(CreateDltAllocAccntsPresenter, null);
			this.ExecuteWithErrorHandlingAndBusyIndicator(cmd);
			if(cmd.Result!=null)
				cmd.Result.Show();
		}
		public void ShowDltAllocForm(				)
		{
			u.FuncCommand<DltAllocs> cmd = new Util.FuncCommand<DltAllocs>(CreateShowDltAllocPresenter, null);
			this.ExecuteWithErrorHandlingAndBusyIndicator(cmd);
			if(cmd.Result!=null)
				cmd.Result.Show();
		}
		public void ShowItemsForm(					)
		{
			u.FuncCommand<Items> cmd = new Util.FuncCommand<Items>(CreateShowItemsPresenter, null);
			this.ExecuteWithErrorHandlingAndBusyIndicator(cmd);
			cmd.Result.Show();
		}
		public void ShowNWAccntDltsForm(			)
		{
			u.FuncCommand<NWAccntDlts> cmd = new Util.FuncCommand<NWAccntDlts>(CreateNWAccntDltsPresenter, null);
			this.ExecuteWithErrorHandlingAndBusyIndicator(cmd);
			if(cmd.Result!=null)
				cmd.Result.Show();
		}
		public void ShowNWAccntsForm(				)
		{
			u.FuncCommand<NWAccnts> cmd = new Util.FuncCommand<NWAccnts>(CreateNWAccntsPresenter, null);
			this.ExecuteWithErrorHandlingAndBusyIndicator(cmd);
			if(cmd.Result!=null)
				cmd.Result.Show();
		}
		public void ShowOwnershipForm(				)
		{
			u.FuncCommand<Ownership> cmd = new Util.FuncCommand<Ownership>(CreateOwnershipPresenter, null);
			this.ExecuteWithErrorHandlingAndBusyIndicator(cmd);
			if(cmd.Result!=null)
				cmd.Result.Show();
		}
		public void ShowParticipantsForm(			)
		{
			u.FuncCommand<Participants> cmd = new Util.FuncCommand<Participants>(CreateParticipantsPresenter, null);
			this.ExecuteWithErrorHandlingAndBusyIndicator(cmd);
			if(cmd.Result!=null)
				cmd.Result.Show();
		}
		public void ShowSummaryForm(				)
		{
			u.FuncCommand<Summary> cmd = new Util.FuncCommand<Summary>(CreateSummaryPresenter, null);
			this.ExecuteWithErrorHandlingAndBusyIndicator(cmd);
			if(cmd.Result!=null)
				cmd.Result.Show();
		}
		public void ShowTransactionsForm(			)
		{
			u.FuncCommand<Transactions> cmd = new Util.FuncCommand<Transactions>(CreateTransactionsPresenter, null);
			this.ExecuteWithErrorHandlingAndBusyIndicator(cmd		);
			if(cmd.Result!=null)
				cmd.Result.Show();
		}

	//	public void ShowTransactionForm(			){new Presenter.Transaction(			_ViewFactory);}
	//	public void ShowTransactionItemsForm(		){new Presenter.TransactionItems(		_ViewFactory);}
	//	public void ShowTransactionNWAccntDltsForm(	){new Presenter.TransactionNWAccntDlts(	_ViewFactory);}

		public void VerifyAll()
		{
			try
			{
				_view.ShowBusyIndicator();
				_Service.VerifyAllTransactions();
				_view.ClearBusyIndicator();
				_view.ShowSimpleMessage("All transactions are in balance.");
			}
			catch (System.Exception ex)
			{
				_view.ClearBusyIndicator();
				_view.ShowException(ex);
			}
		}
		public void Post()
		{
			try
			{
				_view.ShowBusyIndicator();
				_Service.Post();
				_view.ClearBusyIndicator();
				_view.ShowSimpleMessage("Post complete.");
			}
			catch (System.Exception ex)
			{
				_view.ClearBusyIndicator();
				_view.ShowException(ex);
			}
		}
		public void Test()
		{
			try
			{
				_view.ShowBusyIndicator();
				_Service.Test();
			//	_Service.InitDatabase(_strDBInitString);
				_view.ClearBusyIndicator();
				_view.ShowSimpleMessage("Test complete.");
			}
			catch (System.Exception ex)
			{
				_view.ClearBusyIndicator();
				_view.ShowException(ex);
			}
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer (Senior) Austin Regional Clinic
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions