/*
i-net software provides programming examples for illustration only, without warranty
either expressed or implied, including, but not limited to, the implied warranties
of merchantability and/or fitness for a particular purpose. This programming example
assumes that you are familiar with the programming language being demonstrated and
the tools used to create and debug procedures. i-net software support professionals
can help explain the functionality of a particular procedure, but they will not modify
these examples to provide added functionality or construct procedures to meet your
specific needs.
© i-net software 1998-2013
*/
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Inet.Viewer.Data;
namespace Inet.Viewer.WinForms
{
///
/// This is the user control for the GroupTree of the report and provides the methods to fill the group tree and the drilldown function
///
[ToolboxItem(false)]
public partial class GroupTreeView : UserControl, IGroupView
{
private ReportView reportView;
///
/// Constructor to initialize this control
///
public GroupTreeView()
{
InitializeComponent();
this.drillToolStripMenuItem.Click += new EventHandler(drillDownToolStripMenuItem_Click);
this.treeView1.AfterSelect += new TreeViewEventHandler(treeView1_AfterSelect);
}
///
/// reference to the SplitContainer
///
public SplitContainer SplitContainer { get; set; }
///
///
///
public IReportView ReportView
{
get
{
return reportView;
}
set
{
if (reportView != null)
{
reportView.DataChanged -= new DataChanged(reportView_DataChanged);
}
reportView = value as ReportView;
if (reportView != null)
{
reportView.DataChanged += new DataChanged(reportView_DataChanged);
}
}
}
///
///
///
public IReportViewer ReportViewer { get; set; }
///
/// This method clears the gropup tree and fills it with the data from the
///
/// the array with the GroupTreeNodes, nothing happens if null
///
private void SetGroupTree(GroupTreeNode[] groupArray, Exception ex)
{
if (ex != null)
{
reportView.ShowError(ex);
return;
}
else
{
TreeNodeCollection rootCol = treeView1.Nodes;
rootCol.Clear();
SplitContainer.Panel1Collapsed = groupArray.Length <= 1;
// Start the recursion to add the nodes
int i = 1;
do
{
} while (FillTreeRecursive(groupArray, rootCol, 0, ref i) != null);
treeView1.Refresh();
}
reportView.ThreadFinished();
}
///
/// This recursive method fills the GroupTreeView with the nodes accordingly
///
/// groupArray with a list of all TreeNodes
/// The current collection that the node will be added to
/// the current level of this recursion
/// index of the groupArray
///
private TreeNode FillTreeRecursive(GroupTreeNode[] groupArray, TreeNodeCollection nodeCol, int curLevel, ref int i)
{
if (i >= groupArray.Length)
{
// return when all items in the array were looped through
return null;
}
GroupTreeNode dNode = groupArray[i];
if (dNode.Level > curLevel)
{
// add to the Tree
TreeNode tNode = new TreeNode();
tNode.Text = dNode.GroupName;
tNode.Tag = dNode;
if (dNode.RequestURL != null && dNode.RequestURL.Length != 0)
{
tNode.ContextMenuStrip = contextMenuStrip1;
}
nodeCol.Add(tNode);
curLevel = dNode.Level;
i++;
// recursion until all nodes for this level are looped through
TreeNode upNode = null;
do
{
upNode = FillTreeRecursive(groupArray, tNode.Nodes, curLevel, ref i);
} while (upNode != null);
return tNode;
}
return null;
}
///
/// If a TreeView should be rendered this method clears the tree, fills the treeView
/// and adds the events for the context menu. The internal ReportView is used.
/// Is using the GroupLoader for this
///
public void SetupTreeView()
{
if (this.ReportView != null)
{
ThreadManager.RequestGroupTree(this, reportView.ReportDataCache, SetGroupTree);
}
}
///
/// Method invoked with click on "Drilldown" in the context menu of the tree
/// Looks according to the Location of the contextMenuStrip from which NodeTree this
/// Clones the ReporRenderData and creates a new view
/// Context menu was invoked.
///
/// source of the event
/// the event arguments
private void drillDownToolStripMenuItem_Click(object sender, EventArgs e)
{
ToolStripMenuItem toolStripItem = sender as ToolStripMenuItem;
ToolStrip toolStrip = toolStripItem.GetCurrentParent();
ContextMenuStrip context = toolStrip as ContextMenuStrip;
if (context != null)
{
Rectangle rect = context.Bounds;
TreeView tree = context.SourceControl as TreeView;
// get the correct Tree Node
Point contextPoint = new Point(rect.X, rect.Y);
TreeNode treeNodeAt = tree.GetNodeAt(tree.PointToClient(contextPoint));
if (this.ReportView != null && treeNodeAt != null)
{
// set filter param for the subView
GroupTreeNode nodeInfo = treeNodeAt.Tag as GroupTreeNode;
if (nodeInfo != null)
{
IRenderData data = GroupLoader.GetDrillDownRenderDataCopy(nodeInfo, this.ReportView.ReportData);
IReportView subReport = ReportView.ReportViewer.AddNewReportView(data);
subReport.IsCloseable = true;
subReport.ReportTitle = nodeInfo.GroupName;
subReport.CurrentPage = 1;
//if (subView.PromptsOnRefresh)
{
// remove promptsonrefresh as this is deactivated for drilldown
//subView.ReportData[URLPARAMETER_PROMPT_ON_REFRESH, "");
}
}
}
}
}
///
/// This method updates the View with the new page number
///
/// source of the event
/// the event arguments
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
if (ReportView != null)
{
if (this.treeView1 != null && e.Node != null)
{
GroupTreeNode nodeInfo = e.Node.Tag as GroupTreeNode;
TreeNode testNode = this.treeView1.SelectedNode;
if (nodeInfo != null)
{
reportView.ContentView.ScrollTo(nodeInfo.PageFrom, new Point(0, (int)nodeInfo.YFrom), false);
reportView.ContentView.SelectGroup(nodeInfo);
}
}
}
}
///
/// Update the TreeView when the data of the ReportView was changed.
///
/// source of the event
/// the timesstamp in millisecond
private void reportView_DataChanged(object sender, long timestamp)
{
this.SetupTreeView();
}
}
}