Click here to Skip to main content
15,895,656 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 164.7K   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.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using s = System;
using u = Util;
using ns = WinUI;
using ui=UIInterface.NWAccntDlts;
using uib=UIInterface;
using uitb=UIType;
using uit=UIType.NWAccntDlts;

namespace WinUI
{
	public partial class NWAccntDltsForm : Form, ui.IView
	{

		ui.IPresenter _Prsntr;
		IList<uit.IDataDisplayObject> _oInitialData;
		string _strInitialWhereClause;
		int _iInitialIndexOfAccountOptionDisplay;
		bool _bCloakUIHandlers;
		s.Drawing.Color _colorRightClickArea = s.Drawing.Color.PowderBlue;
		string[] _arrstrAccountOptions;

		System.Windows.Forms.DataGridViewTextBoxColumn _dgvtcTransID		;
		System.Windows.Forms.DataGridViewTextBoxColumn _dgvtcPostID			;
		System.Windows.Forms.DataGridViewTextBoxColumn _dgvtcTransDescrip	;
		System.Windows.Forms.DataGridViewTextBoxColumn _dgvtcTransInstant	;
		System.Windows.Forms.DataGridViewTextBoxColumn _dgvtcAmount			;

		void SetupColumns()
		{
			this._dgv.AutoGenerateColumns = false;
			System.Windows.Forms.DataGridViewCellStyle oNumberColumnStyle = Misc.CreateDataGridViewCellStyleForAmountDisplay();

			this._dgvtcTransID		= new DataGridViewTextBoxColumn();
			this._dgvtcPostID		= new DataGridViewTextBoxColumn();
			this._dgvtcTransDescrip	= new DataGridViewTextBoxColumn();
			this._dgvtcTransInstant	= new DataGridViewTextBoxColumn();
			this._dgvtcAmount		= new DataGridViewTextBoxColumn();

			this._dgvtcTransID		.DataPropertyName	= uit.DataDisplayObjectHelper.FLD_TransID		;
			this._dgvtcPostID		.DataPropertyName	= uit.DataDisplayObjectHelper.FLD_PostID		;	
			this._dgvtcTransDescrip	.DataPropertyName	= uit.DataDisplayObjectHelper.FLD_TransDescrip	;
			this._dgvtcTransInstant	.DataPropertyName	= uit.DataDisplayObjectHelper.FLD_TransInstant	;
			this._dgvtcAmount		.DataPropertyName	= uit.DataDisplayObjectHelper.FLD_AmountAsStr	;	

			this._dgvtcTransID		.HeaderText			= uit.DataDisplayObjectHelper.FLD_TransID		;
			this._dgvtcPostID		.HeaderText			= uit.DataDisplayObjectHelper.FLD_PostID		;
			this._dgvtcTransDescrip	.HeaderText			= uit.DataDisplayObjectHelper.FLD_TransDescrip	;
			this._dgvtcTransInstant	.HeaderText			= uit.DataDisplayObjectHelper.FLD_TransInstant	;
			this._dgvtcAmount		.HeaderText			= "Amount";

			_dgvtcTransID		.DefaultCellStyle.BackColor = _colorRightClickArea;
			_dgvtcPostID		.DefaultCellStyle.BackColor = _colorRightClickArea;
			_dgvtcTransDescrip	.DefaultCellStyle.BackColor = _colorRightClickArea;
			_dgvtcTransInstant	.DefaultCellStyle.BackColor = _colorRightClickArea;
			_dgvtcAmount		.DefaultCellStyle.BackColor = _colorRightClickArea;
			oNumberColumnStyle.BackColor = _colorRightClickArea;

			_dgvtcAmount.DefaultCellStyle = oNumberColumnStyle;

			this._dgv.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
				this._dgvtcTransID		,
				this._dgvtcPostID		,
				this._dgvtcTransDescrip	,
				this._dgvtcTransInstant	,
				this._dgvtcAmount		});
		}
		void LLResetData(IList<uit.IDataDisplayObject> data, int iIndexOfAccountOptionDisplay, string strWhereClause)
		{
			this._bCloakUIHandlers = true;
			_dgv.DataSource = data;
			_tbWhere.Text = strWhereClause;
			_cmbAccnt.SelectedIndex = iIndexOfAccountOptionDisplay;
			this._bCloakUIHandlers = false;
		}
		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);
			SetupColumns();
			_cmbAccnt.Items.AddRange(this._arrstrAccountOptions);
			LLResetData(_oInitialData, _iInitialIndexOfAccountOptionDisplay, _strInitialWhereClause);
		}

		void _btnReload_Click(			object sender, EventArgs e){_Prsntr.RefreshEntities();}
		void _cmbAccnt_SelectedIndexChanged(object sender, EventArgs e)
		{
			if(this._bCloakUIHandlers)
				return;
			_Prsntr.ChangeNWAccntToThatIdntifiedByDisplayIndex_(this._cmbAccnt.SelectedIndex);
		}		

		void _dgv_MouseDown(object sender, MouseEventArgs e)
		{
			if (e.Button != System.Windows.Forms.MouseButtons.Right)
				return;
			DataGridView.HitTestInfo hit = _dgv.HitTest(e.X, e.Y);
			if (hit.RowIndex < 0)
				return;
			_Prsntr.DisplayOfTransactionActionOptionsDesired(hit.RowIndex, new Point(e.X, e.Y));
		}
		void _tbWhere_MouseDown(object sender, MouseEventArgs e)
		{
			if (e.Button != System.Windows.Forms.MouseButtons.Right)
				return;

			_Prsntr.DisplayOfPredicateOptionsDesired(new Point(e.X, e.Y));
		}

		public void SetPresenter(		ui.IPresenter aPresenter){_Prsntr = aPresenter					;}
		public void ShowBusyIndicator(							){Misc.ShowBusyIndicator()				;}
		public void ClearBusyIndicator(							){Misc.ClearBusyIndicator()				;}
		public void ShowSimpleMessage(	string str				){Misc.ShowSimpleMessage(str)			;}
		public void ShowException(		System.Exception ex		){Misc.ShowException(ex)				;}

		public void Show(IList<uit.IDataDisplayObject> data, string[] arrstrAccountOptions, int iInitialIndexOfAccountOptionDisplay, string strInitialWhereClause)
		{
			_oInitialData = data;
			_strInitialWhereClause = strInitialWhereClause;
			_iInitialIndexOfAccountOptionDisplay = iInitialIndexOfAccountOptionDisplay;
			_arrstrAccountOptions = arrstrAccountOptions;

			this.Show();
		}
		public void ResetData(IList<uit.IDataDisplayObject> data, int iIndexOfAccountOptionDisplay, string strWhereClause)
		{
			LLResetData(data, iIndexOfAccountOptionDisplay, strWhereClause);
		}
		
		
		public void DisplayTransactionActionOptions(IList<uitb.TransactionActionOption> lst, int iTransactionIndex, int iTransactionID, string strTransactionDescrip, object view_data)
		{
			Misc.DisplayTransactionActionOptions(_dgv, _Prsntr.ExecuteTransactionActionOption, lst, iTransactionIndex, iTransactionID, strTransactionDescrip, view_data);
		}
		public void DisplayPredicateOptions(List<uitb.PredicateOption> lstPredicateOptions, object view_data)
		{
			Misc.DisplayPredicateOptions(_tbWhere, _Prsntr.ExecutePredicateOption, lstPredicateOptions, view_data);
		}

		public NWAccntDltsForm()
		{
			InitializeComponent();
			this._tbWhere.BackColor = _colorRightClickArea;
		}

	}
}

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