组织机构管理
组织机构可以是一个公司 也可以是多个公司,整体设计可以根据自己的需求去使用
左侧树形结构和下拉框是同步获取数据,做到实时数据刷新
代码如下
调用代码
Bll_oa_department.LoadTreeViewAndComboBox(cb_parent_id, tv_department,false,false);
类代码
private static string toadd = "├"; public static void LoadTreeViewAndComboBox(ComboBox cb, TreeView treeView,bool is_show_personnel,bool is_show_checkbox) { ImageList imageList = new ImageList(); imageList.Images.Add("folder", Properties.Resources.folder); imageList.Images.Add("user", Properties.Resources.user); imageList.Images.Add("user_red", Properties.Resources.user_red); imageList.ImageSize = new System.Drawing.Size(32, 32); ArrayList list = new ArrayList(); if (treeView != null) treeView.Nodes.Clear(); treeView.ImageList = imageList; var departmentList = GetDataByParentID(0); foreach (var u in departmentList) { int typeId = u.id; string typeName = u.name; TreeNode node = new TreeNode(); node.Text = Convert.ToString(typeName); node.Name = Convert.ToString(typeId); node.ImageKey = "folder"; // 设置子节点1的图标索引 node.SelectedImageKey = "folder"; if (treeView != null) treeView.Nodes.Add(node); list.Add(new System.Collections.DictionaryEntry(typeId, toadd + typeName)); BindData(typeId, node, list, is_show_personnel, is_show_checkbox); } if (treeView != null) treeView.ExpandAll(); if (cb != null) { cb.DataSource = list; cb.DisplayMember = "Value"; cb.ValueMember = "Key"; } if(is_show_checkbox) // 需要判断是不是需要打开 选择框 treeView.CheckBoxes = true; } private static void BindData(int parentId, TreeNode parentNode, ArrayList list, bool is_show_personnel,bool is_show_checkbox) { var List = GetDataByParentID(parentId); if (is_show_personnel) { var personnelList = Bll.Bll_oa_user.GetDataByDepartmentIDUserList(parentId); // 获取当前节点下的人员列表 foreach (var personnel in personnelList) { TreeNode personnelNode = new TreeNode(); personnelNode.Text = personnel.username; personnelNode.Name = Convert.ToString(personnel.id); if (personnel.gender == "男") { personnelNode.ImageKey = "user"; personnelNode.SelectedImageKey = "user"; } else { personnelNode.ImageKey = "user_red"; personnelNode.SelectedImageKey = "user_red"; } // 在节点前添加复选框 // personnelNode.Checked = true; // 根据实际情况设置是否选中 parentNode.Nodes.Add(personnelNode); } } foreach (var u in List) { int typeId = u.id; string typeName = u.name; TreeNode node = new TreeNode(); node.Text = Convert.ToString(typeName); node.Name = Convert.ToString(typeId); node.ImageKey = "folder"; // 设置子节点1的图标索引 node.SelectedImageKey = "folder"; parentNode.Nodes.Add(node); toadd += "┴"; list.Add(new System.Collections.DictionaryEntry(typeId, toadd + typeName)); BindData(typeId, node, list, is_show_personnel, is_show_checkbox); toadd = toadd.Substring(0, toadd.Length - 1); } }
标签:node,自定义,show,c#,personnelNode,BPM,user,personnel,treeView From: https://www.cnblogs.com/cxyyn/p/17789504.html