Пример #1
0
 private void ForeachNode(TreeNode node)
 {
     if (node.Nodes.Count == 0)
     {
         DepartmentLayer layer   = (DepartmentLayer)node.Tag;
         int[]           deptids = layer.GetDepartment( );
         for (int i = 0; i < deptids.Length; i++)
         {
             Department   dept = new Department(deptids[i]);
             ListViewItem item = new ListViewItem( );
             item.Text = dept.Name;
             item.Tag  = dept;
             if (dept.NoUse == 1)
             {
                 item.ImageIndex = 4;
             }
             else
             {
                 item.ImageIndex = 3;
             }
             lvwDept.Items.Add(item);
         }
     }
     else
     {
         foreach (TreeNode nd in node.Nodes)
         {
             ForeachNode(nd);
         }
     }
 }
Пример #2
0
 private void FrmLayerAttr_Load(object sender, EventArgs e)
 {
     if (layer != null)
     {
         txtLayerName.Text = layer.LayerName;
         DepartmentLayer pLayer = new DepartmentLayer(layer.ParentLayerId);
         txtParentLayer.Text = pLayer.LayerName;
         txtParentLayer.Tag  = pLayer;
     }
 }
Пример #3
0
        private void EditLayer()
        {
            if (tvwDeptlayer.SelectedNode == null)
            {
                return;
            }

            DepartmentLayer layer    = (DepartmentLayer)tvwDeptlayer.SelectedNode.Tag;
            FrmLayerAttr    frmLayer = new FrmLayerAttr(this.tvwDeptlayer, layer);

            frmLayer.ShowDialog( );
        }
Пример #4
0
        private void btnParent_Click(object sender, EventArgs e)
        {
            Form     frmSelect = new Form( );
            TreeView tree      = new TreeView( );

            tree.Name = "tvwLayer";
            DataTable tbLayer = DepartmentLayer.GetAllLayer( );

            DataRow[] drTop = tbLayer.Select("P_LAYER_ID = 0 ");
            for (int i = 0; i < drTop.Length; i++)
            {
                DepartmentLayer dept = new DepartmentLayer(drTop[i]);
                TreeNode        node = new TreeNode( );
                node.Text = dept.LayerName;
                node.Tag  = dept;

                AddSubLayerNode(node, tbLayer);
                tree.Nodes.Add(node);
            }

            tree.Dock                 = DockStyle.Top;
            tree.Height               = frmSelect.Height * 4 / 5;
            frmSelect.StartPosition   = FormStartPosition.CenterScreen;
            frmSelect.FormBorderStyle = FormBorderStyle.FixedSingle;
            frmSelect.MinimizeBox     = false;
            frmSelect.MaximizeBox     = false;
            frmSelect.Text            = "选择层次";
            tree.KeyPress            += new KeyPressEventHandler(tree_KeyPress);
            frmSelect.Controls.Add(tree);

            Button btnSelect = new Button( );

            btnSelect.Text   = "确定";
            btnSelect.Left   = frmSelect.Width / 2 - btnSelect.Width - 20;
            btnSelect.Top    = tree.Height + 5;
            btnSelect.Click += new EventHandler(btnSelect_Click);
            frmSelect.Controls.Add(btnSelect);

            Button btnCloseFrm = new Button( );

            btnCloseFrm.Text   = "取消";
            btnCloseFrm.Left   = frmSelect.Width / 2 + 20;
            btnCloseFrm.Top    = btnSelect.Top;
            btnCloseFrm.Click += new EventHandler(btnCloseFrm_Click);
            frmSelect.Controls.Add(btnCloseFrm);


            if (frmSelect.ShowDialog( ) == DialogResult.OK)
            {
                txtParentDept.Text = ((DepartmentLayer)tree.SelectedNode.Tag).LayerName;
                txtParentDept.Tag  = (DepartmentLayer)tree.SelectedNode.Tag;
            }
        }
Пример #5
0
        /// <summary>
        /// 增加子层
        /// </summary>
        /// <param name="parentNode"></param>
        /// <param name="tbAllLay"></param>
        private void AddSubLayerNode(TreeNode parentNode, DataTable tbAllLay)
        {
            DataRow[] drSubs = tbAllLay.Select("P_LAYER_ID =  " + ((DepartmentLayer)parentNode.Tag).LayerID);

            for (int i = 0; i < drSubs.Length; i++)
            {
                DepartmentLayer dept = new DepartmentLayer(drSubs[i]);
                TreeNode        node = new TreeNode( );
                node.Text = dept.LayerName;
                node.Tag  = dept;

                AddSubLayerNode(node, tbAllLay);

                parentNode.Nodes.Add(node);
            }
        }
Пример #6
0
        /// <summary>
        /// 名称是否存在
        /// </summary>
        /// <param name="layer"></param>
        /// <returns></returns>
        public static bool NameExists(DepartmentLayer layer)
        {
            string sql = "SELECT * FROM BASE_DEPT_LAYER WHERE NAME = '" + layer + "'";

            if (layer.LayerID > 0)
            {
                sql = sql + " AND LAYER_ID<>" + layer.LayerID;
            }
            DataRow dr = DatabaseAccess.GetDataRow(DatabaseType.IbmDb2, sql);

            if (dr == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Пример #7
0
        /// <summary>
        /// 加载科室层次结构
        /// </summary>
        private void LoadDepartmentLayer()
        {
            tvwDeptlayer.Nodes.Clear( );

            DataTable tbLayer = DepartmentLayer.GetAllLayer( );

            DataRow[] drTop = tbLayer.Select("P_LAYER_ID = 0 ");

            for (int i = 0; i < drTop.Length; i++)
            {
                DepartmentLayer dept = new DepartmentLayer(drTop[i]);
                TreeNode        node = new TreeNode( );
                node.Text = dept.LayerName;
                node.Tag  = dept;
                AddSubLayerNode(node, tbLayer);

                tvwDeptlayer.Nodes.Add(node);
            }
            tvwDeptlayer.ExpandAll( );
        }
Пример #8
0
        private void DeleteLayer()
        {
            if (tvwDeptlayer.SelectedNode == null)
            {
                return;
            }

            DepartmentLayer layer = (DepartmentLayer)tvwDeptlayer.SelectedNode.Tag;

            if (layer.HasChild( ))
            {
                MessageBox.Show("该层次下还有子层,不能删除", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            try
            {
                if (layer.HasDepartments( ))
                {
                    if (MessageBox.Show("该层下还有科室,是否继续?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        if (layer.Delete( ))
                        {
                            MessageBox.Show("该层已删除,原所属的科室请重新分配层次", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    layer.Delete( );
                }
                tvwDeptlayer.Nodes.Remove(tvwDeptlayer.SelectedNode);
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #9
0
        private void tvwDeptlayer_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (tvwDeptlayer.SelectedNode.Tag == null)
            {
                return;
            }

            if (tvwDeptlayer.SelectedNode.Nodes.Count == 0)
            {
                DepartmentLayer layer   = (DepartmentLayer)tvwDeptlayer.SelectedNode.Tag;
                int[]           deptids = layer.GetDepartment( );
                lvwDept.Items.Clear( );
                lvwEmployee.Items.Clear( );

                for (int i = 0; i < deptids.Length; i++)
                {
                    Department   dept = new Department(deptids[i]);
                    ListViewItem item = new ListViewItem( );
                    item.Text = dept.Name;
                    item.Tag  = dept;
                    if (dept.NoUse == 1)
                    {
                        item.ImageIndex = 4;
                    }
                    else
                    {
                        item.ImageIndex = 3;
                    }
                    lvwDept.Items.Add(item);
                    Employee[] employies = dept.GetEmployeies( );
                    for (int j = 0; j < employies.Length; j++)
                    {
                        ListViewItem item1 = new ListViewItem( );
                        item1.Text = employies[j].Name;
                        item1.Tag  = employies[j];
                        item1.SubItems.Add(employies[j].UserCode);
                        switch (employies[j].Role)
                        {
                        case 1:
                            item1.SubItems.Add("医生");
                            break;

                        case 2:
                            item1.SubItems.Add("护士");
                            break;

                        default:
                            item1.SubItems.Add("");
                            break;
                        }
                        item1.ImageIndex = 2;
                        lvwEmployee.Items.Add(item1);
                    }
                }
            }
            else
            {
                lvwDept.Items.Clear( );
                lvwEmployee.Items.Clear( );
                foreach (TreeNode nd in tvwDeptlayer.SelectedNode.Nodes)
                {
                    if (nd.Nodes.Count == 0)
                    {
                        DepartmentLayer layer   = (DepartmentLayer)nd.Tag;
                        int[]           deptids = layer.GetDepartment( );
                        for (int i = 0; i < deptids.Length; i++)
                        {
                            Department   dept = new Department(deptids[i]);
                            ListViewItem item = new ListViewItem( );
                            item.Text = dept.Name;
                            item.Tag  = dept;
                            if (dept.NoUse == 1)
                            {
                                item.ImageIndex = 4;
                            }
                            else
                            {
                                item.ImageIndex = 3;
                            }
                            lvwDept.Items.Add(item);
                        }
                    }
                    else
                    {
                        ForeachNode(nd);
                    }
                }
            }
        }
Пример #10
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (txtLayerName.Text.Trim( ) == "")
            {
                MessageBox.Show("名称不能为空!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (layer == null)
            {
                layer = new DepartmentLayer( );
            }
            layer.LayerName = txtLayerName.Text;
            if (txtParentLayer.Tag != null)
            {
                layer.ParentLayerId = txtParentLayer.Text.Trim( ) == "" ? 0 : ((DepartmentLayer)txtParentLayer.Tag).LayerID;
            }
            else
            {
                layer.ParentLayerId = 0;
            }

            if (DepartmentLayer.NameExists(layer))
            {
                MessageBox.Show("名称已经存在", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (layer.LayerID == 0)
                {
                    layer = null;
                }

                return;
            }

            if (layer.LayerID == 0)
            {
                layer.Add( );
                TreeNode node = new TreeNode( );
                node.Text = layer.LayerName;
                node.Tag  = layer;

                TreeNode pNode = GetNode(layer.ParentLayerId);
                if (pNode == null)
                {
                    tvw.Nodes.Add(node);
                }
                else
                {
                    pNode.Nodes.Add(node);
                }
                tvw.ExpandAll( );

                txtLayerName.Text = "";
                txtLayerName.Focus( );
                layer = null;
            }
            else
            {
                layer.Update( );

                TreeNode node = new TreeNode( );
                node.Text = layer.LayerName;
                node.Tag  = layer;

                tvw.Nodes.Remove(tvw.SelectedNode);

                TreeNode pNode = GetNode(layer.ParentLayerId);
                if (pNode != null)
                {
                    pNode.Nodes.Add(node);
                }
                else
                {
                    tvw.Nodes.Add(node);
                }

                this.Close( );
            }
        }