zoukankan      html  css  js  c++  java
  • 分组并赋值

    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; }
    }

  • 相关阅读:
    Python subprocess方法
    Python hashlib、hmac加密模块
    mysql binlog详解
    Nginx 关键字详解
    账号笔记
    Python configparser模块
    Python yaml处理
    Linux && 与 ||
    spring boot 学习(十一)使用@Async实现异步调用
    spring boot 学习(十)SpringBoot配置发送Email
  • 原文地址:https://www.cnblogs.com/chang1/p/7424297.html
Copyright © 2011-2022 走看看