PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/ZXFramework_2/source/Tool/HF.WorkFlow.Tool/FrmworkTreeFrm.cs

#
C# | 310 lines | 297 code | 12 blank | 1 comment | 9 complexity | 7ae126505ea5ee33a5c8b401511bfee7 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, Apache-2.0, GPL-2.0, BSD-3-Clause, LGPL-2.0, MIT, GPL-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.IO;
  8. using System.Windows.Forms;
  9. using HF.Framework.UI.BaseForms;
  10. using HF.Framework;
  11. using HF.WorkFlow.Navigate;
  12. using HF.WorkFlow.DataContract;
  13. using HF.WorkFlow.Const;
  14. using HF.Framework.Windows;
  15. namespace HF.WorkFlow.Tool
  16. {
  17. public partial class FrmworkTreeFrm : BaseForm_Single
  18. {
  19. private string formState;//窗体状态,是修改还是新建
  20. private string InfoId;//操做主键
  21. private HFTreeNode NowTreeNode;//当前节点
  22. private FrmworkTreeEntity NowTreeNodeEntity;
  23. public FrmworkTreeFrm()
  24. {
  25. InitializeComponent();
  26. }
  27. private void initImage()
  28. {
  29. //AboutFrm
  30. this.Icon = HF.Resources.Properties.Resources.HF_AppMainIcon;
  31. }
  32. public FrmworkTreeFrm(string state, string iInfoId, HFTreeNode node)
  33. {
  34. InitializeComponent();
  35. formState = state;
  36. InfoId = iInfoId;
  37. NowTreeNode = node;
  38. NowTreeNodeEntity = (FrmworkTreeEntity)node.Tag;
  39. if (formState == WorkFlowConst.STATE_ADD)
  40. {
  41. this.Text = "新建模块";
  42. this.tbxFatherCaption.Text = NowTreeNodeEntity.Caption;
  43. rbtnWindow.Checked = true;//默认弹出窗体
  44. cbxOpenType.SelectedIndex = 1;//默认新窗口打开
  45. cbxRunType.SelectedIndex = 1;//默认双击执行
  46. }
  47. else
  48. {
  49. this.Text = "修改模块";
  50. getInfoById();
  51. }
  52. }
  53. private void getInfoById()
  54. {
  55. this.tbxNodeCaption.Text = NowTreeNodeEntity.Caption;
  56. if (NowTreeNode.Parent != null)
  57. {
  58. this.tbxFatherCaption.Text = NowTreeNode.Parent.Text; //上级节点名称,只做显示。
  59. }
  60. this.tbxDllFile.Text = NowTreeNodeEntity.DllFileName;
  61. string AssemblyName = Global.AppPath + "\\" + tbxDllFile.Text;
  62. if (File.Exists(AssemblyName) == false)
  63. {
  64. WorkDialog.WarningDlg("未找到程序集:" + AssemblyName + ",请将该程序集复制到程序运行目录下!", "警告");
  65. return;
  66. }
  67. loadClass(AssemblyName);
  68. if (string.IsNullOrEmpty(NowTreeNodeEntity.DllClassName)==false)
  69. this.cbxClassName.SelectedIndex =cbxClassName.Items.IndexOf( NowTreeNodeEntity.DllClassName);
  70. loadMethod(AssemblyName, NowTreeNodeEntity.DllClassName);
  71. this.tbxDescription.Text = NowTreeNodeEntity.Description;
  72. rbtnWindow.Checked = (NowTreeNodeEntity.NodeType == WorkFlowConst.TREENODE_TYPE_WIN);//弹出窗体
  73. cbxOpenType.Enabled = (NowTreeNodeEntity.NodeType == WorkFlowConst.TREENODE_TYPE_WIN);//窗口打开方式
  74. rbtnFunction.Checked = (NowTreeNodeEntity.NodeType == WorkFlowConst.TREENODE_TYPE_FUN);//执行功能
  75. cbxMethodName.Enabled = (NowTreeNodeEntity.NodeType == WorkFlowConst.TREENODE_TYPE_FUN);//功能名称
  76. if (string.IsNullOrEmpty(NowTreeNodeEntity.OpenWindowType) == false)
  77. cbxOpenType.SelectedIndex = cbxOpenType.Items.IndexOf(NowTreeNodeEntity.OpenWindowType);//打开方式 新窗口/独占
  78. if (string.IsNullOrEmpty(NowTreeNodeEntity.DllMethodName) == false)
  79. cbxMethodName.SelectedIndex = cbxMethodName.Items.IndexOf(NowTreeNodeEntity.DllMethodName);//功能名
  80. if (NowTreeNodeEntity.MouseIsClick)
  81. {
  82. cbxRunType.SelectedIndex = 0;//单击
  83. }
  84. else
  85. {
  86. cbxRunType.SelectedIndex = 1;//双击
  87. }
  88. this.cbxVisable.Checked = NowTreeNodeEntity.IsVisable;
  89. this.cmbxImageIndex.SelectedIndex = NowTreeNodeEntity.ImageIndex;
  90. }
  91. private void btnClose_Click(object sender, EventArgs e)
  92. {
  93. this.Close();
  94. }
  95. private bool checkData()
  96. {
  97. if (string.IsNullOrEmpty(tbxNodeCaption.Text))
  98. {
  99. WorkDialog.WarningDlg("当前节点名称不能为空!","警告");
  100. tbxNodeCaption.Focus();
  101. return false;
  102. }
  103. if (string.IsNullOrEmpty(tbxDllFile.Text))
  104. {
  105. WorkDialog.WarningDlg("模块DLL文件不能为空!", "警告");
  106. tbxDllFile.Focus();
  107. return false;
  108. }
  109. if (cbxClassName.SelectedIndex<1)
  110. {
  111. WorkDialog.WarningDlg("请选择类名!", "警告");
  112. cbxClassName.Focus();
  113. return false;
  114. }
  115. if (rbtnFunction.Checked && cbxMethodName.SelectedIndex < 1)
  116. {
  117. WorkDialog.WarningDlg("请选择执行的功能!", "警告");
  118. cbxMethodName.Focus();
  119. return false;
  120. }
  121. if (rbtnWindow.Checked && cbxOpenType.SelectedIndex < 0)
  122. {
  123. WorkDialog.WarningDlg("请选择窗体打开方式!", "警告");
  124. cbxOpenType.Focus();
  125. return false;
  126. }
  127. if (cbxRunType.SelectedIndex < 0)
  128. {
  129. WorkDialog.WarningDlg("请选择执行方式!", "警告");
  130. cbxRunType.Focus();
  131. return false;
  132. }
  133. return true;
  134. }
  135. private void btnSave_Click(object sender, EventArgs e)
  136. {
  137. if (checkData() == false) return;
  138. if (formState == WorkFlowConst.STATE_ADD)
  139. {
  140. FrmworkTreeEntity entity = new FrmworkTreeEntity();
  141. entity.FatherId = NowTreeNode.NodeId;
  142. entity.TreeId = Guid.NewGuid().ToString();
  143. entity.Caption = this.tbxNodeCaption.Text;
  144. entity.DllFileName = this.tbxDllFile.Text;
  145. entity.DllClassName = this.cbxClassName.SelectedItem.ToString();
  146. entity.Description = this.tbxDescription.Text;
  147. entity.MouseIsClick = (this.cbxRunType.SelectedIndex == 0);
  148. entity.IsVisable = this.cbxVisable.Checked;
  149. if (rbtnWindow.Checked)
  150. {
  151. entity.NodeType = WorkFlowConst.TREENODE_TYPE_WIN;
  152. entity.OpenWindowType = this.cbxOpenType.SelectedItem.ToString();
  153. }
  154. else
  155. {
  156. entity.NodeType = WorkFlowConst.TREENODE_TYPE_FUN;
  157. entity.DllMethodName = this.cbxMethodName.SelectedItem.ToString();
  158. }
  159. entity.ImageIndex = this.cmbxImageIndex.SelectedIndex;
  160. FrmworkTreeData.GetInstance().Insert(entity);
  161. HFTreeNode tmpNode = new HFTreeNode();
  162. tmpNode.NodeId = entity.TreeId;
  163. tmpNode.Text = entity.Caption;
  164. tmpNode.ImageIndex = entity.ImageIndex;
  165. tmpNode.SelectedImageIndex = entity.ImageIndex;
  166. tmpNode.Tag = entity;
  167. NowTreeNode.Nodes.Add(tmpNode);
  168. }
  169. else
  170. {
  171. NowTreeNodeEntity.Caption = this.tbxNodeCaption.Text;
  172. NowTreeNodeEntity.DllFileName = this.tbxDllFile.Text;
  173. NowTreeNodeEntity.DllClassName = this.cbxClassName.SelectedItem.ToString();
  174. NowTreeNodeEntity.Description = this.tbxDescription.Text;
  175. NowTreeNodeEntity.MouseIsClick = (this.cbxRunType.SelectedIndex == 0);
  176. NowTreeNodeEntity.IsVisable = this.cbxVisable.Checked;
  177. if (rbtnWindow.Checked)
  178. {
  179. NowTreeNodeEntity.NodeType = WorkFlowConst.TREENODE_TYPE_WIN;
  180. NowTreeNodeEntity.OpenWindowType = this.cbxOpenType.SelectedItem.ToString();
  181. }
  182. else
  183. {
  184. NowTreeNodeEntity.NodeType = WorkFlowConst.TREENODE_TYPE_FUN;
  185. NowTreeNodeEntity.DllMethodName = this.cbxMethodName.SelectedItem.ToString();
  186. }
  187. NowTreeNodeEntity.ImageIndex = this.cmbxImageIndex.SelectedIndex;
  188. FrmworkTreeData.GetInstance().Update(NowTreeNodeEntity);
  189. NowTreeNode.NodeId = NowTreeNodeEntity.TreeId;
  190. NowTreeNode.Text = NowTreeNodeEntity.Caption;
  191. NowTreeNode.ImageIndex = NowTreeNodeEntity.ImageIndex;
  192. NowTreeNode.SelectedImageIndex = NowTreeNodeEntity.ImageIndex;
  193. }
  194. this.Close();
  195. }
  196. private void cmbxNodeType_SelectedIndexChanged(object sender, EventArgs e)
  197. {
  198. }
  199. private void FrmworkTreeFrm_Load(object sender, EventArgs e)
  200. {
  201. initImage();
  202. }
  203. private void rbtnWindow_CheckedChanged(object sender, EventArgs e)
  204. {
  205. cbxOpenType.Enabled = (rbtnWindow.Checked);
  206. cbxMethodName.Enabled = rbtnFunction.Checked;
  207. }
  208. private void loadCombobox(List<string> list,ComboBox cb)
  209. {
  210. cb.Items.Clear();
  211. cb.Items.Add("请选择...");
  212. foreach (string each in list)
  213. {
  214. cb.Items.Add(each);
  215. }
  216. }
  217. private void loadClass(string assemblyName)
  218. {
  219. List<string> classList = DynamicLibrary.GetAssemblyClassList(assemblyName);
  220. loadCombobox(classList, cbxClassName);
  221. }
  222. private void loadMethod(string assemblyName, string className)
  223. {
  224. List<string> methodList = DynamicLibrary.GetAssemblyMethodList(assemblyName, className);
  225. loadCombobox(methodList, cbxMethodName);
  226. }
  227. private void btnOpenDll_Click(object sender, EventArgs e)
  228. {
  229. if (openFileDialog1.ShowDialog() == DialogResult.OK)
  230. {
  231. string fileName =Path.GetFileName(openFileDialog1.FileName);
  232. tbxDllFile.Text = fileName;
  233. string AssemblyName = Global.AppPath + "\\" + fileName;
  234. if (File.Exists(AssemblyName) == false)
  235. {
  236. WorkDialog.WarningDlg("未找到程序集:"+AssemblyName+",请将该程序集复制到程序运行目录下!","警告");
  237. return ;
  238. }
  239. loadClass(AssemblyName);
  240. }
  241. }
  242. private void btnLoadClass_Click(object sender, EventArgs e)
  243. {
  244. }
  245. private void cbxMethodName_DropDown(object sender, EventArgs e)
  246. {
  247. string ClassName = cbxClassName.SelectedItem.ToString();
  248. string AssemblyName = Global.AppPath + "\\" + tbxDllFile.Text;
  249. if (File.Exists(AssemblyName) == false)
  250. {
  251. WorkDialog.WarningDlg("未找到程序集:" + AssemblyName + ",请将该程序集复制到程序运行目录下!", "警告");
  252. return;
  253. }
  254. if (cbxClassName.SelectedIndex < 1)
  255. {
  256. WorkDialog.WarningDlg("请先选择类名!", "警告");
  257. return;
  258. }
  259. loadMethod(AssemblyName, ClassName);
  260. }
  261. private void cbxClassName_DropDown(object sender, EventArgs e)
  262. {
  263. string AssemblyName = Global.AppPath + "\\" + tbxDllFile.Text;
  264. if (File.Exists(AssemblyName) == false)
  265. {
  266. WorkDialog.WarningDlg("未找到程序集:" + AssemblyName + ",请将该程序集复制到程序运行目录下!", "警告");
  267. return;
  268. }
  269. loadClass(AssemblyName);
  270. }
  271. }
  272. }