using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.Entities; using EMIS.ViewModel; using EMIS.DataLogic.ExaminationApply; using EMIS.ViewModel.ExaminationApply; using Bowin.Common.Utility; using System.Text.RegularExpressions; namespace EMIS.CommonLogic.ExaminationApply { public class ExaminationSubjectsServices : BaseServices, IExaminationSubjectsServices { public ExaminationSubjectDAL ExaminationSubjectDAL { get; set; } public Bowin.Common.Linq.Entity.IGridResultSet GetExaminationSubjectViewList(ViewModel.ConfiguretView examinationSubjectView, int? examinationFormID, int pageIndex, int pageSize) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (examinationFormID.HasValue) { exp = exp.And(x => x.ExaminationFormID == examinationFormID); } var q = ExaminationSubjectDAL.GetExaminationSubjectView(exp); if (!string.IsNullOrEmpty(examinationSubjectView.ConditionValue) && !string.IsNullOrEmpty(examinationSubjectView.Attribute)) q = q.DynamicWhere(examinationSubjectView.Attribute, examinationSubjectView.Condition, examinationSubjectView.ConditionValue); return q.OrderBy(x => x.Name).ToGridResultSet(pageIndex, pageSize); } public IList GetExaminationSubjectViewList(ViewModel.ConfiguretView examinationSubjectView, int? examinationFormID, Guid? examinationSubjectID) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (examinationFormID.HasValue) { exp = exp.And(x => x.ExaminationFormID == examinationFormID); } var q = ExaminationSubjectDAL.GetExaminationSubjectView(exp); if (!string.IsNullOrEmpty(examinationSubjectView.ConditionValue) && !string.IsNullOrEmpty(examinationSubjectView.Attribute)) q = q.DynamicWhere(examinationSubjectView.Attribute, examinationSubjectView.Condition, examinationSubjectView.ConditionValue); return q.OrderBy(x => x.Name).ToList(); } public ViewModel.ExaminationApply.ExaminationSubjectView GetExaminationSubjectViewInfo(Guid? examinationSubjectID) { return ExaminationSubjectDAL.GetExaminationSubjectView(x => x.ExaminationSubjectID == examinationSubjectID).FirstOrDefault(); } public void Save(ViewModel.ExaminationApply.ExaminationSubjectView examinationSubjectView) { var examinationSubjectEntity = ExaminationSubjectDAL.ExaminationSubjectRepository.GetSingle(x => x.ExaminationSubjectID == examinationSubjectView.ExaminationSubjectID); //考试科目名字唯一 var RepeatSubject = ExaminationSubjectDAL.ExaminationSubjectRepository.GetSingle(x => //x.ExaminationTypeID == examinationSubjectView.ExaminationTypeID && //x.ExaminationFormID == examinationSubjectView.ExaminationFormID && //x.SchoolyearID == examinationSubjectView.SchoolyearID && x.Name == examinationSubjectView.Name); if (examinationSubjectEntity != null) { if (RepeatSubject != null && examinationSubjectEntity.ExaminationSubjectID != RepeatSubject.ExaminationSubjectID) { //考试科目,判断考试类型、考试类别、学年学期、考试科目名称不能重复 throw new Exception("已存在【" + RepeatSubject.Name + "】考试科目,请核查"); } examinationSubjectEntity.ExaminationTypeID = examinationSubjectView.ExaminationTypeID; examinationSubjectEntity.SchoolyearID = examinationSubjectView.SchoolyearID; examinationSubjectEntity.ExaminationFormID = examinationSubjectView.ExaminationFormsID; examinationSubjectEntity.Name = examinationSubjectView.Name; examinationSubjectEntity.PreposeSubjectID = examinationSubjectView.PreposeSubjectID; examinationSubjectEntity.PreposeScoreLimit = examinationSubjectView.PreposeScoreLimit; examinationSubjectEntity.ExaminationDate = examinationSubjectView.ExaminationDate; examinationSubjectEntity.PeopleNumLimit = examinationSubjectView.PeopleNumLimit; examinationSubjectEntity.Cost = examinationSubjectView.Cost; examinationSubjectEntity.Remark = examinationSubjectView.Remark; this.SetModifyStatus(examinationSubjectEntity); } else { if (RepeatSubject != null) { //考试科目,判断考试类型、考试类别、学年学期、名称不能重复 throw new Exception("已存在【" + RepeatSubject.Name + "】考试科目,请核查"); } examinationSubjectEntity = new EX_ExaminationSubject(); examinationSubjectEntity.ExaminationSubjectID = Guid.NewGuid(); examinationSubjectEntity.ExaminationTypeID = examinationSubjectView.ExaminationTypeID; examinationSubjectEntity.SchoolyearID = examinationSubjectView.SchoolyearID; examinationSubjectEntity.ExaminationFormID = examinationSubjectView.ExaminationFormsID; examinationSubjectEntity.Name = examinationSubjectView.Name; examinationSubjectEntity.PreposeSubjectID = examinationSubjectView.PreposeSubjectID; examinationSubjectEntity.PreposeScoreLimit = examinationSubjectView.PreposeScoreLimit; examinationSubjectEntity.ExaminationDate = examinationSubjectView.ExaminationDate; examinationSubjectEntity.PeopleNumLimit = examinationSubjectView.PeopleNumLimit; examinationSubjectEntity.Cost = examinationSubjectView.Cost; examinationSubjectEntity.Remark = examinationSubjectView.Remark; this.SetNewStatus(examinationSubjectEntity); UnitOfWork.Add(examinationSubjectEntity); } UnitOfWork.Commit(); } public void Delete(IList examinationSubjectID) { if (examinationSubjectID.Count > 0) { UnitOfWork.Delete(x => examinationSubjectID.Contains(x.ExaminationSubjectID)); } } public string[] Validation(List ExaminationFormIDs, List names) { try { for (int i = 0; i < ExaminationFormIDs.Count; i++) {int? ExaminationFormID = ExaminationFormIDs[0]; string name = names[0]; //var SubjectCountLimit = SubjectCountLimitDAL.ExaminationSubjectCountLimitRepository.Entities.Where(x => // x.ExaminationTypeID == examinationType.Value && x.FacultymajorID == facultymajorIDs[0].Value && // x.Years == years[0].Value).FirstOrDefault(); var Subject = ExaminationSubjectDAL.GetExaminationSubjectView(x =>x.ExaminationFormID == ExaminationFormID && x.Name == name).FirstOrDefault(); if (Subject != null) return new[] { "false", "科目【" + Subject.Name + "】"+ Subject.ExaminationFormName + "的考试性质数据已存在。" }; } } catch (Exception ex) { return new[] { "false", ex.Message }; } return new[] { "true", "成功" }; } } }