public ActionResult AddContract(Contract model) { try { if (ModelState.IsValid == false) return View(); bool isok = CheckContractData(model); if (isok == false) return View(); ContractMvcWeb.Models.ContractContext dbContext = new Models.ContractContext(); bool isExist = dbContext.ExistContractBySeqAndprojectNum( model.seq , model.projectnum ); if (isExist) { ModelState.AddModelError("e1", "序号和项目编号已经存在,操作失败。"); return View(); } model.createtime = DateTime.Now; model.modifytime = model.createtime; model.operatorName = Request.RequestContext.HttpContext.User.Identity.Name; //model.operatorId = bool result = dbContext.AddContract(model); if (result == false) { ModelState.AddModelError("e2", "新增失败。"); return View(); } return new RedirectResult("~/contract/contractlist"); } catch (Exception ex) { ModelState.AddModelError("e3", ex.Message); return View(); } }
//protected Contract GetNextContract(int contractid, long modifytime) //{ // ContractMvcWeb.Models.ContractContext dbContext = new Models.ContractContext(); // dbContext.get //} protected JsonResult AddContract(Contract model) { JsonResult json = null; if (model == null) { json = new JsonResult(); json.Data = new Models.Result((int)Models.ResultCodeEnum.Error, "参数错误", ""); return json; } if (string.IsNullOrEmpty(model.contractnum)) { json = new JsonResult(); json.Data = new Models.Result((int)Models.ResultCodeEnum.Error, "合同编号不能空", ""); return json; } if (string.IsNullOrEmpty(model.seq)) { json = new JsonResult(); json.Data = new Models.Result((int)Models.ResultCodeEnum.Error, "序号不能空",""); return json; } if (string.IsNullOrEmpty(model.projectnum)) { json = new JsonResult(); json.Data = new Models.Result((int)Models.ResultCodeEnum.Error, "项目编号不能空", ""); return json; } if (string.IsNullOrEmpty(model.projectname)) { json = new JsonResult(); json.Data = new Models.Result((int)Models.ResultCodeEnum.Error, "项目名称不能空", ""); return json; } decimal fbys = 0; if (string.IsNullOrEmpty(model.packageBudget)) { model.packageBudget = "0.00"; } if (decimal.TryParse(model.packageBudget, out fbys) == false) { json = new JsonResult(); json.Data = new Models.Result((int)Models.ResultCodeEnum.Error, "分包预算必须是数字", ""); return json; } if (string.IsNullOrEmpty(model.money)) { model.money = "0.00"; } decimal zbje = 0; if (decimal.TryParse(model.money, out zbje) == false) { json = new JsonResult(); json.Data = new Models.Result((int)Models.ResultCodeEnum.Error, "中标金额必须是数字", ""); return json; } ContractMvcWeb.Models.ContractContext dbContext = new Models.ContractContext(); bool isExist = dbContext.ExistContractBySeqAndprojectNum(model.seq, model.projectnum); //dbContext.ExistContract(model.projectnum, model.projectname); if (isExist) { Models.Result result = new Models.Result((int)Models.ResultCodeEnum.Error, "序号和项目编号已经存在,操作失败。", ""); json = new JsonResult(); json.Data = result; return json; } if (string.IsNullOrEmpty(model.contractrfid) == false) { isExist = dbContext.ExistContract(model.contractrfid); if (isExist) { Models.Result result = new Models.Result((int)Models.ResultCodeEnum.Error, "标签已经被使用,操作失败。", ""); json = new JsonResult(); json.Data = result; return json; } } model.createtime = DateTime.Now; model.modifytime = model.createtime; model.operatorName = Request.RequestContext.HttpContext.User.Identity.Name; //model.operatorId = bool isok = dbContext.AddContract(model); if ( isok == false ) { Models.Result result = new Models.Result((int)Models.ResultCodeEnum.Error, "新增操作失败。", ""); json = new JsonResult(); json.Data = result; return json; } json = new JsonResult(); json.Data = new Models.Result((int)Models.ResultCodeEnum.Success, "", ""); return json; }