public JsonResult PersonnelPayRaiseApplySave(T_PersonnelPayRaise model)
        {
            using (TransactionScope sc = new TransactionScope())
            {
                try
                {
                    string approveName = db.T_PersonnelPayRaiseConfig.First(a => a.Step == 1).Name;
                    model.PostTime = DateTime.Now;
                    model.Status   = -1;
                    model.Step     = 1;
                    //model.CurrentApproveName = approveName;
                    model.PostUser = UserModel.Nickname;
                    model.isDelete = 0;
                    db.T_PersonnelPayRaise.Add(model);
                    db.SaveChanges();

                    T_PersonnelPayRaiseApprove newApprove = new T_PersonnelPayRaiseApprove();
                    newApprove.ApproveName = model.CurrentApproveName;
                    newApprove.PID         = model.ID;
                    newApprove.Status      = 0;
                    newApprove.Step        = 1;
                    db.T_PersonnelPayRaiseApprove.Add(newApprove);
                    db.SaveChanges();
                    sc.Complete();
                    return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception e)
                {
                    return(Json(new { State = "Faile", Message = e.Message }, JsonRequestBehavior.AllowGet));
                }
            }
        }
        public JsonResult PayRaiseEditSave(T_PersonnelPayRaise model)
        {
            using (TransactionScope sc = new TransactionScope())
            {
                try
                {
                    T_PersonnelPayRaise editModel = db.T_PersonnelPayRaise.Find(model.ID);
                    editModel.PresentSalary = model.PresentSalary;
                    editModel.PayRaise      = model.PayRaise;
                    editModel.Reason        = model.Reason;

                    if (editModel.Status == 2)
                    {
                        editModel.Status = -1;
                        editModel.Step   = 1;

                        T_PersonnelPayRaiseApprove newApprove = new T_PersonnelPayRaiseApprove();
                        newApprove.ApproveName = db.T_PersonnelPayRaiseApprove.FirstOrDefault(a => a.PID == editModel.ID && a.Step == 1).ApproveName; //db.T_PersonnelTransferConfig.First(a => a.Step == editModel.Step).Name;
                        newApprove.PID         = model.ID;
                        newApprove.Status      = 0;
                        newApprove.Step        = 1;
                        db.T_PersonnelPayRaiseApprove.Add(newApprove);
                    }


                    db.SaveChanges();
                    sc.Complete();
                    return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception e)
                {
                    return(Json(new { State = "Faile", Message = e.Message }, JsonRequestBehavior.AllowGet));
                }
            }
        }
        public JsonResult PayRaiseCheckSave(T_PersonnelPayRaiseApprove model)
        {
            using (TransactionScope sc = new TransactionScope())
            {
                try
                {
                    string name = Server.UrlDecode(Request.Cookies["NickName"].Value);
                    T_PersonnelPayRaiseApprove editModel = db.T_PersonnelPayRaiseApprove.Find(model.ID);
                    editModel.Status      = model.Status;
                    editModel.ApproveTime = DateTime.Now;
                    editModel.ApproveName = name;
                    editModel.Memo        = model.Memo;
                    db.Entry <T_PersonnelPayRaiseApprove>(editModel).State = System.Data.Entity.EntityState.Modified;
                    T_PersonnelPayRaise PayRaiseModel = db.T_PersonnelPayRaise.Find(editModel.PID);
                    if (model.Status == 1)//同意
                    {
                        int nextStep = editModel.Step + 1;
                        List <T_PersonnelPayRaiseConfig> ConfigList = db.T_PersonnelPayRaiseConfig.Where(a => a.Step == nextStep).ToList();
                        if (ConfigList.Count > 0)//下一步
                        {
                            PayRaiseModel.Status             = 0;
                            PayRaiseModel.Step               = nextStep;
                            PayRaiseModel.CurrentApproveName = ConfigList.First().Name;
                            T_PersonnelPayRaiseApprove newApprove = new T_PersonnelPayRaiseApprove();
                            newApprove.ApproveName = ConfigList.First().Name;
                            newApprove.PID         = editModel.PID;
                            newApprove.Status      = 0;
                            newApprove.Step        = nextStep;
                            db.T_PersonnelPayRaiseApprove.Add(newApprove);
                        }
                        else//结束
                        {
                            T_PersonnelFile person = db.T_PersonnelFile.Find(PayRaiseModel.PFID);
                            person.Salary = PayRaiseModel.PayRaise;
                            db.Entry <T_PersonnelFile>(person).State = System.Data.Entity.EntityState.Modified;   //修改档案表T_PersonnelFile薪资信息

                            PayRaiseModel.CurrentApproveName = "";
                            PayRaiseModel.Status             = 1;
                            PayRaiseModel.Step = 99;
                        }
                    }
                    else//不同意结束
                    {
                        PayRaiseModel.CurrentApproveName = "";
                        PayRaiseModel.Status             = 2;
                        PayRaiseModel.Step = 99;
                    }
                    db.Entry <T_PersonnelPayRaise>(PayRaiseModel).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    sc.Complete();
                    return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception e)
                {
                    return(Json(new { State = "Faile", Message = e.Message }, JsonRequestBehavior.AllowGet));
                }
            }
        }
        public ActionResult ViewCheck(int PID)
        {
            T_PersonnelPayRaiseApprove model = db.T_PersonnelPayRaiseApprove.FirstOrDefault(a => a.PID == PID && a.Status == 0);

            if (model != null)
            {
                return(View(model));
            }
            else
            {
                return(HttpNotFound());
            }
        }