private void Recycle()
        {
            string Result = "T";
            string id     = Request["id"];
            IList <ExamineTask> etEnts = ExamineTask.FindAllByProperty(ExamineTask.Prop_ProjectId, id);

            foreach (ExamineTask etEnt in etEnts)
            {
                IList <ExamineOpinion> eoEnts = ExamineOpinion.FindAllByProperty(ExamineOpinion.Prop_ExamineTaskId, etEnt.Id);
                if (eoEnts.Count > 0)
                {
                    Result = "F";
                    break;
                }
            }
            if (Result == "T")
            {
                ExamineTask.DeleteAll("ProjectId='" + id + "'");
                pEnt          = Project.Find(id);
                pEnt.Status   = "已创建";
                pEnt.TaskQuan = 0;
                pEnt.DoUpdate();
            }
            Response.Write("{success:  true ,Result:'" + Result + "'}");
            Response.End();
        }
 private void LaunchExamine()
 {
     // 如果是部门级考核 启动时需要把自定义指标状态置为3
     if (esEnt.ExamineType == "部门级考核")
     {
         sql = @"select A.* from BJKY_Examine..DeptExamineRelation as A left join BJKY_Examine..ExamineStageDetail as B on A.Id=B.ExamineRelationId 
                     where B.ExamineStageId='" + esEnt.Id + "'";//找到部门考核关系里面的所有被考核人  查找他们的自定义指标
         IList <EasyDictionary> dicsRelation = DataHelper.QueryDictList(sql);
         string beUserIds = ""; string beUserNames = "";
         foreach (EasyDictionary dic in dicsRelation)
         {
             beUserIds   += dic.Get <string>("BeUserIds") + ",";
             beUserNames += dic.Get <string>("BeUserNames") + ",";
         }
         string[] userIdArray = null;
         if (!string.IsNullOrEmpty(beUserIds))
         {
             userIdArray = beUserIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
         }
         for (int j = 0; j < userIdArray.Length; j++)
         {
             IList <CustomIndicator> ciEnts = CustomIndicator.FindAllByProperties("CreateId", userIdArray[j], "Year", esEnt.Year, "StageType", esEnt.StageType);
             if (ciEnts.Count > 0)
             {
                 ciEnts[0].State = "3";//启动考核的时候将自定义指标的状态改为3  已结束
                 ciEnts[0].DoUpdate();
             }
         }
         IList <ExamineTask> etEnts = ExamineTask.FindAllByProperty(ExamineTask.Prop_ExamineStageId, id);
         foreach (ExamineTask etEnt in etEnts)
         {
             etEnt.State = "1";//任务状态
             etEnt.DoUpdate();
         }
         esEnt.State = 2;
         esEnt.DoUpdate();
         PageState.Add("Result", "T");
     }
     else//院级考核
     {
         IList <ExamineTask> etEnts = ExamineTask.FindAllByProperty(ExamineTask.Prop_ExamineStageId, id);
         foreach (ExamineTask etEnt in etEnts)
         {
             etEnt.State = "1";//任务状态
             etEnt.DoUpdate();
         }
         esEnt.State = 2;
         esEnt.DoUpdate();
         PageState.Add("Result", "T");
     }
 }
示例#3
0
        private void AmendTask()
        {
            IList <TempTask>    ttEnts = TempTask.FindAllByProperty(TempTask.Prop_ExamineStageId, ExamineStageId);
            IList <ExamineTask> etEnts = null;

            foreach (TempTask ttEnt in ttEnts)
            {
                if (esEnt.StageType == "院级考核")
                {
                    etEnts = ExamineTask.FindAllByProperties(ExamineTask.Prop_ExamineStageId, ExamineStageId, "BeUserId", ttEnt.BeUserId, "BeRoleCode", ttEnt.BeRoleCode, "BeDeptId", ttEnt.BeDeptId, "ToUserId", ttEnt.ToUserId, "ToRoleCode", ttEnt.ToRoleCode);
                }
                else
                {
                    etEnts = ExamineTask.FindAllByProperties(ExamineTask.Prop_ExamineStageId, ExamineStageId, "BeUserId", ttEnt.BeUserId, "BeDeptId", ttEnt.BeDeptId, "ToUserId", ttEnt.ToUserId);
                }
                if (etEnts.Count > 0)
                {
                    ttEnt.AmendState = "-";
                }
                else
                {
                    ttEnt.AmendState = "+";
                }
                ttEnt.DoUpdate();
            }
            etEnts = ExamineTask.FindAllByProperty(ExamineTask.Prop_ExamineStageId, ExamineStageId);
            foreach (ExamineTask etEnt in etEnts)
            {
                if (esEnt.StageType == "院级考核")
                {
                    ttEnts = TempTask.FindAllByProperties("ExamineStageId", ExamineStageId, "BeUserId", etEnt.BeUserId, "BeRoleCode", etEnt.BeRoleCode, "BeDeptId", etEnt.BeDeptId, "ToUserId", etEnt.ToUserId, "ToRoleCode", etEnt.ToRoleCode);
                }
                else
                {
                    ttEnts = TempTask.FindAllByProperties("ExamineStageId", ExamineStageId, "BeUserId", etEnt.BeUserId, "BeDeptId", etEnt.BeDeptId, "ToUserId", etEnt.ToUserId);
                }
                if (ttEnts.Count == 0)
                {
                    etEnt.AmendState = "-";
                }
                etEnt.DoUpdate();
            }
            sql = "delete BJKY_Examine..TempTask where ExamineStageId='" + ExamineStageId + "' and AmendState='-'";
            DataHelper.ExecSql(sql);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            id = RequestData.Get <string>("id");
            if (!string.IsNullOrEmpty(id))
            {
                esEnt = ExamineStage.Find(id);
            }
            switch (RequestActionString)
            {
            case "delete":
                string ids = RequestData.Get <string>("ids");
                sql = "delete BJKY_Examine..ExamineTask where PatIndex('%'+id+'%','" + ids + "')>0";
                DataHelper.ExecSql(sql);
                break;

            case "canceltask":
                if (esEnt.State == 1)
                {
                    sql = "delete BJKY_Examine..ExamineTask where ExamineStageId='" + id + "'";
                    DataHelper.ExecSql(sql);
                    sql = "delete BJKY_Examine..CustomIndicator where ExamineStageId='" + id + "'";
                    DataHelper.ExecSql(sql);
                    esEnt.TaskQuan = 0;
                    esEnt.State    = 0;
                    esEnt.DoUpdate();
                }
                break;

            case "createtask":
                if (esEnt.State == 0)
                {
                    CreateExamineTask(); //同时创建自定义的考核指标
                    esEnt.State    = 1;  //更新考核阶段状态为1 已生成
                    etEnts         = ExamineTask.FindAllByProperty(ExamineTask.Prop_ExamineStageId, id);
                    esEnt.TaskQuan = etEnts.Count;
                    esEnt.DoUpdate();
                }
                break;

            default:
                DoSelect();
                break;
            }
        }
        private void CancelLaunch()                                     //撤销启动
        {
            if (esEnt.ExamineType == "部门级考核")                           //撤销启动的时候 如果是部门级考核 需要将考核对象的自定义指标状态设置为2  也就是可以还填写自我评价
            {
                sql = @"select A.* from BJKY_Examine..DeptExamineRelation as A left join BJKY_Examine..ExamineStageDetail as B on A.Id=B.ExamineRelationId 
                            where B.ExamineStageId='" + esEnt.Id + "'"; //找到部门考核关系里面的所有被考核人  查找他们的自定义指标
                IList <EasyDictionary> dicsRelation = DataHelper.QueryDictList(sql);
                string beUserIds = ""; string beUserNames = "";
                foreach (EasyDictionary dic in dicsRelation)
                {
                    beUserIds   += dic.Get <string>("BeUserIds") + ",";
                    beUserNames += dic.Get <string>("BeUserNames") + ",";
                }
                string[] userIdArray = null;
                if (!string.IsNullOrEmpty(beUserIds))
                {
                    userIdArray = beUserIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                }
                for (int j = 0; j < userIdArray.Length; j++)
                {
                    IList <CustomIndicator> ciEnts = CustomIndicator.FindAllByProperties("CreateId", userIdArray[j], "Year", esEnt.Year, "StageType", esEnt.StageType);
                    if (ciEnts.Count > 0)
                    {
                        ciEnts[0].State = "2";
                        ciEnts[0].DoUpdate();
                    }
                }
            }
            IList <ExamineTask> etEnts = ExamineTask.FindAllByProperty(ExamineTask.Prop_ExamineStageId, esEnt.Id);

            foreach (ExamineTask etEnt in etEnts)
            {
                IList <IndicatorScore> isEnts = IndicatorScore.FindAllByProperty(IndicatorScore.Prop_ExamineTaskId, etEnt.Id);
                foreach (IndicatorScore isEnt in isEnts)
                {
                    isEnt.DoDelete();
                }
                etEnt.DoDelete();
            }
            esEnt.TaskQuan = 0;
            esEnt.State    = 0;
            esEnt.DoUpdate();
        }
        private void EndExamine()
        {
            IList <ExamineStageDetail> esdEnts = ExamineStageDetail.FindAllByProperty(ExamineStageDetail.Prop_ExamineStageId, id);

            #region 院级考核算分
            if (esEnt.ExamineType == "院级考核")
            {
                string beUserIds   = string.Empty;//存储被考核对象具体的人
                string beUserNames = string.Empty;
                string beDeptIds   = string.Empty;
                string beDeptNames = string.Empty;
                foreach (ExamineStageDetail esdEnt in esdEnts)//循环考核对象
                {
                    string[] array = GetBeUsersInfo(esdEnt);
                    beUserIds   = array[0];
                    beUserNames = array[1];
                    beDeptIds   = array[2];
                    beDeptNames = array[3];
                    //人+部门+被考核对象CODE就可以找到这个其下所有的任务 不能单纯按人查。因为有特例。一个人在在多个部门任职
                    string[] beUserIdArray = new string[] { }; string[] beUserNameArray = new string[] { };
                    string[] beDeptIdArray = new string[] { }; string[] beDeptNameArray = new string[] { };
                    if (!string.IsNullOrEmpty(beUserIds))//防止部分角色下无人
                    {
                        beUserIdArray = beUserIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    }
                    if (!string.IsNullOrEmpty(beUserNames))
                    {
                        beUserNameArray = beUserNames.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    }
                    if (!string.IsNullOrEmpty(beDeptIds))
                    {
                        beDeptIdArray = beDeptIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    }
                    if (!string.IsNullOrEmpty(beDeptNames))
                    {
                        beDeptNameArray = beDeptNames.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    }
                    ExamineRelation erEnt = ExamineRelation.Find(esdEnt.ExamineRelationId);
                    string          UpLevelCode = ""; string SameLevelCode = ""; string DownLevelCode = "";
                    if (!string.IsNullOrEmpty(erEnt.UpLevelCode))
                    {
                        string[] upArray = erEnt.UpLevelCode.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                        for (int n = 0; n < upArray.Length; n++)
                        {
                            if (n != upArray.Length - 1)
                            {
                                UpLevelCode += "'" + upArray[n] + "',";
                            }
                            else
                            {
                                UpLevelCode += "'" + upArray[n] + "'";
                            }
                        }
                    }
                    if (!string.IsNullOrEmpty(erEnt.SameLevelCode))
                    {
                        string[] sameArray = erEnt.SameLevelCode.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                        for (int n = 0; n < sameArray.Length; n++)
                        {
                            if (n != sameArray.Length - 1)
                            {
                                SameLevelCode += "'" + sameArray[n] + "',";
                            }
                            else
                            {
                                SameLevelCode += "'" + sameArray[n] + "'";
                            }
                        }
                    }
                    if (!string.IsNullOrEmpty(erEnt.DownLevelCode))
                    {
                        string[] downArray = erEnt.DownLevelCode.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                        for (int n = 0; n < downArray.Length; n++)
                        {
                            if (n != downArray.Length - 1)
                            {
                                DownLevelCode += "'" + downArray[n] + "',";
                            }
                            else
                            {
                                DownLevelCode += "'" + downArray[n] + "'";
                            }
                        }
                    }
                    #region 开始计算个人成绩
                    for (int i = 0; i < beUserIdArray.Length; i++)
                    {
                        ExamineStageResult esrEnt = new ExamineStageResult();
                        esrEnt.ExamineStageId = esEnt.Id;
                        esrEnt.BeRoleCode     = esdEnt.BeRoleCode;
                        esrEnt.BeRoleName     = esdEnt.BeRoleName;
                        esrEnt.UserId         = beUserIdArray[i];
                        esrEnt.UserName       = beUserNameArray[i];
                        esrEnt.DeptId         = beDeptIdArray[i];
                        esrEnt.DeptName       = beDeptNameArray[i];
                        esrEnt.StageType      = esEnt.StageType;
                        esrEnt.Year           = esEnt.Year;
                        //分别计算上级  同级  下级评分
                        decimal tempScore = 0; string subBalanceUserIds = ""; int subBalanceWeightTotal = 0;
                        if (esdEnt.BeRoleCode == "BeBusinessDeptLeader")//经营目标单位正职 (有一部分特殊任务)   需要计算特殊分   Tag='1'
                        {
                            sql       = @"select avg(isnull(Score,0)) from BJKY_Examine..ExamineTask where State='2' and ExamineStageId='{0}' and BeRoleCode='{1}'
                            and BeDeptId='{2}' and BeUserId='{3}' and Tag='1'";
                            sql       = string.Format(sql, esEnt.Id, esdEnt.BeRoleCode, beDeptIdArray[i], beUserIdArray[i]);
                            tempScore = DataHelper.QueryValue <decimal>(sql);
                        }
                        if (!string.IsNullOrEmpty(UpLevelCode))//如果有上级考核对象
                        {
                            //因为考核关系有时候需要把级别权重拆分到人分权重   不能单独取所有上级的平均分 //20130430  已更新到如下代码
                            IList <UserBalance> ubEnts = UserBalance.FindAllByProperties("ExamineRelationId", erEnt.Id, "ToRoleCode", "UpLevel");//该考核关系下 上级考核的人员权重明细
                            foreach (UserBalance ubEnt in ubEnts)
                            {
                                if (ubEnt.Balance > 0)
                                {
                                    subBalanceUserIds     += ubEnt.ToUserId + ",";
                                    subBalanceWeightTotal += ubEnt.Balance.Value;
                                }
                            }
                            decimal subScore = 0;
                            if (subBalanceWeightTotal < 100)                                                                                        //如果人员权重没有将100的总权重分配完
                            {
                                sql = @"select avg(isnull(Score,0)) from BJKY_Examine..ExamineTask where State='2' and ExamineStageId='{0}' and BeRoleCode='{1}'
                                and BeDeptId='{2}' and BeUserId='{3}' and ToRoleCode in (" + UpLevelCode + ") and PatIndex('%ToUserId%','{4}')= 0"; //去掉已分配人员权重的人
                                sql = string.Format(sql, esEnt.Id, esdEnt.BeRoleCode, beDeptIdArray[i], beUserIdArray[i], subBalanceUserIds);
                                if (DataHelper.QueryValue <decimal>(sql) > 0)
                                {
                                    foreach (UserBalance ubEnt in ubEnts)
                                    {
                                        if (ubEnt.Balance > 0)
                                        {
                                            sql       = @"select top 1 Score from BJKY_Examine..ExamineTask where State='2' and ExamineStageId='{0}' and BeRoleCode='{1}'
                                            and BeDeptId='{2}' and BeUserId='{3}' and  ToUserId='{4}'";
                                            sql       = string.Format(sql, esEnt.Id, esdEnt.BeRoleCode, beDeptIdArray[i], beUserIdArray[i], ubEnt.ToUserId);
                                            subScore += DataHelper.QueryValue <decimal>(sql) * (ubEnt.Balance.Value / 100);
                                        }
                                    }
                                    esrEnt.UpAvgScore = subScore + (DataHelper.QueryValue <decimal>(sql) * (100 - subBalanceWeightTotal) / 100) + tempScore;
                                }
                                else //如果没有其他的分数,但权重又没有分配完
                                {
                                    foreach (UserBalance ubEnt in ubEnts)
                                    {
                                        if (ubEnt.Balance > 0)
                                        {
                                            sql       = @"select top 1 Score from BJKY_Examine..ExamineTask where State='2' and ExamineStageId='{0}' and BeRoleCode='{1}'
                                            and BeDeptId='{2}' and BeUserId='{3}' and  ToUserId='{4}'";
                                            sql       = string.Format(sql, esEnt.Id, esdEnt.BeRoleCode, beDeptIdArray[i], beUserIdArray[i], ubEnt.ToUserId);
                                            subScore += DataHelper.QueryValue <decimal>(sql) * (ubEnt.Balance.Value / subBalanceWeightTotal);
                                        }
                                    }
                                    esrEnt.UpAvgScore = subScore + tempScore;
                                }
                            }
                            else//如果人员权重已经满100,这个时候不计算已打分但未分配子权重的人员提交的考核任务
                            {
                                esrEnt.UpAvgScore = subScore + tempScore;
                            }
                        }
                        if (!string.IsNullOrEmpty(SameLevelCode))//如果有同级考核对象
                        {
                            sql = @"select avg(isnull(Score,0)) from BJKY_Examine..ExamineTask where State='2' and ExamineStageId='{0}' and BeRoleCode='{1}'
                            and BeDeptId='{2}' and BeUserId='{3}' and ToRoleCode in (" + SameLevelCode + ")";
                            sql = string.Format(sql, esEnt.Id, esdEnt.BeRoleCode, beDeptIdArray[i], beUserIdArray[i]);
                            esrEnt.SameAvgScore = DataHelper.QueryValue <decimal>(sql) + tempScore;
                        }
                        if (!string.IsNullOrEmpty(DownLevelCode))//如果有下级考核对象
                        {
                            sql = @"select avg(isnull(Score,0)) from BJKY_Examine..ExamineTask where State='2' and ExamineStageId='{0}' and BeRoleCode='{1}'
                            and BeDeptId='{2}' and BeUserId='{3}' and ToRoleCode in (" + DownLevelCode + ")";
                            sql = string.Format(sql, esEnt.Id, esdEnt.BeRoleCode, beDeptIdArray[i], beUserIdArray[i]);
                            esrEnt.DownAvgScore = DataHelper.QueryValue <decimal>(sql) + tempScore;
                        }
                        decimal score = 0;
                        //这里需要考虑一种特例就是  权重配好了 但可能没人给他打分   就是有权重  无分的现象  这个时候该权重不计入总权重
                        int upWeight = 0; int sameWeight = 0; int downWeight = 0;
                        if (erEnt.UpLevelWeight > 0 && esrEnt.UpAvgScore > 0)
                        {
                            upWeight = erEnt.UpLevelWeight.Value;
                        }
                        if (erEnt.SameLevelWeight > 0 && esrEnt.SameAvgScore > 0)
                        {
                            sameWeight = erEnt.SameLevelWeight.Value;
                        }
                        if (erEnt.DownLevelWeight > 0 && esrEnt.DownAvgScore > 0)
                        {
                            downWeight = erEnt.DownLevelWeight.Value;
                        }
                        int totalWeight = upWeight + sameWeight + downWeight;
                        if (upWeight > 0 && esrEnt.UpAvgScore > 0)
                        {
                            score += (((decimal)upWeight / (decimal)totalWeight) * esrEnt.UpAvgScore).Value;
                        }
                        if (sameWeight > 0 && esrEnt.SameAvgScore > 0)
                        {
                            score += (((decimal)sameWeight / (decimal)totalWeight) * esrEnt.SameAvgScore).Value;
                        }
                        if (downWeight > 0 && esrEnt.DownAvgScore > 0)
                        {
                            score += (((decimal)downWeight / (decimal)totalWeight) * esrEnt.DownAvgScore).Value;
                        }
                        esrEnt.Score     = score;
                        esrEnt.SortIndex = i + 1;
                        esrEnt.DoCreate();
                    }
                    #endregion
                }
            }
            #endregion
            #region 部门级考核
            else  //部门级考核关联的是部门级考核关系
            {
                foreach (ExamineStageDetail esdEnt in esdEnts)
                {
                    DeptExamineRelation derEnt = DeptExamineRelation.Find(esdEnt.ExamineRelationId);
                    string[]            beUserIdArray = new string[] { }; string[] beUserNameArray = new string[] { };
                    if (!string.IsNullOrEmpty(derEnt.BeUserIds))
                    {
                        beUserIdArray   = derEnt.BeUserIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                        beUserNameArray = derEnt.BeUserNames.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    }
                    for (int i = 0; i < beUserIdArray.Length; i++)
                    {
                        ExamineStageResult esrEnt = new ExamineStageResult();
                        esrEnt.ExamineStageId = esEnt.Id;
                        esrEnt.UserId         = beUserIdArray[i];
                        esrEnt.UserName       = beUserNameArray[i];
                        esrEnt.DeptId         = esEnt.LaunchDeptId;
                        esrEnt.DeptName       = esEnt.LaunchDeptName;
                        esrEnt.StageType      = esEnt.StageType;
                        esrEnt.Year           = esEnt.Year;
                        //分别计算上级  同级  下级评分
                        if (!string.IsNullOrEmpty(derEnt.UpLevelUserIds))//如果有上级考核人
                        {
                            // IList<UserBalance> ubEnts = UserBalance.FindAllByProperties("ExamineRelationId", derEnt.Id, "ToRoleCode", "UpLevel");//该考核关系下 上级考核的人员权重明细
                            decimal subScore = 0;
                            //                            if (ubEnts.Count > 0)//如果存在人员权重
                            //                            {
                            //                                foreach (UserBalance ubEnt in ubEnts)
                            //                                {
                            //                                    if (ubEnt.Balance > 0)
                            //                                    {
                            //                                        sql = @"select top 1 Score from BJKY_Examine..ExamineTask where State='2' and ExamineStageId='{0}'
                            //                                                                        and BeUserId='{1}' and  ToUserId ='{2}'";
                            //                                        sql = string.Format(sql, esEnt.Id, beUserIdArray[i], ubEnt.ToUserId);
                            //                                        subScore += DataHelper.QueryValue<decimal>(sql) * (ubEnt.Balance.Value / 100);
                            //                                    }
                            //                                }
                            //                            }
                            //                            else
                            //                            {
                            sql      = @"select avg(isnull(Score,0)) from BJKY_Examine..ExamineTask where State='2' and ExamineStageId='{0}'  
                                and BeUserId='{1}' and PatIndex('%'+ToUserId+'%','{2}')>0";
                            sql      = string.Format(sql, esEnt.Id, beUserIdArray[i], derEnt.UpLevelUserIds);
                            subScore = DataHelper.QueryValue <decimal>(sql);
                            // }
                            esrEnt.UpAvgScore = subScore;
                        }
                        if (!string.IsNullOrEmpty(derEnt.SameLevelUserIds))//如果有同级考核人
                        {
                            sql = @"select avg(isnull(Score,0)) from BJKY_Examine..ExamineTask where State='2' and ExamineStageId='{0}'  
                            and BeUserId='{1}' and PatIndex('%'+ToUserId+'%','{2}')>0";
                            sql = string.Format(sql, esEnt.Id, beUserIdArray[i], derEnt.SameLevelUserIds);
                            esrEnt.SameAvgScore = DataHelper.QueryValue <decimal>(sql);
                        }
                        if (!string.IsNullOrEmpty(derEnt.DownLevelUserIds))//如果有下级考核人
                        {
                            sql = @"select avg(isnull(Score,0)) from BJKY_Examine..ExamineTask where State='2' and ExamineStageId='{0}'  
                            and BeUserId='{1}' and PatIndex('%'+ToUserId+'%','{2}')>0";
                            sql = string.Format(sql, esEnt.Id, beUserIdArray[i], derEnt.DownLevelUserIds);
                            esrEnt.DownAvgScore = DataHelper.QueryValue <decimal>(sql);
                        }
                        decimal score = 0;
                        //这里需要考虑一种特例就是  权重配好了 但可能没人给他打分   就是有权重  无分的现象  这个时候该权重不计入总权重
                        int upWeight = 0; int sameWeight = 0; int downWeight = 0;
                        if (derEnt.UpLevelWeight > 0 && esrEnt.UpAvgScore > 0)
                        {
                            upWeight = derEnt.UpLevelWeight.Value;
                        }
                        if (derEnt.SameLevelWeight > 0 && esrEnt.SameAvgScore > 0)
                        {
                            sameWeight = derEnt.SameLevelWeight.Value;
                        }
                        if (derEnt.DownLevelWeight > 0 && esrEnt.DownAvgScore > 0)
                        {
                            downWeight = derEnt.DownLevelWeight.Value;
                        }
                        int totalWeight = upWeight + sameWeight + downWeight;
                        if (upWeight > 0 && esrEnt.UpAvgScore > 0)
                        {
                            score += (((decimal)upWeight / (decimal)totalWeight) * esrEnt.UpAvgScore).Value;
                        }
                        if (sameWeight > 0 && esrEnt.SameAvgScore > 0)
                        {
                            score += (((decimal)sameWeight / (decimal)totalWeight) * esrEnt.SameAvgScore).Value;
                        }
                        if (downWeight > 0 && esrEnt.DownAvgScore > 0)
                        {
                            score += (((decimal)downWeight / (decimal)totalWeight) * esrEnt.DownAvgScore).Value;
                        }
                        esrEnt.Score     = score;
                        esrEnt.SortIndex = i + 1;
                        esrEnt.DoCreate();
                    }
                }
            }
            #endregion
            IList <ExamineTask> etEnts = ExamineTask.FindAllByProperty(ExamineTask.Prop_ExamineStageId, esEnt.Id); //更改任务状态
            foreach (ExamineTask etEnt in etEnts)
            {                                                                                                      //0  表示已生成的任务   1  表示已启动的任务 可以打分
                if (etEnt.State == "2")                                                                            //提交的任务
                {
                    etEnt.State = "3";                                                                             //已结束的任务
                }
                else
                {
                    etEnt.State = "4";//已作废的任务
                }
                etEnt.DoUpdate();
            }
            if (esEnt.StageType == "4")
            {
                CaculateYearResult();
            }
            esEnt.State = 3; // 0: '已创建', 1: '已生成', 2: '已启动', 3: '已结束'
            esEnt.DoUpdate();
            PageState.Add("Result", "T");
        }
        private void EndExamine()
        {
            IList <ExamineStageDetail> esdEnts = ExamineStageDetail.FindAllByProperty(ExamineStageDetail.Prop_ExamineStageId, id);

            foreach (ExamineStageDetail esdEnt in esdEnts)
            {
                DeptExamineRelation derEnt = DeptExamineRelation.Find(esdEnt.ExamineRelationId);
                string[]            beUserIdArray = new string[] { }; string[] beUserNameArray = new string[] { };
                if (!string.IsNullOrEmpty(derEnt.BeUserIds))
                {
                    beUserIdArray   = derEnt.BeUserIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    beUserNameArray = derEnt.BeUserNames.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                }
                for (int i = 0; i < beUserIdArray.Length; i++)
                {
                    ExamineStageResult esrEnt = new ExamineStageResult();
                    esrEnt.ExamineStageId = esEnt.Id;
                    esrEnt.UserId         = beUserIdArray[i];
                    esrEnt.UserName       = beUserNameArray[i];
                    string[] bedept = Utility.GetDeptInfo(beUserIdArray[i]);
                    esrEnt.DeptId    = bedept[0];
                    esrEnt.DeptName  = bedept[1];
                    esrEnt.StageType = esEnt.StageType;
                    esrEnt.Year      = esEnt.Year;
                    //分别计算上级  同级  下级评分
                    if (!string.IsNullOrEmpty(derEnt.UpLevelUserIds))//如果有上级考核人
                    {
                        // IList<UserBalance> ubEnts = UserBalance.FindAllByProperties("ExamineRelationId", derEnt.Id, "ToRoleCode", "UpLevel");//该考核关系下 上级考核的人员权重明细
                        decimal subScore = 0;
                        //                            if (ubEnts.Count > 0)//如果存在人员权重
                        //                            {
                        //                                foreach (UserBalance ubEnt in ubEnts)
                        //                                {
                        //                                    if (ubEnt.Balance > 0)
                        //                                    {
                        //                                        sql = @"select top 1 Score from BJKY_Examine..ExamineTask where State='2' and ExamineStageId='{0}'
                        //                                            and BeUserId='{1}' and  ToUserId ='{2}'";
                        //                                        sql = string.Format(sql, esEnt.Id, beUserIdArray[i], ubEnt.ToUserId);
                        //                                        subScore += DataHelper.QueryValue<decimal>(sql) * (ubEnt.Balance.Value / 100);
                        //                                    }
                        //                                }
                        //                            }
                        //                            else
                        //                            {
                        sql      = @"select avg(isnull(Score,0)) from BJKY_Examine..ExamineTask where State='2' and ExamineStageId='{0}'  
                                and BeUserId='{1}' and PatIndex('%'+ToUserId+'%','{2}')>0";
                        sql      = string.Format(sql, esEnt.Id, beUserIdArray[i], derEnt.UpLevelUserIds);
                        subScore = DataHelper.QueryValue <decimal>(sql);
                        // }
                        esrEnt.UpAvgScore = subScore;
                    }
                    if (!string.IsNullOrEmpty(derEnt.SameLevelUserIds))//如果有同级考核人
                    {
                        sql = @"select avg(isnull(Score,0)) from BJKY_Examine..ExamineTask where State='2' and ExamineStageId='{0}'  
                            and BeUserId='{1}' and PatIndex('%'+ToUserId+'%','{2}')>0";
                        sql = string.Format(sql, esEnt.Id, beUserIdArray[i], derEnt.SameLevelUserIds);
                        esrEnt.SameAvgScore = DataHelper.QueryValue <decimal>(sql);
                    }
                    if (!string.IsNullOrEmpty(derEnt.DownLevelUserIds))//如果有下级考核人
                    {
                        sql = @"select avg(isnull(Score,0)) from BJKY_Examine..ExamineTask where State='2' and ExamineStageId='{0}'  
                            and BeUserId='{1}' and PatIndex('%'+ToUserId+'%','{2}')>0";
                        sql = string.Format(sql, esEnt.Id, beUserIdArray[i], derEnt.DownLevelUserIds);
                        esrEnt.DownAvgScore = DataHelper.QueryValue <decimal>(sql);
                    }
                    decimal score = 0;
                    //这里需要考虑一种特例就是  权重配好了 但可能没人给他打分   就是有权重  无分的现象  这个时候该权重不计入总权重
                    int upWeight = 0; int sameWeight = 0; int downWeight = 0;
                    if (derEnt.UpLevelWeight > 0 && esrEnt.UpAvgScore > 0)
                    {
                        upWeight = derEnt.UpLevelWeight.Value;
                    }
                    if (derEnt.SameLevelWeight > 0 && esrEnt.SameAvgScore > 0)
                    {
                        sameWeight = derEnt.SameLevelWeight.Value;
                    }
                    if (derEnt.DownLevelWeight > 0 && esrEnt.DownAvgScore > 0)
                    {
                        downWeight = derEnt.DownLevelWeight.Value;
                    }
                    int totalWeight = upWeight + sameWeight + downWeight;
                    if (upWeight > 0 && esrEnt.UpAvgScore > 0)
                    {
                        score += (((decimal)upWeight / (decimal)totalWeight) * esrEnt.UpAvgScore).Value;
                    }
                    if (sameWeight > 0 && esrEnt.SameAvgScore > 0)
                    {
                        score += (((decimal)sameWeight / (decimal)totalWeight) * esrEnt.SameAvgScore).Value;
                    }
                    if (downWeight > 0 && esrEnt.DownAvgScore > 0)
                    {
                        score += (((decimal)downWeight / (decimal)totalWeight) * esrEnt.DownAvgScore).Value;
                    }
                    esrEnt.Score     = score;
                    esrEnt.SortIndex = i + 1;
                    esrEnt.DoCreate();
                }
            }
            IList <ExamineTask> etEnts = ExamineTask.FindAllByProperty(ExamineTask.Prop_ExamineStageId, esEnt.Id);//更改任务状态

            foreach (ExamineTask etEnt in etEnts)
            {                           //0  表示已生成的任务   1  表示已启动的任务 可以打分
                if (etEnt.State == "2") //提交的任务
                {
                    etEnt.State = "3";  //已结束的任务
                }
                else
                {
                    etEnt.State = "4";//已作废的任务
                }
                etEnt.DoUpdate();
            }
            if (esEnt.StageType == "4")
            {
                CaculateYearResult();
            }
            esEnt.State = 3; // 0: '已创建', 1: '已生成', 2: '已启动', 3: '已结束'
            esEnt.DoUpdate();
            PageState.Add("Result", "T");
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            id = RequestData.Get <string>("id");
            if (!string.IsNullOrEmpty(id))
            {
                esEnt = ExamineStage.Find(id);
            }
            switch (RequestActionString)
            {
            case "UpdatePathLevel":
                IList <SysGroup> sgEnts = SysGroup.FindAll();
                foreach (SysGroup sgEnt in sgEnts)
                {
                    if (!string.IsNullOrEmpty(sgEnt.Path))
                    {
                        string[] array = sgEnt.Path.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries);
                        sgEnt.PathLevel = array.Length;
                        sgEnt.DoUpdate();
                    }
                }
                break;

            case "CreateTask":
                esdEnts = ExamineStageDetail.FindAllByProperty(ExamineStageDetail.Prop_ExamineStageId, id);
                bool allowStart = true;    //确认考核对象  考核关系  考核指标 配置是否齐全
                if (esdEnts.Count == 0)
                {
                    allowStart = false;
                }
                else
                {
                    foreach (ExamineStageDetail esdEnt in esdEnts)
                    {
                        if (string.IsNullOrEmpty(esdEnt.ExamineRelationId) || string.IsNullOrEmpty(esdEnt.ExamineIndicatorId))
                        {
                            allowStart = false; break;
                        }
                    }
                }
                if (allowStart)
                {
                    CreateTask();       //生成考核任务
                    esEnt.State    = 1; //更新考核阶段状态为
                    etEnts         = ExamineTask.FindAllByProperty(ExamineTask.Prop_ExamineStageId, id);
                    esEnt.TaskQuan = etEnts.Count;
                    esEnt.DoUpdate();
                    PageState.Add("Result", "考核任务生成成功!");
                }
                else
                {
                    PageState.Add("Result", "考核任务生成失败!请检查考核对象、考核关系、考核指标是否配置完整!");
                }
                break;

            case "TakeBack":
                etEnts = ExamineTask.FindAllByProperty(ExamineTask.Prop_ExamineStageId, id);
                foreach (ExamineTask etEnt in etEnts)
                {
                    etEnt.DoDelete();
                }
                //删除所有的自定义指标
                sql = "delete BJKY_Examine..CustomIndicator where ExamineStageId='" + id + "'";
                DataHelper.ExecSql(sql);
                esEnt.State    = 0;
                esEnt.TaskQuan = 0;
                esEnt.DoUpdate();
                PageState.Add("Result", "T");
                break;

            case "JudgeCustomIndicator":
                if (esEnt.ExamineType == "部门级考核")
                {
                    sql = @"select A.* from BJKY_Examine..DeptExamineRelation as A left join BJKY_Examine..ExamineStageDetail as B on A.Id=B.ExamineRelationId 
                            where B.ExamineStageId='" + esEnt.Id + "'";//找到部门考核关系里面的所有被考核人  查找他们的自定义指标
                    IList <EasyDictionary> dicsRelation = DataHelper.QueryDictList(sql);
                    string beUserIds = ""; string beUserNames = "";
                    foreach (EasyDictionary dic in dicsRelation)
                    {
                        beUserIds   += dic.Get <string>("BeUserIds") + ",";
                        beUserNames += dic.Get <string>("BeUserNames") + ",";
                    }
                    string[] userIdArray = null;
                    if (!string.IsNullOrEmpty(beUserIds))
                    {
                        userIdArray = beUserIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    }
                    bool allowLaunch = true;
                    for (int i = 0; i < userIdArray.Length; i++)
                    {
                        IList <CustomIndicator> ciEnts = CustomIndicator.FindAllByProperties("CreateId", userIdArray[i], "Year", esEnt.Year, "StageType", esEnt.StageType, "Result", "同意");
                        if (ciEnts.Count == 0)
                        {
                            allowLaunch = false;
                            break;
                        }
                    }
                    PageState.Add("Result", allowLaunch == true ? "T" : "F");
                }
                else
                {
                    PageState.Add("Result", "T");
                }
                break;

            case "Launch":    //生成考核任务
                LaunchExamine();
                break;

            case "CancelLaunch":
                CancelLaunch();
                break;

            case "EndExamine":
                EndExamine();
                break;

            case "delete":
                IList <ExamineStageDeptDetail> esddEnts = ExamineStageDeptDetail.FindAllByProperty(ExamineStageDeptDetail.Prop_ExamineStageId, id);
                foreach (ExamineStageDeptDetail esddEnt in esddEnts)
                {
                    esddEnt.DoDelete();
                }
                esdEnts = ExamineStageDetail.FindAllByProperty(ExamineStageDetail.Prop_ExamineStageId, id);
                foreach (ExamineStageDetail esdEnt in esdEnts)
                {
                    esdEnt.DoDelete();
                }
                esEnt.DoDelete();
                break;

            default:
                DoSelect();
                break;
            }
        }