using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using EmitMapper; using EmitMapper.MappingConfiguration; using Model.HSSE; namespace BLL { public static class APITrainTestRecordService { #region 根据projectId、获取培训记录列表 /// /// 根据projectId获取培训记录列表 /// /// /// public static List getTrainRecordListByProjectId(string projectId) { using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { var getDataLists = (from x in db.Training_TrainTestRecord where ((string.IsNullOrEmpty(projectId) && x.ProjectId == null) || (!string.IsNullOrEmpty(projectId) && x.ProjectId == projectId)) orderby x.DateA descending select new Model.HSSE.TrainTestRecordItem { TrainingTestRecordId = x.TrainingTestRecordId, TrainingName = x.TrainingName, UnitId = x.UnitId, ProjectId = x.ProjectId, DateA = string.Format("{0:yyyy-MM-dd HH:mm}", x.DateA), UnitName = db.Base_Unit.FirstOrDefault(y => y.UnitId == x.UnitId).UnitName, DateZ = string.Format("{0:yyyy-MM-dd HH:mm}", x.DateZ), TrainingType = x.TrainingType, TrainingTypeName = db.Base_TrainType.FirstOrDefault(y=>y.TrainTypeId==x.TrainingType).TrainTypeName, PeopleNum = x.PeopleNum, }).ToList(); return getDataLists; } } #endregion #region 根据培训ID获取培训记录详细 /// /// 根据培训ID获取培训记录详细 /// /// /// public static Model.HSSE.TrainTestRecordItem getTrainRecordByTrainingId(string trainRecordId) { using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { var getDataLists = from x in db.Training_TrainTestRecord where x.TrainingTestRecordId == trainRecordId select new Model.HSSE.TrainTestRecordItem { TrainingTestRecordId = x.TrainingTestRecordId, TrainingName = x.TrainingName, UnitId = x.UnitId, ProjectId = x.ProjectId, DateA = string.Format("{0:yyyy-MM-dd HH:mm}", x.DateA), UnitName = db.Base_Unit.FirstOrDefault(y => y.UnitId == x.UnitId).UnitName, DateZ = string.Format("{0:yyyy-MM-dd HH:mm}", x.DateZ), TrainingType = x.TrainingType, PeopleNum = x.PeopleNum, TrainingTypeName = db.Base_TrainType.FirstOrDefault(y => y.TrainTypeId == x.TrainingType).TrainTypeName, AttachUrl1 = AttachFileService.getFileUrl(x.TrainingTestRecordId + "r"), AttachUrl2 = AttachFileService.getFileUrl(x.TrainingTestRecordId + "re") }; return getDataLists.FirstOrDefault(); } } #endregion #region 根据考生计划结束时 将相关培训考生内容 写培训记录归档 /// /// 根据考生计划结束时 将相关培训考生内容 写培训记录归档 /// /// public static void updateTrainRecord(Model.HSSE.TrainTestRecordItem x) { using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { ////获取培训计划 Model.Training_TrainTestRecord newTrainRecord = db.Training_TrainTestRecord.FirstOrDefault(u => u.TrainingTestRecordId == x.TrainingTestRecordId); if (newTrainRecord != null) { newTrainRecord.TrainingName = x.TrainingName; newTrainRecord.UnitId = x.UnitId; newTrainRecord.ProjectId = x.ProjectId; newTrainRecord.DateA = Convert.ToDateTime(x.DateA); newTrainRecord.DateZ = Convert.ToDateTime(x.DateZ); newTrainRecord.TrainingType = x.TrainingType; newTrainRecord.PeopleNum = x.PeopleNum; } else { newTrainRecord = new Model.Training_TrainTestRecord { TrainingTestRecordId = x.TrainingTestRecordId, TrainingName = x.TrainingName, UnitId = x.UnitId, ProjectId = x.ProjectId, DateA = Convert.ToDateTime(x.DateA), DateZ = Convert.ToDateTime(x.DateZ), TrainingType = x.TrainingType, PeopleNum = x.PeopleNum }; db.Training_TrainTestRecord.InsertOnSubmit(newTrainRecord); } ///新增培训记录 db.SubmitChanges(); } } #endregion } }