/// <summary> /// 将DataTable中的数据装载到List列表 /// </summary> /// <param name="dt">DataTable</param> /// <returns>返回列表对象</returns> private static List <WebApi_DataStruct_Details> LoadWebApi_DataStructDetailsToList(DataTable dt) { if (dt.Rows.Count > 0) { List <WebApi_DataStruct_Details> list = new List <WebApi_DataStruct_Details>(); //循环遍历数据表中的每一行 foreach (DataRow dr in dt.Rows) { WebApi_DataStruct_Details model = new WebApi_DataStruct_Details(); LoadWebApi_DataStructDetailsEntity(dr, model); list.Add(model); } return(list); } return(null); }
/// <summary> /// 将DataRow数据装载到实体对象 /// </summary> /// <param name="dr">DataRow对象</param> /// <param name="data">实体对象</param> private static void LoadWebApi_DataStructDetailsEntity(DataRow dr, WebApi_DataStruct_Details data) { if (dr.Table.Columns.Contains("DataStructId")) { if (!string.IsNullOrEmpty(dr["DataStructId"].ToString())) { data.DataStructId = int.Parse(dr["DataStructId"].ToString()); } } if (dr.Table.Columns.Contains("GroupId")) { if (!string.IsNullOrEmpty(dr["GroupId"].ToString())) { data.GroupId = int.Parse(dr["GroupId"].ToString()); } } if (dr.Table.Columns.Contains("DetailsId")) { if (!string.IsNullOrEmpty(dr["DetailsId"].ToString())) { data.DetailsId = int.Parse(dr["DetailsId"].ToString()); } } if (dr.Table.Columns.Contains("DetailsName")) { if (!string.IsNullOrEmpty(dr["DetailsName"].ToString())) { data.DetailsName = dr["DetailsName"].ToString(); } } if (dr.Table.Columns.Contains("ParentActionUrl")) { if (!string.IsNullOrEmpty(dr["ParentActionUrl"].ToString())) { data.ParentActionUrl = dr["ParentActionUrl"].ToString(); } } if (dr.Table.Columns.Contains("ActionUrl")) { if (!string.IsNullOrEmpty(dr["ActionUrl"].ToString())) { data.ActionUrl = dr["ActionUrl"].ToString(); } } if (dr.Table.Columns.Contains("DataStructName")) { if (!string.IsNullOrEmpty(dr["DataStructName"].ToString())) { data.DataStructName = dr["DataStructName"].ToString(); } } if (dr.Table.Columns.Contains("Description")) { if (!string.IsNullOrEmpty(dr["Description"].ToString())) { data.Description = dr["Description"].ToString(); } } if (dr.Table.Columns.Contains("StructDesc")) { if (!string.IsNullOrEmpty(dr["StructDesc"].ToString())) { data.StructDesc = dr["StructDesc"].ToString(); } } if (dr.Table.Columns.Contains("DataType")) { if (!string.IsNullOrEmpty(dr["DataType"].ToString())) { data.DataType = dr["DataType"].ToString(); } } if (dr.Table.Columns.Contains("DataDemo")) { if (!string.IsNullOrEmpty(dr["DataDemo"].ToString())) { data.DataDemo = dr["DataDemo"].ToString(); } } if (dr.Table.Columns.Contains("UpdateTime")) { if (dr["UpdateTime"] != null) { data.UpdateTime = Convert.ToDateTime(dr["UpdateTime"]); } } if (dr.Table.Columns.Contains("CreateTime")) { if (dr["CreateTime"] != null) { data.CreateTime = Convert.ToDateTime(dr["CreateTime"]); } } if (dr.Table.Columns.Contains("OpenTime")) { if (dr["OpenTime"] != null) { data.OpenTime = Convert.ToDateTime(dr["OpenTime"]); } } if (dr.Table.Columns.Contains("IsDelete")) { if (dr["IsDelete"] != null) { data.IsDelete = Convert.ToBoolean(dr["IsDelete"]); } } }