Ejemplo n.º 1
0
        /// <summary>
        /// 生成培训人员的培训教材明细
        /// </summary>
        /// <param name="taskId"></param>
        public static void CreateTrainingTaskItemByTaskId(string taskId)
        {
            using (Model.SUBHSSEDB db = new Model.SUBHSSEDB(Funs.ConnString))
            {
                /////查找未生成教材明细的 培训任务
                var getTasks = from x in db.Training_Task
                               where x.States == Const.State_0 && (x.TaskId == taskId || taskId == null)
                               select x;
                if (getTasks.Count() > 0)
                {
                    foreach (var item in getTasks)
                    {
                        var getPerson = db.SitePerson_Person.FirstOrDefault(e => e.PersonId == item.UserId);
                        if (getPerson != null)
                        {
                            ////获取计划下 人员培训教材明细
                            var getDataList = db.Sp_GetTraining_TaskItemTraining(item.PlanId, getPerson.WorkPostId);
                            foreach (var dataItem in getDataList)
                            {
                                Model.Training_TaskItem newTaskItem = new Model.Training_TaskItem
                                {
                                    TaskId           = item.TaskId,
                                    PlanId           = item.PlanId,
                                    PersonId         = item.UserId,
                                    TrainingItemCode = dataItem.TrainingItemCode,
                                    TrainingItemName = dataItem.TrainingItemName,
                                    AttachUrl        = dataItem.AttachUrl,
                                };

                                var getTaskItem = db.Training_TaskItem.FirstOrDefault(x => x.TaskId == item.TaskId && x.TrainingItemName == newTaskItem.TrainingItemName && x.AttachUrl == newTaskItem.AttachUrl);
                                if (getTaskItem == null)
                                {
                                    newTaskItem.TaskItemId = SQLHelper.GetNewID();
                                    db.Training_TaskItem.InsertOnSubmit(newTaskItem);
                                    db.SubmitChanges();
                                }
                            }
                        }

                        ////更新培训任务
                        item.States = Const.State_1;
                        db.SubmitChanges();
                    }
                }
            }
        }