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; }
public ActionResult EditContract(Contract contract) { if (ModelState.IsValid) { bool isok = CheckContractData(contract); if (isok == false) return View(); ContractMvcWeb.Models.ContractContext dbContext = new Models.ContractContext(); contract.modifytime = DateTime.Now; bool isExist = dbContext.ExistContractBySeqAndprojectNum(contract.seq, contract.projectnum, contract.contractid); if (isExist) { ModelState.AddModelError("error", "序号和项目编号已经存在。"); return View(); } bool success = dbContext.EditContract(contract); if (success == true) { return new RedirectResult("~/Contract/ContractList"); } else { ModelState.AddModelError("e3", "保存失败!"); return View(); } } return View (); }
protected JsonResult EditContract(Contract contract) { decimal fbys = 0; if (string.IsNullOrEmpty(contract.packageBudget)) { contract.packageBudget = "0.00"; } if (decimal.TryParse(contract.packageBudget, out fbys) == false) { Models.Result result = new Models.Result((int)Models.ResultCodeEnum.Error, "分包预算必须数字", ""); JsonResult json = new JsonResult(); json.Data = result; return json; } if (string.IsNullOrEmpty(contract.money)) { contract.money = "0.00"; } decimal money = 0; if (decimal.TryParse(contract.money, out money) == false) { Models.Result result = new Models.Result((int)Models.ResultCodeEnum.Error, "中标金额必须数字", ""); JsonResult json = new JsonResult(); json.Data = result; return json; } ContractMvcWeb.Models.ContractContext dbContext = new Models.ContractContext(); bool isExist = dbContext.ExistContractBySeqAndprojectNum(contract.seq, contract.projectnum, contract.contractid); //dbContext.ExistContract(contract.projectnum, contract.projectname , contract.contractid); if (isExist) { Models.Result result = new Models.Result((int)Models.ResultCodeEnum.Error, "序号和项目编号已经存在,操作失败。", ""); JsonResult json = new JsonResult(); json.Data = result; return json; } if (string.IsNullOrEmpty(contract.contractrfid) == false) { isExist = dbContext.ExistContractNotSelf( contract.contractrfid , contract.contractid ); if (isExist) { Models.Result result = new Models.Result((int)Models.ResultCodeEnum.Error, "标签已经被使用,操作失败。", ""); JsonResult json = new JsonResult(); json.Data = result; return json; } } contract.modifytime = DateTime.Now; bool success = dbContext.EditContract(contract); if (success == true) { Models.Result result = new Models.Result((int)Models.ResultCodeEnum.Success, "", ""); JsonResult json = new JsonResult(); json.Data = result; return json; } else { Models.Result result = new Models.Result((int)Models.ResultCodeEnum.Error, "", ""); JsonResult json = new JsonResult(); json.Data = result; return json; } }