public ActionResult AddEdit() { this.Internationalization(); #region Add if (Request.Form["oper"].Equals("add")) { try { TugDataEntities db = new TugDataEntities(); { TugDataModel.TugInfor tug = new TugInfor(); tug.Code = Request.Form["Code"]; tug.Name1 = Request.Form["Name1"]; tug.Name2 = Request.Form["Name2"]; tug.SimpleName = Request.Form["SimpleName"]; tug.Power = Request.Form["Power"]; tug.Class = Request.Form["Class"]; tug.Speed = Request.Form["Speed"]; tug.Length = Request.Form["Length"]; tug.Width = Request.Form["Width"]; tug.Remark = Request.Form["Remark"]; tug.OwnerID = -1; tug.CreateDate = tug.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");; tug.UserID = Session.GetDataFromSession<int>("userid"); tug.UserDefinedCol1 = Request.Form["UserDefinedCol1"]; tug.UserDefinedCol2 = Request.Form["UserDefinedCol2"]; tug.UserDefinedCol3 = Request.Form["UserDefinedCol3"]; tug.UserDefinedCol4 = Request.Form["UserDefinedCol4"]; if (Request.Form["UserDefinedCol5"] != "") tug.UserDefinedCol5 = Convert.ToDouble(Request.Form["UserDefinedCol5"]); if (Request.Form["UserDefinedCol6"] != "") tug.UserDefinedCol6 = Util.toint(Request.Form["UserDefinedCol6"]); if (Request.Form["UserDefinedCol7"] != "") tug.UserDefinedCol7 = Util.toint(Request.Form["UserDefinedCol7"]); if (Request.Form["UserDefinedCol8"] != "") tug.UserDefinedCol8 = Util.toint(Request.Form["UserDefinedCol8"]); tug.UserDefinedCol9 = Request.Form["UserDefinedCol9"]; tug.UserDefinedCol10 = Request.Form["UserDefinedCol10"]; tug = db.TugInfor.Add(tug); db.SaveChanges(); var ret = new { code = Resources.Common.SUCCESS_CODE, message = Resources.Common.SUCCESS_MESSAGE }; //Response.Write(@Resources.Common.SUCCESS_MESSAGE); return Json(ret); } } catch (Exception) { var ret = new { code = Resources.Common.EXCEPTION_CODE, message = Resources.Common.EXCEPTION_MESSAGE }; //Response.Write(@Resources.Common.EXCEPTION_MESSAGE); return Json(ret); } } #endregion Add #region Edit if (Request.Form["oper"].Equals("edit")) { try { TugDataEntities db = new TugDataEntities(); string name1 = Request.Form["Name1"]; int idx = Util.toint(Request.Form["IDX"]); System.Linq.Expressions.Expression<Func<TugInfor, bool>> exp = u => u.Name1 == name1 && u.IDX != idx; TugInfor tmpName = db.TugInfor.Where(exp).FirstOrDefault(); if (tmpName != null) { return Json(new { code = Resources.Common.ERROR_CODE, message = "拖轮名称1已存在!" });//Resources.Common.ERROR_MESSAGE } TugInfor tug = db.TugInfor.Where(u => u.IDX == idx).FirstOrDefault(); if (tug == null) { return Json(new { code = Resources.Common.ERROR_CODE, message = Resources.Common.ERROR_MESSAGE }); } else { string oldTugName1 = tug.Name1; string newTugName1 = Request.Form["Name1"].Trim(); int tugIdx = idx; tug.Code = Request.Form["Code"]; tug.Name1 = Request.Form["Name1"]; tug.Name2 = Request.Form["Name2"]; tug.SimpleName = Request.Form["SimpleName"]; tug.Power = Request.Form["Power"]; tug.Class = Request.Form["Class"]; tug.Speed = Request.Form["Speed"]; tug.Length = Request.Form["Length"]; tug.Width = Request.Form["Width"]; tug.Remark = Request.Form["Remark"]; tug.OwnerID = -1; tug.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");; tug.UserID = Session.GetDataFromSession<int>("userid"); tug.UserDefinedCol1 = Request.Form["UserDefinedCol1"]; tug.UserDefinedCol2 = Request.Form["UserDefinedCol2"]; tug.UserDefinedCol3 = Request.Form["UserDefinedCol3"]; tug.UserDefinedCol4 = Request.Form["UserDefinedCol4"]; if (Request.Form["UserDefinedCol5"] != "") tug.UserDefinedCol5 = Convert.ToDouble(Request.Form["UserDefinedCol5"]); if (Request.Form["UserDefinedCol6"] != "") tug.UserDefinedCol6 = Util.toint(Request.Form["UserDefinedCol6"]); if (Request.Form["UserDefinedCol7"] != "") tug.UserDefinedCol7 = Util.toint(Request.Form["UserDefinedCol7"]); if (Request.Form["UserDefinedCol8"] != "") tug.UserDefinedCol8 = Util.toint(Request.Form["UserDefinedCol8"]); tug.UserDefinedCol9 = Request.Form["UserDefinedCol9"]; tug.UserDefinedCol10 = Request.Form["UserDefinedCol10"]; db.Entry(tug).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); TugBusinessLogic.Utils.UpDateTugName1(tugIdx, oldTugName1, newTugName1); return Json(new { code = Resources.Common.SUCCESS_CODE, message = Resources.Common.SUCCESS_MESSAGE }); } } catch (Exception exp) { return Json(new { code = Resources.Common.EXCEPTION_CODE, message = Resources.Common.EXCEPTION_MESSAGE }); } } #endregion Edit return Json(new { code = Resources.Common.ERROR_CODE, message = Resources.Common.ERROR_MESSAGE }); }
public ActionResult AddTug(string Code, string Name1, string Name2, string SimpleName, string Power, string Class, string Speed, string Length, string Width, string Remark) { this.Internationalization(); try { TugDataEntities db = new TugDataEntities(); System.Linq.Expressions.Expression<Func<TugInfor, bool>> exp = u => u.Name1 == Name1; TugInfor tmpName = db.TugInfor.Where(exp).FirstOrDefault(); if (tmpName != null) { throw new Exception("拖轮名称1已存在!"); } { TugDataModel.TugInfor tug = new TugInfor(); tug.Code = Code; tug.Name1 = Name1; tug.Name2 = Name2; tug.SimpleName = SimpleName; tug.Power = Power; tug.Class = Class; tug.Speed = Speed; tug.Length = Length; tug. Width= Width; tug.Remark =Remark ; tug.OwnerID = -1; tug.CreateDate = tug.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); ; tug.UserID = Session.GetDataFromSession<int>("userid"); //tug.UserDefinedCol1 = ""; //tug.UserDefinedCol2 = ""; //tug.UserDefinedCol3 = ""; //tug.UserDefinedCol4 = ""; //if (Request.Form["UserDefinedCol5"] != "") // tug.UserDefinedCol5 = Convert.ToDouble(Request.Form["UserDefinedCol5"]); //if (Request.Form["UserDefinedCol6"] != "") // tug.UserDefinedCol6 = Util.toint(Request.Form["UserDefinedCol6"]); //if (Request.Form["UserDefinedCol7"] != "") // tug.UserDefinedCol7 = Util.toint(Request.Form["UserDefinedCol7"]); //if (Request.Form["UserDefinedCol8"] != "") // tug.UserDefinedCol8 = Util.toint(Request.Form["UserDefinedCol8"]); //tug.UserDefinedCol9 = ""; //tug.UserDefinedCol10 = ""; tug = db.TugInfor.Add(tug); db.SaveChanges(); var ret = new { code = Resources.Common.SUCCESS_CODE, message = Resources.Common.SUCCESS_MESSAGE }; //Response.Write(@Resources.Common.SUCCESS_MESSAGE); return Json(ret); } } catch (Exception ex) { //var ret = new { code = Resources.Common.EXCEPTION_CODE, message = Resources.Common.EXCEPTION_MESSAGE }; //return Json(ret); throw ex; } }