|
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()
{
backgroundWorker.CancelAsync();
}
#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.
I've did some programming for Macintosh a few years back and working with Microsoft technologies since then.