/// <summary> /// 加载表单字段 /// </summary> /// <param name="ff"></param> /// <returns></returns> private Control LoadFormField(SysFormField ff, FormFieldPrivilege fp, ref Dictionary <long, IDrisionControl> controlDict) { HtmlGenericControl field = new HtmlGenericControl("div"); field.Attributes["class"] = "formField"; //表单字段前面的文字说明 HtmlGenericControl fieldDisplayText = new HtmlGenericControl("span"); fieldDisplayText.Attributes["class"] = "formFieldDisplayText"; fieldDisplayText.InnerText = GetFormFieldDisplayText(ff); field.Controls.Add(fieldDisplayText); //是否必输前面的星号 HtmlGenericControl star = new HtmlGenericControl("span"); star.Attributes["class"] = "left_star"; if (!(ff.IsNullable ?? true)) { star.InnerHtml = "*"; } else { star.InnerHtml = " "; } field.Controls.Add(star); //控件 Control control; if (this.IsDetailPage) //详情页面的解析和其它不同 { control = FormPreviewHelper.LoadControlForDetailPage(ff); } else { control = FormPreviewHelper.LoadControl(ff); } //权限处理 if (fp == FormFieldPrivilege.Invisible) { control.Visible = false; field.Style[HtmlTextWriterStyle.Display] = "none"; } else if (fp == FormFieldPrivilege.ReadOnly) { //(control as IReadOnlyControl).ReadOnly = true; } field.Controls.Add(control); controlDict[ff.FormFieldId] = (control as IDrisionControl); //记住所有的IDrisionControl,后面有可能要赋值 return(field); }
/// <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="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { try { if (this.SelectedRoleId == null) { throw new Exception("请选择角色"); } //现有配置 var fpDict = this.DataHelper.Set <SysFormRolePrivilege>() .Where(p => p.RoleId == this.SelectedRoleId && p.FormId == this.FormId).ToList().ToDictionary(p => p.FormFieldId); using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope()) { using (BizDataContext db = new BizDataContext()) { foreach (RepeaterItem section in rSection.Items) { Repeater rField = section.FindControl("rField") as Repeater; foreach (RepeaterItem field in rField.Items) { var hf = field.FindControl("hf") as HiddenField; var ccInvisible = field.FindControl("ccInvisible") as RadioButton; var ccReadOnly = field.FindControl("ccReadOnly") as RadioButton; var ccReadWrite = field.FindControl("ccReadWrite") as RadioButton; if (hf != null && ccInvisible != null && ccReadOnly != null && ccReadWrite != null) { var id = hf.Value.ToLong(); FormFieldPrivilege privilege = FormFieldPrivilege.Invisible; if (ccReadOnly.Checked) { privilege = FormFieldPrivilege.ReadOnly; } else if (ccReadWrite.Checked) { privilege = FormFieldPrivilege.ReadWrite; } if (fpDict.ContainsKey(id)) { var fp = fpDict[id]; if (fp.DisplayPrivilege != (int)privilege) { fp.DisplayPrivilege = (int)privilege; db.UpdatePartial(fp, p => new { p.DisplayPrivilege }); } } else { SysFormRolePrivilege fp = new SysFormRolePrivilege() { PrivilegeId = db.GetNextIdentity(), FormFieldId = id, FormId = this.FormId, RoleId = this.SelectedRoleId, DisplayPrivilege = (int)privilege, CreateTime = DateTime.Now, CreateUserId = this.LoginUserID, }; db.Insert(fp); } } } } } ts.Complete(); } this.AjaxAlertAndEnableButton("保存成功"); } catch (Exception ex) { this.AjaxAlertAndEnableButton(ex); } }