/// <summary> /// 新增表单区域 /// </summary> /// <param name="formId"></param> /// <returns></returns> private string NewSection(long formId) { int maxOrder = this.DataHelper.Set <SysFormFieldSection>().Where(p => p.FormId == formId).Max(p => p.DisplayOrder ?? 0); SysFormFieldSection section = new SysFormFieldSection() { FormSectionId = this.DataHelper.GetNextIdentity(), FormId = formId, DisplayOrder = maxOrder + 1, CreateTime = DateTime.Now, CreateUserId = this.LoginUserID, }; this.DataHelper.Insert(section); return(string.Format("<div id=\"{0}\" class=\"section\" onclick=\"Select(this);\"></div>", section.FormSectionId)); }
/// <summary> /// 加载表单区域 /// </summary> /// <param name="fs"></param> /// <returns></returns> private Control LoadFormSection(SysFormFieldSection fs, Dictionary <long, FormFieldPrivilege> fpDict, ref Dictionary <long, IDrisionControl> controlDict) { HtmlGenericControl section = new HtmlGenericControl("div"); section.Attributes["class"] = "formFieldSection"; var ffList = this.DataHelper.Set <SysFormField>() .Where(p => p.FormSectionId == fs.FormSectionId) .OrderBy(p => p.DisplayOrder).ToList(); var inVisibleCount = 0; foreach (var ff in ffList) { ff.Field = BasePage.GetField(ff.FieldId); //权限 FormFieldPrivilege fp = FormFieldPrivilege.ReadWrite; if (fpDict.ContainsKey(ff.FormFieldId)) { fp = fpDict[ff.FormFieldId]; if (fp == FormFieldPrivilege.Invisible) { inVisibleCount++; } } var field = LoadFormField(ff, fp, ref controlDict); section.Controls.Add(field); } var cl = new HtmlGenericControl("div"); cl.Attributes["class"] = "cl"; section.Controls.Add(cl); //如果区域下所有的字段都是不可见的,将区域设为不可见 if (inVisibleCount == ffList.Count) { section.Style[HtmlTextWriterStyle.Display] = "none"; } return(section); }
/// <summary> /// 选中现有字段并添加为表单字段 /// </summary> /// <param name="sectionId"></param> /// <param name="parameter"></param> /// <returns></returns> private string SelectField(long sectionId, string parameter) { StringBuilder sb = new StringBuilder(); SysFormFieldSection section = this.DataHelper.FindById <SysFormFieldSection>(sectionId); if (section != null) { JavaScriptSerializer js = new JavaScriptSerializer(); object[] fieldList = js.DeserializeObject(parameter) as object[]; if (fieldList == null) { throw new Exception("回调参数不正确"); } var source = fieldList.Select(p => p as Dictionary <string, object>) .Select(p => new { FieldId = p["FieldId"].ToLong(), RelationId = p["RelationId"].ToStringNullable().ToLongNullable(), }); int maxOrder = this.DataHelper.Set <SysFormField>().Where(p => p.FormSectionId == sectionId).Max(p => p.DisplayOrder ?? 0); using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope()) { using (BizDataContext db = new BizDataContext()) { foreach (var p in source) { SysField field = this.EntityCache.FindById <SysField>(p.FieldId); if (field == null) { field = db.FindById <SysField>(p.FieldId); } if (field != null) { SysFormField ff = new SysFormField() { FormFieldId = db.GetNextIdentity(), FormSectionId = sectionId, FormId = section.FormId, FieldId = p.FieldId, RelationId = p.RelationId, DisplayOrder = ++maxOrder, EntityId = field.EntityId, DataType = field.DataType, IsNullable = true, CreateUserId = this.LoginUserID, CreateTime = DateTime.Now, }; db.Insert(ff); sb.AppendFormat("<div id=\"{0}\" class=\"field unselected\" onclick=\"Select(this);\">{1}</div>", ff.FormFieldId, field.DisplayText); } else { throw new Exception("找不到关联字段"); } } } ts.Complete(); } } else { throw new Exception("找不到表单段落"); } return(sb.ToString()); }
/// <summary> /// 新增表单字段 /// </summary> /// <param name="sectionId"></param> /// <param name="parameter"></param> /// <param name="otherContent"></param> /// <returns></returns> private string NewField(long sectionId, string parameter, ref object otherContent) { string result = string.Empty; SysFormFieldSection section = this.DataHelper.FindById <SysFormFieldSection>(sectionId); if (section != null) { SysForm form = this.DataHelper.FindById <SysForm>(section.FormId); if (form == null) { throw new Exception("表单不存在"); } JavaScriptSerializer js = new JavaScriptSerializer(); var valueDict = js.DeserializeObject(parameter) as Dictionary <string, object>; if (valueDict == null) { throw new Exception("回调参数不正确"); } string displayText = valueDict["DisplayText"].ToStringNullable(); string fieldName = valueDict["FieldName"].ToStringNullable(); int? dataType = valueDict["DataType"].ToStringNullable().ToIntNullable(); int temp = this.DataHelper.Set <SysField>().Where(p => p.EntityId == form.EntityId && (p.DisplayText == displayText || p.FieldName == fieldName)).Count(); if (temp > 0) { throw new Exception("当前新增的字段名称已经存在"); } int maxOrder = this.DataHelper.Set <SysFormField>().Where(p => p.FormSectionId == sectionId).Max(p => p.DisplayOrder ?? 0); using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope()) { using (BizDataContext db = new BizDataContext()) { //新增字段 SysField field = new SysField() { FieldId = db.GetNextIdentity(), DisplayText = displayText, FieldName = fieldName, EntityId = form.EntityId, Description = displayText, DataType = dataType, IsFormField = true,//2013-9-24 zhumin }; db.Insert(field); //新增表单字段 SysFormField ff = new SysFormField() { FormFieldId = db.GetNextIdentity(), FormSectionId = sectionId, EntityId = form.EntityId, DisplayOrder = maxOrder + 1, FormId = form.FormId, FieldId = field.FieldId, DataType = field.DataType, IsNullable = true, CreateTime = DateTime.Now, CreateUserId = this.LoginUserID, }; db.Insert(ff); result = string.Format("<div id=\"{0}\" class=\"field unselected\" onclick=\"Select(this);\">{1}</div>", ff.FormFieldId, field.DisplayText); otherContent = string.Format("<div class=\"divField\"><span><input type=\"checkbox\" fid=\"{0}\" /></span><span>{1}</span><span>{2}</span></div>", field.FieldId, field.DisplayText, field.FieldName); } ts.Complete(); } } return(result); }