| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- using System;
- using System.IO;
- using System.Windows.Forms;
- using Dongke.IBOSS.PRD.Basics.BaseResources;
- using Dongke.IBOSS.PRD.Basics.Library;
- using Dongke.IBOSS.PRD.Client.CommonModule;
- using Dongke.IBOSS.PRD.Client.DataModels;
- using Dongke.IBOSS.PRD.WCF.Proxys;
- using Dongke.IBOSS.PRD.Basics.DockPanel;
- using System.Collections;
- using System.Data;
- using System.Collections.Generic;
- using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
- using Dongke.IBOSS.PRD.WCF.DataModels;
- namespace Dongke.IBOSS.PRD.Client.SystemModule
- {
- public partial class F_MST_0103 : DockPanelBase
- {
- #region 成员变量
- private TreeNode _selectedNode = null; // 选择的节点
- private string _moveOrganizationCode=null; // 存储要移动的组织机构的编码
- #endregion
- #region 属性
- /// <summary>
- /// 选择的节点
- /// </summary>
- public TreeNode SelectedNode
- {
- get
- {
- return _selectedNode;
- }
- set
- {
- _selectedNode = value;
- }
- }
- #endregion
- #region 构造函数
- /// <summary>
- /// 构造函数
- /// </summary>
- public F_MST_0103()
- {
- InitializeComponent();
- // 窗体标题
- this.Text ="组织机构移动";
- // 按钮文本
- //this.btnConfirm.Text = Constant.BUTTON_TEXT_OK;
- //this.btnCancel.Text = Constant.BUTTON_TEXT_CANCEL;
- }
- /// <summary>
- /// 构造函数
- /// </summary>
- public F_MST_0103(string moveNode)
- {
- InitializeComponent();
- this.Text = "组织机构移动";
- this._moveOrganizationCode = moveNode;
- // 按钮文本
- //this.btnConfirm.Text = Constant.BUTTON_TEXT_OK;
- //this.btnCancel.Text = Constant.BUTTON_TEXT_CANCEL;
- }
- #endregion
- #region 事件
- /// <summary>
- /// 窗体加载事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void FrmMoveOrganization_Load(object sender, EventArgs e)
- {
- try
- {
- // 生成组织机构树形
- this.CreateOrganizationTree();
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 节点收缩之后,显示关闭图标
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tvwOrganization_AfterCollapse(object sender, TreeViewEventArgs e)
- {
- e.Node.SelectedImageIndex = 0;
- e.Node.ImageIndex = 0;
- }
- /// <summary>
- /// 节点展开之后,显示打开图标
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tvwOrganization_AfterExpand(object sender, TreeViewEventArgs e)
- {
- e.Node.SelectedImageIndex = 2;
- e.Node.ImageIndex = 2;
- }
- /// <summary>
- /// 选择组织机构
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnConfirm_Click(object sender, EventArgs e)
- {
- try
- {
- if (this.tvwOrganization.SelectedNode != null)
- {
- // 组织机构不能移动到其本身
- if (this._moveOrganizationCode.Equals(this.tvwOrganization.SelectedNode.Name))
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "组织机构不能移动到其本身"),
- this.Text,
- MessageBoxButtons.OK,
- MessageBoxIcon.Warning);
- return;
- }
- // 组织机构不能移动到其本身或者下级
- if (this.tvwOrganization.SelectedNode.Name.IndexOf(this._moveOrganizationCode) == 0)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "组织机构不能移动到其下级"),
- this.Text,
- MessageBoxButtons.OK,
- MessageBoxIcon.Warning);
- return;
- }
- this._selectedNode = tvwOrganization.SelectedNode;
- this.DialogResult = DialogResult.OK;
- this.Close();
- }
- else
- {
- //MessageBox.Show(string.Format(Messages.MESSAGE_W011,"组织机构"),
- // this.Text,
- // MessageBoxButtons.OK,
- // MessageBoxIcon.Warning);
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 关闭按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnCancel_Click(object sender, EventArgs e)
- {
- try
- {
- this.DialogResult = DialogResult.No;
- this.Close();
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 根据所取得的组织数据,生成树形
- /// </summary>
- private void CreateOrganizationTree()
- {
- try
- {
- // 取得组织机构数据
- OrganizationEntity organization = new OrganizationEntity();
- object[] valueFlags = new object[1];
- valueFlags[0] = 1;
- organization.ValueFlags = valueFlags;
- DataSet orgData = (DataSet)SystemModuleProxy.Service.SelectOrganizationData(organization);
- // 组织为空时,直接返回
- if (orgData == null || orgData.Tables[0].Rows.Count < 1)
- {
- return;
- }
- // 将所有节点清除
- this.tvwOrganization.Nodes.Clear();
- TreeNode organizationNode = null;
- DataRow[] organizationRows
- = orgData.Tables[0].Select("OrganizationCode LIKE '00%' AND LEN(OrganizationCode) = 3");
- // 显示节点
- InitTreeView(orgData.Tables[0], organizationRows, organizationNode);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 递归显示组织树形目录
- /// </summary>
- /// <param name="orgData">组织机构数据源</param>
- /// <param name="rows">根节点</param>
- /// <param name="node">树节点</param>
- private void InitTreeView(DataTable orgData, DataRow[] rows, TreeNode node)
- {
- foreach (DataRow row in rows)
- {
- TreeNode sNode = null;
- if (node == null)
- {
- // 新建树节点并添加
- sNode = new TreeNode();
- sNode.Text = row["OrganizationName"].ToString();
- sNode.Name = row["OrganizationCode"].ToString();
- sNode.Tag = row["OrganizationID"].ToString();
- this.tvwOrganization.Nodes.Add(sNode);
- }
- else
- {
- // 在原有树中加入节点
- sNode = node.Nodes.Add(row["OrganizationName"].ToString());
- sNode.Name = row["OrganizationCode"].ToString();
- sNode.Tag = row["OrganizationID"].ToString();
- }
- // 查找子节点
- string filterExpression = "OrganizationCode LIKE '" + row["OrganizationCode"].ToString()
- + "%' AND LEN(OrganizationCode) = " + (row["OrganizationCode"].ToString().Length + 3);
- DataRow[] subRows = orgData.Select(filterExpression);
- // 递归绑定子节点
- InitTreeView(orgData, subRows, sNode);
- }
- }
- #endregion
- }
- }
|