#region Copyright (C) 2003-2009 Stimulsoft
/*
{*******************************************************************}
{ }
{ Stimulsoft Reports.Net }
{ }
{ }
{ Copyright (C) 2003-2009 Stimulsoft }
{ ALL RIGHTS RESERVED }
{ }
{ The entire contents of this file is protected by U.S. and }
{ International Copyright Laws. Unauthorized reproduction, }
{ reverse-engineering, and distribution of all or any portion of }
{ the code contained in this file is strictly prohibited and may }
{ result in severe civil and criminal penalties and will be }
{ prosecuted to the maximum extent possible under the law. }
{ }
{ RESTRICTIONS }
{ }
{ THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES }
{ ARE CONFIDENTIAL AND PROPRIETARY }
{ TRADE SECRETS OF Stimulsoft }
{ }
{ CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON }
{ ADDITIONAL RESTRICTIONS. }
{ }
{*******************************************************************}
*/
#endregion Copyright (C) 2003-2009 Stimulsoft
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using Stimulsoft.Controls;
using System.Reflection;
using Stimulsoft.Base.Services;
using Stimulsoft.Base.Localization;
using Stimulsoft.Report.Dictionary;
using Stimulsoft.Report.CodeDom;
using Stimulsoft.Report.Design.Controls;
namespace Stimulsoft.Report.Components.TextFormats.Design
{
///
/// The class describes the control for StiCustomFormatService edition.
///
[ToolboxItem(false)]
public class StiCustomEditor : StiFormatEditor
{
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
private ListBox lbFormats;
private System.Windows.Forms.Label lbFormatMask;
private Stimulsoft.Controls.StiTreeViewBox ebFormatMask;
private StiCustomFormatService service;
internal StiReport report = null;
public StiCustomEditor(StiCustomFormatService service)
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitForm call
this.service = service;
lbFormats.SelectedIndex = Build(service, "custom", lbFormats.Items);
ebFormatMask.Text = service.StringFormat;
if (!this.DesignMode)Localize();
}
private void Localize()
{
lbFormatMask.Text = StiLocalization.Get("FormFormatEditor", "FormatMask");
}
protected override int Build(StiFormatService service, string category, ListBox.ObjectCollection items)
{
#region Fill list
int index = 0;
string []keys = StiLocalization.GetKeys("Formats");
foreach (string key in keys)
{
if (key.IndexOf(category, StringComparison.InvariantCulture) > -1)
{
string value = StiLocalization.Get("Formats", key);
if (value != null)
{
if (value.Length > 0 && value[0] == '*')
{
Formats.Add(value.Substring(1));
items.Add('*' + service.Format(value.Substring(1), service.Sample));
}
else
{
Formats.Add(value);
items.Add(value);
}
}
}
}
#endregion
#region Searching value for select
foreach (string str in Formats)
{
if (str == service.StringFormat)return index;
index++;
}
#endregion
return -1;
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if ( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.lbFormats = new System.Windows.Forms.ListBox();
this.lbFormatMask = new System.Windows.Forms.Label();
this.ebFormatMask = new Stimulsoft.Controls.StiTreeViewBox();
this.SuspendLayout();
//
// lbFormats
//
this.lbFormats.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.lbFormats.BackColor = System.Drawing.SystemColors.Window;
this.lbFormats.ForeColor = System.Drawing.SystemColors.ControlText;
this.lbFormats.IntegralHeight = false;
this.lbFormats.Location = new System.Drawing.Point(0, 24);
this.lbFormats.Name = "lbFormats";
this.lbFormats.Size = new System.Drawing.Size(216, 160);
this.lbFormats.TabIndex = 0;
this.lbFormats.SelectedIndexChanged += new System.EventHandler(this.lbFormats_SelectedIndexChanged);
//
// lbFormatMask
//
this.lbFormatMask.ForeColor = System.Drawing.SystemColors.ControlText;
this.lbFormatMask.Location = new System.Drawing.Point(8, 0);
this.lbFormatMask.Name = "lbFormatMask";
this.lbFormatMask.Size = new System.Drawing.Size(88, 20);
this.lbFormatMask.TabIndex = 1;
this.lbFormatMask.Text = "FormatMask";
this.lbFormatMask.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// ebFormatMask
//
this.ebFormatMask.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.ebFormatMask.BackColor = System.Drawing.SystemColors.Window;
this.ebFormatMask.DropDownWidth = 200;
this.ebFormatMask.Flat = false;
this.ebFormatMask.ForeColor = System.Drawing.SystemColors.ControlText;
this.ebFormatMask.Location = new System.Drawing.Point(96, 0);
this.ebFormatMask.Name = "ebFormatMask";
this.ebFormatMask.ReadOnly = false;
this.ebFormatMask.Size = new System.Drawing.Size(112, 20);
this.ebFormatMask.TabIndex = 2;
this.ebFormatMask.TextChanged += new System.EventHandler(this.ebFormatMask_TextChanged);
this.ebFormatMask.ValueChanged += new Stimulsoft.Controls.StiTreeViewBox.ValueChangedEventHandler(this.ebFormatMask_ValueChanged);
this.ebFormatMask.TreeNodesFill += new Stimulsoft.Controls.StiTreeViewBox.TreeNodesFillEventHandler(this.ebFormatMask_TreeNodesFill);
//
// StiCustomEditor
//
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.ebFormatMask,
this.lbFormatMask,
this.lbFormats});
this.Name = "StiCustomEditor";
this.Size = new System.Drawing.Size(216, 184);
this.ResumeLayout(false);
}
#endregion
private void lbFormats_SelectedIndexChanged(object sender, System.EventArgs e)
{
ebFormatMask.Text = lbFormats.SelectedItem as string;
service.StringFormat = Formats[this.lbFormats.SelectedIndex];
}
private void ebFormatMask_TextChanged(object sender, System.EventArgs e)
{
service.StringFormat = ebFormatMask.Text;
}
private string No
{
get
{
return '[' + StiLocalization.Get("Report", "No") + ']';
}
}
private TreeNode SelectNode(TreeNode node, string[]strs, int index)
{
TreeNode selectedNode = null;
foreach (TreeNode nd in node.Nodes)
{
if (StiNameValidator.CorrectName(nd.Text) == strs[index])
{
selectedNode = nd;
break;
}
}
if (selectedNode == null)return node;
else return SelectNode(selectedNode, strs, ++index);
}
private void ebFormatMask_TreeNodesFill(object sender, Stimulsoft.Controls.StiTreeNodesFillEventArgs e)
{
TreeNode treeNode = new TreeNode(No);
treeNode.ImageKey = treeNode.SelectedImageKey = "Close";
e.TreeView.ImageList = StiDataBuilder.Images;
e.Nodes.Add(treeNode);
StiDataBuilder dataBuilder = new StiDataBuilder();
TreeNode node = new TreeNode();
dataBuilder.Build(e.Nodes, report.Dictionary, true, true);
if (node != null && node.Nodes.Count > 0)
{
e.Nodes.Add(node);
#region Searching current sorting
StiTreeViewBox cb = sender as StiTreeViewBox;
if (cb.Text == No)e.TreeView.SelectedNode = e.Nodes[0];
else
{
string[] strs = cb.Text.Split(new char[]{'.'});
e.TreeView.SelectedNode = SelectNode(e.Nodes[1], strs, 0);
}
#endregion
}
}
private void ebFormatMask_ValueChanged(object sender, Stimulsoft.Controls.StiValueChangedEventArgs e)
{
if (e.Text != No)
{
TreeNode node = e.TreeView.SelectedNode;
if (node != null)
{
if (!(node.Tag is StiDataColumn))e.Text = "{" + e.Text + "}";
else
{
string column = StiDataBuilder.GetColumnPathFromNode(node);
e.Text = "{" + column + "}";
}
}
else e.Text = "";
}
else e.Text = "";
}
}
}