• DataSet 转 List


     public class OrderInfo
        {
            public OrderResult GetOrderInfoByOrderNum(List<string> orderNumList)
            {
                OrderResult result = new OrderResult();
                OmcOrderSearchClient orderSearch = new OmcOrderSearchClient();
                ArrayList arrayList = new ArrayList();
                arrayList.AddRange(orderNumList);
                var orderInfo = orderSearch.GetOrderInfoCoMainDetailsTable(arrayList);
                if (!orderInfo.State)
                {
                    result.IsSuc = false;
                    result.Msg = orderInfo.VMsg;
                    return result;
                }
                var order = DataSetToIList<Fct_Order>((DataSet)orderInfo.ResultObj, "Order");
                var commodity = DataSetToIList<Fct_Commodity>((DataSet)orderInfo.ResultObj, "Commodity");
                var orderPayment = DataSetToIList<Fct_OrderPayment>((DataSet)orderInfo.ResultObj, "OrderPayment");
                result.IsSuc = true;
                result.Msg = "OK";
                result.OrderList = order;
                result.CommodityList = commodity;
                result.OrderPaymentList = orderPayment;
                return result;
            }
            /// <summary> 
            /// DataSet装换为泛型集合 
            /// </summary> 
            /// <typeparam name="T"></typeparam> 
            /// <param name="p_DataSet">DataSet</param> 
            /// <param name="p_TableIndex">待转换数据表索引</param> 
            /// <returns></returns> 
            /// 2008-08-01 22:46 HPDV2806 
            public static IList<T> DataSetToIList<T>(DataSet p_DataSet, int p_TableIndex)
            {
                if (p_DataSet == null || p_DataSet.Tables.Count < 0)
                    return null;
                if (p_TableIndex > p_DataSet.Tables.Count - 1)
                    return null;
                if (p_TableIndex < 0)
                    p_TableIndex = 0;
    
                DataTable p_Data = p_DataSet.Tables[p_TableIndex];
                // 返回值初始化 
                IList<T> result = new List<T>();
                for (int j = 0; j < p_Data.Rows.Count; j++)
                {
                    T _t = (T)Activator.CreateInstance(typeof(T));
                    PropertyInfo[] propertys = _t.GetType().GetProperties();
                    foreach (PropertyInfo pi in propertys)
                    {
                        for (int i = 0; i < p_Data.Columns.Count; i++)
                        {
                            // 属性与字段名称一致的进行赋值 
                            if (pi.Name.Equals(p_Data.Columns[i].ColumnName))
                            {
                                // 数据库NULL值单独处理 
                                if (p_Data.Rows[j][i] != DBNull.Value)
                                    pi.SetValue(_t, p_Data.Rows[j][i], null);
                                else
                                    pi.SetValue(_t, null, null);
                                break;
                            }
                        }
                    }
                    result.Add(_t);
                }
                return result;
            }
    
            /// <summary> 
            /// DataSet装换为泛型集合 
            /// </summary> 
            /// <typeparam name="T"></typeparam> 
            /// <param name="p_DataSet">DataSet</param> 
            /// <param name="p_TableName">待转换数据表名称</param> 
            /// <returns></returns> 
            /// 2008-08-01 22:47 HPDV2806 
            public static IList<T> DataSetToIList<T>(DataSet p_DataSet, string p_TableName)
            {
                int _TableIndex = 0;
                if (p_DataSet == null || p_DataSet.Tables.Count < 0)
                    return null;
                if (string.IsNullOrEmpty(p_TableName))
                    return null;
                for (int i = 0; i < p_DataSet.Tables.Count; i++)
                {
                    // 获取Table名称在Tables集合中的索引值 
                    if (p_DataSet.Tables[i].TableName.Equals(p_TableName))
                    {
                        _TableIndex = i;
                        break;
                    }
                }
                return DataSetToIList<T>(p_DataSet, _TableIndex);
            }
    
            /// <summary>
            /// 订单表
            /// </summary>
            public class Fct_Order
            {
                /// <summary>
                /// 订单金额
                /// </summary>
                public decimal TotalPrice { get; set; }
    
                /// <summary>
                /// 订单流水号
                /// </summary>
    
                public int SerialNumber { get; set; }
    
                /// <summary>
                /// 如果是充值订单,是否已充值
                /// </summary>
                public int IsGetMoney { get; set; }
    
                /// <summary>
                /// 用户名
                /// </summary>
                public string UserName { get; set; }
    
            }
            /// <summary>
            /// 商品表
            /// </summary>
            public class Fct_Commodity
            {
                /// <summary>
                /// 商品id
                /// </summary>
                public Guid CommodityId { get; set; }
    
                /// <summary>
                /// 数量
                /// </summary>
                public decimal Amount { get; set; }
            }
            public class OrderResult
            {
                /// <summary>
                /// 返回结果是否成功,true:成功,false:失败
                /// </summary>
                public bool IsSuc { get; set; }
    
                /// <summary>
                /// 返回消息
                /// </summary>
                public string Msg { get; set; }
    
                /// <summary>
                /// 订单信息
                /// </summary>
                public IList<Fct_Order> OrderList { get; set; }
    
                /// <summary>
                /// 商品信息
                /// </summary>
                public IList<Fct_Commodity> CommodityList { get; set; }
    
                /// <summary>
                /// 订单支付
                /// </summary>
                public IList<Fct_OrderPayment> OrderPaymentList { get; set; }
            }
            /// <summary>
            /// 订单付款表
            /// </summary>
            public class Fct_OrderPayment
            {
                /// <summary>
                /// 折扣金额
                /// </summary>
                public decimal PaymentPrice { get; set; }
            }
        }
  • 相关阅读:
    TCP 协议如何解决粘包、半包问题 转载:https://mp.weixin.qq.com/s/XqGCaX94hCvrYI_Tvfq_yQ
    [国家集训队]happiness
    CF592D Super M
    [APIO2010]巡逻
    [NOI2012]美食节
    [JSOI2008]Blue Mary的旅行
    [十二省联考2019]D1T2字符串问题
    [十二省联考2019]D2T2春节十二响
    [十二省联考2019]D1T1异或粽子
    [WC2008]游览计划
  • 原文地址:https://www.cnblogs.com/xuguanghui/p/5760726.html
Copyright © 2020-2023  润新知