• 分组并赋值


    public AllDesColumnEntity GetAllColumnList()
    {
    AllDesColumnEntity list = new AllDesColumnEntity();
    string sql = @"SELECT function_id, property_valuename '字段编码', property_displayname '字段名称',* FROM BT_AllColumn WHERE status=0;";
    var dt = SqlHelper.ExecuteDataset(dsDB_Read_ConnectionString, CommandType.Text, sql, null).Tables[0].AsEnumerable();
    var query = (from t in dt.AsEnumerable()
    group t by new { t1 = t.Field<Int32>("function_id") } into m
    select new DataItem
    {
    functionId = m.Key.t1,
    }).ToList();
    foreach (var item in query)
    {
    var listChilds = dt.Where(x => x.Field<Int32>("function_id").Equals(item.functionId)).Select(x => new ChildItem() { Id = x.Field<Int32>("function_id"), 字段名称 = x.Field<string>("字段名称"), 字段编码 = x.Field<string>("字段编码") }).ToList();
    if (listChilds.Count > 0)
    {
    item.Child = listChilds;
    }
    }
    list.data = query;
    list.total = query.Count;
    return list;
    }

    public class ChildItem
    {
    /// <summary>
    ///
    /// </summary>
    public int Id { get; set; }
    /// <summary>
    /// 企业ID
    /// </summary>
    public string 字段名称 { get; set; }
    /// <summary>
    ///
    /// </summary>
    public string 字段编码 { get; set; }
    /// <summary>
    ///
    /// </summary>
    public string 是否选中 { get; set; }
    }

    public class DataItem
    {
    /// <summary>
    ///
    /// </summary>
    public int functionId { get; set; }
    /// <summary>
    /// 企业查询
    /// </summary>
    public string 指标名称 { get; set; }
    /// <summary>
    ///
    /// </summary>
    public string 指标编码 { get; set; }
    /// <summary>
    ///
    /// </summary>
    public string 是否选中 { get; set; }
    /// <summary>
    ///
    /// </summary>
    public string url { get; set; }
    /// <summary>
    ///
    /// </summary>
    public List<ChildItem> Child { get; set; }
    }

    public class AllDesColumnEntity
    {
    /// <summary>
    ///
    /// </summary>
    public int id { get; set; }
    /// <summary>
    ///
    /// </summary>
    public int total { get; set; }
    /// <summary>
    ///
    /// </summary>
    public List<DataItem> data { get; set; }
    /// <summary>
    /// 查询成功
    /// </summary>
    public string result { get; set; }
    /// <summary>
    ///
    /// </summary>
    public string msg { get; set; }
    }

  • 相关阅读:
    CentOS6.5安装Tab增强版:bash-completion
    005_linux下logrotate 配置和理解
    ITIL与ITSM的联系与区别
    C++----练习--bool类型作为特别的int要区别对待
    C++----练习--while求和
    C++----练习
    mysql----二进制包安装
    linux----ulimit 限制
    python----特性003
    python----特性002
  • 原文地址:https://www.cnblogs.com/chang1/p/7424297.html
Copyright © 2020-2023  润新知