private void Init() { using (var db = DbAccess.DbCRMContext.Create()) { this.DbForm = db.T_QCRM_Form.Where(w => w.Code == this.FormCode).FirstOrDefault(); if (DbForm == null) { throw new UIValidateException("表单信息不存在!Code=【{0}】", this.FormCode); } } }
public ActionResult Save() { var result = QWF.Framework.Web.ResultWebData.Default(); var curUser = QWF.Framework.Web.UserContext.GetCurrentInfo(); var id = this.Request["id"].SafeConvert().ToStr(); var code = this.Request["code"].SafeConvert().ToStr(); var name = this.Request["name"].SafeConvert().ToStr(); var actionName = this.Request["actionName"].SafeConvert().ToStr(); var actionStyle = this.Request["actionStyle"].SafeConvert().ToInt32(0); var actionType = this.Request["actionType"].SafeConvert().ToStr(); var buttonIcon = this.Request["buttonIcon"].SafeConvert().ToStr(); var buttonStyle = this.Request["buttonStyle"].SafeConvert().ToStr(); var remaks = this.Request["remarks"].SafeConvert().ToStr(); var styleColums = this.Request["styleColums"].SafeConvert().ToInt32(1); var windowsWidth = this.Request["windowsWidth"].SafeConvert().ToInt32(550); var mainTable = this.Request["mainTable"].SafeConvert().ToStr(); var plugInClass = this.Request["plugInClass"].SafeConvert().ToStr(); if (id.Length == 0 && code.Length == 0) { throw new UIValidateException("表单代码不能空填。"); } if (name.Length == 0) { throw new UIValidateException("表单名称不能空填。"); } if (actionName.Length == 0) { throw new UIValidateException("事件名称不能空填。"); } if (actionType.Length == 0) { throw new UIValidateException("事件类型不能为空填"); } if (actionStyle == 0) { throw new UIValidateException("弹窗样式不能为空填。"); } var permission = QWF.CRM.Utils.PermissionUtils.Create(); using (var db = DbAccess.DbCRMContext.Create()) { if (id.Length == 0) { if (mainTable.Length == 0) { throw new UIValidateException("请选择所属表。"); } if (!code.StrValidatorHelper().IsLetterOrNumberCode()) { throw new UIValidateException("表单代码格式不正确,只能是字母、数字或下划线组合。"); } var dbModel = db.T_QCRM_Form.Where(w => w.Code == code).FirstOrDefault(); if (dbModel != null) { throw new UIValidateException("表单代码【{0}】已经存在,请更换代码。", code); } dbModel = new DbAccess.T_QCRM_Form(); dbModel.Code = code; dbModel.Name = name; dbModel.ActionType = actionType; dbModel.ActionName = actionName; dbModel.ActionStyle = actionStyle; dbModel.StyleColums = styleColums; dbModel.WindowsWidth = windowsWidth; dbModel.ButtonStyle = buttonStyle; dbModel.ButtonIcon = buttonIcon; dbModel.Remarks = remaks; dbModel.MainTable = mainTable; dbModel.CreateUser = curUser.CurrentUserCode; dbModel.CreateTime = DateTime.Now; if (permission.IsAdministrator()) { dbModel.PlugInClass = plugInClass; } db.T_QCRM_Form.Add(dbModel); } else { //编辑 var dbModel = db.T_QCRM_Form.Where(w => w.Code == id).FirstOrDefault(); if (dbModel == null) { throw new UIValidateException("表单代码不存在,请检查数据【ID={0}】。", id); } dbModel.Name = name; dbModel.ActionType = actionType; dbModel.ActionName = actionName; dbModel.ActionStyle = actionStyle; dbModel.StyleColums = styleColums; dbModel.WindowsWidth = windowsWidth; dbModel.ButtonStyle = buttonStyle; dbModel.ButtonIcon = buttonIcon; dbModel.Remarks = remaks; dbModel.UpdateUser = curUser.CurrentUserCode; dbModel.UpdateTime = DateTime.Now; if (permission.IsAdministrator()) { dbModel.PlugInClass = plugInClass; } } db.SaveChanges(); } return(this.Content(Newtonsoft.Json.JsonConvert.SerializeObject(result))); }