示例#1
0
        /// <summary>
        /// Validate comparing with a minimum date
        /// </summary>
        /// <param name="element">Xml form element</param>
        /// <param name="fieldName">Field name</param>
        /// <param name="valData">Form value entered by the user</param>
        protected void ValidateRuleStartDate(FormSectionElement element, string fieldName, string valData)
        {
            string stringXml;
            DateTime dateValue;
            DateTime startDate;
            stringXml = element.Field.GetPropertyValue<string>("StartDate");
            startDate = stringXml.ToUpper().Equals("TODAY") ? DateTime.Today : Convert.ToDateTime(stringXml);

            try
            {
                dateValue = Convert.ToDateTime(valData,
                                               new System.Globalization.CultureInfo("fr-FR"));
                //If the value is less than a date allowed then an error
                if (dateValue < startDate)
                {
                    ModelState.AddModelError("",
                                             String.Format(
                                                 Resources.ServiceOrder.
                                                     ErrorFieldDateRuleStartDate,
                                                 fieldName, startDate.ToShortDateString()));
                }
            }
            catch (FormatException)
            {
                if (ModelState.Keys.FirstOrDefault(item => item == "ErrorDate") == null)
                    ModelState.AddModelError("ErrorDate",
                                             String.Format(
                                                 Resources.ServiceOrder.
                                                     ErrorFieldDateIncorrect,
                                                 fieldName));
            }
        }
示例#2
0
        /// <summary>
        /// Validate the number of the digits in a value entered by the user
        /// </summary>
        /// <param name="element">Element of the XML file</param>
        /// <param name="fieldName">Field name</param>
        /// <param name="valData">Field value entered by the user</param>
        protected void ValidateNumDigit(FormSectionElement element, string fieldName, string valData)
        {
            int numDigitsEnter;
            int numDigitsAllow;
            numDigitsAllow =
                Convert.ToInt32(element.Field.GetPropertyValue<string>("NumDigit"));

            //Get the number of decimal digits considering the period as separator
            if (valData.Contains("."))
            {
                int s = (valData.IndexOf(".") + 1); // the first numbers plus decimal point
                numDigitsEnter = ((valData.Length) - s);
            }
            //Get the number of decimal digits considering the comma as separator
            else if (valData.Contains(","))
            {
                int s = (valData.IndexOf(".") + 1); // the first numbers plus decimal point
                numDigitsEnter = ((valData.Length) - s);
            }
            else
            {
                numDigitsEnter = 0;
            }

            //In case the digits entered comparing with the allowed ones then an error
            if (numDigitsEnter != numDigitsAllow)
            {
                ModelState.AddModelError("",
                                         String.Format(
                                             Resources.ServiceOrder.ErrorFieldTextNumDigit,
                                             fieldName));
            }
        }
示例#3
0
 /// <summary>
 /// Validate data comparing with a minimun value defined in the xml 
 /// </summary>
 /// <param name="element">Form element with the rule</param>
 /// <param name="fieldName">Field name</param>
 /// <param name="valData">Form value entered by the user</param>
 protected void ValidateRuleMinValue(FormSectionElement element, string fieldName, string valData)
 {
     decimal maxMinValue;
     try
     {
         maxMinValue =
             Convert.ToDecimal(element.Field.GetPropertyValue<object>("MinValue").ToString());
         //If the value is less than a min allowed then an error
         if (Convert.ToDecimal(valData) < maxMinValue)
         {
             ModelState.AddModelError("",
                                      String.Format(
                                          Resources.ServiceOrder.
                                              ErrorFieldTextMinValue,
                                          fieldName));
         }
     }
     catch (FormatException)
     {
         if (ModelState.Keys.FirstOrDefault(item => item == "ErrorNumeric") == null)
             ModelState.AddModelError("ErrorNumeric",
                                      String.Format(
                                          Resources.ServiceOrder.
                                              ErrorFieldNumericIncorrect,
                                          fieldName));
     }
 }
示例#4
0
 /// <summary>
 /// Verify if the field name defined in the xml is as mandatory. In this case add an error to the model because this field doesn't have value.
 /// </summary>
 /// <param name="element">Xml form element</param>
 /// <param name="fieldName">Field name</param>
 protected void ValidateMandatoryField(FormSectionElement element, string fieldName)
 {
     if ((element.Field.RulesForms.Where(item => item == RulesForm.RuleMandatory)).ToList().Count > 0)
     {
         ModelState.AddModelError("", String.Format(Resources.ServiceOrder.ErrorFieldRequired, fieldName));
     }
 }