public ActionResult UpdateInfo(string ID, int ShiDe = -1, int BossScore = -1, int SuperScore = -1, int StuScore = -1, int DutyTime = -1, int beLate = -1, int didnotShowup = -1, int DepartWork = -1)
        {
            if (ShiDe == -1)
            {
                return(UpdateInfo(ID));
            }
            TeacherRewardEntities db = new TeacherRewardEntities();
            var thisTeacherInfo      = db.TeacherInfo.SingleOrDefault(x => x.ID == ID);

            //计算分值
            thisTeacherInfo.ShiDe       = Cal_PerformScore(ShiDe);
            thisTeacherInfo.BossScore   = Cal_PerformScore(BossScore);
            thisTeacherInfo.SuperScore  = Cal_PerformScore(SuperScore);
            thisTeacherInfo.StuScore    = Cal_PerformScore(StuScore);
            thisTeacherInfo.DutyTime    = Cal_DutyTimeScore(DutyTime);
            thisTeacherInfo.Showup      = Cal_ShowupScore(beLate, didnotShowup);
            thisTeacherInfo.DepartWorks = Cal_DepartWorkScore(DepartWork);

            try {
                db.SaveChanges();
                return(RedirectToAction("PostInfo", "Admin"));
            } catch (Exception) {
                return(RedirectToAction("Error", "Admin"));
            } finally {
                db.Dispose();
            }
        }
        /// <summary>
        /// 以下get函数为DropdownList准备字典
        /// </summary>
        ///
        private void getDepartmentList()
        {
            TeacherRewardEntities    db  = new TeacherRewardEntities();
            Dictionary <int, string> dic = new Dictionary <int, string> {
                { 0, "全部" }
            };
            var departs = db.Department.Select(x => x);

            foreach (var i in departs)
            {
                dic.Add(i.ID, i.Name);
            }
            ViewBag.Department     = dic;
            ViewBag.SearchByDepart = new SelectList(dic, "Key", "Value");
            db.Dispose();
        }
        /// <summary>
        /// 获取当前用户的用户信息和部门信息
        /// </summary>
        private void CommonWork()
        {
            TeacherRewardEntities db = new TeacherRewardEntities();

            string userID = Session["userID"].ToString();

            this.userDetails = db.Users.Where(x => x.ID == userID).FirstOrDefault();

            int userdp = this.userDetails.Department;

            this.userDepart = db.Department.Where(x => x.ID == userdp).FirstOrDefault();

            ViewBag.curUserID   = this.userDetails.ID.ToString();
            ViewBag.curUserName = this.userDetails.Name.ToString();
            ViewBag.userDepart  = this.userDepart.Name.ToString();

            db.Dispose();
        }
        public ActionResult Select(string ID = null, int isSelect = -1)
        {
            if (ID == null || isSelect == -1)
            {
                return(RedirectToAction("Error", "Admin"));
            }
            TeacherRewardEntities db = new TeacherRewardEntities();
            var thisTeacherScore     = db.TeacherScore.Single(x => x.ID == ID);

            thisTeacherScore.isSelected = isSelect == 1 ? true : false;
            try {
                db.SaveChanges();
                return(RedirectToAction("ShowAll", "Admin"));
            } catch (Exception) {
                return(RedirectToAction("Error", "Admin"));
            } finally {
                db.Dispose();
            }
        }
 public ActionResult ChangePwd(Users user)
 {
     CommonWork();
     if (this.userDetails.Password != user.Password)
     {
         user.ErrMsg = "原密码输入错误";
         return(View(user));
     }
     using (TeacherRewardEntities db = new TeacherRewardEntities()) {
         var updateuser = db.Users.Single(x => x.ID == userDetails.ID);
         updateuser.Password = user.NewPassword;
         try {
             db.Configuration.ValidateOnSaveEnabled = false;
             db.SaveChanges();
             db.Configuration.ValidateOnSaveEnabled = true;
             return(RedirectToAction("Logout", "Login"));
         } catch (Exception) {
             db.Dispose();
             return(RedirectToAction("Index", "Home"));
         }
     }
 }
        public ActionResult CalFinalScore(int Affirm = -1)
        {
            int res = Check();

            if (res == 1)
            {
                return(RedirectToAction("Index", "Login"));
            }
            else if (res == 2)
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                CommonWork();
                TeacherRewardEntities db = new TeacherRewardEntities();
                //检查
                if (db.TeacherScore.Where(x => x.Depart == userDetails.Department).Count() == 0)
                {
                    ViewBag.ReadyStatus = 0;                    //没有教师填写信息
                }
                else if (db.TeacherInfo.Where(x => x.DutyTime == 0 && x.Depart == userDetails.Department).Count() != 0)
                {
                    ViewBag.ReadyStatus = 1;                    //存在主任未评分的教师信息
                }
                else if (db.TeacherScore.Where(x => x.Depart == userDetails.Department).Count() != db.Users.Where(x => x.Department == userDetails.Department && x.isAdmin == false).Count())
                {
                    ViewBag.ReadyStatus = 2;                                                                             //本系内部分教师未填写信息
                }
                else if (db.TeacherScore.Where(x => x.KPIScore == 0 && x.Depart == userDetails.Department).Count() == 0) //已经评分完毕
                {
                    ViewBag.ReadyStatus = 3;
                }
                else
                {
                    ViewBag.ReadyStatus = 4;
                }

                if (Affirm == -1)
                {
                    return(View());
                }
                else
                {
                    string[] HighScores   = getHighSocores();
                    var      TeacherInfos = db.TeacherInfo.Where(x => x.Depart == userDetails.Department);
                    foreach (TeacherInfo each in TeacherInfos)
                    {
                        var thisTeacherScore = db.TeacherScore.Single(x => x.ID == each.ID);
                        thisTeacherScore.KPIScore   = Cal_KPIScore(each, HighScores);
                        thisTeacherScore.CPIScore   = Cal_CPIScore(each, HighScores);
                        thisTeacherScore.FinalScore = thisTeacherScore.KPIScore + thisTeacherScore.CPIScore;
                    }
                    try {
                        db.SaveChanges();
                        return(RedirectToAction("Success", "Admin"));
                    } catch (Exception) {
                        return(RedirectToAction("Error", "Admin"));
                    } finally {
                        db.Dispose();
                    }
                }
            }
        }
        public ActionResult CalFinalScore(int Affirm = -1)
        {
            int res = Check();

            if (res == 1)
            {
                return(RedirectToAction("Index", "Login"));
            }
            else if (res == 2)
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                CommonWork();
                TeacherRewardEntities db = new TeacherRewardEntities();
                //检查
                if (db.TeacherScore.Where(x => x.Depart == userDetails.Department).Count() == 0)
                {
                    ViewBag.ReadyStatus = 0;                    //没有教师填写信息
                }
                else if (db.TeacherInfo.Where(x => x.DutyTime == 0 && x.Depart == userDetails.Department).Count() != 0)
                {
                    ViewBag.ReadyStatus = 1;                    //存在主任未评分的教师信息
                }
                else if (db.TeacherScore.Where(x => x.Depart == userDetails.Department).Count() != db.Users.Where(x => x.Department == userDetails.Department && x.isAdmin == false).Count())
                {
                    ViewBag.ReadyStatus = 2;                                                                             //本系内部分教师未填写信息
                }
                else if (db.TeacherScore.Where(x => x.KPIScore == 0 && x.Depart == userDetails.Department).Count() == 0) //已经评分完毕
                {
                    ViewBag.ReadyStatus = 3;
                }
                else
                {
                    ViewBag.ReadyStatus = 4;
                }

                if (Affirm == -1)
                {
                    return(View());
                }
                else
                {
                    string[] HighScores   = getHighSocores();                                              //当前最高分数
                    var      TeacherInfos = db.TeacherInfo.Where(x => x.Depart == userDetails.Department); //分数表
                    var      Vetos        = db.Veto.Select(x => x);                                        //否决表
                    var      Deductions   = db.Deduction.Select(x => x);                                   //减分表

                    foreach (TeacherInfo each in TeacherInfos)
                    {
                        if (Vetos.Where(x => x.ID == each.ID).Any())                           //被否决的教师不算分
                        {
                            continue;
                        }
                        double DeductionScore = 0;
                        if (Deductions.Where(x => x.ID == each.ID).Any())
                        {
                            var this_unfortunate_teacher = Deductions.Where(x => x.ID == each.ID).FirstOrDefault();
                            DeductionScore = Cal_DeductionScore(this_unfortunate_teacher);
                        }
                        var thisTeacherScore = db.TeacherScore.Single(x => x.ID == each.ID);
                        thisTeacherScore.KPIScore   = Cal_KPIScore(each, HighScores);
                        thisTeacherScore.CPIScore   = Cal_CPIScore(each, HighScores);
                        thisTeacherScore.FinalScore = thisTeacherScore.KPIScore + thisTeacherScore.CPIScore - DeductionScore;
                    }

                    try {
                        db.SaveChanges();
                        return(RedirectToAction("Success", "Admin"));
                    } catch (Exception) {
                        return(RedirectToAction("Error", "Admin"));
                    } finally {
                        db.Dispose();
                    }
                }
            }
        }
        public ActionResult Submit(AllInfo form, int Project1Level, int Project2Level, int Project3Level, int Project4Level, int Task1Level, int Task2Level, int Task3Level, int Task4Level, int CTask, int Task1, int Task2, int Task3, int Task4, int PThesisLevel1, int PThesisLevel2, int PThesisLevel3, int PThesisLevel4, int PThesis1, int PThesis2, int PThesis3, int PThesis4, int TeachingAward, int TeachThesis1Type, int TeachThesis2Type, int TeachThesis3Type, int TeachThesis4Type, int TeachThesis1, int TeachThesis2, int TeachThesis3, int TeachThesis4, int Project1, int Project2, int Project3, int Project4, int PrizeLevel1, int PrizeLevel2, int PrizeLevel3, int PrizeLevel4, int Prize1, int Prize2, int Prize3, int Prize4)
        {
            CommonWork();
            getListsReady();

            //计算各分值
            int[] TeachingTimeScore = Cal_TeachingTimeScore(Convert.ToInt32(form.TInfo.baseTeachingTime));
            int   PrizeScore        = Cal_PrizeScore(new int[] { Prize1, Prize2, Prize3, Prize4 }, new int[] { PrizeLevel1, PrizeLevel2, PrizeLevel3, PrizeLevel4 });

            double[] ProjectScore       = Cal_ProjectScore(new int[] { Project1, Project2, Project3, Project4 });
            int[]    TeachThesisScore   = Cal_TeachThesisScore(new int[] { TeachThesis1, TeachThesis2, TeachThesis3, TeachThesis4 }, new int[] { TeachThesis1Type, TeachThesis2Type, TeachThesis3Type, TeachThesis4Type });
            int      TeachingAwardScore = Cal_TeachingAwardScore(TeachingAward);

            double[] PublishThesisScore = Cal_PublishThesisScore(new int[] { PThesisLevel1, PThesisLevel2, PThesisLevel3, PThesisLevel4 }, new int[] { PThesis1, PThesis2, PThesis3, PThesis4 });
            double[] TaskScore          = Cal_TaskScore(new int[] { Task1, Task2, Task3, Task4 });
            double   CrosswiseTaskScore = Cal_CrosswiseTaskScore(CTask);

            //竞赛、项目、教学论文/教材、发表论文、纵向课题、横向课题的详细信息
            putPrizeInfo(ref form, new int[] { Prize1, Prize2, Prize3, Prize4 }, new int[] { PrizeLevel1, PrizeLevel2, PrizeLevel3, PrizeLevel4 });
            putProjectInfo(ref form, new int[] { Project1, Project2, Project3, Project4 }, new int[] { Project1Level, Project2Level, Project3Level, Project4Level });
            putTeachThesisInfo(ref form, new int[] { TeachThesis1, TeachThesis2, TeachThesis3, TeachThesis4 }, new int[] { TeachThesis1Type, TeachThesis2Type, TeachThesis3Type, TeachThesis4Type });
            putPublishThesisInfo(ref form, new int[] { PThesis1, PThesis2, PThesis3, PThesis4 }, new int[] { PThesisLevel1, PThesisLevel2, PThesisLevel3, PThesisLevel4 });
            putTaskInfo(ref form, new int[] { Task1, Task2, Task3, Task4 }, new int[] { Task1Level, Task2Level, Task3Level, Task4Level });
            putCrosswiseTaskInfo(ref form, CTask);
            form.TCTask.ID = form.TPrize.ID = form.TProject.ID = form.TPThesis.ID = form.TTask.ID = form.TTThesis.ID = userDetails.ID;

            TeacherRewardEntities db = new TeacherRewardEntities();
            //新数据
            TeacherInfo              insertion            = new TeacherInfo();
            TeacherScore             newScore             = new TeacherScore();
            TeacherPrizeInfo         newPrizeInfo         = new TeacherPrizeInfo();
            TeacherProjectInfo       newProjectInfo       = new TeacherProjectInfo();
            TeacherTeachThesisInfo   newTeachThesisInfo   = new TeacherTeachThesisInfo();
            TeacherPublishThesisInfo newPublishThesisInfo = new TeacherPublishThesisInfo();
            TeacherTaskInfo          newTaskInfo          = new TeacherTaskInfo();
            TeacherCrosswiseTaskInfo newCTaskInfo         = new TeacherCrosswiseTaskInfo();
            //重新提交数据
            var curTeacherInfo = db.TeacherInfo.Where(x => x.ID == userDetails.ID).FirstOrDefault();
            var curPrizeInfo   = db.TeacherPrizeInfo.Where(x => x.ID == userDetails.ID).FirstOrDefault();
            var curProjectInfo = db.TeacherProjectInfo.Where(x => x.ID == userDetails.ID).FirstOrDefault();
            var curTThesisInfo = db.TeacherTeachThesisInfo.Where(x => x.ID == userDetails.ID).FirstOrDefault();
            var curPThesisInfo = db.TeacherPublishThesisInfo.Where(x => x.ID == userDetails.ID).FirstOrDefault();
            var curTaskInfo    = db.TeacherTaskInfo.Where(x => x.ID == userDetails.ID).FirstOrDefault();
            var curCTaskInfo   = db.TeacherCrosswiseTaskInfo.Where(x => x.ID == userDetails.ID).FirstOrDefault();

            if (curTeacherInfo != null)
            {
                curTeacherInfo.baseTeachingTime  = TeachingTimeScore[0];
                curTeacherInfo.extTeachingTime   = TeachingTimeScore[1];
                curTeacherInfo.Prize             = PrizeScore;
                curTeacherInfo.baseProject       = ProjectScore[0];
                curTeacherInfo.extProject        = ProjectScore[1];
                curTeacherInfo.baseTeachThesis   = TeachThesisScore[0];
                curTeacherInfo.extTeachThesis    = TeachThesisScore[1];
                curTeacherInfo.TeachingAward     = TeachingAwardScore;
                curTeacherInfo.basePublishThesis = PublishThesisScore[0];
                curTeacherInfo.extPublishThesis  = PublishThesisScore[1];
                curTeacherInfo.baseTask          = TaskScore[0];
                curTeacherInfo.extTask           = TaskScore[1];
                curTeacherInfo.CrosswiseTask     = CrosswiseTaskScore;

                curPrizeInfo   = form.TPrize;
                curProjectInfo = form.TProject;
                curTThesisInfo = form.TTThesis;
                curPThesisInfo = form.TPThesis;
                curTaskInfo    = form.TTask;
                curCTaskInfo   = form.TCTask;
            }
            else
            {
                insertion.ID                = userDetails.ID;
                insertion.Name              = userDetails.Name;
                insertion.Depart            = userDepart.ID;
                insertion.baseTeachingTime  = TeachingTimeScore[0];
                insertion.extTeachingTime   = TeachingTimeScore[1];
                insertion.Prize             = PrizeScore;
                insertion.baseProject       = ProjectScore[0];
                insertion.extProject        = ProjectScore[1];
                insertion.baseTeachThesis   = TeachThesisScore[0];
                insertion.extTeachThesis    = TeachThesisScore[1];
                insertion.TeachingAward     = TeachingAwardScore;
                insertion.basePublishThesis = PublishThesisScore[0];
                insertion.extPublishThesis  = PublishThesisScore[1];
                insertion.baseTask          = TaskScore[0];
                insertion.extTask           = TaskScore[1];
                insertion.CrosswiseTask     = CrosswiseTaskScore;

                newScore.ID         = userDetails.ID;
                newScore.Name       = userDetails.Name;
                newScore.Depart     = userDepart.ID;
                newScore.isSelected = false;

                newCTaskInfo         = form.TCTask;
                newPrizeInfo         = form.TPrize;
                newProjectInfo       = form.TProject;
                newTeachThesisInfo   = form.TTThesis;
                newPublishThesisInfo = form.TPThesis;
                newTaskInfo          = form.TTask;
            }
            //写入数据库
            try {
                if (curTeacherInfo == null)                   //如果没有旧条目,则添加新条目
                {
                    db.TeacherInfo.Add(insertion);
                    db.TeacherScore.Add(newScore);
                    db.TeacherPrizeInfo.Add(newPrizeInfo);
                    db.TeacherProjectInfo.Add(newProjectInfo);
                    db.TeacherPublishThesisInfo.Add(newPublishThesisInfo);
                    db.TeacherTeachThesisInfo.Add(newTeachThesisInfo);
                    db.TeacherTaskInfo.Add(newTaskInfo);
                    db.TeacherCrosswiseTaskInfo.Add(newCTaskInfo);
                }
                db.SaveChanges();
                return(RedirectToAction("Success", "Home"));
            } catch (Exception) {
                return(RedirectToAction("Error", "Home"));
            } finally {
                db.Dispose();
            }
        }