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
Another approach to the MVC pattern
using System;
using System.Data;
using System.Drawing;
using MvcExample.Models;
using ZedGraph;

namespace MvcExample.Views
{
	public class View_Graph_Income : BaseView
	{
		#region Data members
		protected GraphPane graphPane;
		#endregion Data members

		#region Windows Form Designer generated code
		private ZedGraph.ZedGraphControl zedGraph;

		private System.ComponentModel.Container components = null;

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose(disposing);
		}

		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.zedGraph = new ZedGraph.ZedGraphControl();
			this.SuspendLayout();
			// 
			// butClose
			// 
			this.butClose.Location = new System.Drawing.Point(600, 392);
			this.butClose.Name = "butClose";
			// 
			// progressBar
			// 
			this.progressBar.Location = new System.Drawing.Point(8, 400);
			this.progressBar.Name = "progressBar";
			this.progressBar.Size = new System.Drawing.Size(584, 16);
			// 
			// zedGraph
			// 
			this.zedGraph.Anchor = ((System.Windows.Forms.AnchorStyles) ((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
				| System.Windows.Forms.AnchorStyles.Left)
				| System.Windows.Forms.AnchorStyles.Right)));
			this.zedGraph.Location = new System.Drawing.Point(8, 8);
			this.zedGraph.Name = "zedGraph";
			this.zedGraph.ScrollMaxX = 0;
			this.zedGraph.ScrollMaxY = 0;
			this.zedGraph.ScrollMaxY2 = 0;
			this.zedGraph.ScrollMinX = 0;
			this.zedGraph.ScrollMinY = 0;
			this.zedGraph.ScrollMinY2 = 0;
			this.zedGraph.Size = new System.Drawing.Size(672, 376);
			this.zedGraph.TabIndex = 2;
			// 
			// View_Graph_Income
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(688, 427);
			this.Controls.Add(this.zedGraph);
			this.Name = "View_Graph_Income";
			this.Text = "Graphical representation of test data";
			this.Controls.SetChildIndex(this.progressBar, 0);
			this.Controls.SetChildIndex(this.zedGraph, 0);
			this.Controls.SetChildIndex(this.butClose, 0);
			this.ResumeLayout(false);

		}
		#endregion

		#region constructor
		public View_Graph_Income()
		{
			InitializeComponent();

			graphPane = zedGraph.GraphPane;

			// graph titles
			graphPane.Title.Text = "MVC example";
			graphPane.XAxis.Title.Text = "years";
			graphPane.YAxis.Title.Text = "income";
		}
		#endregion constructor

		#region overriden methods
		protected override void ContinueUpdateView(ref DataSet ds)
		{
			if (ds.Tables.Count > 0)
			{
				string colYear = EnumIncome.Year.ToString();
				string colIncome = EnumIncome.Income.ToString();
				PointPairList points = new PointPairList();

				for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
				{
					DataRow row = ds.Tables[0].Rows[i];
					points.Add(
						Convert.ToDouble(row[colYear]),
						Convert.ToDouble(row[colIncome]));
				}

				LineItem myCurve = graphPane.AddCurve("example",
				                                      points, Color.Red, SymbolType.Diamond);

				// disable legend
				graphPane.Legend.IsVisible = false;

				zedGraph.AxisChange();
				zedGraph.Invalidate();
			} // if
		}
		#endregion overriden 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)

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 | Mobile
Web03 | 2.8.140721.1 | Last Updated 8 Jan 2007
Article Copyright 2007 by Zoltan Balazs
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid