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_AutoCorrect(object sender, AutoCorrectEventArgs e)
 {
     if (AutoCorrect != null) AutoCorrect(this, e);
 }
        /// <summary>
        /// 自動修正事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void docValidate_AutoCorrect(object sender, AutoCorrectEventArgs e)
        {
            #region 將修正後的值寫入該欄位
            SheetRowSource row = e.Row as SheetRowSource;
            SheetHelper sheetHelper = row.Sheet;

            int FieldIndex = sheetHelper.GetFieldIndex(e.FieldName);
            if (FieldIndex != -1) //當自動修正,Excel-Sheet內卻沒有欄位
            {
                sheetHelper.Sheet.Cells[row.Position, sheetHelper.GetFieldIndex(e.FieldName)].PutValue(e.NewValue);

                string Description = string.Format("「{0}」值由『{1}』改為『{2}』。", e.FieldName, e.OldValue, e.NewValue);
                List<string> Fields = new List<string>() { e.FieldName };
                ErrorType ErrorType = ErrorType.Correct;
                ValidatorType ValidatorType = ValidatorType.Field;

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

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

                AutoCorrectCount++;
            }
            else //就不處理
            {

            }
            #endregion
        }
 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;
 }