/*
* Created by SharpDevelop.
* User: Ken
* Date: 7/08/2004
* Time: 10:31 AM
*/
using System;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;
using OMC.DrillDown;
namespace OMC.DrillDownDemo
{
public class MainForm : System.Windows.Forms.Form
{
#region Windows Forms Designer generated code
/// <summary>
/// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might
/// not be able to load this method if it was changed manually.
/// </summary>
private void InitializeComponent() {
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MainForm));
this.LblOutput = new System.Windows.Forms.Label();
this.CboEnumerationId = new System.Windows.Forms.ComboBox();
this.ImlMain = new System.Windows.Forms.ImageList(this.components);
this.PicMain = new System.Windows.Forms.PictureBox();
this.CboOutput = new System.Windows.Forms.ComboBox();
this.LblEnumeration = new System.Windows.Forms.Label();
this.DdMain = new OMC.DrillDown.DrillDown();
this.SuspendLayout();
//
// LblOutput
//
this.LblOutput.Location = new System.Drawing.Point(32, 344);
this.LblOutput.Name = "LblOutput";
this.LblOutput.Size = new System.Drawing.Size(120, 24);
this.LblOutput.TabIndex = 3;
this.LblOutput.Text = "Set Output:";
this.LblOutput.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// CboEnumerationId
//
this.CboEnumerationId.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CboEnumerationId.Items.AddRange(new object[] {
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12"});
this.CboEnumerationId.Location = new System.Drawing.Point(168, 368);
this.CboEnumerationId.Name = "CboEnumerationId";
this.CboEnumerationId.Size = new System.Drawing.Size(132, 21);
this.CboEnumerationId.TabIndex = 4;
this.CboEnumerationId.SelectionChangeCommitted += new System.EventHandler(this.CboEnumerationIdSelectionChangeCommitted);
//
// ImlMain
//
this.ImlMain.ImageSize = new System.Drawing.Size(200, 200);
this.ImlMain.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ImlMain.ImageStream")));
this.ImlMain.TransparentColor = System.Drawing.Color.Transparent;
//
// PicMain
//
this.PicMain.Dock = System.Windows.Forms.DockStyle.Top;
this.PicMain.Location = new System.Drawing.Point(30, 120);
this.PicMain.Name = "PicMain";
this.PicMain.Size = new System.Drawing.Size(270, 208);
this.PicMain.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
this.PicMain.TabIndex = 1;
this.PicMain.TabStop = false;
//
// CboOutput
//
this.CboOutput.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CboOutput.Items.AddRange(new object[] {
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11"});
this.CboOutput.Location = new System.Drawing.Point(168, 344);
this.CboOutput.Name = "CboOutput";
this.CboOutput.Size = new System.Drawing.Size(132, 21);
this.CboOutput.TabIndex = 2;
this.CboOutput.SelectionChangeCommitted += new System.EventHandler(this.CboOutputSelectionChangeCommitted);
//
// LblEnumeration
//
this.LblEnumeration.Location = new System.Drawing.Point(32, 368);
this.LblEnumeration.Name = "LblEnumeration";
this.LblEnumeration.Size = new System.Drawing.Size(120, 24);
this.LblEnumeration.TabIndex = 5;
this.LblEnumeration.Text = "Set EnumerationId:";
this.LblEnumeration.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// DdMain
//
this.DdMain.BackColor = System.Drawing.SystemColors.Window;
this.DdMain.Categories = null;
this.DdMain.CategoryAllowDrop = false;
this.DdMain.CategoryAnchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)));
this.DdMain.CategoryBackColor = System.Drawing.SystemColors.Window;
this.DdMain.CategoryContextMenu = null;
this.DdMain.CategoryCursor = System.Windows.Forms.Cursors.Default;
this.DdMain.CategoryDock = System.Windows.Forms.DockStyle.Top;
this.DdMain.CategoryEnabled = true;
this.DdMain.CategoryFont = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.DdMain.CategoryForeColor = System.Drawing.SystemColors.ControlText;
this.DdMain.CategoryHeight = 24;
this.DdMain.CategoryLocation = new System.Drawing.Point(0, 0);
this.DdMain.CategoryRightToLeft = System.Windows.Forms.RightToLeft.No;
this.DdMain.CategorySize = new System.Drawing.Size(270, 24);
this.DdMain.CategoryWidth = 270;
this.DdMain.ComboAllowDrop = false;
this.DdMain.ComboAnchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)));
this.DdMain.ComboBackColor = System.Drawing.SystemColors.Window;
this.DdMain.ComboContextMenu = null;
this.DdMain.ComboCursor = System.Windows.Forms.Cursors.Default;
this.DdMain.ComboDisplayMember = "";
this.DdMain.ComboDock = System.Windows.Forms.DockStyle.Fill;
this.DdMain.ComboDrawMode = System.Windows.Forms.DrawMode.Normal;
this.DdMain.ComboDropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.DdMain.ComboDropDownWidth = 153;
this.DdMain.ComboEnabled = true;
this.DdMain.ComboFont = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.DdMain.ComboForeColor = System.Drawing.SystemColors.WindowText;
this.DdMain.ComboHeight = 21;
this.DdMain.ComboIntegralHeight = true;
this.DdMain.ComboItemHeight = 13;
this.DdMain.ComboLocation = new System.Drawing.Point(131, 0);
this.DdMain.ComboMaxDropDownItems = 8;
this.DdMain.ComboMaxLength = 0;
this.DdMain.ComboRightToLeft = System.Windows.Forms.RightToLeft.No;
this.DdMain.ComboSize = new System.Drawing.Size(139, 21);
this.DdMain.ComboSorted = true;
this.DdMain.ComboValueMember = "";
this.DdMain.ComboWidth = 139;
this.DdMain.Dock = System.Windows.Forms.DockStyle.Top;
this.DdMain.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.DdMain.IncludeBlankEnumeration = true;
this.DdMain.LabelAllowDrop = false;
this.DdMain.LabelAnchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)));
this.DdMain.LabelAutoSize = false;
this.DdMain.LabelBackColor = System.Drawing.Color.Transparent;
this.DdMain.LabelBorderStyle = System.Windows.Forms.BorderStyle.None;
this.DdMain.LabelContextMenu = null;
this.DdMain.LabelCursor = System.Windows.Forms.Cursors.Default;
this.DdMain.LabelDock = System.Windows.Forms.DockStyle.Left;
this.DdMain.LabelEnabled = true;
this.DdMain.LabelFlatStyle = System.Windows.Forms.FlatStyle.Standard;
this.DdMain.LabelFont = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.DdMain.LabelForeColor = System.Drawing.SystemColors.ControlText;
this.DdMain.LabelHeight = 24;
this.DdMain.LabelImage = null;
this.DdMain.LabelImageAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.DdMain.LabelImageIndex = -1;
this.DdMain.LabelImageList = null;
this.DdMain.LabelLocation = new System.Drawing.Point(0, 0);
this.DdMain.LabelRightToLeft = System.Windows.Forms.RightToLeft.No;
this.DdMain.LabelSize = new System.Drawing.Size(128, 24);
this.DdMain.LabelTextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.DdMain.LabelWidth = 128;
this.DdMain.Location = new System.Drawing.Point(30, 30);
this.DdMain.Name = "DdMain";
this.DdMain.Size = new System.Drawing.Size(270, 90);
this.DdMain.SplitterAllowDrop = false;
this.DdMain.SplitterAnchor = System.Windows.Forms.AnchorStyles.None;
this.DdMain.SplitterBackColor = System.Drawing.SystemColors.Window;
this.DdMain.SplitterBorderStyle = System.Windows.Forms.BorderStyle.None;
this.DdMain.SplitterContextMenu = null;
this.DdMain.SplitterCursor = System.Windows.Forms.Cursors.VSplit;
this.DdMain.SplitterDock = System.Windows.Forms.DockStyle.Left;
this.DdMain.SplitterEnabled = true;
this.DdMain.SplitterFont = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.DdMain.SplitterForeColor = System.Drawing.SystemColors.ControlText;
this.DdMain.SplitterHeight = 24;
this.DdMain.SplitterLocation = new System.Drawing.Point(128, 0);
this.DdMain.SplitterRightToLeft = System.Windows.Forms.RightToLeft.No;
this.DdMain.SplitterSize = new System.Drawing.Size(3, 24);
this.DdMain.SplitterWidth = 3;
this.DdMain.TabIndex = 6;
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(330, 400);
this.Controls.Add(this.LblEnumeration);
this.Controls.Add(this.CboEnumerationId);
this.Controls.Add(this.LblOutput);
this.Controls.Add(this.CboOutput);
this.Controls.Add(this.PicMain);
this.Controls.Add(this.DdMain);
this.DockPadding.All = 30;
this.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Name = "MainForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Drill-down Demo";
this.Load += new System.EventHandler(this.MainFormLoad);
this.ResumeLayout(false);
}
#endregion
#region private members
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Label LblEnumeration;
private System.Windows.Forms.ComboBox CboOutput;
private System.Windows.Forms.PictureBox PicMain;
private System.Windows.Forms.ComboBox CboEnumerationId;
private System.Windows.Forms.Label LblOutput;
private OMC.DrillDown.DrillDown DdMain;
public System.Windows.Forms.ImageList ImlMain;
#endregion
#region ctors
public MainForm()
{
InitializeComponent();
}
#endregion
#region entry point
[STAThread]
public static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.Run(new MainForm());
}
#endregion
#region event handlers
/// <summary>
/// Load data and initialise drill-down control.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void MainFormLoad(object sender, System.EventArgs e)
{
// load config
System.Collections.IDictionary dict = (System.Collections.IDictionary)System.Configuration.ConfigurationSettings.GetConfig("Database");
// populate a drill-down dataset
DrillDownDataSet d = new DrillDownDataSet();
// open connection
OleDbConnection con = new OleDbConnection(dict["ConnectionString"].ToString());
con.Open();
// fill dataset
OleDbDataAdapter dap = new OleDbDataAdapter();
dap.SelectCommand = new OleDbCommand(dict["CategoriesSource"].ToString(), con);
dap.Fill(d.DdCategories);
dap.SelectCommand = new OleDbCommand(dict["OutputsSource"].ToString(), con);
dap.Fill(d.DdOutputs);
dap.SelectCommand = new OleDbCommand(dict["EnumerationsSource"].ToString(), con);
dap.Fill(d.DdEnumerations);
// close connection
con.Close();
// initialise drill-down control
this.DdMain.UserSelection += new UserSelectionHandler(OnUserSelection);
this.DdMain.Initialise(d);
}
/// <summary>
/// Handle UserSelection event, displaying a Picture of the selection
/// if the last category has changed values.
/// </summary>
/// <param name="c">The category combo whose value has changed.</param>
private void OnUserSelection(CategoryCombo c)
{
int index = this.DdMain.Categories.IndexOf(c);
if (index == this.DdMain.Categories.Count - 1)
{
if (this.DdMain.Output == int.MinValue)
{
this.PicMain.Image = null;
}
else
{
this.PicMain.Image = this.ImlMain.Images[this.DdMain.Output];
}
}
}
/// <summary>
/// Handle user selection of output. Demonstrates how the state of the drill-down
/// can be set by the single output value - to save the state of the drill-down,
/// one need only save the output value. Note that if output values are not unique,
/// the first valid enumeration matching the output is used as the drill-down state.
/// </summary>
/// <param name="sender">Combo.</param>
/// <param name="e">Event args.</param>
void CboOutputSelectionChangeCommitted(object sender, System.EventArgs e)
{
this.DdMain.Output = int.Parse(this.CboOutput.Text);
}
/// <summary>
/// Handle user selection of enumeration id. Demonstrates how the state of the
/// drill-down can be set by the unique enumeration id value.
/// </summary>
/// <param name="sender">Combo.</param>
/// <param name="e">Event args.</param>
void CboEnumerationIdSelectionChangeCommitted(object sender, System.EventArgs e)
{
this.DdMain.EnumerationId = int.Parse(this.CboEnumerationId.Text);
}
#endregion
}
}