/// <summary> /// Returns true if value matches field's data type. /// </summary> /// <param name="value">Setting's value</param> /// <param name="settingField">Settings field definition</param> private bool IsDataTypeValid(object value, FormFieldInfo settingField) { if (settingField != null) { var checkType = new DataTypeIntegrity(value, settingField, SystemContext.EnglishCulture); return(String.IsNullOrEmpty(checkType.ValidateDataType())); } return(false); }
/// <summary> /// Returns true if value matches field's data type. /// </summary> /// <param name="value">Setting's value</param> /// <param name="settingField">Settings field definition</param> private bool IsDataTypeValid(object value, FormFieldInfo settingField) { if (settingField != null) { var checkType = new DataTypeIntegrity(value, settingField, SystemContext.EnglishCulture); return(checkType.GetValidationResult().Success); } return(false); }
/// <summary> /// Returns true if user control is valid. /// </summary> public override bool IsValid() { bool valid = true; // Check 'options' validity if (lstOptions.SelectedIndex == ListSourceIndex) { // Some option must be included if (String.IsNullOrWhiteSpace(txtValue.Text)) { ValidationError += GetString("TemplateDesigner.ErrorDropDownListOptionsEmpty") + " "; valid = false; } else { // Parse lines int lineIndex; string[] lines = txtValue.Text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); for (lineIndex = 0; lineIndex <= lines.GetUpperBound(0); lineIndex++) { // Loop through only not-empty lines string line = lines[lineIndex]; if (!String.IsNullOrWhiteSpace(line)) { // Get line items string[] items = line.Replace(SpecialFieldsDefinition.SEMICOLON_TO_REPLACE, SpecialFieldsDefinition.REPLACED_SEMICOLON).Split(';'); // Every line must have value and item element and optionally visibility macro if (items.Length > 3) { ValidationError += GetString("TemplateDesigner.ErrorDropDownListOptionsInvalidFormat") + " "; valid = false; break; } // Check for possible macro (with/without visibility condition) if (items.Length <= 2) { string specialMacro = items[0].Trim(); // Check if special macro is used if (SpecialFieldsDefinition.IsSpecialFieldMacro(specialMacro)) { string macro = (items.Length == 2) ? items[1].Trim() : String.Empty; // If special field macro used and second item isn't macro show error if (!String.IsNullOrEmpty(macro) && !MacroProcessor.ContainsMacro(macro)) { ValidationError += string.Format(GetString("TemplateDesigner.ErrorDropDownListOptionsInvalidMacroFormat"), lineIndex + 1) + " "; valid = false; break; } } } // Validate input value var checkType = new DataTypeIntegrity(items[0], EditedFieldDataType); var result = checkType.ValidateDataType(); if (!String.IsNullOrEmpty(result)) { ValidationError += string.Format(GetString("TemplateDesigner.ErrorDropDownListOptionsInvalidValue"), lineIndex + 1) + " " + result + " "; valid = false; break; } } } } } // Check SQL query validity else if ((lstOptions.SelectedIndex == SqlSourceIndex) && String.IsNullOrWhiteSpace(txtValue.Text)) { ValidationError += GetString("TemplateDesigner.ErrorDropDownListQueryEmpty") + " "; valid = false; } else if ((lstOptions.SelectedIndex == MacroSourceIndex) && String.IsNullOrWhiteSpace(txtValue.Text)) { ValidationError += GetString("TemplateDesigner.ErrorDropDownListMacroEmpty") + " "; valid = false; } return(valid); }
/// <summary> /// Returns true if value matches field's data type. /// </summary> /// <param name="value">Setting's value</param> /// <param name="settingField">Settings field definition</param> private bool IsDataTypeValid(object value, FormFieldInfo settingField) { if (settingField != null) { var checkType = new DataTypeIntegrity(value, settingField.DataType, SystemContext.EnglishCulture); return String.IsNullOrEmpty(checkType.ValidateDataType()); } return false; }
/// <summary> /// Validates database configuration. Returns error message if validation fails. /// </summary> /// <param name="originalFieldInfo">Original field info</param> public string Validate(FormFieldInfo originalFieldInfo) { var fieldType = AttributeType; var dataType = DataTypeManager.GetDataType(TypeEnum.Field, fieldType); if (dataType != null) { int attributeSize = ValidationHelper.GetInteger(AttributeSize, 0); if (dataType.VariableSize) { // Attribute size is invalid -> error if ((attributeSize <= 0) || (attributeSize > dataType.MaxSize)) { return(String.Format(GetString("TemplateDesigner.ErrorInvalidAttributeSize"), dataType.MaxSize)); } // Validate default value size for string field if (!txtDefaultValue.IsMacro && DataTypeManager.IsString(TypeEnum.Field, fieldType)) { var defValue = ValidationHelper.GetString(txtDefaultValue.Value, String.Empty); if (defValue.Length > attributeSize) { return(String.Format(GetString("TemplateDesigner.ErrorDefaultValueSize"), dataType.MaxSize)); } } } if (dataType.VariablePrecision) { int attributePrec = ValidationHelper.GetInteger(AttributePrecision, 0); var maxPrecision = dataType.MaxPrecision; if (dataType.VariableSize && (attributeSize < maxPrecision)) { maxPrecision = attributeSize; } // Attribute size is invalid -> error if ((attributePrec < 0) || (attributePrec > maxPrecision)) { return(String.Format(GetString("TemplateDesigner.ErrorInvalidAttributePrecision"), maxPrecision)); } } } // Validate configuration for dependent page type var msg = ValidateDependentPageTypes(originalFieldInfo, dataType); if (!String.IsNullOrEmpty(msg)) { return(msg); } UpdateDefaultValueControlSettings(); // Get the default value var ctrl = GetDefaultValueControl(); // Validate the value through control itself if (!ctrl.IsValid()) { return(GetString("TemplateDesigner.ErrorDefaultValue") + " " + ctrl.ValidationError); } // Validate the default value for proper type bool isMacro; string defaultValue = GetDefaultValue(out isMacro); if (!isMacro && !IsNowOrToday(defaultValue)) { // Validate input value var checkType = new DataTypeIntegrity(defaultValue, AttributeType); var result = checkType.ValidateDataType(); if (!String.IsNullOrEmpty(result)) { return(GetString("TemplateDesigner.ErrorDefaultValue") + " " + result); } } return(null); }
/// <summary> /// Validates database configuration. Returns error message if validation fails. /// </summary> public string Validate() { var fieldType = AttributeType; var dataType = DataTypeManager.GetDataType(TypeEnum.Field, fieldType); if (dataType != null) { int attributeSize = ValidationHelper.GetInteger(AttributeSize, 0); if (dataType.VariableSize && (fieldType != FieldDataType.DocAttachments)) { // Attribute size is invalid -> error if ((attributeSize <= 0) || (attributeSize > dataType.MaxSize)) { return String.Format(GetString("TemplateDesigner.ErrorInvalidAttributeSize"), dataType.MaxSize); } // Validate default value size for string field if (!txtDefaultValue.IsMacro && DataTypeManager.IsString(TypeEnum.Field, fieldType)) { var defValue = ValidationHelper.GetString(txtDefaultValue.Value, String.Empty); if (defValue.Length > attributeSize) { return String.Format(GetString("TemplateDesigner.ErrorDefaultValueSize"), dataType.MaxSize); } } } if (dataType.VariablePrecision) { int attributePrec = ValidationHelper.GetInteger(AttributePrecision, 0); var maxPrecision = dataType.MaxPrecision; if (dataType.VariableSize && (attributeSize < maxPrecision)) { maxPrecision = attributeSize; } // Attribute size is invalid -> error if ((attributePrec < 0) || (attributePrec > maxPrecision)) { return String.Format(GetString("TemplateDesigner.ErrorInvalidAttributePrecision"), maxPrecision); } } } UpdateDefaultValueControlSettings(); // Get the default value var ctrl = GetDefaultValueControl(); // Validate the value through control itself if (!ctrl.IsValid()) { return GetString("TemplateDesigner.ErrorDefaultValue") + " " + ctrl.ValidationError; } // Validate the default value for proper type bool isMacro; string defaultValue = GetDefaultValue(out isMacro); if (!ctrl.IsMacro) { // Validate input value var checkType = new DataTypeIntegrity(defaultValue, AttributeType); var result = checkType.ValidateDataType(); if (!String.IsNullOrEmpty(result)) { return GetString("TemplateDesigner.ErrorDefaultValue") + " " + result; } } return null; }
/// <summary> /// Returns true if user control is valid. /// </summary> public override bool IsValid() { bool valid = true; // Check 'options' validity if (lstOptions.SelectedIndex == ListSourceIndex) { // Some option must be included if (String.IsNullOrWhiteSpace(txtValue.Text)) { ValidationError += GetString("TemplateDesigner.ErrorDropDownListOptionsEmpty") + " "; valid = false; } else { // Parse lines int lineIndex; string[] lines = txtValue.Text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); for (lineIndex = 0; lineIndex <= lines.GetUpperBound(0); lineIndex++) { // Loop through only not-empty lines string line = lines[lineIndex]; if (!String.IsNullOrWhiteSpace(line)) { // Get line items string[] items = line.Replace(SpecialFieldsDefinition.SEMICOLON_TO_REPLACE, SpecialFieldsDefinition.REPLACED_SEMICOLON).Split(';'); // Every line must have value and item element and optionally visibility macro if (items.Length > 3) { ValidationError += GetString("TemplateDesigner.ErrorDropDownListOptionsInvalidFormat") + " "; valid = false; break; } // Check for possible macro (with/without visibility condition) if (items.Length <= 2) { string specialMacro = items[0].Trim(); // Check if special macro is used if (SpecialFieldsDefinition.IsSpecialFieldMacro(specialMacro)) { string macro = (items.Length == 2) ? items[1].Trim() : String.Empty; // If special field macro used and second item isn't macro show error if (!String.IsNullOrEmpty(macro) && !MacroProcessor.ContainsMacro(macro)) { ValidationError += string.Format(GetString("TemplateDesigner.ErrorDropDownListOptionsInvalidMacroFormat"), lineIndex + 1) + " "; valid = false; break; } } } // Validate input value var checkType = new DataTypeIntegrity(items[0], EditedFieldDataType); var result = checkType.ValidateDataType(); if (!String.IsNullOrEmpty(result)) { ValidationError += string.Format(GetString("TemplateDesigner.ErrorDropDownListOptionsInvalidValue"), lineIndex + 1) + " " + result + " "; valid = false; break; } } } } } // Check SQL query validity else if ((lstOptions.SelectedIndex == SqlSourceIndex) && String.IsNullOrWhiteSpace(txtValue.Text)) { ValidationError += GetString("TemplateDesigner.ErrorDropDownListQueryEmpty") + " "; valid = false; } else if ((lstOptions.SelectedIndex == MacroSourceIndex) && String.IsNullOrWhiteSpace(txtValue.Text)) { ValidationError += GetString("TemplateDesigner.ErrorDropDownListMacroEmpty") + " "; valid = false; } return valid; }