📄 fieldsexplorer.cs
字号:
//------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Runtime Version: 1.1.ascendingIconscendingIcon322.2032
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------
using System;
using System.IO;
using System.Data;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using System.ComponentModel;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
using SharpReport;
using SharpReportCore;
/// <summary>
/// This Pad shows the Available Fields from a report and is used to handel sorting /grouping
/// </summary>
namespace SharpReportAddin {
public class FieldsExplorer : TreeView, IPadContent {
Panel contentPanel = new Panel();
private SectionTreeNode nodeAvailableFields;
private SectionTreeNode nodeSorting;
private SectionTreeNode nodeGrouping;
private TreeNode nodeFunction;
private TreeNode nodeParams;
private ReportModel reportModel;
private bool isFilled ;
#region Publics
///<summary>
/// Clear the selected Section
/// </summary>
public void ClearNodeSection () {
if (this.SelectedNode is SectionTreeNode) {
if (this.SelectedNode.Nodes.Count > 0) {
this.SelectedNode.Nodes.Clear();
NotifyReportView();
}
}
}
/// <summary>
/// Remove the selected Node from Sorting or Grouping Collection
/// </summary>
public void ClearSelectedNode() {
if (this.SelectedNode != null) {
TreeNode parent = this.SelectedNode.Parent;
this.SelectedNode.Remove();
this.SelectedNode = parent;
NotifyReportView();
}
}
/// <summary>
/// Toggle the SortDirection
/// </summary>
public void ToogleSortDirection () {
if (this.SelectedNode is ColumnsTreeNode) {
ColumnsTreeNode cn = (ColumnsTreeNode)this.SelectedNode;
if (cn.SortDirection == ListSortDirection.Ascending) {
cn.SortDirection = ListSortDirection.Descending;
cn.ImageIndex = descendingIcon;
cn.SelectedImageIndex = descendingIcon;
} else {
cn.SortDirection = ListSortDirection.Ascending;
cn.ImageIndex = ascendingIcon;
cn.SelectedImageIndex = ascendingIcon;
}
this.NotifyReportView();
}
}
#endregion
#region TreeView Events
private void TreeMouseDown(object sender, System.Windows.Forms.MouseEventArgs e){
TreeNode node = this.GetNodeAt(PointToClient(Cursor.Position));
if (node != null) {
this.SelectedNode = node;
CheckNode (node);
if (e.Button == MouseButtons.Right) {
AbstractFieldsNode abstrNode = node as AbstractFieldsNode;
if (abstrNode != null) {
if (abstrNode.ContextmenuAddinTreePath.Length > 0) {
ContextMenuStrip ctMen = MenuService.CreateContextMenu (this,abstrNode.ContextmenuAddinTreePath);
ctMen.Show (this,new Point (e.X,e.Y));
}
}
/*
if (node is AbstractFieldsNode) {
AbstractFieldsNode abstrNode = (AbstractFieldsNode)node;
if (abstrNode.ContextmenuAddinTreePath.Length > 0) {
ContextMenuStrip ctMen = MenuService.CreateContextMenu (this,abstrNode.ContextmenuAddinTreePath);
ctMen.Show (this,new Point (e.X,e.Y));
}
}
*/
}
}
}
void TreeViewItemDrag (object sender,ItemDragEventArgs e) {
if (e.Item is ColumnsTreeNode) {
ColumnsTreeNode node = (ColumnsTreeNode)e.Item;
// for now, only dragging of Columns is allowed
if (node.ImageIndex == columnIcon) {
this.SelectedNode = node;
if (node != null) {
this.DoDragDrop(node.DragDropDataObject,
DragDropEffects.Copy | DragDropEffects.Scroll);
}
}
}
}
void TreeViewDragOver (object sender,DragEventArgs e) {
TreeNode node = this.GetNodeAt(PointToClient(new Point (e.X,e.Y)));
node.EnsureVisible();
if (node.Nodes.Count > 0) {
node.Expand();
}
if(e.Data.GetDataPresent("SharpReportAddin.ColumnsTreeNode", false)){
//If we are in the AvailableFields Section we can't drop
if (node is SectionTreeNode){
e.Effect = DragDropEffects.Copy | DragDropEffects.Scroll;
} else {
e.Effect = DragDropEffects.None;
}
} else {
e.Effect = DragDropEffects.None;
}
}
void TreeViewDragDrop (object sender,DragEventArgs e) {
if(e.Data.GetDataPresent("SharpReportAddin.ColumnsTreeNode", false)){
Point pt = this.PointToClient (new Point( e.X,e.Y));
SectionTreeNode node = this.GetNodeAt (pt) as SectionTreeNode;
if (node != null) {
ColumnsTreeNode t = (ColumnsTreeNode)e.Data.GetData("SharpReportAddin.ColumnsTreeNode", true);
ColumnsTreeNode dest = new ColumnsTreeNode (t.Text);
// Useless to add a node twice
if (!FieldsExplorer.CheckForExist (node,dest)) {
dest.SortDirection = ListSortDirection.Ascending;
dest.ImageIndex = ascendingIcon;
dest.SelectedImageIndex = ascendingIcon;
this.SelectedNode = (TreeNode)dest;
CheckNode (dest);
node.Nodes.Add(dest);
NotifyReportView();
this.OnViewSaving(this,EventArgs.Empty);
}
}
}
}
private void FillExplorer () {
this.FillTree();
this.ExpandAll();
isFilled = true;
}
private static bool CheckForExist (SectionTreeNode sec,ColumnsTreeNode col) {
if (sec.Nodes.Count > 0) {
for (int i = 0;i < sec.Nodes.Count ;i++ ) {
if (sec.Nodes[i].Text == col.Text) {
return true;
}
}
} else {
return false;
}
return false;
}
private void CheckNode (TreeNode node) {
ColumnsTreeNode cn = node as ColumnsTreeNode;
if (cn != null) {
if (node.Parent == nodeSorting) {
if (cn.SortDirection == ListSortDirection.Ascending) {
cn.ImageIndex = ascendingIcon;
} else {
cn.ImageIndex = descendingIcon;
}
} else if (node.Parent == this.nodeGrouping) {
cn.ImageIndex = clearIcon;
cn.SelectedImageIndex = clearIcon;
}
}
}
#endregion
private void NotifyReportView() {
if (this.isFilled) {
if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent is SharpReportView) {
WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent.IsDirty = true;
}
}
}
#region PadEvents
private void OnUpdateExplorerWindow (object sender,EventArgs e) {
if (WorkbenchSingleton.Workbench.ActiveContent != null) {
Type type = WorkbenchSingleton.Workbench.ActiveContent.GetType();
if (type != typeof(PropertyPad)) {
try {
if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow == null || WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent == null) {
return;
}
WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent.Saving -= OnViewSaving;
WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent.Saving += OnViewSaving;
PadDescriptor pad =
WorkbenchSingleton.Workbench.GetPad(typeof(FieldsExplorer));
if (pad != null) {
SharpReportView view =
WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ActiveViewContent
as SharpReportView;
if ((view != null) && (!view.Disposed)) {
this.reportModel = view.ReportManager.BaseDesignControl.ReportModel;
if (this.reportModel != null) {
this.FillExplorer();
WorkbenchSingleton.Workbench.ShowPad(pad);
pad.BringPadToFront();
}
}
}
else {
WorkbenchSingleton.Workbench.WorkbenchLayout.HidePad(pad);
}
} catch (Exception) {
// throw;
}
}
}
}
private void OnViewSaving (object sender, EventArgs e) {
if (this.isFilled) {
UpdateSorting();
UpdateGrouping();
}
}
#endregion
#region Build TreeControl
private void UpdateSorting () {
this.reportModel.ReportSettings.SortColumnCollection.Clear();
if (this.nodeSorting.Nodes.Count > 0) {
SortColumn sc;
AbstractColumn af;
for (int i = 0;i < this.nodeSorting.Nodes.Count ;i++ ) {
ColumnsTreeNode cn = (ColumnsTreeNode)this.nodeSorting.Nodes[i];
af = this.reportModel.ReportSettings.AvailableFieldsCollection.Find(cn.Text);
if (af != null) {
sc = new SortColumn (cn.Text,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -