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 属性 /// /// 选择的节点 /// public TreeNode SelectedNode { get { return _selectedNode; } set { _selectedNode = value; } } #endregion #region 构造函数 /// /// 构造函数 /// public F_MST_0103() { InitializeComponent(); // 窗体标题 this.Text ="组织机构移动"; // 按钮文本 //this.btnConfirm.Text = Constant.BUTTON_TEXT_OK; //this.btnCancel.Text = Constant.BUTTON_TEXT_CANCEL; } /// /// 构造函数 /// 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 事件 /// /// 窗体加载事件 /// /// /// 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); } } /// /// 节点收缩之后,显示关闭图标 /// /// /// private void tvwOrganization_AfterCollapse(object sender, TreeViewEventArgs e) { e.Node.SelectedImageIndex = 0; e.Node.ImageIndex = 0; } /// /// 节点展开之后,显示打开图标 /// /// /// private void tvwOrganization_AfterExpand(object sender, TreeViewEventArgs e) { e.Node.SelectedImageIndex = 2; e.Node.ImageIndex = 2; } /// /// 选择组织机构 /// /// /// 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); } } /// /// 关闭按钮事件 /// /// /// 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 私有方法 /// /// 根据所取得的组织数据,生成树形 /// 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; } } /// /// 递归显示组织树形目录 /// /// 组织机构数据源 /// 根节点 /// 树节点 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 } }