//获取根节点 public List <JsonCompanyTree> GetCompanyChildNodes(DataSet parDs, DataTable ds) { DataView dv = parDs.Tables[0].DefaultView; List <JsonCompanyTree> list = new List <JsonCompanyTree>(); for (int i = 0; i < ds.Rows.Count; i++) { JsonCompanyTree model = new JsonCompanyTree(); model.id = ds.Rows[i]["id"].ToString(); model.parentId = ds.Rows[i]["CreateCompanyId"].ToString(); model.text = ds.Rows[i]["Name"].ToString(); switch (int.Parse(ds.Rows[i]["Attribute"].ToString()))//1:集团 2:公司 3:分公司 4:子公司 { case 0: model.iconCls = ""; break; case 1: model.iconCls = "GTP_home"; break; case 2: model.iconCls = "GTP_dept"; break; case 3: model.iconCls = "GTP_post"; break; case 4: model.iconCls = "GTP_post"; break; case 5: model.iconCls = "GTP_post"; break; } model.Status = int.Parse(ds.Rows[i]["Status"].ToString()); model.expanded = false; model.leaf = true; model.Code = ds.Rows[i]["Code"].ToString(); model.LinkUser = ds.Rows[i]["LinkUser"].ToString(); model.Phone = ds.Rows[i]["Phone"].ToString(); model.CreateTime = Convert.ToDateTime(ds.Rows[i]["CreateTime"]); model.NameTitle = ds.Rows[i]["NameTitle"].ToString(); model.Attribute = int.Parse(ds.Rows[i]["Attribute"].ToString()); //查询子节点 dv.RowFilter = "CreateCompanyId='" + ds.Rows[i]["id"].ToString() + "'"; DataTable childSet = dv.ToTable(); if (childSet.Rows.Count > 0) { model.leaf = false; model.children = GetCompanyChildNodes(parDs, childSet); } list.Add(model); } return(list); }
public void SearchPostData() { try { if (CurrentMaster.Attribute == (int)AdminTypeEnum.系统管理员) { //超级管理员查看所有单位 _where += " and (Attribute>=" + (int)CompanyType.单位 + " and Attribute<=" + (int)CompanyType.部门 + ") and Status=" + (int)StatusEnum.正常; } else if (CurrentMaster.Attribute == (int)AdminTypeEnum.单位管理员 || CurrentMaster.Attribute == (int)AdminTypeEnum.供应商管理员 || CurrentMaster.Attribute == (int)AdminTypeEnum.维保公司管理员 || CurrentMaster.Attribute == (int)AdminTypeEnum.消防部门管理员) { //查看自己单位 _where += " and (Attribute>=" + (int)CompanyType.单位 + " and Attribute<=" + (int)CompanyType.部门 + ") and Status=" + (int)StatusEnum.正常 + " and (Id='" + CurrentMaster.Cid + "' or CreateCompanyId='" + CurrentMaster.Cid + "')"; } if (!string.IsNullOrEmpty(Request["BrandName"])) { _where += " and (Name like '%" + Request["BrandName"].ToString() + "%')"; } _mySet = bll.GetTreeList(_where); List <JsonCompanyTree> list = new FunTreeCommon().GetCompanyTreeNodes(_mySet); if (_mySet.Tables[0].Rows.Count > 0 && list.Count == 0) { for (int i = 0; i < _mySet.Tables[0].Rows.Count; i++) { JsonCompanyTree model = new JsonCompanyTree(); model.id = _mySet.Tables[0].Rows[i]["Id"].ToString(); model.parentId = "0"; model.text = _mySet.Tables[0].Rows[i]["Name"].ToString(); model.expanded = false; model.leaf = true; model.leaf = true; list.Add(model); } } Output = JsonHelper.ToJson(list); } catch { Output = ""; } WriteJsonToPage(Output); }