SelectMethod.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. namespace IndexFormula.Finance.Win
  2. {
  3. using IndexFormula.Finance;
  4. using IndexFormula.Finance.Win.FormulaResx;
  5. using MuchInfo.Chart.Data.EnumTypes;
  6. using System;
  7. using System.ComponentModel;
  8. using System.Drawing;
  9. using System.Reflection;
  10. using System.Resources;
  11. using System.Windows.Forms;
  12. [ToolboxItem(false)]
  13. public class SelectMethod : Form
  14. {
  15. private Button btnCancel;
  16. private Button btnOK;
  17. private IContainer components;
  18. private ImageList ilMethod;
  19. private Label lDescription;
  20. private Label lName;
  21. private Label lParam;
  22. private Panel pnRight;
  23. private string Result;
  24. private Splitter spLeft;
  25. private TreeView tvMethod;
  26. public SelectMethod()
  27. {
  28. this.InitializeComponent();
  29. }
  30. private void btnOK_Click(object sender, EventArgs e)
  31. {
  32. this.Result = null;
  33. TreeNode selectedNode = this.tvMethod.SelectedNode;
  34. if ((selectedNode != null) && (selectedNode.Tag != null))
  35. {
  36. MemberInfo tag = (MemberInfo)selectedNode.Tag;
  37. this.Result = tag.Name + this.GetParam(tag);
  38. }
  39. }
  40. protected override void Dispose(bool disposing)
  41. {
  42. if (disposing && (this.components != null))
  43. {
  44. this.components.Dispose();
  45. }
  46. base.Dispose(disposing);
  47. }
  48. private string GetParam(MemberInfo mi)
  49. {
  50. string str = "";
  51. if (!(mi is MethodInfo))
  52. {
  53. return str;
  54. }
  55. ParameterInfo[] parameters = (mi as MethodInfo).GetParameters();
  56. for (int i = 0; i < parameters.Length; i++)
  57. {
  58. if (str != "")
  59. {
  60. str = str + ",";
  61. }
  62. str = str + parameters[i].Name;
  63. }
  64. return ("(" + str + ")");
  65. }
  66. private string GetParamDesc(MemberInfo mi)
  67. {
  68. string str = "";
  69. if (mi is MethodInfo)
  70. {
  71. ParameterInfo[] parameters = (mi as MethodInfo).GetParameters();
  72. for (int i = 0; i < parameters.Length; i++)
  73. {
  74. string str3 = str;
  75. str = str3 + parameters[i].Name + "\t:" + this.ReplaceType(parameters[i].ParameterType) + "\r\n";
  76. }
  77. }
  78. return str;
  79. }
  80. private void InitializeComponent()
  81. {
  82. this.components = new System.ComponentModel.Container();
  83. System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SelectMethod));
  84. this.tvMethod = new System.Windows.Forms.TreeView();
  85. this.ilMethod = new System.Windows.Forms.ImageList(this.components);
  86. this.spLeft = new System.Windows.Forms.Splitter();
  87. this.pnRight = new System.Windows.Forms.Panel();
  88. this.lParam = new System.Windows.Forms.Label();
  89. this.lDescription = new System.Windows.Forms.Label();
  90. this.lName = new System.Windows.Forms.Label();
  91. this.btnCancel = new System.Windows.Forms.Button();
  92. this.btnOK = new System.Windows.Forms.Button();
  93. this.pnRight.SuspendLayout();
  94. this.SuspendLayout();
  95. //
  96. // tvMethod
  97. //
  98. this.tvMethod.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  99. resources.ApplyResources(this.tvMethod, "tvMethod");
  100. this.tvMethod.FullRowSelect = true;
  101. this.tvMethod.HideSelection = false;
  102. this.tvMethod.ImageList = this.ilMethod;
  103. this.tvMethod.Name = "tvMethod";
  104. this.tvMethod.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tvMethod_AfterSelect);
  105. this.tvMethod.DoubleClick += new System.EventHandler(this.tvMethod_DoubleClick);
  106. //
  107. // ilMethod
  108. //
  109. this.ilMethod.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilMethod.ImageStream")));
  110. this.ilMethod.TransparentColor = System.Drawing.Color.Transparent;
  111. this.ilMethod.Images.SetKeyName(0, "");
  112. this.ilMethod.Images.SetKeyName(1, "");
  113. //
  114. // spLeft
  115. //
  116. resources.ApplyResources(this.spLeft, "spLeft");
  117. this.spLeft.Name = "spLeft";
  118. this.spLeft.TabStop = false;
  119. //
  120. // pnRight
  121. //
  122. this.pnRight.Controls.Add(this.lParam);
  123. this.pnRight.Controls.Add(this.lDescription);
  124. this.pnRight.Controls.Add(this.lName);
  125. this.pnRight.Controls.Add(this.btnCancel);
  126. this.pnRight.Controls.Add(this.btnOK);
  127. resources.ApplyResources(this.pnRight, "pnRight");
  128. this.pnRight.Name = "pnRight";
  129. //
  130. // lParam
  131. //
  132. this.lParam.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(64)))), ((int)(((byte)(0)))));
  133. resources.ApplyResources(this.lParam, "lParam");
  134. this.lParam.Name = "lParam";
  135. //
  136. // lDescription
  137. //
  138. this.lDescription.ForeColor = System.Drawing.Color.Blue;
  139. resources.ApplyResources(this.lDescription, "lDescription");
  140. this.lDescription.Name = "lDescription";
  141. //
  142. // lName
  143. //
  144. resources.ApplyResources(this.lName, "lName");
  145. this.lName.Name = "lName";
  146. //
  147. // btnCancel
  148. //
  149. resources.ApplyResources(this.btnCancel, "btnCancel");
  150. this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  151. this.btnCancel.Name = "btnCancel";
  152. //
  153. // btnOK
  154. //
  155. resources.ApplyResources(this.btnOK, "btnOK");
  156. this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
  157. this.btnOK.Name = "btnOK";
  158. this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
  159. //
  160. // SelectMethod
  161. //
  162. this.AcceptButton = this.btnOK;
  163. resources.ApplyResources(this, "$this");
  164. this.CancelButton = this.btnCancel;
  165. this.Controls.Add(this.pnRight);
  166. this.Controls.Add(this.spLeft);
  167. this.Controls.Add(this.tvMethod);
  168. this.Name = "SelectMethod";
  169. this.Load += new System.EventHandler(this.SelectMethod_Load);
  170. this.pnRight.ResumeLayout(false);
  171. this.pnRight.PerformLayout();
  172. this.ResumeLayout(false);
  173. }
  174. private void RefreshTree()
  175. {
  176. this.tvMethod.BeginUpdate();
  177. try
  178. {
  179. this.tvMethod.Nodes.Clear();
  180. this.tvMethod.Nodes.Add("Root");
  181. MemberInfo[] allMembers = FormulaBase.GetAllMembers();
  182. for (int i = 0; i < allMembers.Length; i++)
  183. {
  184. object[] customAttributes = allMembers[i].GetCustomAttributes(false);
  185. TreeNode node = this.tvMethod.Nodes[0];
  186. foreach (object obj2 in customAttributes)
  187. {
  188. if (!(obj2 is CategoryAttribute))
  189. {
  190. continue;
  191. }
  192. TreeNode node2 = null;
  193. string category = (obj2 as CategoryAttribute).Category;
  194. string treeNodeName = string.Empty;
  195. switch (SetLanguage.currentLanguage)
  196. {
  197. case ChartLanguageType.English:
  198. treeNodeName = (string)Formula_en.ResourceManager.GetObject(category);
  199. break;
  200. case ChartLanguageType.SimplifiedChinese:
  201. treeNodeName = (string)Formula_zh_Hans.ResourceManager.GetObject(category);
  202. break;
  203. case ChartLanguageType.TraditionalChinese:
  204. treeNodeName = (string)Formula_zh_Hant.ResourceManager.GetObject(category);
  205. break;
  206. default:
  207. treeNodeName = (string)Formula_en.ResourceManager.GetObject(category);
  208. break;
  209. }
  210. for (int j = 0; j < node.Nodes.Count; j++)
  211. {
  212. if (node.Nodes[j].Text == treeNodeName)
  213. {
  214. node2 = node.Nodes[j];
  215. break;
  216. }
  217. }
  218. if (node2 == null)
  219. {
  220. node.Nodes.Add(node2 = new TreeNode(treeNodeName, 0, 0));
  221. }
  222. TreeNode node3 = new TreeNode(allMembers[i].Name + this.GetParam(allMembers[i]), 1, 1);
  223. node3.Tag = allMembers[i];
  224. node2.Nodes.Add(node3);
  225. }
  226. }
  227. this.tvMethod.Nodes[0].Expand();
  228. }
  229. finally
  230. {
  231. this.tvMethod.EndUpdate();
  232. }
  233. }
  234. private string ReplaceType(Type t)
  235. {
  236. if (t == typeof(FormulaData))
  237. {
  238. return "Data Array";
  239. }
  240. if ((t == typeof(double)) || (t == typeof(int)))
  241. {
  242. return "Number";
  243. }
  244. if (t == typeof(string))
  245. {
  246. return "string";
  247. }
  248. if (t == typeof(bool))
  249. {
  250. return "TRUE or FALSE";
  251. }
  252. return "";
  253. }
  254. public string Select(string Default)
  255. {
  256. if (base.ShowDialog() == DialogResult.OK)
  257. {
  258. return this.Result;
  259. }
  260. return null;
  261. }
  262. private void SelectMethod_Load(object sender, EventArgs e)
  263. {
  264. this.RefreshTree();
  265. }
  266. private void tvMethod_AfterSelect(object sender, TreeViewEventArgs e)
  267. {
  268. TreeNode selectedNode = this.tvMethod.SelectedNode;
  269. if ((selectedNode != null) && (selectedNode.Tag != null))
  270. {
  271. MemberInfo tag = (MemberInfo)selectedNode.Tag;
  272. object[] customAttributes = tag.GetCustomAttributes(typeof(DescriptionAttribute), false);
  273. this.lName.Text = tag.Name;
  274. string resxName = (customAttributes[0] as DescriptionAttribute).Description;
  275. switch (SetLanguage.currentLanguage)
  276. {
  277. case ChartLanguageType.English:
  278. this.lDescription.Text = (string)Formula_en.ResourceManager.GetObject(resxName);
  279. break;
  280. case ChartLanguageType.SimplifiedChinese:
  281. this.lDescription.Text = (string)Formula_zh_Hans.ResourceManager.GetObject(resxName);
  282. break;
  283. case ChartLanguageType.TraditionalChinese:
  284. this.lDescription.Text = (string)Formula_zh_Hant.ResourceManager.GetObject(resxName);
  285. break;
  286. default:
  287. this.lDescription.Text = (string)Formula_en.ResourceManager.GetObject(resxName);
  288. break;
  289. }
  290. this.lParam.Text = this.GetParamDesc(tag);
  291. //this.lDescription.Text = (customAttributes[0] as DescriptionAttribute).Description;
  292. }
  293. else
  294. {
  295. this.lName.Text = "";
  296. this.lDescription.Text = "";
  297. this.lParam.Text = "";
  298. }
  299. }
  300. private void tvMethod_DoubleClick(object sender, EventArgs e)
  301. {
  302. TreeNode selectedNode = this.tvMethod.SelectedNode;
  303. if ((selectedNode != null) && (selectedNode.Tag != null))
  304. {
  305. this.btnOK.PerformClick();
  306. }
  307. }
  308. }
  309. }