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 < )
return null;
if (p_TableIndex > p_DataSet.Tables.Count - )
return null;
if (p_TableIndex < )
p_TableIndex = ; DataTable p_Data = p_DataSet.Tables[p_TableIndex];
// 返回值初始化
IList<T> result = new List<T>();
for (int j = ; 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 = ; 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 = ;
if (p_DataSet == null || p_DataSet.Tables.Count < )
return null;
if (string.IsNullOrEmpty(p_TableName))
return null;
for (int i = ; 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; }
}
}
上一篇:linux的查找命令 find whereis locate


下一篇:mysql常用基础操作语法(八)~~多表查询合并结果和内连接查询【命令行模式】