namespace IndexFormula.Finance.Win { using IndexFormula.Finance; using IndexFormula.Finance.Win.FormulaResx; using MuchInfo.Chart.Data.EnumTypes; 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 System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SelectMethod)); this.tvMethod = new System.Windows.Forms.TreeView(); this.ilMethod = new System.Windows.Forms.ImageList(this.components); this.spLeft = new System.Windows.Forms.Splitter(); this.pnRight = new System.Windows.Forms.Panel(); this.lParam = new System.Windows.Forms.Label(); this.lDescription = new System.Windows.Forms.Label(); this.lName = new System.Windows.Forms.Label(); this.btnCancel = new System.Windows.Forms.Button(); this.btnOK = new System.Windows.Forms.Button(); this.pnRight.SuspendLayout(); this.SuspendLayout(); // // tvMethod // this.tvMethod.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; resources.ApplyResources(this.tvMethod, "tvMethod"); this.tvMethod.FullRowSelect = true; this.tvMethod.HideSelection = false; this.tvMethod.ImageList = this.ilMethod; this.tvMethod.Name = "tvMethod"; this.tvMethod.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tvMethod_AfterSelect); this.tvMethod.DoubleClick += new System.EventHandler(this.tvMethod_DoubleClick); // // ilMethod // this.ilMethod.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilMethod.ImageStream"))); this.ilMethod.TransparentColor = System.Drawing.Color.Transparent; this.ilMethod.Images.SetKeyName(0, ""); this.ilMethod.Images.SetKeyName(1, ""); // // spLeft // resources.ApplyResources(this.spLeft, "spLeft"); this.spLeft.Name = "spLeft"; this.spLeft.TabStop = false; // // pnRight // 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); resources.ApplyResources(this.pnRight, "pnRight"); this.pnRight.Name = "pnRight"; // // lParam // this.lParam.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(64)))), ((int)(((byte)(0))))); resources.ApplyResources(this.lParam, "lParam"); this.lParam.Name = "lParam"; // // lDescription // this.lDescription.ForeColor = System.Drawing.Color.Blue; resources.ApplyResources(this.lDescription, "lDescription"); this.lDescription.Name = "lDescription"; // // lName // resources.ApplyResources(this.lName, "lName"); this.lName.Name = "lName"; // // btnCancel // resources.ApplyResources(this.btnCancel, "btnCancel"); this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.btnCancel.Name = "btnCancel"; // // btnOK // resources.ApplyResources(this.btnOK, "btnOK"); this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK; this.btnOK.Name = "btnOK"; this.btnOK.Click += new System.EventHandler(this.btnOK_Click); // // SelectMethod // this.AcceptButton = this.btnOK; resources.ApplyResources(this, "$this"); this.CancelButton = this.btnCancel; this.Controls.Add(this.pnRight); this.Controls.Add(this.spLeft); this.Controls.Add(this.tvMethod); this.Name = "SelectMethod"; this.Load += new System.EventHandler(this.SelectMethod_Load); this.pnRight.ResumeLayout(false); this.pnRight.PerformLayout(); this.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; string treeNodeName = string.Empty; switch (SetLanguage.currentLanguage) { case ChartLanguageType.English: treeNodeName = (string)Formula_en.ResourceManager.GetObject(category); break; case ChartLanguageType.SimplifiedChinese: treeNodeName = (string)Formula_zh_Hans.ResourceManager.GetObject(category); break; case ChartLanguageType.TraditionalChinese: treeNodeName = (string)Formula_zh_Hant.ResourceManager.GetObject(category); break; default: treeNodeName = (string)Formula_en.ResourceManager.GetObject(category); break; } for (int j = 0; j < node.Nodes.Count; j++) { if (node.Nodes[j].Text == treeNodeName) { node2 = node.Nodes[j]; break; } } if (node2 == null) { node.Nodes.Add(node2 = new TreeNode(treeNodeName, 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; string resxName = (customAttributes[0] as DescriptionAttribute).Description; switch (SetLanguage.currentLanguage) { case ChartLanguageType.English: this.lDescription.Text = (string)Formula_en.ResourceManager.GetObject(resxName); break; case ChartLanguageType.SimplifiedChinese: this.lDescription.Text = (string)Formula_zh_Hans.ResourceManager.GetObject(resxName); break; case ChartLanguageType.TraditionalChinese: this.lDescription.Text = (string)Formula_zh_Hant.ResourceManager.GetObject(resxName); break; default: this.lDescription.Text = (string)Formula_en.ResourceManager.GetObject(resxName); break; } this.lParam.Text = this.GetParamDesc(tag); //this.lDescription.Text = (customAttributes[0] as DescriptionAttribute).Description; } 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(); } } } }