private void Validator_Column(List <TemplateFormatCAC> templateCAC, IXLTable table) { try { using (table) { DTOValidacionArchivo validation = null; foreach (TemplateFormatCAC template in templateCAC) { // Si el numero de columnas del formato es diferente a las del archivo if (templateCAC.Count != table.HeadersRow().CellCount()) { string concatHeader = ""; table.HeadersRow().CellsUsed().Select(m => m.Value.ToString()).ToList().Except(templateCAC.Select(m => m.Name).ToList()).ForEach(m => concatHeader = $"{concatHeader} {m}"); //table.HeadersRow().CellsUsed().ForEach(m => concatHeader = $"{concatHeader} {m.Value}"); validation = new DTOValidacionArchivo() { FechaCreacion = DateTime.Now.ToString(Configuration.GetValueConf(Constants.DateFormat)), Descripcion = string.Format(Resource_DefaultMessage.ERROR_COLUMNS_NOT_EQUALS, table.HeadersRow().CellCount(), templateCAC.Count), Valor = $"{concatHeader}", Celda = $"{table.HeadersRow().RangeAddress}", Fila = $"{table.HeadersRow().RangeAddress.FirstAddress.RowNumber}", Columna = $"{table.HeadersRow().RangeAddress.LastAddress.ColumnLetter}" }; Auditor.SaveLog(string.Format(Resource_DefaultMessage.CONTROL_VALUE, nameof(FileProcessBP.Validator_Column), validation.Columna, validation.Valor, "ERROR_COLUMNS_NOT_EQUALS", validation.ToString(), table.Worksheet.Name)); validator_result.Add(validation); } var field = table.Fields.Where(m => m.Name == template.Name).FirstOrDefault(); //Validacion de existencia de columna if (field == null) { validation = new DTOValidacionArchivo() { FechaCreacion = DateTime.Now.ToString(Configuration.GetValueConf(Constants.DateFormat)), Descripcion = string.Format(Resource_DefaultMessage.ERROR_COLUMN_MISSING_NAME, template.Name), Valor = template.Name, Celda = $"A1", Fila = $"1", Columna = $"A" }; Auditor.SaveLog(string.Format(Resource_DefaultMessage.CONTROL_VALUE, nameof(FileProcessBP.Validator_Column), validation.Columna, validation.Valor, "ERROR_COLUMN_MISSING_NAME", validation.ToString(), table.Worksheet.Name)); validator_result.Add(validation); } else { int field_index = field.Index + 1; IXLCells cells = table.Column(field_index).CellsUsed(); var values = cells.Select(m => m.Value).ToList(); values.RemoveAll(item => item == null || item.ToString() == ""); var duplicateKeys = values.GroupBy(x => x).Where(group => group.Count() > 1).Select(group => group.Key); //Validacion duplicados bool hasDuplicates = template.Duplicate == false && duplicateKeys.Count() > 0; //ValidaciĆ³n de existencia de filas if (table.Column(field_index).CellsUsed().Count() == 0) { var first = cells.OrderBy(m => m.Address).FirstOrDefault() != null?cells.OrderBy(m => m.Address).FirstOrDefault().Address.ToString() : ""; var last = cells.OrderByDescending(m => m.Address).FirstOrDefault() != null?cells.OrderByDescending(m => m.Address).FirstOrDefault().Address.ToString() : ""; validation = new DTOValidacionArchivo() { FechaCreacion = DateTime.Now.ToString(Configuration.GetValueConf(Constants.DateFormat)), Descripcion = string.Format(Resource_DefaultMessage.ERROR_COLUMN_NOT_DATA, template.Name), Valor = "", Celda = $"{first}:{last}", Fila = $"{table.HeadersRow().RangeAddress.FirstAddress.RowNumber}", Columna = $"{table.HeadersRow().RangeAddress.LastAddress.ColumnLetter}" }; Auditor.SaveLog(string.Format(Resource_DefaultMessage.CONTROL_VALUE, nameof(FileProcessBP.Validator_Column), validation.Columna, validation.Valor, "ERROR_COLUMN_NOT_DATA", validation.ToString(), table.Worksheet.Name)); validator_result.Add(validation); } if (hasDuplicates) { validation = new DTOValidacionArchivo() { FechaCreacion = DateTime.Now.ToString(Configuration.GetValueConf(Constants.DateFormat)), Descripcion = string.Format(Resource_DefaultMessage.ERROR_COLUMN_NOT_DUPLICATE_DATA, template.Name), Valor = "", Celda = $"{table.Column(field.Name).RangeAddress}", Fila = $"{table.Column(field.Name).RangeAddress.FirstAddress.RowNumber}", Columna = $"{table.Column(field.Name).RangeAddress.LastAddress.ColumnLetter}" }; Auditor.SaveLog(string.Format(Resource_DefaultMessage.CONTROL_VALUE, nameof(FileProcessBP.Validator_Column), validation.Columna, validation.Valor, "ERROR_COLUMN_NOT_DUPLICATE_DATA", validation.ToString(), table.Worksheet.Name)); validator_result.Add(validation); } } } } } catch (Exception ex) { validator_result.Add(ExceptionWriter(ex)); throw ex; } }