Пример #1
0
        public void AddFirstColumnWithErrors(List <Error> errors, MessageErrors messageErrors)
        {
            if (!errors.Any())
            {
                return;
            }

            InsertNewColumnBeforeFirst(messageErrors.HeaderFirstColumnWithErrors);

            var summaryErrors = new Dictionary <int, int>();

            foreach (var error in errors)
            {
                AddError(new Error(error.Message, error.Row, StartColumn));
                if (summaryErrors.ContainsKey(error.Row))
                {
                    summaryErrors[error.Row]++;
                }
                else
                {
                    summaryErrors.Add(error.Row, 1);
                }
            }

            foreach (var summary in summaryErrors)
            {
                SetCellValue(summary.Key, StartColumn, $"{summary.Value} {messageErrors.TextFirstColumnWithErrors}");
            }
        }
Пример #2
0
        public virtual ValidationResult <string> GetHeaderWithValidation <T>(WorksheetMap <T> worksheetMap,
                                                                             MessageErrors messageErrors)
        {
            var expectedHeader = worksheetMap.GetFields().Select(s => s.Name).ToList();
            var header         = GetHeader();

            var validationResult = new ValidationResult <string>();

            if (header == null)
            {
                validationResult.AddError(new Error(messageErrors.NullHeaderErrorMessage(), StartRow, StartColumn));
            }

            foreach (var headerItem in header)
            {
                if (headerItem != messageErrors.HeaderFirstColumnWithErrors && !expectedHeader.Contains(headerItem))
                {
                    validationResult.AddError(new Error(messageErrors.InvalidItemHeader(headerItem), StartRow, header.IndexOf(headerItem)));
                }
                else
                {
                    validationResult.AddItem(headerItem);
                }
            }

            foreach (var expectedHeaderItem in expectedHeader)
            {
                if (!header.Contains(expectedHeaderItem))
                {
                    validationResult.AddError(new Error(messageErrors.MissingItemHeader(expectedHeaderItem), StartRow, StartColumn));
                }
            }

            return(validationResult);
        }
 public WorksheetInterpreter(ValueSetter valueSetter,
                             WorksheetMap <T> worksheetMap,
                             MessageErrors messageErrors)
 => (this.valueSetter, this.worksheetMap, this.messageErrors)
Пример #4
0
 public WorksheetParser(WorksheetInterpreter <T> parser, MessageErrors messageErrors)
 {
     this.parser        = parser;
     this.messageErrors = messageErrors;
 }