Beispiel #1
0
 public bool validate(AFField field, StringBuilder errorMsgs, AFValidationRule rule)
 {
     bool validationIsFine = true;
     if (Utils.IsFieldWritable(field.getFieldInfo().getWidgetType()))
     {
         TextBox textfield = (TextBox)field.getFieldView();
         if (textfield.Text != null && textfield.Text.Length > Convert.ToInt32(rule.getValue()))
         {
             validationIsFine = false;
         }
     }
     if (field.getFieldInfo().getWidgetType().Equals(SupportedWidgets.PASSWORD))
     {
         PasswordBox textfield = (PasswordBox)field.getFieldView();
         if (textfield.Password != null && textfield.Password.Length > Convert.ToInt32(rule.getValue()))
         {
             validationIsFine = false;
         }
     }
     if (!validationIsFine)
     {
         errorMsgs.Append(Localization.translate("validation.maxchars"));
     }
     return validationIsFine;
 }
Beispiel #2
0
        public bool validate(AFField field, StringBuilder errorMsgs, AFValidationRule rule)
        {
            bool validationIsFine = true;
            if (Utils.IsFieldNumberField(field))
            {
                TextBox numberField = (TextBox)field.getFieldView();
                try
                {
                    if (!String.IsNullOrEmpty(numberField.Text) &&
                        Convert.ToDouble(numberField.Text) > Convert.ToDouble(rule.getValue()))
                    {
                        validationIsFine = false;
                    }
                }
                catch (Exception ex) //catch convert exception
                {
                    validationIsFine = true; //if there is no number in field we cant validate its value
                    Debug.WriteLine(ex.StackTrace);
                }
            }
            if (!validationIsFine)
            {
                errorMsgs.Append(Localization.translate("validation.maxval") + " " + rule.getValue());
            }
            return validationIsFine;

        }
Beispiel #3
0
        public bool validate(AFField field, StringBuilder errorMsgs, AFValidationRule rule)
        {
            bool validationIsFine = true;
            Object otherData = ((AFForm)field.getParent()).getDataFromFieldWithId(rule.getValue());
            if (otherData != null)
            {
                if (Utils.IsFieldNumberField(field))
                {
                    //TODO pro cisla
                }
                if (field.getFieldInfo().getWidgetType().Equals(SupportedWidgets.CALENDAR))
                {
                    Object fieldData = ((AFForm)field.getParent()).getDataFromFieldWithId(field.getId());
                    if (fieldData != null)
                    {
                        DateTime? date = Utils.ParseDate(fieldData.ToString());
                        DateTime? otherDate = Utils.ParseDate(otherData.ToString());
                        if (date > otherDate)
                        {
                            validationIsFine = false;
                        }
                    }
                }
                if (!validationIsFine)
                {
                    String otherFieldLabelText = (field.getParent()).getFieldById(rule.getValue()).getFieldInfo().getLabelText();
                    errorMsgs.Append(Localization.translate("validation.lessthan") + " "
                            + Localization.translate(otherFieldLabelText));
                }
            }
            return validationIsFine;

        }
Beispiel #4
0
 public bool validate(AFField field, StringBuilder errorMsgs, AFValidationRule rule)
 {
     bool validationIsFine = true;
     if (Utils.IsFieldWritable(field.getFieldInfo().getWidgetType()))
     {
         TextBox textfield = (TextBox) field.getFieldView();
         if (String.IsNullOrWhiteSpace(textfield.Text))
         {
             validationIsFine = false;
         }
     }
     if (field.getFieldInfo().getWidgetType().Equals(SupportedWidgets.PASSWORD))
     {
         PasswordBox passwordField = (PasswordBox)field.getFieldView();
         if (String.IsNullOrWhiteSpace(passwordField.Password))
         {
             validationIsFine = false;
         }
     }
     if (field.getFieldInfo().getWidgetType().Equals(SupportedWidgets.OPTION))
     {
         StackPanel radioGroup = (StackPanel)field.getFieldView();
         bool atLeastOneIsChecked = false;
         foreach(RadioButton child in radioGroup.Children)
         {
             if(child.IsChecked.Value)
             {
                 atLeastOneIsChecked = true;
             }
         }
         if (!atLeastOneIsChecked)
         {
             validationIsFine = false;
         }
     }
     if (field.getFieldInfo().getWidgetType().Equals(SupportedWidgets.DROPDOWNMENU))
     {
         ComboBox cb = (ComboBox)field.getFieldView();
         if (cb.SelectedItem == null)
         {
             validationIsFine = false;
         }
     }
     if (field.getFieldInfo().getWidgetType().Equals(SupportedWidgets.CALENDAR))
     {
         DatePicker textfield = (DatePicker)field.getFieldView();
         if (String.IsNullOrWhiteSpace(textfield.Date.ToString()))
         {
             validationIsFine = false;
         }
     }
     if (!validationIsFine)
     {
         errorMsgs.Append(Localization.translate("validation.required"));
     }
     return validationIsFine;
 }
Beispiel #5
0
        public bool validate(AFField field, StringBuilder errorMsgs, AFValidationRule rule)
        {
            bool validationIsFine = true;
            String message = "";
            TextBox numberField = (TextBox)field.getFieldView();
            if (field.getFieldInfo().getWidgetType().Equals(SupportedWidgets.NUMBERFIELD))
            {
                try
                {
                    if (!String.IsNullOrWhiteSpace(numberField.Text))
                    {
                        Convert.ToInt32(numberField.Text);
                    }

                }
                catch (Exception ex)
                {
                    validationIsFine = false;
                    Debug.WriteLine(ex.StackTrace);
                    message = Localization.translate("validation.integer");
                }
            }
            //for doubles 
            if (field.getFieldInfo().getWidgetType().Equals(SupportedWidgets.NUMBERDOUBLEFIELD))
            {
                try
                {
                    if (!String.IsNullOrWhiteSpace(numberField.Text))
                    {

                        double.Parse(numberField.Text.Replace(',','.'),NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
                    }

                }
                catch (Exception ex)
                {
                    validationIsFine = false;
                    Debug.WriteLine(ex.StackTrace);
                    message = Localization.translate("validation.double");
                }
            }
            if (!validationIsFine)
            {
                errorMsgs.Append(message);
            }
            return validationIsFine;
        }