@@ -54,8 +54,34 @@ namespace Learun.Application.WebApi.Modules.Hetian | |||||
/// <returns></returns> | /// <returns></returns> | ||||
public Response GetBaomin(dynamic _) | public Response GetBaomin(dynamic _) | ||||
{ | { | ||||
var list = internShipSignUpIBLL.GetMyList(userInfo.account); | |||||
var id = GetReqData(); | |||||
var list = internShipSignUpIBLL.GetMyList(userInfo.account,id); | |||||
if (list.Any()) | |||||
{ | |||||
var unts = Util.DataBase.DataTableListHelper.TableToList<PracticeBaseEntity>(dataSourceIBLL.GetDataTable("PracticeBase", "")); | |||||
var psts = Util.DataBase.DataTableListHelper.TableToList<PracticeBaseEntity>(dataSourceIBLL.GetDataTable("PBPost", "")); | |||||
foreach (var item in list) | |||||
{ | |||||
var unt = unts.FirstOrDefault(x => x.ID == item.IUnit); | |||||
if(unt == null) | |||||
{ | |||||
item.UnitName = string.Empty; | |||||
} | |||||
else | |||||
{ | |||||
item.UnitName = unt.Name; | |||||
} | |||||
var pst=psts.FirstOrDefault(x=>x.ID==item.IPost); | |||||
if(pst == null) | |||||
{ | |||||
item.PostName = string.Empty; | |||||
} | |||||
else | |||||
{ | |||||
item.PostName = pst.Name; | |||||
} | |||||
} | |||||
} | |||||
return Success(list); | return Success(list); | ||||
} | } | ||||
@@ -68,7 +94,8 @@ namespace Learun.Application.WebApi.Modules.Hetian | |||||
{ | { | ||||
var queryJson = GetReqData(); | var queryJson = GetReqData(); | ||||
var queryParam = queryJson.ToObject<InternShipSignUpEntity>(); | var queryParam = queryJson.ToObject<InternShipSignUpEntity>(); | ||||
internShipSignUpIBLL.SaveEntity("", queryParam); | |||||
var id = queryParam.ID.IsEmpty() ? "" : queryParam.ID; | |||||
internShipSignUpIBLL.SaveEntity(id, queryParam); | |||||
return Success(true); | return Success(true); | ||||
} | } | ||||
@@ -119,11 +119,11 @@ namespace Learun.Application.TwoDevelopment.EducationalAdministration | |||||
} | } | ||||
} | } | ||||
public IEnumerable<InternShipSignUpEntity> GetMyList(string acc) | |||||
public IEnumerable<InternShipSignUpEntity> GetMyList(string acc, string id) | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
return internShipSignUpService.GetMyList(acc); | |||||
return internShipSignUpService.GetMyList(acc,id); | |||||
} | } | ||||
catch (Exception ex) | catch (Exception ex) | ||||
{ | { | ||||
@@ -81,6 +81,17 @@ namespace Learun.Application.TwoDevelopment.EducationalAdministration | |||||
} | } | ||||
#endregion | #endregion | ||||
#region 扩展字段 | #region 扩展字段 | ||||
/// <summary> | |||||
/// 实习单位 | |||||
/// </summary> | |||||
[NotMapped] | |||||
public string UnitName { get; set; } | |||||
/// <summary> | |||||
/// 实习岗位 | |||||
/// </summary> | |||||
[NotMapped] | |||||
public string PostName { get; set; } | |||||
#endregion | #endregion | ||||
} | } | ||||
} | } | ||||
@@ -45,6 +45,6 @@ namespace Learun.Application.TwoDevelopment.EducationalAdministration | |||||
void SaveEntity(string keyValue, InternShipSignUpEntity entity); | void SaveEntity(string keyValue, InternShipSignUpEntity entity); | ||||
#endregion | #endregion | ||||
IEnumerable<InternShipSignUpEntity> GetMyList(string acc); | |||||
IEnumerable<InternShipSignUpEntity> GetMyList(string acc,string id); | |||||
} | } | ||||
} | } |
@@ -4,6 +4,7 @@ using Learun.Util; | |||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Data; | using System.Data; | ||||
using System.Linq; | |||||
using System.Text; | using System.Text; | ||||
namespace Learun.Application.TwoDevelopment.EducationalAdministration | namespace Learun.Application.TwoDevelopment.EducationalAdministration | ||||
@@ -149,7 +150,7 @@ namespace Learun.Application.TwoDevelopment.EducationalAdministration | |||||
} | } | ||||
#endregion | #endregion | ||||
public IEnumerable<InternShipSignUpEntity> GetMyList(string acc) | |||||
public IEnumerable<InternShipSignUpEntity> GetMyList(string acc, string id) | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
@@ -163,9 +164,14 @@ namespace Learun.Application.TwoDevelopment.EducationalAdministration | |||||
"); | "); | ||||
strSql.Append(" FROM InternShipSignUp t "); | strSql.Append(" FROM InternShipSignUp t "); | ||||
strSql.Append(" WHERE StudentID=@StudentID "); | strSql.Append(" WHERE StudentID=@StudentID "); | ||||
if(!id.IsEmpty()) | |||||
{ | |||||
dp.Add("ID", "" + id + "", DbType.String); | |||||
strSql.Append(" AND ID=@ID "); | |||||
} | |||||
var list = this.BaseRepository("CollegeMIS").FindList<InternShipSignUpEntity>(strSql.ToString(), dp); | |||||
return this.BaseRepository("CollegeMIS").FindList<InternShipSignUpEntity>(strSql.ToString(), dp); | |||||
return list; | |||||
} | } | ||||
catch (Exception ex) | catch (Exception ex) | ||||
{ | { | ||||
@@ -0,0 +1,174 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Data; | |||||
using System.Linq; | |||||
using System.Reflection; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Learun.Util.DataBase | |||||
{ | |||||
public class DataTableListHelper | |||||
{ | |||||
/// <summary> | |||||
/// DataTable转化为List集合 | |||||
/// </summary> | |||||
/// <typeparam name="T">实体对象</typeparam> | |||||
/// <param name="dt">datatable表</param> | |||||
/// <param name="isStoreDB">是否存入数据库datetime字段,date字段没事,取出不用判断</param> | |||||
/// <returns>返回list集合</returns> | |||||
public static List<T> TableToList<T>(DataTable dt, bool isStoreDB = true) | |||||
{ | |||||
List<T> list = new List<T>(); | |||||
Type type = typeof(T); | |||||
//List<string> listColums = new List<string>(); | |||||
PropertyInfo[] pArray = type.GetProperties(); //集合属性数组 | |||||
foreach (DataRow row in dt.Rows) | |||||
{ | |||||
T entity = Activator.CreateInstance<T>(); //新建对象实例 | |||||
foreach (PropertyInfo p in pArray) | |||||
{ | |||||
if (!dt.Columns.Contains(p.Name) || row[p.Name] == null || row[p.Name] == DBNull.Value) | |||||
{ | |||||
continue; //DataTable列中不存在集合属性或者字段内容为空则,跳出循环,进行下个循环 | |||||
} | |||||
if (isStoreDB && p.PropertyType == typeof(DateTime) && Convert.ToDateTime(row[p.Name]) < Convert.ToDateTime("1753-01-01")) | |||||
{ | |||||
continue; | |||||
} | |||||
try | |||||
{ | |||||
var obj = Convert.ChangeType(row[p.Name], p.PropertyType); //类型强转,将table字段类型转为集合字段类型 | |||||
p.SetValue(entity, obj, null); | |||||
} | |||||
catch (Exception) | |||||
{ | |||||
// throw; | |||||
} | |||||
//if (row[p.Name].GetType() == p.PropertyType) | |||||
//{ | |||||
// p.SetValue(entity, row[p.Name], null); //如果不考虑类型异常,foreach下面只要这一句就行 | |||||
//} | |||||
//object obj = null; | |||||
//if (ConvertType(row[p.Name], p.PropertyType,isStoreDB, out obj)) | |||||
//{ | |||||
// p.SetValue(entity, obj, null); | |||||
//} | |||||
} | |||||
list.Add(entity); | |||||
} | |||||
return list; | |||||
} | |||||
/// <summary> | |||||
/// List集合转DataTable | |||||
/// </summary> | |||||
/// <typeparam name="T">实体类型</typeparam> | |||||
/// <param name="list">传入集合</param> | |||||
/// <param name="isStoreDB">是否存入数据库DateTime字段,date时间范围没事,取出展示不用设置TRUE</param> | |||||
/// <returns>返回datatable结果</returns> | |||||
public static DataTable ListToTable<T>(List<T> list, bool isStoreDB = true) | |||||
{ | |||||
Type tp = typeof(T); | |||||
PropertyInfo[] proInfos = tp.GetProperties(); | |||||
DataTable dt = new DataTable(); | |||||
foreach (var item in proInfos) | |||||
{ | |||||
dt.Columns.Add(item.Name, item.PropertyType); //添加列明及对应类型 | |||||
} | |||||
foreach (var item in list) | |||||
{ | |||||
DataRow dr = dt.NewRow(); | |||||
foreach (var proInfo in proInfos) | |||||
{ | |||||
object obj = proInfo.GetValue(item); | |||||
if (obj == null) | |||||
{ | |||||
continue; | |||||
} | |||||
//if (obj != null) | |||||
// { | |||||
if (isStoreDB && proInfo.PropertyType == typeof(DateTime) && Convert.ToDateTime(obj) < Convert.ToDateTime("1753-01-01")) | |||||
{ | |||||
continue; | |||||
} | |||||
// dr[proInfo.Name] = proInfo.GetValue(item); | |||||
dr[proInfo.Name] = obj; | |||||
// } | |||||
} | |||||
dt.Rows.Add(dr); | |||||
} | |||||
return dt; | |||||
} | |||||
/// <summary> | |||||
/// table指定行转对象 | |||||
/// </summary> | |||||
/// <typeparam name="T">实体</typeparam> | |||||
/// <param name="dt">传入的表格</param> | |||||
/// <param name="rowindex">table行索引,默认为第一行</param> | |||||
/// <returns>返回实体对象</returns> | |||||
public static T TableToEntity<T>(DataTable dt, int rowindex = 0, bool isStoreDB = true) | |||||
{ | |||||
Type type = typeof(T); | |||||
T entity = Activator.CreateInstance<T>(); //创建对象实例 | |||||
if (dt == null) | |||||
{ | |||||
return entity; | |||||
} | |||||
//if (dt != null) | |||||
//{ | |||||
DataRow row = dt.Rows[rowindex]; //要查询的行索引 | |||||
PropertyInfo[] pArray = type.GetProperties(); | |||||
foreach (PropertyInfo p in pArray) | |||||
{ | |||||
if (!dt.Columns.Contains(p.Name) || row[p.Name] == null || row[p.Name] == DBNull.Value) | |||||
{ | |||||
continue; | |||||
} | |||||
if (isStoreDB && p.PropertyType == typeof(DateTime) && Convert.ToDateTime(row[p.Name]) < Convert.ToDateTime("1753-01-02")) | |||||
{ | |||||
continue; | |||||
} | |||||
try | |||||
{ | |||||
var obj = Convert.ChangeType(row[p.Name], p.PropertyType); //类型强转,将table字段类型转为对象字段类型 | |||||
p.SetValue(entity, obj, null); | |||||
} | |||||
catch (Exception) | |||||
{ | |||||
// throw; | |||||
} | |||||
// p.SetValue(entity, row[p.Name], null); | |||||
} | |||||
// } | |||||
return entity; | |||||
} | |||||
} | |||||
} |
@@ -92,6 +92,7 @@ | |||||
<Compile Include="Common\TimeOutCheckTool.cs" /> | <Compile Include="Common\TimeOutCheckTool.cs" /> | ||||
<Compile Include="Config\Config.cs" /> | <Compile Include="Config\Config.cs" /> | ||||
<Compile Include="DataBase\DataConvert.cs" /> | <Compile Include="DataBase\DataConvert.cs" /> | ||||
<Compile Include="DataBase\DataTableListHelper.cs" /> | |||||
<Compile Include="DataBase\FieldTypeHepler.cs" /> | <Compile Include="DataBase\FieldTypeHepler.cs" /> | ||||
<Compile Include="DataBase\FieldValueParam.cs" /> | <Compile Include="DataBase\FieldValueParam.cs" /> | ||||
<Compile Include="DataBase\DbWhere.cs" /> | <Compile Include="DataBase\DbWhere.cs" /> | ||||