public JsonResult SecurityCodeApp(T_SecurityCode model) { string Nickname = Server.UrlDecode(Request.Cookies["Nickname"].Value); model.ApplyName = Nickname; model.ApplyDate = DateTime.Now; model.Status = -1; model.Step = 0; model.Isdelete = 0; db.T_SecurityCode.Add(model); int i = db.SaveChanges(); if (i > 0) { T_SecurityCodeConfig modelconfig = db.T_SecurityCodeConfig.SingleOrDefault(a => a.Step == 0 && a.Reason == "1"); T_SecurityCodeAppRove AppRoveModel = new T_SecurityCodeAppRove(); AppRoveModel.Status = -1; AppRoveModel.Step = "0"; if (modelconfig.Name == null || modelconfig.Name == "") { AppRoveModel.ApproveName = modelconfig.Type; } else { AppRoveModel.ApproveName = modelconfig.Name; } AppRoveModel.ApproveDName = modelconfig.Type; AppRoveModel.Oid = model.ID; db.T_SecurityCodeAppRove.Add(AppRoveModel); db.SaveChanges(); return(Json(i, JsonRequestBehavior.AllowGet)); } else { return(Json(i, JsonRequestBehavior.AllowGet)); } }
//审核 public JsonResult SecurityCodeCheck(T_SecurityCode model, string status, string Memo) { using (TransactionScope sc = new TransactionScope()) { int ID = model.ID; T_SecurityCode Invoicemodel = db.T_SecurityCode.SingleOrDefault(a => a.ID == ID && a.Isdelete == 0); if (Invoicemodel == null) { return(Json("数据可能被删除", JsonRequestBehavior.AllowGet)); } T_SecurityCodeAppRove modelApprove = db.T_SecurityCodeAppRove.FirstOrDefault(a => a.Oid == ID && a.ApproveTime == null); string Nickname = Server.UrlDecode(Request.Cookies["Nickname"].Value); string result = ""; modelApprove.ApproveName = Nickname; modelApprove.Memo = Memo; modelApprove.ApproveTime = DateTime.Now; modelApprove.Status = int.Parse(status); db.Entry <T_SecurityCodeAppRove>(modelApprove).State = System.Data.Entity.EntityState.Modified; int i = db.SaveChanges(); if (i > 0) { if (status == "1") { T_SecurityCodeAppRove newApprove = new T_SecurityCodeAppRove(); int step = int.Parse(Invoicemodel.Step.ToString()); step++; IQueryable <T_SecurityCodeConfig> config = db.T_SecurityCodeConfig.AsQueryable(); int stepLength = config.Count();//总共步骤 if (step < stepLength) { Invoicemodel.Status = 0; T_SecurityCodeConfig stepMod = db.T_SecurityCodeConfig.SingleOrDefault(a => a.Step == step); string nextName = stepMod.Name; newApprove.Memo = ""; newApprove.Oid = ID; newApprove.Status = -1; newApprove.Step = step.ToString(); if (nextName != null) { newApprove.ApproveName = nextName; newApprove.ApproveDName = stepMod.Type; } else { newApprove.ApproveName = stepMod.Type; newApprove.ApproveDName = stepMod.Type; } db.T_SecurityCodeAppRove.Add(newApprove); db.SaveChanges(); } else { Invoicemodel.Status = int.Parse(status); } Invoicemodel.Step = step; db.Entry <T_SecurityCode>(Invoicemodel).State = System.Data.Entity.EntityState.Modified; int j = db.SaveChanges(); if (j > 0) { result = "保存成功"; } else { result = "保存失败"; } } else { //不同意 Invoicemodel.Step = 0; Invoicemodel.Status = 2; db.Entry <T_SecurityCode>(Invoicemodel).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); //审核流程结束 申请人编辑后插入下一条记录 result = "保存成功"; } } else { result = "保存失败"; } sc.Complete(); return(Json(result, JsonRequestBehavior.AllowGet)); } }