Change excel reading process

This commit is contained in:
Evgeny Redikultsev
2025-10-18 20:04:08 +05:00
parent 8d4c788a7e
commit 5bf01bcb09
21 changed files with 337 additions and 61 deletions

View File

@@ -35,6 +35,7 @@ namespace StructureHelperCommon.Models.Forces
if (ReferenceEquals(targetObject, sourceObject)) { return; }
InitializeLogics();
baseUpdateStrategy.Update(targetObject, sourceObject);
targetObject.SkipWrongRows = sourceObject.SkipWrongRows;
CheckObject.IsNull(targetObject.CombinationProperty, "Target object combination property");
CheckObject.IsNull(sourceObject.CombinationProperty, "Source object combination property");
combinationPropertyUpdateStrategy.Update(targetObject.CombinationProperty, sourceObject.CombinationProperty);

View File

@@ -24,6 +24,7 @@ namespace StructureHelperCommon.Models.Forces
public IShiftTraceLogger? TraceLogger { get; set; }
public IColumnedFileProperty ForceFileProperty { get; set; }
public bool SkipWrongRows { get; internal set; }
public IForceTuple GetForceTuple(IExcelDataReader? reader)
{
@@ -38,10 +39,24 @@ namespace StructureHelperCommon.Models.Forces
throw new StructureHelperException(ErrorStrings.NullReference + $": reader value for column {item.Name} in file {ForceFileProperty.FilePath}");
}
var readerValue = reader.GetValue(item.Index);
if (readerValue is null)
{
if (SkipWrongRows == true)
{
continue;
}
else
{
throw new StructureHelperException(ErrorStrings.NullReference + $": wrong row in file {ForceFileProperty.FilePath}, total row number n = {reader.RowCount}");
}
}
var strValue = readerValue.ToString();
double factor = ForceFileProperty.GlobalFactor * item.Factor * 1000d;
var doubleValue = Convert.ToDouble(strValue) * factor;
fillArrayLogic ??= new FillTupleArrayByColumnNameLogic() { TraceLogger = TraceLogger };
fillArrayLogic ??= new FillTupleArrayByColumnNameLogic()
{
TraceLogger = TraceLogger
};
fillArrayLogic.ProceeForceTupleArray(nDouble, doubleValue, item.Name, ForceFileProperty.FilePath);
}
TraceLogger?.AddMessage($"String values: Nz = {nDouble[0]}, Mx = {nDouble[1]}, My = {nDouble[2]} were gained", TraceLogStatuses.Debug);

View File

@@ -4,6 +4,7 @@ using StructureHelperCommon.Infrastructures.Interfaces;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
@@ -35,6 +36,7 @@ namespace StructureHelperCommon.Models.Forces
public IColumnedFileProperty ForceFileProperty { get; set; }
public IShiftTraceLogger? TraceLogger { get; set; }
public bool SkipWrongRows { get; set; } = false;
public List<IForceTuple> GetTuples()
{
@@ -56,7 +58,7 @@ namespace StructureHelperCommon.Models.Forces
// Create an Excel reader
using (var reader = ExcelReaderFactory.CreateReader(stream))
{
// Skip the first two header rows if necessary (adjust based on structure)
// Skip the first header rows if necessary (adjust based on structure)
for (int i = 0; i < skipRows; i++)
{
reader.Read(); // Skip row
@@ -65,7 +67,8 @@ namespace StructureHelperCommon.Models.Forces
excelReaderLogic ??= new GetTupleByExcelReaderLogic()
{
ForceFileProperty = ForceFileProperty,
TraceLogger = TraceLogger
TraceLogger = TraceLogger,
SkipWrongRows = SkipWrongRows
};
// Loop through the rows
@@ -74,11 +77,13 @@ namespace StructureHelperCommon.Models.Forces
try
{
IForceTuple newTuple = excelReaderLogic.GetForceTuple(reader);
result.Add(newTuple);
if (! result.Any(x => x.Mx == newTuple.Mx && x.My == newTuple.My && x.Nz == newTuple.Nz))
{
result.Add(newTuple);
}
}
catch (Exception ex)
{
//to do implement case when file has a data in the row, but thus date is not correct
string errorString = ErrorStrings.DataIsInCorrect + $": incorrect data in file {ForceFileProperty.FilePath}, " + ex.Message;
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
throw new StructureHelperException(errorString);

View File

@@ -5,6 +5,7 @@ namespace StructureHelperCommon.Models.Forces
{
public interface IGetTuplesFromFileLogic : ILogic
{
bool SkipWrongRows { get; set; }
IColumnedFileProperty ForceFileProperty { get; set; }
List<IForceTuple> GetTuples();