Exemple #1
0
 /// <summary>
 /// 修改培训计划
 /// </summary>
 /// <param name="TestPlan"></param>
 public static void UpdateTestPlan(Model.Training_TestPlan TestPlan)
 {
     Model.Training_TestPlan newTestPlan = db.Training_TestPlan.FirstOrDefault(e => e.TestPlanId == TestPlan.TestPlanId);
     if (newTestPlan != null)
     {
         newTestPlan.PlanCode      = TestPlan.PlanCode;
         newTestPlan.PlanName      = TestPlan.PlanName;
         newTestPlan.PlanManId     = TestPlan.PlanManId;
         newTestPlan.PlanDate      = TestPlan.PlanDate;
         newTestPlan.TestStartTime = TestPlan.TestStartTime;
         newTestPlan.TestEndTime   = TestPlan.TestEndTime;
         newTestPlan.Duration      = TestPlan.Duration;
         newTestPlan.TotalScore    = TestPlan.TotalScore;
         newTestPlan.QuestionCount = TestPlan.QuestionCount;
         newTestPlan.TestPalce     = TestPlan.TestPalce;
         newTestPlan.UnitIds       = TestPlan.UnitIds;
         newTestPlan.UnitNames     = TestPlan.UnitNames;
         newTestPlan.DepartIds     = TestPlan.DepartIds;
         newTestPlan.DepartNames   = TestPlan.DepartNames;
         newTestPlan.WorkPostIds   = TestPlan.WorkPostIds;
         newTestPlan.WorkPostNames = TestPlan.WorkPostNames;
         newTestPlan.States        = TestPlan.States;
         db.SubmitChanges();
     }
 }
Exemple #2
0
        /// <summary>
        /// 结束考试
        /// </summary>
        public static void SubmitTest(Model.Training_TestPlan getTestPlan)
        {
            using (Model.SUBHSSEDB db = new Model.SUBHSSEDB(Funs.ConnString))
            {
                ////所有交卷的人员 交卷 并计算分数
                var getTrainingTestRecords = from x in db.Training_TestRecord
                                             where x.TestPlanId == getTestPlan.TestPlanId && (!x.TestEndTime.HasValue || !x.TestScores.HasValue)
                                             select x;
                foreach (var itemRecord in getTrainingTestRecords)
                {
                    itemRecord.TestEndTime = DateTime.Now;
                    itemRecord.TestScores  = db.Training_TestRecordItem.Where(x => x.TestRecordId == itemRecord.TestRecordId).Sum(x => x.SubjectScore) ?? 0;
                    db.SubmitChanges();
                }

                var getTrainingTasks = from x in db.Training_Task
                                       where x.PlanId == getTestPlan.PlanId && (x.States != "2" || x.States == null)
                                       select x;
                foreach (var item in getTrainingTasks)
                {
                    item.States = "2";
                    db.SubmitChanges();
                }

                ////TODO 讲培训计划 考试记录 写入到培训记录
                APITrainRecordService.InsertTrainRecord(getTestPlan);
            }
        }
Exemple #3
0
        /// <summary>
        /// 添加培训计划
        /// </summary>
        /// <param name="testPlan"></param>
        public static void AddTestPlan(Model.Training_TestPlan testPlan)
        {
            Model.Training_TestPlan newTestPlan = new Model.Training_TestPlan
            {
                TestPlanId    = testPlan.TestPlanId,
                ProjectId     = testPlan.ProjectId,
                PlanCode      = testPlan.PlanCode,
                PlanName      = testPlan.PlanName,
                PlanManId     = testPlan.PlanManId,
                PlanDate      = testPlan.PlanDate,
                TestStartTime = testPlan.TestStartTime,
                TestEndTime   = testPlan.TestEndTime,
                Duration      = testPlan.Duration,
                SValue        = testPlan.SValue,
                MValue        = testPlan.MValue,
                JValue        = testPlan.JValue,
                TotalScore    = testPlan.TotalScore,
                QuestionCount = testPlan.QuestionCount,
                TestPalce     = testPlan.TestPalce,
                UnitIds       = testPlan.UnitIds,
                UnitNames     = testPlan.UnitNames,
                DepartIds     = testPlan.DepartIds,
                DepartNames   = testPlan.DepartNames,
                WorkPostIds   = testPlan.WorkPostIds,
                WorkPostNames = testPlan.WorkPostNames,
                PlanId        = testPlan.PlanId,
                States        = testPlan.States
            };

            db.Training_TestPlan.InsertOnSubmit(newTestPlan);
            db.SubmitChanges();
        }
Exemple #4
0
        /// <summary>
        /// 保存TestPlan
        /// </summary>
        /// <param name="getTestPlan">考试计划记录</param>
        public static string SaveTestPlan(Model.TestPlanItem getTestPlan)
        {
            string alterStr = string.Empty;

            using (Model.SUBHSSEDB db = new Model.SUBHSSEDB(Funs.ConnString))
            {
                Model.Training_TestPlan newTestPlan = new Model.Training_TestPlan
                {
                    TestPlanId = getTestPlan.TestPlanId,
                    ProjectId  = getTestPlan.ProjectId,
                    PlanCode   = getTestPlan.TestPlanCode,
                    PlanName   = getTestPlan.TestPlanName,
                    PlanManId  = getTestPlan.TestPlanManId,
                    //PlanDate= getTestPlan.TestPlanDate,
                    TestStartTime = Funs.GetNewDateTimeOrNow(getTestPlan.TestStartTime),
                    TestEndTime   = Funs.GetNewDateTimeOrNow(getTestPlan.TestEndTime),
                    Duration      = getTestPlan.Duration,
                    SValue        = getTestPlan.SValue,
                    MValue        = getTestPlan.MValue,
                    JValue        = getTestPlan.JValue,
                    TotalScore    = getTestPlan.TotalScore,
                    QuestionCount = getTestPlan.QuestionCount,
                    TestPalce     = getTestPlan.TestPalce,
                    UnitIds       = getTestPlan.UnitIds,
                    WorkPostIds   = getTestPlan.WorkPostIds,
                    States        = getTestPlan.States,
                    PlanDate      = DateTime.Now,
                };

                if (!string.IsNullOrEmpty(getTestPlan.TrainingPlanId))
                {
                    newTestPlan.PlanId = getTestPlan.TrainingPlanId;
                }
                var isUpdate = db.Training_TestPlan.FirstOrDefault(x => x.TestPlanId == newTestPlan.TestPlanId);
                if (isUpdate == null)
                {
                    string unitId = string.Empty;
                    var    user   = db.Sys_User.FirstOrDefault(e => e.UserId == newTestPlan.PlanManId);
                    if (user != null)
                    {
                        unitId = user.UnitId;
                    }
                    newTestPlan.PlanCode = CodeRecordsService.ReturnCodeByMenuIdProjectId(Const.ProjectTestPlanMenuId, newTestPlan.ProjectId, unitId);
                    if (string.IsNullOrEmpty(newTestPlan.TestPlanId))
                    {
                        newTestPlan.TestPlanId = SQLHelper.GetNewID();
                    }

                    db.Training_TestPlan.InsertOnSubmit(newTestPlan);
                    db.SubmitChanges();

                    CodeRecordsService.InsertCodeRecordsByMenuIdProjectIdUnitId(Const.ProjectTestPlanMenuId, newTestPlan.ProjectId, null, newTestPlan.TestPlanId, newTestPlan.PlanDate);
                }
                else
                {
                    isUpdate.States = newTestPlan.States;
                    if (isUpdate.States == "0" || isUpdate.States == "1")
                    {
                        isUpdate.PlanName      = newTestPlan.PlanName;
                        isUpdate.PlanManId     = newTestPlan.PlanManId;
                        isUpdate.PlanDate      = newTestPlan.PlanDate;
                        isUpdate.TestStartTime = newTestPlan.TestStartTime;
                        isUpdate.TestEndTime   = newTestPlan.TestEndTime;
                        isUpdate.Duration      = newTestPlan.Duration;
                        isUpdate.TotalScore    = newTestPlan.TotalScore;
                        isUpdate.QuestionCount = newTestPlan.QuestionCount;
                        isUpdate.TestPalce     = newTestPlan.TestPalce;
                        isUpdate.UnitIds       = newTestPlan.UnitIds;
                        isUpdate.WorkPostIds   = newTestPlan.WorkPostIds;
                        ////删除 考生记录
                        var deleteRecords = from x in db.Training_TestRecord
                                            where x.TestPlanId == isUpdate.TestPlanId
                                            select x;
                        if (deleteRecords.Count() > 0)
                        {
                            foreach (var item in deleteRecords)
                            {
                                var testRecordItem = from x in db.Training_TestRecordItem
                                                     where x.TestRecordId == item.TestRecordId
                                                     select x;
                                if (testRecordItem.Count() > 0)
                                {
                                    db.Training_TestRecordItem.DeleteAllOnSubmit(testRecordItem);
                                    db.SubmitChanges();
                                }
                            }

                            db.Training_TestRecord.DeleteAllOnSubmit(deleteRecords);
                            db.SubmitChanges();
                        }

                        ////删除 考试题目类型
                        var deleteTestPlanTrainings = from x in db.Training_TestPlanTraining where x.TestPlanId == isUpdate.TestPlanId select x;
                        if (deleteTestPlanTrainings.Count() > 0)
                        {
                            db.Training_TestPlanTraining.DeleteAllOnSubmit(deleteTestPlanTrainings);
                            db.SubmitChanges();
                        }
                    }
                    else if (isUpdate.States == "3") ////考试状态3时 更新培训计划状态 把培训计划写入培训记录中
                    {
                        DateTime?endTime = Funs.GetNewDateTime(getTestPlan.TestEndTime);
                        ////判断是否有未考完的考生
                        var getTrainingTestRecords = db.Training_TestRecord.FirstOrDefault(x => x.TestPlanId == isUpdate.TestPlanId &&
                                                                                           (!x.TestStartTime.HasValue || ((!x.TestEndTime.HasValue || !x.TestScores.HasValue) && x.TestStartTime.Value.AddMinutes(isUpdate.Duration) >= DateTime.Now)));
                        if (getTrainingTestRecords != null && endTime.HasValue && endTime.Value.AddMinutes(isUpdate.Duration) < DateTime.Now)
                        {
                            alterStr        = "当前存在未交卷考生,不能提前结束考试!";
                            isUpdate.States = "2";
                        }
                        else
                        {
                            SubmitTest(isUpdate);
                        }
                    }
                    else if (newTestPlan.States == "2") ////开始考试 只更新考试计划状态为考试中。
                    {
                        if (isUpdate.TestStartTime > DateTime.Now)
                        {
                            isUpdate.States = "1";
                            alterStr        = "未到考试扫码开始时间,不能开始考试!";
                        }
                    }
                    if (string.IsNullOrEmpty(alterStr))
                    {
                        db.SubmitChanges();
                    }
                }

                if (newTestPlan.States == "0" || newTestPlan.States == "1")
                {
                    if (getTestPlan.TestRecordItems.Count() > 0)
                    {
                        ////新增考试人员明细
                        foreach (var item in getTestPlan.TestRecordItems)
                        {
                            var person = db.SitePerson_Person.FirstOrDefault(e => e.PersonId == item.TestManId);
                            if (person != null)
                            {
                                Model.Training_TestRecord newTrainDetail = new Model.Training_TestRecord
                                {
                                    TestRecordId = SQLHelper.GetNewID(),
                                    ProjectId    = newTestPlan.ProjectId,
                                    TestPlanId   = newTestPlan.TestPlanId,
                                    TestManId    = item.TestManId,
                                    TestType     = item.TestType,
                                    Duration     = newTestPlan.Duration,
                                };
                                db.Training_TestRecord.InsertOnSubmit(newTrainDetail);
                                db.SubmitChanges();
                            }
                        }
                    }
                    if (getTestPlan.TestPlanTrainingItems.Count() > 0)
                    {
                        foreach (var item in getTestPlan.TestPlanTrainingItems)
                        {
                            var trainingType = TestTrainingService.GetTestTrainingById(item.TrainingTypeId);
                            if (trainingType != null)
                            {
                                Model.Training_TestPlanTraining newPlanItem = new Model.Training_TestPlanTraining
                                {
                                    TestPlanTrainingId = SQLHelper.GetNewID(),
                                    TestPlanId         = newTestPlan.TestPlanId,
                                    TrainingId         = item.TrainingTypeId,
                                    TestType1Count     = item.TestType1Count,
                                    TestType2Count     = item.TestType2Count,
                                    TestType3Count     = item.TestType3Count,
                                };

                                db.Training_TestPlanTraining.InsertOnSubmit(newPlanItem);
                                db.SubmitChanges();
                            }
                        }
                    }
                }
            }
            return(alterStr);
        }
Exemple #5
0
        /// <summary>
        /// 根据培训计划ID生成 考试计划信息
        /// </summary>
        /// <param name="getTestPlan"></param>
        public static string SaveTestPlanByTrainingPlanId(string trainingPlanId, string userId)
        {
            string testPlanId = string.Empty;

            using (Model.SUBHSSEDB db = new Model.SUBHSSEDB(Funs.ConnString))
            {
                ////培训计划
                var getTrainingPlan = db.Training_Plan.FirstOrDefault(x => x.PlanId == trainingPlanId);;
                if (getTrainingPlan != null && getTrainingPlan.States == "1")
                {
                    testPlanId = SQLHelper.GetNewID();
                    Model.Training_TestPlan newTestPlan = new Model.Training_TestPlan
                    {
                        TestPlanId = testPlanId,
                        ProjectId  = getTrainingPlan.ProjectId,
                        //PlanCode = getTrainingPlan.PlanCode,
                        PlanName      = getTrainingPlan.PlanName,
                        PlanManId     = userId,
                        PlanDate      = DateTime.Now,
                        TestStartTime = DateTime.Now,
                        TestPalce     = getTrainingPlan.TeachAddress,
                        UnitIds       = getTrainingPlan.UnitIds,
                        UnitNames     = UnitService.getUnitNamesUnitIds(getTrainingPlan.UnitIds),
                        WorkPostIds   = getTrainingPlan.WorkPostId,
                        WorkPostNames = WorkPostService.getWorkPostNamesWorkPostIds(getTrainingPlan.WorkPostId),
                        PlanId        = getTrainingPlan.PlanId,
                        States        = "0",
                    };

                    string unitId = string.Empty;
                    var    user   = db.Sys_User.FirstOrDefault(e => e.UserId == userId);
                    if (user != null)
                    {
                        unitId = user.UnitId;
                    }
                    newTestPlan.PlanCode = CodeRecordsService.ReturnCodeByMenuIdProjectId(Const.ProjectTestPlanMenuId, newTestPlan.ProjectId, unitId);

                    int Duration       = 90;
                    int SValue         = 1;
                    int MValue         = 2;
                    int JValue         = 1;
                    int testType1Count = 40;
                    int testType2Count = 10;
                    int testType3Count = 40;
                    ////获取考试规则设置数据
                    var getTestRule = db.Sys_TestRule.FirstOrDefault(); ////考试数据设置
                    if (getTestRule != null)
                    {
                        Duration       = getTestRule.Duration;
                        SValue         = getTestRule.SValue;
                        MValue         = getTestRule.MValue;
                        JValue         = getTestRule.JValue;
                        testType1Count = getTestRule.SCount;
                        testType2Count = getTestRule.MCount;
                        testType3Count = getTestRule.JCount;
                    }
                    ////按照培训类型获取试题类型及题型数量
                    var getTrainTypeItems = from x in db.Base_TrainTypeItem
                                            where x.TrainTypeId == getTrainingPlan.TrainTypeId
                                            select x;
                    if (getTrainTypeItems.Count() > 0)
                    {
                        testType1Count = getTrainTypeItems.Sum(x => x.SCount);
                        testType2Count = getTrainTypeItems.Sum(x => x.MCount);
                        testType3Count = getTrainTypeItems.Sum(x => x.JCount);
                    }

                    newTestPlan.Duration      = getTestRule.Duration;
                    newTestPlan.SValue        = getTestRule.SValue;
                    newTestPlan.MValue        = getTestRule.MValue;
                    newTestPlan.JValue        = getTestRule.JValue;
                    newTestPlan.TotalScore    = testType1Count * SValue + testType2Count * MValue + testType3Count * JValue;
                    newTestPlan.QuestionCount = testType1Count + testType2Count + testType3Count;
                    newTestPlan.TestEndTime   = newTestPlan.TestStartTime.AddMinutes(newTestPlan.Duration);
                    ////新增考试计划记录
                    var getIsTestPlan = db.Training_TestPlan.FirstOrDefault(x => x.PlanId == newTestPlan.PlanId);
                    if (getIsTestPlan == null)
                    {
                        db.Training_TestPlan.InsertOnSubmit(newTestPlan);
                        db.SubmitChanges();
                        CodeRecordsService.InsertCodeRecordsByMenuIdProjectIdUnitId(Const.ProjectTestPlanMenuId, newTestPlan.ProjectId, null, testPlanId, newTestPlan.PlanDate);
                        ///培训人员
                        var getTrainingTask = (from x in db.Training_Task where x.PlanId == trainingPlanId select x).ToList();
                        foreach (var itemTask in getTrainingTask)
                        {
                            Model.Training_TestRecord newTestRecord = new Model.Training_TestRecord
                            {
                                TestRecordId = SQLHelper.GetNewID(),
                                ProjectId    = getTrainingPlan.ProjectId,
                                TestPlanId   = testPlanId,
                                TestManId    = itemTask.UserId,
                                TestType     = db.Base_TrainType.First(z => z.TrainTypeId == getTrainingPlan.TrainTypeId).TrainTypeName,
                            };

                            db.Training_TestRecord.InsertOnSubmit(newTestRecord);
                            db.SubmitChanges();
                        }
                        if (getTrainTypeItems.Count() == 0)
                        {
                            /////考试题型类别及数量
                            Model.Training_TestPlanTraining newTestPlanTraining = new Model.Training_TestPlanTraining
                            {
                                TestPlanTrainingId = SQLHelper.GetNewID(),
                                TestPlanId         = testPlanId,
                                TestType1Count     = testType1Count,
                                TestType2Count     = testType2Count,
                                TestType3Count     = testType3Count,
                            };

                            db.Training_TestPlanTraining.InsertOnSubmit(newTestPlanTraining);
                            db.SubmitChanges();
                        }
                        else
                        {
                            foreach (var item in getTrainTypeItems)
                            {
                                /////考试题型类别及数量
                                Model.Training_TestPlanTraining newTestPlanTraining = new Model.Training_TestPlanTraining
                                {
                                    TestPlanTrainingId = SQLHelper.GetNewID(),
                                    TestPlanId         = testPlanId,
                                    TrainingId         = item.TrainingId,
                                    TestType1Count     = item.SCount,
                                    TestType2Count     = item.MCount,
                                    TestType3Count     = item.JCount,
                                };
                                db.Training_TestPlanTraining.InsertOnSubmit(newTestPlanTraining);
                                db.SubmitChanges();
                            }
                        }
                    }
                    ////回写培训计划状态
                    getTrainingPlan.States = "2";
                    db.SubmitChanges();
                }
            }
            return(testPlanId);
        }
Exemple #6
0
 /// <summary>
 ///  新增 考试人员明细
 /// </summary>
 public static void AddTrainingTestRecord(List <Model.TestRecordItem> testRecords, Model.Training_TestPlan newTestPlan)
 {
     foreach (var item in testRecords)
     {
         var person = PersonService.GetPersonById(item.TestManId);
         if (person != null)
         {
             Model.Training_TestRecord newTrainDetail = new Model.Training_TestRecord
             {
                 TestRecordId = SQLHelper.GetNewID(),
                 ProjectId    = newTestPlan.ProjectId,
                 TestPlanId   = newTestPlan.TestPlanId,
                 TestManId    = item.TestManId,
                 TestType     = item.TestType,
                 Duration     = newTestPlan.Duration,
             };
             TestRecordService.AddTestRecord(newTrainDetail);
         }
     }
 }
        /// <summary>
        /// 根据考生计划结束时 将相关培训考生内容 写培训记录归档
        /// </summary>
        /// <param name="getTestPlan"></param>

        public static void InsertTrainRecord(Model.Training_TestPlan getTestPlan)
        {
            using (Model.SUBHSSEDB db = new Model.SUBHSSEDB(Funs.ConnString))
            {
                ////获取培训计划
                var getTrainingPlan = db.Training_Plan.FirstOrDefault(e => e.PlanId == getTestPlan.PlanId);
                var getTrainRecord  = db.EduTrain_TrainRecord.FirstOrDefault(x => x.PlanId == getTestPlan.PlanId);
                if (getTrainingPlan != null && getTrainRecord == null)
                {
                    getTrainingPlan.States = "3";
                    db.SubmitChanges();

                    Model.EduTrain_TrainRecord newTrainRecord = new Model.EduTrain_TrainRecord
                    {
                        TrainingId     = SQLHelper.GetNewID(),
                        TrainingCode   = getTrainingPlan.PlanCode,
                        ProjectId      = getTrainingPlan.ProjectId,
                        TrainTitle     = getTrainingPlan.PlanName,
                        TrainContent   = getTrainingPlan.TrainContent,
                        TrainStartDate = getTrainingPlan.TrainStartDate,
                        TeachHour      = getTrainingPlan.TeachHour,
                        TrainEndDate   = getTrainingPlan.TrainEndDate,
                        TeachMan       = getTrainingPlan.TeachMan,
                        TeachAddress   = getTrainingPlan.TeachAddress,
                        Remark         = "来源:培训计划",
                        TrainTypeId    = getTrainingPlan.TrainTypeId,
                        TrainLevelId   = getTrainingPlan.TrainLevelId,
                        UnitIds        = getTrainingPlan.UnitIds,
                        States         = Const.State_2,
                        WorkPostIds    = getTrainingPlan.WorkPostId,
                        PlanId         = getTrainingPlan.PlanId,
                    };
                    newTrainRecord.CompileMan = UserService.GetUserNameByUserId(getTrainingPlan.DesignerId);
                    ///获取培训人员
                    var getTrainingTasks = from x in db.Training_Task where x.PlanId == getTrainingPlan.PlanId
                                           select x;
                    newTrainRecord.TrainPersonNum = getTrainingTasks.Count();
                    ///新增培训记录
                    db.EduTrain_TrainRecord.InsertOnSubmit(newTrainRecord);
                    db.SubmitChanges();

                    ////及格分数
                    int passScore = 80;
                    var testRule  = db.Sys_TestRule.FirstOrDefault();
                    if (testRule != null)
                    {
                        passScore = testRule.PassingScore;
                    }

                    foreach (var item in getTrainingTasks)
                    {
                        decimal gScores = 0;
                        bool    result  = false;
                        ////获取 考生试卷
                        var getTestRecord = db.Training_TestRecord.Where(x => x.TestPlanId == getTestPlan.TestPlanId && x.TestManId == item.UserId);
                        foreach (var itemR in getTestRecord)
                        {
                            if (itemR.TestScores > gScores)
                            {
                                gScores = itemR.TestScores ?? 0;
                            }
                        }

                        if (gScores >= passScore)
                        {
                            result = true;
                        }

                        Model.EduTrain_TrainRecordDetail newDetail = new Model.EduTrain_TrainRecordDetail
                        {
                            TrainDetailId = SQLHelper.GetNewID(),
                            TrainingId    = newTrainRecord.TrainingId,
                            PersonId      = item.UserId,
                            CheckScore    = gScores,
                            CheckResult   = result,
                        };
                        db.EduTrain_TrainRecordDetail.InsertOnSubmit(newDetail);
                        db.SubmitChanges();

                        ///// 培训考试 通过 更新卡号
                        if (result)
                        {
                            var getPerson = db.SitePerson_Person.FirstOrDefault(e => e.PersonId == newDetail.PersonId);
                            if (getPerson != null && string.IsNullOrEmpty(getPerson.CardNo))
                            {
                                getPerson.CardNo = SQLHelper.RunProcNewId("SpGetNewNumber", "SitePerson_Person", "CardNo", getPerson.ProjectId, UnitService.GetUnitCodeByUnitId(getPerson.UnitId));
                                db.SubmitChanges();
                            }
                        }
                    }

                    ////增加一条编码记录
                    CodeRecordsService.InsertCodeRecordsByMenuIdProjectIdUnitId(Const.ProjectTrainRecordMenuId, newTrainRecord.ProjectId, null, newTrainRecord.TrainingId, newTrainRecord.TrainStartDate);
                    CommonService.btnSaveData(newTrainRecord.ProjectId, Const.ProjectTrainRecordMenuId, newTrainRecord.TrainingId, getTrainingPlan.DesignerId, true, newTrainRecord.TrainTitle, "../EduTrain/TrainRecordView.aspx?TrainingId={0}");
                }
            }
        }
        /// <summary>
        /// 根据PersonId、TestPlanId生成试卷 扫码生成试卷
        /// </summary>
        /// <param name="testPlanId"></param>
        /// <returns></returns>
        public static string CreateTestRecordItem(Model.Training_TestPlan getTestPlan, string testRecordId, Model.SitePerson_Person person)
        {
            using (Model.SUBHSSEDB db = new Model.SUBHSSEDB(Funs.ConnString))
            {
                var getTestRecord = db.Training_TestRecord.FirstOrDefault(x => x.TestRecordId == testRecordId);
                if (getTestRecord != null && !getTestRecord.TestStartTime.HasValue)
                {
                    ////考试时长
                    getTestRecord.Duration      = getTestPlan.Duration;
                    getTestRecord.TestStartTime = DateTime.Now;
                    db.SubmitChanges();
                }

                ////当前人考试记录  未加入考试计划的 当考试开始扫码时 不允许再参与考试
                var item = db.Training_TestRecordItem.FirstOrDefault(x => x.TestRecordId == getTestRecord.TestRecordId);
                if (item == null)
                {
                    List <Model.Training_TestTrainingItem> getTestTrainingItemList = new List <Model.Training_TestTrainingItem>();
                    var testPlanTrainings = from x in db.Training_TestPlanTraining
                                            where x.TestPlanId == getTestPlan.TestPlanId
                                            select x;
                    //// 计划考试中单选、多选、判断题总数
                    int sumTestType1Count = testPlanTrainings.Sum(x => x.TestType1Count) ?? 0;
                    int sumTestType2Count = testPlanTrainings.Sum(x => x.TestType2Count) ?? 0;
                    int sumTestType3Count = testPlanTrainings.Sum(x => x.TestType3Count) ?? 0;

                    ////获取类型下适合岗位试题集合
                    var getTestTrainingItemALLs = from x in db.Training_TestTrainingItem
                                                  where x.TrainingId != null && (x.WorkPostIds == null || (x.WorkPostIds.Contains(person.WorkPostId) && person.WorkPostId != null))
                                                  select x;
                    foreach (var itemT in testPlanTrainings)
                    {
                        //// 获取类型下的题目
                        var getTestTrainingItems = getTestTrainingItemALLs.Where(x => x.TrainingId == itemT.TrainingId).ToList();
                        if (getTestTrainingItems.Count() > 0)
                        {
                            ////单选题
                            var getSItem = getTestTrainingItems.Where(x => x.TestType == "1").OrderBy(x => Guid.NewGuid()).Take(itemT.TestType1Count ?? 1);
                            if (getSItem.Count() > 0)
                            {
                                getTestTrainingItemList.AddRange(getSItem);
                            }
                            ///多选题
                            var getMItem = getTestTrainingItems.Where(x => x.TestType == "2").OrderBy(x => Guid.NewGuid()).Take(itemT.TestType2Count ?? 1);
                            if (getMItem.Count() > 0)
                            {
                                getTestTrainingItemList.AddRange(getMItem);
                            }
                            ///判断题
                            var getJItem = getTestTrainingItems.Where(x => x.TestType == "3").OrderBy(x => Guid.NewGuid()).Take(itemT.TestType3Count ?? 1);
                            if (getJItem.Count() > 0)
                            {
                                getTestTrainingItemList.AddRange(getJItem);
                            }
                        }
                    }
                    //// 获取得到的单选题、多选题、判断题 数量
                    int getDiffTestType1Count = sumTestType1Count - getTestTrainingItemList.Where(x => x.TestType == "1").Count();
                    int getDiffTestType2Count = sumTestType2Count - getTestTrainingItemList.Where(x => x.TestType == "2").Count();
                    int getDiffTestType3Count = sumTestType3Count - getTestTrainingItemList.Where(x => x.TestType == "3").Count();
                    if (getDiffTestType1Count > 0 || getDiffTestType2Count > 0 || getDiffTestType3Count > 0)
                    {
                        var getTestTrainingItemNulls = getTestTrainingItemALLs.Where(x => x.WorkPostIds == null).ToList();
                        if (getTestTrainingItemNulls.Count() > 0)
                        {
                            /// 通用且未选择的题目
                            var getTestTrainingItemDiffs = getTestTrainingItemNulls.Except(getTestTrainingItemList).ToList();
                            ////单选题
                            if (getDiffTestType1Count > 0)
                            {
                                var getSItemD = getTestTrainingItemDiffs.Where(x => x.TestType == "1").OrderBy(x => Guid.NewGuid()).Take(getDiffTestType1Count);
                                if (getSItemD.Count() > 0)
                                {
                                    getTestTrainingItemList.AddRange(getSItemD);
                                }
                            }
                            ///多选题
                            if (getDiffTestType2Count > 0)
                            {
                                var getMItemD = getTestTrainingItemDiffs.Where(x => x.TestType == "2").OrderBy(x => Guid.NewGuid()).Take(getDiffTestType2Count);
                                if (getMItemD.Count() > 0)
                                {
                                    getTestTrainingItemList.AddRange(getMItemD);
                                }
                            }
                            ///判断题
                            if (getDiffTestType3Count > 0)
                            {
                                var getJItemD = getTestTrainingItemDiffs.Where(x => x.TestType == "3").OrderBy(x => Guid.NewGuid()).Take(getDiffTestType3Count);
                                if (getJItemD.Count() > 0)
                                {
                                    getTestTrainingItemList.AddRange(getJItemD);
                                }
                            }
                        }
                    }

                    if (getTestTrainingItemList.Count() > 0)
                    {
                        var getItems = from x in getTestTrainingItemList
                                       select new Model.Training_TestRecordItem
                        {
                            TestRecordItemId = SQLHelper.GetNewID(),
                            TestRecordId     = getTestRecord.TestRecordId,
                            TrainingItemName = x.TrainingItemName,
                            TrainingItemCode = x.TrainingItemCode,
                            Abstracts        = x.Abstracts,
                            AttachUrl        = x.AttachUrl,
                            TestType         = x.TestType,
                            AItem            = x.AItem,
                            BItem            = x.BItem,
                            CItem            = x.CItem,
                            DItem            = x.DItem,
                            EItem            = x.EItem,
                            AnswerItems      = x.AnswerItems,
                            Score            = x.TestType == "1" ? getTestPlan.SValue : (x.TestType == "2" ? getTestPlan.MValue : getTestPlan.JValue),
                        };

                        db.Training_TestRecordItem.InsertAllOnSubmit(getItems);
                        db.SubmitChanges();
                    }
                }
            }
            return(testRecordId);
        }