.net 树型数据
Model
public string Id { get; set; }
public string Title { get; set; }
public List<TreeModel> Children { get; set; }
public string ParentId { get; set; }
public string shenfenzhengurl { get; set; }
/// <summary>
/// 标记
/// </summary>
public string Sign { get; set; }
[HttpGet]
public IHttpActionResult GetCompanyTeamTree(string project_base_id)
{
ResultModel<List<TreeModel>> result = new ResultModel<List<TreeModel>>();
try
{
using (var _db = DB.DBHelper.GetInstance())
{
var authInfo = RequestContext.RouteData.Values["authInfo"] as AuthInfo;
List<TreeModel> list = new List<TreeModel>();
StringBuilder sh = new StringBuilder();
sh.Append(" SELECT xc.qiyemingcheng,xpc.id,xpc.project_base_id,xpc.company_id,xc.qiyeleixing from xm_project_company xpc ");
sh.Append(" JOIN xm_project_base xb on xb.id = xpc.project_base_id ");
sh.Append(" JOIN xm_company xc on xc.id = xpc.company_id ");
sh.Append(" WHERE xpc.project_base_id = '" + project_base_id + "' and xpc.isdel = 0 ");
var companys = _db.SqlQueryable<ProjectCompanyView>(sh.ToString()).ToList();
if (companys.Count > 0)
{
foreach (var entity in companys)
{
TreeModel model = new TreeModel();
model.Id = entity.company_id;
model.Title = entity.qiyemingcheng;
model.Sign = "company";
model.Children = GetCompanyTeamList(entity.project_base_id, entity.company_id);
model.ParentId = entity.project_base_id;
list.Add(model);
}
}
if (list.Count > 0)
{
result.Code = 0;
result.Message = "";
result.Data = list;
}
else
{
result.Code = -1;
result.Message = "未查询到数据";
result.Data = list;
}
}
}
catch (Exception ex)
{
result.Code = -1;
result.Message = "未查询到数据:" + ex.ToString();
}
return Json(result);
}
private List<TreeModel> GetCompanyTeamList(string projectId, string companyId)
{
using (var _db = DB.DBHelper.GetInstance())
{
List<TreeModel> result = new List<TreeModel>();
List<EnterpriseTeamModel> list = _db.Queryable<EnterpriseTeamModel>().Where(t => t.ProjectId.Equals(projectId) && t.CompanyId.Equals(companyId)).ToList();
if (list.Count > 0)
{
foreach (var entity in list)
{
TreeModel model = new TreeModel();
model.Id = entity.Id;
model.Title = entity.TeamName;
model.Sign = "team";
model.Children = GetWorkList(entity.ProjectId, entity.CompanyId, entity.TeamName);
model.ParentId = entity.CompanyId;
result.Add(model);
}
}
return result;
}
}

浙公网安备 33010602011771号