public JsonResult CheckSave(T_BorrowGoodsApprove model)
        {
            using (TransactionScope sc = new TransactionScope())
            {
                try
                {
                    string name = Server.UrlDecode(Request.Cookies["NickName"].Value);
                    T_BorrowGoodsApprove editModel = db.T_BorrowGoodsApprove.Find(model.ID);
                    editModel.Status      = model.Status;
                    editModel.ApproveTime = DateTime.Now;
                    editModel.ApproveName = name;
                    editModel.Memo        = model.Memo;
                    db.Entry <T_BorrowGoodsApprove>(editModel).State = System.Data.Entity.EntityState.Modified;
                    T_BorrowGoods BorrowModel = db.T_BorrowGoods.Find(editModel.PID);
                    if (model.Status == 1)//同意
                    {
                        int nextStep = editModel.Step + 1;
                        BorrowModel.Step = nextStep;
                        List <T_BorrowGoodsConfig> ConfigList = db.T_BorrowGoodsConfig.Where(a => a.Step == nextStep).ToList();
                        if (ConfigList.Count > 0)//下一步
                        {
                            BorrowModel.Status         = 0;
                            BorrowModel.Step           = nextStep;
                            BorrowModel.CurrentApprove = ConfigList.First().Name;

                            T_BorrowGoodsApprove newApprove = new T_BorrowGoodsApprove();
                            newApprove.ApproveName = ConfigList.First().Name;
                            newApprove.PID         = editModel.PID;
                            newApprove.Status      = -1;
                            newApprove.Step        = nextStep;
                            db.T_BorrowGoodsApprove.Add(newApprove);
                        }
                        else//结束
                        {
                            BorrowModel.Status = 1;
                            BorrowModel.Step   = 99;
                        }
                    }
                    else//不同意结束
                    {
                        BorrowModel.Status = 2;
                        BorrowModel.Step   = 99;
                    }
                    db.Entry <T_BorrowGoods>(BorrowModel).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 ViewApply()
        {
            string name = Server.UrlDecode(Request.Cookies["NickName"].Value);

            ViewData["ApproveList"] = getApproveName(1);
            T_BorrowGoods model = new T_BorrowGoods();
            T_User        user  = db.T_User.FirstOrDefault(a => a.Nickname == name);

            model.PostUser   = name;
            model.Dept       = Com.GetDepartmentName(Convert.ToInt32(user.DepartmentId));
            model.ReturnDate = DateTime.Now;

            return(View(model));
        }
 public JsonResult Delete(int ID)
 {
     try
     {
         T_BorrowGoods delModel = db.T_BorrowGoods.Find(ID);
         delModel.IsDelete = 1;
         db.Entry <T_BorrowGoods>(delModel).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception e)
     {
         return(Json(new { State = "Faile", Message = e.Message }, JsonRequestBehavior.AllowGet));
     }
 }
        public ActionResult ViewEdit(int ID)
        {
            ViewData["ID"] = ID;
            T_BorrowGoods model = db.T_BorrowGoods.Find(ID);

            ViewData["ApproveList"] = getApproveName(1);
            if (model != null)
            {
                return(View(model));
            }
            else
            {
                return(HttpNotFound());
            }
        }
        public JsonResult EditSave(T_BorrowGoods model, string jsonStr)
        {
            using (TransactionScope sc = new TransactionScope())
            {
                try
                {
                    T_BorrowGoods editModel = db.T_BorrowGoods.Find(model.ID);
                    editModel.CurrentApprove = model.CurrentApprove;
                    db.Entry <T_BorrowGoods>(editModel).State = System.Data.Entity.EntityState.Modified;
                    List <T_BorrowGoodsDetail> details = Com.Deserialize <T_BorrowGoodsDetail>(jsonStr);
                    // editModel.CurrentApprove = model.CurrentApprove;
                    foreach (T_BorrowGoodsDetail item in details)
                    {
                        T_BorrowGoodsDetail editDetail = db.T_BorrowGoodsDetail.Find(item.ID);

                        editDetail.GoodsCode = item.GoodsCode;
                        editDetail.GoodsName = item.GoodsName;
                        editDetail.qty       = item.qty;

                        db.Entry <T_BorrowGoodsDetail>(editDetail).State = System.Data.Entity.EntityState.Modified;
                    }


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

                        T_BorrowGoodsApprove Approvemodel = new T_BorrowGoodsApprove();
                        Approvemodel.Status      = -1;
                        Approvemodel.ApproveName = editModel.CurrentApprove;
                        Approvemodel.Memo        = "";
                        Approvemodel.PID         = model.ID;
                        Approvemodel.Step        = 1;
                        db.T_BorrowGoodsApprove.Add(Approvemodel);
                    }


                    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 ApplySave(T_BorrowGoods model, string jsonStr)
        {
            using (TransactionScope sc = new TransactionScope())
            {
                try
                {
                    string nickName = Server.UrlDecode(Request.Cookies["NickName"].Value);
                    List <T_BorrowGoodsDetail> details = Com.Deserialize <T_BorrowGoodsDetail>(jsonStr);
                    //主表保存
                    model.PostTime = DateTime.Now;
                    model.Status   = -1;
                    model.Step     = 1;
                    model.IsDelete = 0;
                    // model.CurrentApprove = "游神";
                    model.PostUser = nickName;
                    db.T_BorrowGoods.Add(model);
                    int i = db.SaveChanges();
                    if (i > 0)
                    {
                        T_BorrowGoodsApprove Approvemodel = new T_BorrowGoodsApprove();
                        Approvemodel.Status      = -1;
                        Approvemodel.ApproveName = model.CurrentApprove;
                        Approvemodel.Memo        = "";
                        Approvemodel.PID         = model.ID;
                        Approvemodel.Step        = 1;
                        db.T_BorrowGoodsApprove.Add(Approvemodel);
                        foreach (T_BorrowGoodsDetail item in details)
                        {
                            item.Pid = model.ID;
                            db.T_BorrowGoodsDetail.Add(item);
                        }

                        db.SaveChanges();

                        sc.Complete();
                        return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet));
                    }
                    return(Json(new { State = "Faile", Message = "保存失败" }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    return(Json(new { State = "Faile", Message = ex.Message }, JsonRequestBehavior.AllowGet));
                }
            }
        }