Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

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.RunWorkerAsync(ds);
			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.Add("RESULT");
			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);

				ds.Tables[0].Rows.Add(row);

				if (backgroundWorker.CancellationPending)
					break;

				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.

License

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

Share

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.

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