コード例 #1
0
        /// <summary>
        /// 保存表单字段的属性
        /// </summary>
        /// <param name="formFieldId"></param>
        /// <param name="parameter"></param>
        private string PropertySave(long formFieldId, string parameter)
        {
            SysFormField ff = this.DataHelper.FindById <SysFormField>(formFieldId);

            if (ff != null)
            {
                JavaScriptSerializer js = new JavaScriptSerializer();
                var valueDict           = js.DeserializeObject(parameter) as Dictionary <string, object>;
                if (valueDict == null)
                {
                    throw new Exception("回调参数不正确");
                }

                int?   displayType  = valueDict["DisplayType"].ToStringNullable().ToIntNullable();
                int?   maxLength    = valueDict["MaxLength"].ToStringNullable().ToIntNullable();
                int?   minLength    = valueDict["MinLength"].ToStringNullable().ToIntNullable();
                int?   maxValue     = valueDict["MaxValue"].ToStringNullable().ToIntNullable();
                int?   minValue     = valueDict["MinValue"].ToStringNullable().ToIntNullable();
                bool?  isNullable   = valueDict["IsNullable"].ToStringNullable().ToLower().ToBoolNullable();
                string customLabel  = valueDict["CustomLabel"].ToStringNullable();
                string defaultValue = valueDict["DefaultValue"].ToStringNullable();

                if (maxLength < minLength)
                {
                    throw new Exception("最大长度不能小于最小长度");
                }

                if (maxValue < minValue)
                {
                    throw new Exception("最大值不能小于最小值");
                }

                ff.DisplayType  = displayType;
                ff.MaxLength    = maxLength;
                ff.MinLength    = minLength;
                ff.MaxValue     = maxValue;
                ff.MinValue     = minValue;
                ff.IsNullable   = isNullable;
                ff.CustomLabel  = customLabel;
                ff.DefaultValue = defaultValue;
                this.DataHelper.UpdatePartial(ff, p => new
                {
                    p.DisplayType,
                    p.MaxLength,
                    p.MinLength,
                    p.MaxValue,
                    p.MinValue,
                    p.IsNullable,
                    p.CustomLabel,
                    p.DefaultValue,
                });

                return(customLabel);
            }
            else
            {
                throw new Exception("找不到表单字段");
            }
        }
コード例 #2
0
        /// <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 = "&nbsp;";
            }
            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);
        }
コード例 #3
0
ファイル: FormPreviewHelper.cs プロジェクト: zhangchi0420/cms
 private static DataTypeControlHelperBase GetControlHelper(SysFormField ff)
 {
     if (ff.DisplayType == (int)FormFieldDisplayType.StaticText) //显示方式为静态文本
     {
         return(new plabel_ControlHelper(ff));
     }
     else if (dict.ContainsKey((DataTypeEnum)ff.DataType))
     {
         return(dict[(DataTypeEnum)ff.DataType](ff));
     }
     throw new Exception(string.Format("字段【{0}】的数据类型,暂不支持", ff.Field.FieldName));
 }
コード例 #4
0
ファイル: FormPreviewHelper.cs プロジェクト: zhangchi0420/cms
 public DataTypeControlHelperBase(SysFormField ff)
 {
     this.DataType     = (DataTypeEnum)ff.DataType;
     this.IsRequired   = !(ff.IsNullable ?? true);
     this.MaxLength    = ff.MaxLength ?? 0;
     this.MinLength    = ff.MinLength ?? 0;
     this.MaxValue     = ff.MaxValue;
     this.MinValue     = ff.MinValue;
     this.DefaultValue = ff.DefaultValue;
     this.ID           = string.Format("ff_{0}", ff.FormFieldId);
     this.Field        = ff.Field;
     this.FieldName    = ff.Field.FieldName;
 }
コード例 #5
0
        /// <summary>
        /// 获得表单字段的显示名称
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        private string GetFormFieldDisplayText(SysFormField p)
        {
            string result = string.Empty;

            if (!string.IsNullOrEmpty(p.CustomLabel)) //自定义标签
            {
                result = p.CustomLabel;
            }
            else
            {
                var field = GetField(p.FieldId);
                if (field != null)
                {
                    result = field.DisplayText;
                }
            }
            return(result);
        }
コード例 #6
0
        /// <summary>
        /// 读取表单字段的属性
        /// </summary>
        /// <param name="formFieldId"></param>
        /// <param name="otherContent"></param>
        private void PropertyRead(long formFieldId, ref object otherContent)
        {
            SysFormField ff = this.DataHelper.FindById <SysFormField>(formFieldId);

            if (ff != null)
            {
                otherContent = new
                {
                    ff.DisplayType,
                    ff.MaxLength,
                    ff.MinLength,
                    ff.MaxValue,
                    ff.MinValue,
                    ff.IsNullable,
                    ff.CustomLabel,
                    ff.DefaultValue,
                };
            }
            else
            {
                throw new Exception("找不到表单字段");
            }
        }
コード例 #7
0
ファイル: FormPreviewHelper.cs プロジェクト: zhangchi0420/cms
 /// <summary>
 /// 加载控件(详情页面)
 /// </summary>
 /// <param name="ff">表单字段</param>
 /// <returns></returns>
 public static Control LoadControlForDetailPage(SysFormField ff)
 {
     return(GetControlHelper(ff).LoadControlForDetailPage());
 }
コード例 #8
0
ファイル: FormPreviewHelper.cs プロジェクト: zhangchi0420/cms
 /// <summary>
 /// 加载控件(非详情页面)
 /// </summary>
 /// <param name="ff">表单字段</param>
 /// <returns></returns>
 public static Control LoadControl(SysFormField ff)
 {
     return(GetControlHelper(ff).LoadControl());
 }
コード例 #9
0
ファイル: FormPreviewHelper.cs プロジェクト: zhangchi0420/cms
 public ppassword_ControlHelper(SysFormField ff) : base(ff)
 {
 }
コード例 #10
0
ファイル: FormPreviewHelper.cs プロジェクト: zhangchi0420/cms
 public penum_ControlHelper(SysFormField ff) : base(ff)
 {
 }
コード例 #11
0
ファイル: FormPreviewHelper.cs プロジェクト: zhangchi0420/cms
 public pref_ControlHelper(SysFormField ff) : base(ff)
 {
 }
コード例 #12
0
        /// <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());
        }
コード例 #13
0
ファイル: FormPreviewHelper.cs プロジェクト: zhangchi0420/cms
 public pfile_ControlHelper(SysFormField ff) : base(ff)
 {
 }
コード例 #14
0
 private bool[] GetFormFieldPrivilege(Dictionary <long?, SysFormRolePrivilege> fpDict, SysFormField ff)
 {
     bool[] result = new bool[3] {
         false, false, false
     };
     if (fpDict.ContainsKey(ff.FormFieldId))
     {
         var fp = fpDict[ff.FormFieldId];
         result[fp.DisplayPrivilege ?? (int)FormFieldPrivilege.ReadWrite] = true;
     }
     else
     {
         result[(int)FormFieldPrivilege.ReadWrite] = true;
     }
     return(result);
 }
コード例 #15
0
ファイル: FormPreviewHelper.cs プロジェクト: zhangchi0420/cms
 public ptext_ControlHelper(SysFormField ff) : base(ff)
 {
 }
コード例 #16
0
ファイル: FormPreviewHelper.cs プロジェクト: zhangchi0420/cms
 public pdecimal_ControlHelper(SysFormField ff) : base(ff)
 {
 }
コード例 #17
0
ファイル: FormPreviewHelper.cs プロジェクト: zhangchi0420/cms
 public pdatetime_ControlHelper(SysFormField ff) : base(ff)
 {
 }
コード例 #18
0
ファイル: FormPreviewHelper.cs プロジェクト: zhangchi0420/cms
 /// <summary>
 /// 给控件赋值(详情页面)
 /// </summary>
 /// <param name="ff">表单字段</param>
 /// <param name="c">控件</param>
 /// <param name="value">值</param>
 public static void SetValueForDetailPage(SysFormField ff, IDrisionControl c, object value)
 {
     GetControlHelper(ff).SetValueForDetailPage(c, value);
 }
コード例 #19
0
ファイル: FormPreviewHelper.cs プロジェクト: zhangchi0420/cms
 public pbool_ControlHelper(SysFormField ff) : base(ff)
 {
 }
コード例 #20
0
ファイル: FormPreviewHelper.cs プロジェクト: zhangchi0420/cms
 public plong_ControlHelper(SysFormField ff) : base(ff)
 {
 }
コード例 #21
0
        /// <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);
        }