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; } }
/// <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( ); }