SelectMethod.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. namespace Easychart.Finance.Win
  2. {
  3. using Easychart.Finance;
  4. using System;
  5. using System.ComponentModel;
  6. using System.Drawing;
  7. using System.Reflection;
  8. using System.Resources;
  9. using System.Windows.Forms;
  10. [ToolboxItem(false)]
  11. public class SelectMethod : Form
  12. {
  13. private Button btnCancel;
  14. private Button btnOK;
  15. private IContainer components;
  16. private ImageList ilMethod;
  17. private Label lDescription;
  18. private Label lName;
  19. private Label lParam;
  20. private Panel pnRight;
  21. private string Result;
  22. private Splitter spLeft;
  23. private TreeView tvMethod;
  24. public SelectMethod()
  25. {
  26. this.InitializeComponent();
  27. }
  28. private void btnOK_Click(object sender, EventArgs e)
  29. {
  30. this.Result = null;
  31. TreeNode selectedNode = this.tvMethod.SelectedNode;
  32. if ((selectedNode != null) && (selectedNode.Tag != null))
  33. {
  34. MemberInfo tag = (MemberInfo) selectedNode.Tag;
  35. this.Result = tag.Name + this.GetParam(tag);
  36. }
  37. }
  38. protected override void Dispose(bool disposing)
  39. {
  40. if (disposing && (this.components != null))
  41. {
  42. this.components.Dispose();
  43. }
  44. base.Dispose(disposing);
  45. }
  46. private string GetParam(MemberInfo mi)
  47. {
  48. string str = "";
  49. if (!(mi is MethodInfo))
  50. {
  51. return str;
  52. }
  53. ParameterInfo[] parameters = (mi as MethodInfo).GetParameters();
  54. for (int i = 0; i < parameters.Length; i++)
  55. {
  56. if (str != "")
  57. {
  58. str = str + ",";
  59. }
  60. str = str + parameters[i].Name;
  61. }
  62. return ("(" + str + ")");
  63. }
  64. private string GetParamDesc(MemberInfo mi)
  65. {
  66. string str = "";
  67. if (mi is MethodInfo)
  68. {
  69. ParameterInfo[] parameters = (mi as MethodInfo).GetParameters();
  70. for (int i = 0; i < parameters.Length; i++)
  71. {
  72. string str3 = str;
  73. str = str3 + parameters[i].Name + "\t:" + this.ReplaceType(parameters[i].ParameterType) + "\r\n";
  74. }
  75. }
  76. return str;
  77. }
  78. private void InitializeComponent()
  79. {
  80. this.components = new Container();
  81. ResourceManager manager = new ResourceManager(typeof(SelectMethod));
  82. this.tvMethod = new TreeView();
  83. this.ilMethod = new ImageList(this.components);
  84. this.spLeft = new Splitter();
  85. this.pnRight = new Panel();
  86. this.lParam = new Label();
  87. this.lDescription = new Label();
  88. this.lName = new Label();
  89. this.btnCancel = new Button();
  90. this.btnOK = new Button();
  91. this.pnRight.SuspendLayout();
  92. base.SuspendLayout();
  93. this.tvMethod.BorderStyle = BorderStyle.FixedSingle;
  94. this.tvMethod.Dock = DockStyle.Left;
  95. this.tvMethod.FullRowSelect = true;
  96. this.tvMethod.HideSelection = false;
  97. this.tvMethod.ImageList = this.ilMethod;
  98. this.tvMethod.Location = new Point(0, 0);
  99. this.tvMethod.Name = "tvMethod";
  100. this.tvMethod.Size = new Size(360, 0x1ad);
  101. this.tvMethod.TabIndex = 4;
  102. this.tvMethod.DoubleClick += new EventHandler(this.tvMethod_DoubleClick);
  103. this.tvMethod.AfterSelect += new TreeViewEventHandler(this.tvMethod_AfterSelect);
  104. this.ilMethod.ImageSize = new Size(0x10, 0x10);
  105. this.ilMethod.ImageStream = (ImageListStreamer) manager.GetObject("ilMethod.ImageStream");
  106. this.ilMethod.TransparentColor = Color.Transparent;
  107. this.spLeft.Location = new Point(360, 0);
  108. this.spLeft.Name = "spLeft";
  109. this.spLeft.Size = new Size(3, 0x1ad);
  110. this.spLeft.TabIndex = 5;
  111. this.spLeft.TabStop = false;
  112. this.pnRight.Controls.Add(this.lParam);
  113. this.pnRight.Controls.Add(this.lDescription);
  114. this.pnRight.Controls.Add(this.lName);
  115. this.pnRight.Controls.Add(this.btnCancel);
  116. this.pnRight.Controls.Add(this.btnOK);
  117. this.pnRight.Dock = DockStyle.Fill;
  118. this.pnRight.Location = new Point(0x16b, 0);
  119. this.pnRight.Name = "pnRight";
  120. this.pnRight.Size = new Size(0xf5, 0x1ad);
  121. this.pnRight.TabIndex = 6;
  122. this.lParam.ForeColor = Color.FromArgb(0xc0, 0x40, 0);
  123. this.lParam.Location = new Point(0x10, 0xd0);
  124. this.lParam.Name = "lParam";
  125. this.lParam.Size = new Size(0xd8, 120);
  126. this.lParam.TabIndex = 4;
  127. this.lParam.Text = "Param";
  128. this.lDescription.ForeColor = Color.Blue;
  129. this.lDescription.Location = new Point(0x10, 0x38);
  130. this.lDescription.Name = "lDescription";
  131. this.lDescription.Size = new Size(0xd8, 0x88);
  132. this.lDescription.TabIndex = 3;
  133. this.lDescription.Text = "Description";
  134. this.lName.AutoSize = true;
  135. this.lName.Location = new Point(0x10, 0x18);
  136. this.lName.Name = "lName";
  137. this.lName.Size = new Size(0x26, 0x11);
  138. this.lName.TabIndex = 2;
  139. this.lName.Text = "Name";
  140. this.btnCancel.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
  141. this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  142. this.btnCancel.Location = new Point(0x98, 0x180);
  143. this.btnCancel.Name = "btnCancel";
  144. this.btnCancel.TabIndex = 1;
  145. this.btnCancel.Text = "Cancel";
  146. this.btnOK.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
  147. this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
  148. this.btnOK.Location = new Point(0x40, 0x180);
  149. this.btnOK.Name = "btnOK";
  150. this.btnOK.TabIndex = 0;
  151. this.btnOK.Text = "OK";
  152. this.btnOK.Click += new EventHandler(this.btnOK_Click);
  153. base.AcceptButton = this.btnOK;
  154. this.AutoScaleBaseSize = new Size(6, 14);
  155. base.CancelButton = this.btnCancel;
  156. base.ClientSize = new Size(0x260, 0x1ad);
  157. base.Controls.Add(this.pnRight);
  158. base.Controls.Add(this.spLeft);
  159. base.Controls.Add(this.tvMethod);
  160. this.Font = new Font("Verdana", 8.5f);
  161. base.MinimumSize = new Size(500, 400);
  162. base.Name = "SelectMethod";
  163. base.StartPosition = FormStartPosition.CenterScreen;
  164. this.Text = "Select Method";
  165. base.Load += new EventHandler(this.SelectMethod_Load);
  166. this.pnRight.ResumeLayout(false);
  167. base.ResumeLayout(false);
  168. }
  169. private void RefreshTree()
  170. {
  171. this.tvMethod.BeginUpdate();
  172. try
  173. {
  174. this.tvMethod.Nodes.Clear();
  175. this.tvMethod.Nodes.Add("Root");
  176. MemberInfo[] allMembers = FormulaBase.GetAllMembers();
  177. for (int i = 0; i < allMembers.Length; i++)
  178. {
  179. object[] customAttributes = allMembers[i].GetCustomAttributes(false);
  180. TreeNode node = this.tvMethod.Nodes[0];
  181. foreach (object obj2 in customAttributes)
  182. {
  183. if (!(obj2 is CategoryAttribute))
  184. {
  185. continue;
  186. }
  187. TreeNode node2 = null;
  188. string category = (obj2 as CategoryAttribute).Category;
  189. for (int j = 0; j < node.Nodes.Count; j++)
  190. {
  191. if (node.Nodes[j].Text == category)
  192. {
  193. node2 = node.Nodes[j];
  194. break;
  195. }
  196. }
  197. if (node2 == null)
  198. {
  199. node.Nodes.Add(node2 = new TreeNode(category, 0, 0));
  200. }
  201. TreeNode node3 = new TreeNode(allMembers[i].Name + this.GetParam(allMembers[i]), 1, 1);
  202. node3.Tag = allMembers[i];
  203. node2.Nodes.Add(node3);
  204. }
  205. }
  206. this.tvMethod.Nodes[0].Expand();
  207. }
  208. finally
  209. {
  210. this.tvMethod.EndUpdate();
  211. }
  212. }
  213. private string ReplaceType(Type t)
  214. {
  215. if (t == typeof(FormulaData))
  216. {
  217. return "Data Array";
  218. }
  219. if ((t == typeof(double)) || (t == typeof(int)))
  220. {
  221. return "Number";
  222. }
  223. if (t == typeof(string))
  224. {
  225. return "string";
  226. }
  227. if (t == typeof(bool))
  228. {
  229. return "TRUE or FALSE";
  230. }
  231. return "";
  232. }
  233. public string Select(string Default)
  234. {
  235. if (base.ShowDialog() == DialogResult.OK)
  236. {
  237. return this.Result;
  238. }
  239. return null;
  240. }
  241. private void SelectMethod_Load(object sender, EventArgs e)
  242. {
  243. this.RefreshTree();
  244. }
  245. private void tvMethod_AfterSelect(object sender, TreeViewEventArgs e)
  246. {
  247. TreeNode selectedNode = this.tvMethod.SelectedNode;
  248. if ((selectedNode != null) && (selectedNode.Tag != null))
  249. {
  250. MemberInfo tag = (MemberInfo) selectedNode.Tag;
  251. object[] customAttributes = tag.GetCustomAttributes(typeof(DescriptionAttribute), false);
  252. this.lName.Text = tag.Name;
  253. this.lDescription.Text = (customAttributes[0] as DescriptionAttribute).Description;
  254. this.lParam.Text = this.GetParamDesc(tag);
  255. }
  256. else
  257. {
  258. this.lName.Text = "";
  259. this.lDescription.Text = "";
  260. this.lParam.Text = "";
  261. }
  262. }
  263. private void tvMethod_DoubleClick(object sender, EventArgs e)
  264. {
  265. TreeNode selectedNode = this.tvMethod.SelectedNode;
  266. if ((selectedNode != null) && (selectedNode.Tag != null))
  267. {
  268. this.btnOK.PerformClick();
  269. }
  270. }
  271. }
  272. }