Пример #1
0
        /// <summary>
        /// 设置属性
        /// </summary>
        protected override void SetAttributes()
        {
            Label control = this.ControlHost.Content as Label;

            this.HtmlWriter.AddAttribute("dojoType", "Controls/Label");
            if (!IsPreview && !string.IsNullOrEmpty(this.ControlHost.Name))
            {
                this.HtmlWriter.AddAttribute("id", this.ControlHost.Name);
                this.HtmlWriter.AddAttribute("name", this.ControlHost.Name);
            }
            if (!string.IsNullOrEmpty(control.ToolTip) && this.ProjectDocument != null)
            {
                this.HtmlWriter.AddAttribute("tooltip-name", this.ProjectDocument.Name + "_" + control.ToolTip);
            }

            bool isListBox = false;

            if (!IsPreview && this.Parent != null)
            {
                isListBox = BuildCommonMethod.GetIsListBox(this.Parent);
            }
            StringBuilder sbProps       = new StringBuilder();
            StringBuilder sbConstraints = new StringBuilder();
            StringBuilder returnContent = new StringBuilder();
            string        props         = control.BuildControlProps(this.ScreenDefinition, this.IsPreview, this.PermissionData, returnContent, sbConstraints, false, isListBox);

            if (!string.IsNullOrEmpty(props))
            {
                sbProps.AppendFormat("{0},", props);
            }
            if (sbProps.ToString().Length > 0)
            {
                this.HtmlWriter.AddAttribute("data-dojo-props", sbProps.ToString().Substring(0, sbProps.ToString().Length - 1), false);
            }

            base.SetAttributes();
        }
Пример #2
0
        /// <summary>
        /// 设置属性
        /// </summary>
        protected override void SetAttributes()
        {
            SelectPage control = this.ControlHost.Content as SelectPage;

            this.HtmlWriter.AddAttribute("dojoType", "Controls/SelectPage");
            if (!IsPreview && !string.IsNullOrEmpty(this.ControlHost.Name))
            {
                this.HtmlWriter.AddAttribute("id", this.ControlHost.Name);
                this.HtmlWriter.AddAttribute("name", this.ControlHost.Name);
            }
            if (!IsPreview)
            {
                this.HtmlWriter.AddAttribute("forScreen", this.ProjectDocument.Name);
            }

            string stores = GetStore();

            if (!string.IsNullOrEmpty(stores))
            {
                this.HtmlWriter.AddAttribute("store", stores, false);
            }
            StringBuilder sbProps       = new StringBuilder();
            StringBuilder returnContent = new StringBuilder();
            string        props         = control.BuildControlProps(this.ScreenDefinition, this.IsPreview, this.PermissionData, returnContent);

            if (!string.IsNullOrEmpty(props))
            {
                sbProps.AppendFormat("{0},", props);
            }
            string searchAttr = GetSearchAttr();

            if (!string.IsNullOrEmpty(searchAttr))
            {
                sbProps.AppendFormat("{0},", searchAttr);
            }
            sbProps.AppendFormat("{0},", "multiple:" + control.Multiple.ToString().ToLower());
            sbProps.AppendFormat("{0},", "pagination:" + control.Pagination.ToString().ToLower());
            sbProps.AppendFormat("{0},", "dropButton:" + control.DropButton.ToString().ToLower());
            sbProps.AppendFormat("{0},", "selectToCloseList:" + control.SelectToCloseList.ToString().ToLower());
            sbProps.AppendFormat("{0},", "autoSelectFirst:" + control.AutoSelectFirst.ToString().ToLower());
            sbProps.AppendFormat("{0},", "maxSelectLimit:" + control.MaxSelectLimit.ToString());
            sbProps.AppendFormat("{0},", "inputDelay:" + control.InputDelay.ToString());
            if (control.ShowSearch)
            {
                sbProps.AppendFormat("{0},", "showSearch:false");
            }
            else
            {
                sbProps.AppendFormat("{0},", "showSearch:true");
            }
            if (!string.IsNullOrEmpty(control.SelectIndex))
            {
                sbProps.AppendFormat("{0},", "selectIndex:'" + control.SelectIndex.ToString() + "'");
            }
            string dropDownButtonName = string.Empty;

            if (!IsPreview && this.Parent != null)
            {
                dropDownButtonName = BuildCommonMethod.GetIsDropDownButton(this.Parent);
            }
            sbProps.AppendFormat("{0},", "dropDownButtonName:'" + dropDownButtonName + "'");

            if (sbProps.ToString().Length > 0)
            {
                this.HtmlWriter.AddAttribute("data-dojo-props", sbProps.ToString().Substring(0, sbProps.ToString().Length - 1), false);
            }

            base.SetAttributes();
        }
Пример #3
0
        /// <summary>
        /// 获取验证器
        /// </summary>
        /// <param name="controlBase"></param>
        /// <param name="screenDef"></param>
        /// <returns></returns>
        private static string BuildValidators(this ControlBase controlBase, ScreenDefinition screenDef, string validatorFullName)
        {
            StringBuilder result      = new StringBuilder();
            StringBuilder sbValidator = new StringBuilder();

            List <Model.Core.Definitions.Entities.ValidatorBase> listValidators = new List <Model.Core.Definitions.Entities.ValidatorBase>();
            EDataBaseType  baseType        = EDataBaseType.String;
            CommonDataType dataTypeContent = null;

            GetValidators(controlBase, screenDef, validatorFullName, ref listValidators, ref baseType, ref dataTypeContent);
            string dataTypeName = BuildCommonMethod.GetTypeName(baseType);

            if (listValidators.Count > 0 && dataTypeContent != null)
            {
                string defaultValue = string.Empty, maxValue = string.Empty, minValue = string.Empty, maxLength = string.Empty, minLength = string.Empty;
                BuildCommonMethod.GetDataTypeValue(dataTypeContent, ref defaultValue, ref maxValue, ref minValue, ref maxLength, ref minLength);
                foreach (var validator in listValidators)
                {
                    string validatorType = validator.ValidatorType.ToString().ToLower();
                    if (validator.ValidatorType == Model.Core.Definitions.Entities.EValidatorType.Phone)
                    {
                        validatorType = "tel";
                    }
                    else if (validator.ValidatorType == Model.Core.Definitions.Entities.EValidatorType.EmailAddress)
                    {
                        validatorType = "email";
                    }
                    else if (validator.ValidatorType == Model.Core.Definitions.Entities.EValidatorType.RegularExpression)
                    {
                        validatorType = "regexp";
                    }
                    else if (dataTypeName == "date" && validator.ValidatorType == Model.Core.Definitions.Entities.EValidatorType.Range)
                    {
                        validatorType = "daterange";
                    }

                    if (validator.ValidatorType != Model.Core.Definitions.Entities.EValidatorType.Compare)
                    {
                        sbValidator.Append("" + validatorType + ":{");
                        sbValidator.AppendFormat("message:'{0}'", validator.ErrorMessage);

                        switch (validator.ValidatorType)
                        {
                        case Model.Core.Definitions.Entities.EValidatorType.MinLength:
                            if (dataTypeName == "string")
                            {
                                sbValidator.AppendFormat(",min:{0}", minLength);
                            }
                            break;

                        case Model.Core.Definitions.Entities.EValidatorType.MaxLength:
                            if (dataTypeName == "string")
                            {
                                sbValidator.AppendFormat(",max:{0}", maxLength);
                            }
                            break;

                        case Model.Core.Definitions.Entities.EValidatorType.Range:
                            if (dataTypeName == "number")
                            {
                                sbValidator.AppendFormat(",min:{0}", minValue);
                                sbValidator.AppendFormat(",max:{0}", maxValue);
                            }
                            else if (dataTypeName == "date")
                            {
                                if (minValue != null)
                                {
                                    DateTime dtMin = Convert.ToDateTime(minValue);
                                    sbValidator.AppendFormat(",min:'{0}'", dtMin.ToString("yyyy-MM-dd"));
                                }
                                if (maxValue != null)
                                {
                                    DateTime dtMax = Convert.ToDateTime(maxValue);
                                    sbValidator.AppendFormat(",max:'{0}'", dtMax.ToString("yyyy-MM-dd"));
                                }
                            }
                            break;

                        case Model.Core.Definitions.Entities.EValidatorType.RegularExpression:
                            var cValidator = validator as Model.Core.Definitions.Entities.Validators.RegularExpressionValidator;
                            sbValidator.AppendFormat(",pattern:'{0}'", cValidator.Pattern.Replace(@"\", @"\\"));
                            break;
                        }

                        sbValidator.Append("},");
                    }
                }
            }

            string _sbValidator = sbValidator.ToString().Length > 0 ? sbValidator.ToString().Substring(0, sbValidator.ToString().Length - 1) : "";

            if (!string.IsNullOrEmpty(_sbValidator))
            {
                result.Append("validators:{");
                result.Append(_sbValidator);
                result.Append("},");
            }

            return(result.ToString());
        }