|
using System;
using System.Windows.Forms;
using MvcExample.EventHandlers;
using MvcExample.Models;
using MvcExample.Views;
namespace MvcExample.Controllers
{
public class RptController : BaseController
{
#region private members
private BaseModel model;
private BaseView view;
#endregion private members
#region constructor
/// <summary>
/// Instanciates the view (the representation of the data) and
/// the model (the data).
/// </summary>
public RptController(RptControllerType controllerType)
{
switch (controllerType)
{
case RptControllerType.List:
view = new View_List_Income();
model = new Model_Income();
break;
case RptControllerType.Graph:
view = new View_Graph_Income();
model = new Model_Income();
break;
default:
MessageBox.Show("Type of report unimplemented!", "", MessageBoxButtons.OK, MessageBoxIcon.Stop);
return;
}
SubscribeControllerToView();
SubsctribeModelToView();
view.Show();
model.GenerateReport();
}
#endregion constructor
#region subscriber methods
protected override void SubscribeControllerToView()
{
if (view == null)
return;
view.ViewClosed += new EventHandler(OnView_ViewClosed);
}
protected override void SubsctribeModelToView()
{
if (model == null)
return;
model.ModelChanged += new EventHandler(OnModel_ModelChanged);
model.ModelProgress += new ProgressEventHandler(OnModel_ModelProgress);
}
#endregion subscriber methods
#region view eventhandlers
private void OnView_ViewClosed(object sender, EventArgs e)
{
if (model != null)
{
model.CancelBackgroundWorker();
}
}
#endregion view eventhandlers
#region model eventhandlers
private void OnModel_ModelChanged(object sender, EventArgs ea)
{
if (view == null)
return;
if (view.InvokeRequired)
{
view.Invoke(
new GenericEventHandler(view.UpdateView),
new object[] {sender, ea});
}
else
{
view.UpdateView(sender, ea);
}
}
private void OnModel_ModelProgress(object sender, int percent)
{
if (view == null)
return;
if (view.InvokeRequired)
{
view.Invoke(
new ProgressEventHandler(view.UpdateProgress),
new object[] {sender, percent});
}
else
{
view.UpdateProgress(sender, percent);
}
}
#endregion model eventhandlers
} // RptController
}
|
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.