private bool IsCorrectable(IRowStream RowSource, ValidateStatement vs, IRowVaildator rv)
        {
            bool result = false;

            if (vs.AutoCorrect)
            {
                string newValue = rv.Correct(RowSource);

                XmlDocument xmldoc = new XmlDocument();

                try
                {
                    xmldoc.LoadXml(newValue);
                }
                catch
                {
                    throw new ArgumentException(string.Format("Correct Specification Invalid ({0}).", rv.ToString()));
                }

                if (xmldoc.DocumentElement.ChildNodes.Count > 0)
                {
                    foreach (XmlNode each in xmldoc.DocumentElement.ChildNodes)
                    {
                        XmlElement n = each as XmlElement;
                        if (n == null) continue;

                        string OldValue = RowSource.GetValue(n.LocalName);
                        if (AutoCorrect != null)
                        {
                            AutoCorrectEventArgs args = new AutoCorrectEventArgs(RowSource, ValidatorType.Row, n.LocalName, OldValue, n.InnerText);
                            if (AutoCorrect != null) AutoCorrect(this, args);
                            result = true; //修正成功。
                        }
                    }
                }
                else
                {
                    ErrorCapturedEventArgs args = new ErrorCapturedEventArgs(RowSource, ValidatorType.Row, vs.ErrorType, string.Empty, rv.ToString(vs.Description));
                    if (ErrorCaptured != null) ErrorCaptured(this, args);
                }
            }
            else
            {
                ErrorCapturedEventArgs args = new ErrorCapturedEventArgs(RowSource, ValidatorType.Row, vs.ErrorType, string.Empty, rv.ToString(vs.Description));
                if (ErrorCaptured != null) ErrorCaptured(this, args);
            }

            return result;
        }
 private void mRowValidate_ErrorCaptured(object sender, ErrorCapturedEventArgs e)
 {
     if (ErrorCaptured != null) ErrorCaptured(this, e);
 }
Exemplo n.º 3
0
        /// <summary>
        /// 錯誤或警告事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void docValidate_ErrorCaptured(object sender, ErrorCapturedEventArgs e)
        {
            string Description = e.Description;
            List<string> Fields = new List<string>() { e.FieldName };
            ErrorType ErrorType = (e.ErrorType == EMBA.DocumentValidator.ErrorType.Error) ? ErrorType.Error : ErrorType.Warning;
            ValidatorType ValidationType = ValidatorType.Field;

            MessageItem item = new MessageItem(ErrorType, ValidationType, Description, Fields);

            RowMessages[e.Row.Position].MessageItems.Add(item);

            if (e.ErrorType == EMBA.DocumentValidator.ErrorType.Error)
                ErrorCount++;
            else
                WarningCount++;
        }
 private bool IsCorrectable(IRowStream row, FieldDescription field,
     string fieldValue, bool isValidated,
     ValidateStatement vs, IFieldValidator validator)
 {
     if (vs.AutoCorrect)
     {
         string newValue = validator.Correct(fieldValue);
         if (!string.IsNullOrEmpty(newValue))
         {
             XmlDocument xmldoc = new XmlDocument();
             xmldoc.LoadXml(newValue);
             newValue = xmldoc.DocumentElement.InnerText;
             if (AutoCorrect != null)
             {
                 AutoCorrectEventArgs args = new AutoCorrectEventArgs(row, ValidatorType.Field, field.Name, fieldValue, newValue);
                 if (AutoCorrect != null) AutoCorrect(this, args);
             }
             isValidated = false;
         }
         else
         {
             ErrorCapturedEventArgs args = new ErrorCapturedEventArgs(row, ValidatorType.Field, vs.ErrorType, field.Name, validator.ToString(vs.Description));
             if (ErrorCaptured != null) ErrorCaptured(this, args);
         }
     }
     else
     {
         ErrorCapturedEventArgs args = new ErrorCapturedEventArgs(row, ValidatorType.Field, vs.ErrorType, field.Name, validator.ToString(vs.Description));
         if (ErrorCaptured != null) ErrorCaptured(this, args);
     }
     return isValidated;
 }