namespace Easychart.Finance.Win { using Easychart.Finance; using System; using System.ComponentModel; using System.Drawing; using System.Reflection; using System.Resources; using System.Windows.Forms; [ToolboxItem(false)] public class SelectMethod : Form { private Button btnCancel; private Button btnOK; private IContainer components; private ImageList ilMethod; private Label lDescription; private Label lName; private Label lParam; private Panel pnRight; private string Result; private Splitter spLeft; private TreeView tvMethod; public SelectMethod() { this.InitializeComponent(); } private void btnOK_Click(object sender, EventArgs e) { this.Result = null; TreeNode selectedNode = this.tvMethod.SelectedNode; if ((selectedNode != null) && (selectedNode.Tag != null)) { MemberInfo tag = (MemberInfo) selectedNode.Tag; this.Result = tag.Name + this.GetParam(tag); } } protected override void Dispose(bool disposing) { if (disposing && (this.components != null)) { this.components.Dispose(); } base.Dispose(disposing); } private string GetParam(MemberInfo mi) { string str = ""; if (!(mi is MethodInfo)) { return str; } ParameterInfo[] parameters = (mi as MethodInfo).GetParameters(); for (int i = 0; i < parameters.Length; i++) { if (str != "") { str = str + ","; } str = str + parameters[i].Name; } return ("(" + str + ")"); } private string GetParamDesc(MemberInfo mi) { string str = ""; if (mi is MethodInfo) { ParameterInfo[] parameters = (mi as MethodInfo).GetParameters(); for (int i = 0; i < parameters.Length; i++) { string str3 = str; str = str3 + parameters[i].Name + "\t:" + this.ReplaceType(parameters[i].ParameterType) + "\r\n"; } } return str; } private void InitializeComponent() { this.components = new Container(); ResourceManager manager = new ResourceManager(typeof(SelectMethod)); this.tvMethod = new TreeView(); this.ilMethod = new ImageList(this.components); this.spLeft = new Splitter(); this.pnRight = new Panel(); this.lParam = new Label(); this.lDescription = new Label(); this.lName = new Label(); this.btnCancel = new Button(); this.btnOK = new Button(); this.pnRight.SuspendLayout(); base.SuspendLayout(); this.tvMethod.BorderStyle = BorderStyle.FixedSingle; this.tvMethod.Dock = DockStyle.Left; this.tvMethod.FullRowSelect = true; this.tvMethod.HideSelection = false; this.tvMethod.ImageList = this.ilMethod; this.tvMethod.Location = new Point(0, 0); this.tvMethod.Name = "tvMethod"; this.tvMethod.Size = new Size(360, 0x1ad); this.tvMethod.TabIndex = 4; this.tvMethod.DoubleClick += new EventHandler(this.tvMethod_DoubleClick); this.tvMethod.AfterSelect += new TreeViewEventHandler(this.tvMethod_AfterSelect); this.ilMethod.ImageSize = new Size(0x10, 0x10); this.ilMethod.ImageStream = (ImageListStreamer) manager.GetObject("ilMethod.ImageStream"); this.ilMethod.TransparentColor = Color.Transparent; this.spLeft.Location = new Point(360, 0); this.spLeft.Name = "spLeft"; this.spLeft.Size = new Size(3, 0x1ad); this.spLeft.TabIndex = 5; this.spLeft.TabStop = false; this.pnRight.Controls.Add(this.lParam); this.pnRight.Controls.Add(this.lDescription); this.pnRight.Controls.Add(this.lName); this.pnRight.Controls.Add(this.btnCancel); this.pnRight.Controls.Add(this.btnOK); this.pnRight.Dock = DockStyle.Fill; this.pnRight.Location = new Point(0x16b, 0); this.pnRight.Name = "pnRight"; this.pnRight.Size = new Size(0xf5, 0x1ad); this.pnRight.TabIndex = 6; this.lParam.ForeColor = Color.FromArgb(0xc0, 0x40, 0); this.lParam.Location = new Point(0x10, 0xd0); this.lParam.Name = "lParam"; this.lParam.Size = new Size(0xd8, 120); this.lParam.TabIndex = 4; this.lParam.Text = "Param"; this.lDescription.ForeColor = Color.Blue; this.lDescription.Location = new Point(0x10, 0x38); this.lDescription.Name = "lDescription"; this.lDescription.Size = new Size(0xd8, 0x88); this.lDescription.TabIndex = 3; this.lDescription.Text = "Description"; this.lName.AutoSize = true; this.lName.Location = new Point(0x10, 0x18); this.lName.Name = "lName"; this.lName.Size = new Size(0x26, 0x11); this.lName.TabIndex = 2; this.lName.Text = "Name"; this.btnCancel.Anchor = AnchorStyles.Right | AnchorStyles.Bottom; this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.btnCancel.Location = new Point(0x98, 0x180); this.btnCancel.Name = "btnCancel"; this.btnCancel.TabIndex = 1; this.btnCancel.Text = "Cancel"; this.btnOK.Anchor = AnchorStyles.Right | AnchorStyles.Bottom; this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK; this.btnOK.Location = new Point(0x40, 0x180); this.btnOK.Name = "btnOK"; this.btnOK.TabIndex = 0; this.btnOK.Text = "OK"; this.btnOK.Click += new EventHandler(this.btnOK_Click); base.AcceptButton = this.btnOK; this.AutoScaleBaseSize = new Size(6, 14); base.CancelButton = this.btnCancel; base.ClientSize = new Size(0x260, 0x1ad); base.Controls.Add(this.pnRight); base.Controls.Add(this.spLeft); base.Controls.Add(this.tvMethod); this.Font = new Font("Verdana", 8.5f); base.MinimumSize = new Size(500, 400); base.Name = "SelectMethod"; base.StartPosition = FormStartPosition.CenterScreen; this.Text = "Select Method"; base.Load += new EventHandler(this.SelectMethod_Load); this.pnRight.ResumeLayout(false); base.ResumeLayout(false); } private void RefreshTree() { this.tvMethod.BeginUpdate(); try { this.tvMethod.Nodes.Clear(); this.tvMethod.Nodes.Add("Root"); MemberInfo[] allMembers = FormulaBase.GetAllMembers(); for (int i = 0; i < allMembers.Length; i++) { object[] customAttributes = allMembers[i].GetCustomAttributes(false); TreeNode node = this.tvMethod.Nodes[0]; foreach (object obj2 in customAttributes) { if (!(obj2 is CategoryAttribute)) { continue; } TreeNode node2 = null; string category = (obj2 as CategoryAttribute).Category; for (int j = 0; j < node.Nodes.Count; j++) { if (node.Nodes[j].Text == category) { node2 = node.Nodes[j]; break; } } if (node2 == null) { node.Nodes.Add(node2 = new TreeNode(category, 0, 0)); } TreeNode node3 = new TreeNode(allMembers[i].Name + this.GetParam(allMembers[i]), 1, 1); node3.Tag = allMembers[i]; node2.Nodes.Add(node3); } } this.tvMethod.Nodes[0].Expand(); } finally { this.tvMethod.EndUpdate(); } } private string ReplaceType(Type t) { if (t == typeof(FormulaData)) { return "Data Array"; } if ((t == typeof(double)) || (t == typeof(int))) { return "Number"; } if (t == typeof(string)) { return "string"; } if (t == typeof(bool)) { return "TRUE or FALSE"; } return ""; } public string Select(string Default) { if (base.ShowDialog() == DialogResult.OK) { return this.Result; } return null; } private void SelectMethod_Load(object sender, EventArgs e) { this.RefreshTree(); } private void tvMethod_AfterSelect(object sender, TreeViewEventArgs e) { TreeNode selectedNode = this.tvMethod.SelectedNode; if ((selectedNode != null) && (selectedNode.Tag != null)) { MemberInfo tag = (MemberInfo) selectedNode.Tag; object[] customAttributes = tag.GetCustomAttributes(typeof(DescriptionAttribute), false); this.lName.Text = tag.Name; this.lDescription.Text = (customAttributes[0] as DescriptionAttribute).Description; this.lParam.Text = this.GetParamDesc(tag); } else { this.lName.Text = ""; this.lDescription.Text = ""; this.lParam.Text = ""; } } private void tvMethod_DoubleClick(object sender, EventArgs e) { TreeNode selectedNode = this.tvMethod.SelectedNode; if ((selectedNode != null) && (selectedNode.Tag != null)) { this.btnOK.PerformClick(); } } } }