Exemplo n.º 1
0
        public string SaveListTraineeScore(List <Tra_TraineeScoreImport> lstTraineeScore, out List <Tra_TraineeScoreImport> DataReviewOutput)
        {
            using (var context = new VnrHrmDataContext())
            {
                var    unitOfWork           = (IUnitOfWork)(new UnitOfWork(context));
                var    repoTra_Class        = new CustomBaseRepository <Tra_Class>(unitOfWork);
                var    repoTra_Trainee      = new CustomBaseRepository <Tra_Trainee>(unitOfWork);
                var    repoTra_TraineeTopic = new CustomBaseRepository <Tra_TraineeTopic>(unitOfWork);
                var    repoTra_TraineeScore = new CustomBaseRepository <Tra_TraineeScore>(unitOfWork);
                var    repoTra_ScoreType    = new CustomBaseRepository <Tra_ScoreType>(unitOfWork);
                var    traineeScoreServices = new Tra_TraineeScoreServices();
                string message = string.Empty;

                List <Tra_TraineeScoreEntity> entityNew    = new List <Tra_TraineeScoreEntity>();
                List <Tra_TraineeScore>       entityUpdate = new List <Tra_TraineeScore>();
                List <Tra_TraineeScore>       resultNew    = new List <Tra_TraineeScore>();
                List <Tra_TraineeScore>       resultUpdate = new List <Tra_TraineeScore>();
                DataReviewOutput = new List <Tra_TraineeScoreImport>();
                List <string> ClassCode = lstTraineeScore.Select(m => m.ClassCode).Distinct().ToList();
                //Lấy DS ClassID
                List <Guid> ClassID = repoTra_Class.GetAll().Where(m => m.IsDelete == null && ClassCode.Contains(m.Code)).Select(m => m.ID).ToList <Guid>();
                //Lấy DS TraineeID
                List <Guid> TraineeID = repoTra_Trainee.GetAll().Where(m => m.IsDelete == null && ClassID.Contains(m.ClassID)).Select(m => m.ID).ToList <Guid>();
                //Lấy DS TraineetopicID
                List <Guid> lstTraineeTopicID = repoTra_TraineeTopic.GetAll().Where(m => m.IsDelete == null && TraineeID.Contains(m.TraineeID ?? Guid.Empty)).Select(m => m.ID).ToList <Guid>();
                //Lấy DS TraineeTopic
                var TraineeTopicAll = repoTra_TraineeTopic.GetAll().Where(m => m.IsDelete == null && lstTraineeTopicID.Contains(m.ID))
                                      .Select(m => new { m.ID, TopicCode = m.Cat_Topic.Code, CodeEmp = m.Tra_Trainee.Hre_Profile.CodeEmp, ClassCode = m.Tra_Trainee.Tra_Class.Code });
                //Lấy DS TraineeScore
                List <Tra_TraineeScore> LstTraineeScoreAll = repoTra_TraineeScore.GetAll().Where(m => m.IsDelete == null && lstTraineeTopicID.Contains(m.TraineeTopicID ?? Guid.Empty)).ToList <Tra_TraineeScore>();
                List <string>           ScoreTypeCode      = lstTraineeScore.Select(m => m.TypeScore).Distinct().ToList <string>();
                List <Tra_ScoreType>    lstTypeScoreAll    = repoTra_ScoreType.GetAll().Where(m => m.IsDelete == null && ScoreTypeCode.Contains(m.Code)).ToList <Tra_ScoreType>();
                var stt = 1;
                foreach (var TraineeScore in lstTraineeScore)
                {
                    var           TraineeTopic = TraineeTopicAll.Where(m => m.CodeEmp == TraineeScore.CodeEmp && m.TopicCode == TraineeScore.TopicCode).FirstOrDefault();
                    Tra_ScoreType ScoreType    = lstTypeScoreAll.Where(m => m.Code == TraineeScore.TypeScore).FirstOrDefault();
                    if (TraineeTopic == null) //Loi import
                    {
                        TraineeScore.Stt       = stt++;
                        TraineeScore.TypeError = "Không Có Môn Học Của Học Viên";
                        DataReviewOutput.Add(TraineeScore);
                    }
                    else if (ScoreType == null)
                    {
                        TraineeScore.Stt       = stt++;
                        TraineeScore.TypeError = "Không Có Loại Điểm Của Môn Học";
                        DataReviewOutput.Add(TraineeScore);
                    }
                    else
                    {
                        TraineeScore.Stt = stt++;
                        DataReviewOutput.Add(TraineeScore);
                        //Kiem tra diem da co trong DB chua
                        //neu co roi thi update neu chua thi tao moi
                        Guid             TraineeTopicID       = TraineeTopic.ID;
                        Tra_TraineeScore TraineeScore_Current = LstTraineeScoreAll.Where(m => m.TraineeTopicID == TraineeTopicID && m.ScoreTypeID == ScoreType.ID).FirstOrDefault();
                        bool             isNew = false;
                        if (TraineeScore_Current == null)
                        {
                            isNew = true;
                            TraineeScore_Current    = new Tra_TraineeScore();
                            TraineeScore_Current.ID = Guid.NewGuid();
                        }
                        TraineeScore_Current.TraineeTopicID = TraineeTopicID;
                        TraineeScore_Current.ScoreTypeID    = ScoreType.ID;
                        TraineeScore_Current.Score          = TraineeScore.Score;
                        if (isNew)
                        {
                            resultNew.Add(TraineeScore_Current);
                        }
                        else
                        {
                            var entityEdit = new Tra_TraineeScoreEntity
                            {
                                ID             = TraineeScore_Current.ID,
                                TraineeTopicID = TraineeScore_Current.TraineeTopicID,
                                ScoreTypeID    = ScoreType.ID,
                                Score          = TraineeScore.Score
                            };

                            resultUpdate.Add(TraineeScore_Current);
                            message = traineeScoreServices.Edit(entityEdit);
                        }
                    }
                }
                entityNew    = resultNew.Translate <Tra_TraineeScoreEntity>();
                entityUpdate = resultUpdate.Translate <Tra_TraineeScore>();
                if (entityNew.Count > 0)
                {
                    message += traineeScoreServices.Add(entityNew);
                }



                return(message);
            }
        }
Exemplo n.º 2
0
        public string SaveListTraineeScore(List<Tra_TraineeScoreImport> lstTraineeScore, out List<Tra_TraineeScoreImport> DataReviewOutput)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoTra_Class = new CustomBaseRepository<Tra_Class>(unitOfWork);
                var repoTra_Trainee = new CustomBaseRepository<Tra_Trainee>(unitOfWork);
                var repoTra_TraineeTopic = new CustomBaseRepository<Tra_TraineeTopic>(unitOfWork);
                var repoTra_TraineeScore = new CustomBaseRepository<Tra_TraineeScore>(unitOfWork);
                var repoTra_ScoreType = new CustomBaseRepository<Tra_ScoreType>(unitOfWork);
                var traineeScoreServices = new Tra_TraineeScoreServices();
                string message = string.Empty;

                List<Tra_TraineeScoreEntity> entityNew = new List<Tra_TraineeScoreEntity>();
                List<Tra_TraineeScore> entityUpdate = new List<Tra_TraineeScore>();
                List<Tra_TraineeScore> resultNew = new List<Tra_TraineeScore>();
                List<Tra_TraineeScore> resultUpdate= new List<Tra_TraineeScore>();
                DataReviewOutput = new List<Tra_TraineeScoreImport>();
                List<string> ClassCode = lstTraineeScore.Select(m => m.ClassCode).Distinct().ToList();
                //Lấy DS ClassID
                List<Guid> ClassID = repoTra_Class.GetAll().Where(m => m.IsDelete == null && ClassCode.Contains(m.Code)).Select(m => m.ID).ToList<Guid>();
                //Lấy DS TraineeID
                List<Guid> TraineeID = repoTra_Trainee.GetAll().Where(m => m.IsDelete == null && ClassID.Contains(m.ClassID)).Select(m => m.ID).ToList<Guid>();
                //Lấy DS TraineetopicID
                List<Guid> lstTraineeTopicID = repoTra_TraineeTopic.GetAll().Where(m => m.IsDelete == null && TraineeID.Contains(m.TraineeID ?? Guid.Empty)).Select(m => m.ID).ToList<Guid>();
                //Lấy DS TraineeTopic
                var TraineeTopicAll = repoTra_TraineeTopic.GetAll().Where(m => m.IsDelete == null && lstTraineeTopicID.Contains(m.ID))
                    .Select(m => new { m.ID, TopicCode = m.Cat_Topic.Code, CodeEmp = m.Tra_Trainee.Hre_Profile.CodeEmp, ClassCode = m.Tra_Trainee.Tra_Class.Code });
                //Lấy DS TraineeScore
                List<Tra_TraineeScore> LstTraineeScoreAll = repoTra_TraineeScore.GetAll().Where(m => m.IsDelete == null && lstTraineeTopicID.Contains(m.TraineeTopicID ?? Guid.Empty)).ToList<Tra_TraineeScore>();
                List<string> ScoreTypeCode = lstTraineeScore.Select(m => m.TypeScore).Distinct().ToList<string>();
                List<Tra_ScoreType> lstTypeScoreAll = repoTra_ScoreType.GetAll().Where(m => m.IsDelete == null && ScoreTypeCode.Contains(m.Code)).ToList<Tra_ScoreType>();
                var stt = 1;
                foreach (var TraineeScore in lstTraineeScore)
                {
                    var TraineeTopic = TraineeTopicAll.Where(m =>  m.CodeEmp == TraineeScore.CodeEmp && m.TopicCode == TraineeScore.TopicCode).FirstOrDefault();
                    Tra_ScoreType ScoreType = lstTypeScoreAll.Where(m => m.Code == TraineeScore.TypeScore).FirstOrDefault();
                    if (TraineeTopic == null) //Loi import
                    {
                        TraineeScore.Stt = stt++;
                        TraineeScore.TypeError = "Không Có Môn Học Của Học Viên";
                        DataReviewOutput.Add(TraineeScore);
                    }
                    else if (ScoreType == null)
                    {
                        TraineeScore.Stt = stt++;
                        TraineeScore.TypeError = "Không Có Loại Điểm Của Môn Học";
                        DataReviewOutput.Add(TraineeScore);
                    }
                    else
                    {
                        TraineeScore.Stt = stt++;
                        DataReviewOutput.Add(TraineeScore);
                        //Kiem tra diem da co trong DB chua
                        //neu co roi thi update neu chua thi tao moi
                        Guid TraineeTopicID = TraineeTopic.ID;
                        Tra_TraineeScore TraineeScore_Current = LstTraineeScoreAll.Where(m => m.TraineeTopicID == TraineeTopicID && m.ScoreTypeID == ScoreType.ID).FirstOrDefault();
                        bool isNew = false;
                        if (TraineeScore_Current == null)
                        {
                            isNew = true;
                            TraineeScore_Current = new Tra_TraineeScore();
                            TraineeScore_Current.ID = Guid.NewGuid();
                        }
                        TraineeScore_Current.TraineeTopicID = TraineeTopicID;
                        TraineeScore_Current.ScoreTypeID = ScoreType.ID;
                        TraineeScore_Current.Score = TraineeScore.Score;
                        if (isNew)
                        {
                            resultNew.Add(TraineeScore_Current);
                        }
                        else
                        {
                            var entityEdit = new Tra_TraineeScoreEntity 
                            {
                                ID = TraineeScore_Current.ID,
                                TraineeTopicID = TraineeScore_Current.TraineeTopicID,
                                ScoreTypeID = ScoreType.ID,
                                Score = TraineeScore.Score

                            };
                            
                            resultUpdate.Add(TraineeScore_Current);
                            message = traineeScoreServices.Edit(entityEdit);
                        }

                    }
                }
                entityNew = resultNew.Translate<Tra_TraineeScoreEntity>();
                entityUpdate = resultUpdate.Translate<Tra_TraineeScore>();
                if (entityNew.Count > 0)
                {
                    message += traineeScoreServices.Add(entityNew);
                
                }
              
                
              
                return message;
            }


        }
Exemplo n.º 3
0
        public DataTable GetReportTraineeResult(List<Tra_TraineeEntity> lstTrainee, bool IsCreateTemplate, string _ScoreTypeID, string UserLogin)
        {

            using (var context = new VnrHrmDataContext())
            {
                string status = string.Empty;
                var ScoreTypeServices = new Tra_ScoreTypeServices();
                Tra_ScoreTypeEntity objScoreTypeentity = new Tra_ScoreTypeEntity();

                if (_ScoreTypeID != null)
                {
                    _ScoreTypeID = Common.DotNetToOracle(_ScoreTypeID);
                    objScoreTypeentity = ScoreTypeServices.GetData<Tra_ScoreTypeEntity>(_ScoreTypeID, ConstantSql.hrm_tra_sp_get_ScoreTypeByIds, UserLogin, ref status).FirstOrDefault();
                }

                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                DataTable table = CreateReportTraineeResult();
                if (IsCreateTemplate)
                {
                    return table;
                }
                if (lstTrainee == null)
                {
                    return table;
                }
                List<Guid> lstTraineeIDs = lstTrainee.Select(s => s.ID).ToList();
                var traineeTopicServices = new Tra_TraineeTopicServices();
                var objTraineeTopic = new List<object>();
                objTraineeTopic.Add(1);
                objTraineeTopic.Add(int.MaxValue - 1);
                var lstTraineeTopic = traineeTopicServices.GetData<Tra_TraineeTopicEntity>(objTraineeTopic, ConstantSql.hrm_tra_sp_get_TraineeTopic, UserLogin, ref status).ToList();
                List<Guid> lstTraineeTopicIDs = null;
                List<Guid> lstTopicIDs = null;
                if (lstTraineeTopic.Count > 0)
                {
                    lstTraineeTopic = lstTraineeTopic.Where(s => s.TraineeID != null && lstTraineeIDs.Contains(s.TraineeID.Value)).ToList();
                    if (lstTraineeTopic.Count > 0)
                    {
                        lstTraineeTopicIDs = lstTraineeTopic.Select(s => s.ID).ToList();
                        lstTopicIDs = lstTraineeTopic.Select(s => s.TopicID.Value).Distinct().ToList();
                    }

                }
                var scoreTopicServices = new Tra_ScoreTopicServices();
                var objScoreTopic = new List<object>();
                objScoreTopic.Add(1);
                objScoreTopic.Add(int.MaxValue - 1);
                var lstScoreTopic = scoreTopicServices.GetData<Tra_ScoreTopicEntity>(objScoreTopic, ConstantSql.hrm_tra_sp_get_ScoreTopic, UserLogin, ref status).ToList();
                if (lstScoreTopic.Count > 0 && lstTopicIDs != null)
                {
                    lstScoreTopic = lstScoreTopic.Where(s => s.TopicID != null && lstTopicIDs.Contains(s.TopicID.Value)).ToList();
                }
                var traineeScoreServices = new Tra_TraineeScoreServices();
                var objTraineeScore = new List<object>();
                objTraineeScore.Add(1);
                objTraineeScore.Add(int.MaxValue - 1);
                var lstTraineeScore = traineeScoreServices.GetData<Tra_TraineeScoreEntity>(objTraineeScore, ConstantSql.hrm_tra_sp_get_TraineeScore, UserLogin, ref status).ToList();
                if (lstTraineeScore.Count > 0 && lstTraineeTopicIDs != null)
                {
                    lstTraineeScore = lstTraineeScore.Where(s => s.TraineeTopicID != null && lstTraineeTopicIDs.Contains(s.TraineeTopicID.Value)).ToList();
                }
                //var traineeScoreTypeServices = new Tra_ScoreTypeServices();
                //var objTraineeScoreType = new List<object>();
                //objTraineeScoreType.AddRange(new object[4]);
                //objTraineeScoreType[2] = 1;
                //objTraineeScoreType[3] = int.MaxValue - 1;
                //var lstTraineeScoreType = traineeScoreTypeServices.GetData<Tra_ScoreTypeEntity>(objTraineeScoreType, ConstantSql.hrm_tra_sp_get_ScoreType, ref status).ToList();

                foreach (var item in lstTrainee)
                {
                    DataRow row = table.NewRow();
                    var flag = false;
                    //diem
                    if (lstTraineeTopic.Count > 0)
                    {
                        var objTraineeTopicByTrainId = lstTraineeTopic.Where(s => s.TraineeID == item.ID).ToList();
                        foreach (var traineeTopic in objTraineeTopicByTrainId)
                        {
                            var lstScoreTopicByTopicID = lstScoreTopic.Where(s => s.TopicID == traineeTopic.TopicID).Select(s => s.ScoreTypeID).ToList();
                            var lstTraineeScoreByTypeID = lstTraineeScore.Where(s => s.ScoreTypeID != null && lstScoreTopicByTopicID.Contains(s.ScoreTypeID) && s.Score != null && s.TraineeTopicID.Value == traineeTopic.ID).ToList();

                            if (lstTraineeScoreByTypeID.Count > 0)
                            {
                                var lstTraineeScoreByScore = lstTraineeScoreByTypeID.Where(s => s.Score != null).ToList();
                                if (lstTraineeScoreByScore.Count > 0)
                                {

                                    if (objScoreTypeentity != null && objScoreTypeentity.NumOrder != null && lstTraineeScoreByTypeID.Count > 0)
                                    {
                                        var objTraineeScoreByNumOder = lstTraineeScoreByTypeID.Where(s => s.NumOrder.Value == objScoreTypeentity.NumOrder.Value + 1).FirstOrDefault();
                                        if (objTraineeScoreByNumOder != null)
                                            break;
                                    }

                                    flag = true;
                                    if (item.CodeEmp != null)
                                        row[Tra_ReportTraineeResultEntity.FieldNames.CodeEmp] = item.CodeEmp;
                                    if (item.ProfileName != null)
                                        row[Tra_ReportTraineeResultEntity.FieldNames.ProfileName] = item.ProfileName;
                                    if (item.E_DEPARTMENT != null)
                                        row[Tra_ReportTraineeResultEntity.FieldNames.E_DEPARTMENT] = item.E_DEPARTMENT;
                                    if (item.E_DIVISION != null)
                                        row[Tra_ReportTraineeResultEntity.FieldNames.E_DIVISION] = item.E_DIVISION;
                                    if (item.E_SECTION != null)
                                        row[Tra_ReportTraineeResultEntity.FieldNames.E_SECTION] = item.E_SECTION;
                                    if (item.E_TEAM != null)
                                        row[Tra_ReportTraineeResultEntity.FieldNames.E_TEAM] = item.E_TEAM;
                                    if (item.E_UNIT != null)
                                        row[Tra_ReportTraineeResultEntity.FieldNames.E_UNIT] = item.E_UNIT;
                                    if (item.CourseCode != null)
                                        row[Tra_ReportTraineeResultEntity.FieldNames.CourseCode] = item.CourseCode;
                                    if (item.CourseName != null)
                                        row[Tra_ReportTraineeResultEntity.FieldNames.CourseName] = item.CourseName;
                                    if (item.ClassCode != null)
                                        row[Tra_ReportTraineeResultEntity.FieldNames.ClassCode] = item.ClassCode;
                                    if (item.ClassName != null)
                                        row[Tra_ReportTraineeResultEntity.FieldNames.ClassName] = item.ClassName;
                                    if (item.StartDate != null)
                                        row[Tra_ReportTraineeResultEntity.FieldNames.StartDate] = item.StartDate;
                                    if (item.StatusView != null)
                                        row[Tra_ReportTraineeResultEntity.FieldNames.StatusView] = item.StatusView;
                                    if (item.EndDate != null)
                                        row[Tra_ReportTraineeResultEntity.FieldNames.EndDate] = item.EndDate;
                                    if (item.Result != null)
                                        row[Tra_ReportTraineeResultEntity.FieldNames.Result] = item.Result;
                                    if (item.TrainLevelName != null)
                                        row[Tra_ReportTraineeResultEntity.FieldNames.TrainLevelName] = item.TrainLevelName;
                                }
                                foreach (var traineeScore in lstTraineeScoreByTypeID)
                                {
                                    if (traineeScore.Score != null)
                                    {
                                        if (traineeScore.NumOrder == 1)
                                        {
                                            row[Tra_ReportTraineeResultEntity.FieldNames.Score1] = traineeScore.Score;
                                        }
                                        if (traineeScore.NumOrder == 2)
                                        {
                                            row[Tra_ReportTraineeResultEntity.FieldNames.Score2] = traineeScore.Score;
                                        }
                                        if (traineeScore.NumOrder == 3)
                                        {
                                            row[Tra_ReportTraineeResultEntity.FieldNames.Score3] = traineeScore.Score;
                                        }
                                    }

                                }

                            }
                        }

                    }
                    if (flag)
                    {
                        table.Rows.Add(row);

                    }
                }
                return table.ConfigTable(true);
            }
        }
Exemplo n.º 4
0
        public DataTable GetReportTraineeUnAttend(string codeEmp, string profileName, string orgStructureID, Guid[] courseID, Guid[] classID, DateTime? _StartDate, DateTime? _EndDate, bool IsCreateTemplate, Guid[] RequirementTrainIDs, string UserLogin)
        {
            string status = string.Empty;

            DataTable table = CreateReportTraineeUnAttendSchema();
            if (IsCreateTemplate)
            {
                return table;
            }

            var traineeServices = new Tra_TraineeServices();
            var objTrainee = new List<object>();
            objTrainee.AddRange(new object[15]);
            objTrainee[9] = profileName;
            objTrainee[1] = codeEmp;
            objTrainee[8] = orgStructureID;
            objTrainee[3] = DateTime.Now;
            objTrainee[4] = DateTime.MaxValue;
            objTrainee[13] = 1;
            objTrainee[14] = int.MaxValue - 1;

            var lstTrainee = traineeServices.GetData<Tra_TraineeEntity>(objTrainee, ConstantSql.hrm_tra_sp_get_Trainee, UserLogin, ref status).ToList();
            if (lstTrainee.Count > 0)
                lstTrainee = lstTrainee.Where(s => s.EndDate != null && s.EndDate.Value > DateTime.Now).ToList();
            if (_StartDate != null)
                lstTrainee = lstTrainee.Where(s => s.StartDate != null && s.StartDate.Value <= _StartDate.Value).ToList();
            if (_EndDate != null)
                lstTrainee = lstTrainee.Where(s => s.EndDate != null && s.EndDate.Value >= _EndDate.Value).ToList();
            if (courseID != null)
            {
                lstTrainee = lstTrainee.Where(s => courseID.Contains(s.CourseID)).ToList();
            }

            if (classID != null)
            {
                lstTrainee = lstTrainee.Where(s => classID.Contains(s.ClassID)).ToList();
            }

            var lisRequirementDetailByprofileID = new List<Guid>();

            var requirmentDetailServices = new Tra_RequirementTrainDetailServices();
            var objRequirementDetail = new List<object>();
            objRequirementDetail.Add(null);
            objRequirementDetail.Add(1);
            objRequirementDetail.Add(int.MaxValue - 1);
            var lstRequirementDetail = requirmentDetailServices.GetData<Tra_RequirementTrainDetailEntity>(objRequirementDetail, ConstantSql.hrm_tra_sp_get_RequirementDetail, UserLogin, ref status).ToList();

            var lstClassIDByTrainee = lstTrainee.Select(s => s.ClassID).ToList();
            var lstCourseId = lstTrainee.Select(s => s.CourseID).ToList();
            if (RequirementTrainIDs != null)
            {
                lstRequirementDetail = lstRequirementDetail.Where(s => s.RequirementTrainID != null && RequirementTrainIDs.Contains(s.RequirementTrainID.Value)).ToList();
               // lstRequirementDetail = lstRequirementDetail.Where(s => s.CourseID != null && s.ClassID != null && s.ProfileID != null && lisRequirementDetailByprofileID.Contains(s.ProfileID.Value) && lstClassIDByTrainee.Contains(s.ClassID.Value) && lstCourseId.Contains(s.CourseID.Value)).ToList();
                if (lstRequirementDetail.Count > 0)
                {
                    lisRequirementDetailByprofileID = lstRequirementDetail.Where(s => s.ProfileID != null).Select(s => (Guid)s.ProfileID).ToList();                   
                }
            }         

            if(lisRequirementDetailByprofileID.Count > 0)
            {
               // lstTrainee = lstTrainee.Where(s => lisRequirementDetailByprofileID.Contains(s.ProfileID)).ToList();

                lisRequirementDetailByprofileID = lstRequirementDetail.Where(s => s.CourseID != null && s.ClassID != null && s.ProfileID != null && lisRequirementDetailByprofileID.Contains(s.ProfileID.Value) && lstClassIDByTrainee.Contains(s.ClassID.Value) && lstCourseId.Contains(s.CourseID.Value)).Select(s => (Guid)s.ProfileID).ToList();
            }
            var lstTraineeID = lstTrainee.Select(s => s.ID).ToList();


            var traineeTopicServices = new Tra_TraineeTopicServices();
            var objTraineeTopic = new List<object>();
            objTraineeTopic.Add(1);
            objTraineeTopic.Add(int.MaxValue - 1);
            var lstTraineeTopic = traineeTopicServices.GetData<Tra_TraineeTopicEntity>(objTraineeTopic, ConstantSql.hrm_tra_sp_get_TraineeTopic, UserLogin, ref status).ToList();

            lstTraineeTopic = lstTraineeTopic.Where(s => s.TraineeID != null && lstTraineeID.Contains(s.TraineeID.Value)).ToList();
            var lstTraineeTopicID = lstTraineeTopic.Select(s => s.ID).ToList();

            var traineeScoreService = new Tra_TraineeScoreServices();
            var objTraineeScore = new List<object>();
            objTraineeScore.Add(1);
            objTraineeScore.Add(int.MaxValue);
            var lstTraineeScore = traineeScoreService.GetData<Tra_TraineeScoreEntity>(objTraineeScore, ConstantSql.hrm_tra_sp_get_TraineeScore, UserLogin, ref status).ToList();

            
           
            
            lstTraineeScore = lstTraineeScore.Where(s => s.TraineeTopicID != null && lstTraineeTopicID.Contains(s.TraineeTopicID.Value) && s.TraineeID != null && s.Score != null).ToList();

            foreach (var item in lstTrainee)
            {
                DataRow dr = table.NewRow();
                var lstTraineeScoreByTraineeID = lstTraineeScore.Where(s => item.ID == s.TraineeID.Value).ToList();
                if (lstTraineeScoreByTraineeID.Count == 0)
                {
                    dr[Tra_ReportTraineeUnAttendEntity.FieldNames.CodeEmp] = item.CodeEmp;
                    dr[Tra_ReportTraineeUnAttendEntity.FieldNames.ProfileName] = item.ProfileName;
                    dr[Tra_ReportTraineeUnAttendEntity.FieldNames.E_DEPARTMENT] = item.E_DEPARTMENT;
                    dr[Tra_ReportTraineeUnAttendEntity.FieldNames.E_DIVISION] = item.E_DIVISION;
                    dr[Tra_ReportTraineeUnAttendEntity.FieldNames.E_SECTION] = item.E_SECTION;
                    dr[Tra_ReportTraineeUnAttendEntity.FieldNames.E_TEAM] = item.E_TEAM;
                    dr[Tra_ReportTraineeUnAttendEntity.FieldNames.E_UNIT] = item.E_UNIT;
                    dr[Tra_ReportTraineeUnAttendEntity.FieldNames.ClassName] = item.ClassName;
                    dr[Tra_ReportTraineeUnAttendEntity.FieldNames.CourseName] = item.CourseName;
                    dr[Tra_ReportTraineeUnAttendEntity.FieldNames.WorkPlace] = item.WorkPlaceName;
                    dr[Tra_ReportTraineeUnAttendEntity.FieldNames.RequirementTrainName] = item.RequirementTrainName;
                    table.Rows.Add(dr);
                }
            }

            return table;
        }
Exemplo n.º 5
0
        /// <summary>
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Tra_AddPointModel GetById(string id)
        {
            Tra_AddPointModel result = new Tra_AddPointModel();
            List<Guid> SelectedIds = new List<Guid>();

            if (!string.IsNullOrEmpty(id))
            {
                SelectedIds = id.Split(',').Select(s => Guid.Parse(s)).ToList();
            }

            if (SelectedIds != null && SelectedIds.Count > 0)
            {
               
                //Guid[] traineeID = null;
                var message = string.Empty;
                string status = string.Empty;

                List<Guid> lstClassID = new List<Guid>();
                List<Guid> lstTraineeID = new List<Guid>();
                #region load data
                var traineeServices = new Tra_TraineeServices();
                var objTrainee = new List<object>();
                objTrainee.AddRange(new object[15]);
                objTrainee[13] = 1;
                objTrainee[14] = int.MaxValue - 1;
                List<Tra_TraineeEntity> lstTrainee = traineeServices.GetData<Tra_TraineeEntity>(objTrainee, ConstantSql.hrm_tra_sp_get_Trainee, UserLogin, ref status);


                var courseSevices = new Tra_CourseServices();
                var objCoures = new List<object>();
                objCoures.AddRange(new object[11]);
                objCoures[9] = 1;
                objCoures[10] = int.MaxValue - 1;
                List<Tra_CourseEntity> lstCourse = courseSevices.GetData<Tra_CourseEntity>(objCoures, ConstantSql.hrm_tra_sp_get_Course, UserLogin, ref status);

                var classServices = new Tra_ClassServices();
                var objClass = new List<object>();
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(1);
                objClass.Add(int.MaxValue - 1);
                List<Tra_ClassEntity> lstClass = classServices.GetData<Tra_ClassEntity>(objClass, ConstantSql.hrm_tra_sp_get_Class, UserLogin, ref status);

                var traineeTopicServices = new Tra_TraineeTopicServices();
                var objTraineeTopic = new List<object>();
                objTraineeTopic.Add(1);
                objTraineeTopic.Add(int.MaxValue -1);
                var lstTraineeTopic = traineeTopicServices.GetData<Tra_TraineeTopicEntity>(objTraineeTopic, ConstantSql.hrm_tra_sp_get_TraineeTopic, UserLogin, ref status).ToList();

                var scoreTopicServices = new Tra_ScoreTopicServices();
                var objScoreTopic = new List<object>();
                objScoreTopic.Add(1);
                objScoreTopic.Add(int.MaxValue - 1);
                var lstScoreTopic = scoreTopicServices.GetData<Tra_ScoreTopicEntity>(objScoreTopic, ConstantSql.hrm_tra_sp_get_ScoreTopic, UserLogin, ref status).ToList();

                var courseTopicServices = new Tra_TraineeTopicServices();
                var objCourseTopic = new List<object>();
                objCourseTopic.Add(1);
                objCourseTopic.Add(int.MaxValue - 1);
                List<Tra_CourseTopicEntity> lstCourseTopic = courseTopicServices.GetData<Tra_CourseTopicEntity>(objCourseTopic, ConstantSql.hrm_tra_sp_get_CourseTopic, UserLogin, ref status);

                var traineeScoreServices = new Tra_TraineeScoreServices();
                var objTraineeScore = new List<object>();
                objTraineeScore.Add(1);
                objTraineeScore.Add(int.MaxValue - 1);
                var lstTraineeScore = traineeScoreServices.GetData<Tra_TraineeScoreEntity>(objTraineeScore, ConstantSql.hrm_tra_sp_get_TraineeScore, UserLogin, ref status).ToList();

                if (SelectedIds != null)
                {
                    lstTrainee = lstTrainee.Where(s => SelectedIds.Contains(s.ID)).ToList();
                    lstTraineeID = lstTrainee.Select(s => s.ID).ToList();
                    lstClassID = lstTrainee.Select(s => s.ClassID).Distinct().ToList();
                }
                if (lstClassID.Count > 1)
                {
                    DataTable tb = new DataTable();
                    result.ActionStatus = ConstantMessages.PlsChooseTraineeSameClass.ToString();
                    result.Ids = id;
                    result.Table = tb;
                    return result;
                }
                DataTable table = new DataTable();
                table.Columns.Add(Tra_TraineeScoreEntity.FieldNames.ID);
                table.Columns.Add(Tra_TraineeScoreEntity.FieldNames.CodeEmp);
                table.Columns.Add(Tra_TraineeScoreEntity.FieldNames.ProfileName);
                if (lstClassID.Count == 1)
                {
                    var isSimple = false;
                    Guid firstClass = lstClassID[0];
                    var courseEntity = lstClass.Where(s => s.ID == firstClass).Select(s => new { s.CourseID, s.IsComplex }).FirstOrDefault();

                    if (courseEntity != null)
                    {
                        var lstCourseTopicByCourseID = lstCourseTopic.Where(s => courseEntity.CourseID == s.CourseID).ToList();
                        if (courseEntity.IsComplex == null || courseEntity.IsComplex == false)
                        {
                            isSimple = true;
                        }
                        if (lstCourseTopicByCourseID.Count == 0)
                        {
                            DataTable tb = new DataTable();
                            result.ActionStatus = ConstantMessages.CourseNoHaveTopic.ToString();
                            result.Ids = id;
                            result.Table = tb;
                            return result;
                        }
                        if (isSimple == false)
                        {
                           
                            foreach (var trainee in lstTrainee)
                            {
                                DataRow dr = table.NewRow();
                                dr[Tra_TraineeScoreEntity.FieldNames.ID] = trainee.ID != null ? trainee.ID : Guid.Empty;
                                dr[Tra_TraineeScoreEntity.FieldNames.CodeEmp] = trainee.CodeEmp != null ? trainee.CodeEmp : string.Empty;
                                dr[Tra_TraineeScoreEntity.FieldNames.ProfileName] = trainee.ProfileName != null ? trainee.ProfileName : string.Empty;
                                var lstTopicbyCourseID = lstCourseTopic.Where(s => s.CourseID == courseEntity.CourseID).Select(s => new { s.CourseID, s.TopicID, s.IsComplex, s.Code }).ToList();
                                foreach (var item in lstTopicbyCourseID)
                                {
                                    
                                    var traineeTopicEnity = lstTraineeTopic.Where(s => s.TraineeID == trainee.ID && item.TopicID == s.TopicID).FirstOrDefault();
                                  
                                    var lstTraineeScoreByTraineeTopicID = lstTraineeScore.Where(s => traineeTopicEnity != null && s.TraineeTopicID == traineeTopicEnity.ID).ToList(); 
                                    var classeEntity = lstClass.Where(s => s.ID == trainee.ClassID).FirstOrDefault();
                                   
                                    Double value = 0;

                                    if (item.IsComplex == null || item.IsComplex == true)
                                    {
                                        isSimple = true;
                                        if (classeEntity != null)
                                        {
                                            var courseEntityByCourseID = lstCourse.Where(s => s.ID == classeEntity.CourseID).FirstOrDefault();
                                            if (courseEntityByCourseID != null)
                                            {
                                                var lstScoreTopicByTopicID = lstScoreTopic.Where(s => item.TopicID == s.TopicID).OrderBy(s => s.DateCreate).ToList();
                                                foreach (var scoreTopic in lstScoreTopicByTopicID)
                                                {
                                                    var traineeScoreEntity = lstTraineeScore.Where(s => traineeTopicEnity != null && s.ScoreTypeID == scoreTopic.ScoreTypeID && traineeTopicEnity.ID == s.TraineeTopicID).FirstOrDefault();
                                                    if (!table.Columns.Contains(item.Code + "_" + scoreTopic.Code))
                                                    {
                                                        table.Columns.Add(item.Code + "_" + scoreTopic.Code);
                                                    }
                                                    if (table.Columns.Contains(item.Code + "_" + scoreTopic.Code))
                                                    {
                                                        if (traineeScoreEntity != null && traineeScoreEntity.Score != null)
                                                        {
                                                            dr[item.Code + "_" + scoreTopic.Code] = traineeScoreEntity != null ? traineeScoreEntity.Score.Value : 0;
                                                        }
                                                        else
                                                        {
                                                            dr[item.Code + "_" + scoreTopic.Code] = null;
                                                        }

                                                    }
                                                }
                                               
                                            }
                                        }
                                        
                                    }
                                    else
                                    {
                                        isSimple = false;
                                        break;
                                    }
                                }
                                table.Rows.Add(dr);
                            }
                            //  var a = table;
                        }
                    }
                }
                result.Table = table;
                return result;
                #endregion
            }
            return null;
        }
Exemplo n.º 6
0
        public JsonResult SaveImortScore([DataSourceRequest] DataSourceRequest request, CatImportModel model)
        {
            var services = new Tra_TraineeScoreServices();
            List<Tra_TraineeScoreImport> lstTraineeScore = new List<Tra_TraineeScoreImport>();
            List<Tra_TraineeScoreImport> lstTraineeScoreTranslate = new List<Tra_TraineeScoreImport>();
            List<Tra_TraineeScoreImport> DataError = new List<Tra_TraineeScoreImport>();
            var _fileName = Common.GetPath(Common.TemplateURL) + model.TemplateFile;
            _fileName = _fileName.Replace("/", "\\");
            ImportService = new ImportService
            {
                //FileName = Common.GetPath(model.TemplateFile),
                FileName = _fileName,
                DateTimeFormat = model.FormatDate,
                ImportTemplateID = model.ID,

            };

            try
            {

                var table = ImportService.ImportNew(_fileName, model.TemplateFile, model.ID);

                lstTraineeScore = table.Translate<Tra_TraineeScoreImport>();

                foreach (var item in lstTraineeScore)
                {
                    var entity = new Tra_TraineeScoreImport
                    {
                        ClassCode = item.Column2,
                        CodeEmp = item.Column3,
                        TopicCode = item.Column4,
                        TypeScore = item.Column5,
                        Score = item.Column6,
                        TypeError = item.Column7,
                    };
                    lstTraineeScoreTranslate.Add(entity);
                }

                var message = services.SaveListTraineeScore(lstTraineeScoreTranslate, out DataError);
                if (message == NotificationType.Success.ToString())
                {
                    return Json(message, JsonRequestBehavior.AllowGet);
                }
            }
            catch (Exception ex)
            {
                model.Description = ex.Message;
            }
            return Json(DataError.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 7
0
        public ActionResult UpdateScoreInTraineeTopic(Dictionary<string, object> model)
        {
            string status = string.Empty;
            string message = string.Empty;
            var DictraineeID = model.ElementAt(0);
            string[] traineeID = (string[])DictraineeID.Value;
            // var entity = new Tra_TraineeTopicEntity();
            var lstEntity = new List<Tra_TraineeTopicEntity>();
            var topicServices = new ActionService(UserLogin);
            var objTopic = new List<object>();
            objTopic.Add(null);
            objTopic.Add(null);
            objTopic.Add(null);
            objTopic.Add(null);
            objTopic.Add(1);
            objTopic.Add(int.MaxValue - 1);
            var lstTopic = topicServices.GetData<Cat_TopicEntity>(objTopic, ConstantSql.hrm_cat_sp_get_Topic, ref status).ToList();

            var traineeScoreServices = new Tra_TraineeScoreServices();
            var objTraineeScore = new List<object>();
            objTraineeScore.Add(1);
            objTraineeScore.Add(int.MaxValue - 1);
            var lstTraineeScore = topicServices.GetData<Tra_TraineeScoreEntity>(objTraineeScore, ConstantSql.hrm_tra_sp_get_TraineeScore, ref status).ToList();

            var scoreTopicServices = new ActionService(UserLogin);
            var objScoreTopic = new List<object>();
            objScoreTopic.Add(1);
            objScoreTopic.Add(int.MaxValue - 1);
            var lstScoreTopic = scoreTopicServices.GetData<Tra_ScoreTopicEntity>(objScoreTopic, ConstantSql.hrm_tra_sp_get_ScoreTopic, ref status).ToList();

            var traineeTopicServices = new Tra_TraineeTopicServices();
            var objTraineeTopic = new List<object>();
            objTraineeTopic.Add(1);
            objTraineeTopic.Add(int.MaxValue - 1);
            var lstTraineeTopic = topicServices.GetData<Tra_TraineeTopicEntity>(objTraineeTopic, ConstantSql.hrm_tra_sp_get_TraineeTopic, ref status).ToList();
            if (model.Count > 0)
            {
                for (int i = 3; i < model.Count; i++)
                {
                    var entity = new Tra_TraineeTopicEntity();
                    var item = model.ElementAt(i);
                    var strTitle = item.Key.Split('_');
                    string[] score = (string[])item.Value;

                    var topicEnity = lstTopic.Where(s => item.Key.Contains(s.Code)).FirstOrDefault();

                    if (topicEnity != null)
                    {
                        var scoreTopicEntity = lstScoreTopic.Where(s => topicEnity.ID == s.TopicID && strTitle[1] == s.Code).FirstOrDefault();

                        var traineeTopicEntity = lstTraineeTopic.Where(s => s.TraineeID != null && topicEnity.ID == s.TopicID && Guid.Parse(traineeID[0]) == s.TraineeID.Value).FirstOrDefault();
                        if (traineeTopicEntity != null)
                        {
                            //Edit cột score trong bảng traineeTopic

                            if (!string.IsNullOrEmpty(score[0]))
                            {
                                traineeTopicEntity.Score = double.Parse(score[0]);
                            }
                            else {
                                traineeTopicEntity.Score = null;
                            }
                            
                            message = traineeTopicServices.Edit(traineeTopicEntity);

                            //Kiểm tra trong bảng TraineeScoree. Nếu chưa có record thì tạo mới nguoc lai thì edit record
                            var traineeScoreEntity = lstTraineeScore.Where(s => s.TraineeTopicID == traineeTopicEntity.ID && scoreTopicEntity.ScoreTypeID == s.ScoreTypeID).FirstOrDefault();
                            if (traineeScoreEntity == null)
                            {
                                Tra_TraineeScoreEntity newTraineeScoreEntity = new Tra_TraineeScoreEntity();
                                newTraineeScoreEntity.ScoreTypeID = scoreTopicEntity.ScoreTypeID;
                                newTraineeScoreEntity.TraineeTopicID = traineeTopicEntity.ID;
                                newTraineeScoreEntity.Score = traineeTopicEntity.Score;
                                message = traineeScoreServices.Add(newTraineeScoreEntity);
                            }
                            else
                            {
                                traineeScoreEntity.Score = traineeTopicEntity.Score;
                                message = traineeScoreServices.Edit(traineeScoreEntity);
                            }
                            // lstEntity.Add(traineeTopicEntity);
                        }
                    }
                }
                //message = traineeTopicServices.Edit(lstEntity);
            }
            return null;
        }