Click here to Skip to main content
12,292,585 members (66,078 online)
Click here to Skip to main content


141 bookmarked

A Practical Use of the MVC Pattern

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

namespace MvcExample.Models
	public class Model_Income : BaseModel
		#region overriden methods
		/// <summary>
		/// Responsible for generate the report test data.
		/// </summary>
		public override void GenerateReport()
			backgroundWorker.DoWork += new DoWorkEventHandler(GenerateIncome);
			backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(Fire_ModelChanged);
			backgroundWorker.DoWork -= new DoWorkEventHandler(GenerateIncome);
		#endregion overriden methods

		#region private methods
		private void GenerateIncome(object sender, DoWorkEventArgs e)
			string colYear = EnumIncome.Year.ToString();
			string colIncome = EnumIncome.Income.ToString();

			Random random = new Random();

			ds.Tables[0].Columns.Add(colYear, typeof (int));
			ds.Tables[0].Columns.Add(colIncome, typeof (double));

			int rowCount = 26;
			for (int i = 0; i < rowCount; i++)
				DataRow row = ds.Tables[0].NewRow();

				row[colYear] = 1980 + i;
				row[colIncome] = random.NextDouble()*random.Next(500, 1000);


				if (backgroundWorker.CancellationPending)

				Thread.Sleep(random.Next(50, 250));

				Fire_ModelProgress(this, (int) (i*100)/rowCount);
		#endregion private 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...

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