|
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Resources;
using System.Windows.Forms;
namespace IssueVision
{
// The IssueTreeView user control implements the view selection ui for IssueVision
public class IssueTreeView : UserControl, IObserver
{
// icons that can appear in the treeview
private enum TypeIcon
{
None = 0,
AllStaffers = 1,
Staff = 2,
Technician = 3
}
private TreeView trvViews;
private ImageList images;
private IssueSubject m_subject = null;
private const string m_fontname = "Tahoma";
private IContainer components;
public virtual ISubject Subject
{
set
{
m_subject = (IssueSubject)value;
m_subject.LookupDataChanged += new IssueSubject.LookupDataChangedEventHandler(this.Subject_LookupDataChanged);
m_subject.ConflictDataChanged += new IssueSubject.ConflictDataChangedEventHandler(this.Subject_ConflictDataChanged);
}
}
public IssueTreeView()
{
InitializeComponent();
}
protected override void Dispose(bool disposing)
{
if (disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
[DebuggerStepThroughAttribute()]
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(IssueTreeView));
this.trvViews = new System.Windows.Forms.TreeView();
this.images = new System.Windows.Forms.ImageList(this.components);
this.SuspendLayout();
//
// trvViews
//
this.trvViews.AllowDrop = true;
this.trvViews.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.trvViews.Dock = System.Windows.Forms.DockStyle.Fill;
this.trvViews.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
this.trvViews.HideSelection = false;
this.trvViews.ImageList = this.images;
this.trvViews.Location = new System.Drawing.Point(1, 1);
this.trvViews.Name = "trvViews";
this.trvViews.Size = new System.Drawing.Size(190, 334);
this.trvViews.TabIndex = 9;
this.trvViews.AfterSelect += new TreeViewEventHandler(this.trvViews_AfterSelect);
//
// images
//
this.images.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
this.images.ImageSize = new System.Drawing.Size(16, 16);
this.images.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("images.ImageStream")));
this.images.TransparentColor = System.Drawing.Color.Magenta;
//
// IssueTreeView
//
this.Controls.Add(this.trvViews);
this.DockPadding.All = 1;
this.Name = "IssueTreeView";
this.Size = new System.Drawing.Size(192, 336);
base.Load += new EventHandler(this.IssueTreeView_Load);
this.ResumeLayout(false);
}
private void Subject_LookupDataChanged(object sender, EventArgs e)
{
TreeNode staffersNode = trvViews.Nodes[0];
staffersNode.Nodes.Clear();
foreach (DataRow row in m_subject.Staffers.Rows)
{
TreeNode stafferNode = new TreeNode((string)row["DisplayName"]);
stafferNode.Tag = (int)row["StafferID"];
int icon = (int)GetIconType((string)row["StafferType"]);
stafferNode.ImageIndex = icon;
stafferNode.SelectedImageIndex = icon;
staffersNode.Nodes.Add(stafferNode);
}
trvViews.Nodes[0].ExpandAll();
}
private void Subject_ConflictDataChanged(object sender, EventArgs e)
{
if (m_subject.HasConflicts)
{
trvViews.Nodes[1].Text = "Conflicts (" + m_subject.Conflicts.Rows.Count + ") ";
trvViews.Nodes[1].NodeFont = new Font(m_fontname, 8.0F, FontStyle.Bold);
}
else
{
trvViews.Nodes[1].Text = "Conflicts ";
trvViews.Nodes[1].NodeFont = new Font(m_fontname, 8.0F, FontStyle.Bold);
}
}
private void IssueTreeView_Load(object sender, EventArgs e)
{
trvViews.Nodes.AddRange(new TreeNode[]{new TreeNode("All Staffers", 1, 1), new TreeNode("Conflicts ", 4, 4)});
trvViews.Nodes[1].NodeFont = new Font(m_fontname, 8.0F, FontStyle.Bold);
trvViews.SelectedNode = trvViews.Nodes[0];
}
private void trvViews_AfterSelect(object sender, TreeViewEventArgs e)
{
if (m_subject != null)
{
if (e.Node.Text.StartsWith("Conflicts"))
{
m_subject.SetFilter("Conflicts", string.Empty, string.Empty);
}
else if (e.Node.Text == "All Staffers")
{
m_subject.SetFilter("Issues", string.Empty, string.Empty);
}
else
{
m_subject.SetFilter("Issues", "StafferID", e.Node.Tag.ToString());
}
}
}
private int GetIconType(string type)
{
switch (type)
{
case "H":
return (int)TypeIcon.Staff;
case "T":
return (int)TypeIcon.Technician;
}
return (int)TypeIcon.None;
}
}
}
|
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.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
Weidong has been an information system professional since 1990. He has a Master's degree in Computer Science, and is currently a MCSD .NET