F_MST_0103.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. using System;
  2. using System.IO;
  3. using System.Windows.Forms;
  4. using Dongke.IBOSS.PRD.Basics.BaseResources;
  5. using Dongke.IBOSS.PRD.Basics.Library;
  6. using Dongke.IBOSS.PRD.Client.CommonModule;
  7. using Dongke.IBOSS.PRD.Client.DataModels;
  8. using Dongke.IBOSS.PRD.WCF.Proxys;
  9. using Dongke.IBOSS.PRD.Basics.DockPanel;
  10. using System.Collections;
  11. using System.Data;
  12. using System.Collections.Generic;
  13. using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
  14. using Dongke.IBOSS.PRD.WCF.DataModels;
  15. namespace Dongke.IBOSS.PRD.Client.SystemModule
  16. {
  17. public partial class F_MST_0103 : DockPanelBase
  18. {
  19. #region 成员变量
  20. private TreeNode _selectedNode = null; // 选择的节点
  21. private string _moveOrganizationCode=null; // 存储要移动的组织机构的编码
  22. #endregion
  23. #region 属性
  24. /// <summary>
  25. /// 选择的节点
  26. /// </summary>
  27. public TreeNode SelectedNode
  28. {
  29. get
  30. {
  31. return _selectedNode;
  32. }
  33. set
  34. {
  35. _selectedNode = value;
  36. }
  37. }
  38. #endregion
  39. #region 构造函数
  40. /// <summary>
  41. /// 构造函数
  42. /// </summary>
  43. public F_MST_0103()
  44. {
  45. InitializeComponent();
  46. // 窗体标题
  47. this.Text ="组织机构移动";
  48. // 按钮文本
  49. //this.btnConfirm.Text = Constant.BUTTON_TEXT_OK;
  50. //this.btnCancel.Text = Constant.BUTTON_TEXT_CANCEL;
  51. }
  52. /// <summary>
  53. /// 构造函数
  54. /// </summary>
  55. public F_MST_0103(string moveNode)
  56. {
  57. InitializeComponent();
  58. this.Text = "组织机构移动";
  59. this._moveOrganizationCode = moveNode;
  60. // 按钮文本
  61. //this.btnConfirm.Text = Constant.BUTTON_TEXT_OK;
  62. //this.btnCancel.Text = Constant.BUTTON_TEXT_CANCEL;
  63. }
  64. #endregion
  65. #region 事件
  66. /// <summary>
  67. /// 窗体加载事件
  68. /// </summary>
  69. /// <param name="sender"></param>
  70. /// <param name="e"></param>
  71. private void FrmMoveOrganization_Load(object sender, EventArgs e)
  72. {
  73. try
  74. {
  75. // 生成组织机构树形
  76. this.CreateOrganizationTree();
  77. }
  78. catch (Exception ex)
  79. {
  80. // 对异常进行共通处理
  81. ExceptionManager.HandleEventException(this.ToString(),
  82. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  83. }
  84. }
  85. /// <summary>
  86. /// 节点收缩之后,显示关闭图标
  87. /// </summary>
  88. /// <param name="sender"></param>
  89. /// <param name="e"></param>
  90. private void tvwOrganization_AfterCollapse(object sender, TreeViewEventArgs e)
  91. {
  92. e.Node.SelectedImageIndex = 0;
  93. e.Node.ImageIndex = 0;
  94. }
  95. /// <summary>
  96. /// 节点展开之后,显示打开图标
  97. /// </summary>
  98. /// <param name="sender"></param>
  99. /// <param name="e"></param>
  100. private void tvwOrganization_AfterExpand(object sender, TreeViewEventArgs e)
  101. {
  102. e.Node.SelectedImageIndex = 2;
  103. e.Node.ImageIndex = 2;
  104. }
  105. /// <summary>
  106. /// 选择组织机构
  107. /// </summary>
  108. /// <param name="sender"></param>
  109. /// <param name="e"></param>
  110. private void btnConfirm_Click(object sender, EventArgs e)
  111. {
  112. try
  113. {
  114. if (this.tvwOrganization.SelectedNode != null)
  115. {
  116. // 组织机构不能移动到其本身
  117. if (this._moveOrganizationCode.Equals(this.tvwOrganization.SelectedNode.Name))
  118. {
  119. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "组织机构不能移动到其本身"),
  120. this.Text,
  121. MessageBoxButtons.OK,
  122. MessageBoxIcon.Warning);
  123. return;
  124. }
  125. // 组织机构不能移动到其本身或者下级
  126. if (this.tvwOrganization.SelectedNode.Name.IndexOf(this._moveOrganizationCode) == 0)
  127. {
  128. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "组织机构不能移动到其下级"),
  129. this.Text,
  130. MessageBoxButtons.OK,
  131. MessageBoxIcon.Warning);
  132. return;
  133. }
  134. this._selectedNode = tvwOrganization.SelectedNode;
  135. this.DialogResult = DialogResult.OK;
  136. this.Close();
  137. }
  138. else
  139. {
  140. //MessageBox.Show(string.Format(Messages.MESSAGE_W011,"组织机构"),
  141. // this.Text,
  142. // MessageBoxButtons.OK,
  143. // MessageBoxIcon.Warning);
  144. }
  145. }
  146. catch (Exception ex)
  147. {
  148. // 对异常进行共通处理
  149. ExceptionManager.HandleEventException(this.ToString(),
  150. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  151. }
  152. }
  153. /// <summary>
  154. /// 关闭按钮事件
  155. /// </summary>
  156. /// <param name="sender"></param>
  157. /// <param name="e"></param>
  158. private void btnCancel_Click(object sender, EventArgs e)
  159. {
  160. try
  161. {
  162. this.DialogResult = DialogResult.No;
  163. this.Close();
  164. }
  165. catch (Exception ex)
  166. {
  167. // 对异常进行共通处理
  168. ExceptionManager.HandleEventException(this.ToString(),
  169. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  170. }
  171. }
  172. #endregion
  173. #region 私有方法
  174. /// <summary>
  175. /// 根据所取得的组织数据,生成树形
  176. /// </summary>
  177. private void CreateOrganizationTree()
  178. {
  179. try
  180. {
  181. // 取得组织机构数据
  182. OrganizationEntity organization = new OrganizationEntity();
  183. object[] valueFlags = new object[1];
  184. valueFlags[0] = 1;
  185. organization.ValueFlags = valueFlags;
  186. DataSet orgData = (DataSet)SystemModuleProxy.Service.SelectOrganizationData(organization);
  187. // 组织为空时,直接返回
  188. if (orgData == null || orgData.Tables[0].Rows.Count < 1)
  189. {
  190. return;
  191. }
  192. // 将所有节点清除
  193. this.tvwOrganization.Nodes.Clear();
  194. TreeNode organizationNode = null;
  195. DataRow[] organizationRows
  196. = orgData.Tables[0].Select("OrganizationCode LIKE '00%' AND LEN(OrganizationCode) = 3");
  197. // 显示节点
  198. InitTreeView(orgData.Tables[0], organizationRows, organizationNode);
  199. }
  200. catch (Exception ex)
  201. {
  202. throw ex;
  203. }
  204. }
  205. /// <summary>
  206. /// 递归显示组织树形目录
  207. /// </summary>
  208. /// <param name="orgData">组织机构数据源</param>
  209. /// <param name="rows">根节点</param>
  210. /// <param name="node">树节点</param>
  211. private void InitTreeView(DataTable orgData, DataRow[] rows, TreeNode node)
  212. {
  213. foreach (DataRow row in rows)
  214. {
  215. TreeNode sNode = null;
  216. if (node == null)
  217. {
  218. // 新建树节点并添加
  219. sNode = new TreeNode();
  220. sNode.Text = row["OrganizationName"].ToString();
  221. sNode.Name = row["OrganizationCode"].ToString();
  222. sNode.Tag = row["OrganizationID"].ToString();
  223. this.tvwOrganization.Nodes.Add(sNode);
  224. }
  225. else
  226. {
  227. // 在原有树中加入节点
  228. sNode = node.Nodes.Add(row["OrganizationName"].ToString());
  229. sNode.Name = row["OrganizationCode"].ToString();
  230. sNode.Tag = row["OrganizationID"].ToString();
  231. }
  232. // 查找子节点
  233. string filterExpression = "OrganizationCode LIKE '" + row["OrganizationCode"].ToString()
  234. + "%' AND LEN(OrganizationCode) = " + (row["OrganizationCode"].ToString().Length + 3);
  235. DataRow[] subRows = orgData.Select(filterExpression);
  236. // 递归绑定子节点
  237. InitTreeView(orgData, subRows, sNode);
  238. }
  239. }
  240. #endregion
  241. }
  242. }