private void InitDepts() { _depts = new List <SYS_DEPTSModel>(); /*以下代码实现目录列表 List<dbDepts>*/ List <SYS_DEPTSModel> dbDepts = new List <SYS_DEPTSModel>(); DeptsModel.StartDate = DateTime.Parse("1900-01-01"); DeptsModel.EndDate = DateTime.Now; DataTable table = new DataTable(); DataSet ds = XASYU.BLL.DataBaseQuery.query_SYS_DEPTS(userBean, DeptsModel, ref V_ITOTALCOUNT, V_SSTARTINDEX, V_SPERPAGESIZE); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) { dbDepts = DataSetToIList <SYS_DEPTSModel>(ds, 0);//利用反射机制实现DataSet和List之间数据转换 } /*以下代码实现功能是在menus节点中增加Parent节点,以方便实现树形目录*/ for (int i = 0; i < dbDepts.Count; i++) { if (dbDepts[i].ParentID != 0) { SYS_DEPTSModel MenuTemp = dbDepts.Find(delegate(SYS_DEPTSModel p) { return(p.ID == dbDepts[i].ParentID); }); dbDepts[i].Parent = MenuTemp; } } ResolveDeptCollection(dbDepts, null, 0); }
private int ResolveDeptCollection(List <SYS_DEPTSModel> dbDepts, SYS_DEPTSModel parentDept, int level) { int count = 0; foreach (var dept in dbDepts.Where(d => d.Parent == parentDept)) { count++; _depts.Add(dept); dept.TreeLevel = level; dept.IsTreeLeaf = true; dept.Enabled = true; level++; // 如果这个节点下没有子节点,则这是个终结节点 int childCount = ResolveDeptCollection(dbDepts, dept, level); if (childCount != 0) { dept.IsTreeLeaf = false; } level--; } return(count); }
protected void Grid1_RowDataBound(object sender, FineUI.GridRowEventArgs e) { //行绑定后,确定应该选择哪一行 SYS_DEPTSModel dept = e.DataItem as SYS_DEPTSModel; if (dept != null && _deptID == dept.ID) { _selectedRowIndex = e.RowIndex; } }
private void BindDDL(SYS_DEPTSModel current) { List <SYS_DEPTSModel> mys = ResolveDDL <SYS_DEPTSModel>(depHelp.Depts, current.ID); // 绑定到下拉列表(启用模拟树功能和不可选择项功能) ddlParent.EnableSimulateTree = true; ddlParent.DataTextField = "Name"; ddlParent.DataValueField = "ID"; ddlParent.DataSimulateTreeLevelField = "TreeLevel"; ddlParent.DataEnableSelectField = "Enabled"; ddlParent.DataSource = mys; ddlParent.DataBind(); if (current.Parent != null) { // 选中当前节点的父节点 ddlParent.SelectedValue = current.Parent.ID.ToString(); } }
private void LoadData() { btnClose.OnClientClick = ActiveWindow.GetHideReference(); int id = GetQueryIntValue("id"); SYS_DEPTSModel current = depHelp.Depts.Where(d => d.ID == id).FirstOrDefault(); if (current == null) { // 参数错误,首先弹出Alert对话框然后关闭弹出窗口 Alert.Show("参数错误!", String.Empty, ActiveWindow.GetHideReference()); return; } tbxDeptLeader.Text = current.DeptLeader; tbxDeptTel.Text = current.DeptTel; tbxName.Text = current.Name; tbxSortIndex.Text = current.SortIndex.ToString(); tbxRemark.Text = current.Remark; // 绑定下拉列表 BindDDL(current); }