Click here to Skip to main content
13,355,018 members (59,148 online)
Click here to Skip to main content


144 bookmarked
Posted 8 Jan 2007

A Practical Use of the MVC Pattern

, 8 Jan 2007
Another approach to the MVC pattern
using System;
using System.Data;
using MvcExample.EventHandlers;
using WinFormsEx;

namespace MvcExample.Models
	public abstract class BaseModel
		/// <summary>
		/// Event fired when the model is finished calculating/processing the data.
		/// </summary>
		public event EventHandler ModelChanged;

		/// <summary>
		/// Event fired when the model is calculating the data to notify the view
		/// about its progress.
		/// </summary>
		public event ProgressEventHandler ModelProgress;

		#region protected members
		protected BackgroundWorker backgroundWorker;
		protected DataSet ds;
		#endregion protected members

		#region constructor
		protected BaseModel()
			ds = new DataSet();
			backgroundWorker = new BackgroundWorker();

			backgroundWorker.WorkerReportsProgress = false;
			backgroundWorker.WorkerSupportsCancellation = true;
		#endregion constructor

		#region public abstract methods
		public abstract void GenerateReport();
		#endregion public abstract methods

		#region public methods
		/// <summary>
		/// Returns the report data.
		/// </summary>
		public DataSet QueryModel()
			return ds;

		public void CancelBackgroundWorker()
		#endregion public methods

		#region event firing methods
		protected void Fire_ModelChanged(object sender, RunWorkerCompletedEventArgs ea)
			BackgroundWorker bw = sender as BackgroundWorker;
			if (bw != null)
				bw.RunWorkerCompleted -= new RunWorkerCompletedEventHandler(Fire_ModelChanged);

			if (ModelChanged != null)
				ModelChanged(this, EventArgs.Empty);

		protected void Fire_ModelProgress(object sender, int percent)
			if (ModelProgress != null)
				ModelProgress(this, percent);
		#endregion event firing methods

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.


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


About the Author

Zoltan Balazs
Software Developer
Romania Romania
I've did some programming for Macintosh a few years back and working with Microsoft technologies since then.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 8 Jan 2007
Article Copyright 2007 by Zoltan Balazs
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid