Compare commits
9 Commits
e67d94f199
...
8b125e475e
Author | SHA1 | Date | |
---|---|---|---|
|
8b125e475e | ||
|
0e15ad7cd4 | ||
|
f6534fc8c7 | ||
|
51636ca61a | ||
|
f1abb03ac9 | ||
|
656f565152 | ||
|
ab217c9052 | ||
|
65d027179c | ||
|
f620147515 |
@ -161,7 +161,7 @@ public class RhSolutionsFunction
|
||||
.GetResult()
|
||||
.FirstOrDefault();
|
||||
|
||||
DateTime date = dateField == 0 ? DateTime.Now : DateTime.FromOADate(dateField);
|
||||
DateTime date = dateField == 0 ? DateTime.Today : DateTime.FromOADate(dateField);
|
||||
var exchangeRate = currencyClient.GetCurrencyCourse(date)
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
@ -193,7 +193,7 @@ public class RhSolutionsFunction
|
||||
|
||||
if (ExcelAsyncUtil.Run("Database request", dateField, delegate
|
||||
{
|
||||
DateTime date = dateField == 0 ? DateTime.Now : DateTime.FromOADate(dateField);
|
||||
DateTime date = dateField == 0 ? DateTime.Today : DateTime.FromOADate(dateField);
|
||||
var exchangeRate = currencyClient.GetCurrencyCourse(date)
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
|
@ -84,7 +84,7 @@ public class RibbonController : ExcelRibbon
|
||||
|
||||
public bool GetConvertEnabled(IRibbonControl control) => _workbookIsValid;
|
||||
public bool GetDxfEnabled(IRibbonControl control) => _workbookIsValid;
|
||||
public bool GetGuessEnabled(IRibbonControl control) => RhSolutionsAddIn.Excel.ActiveWorkbook == null ? false : !_workbookIsValid;
|
||||
public bool GetGuessEnabled(IRibbonControl control) => RhSolutionsAddIn.Excel.ActiveWorkbook != null && !_workbookIsValid;
|
||||
|
||||
public bool GetExportEnabled(IRibbonControl control)
|
||||
{
|
||||
|
@ -1,5 +1,4 @@
|
||||
using Microsoft.Office.Interop.Excel;
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
|
||||
namespace RhSolutions.Services;
|
||||
|
||||
@ -47,19 +46,21 @@ public class GuessReader : IReader
|
||||
}
|
||||
if (currentIndex > productColumnIndex)
|
||||
{
|
||||
if (IsAmountColumn(range.Columns[currentIndex++]))
|
||||
if (IsAmountColumn(range.Columns[currentIndex]))
|
||||
{
|
||||
amountColumnIndex = currentIndex - 1;
|
||||
amountColumnIndex = currentIndex;
|
||||
break;
|
||||
}
|
||||
else currentIndex++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IsAmountColumn(range.Columns[currentIndex--]))
|
||||
if (IsAmountColumn(range.Columns[currentIndex]))
|
||||
{
|
||||
amountColumnIndex = currentIndex + 1;
|
||||
amountColumnIndex = currentIndex;
|
||||
break;
|
||||
}
|
||||
else currentIndex--;
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,7 +94,7 @@ public class GuessReader : IReader
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ProductSku.TryParse(currentCell.ToString(), out IEnumerable<ProductSku> skus))
|
||||
if (ProductSku.TryParse(currentCell.ToString(), out _))
|
||||
{
|
||||
successCounter++;
|
||||
}
|
||||
@ -111,39 +112,43 @@ public class GuessReader : IReader
|
||||
{
|
||||
int successCounter = 0;
|
||||
var cells = column.Value2;
|
||||
double maxValue = 30000;
|
||||
|
||||
if (cells == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (column.Rows.Count == 1)
|
||||
{
|
||||
double? value = cells as double?;
|
||||
|
||||
return value != null
|
||||
&& value != 0
|
||||
&& value < maxValue;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
for (int row = 1; row < column.Rows.Count + 1; row++)
|
||||
{
|
||||
object currentCell = column.Rows.Count == 1 ? cells : cells[row, 1];
|
||||
if (currentCell == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
object currentCell = cells[row, 1];
|
||||
double? value = currentCell as double?;
|
||||
|
||||
if (value == null || value == 0)
|
||||
if (value == null
|
||||
|| value == 0
|
||||
|| value > maxValue)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (value > 30000)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (++successCounter > 3)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return successCounter > 0;
|
||||
}
|
||||
return successCounter > 1;
|
||||
}
|
||||
|
||||
private Dictionary<Product, double> GetDictionaryFromColumns(Range productColumn, Range amountColumn)
|
||||
|
@ -15,7 +15,7 @@ public class ReaderFactory
|
||||
{
|
||||
"Guess" => (IReader)_serviceProvider.GetService(typeof(GuessReader)),
|
||||
"Excel" => (IReader)_serviceProvider.GetService(typeof(ExcelReader)),
|
||||
_ => (IReader)_serviceProvider.GetService(typeof(ExcelReader))
|
||||
_ => throw new ArgumentException($"Незвестный интерфейс {nameof(IReader)}: {readerName}")
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public class WriterFactory
|
||||
{
|
||||
"Excel" => (IWriter)_serviceProvider.GetService(typeof(ExcelWriter)),
|
||||
"Dxf" => (IWriter)_serviceProvider.GetService(typeof(DxfWriter)),
|
||||
_ => (IWriter)_serviceProvider.GetService(typeof(ExcelWriter))
|
||||
_ => throw new ArgumentException($"Незвестный интерфейс {nameof(IWriter)}: {writerName}")
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ internal class ToolFactory
|
||||
"merge" => new MergeTool(RhSolutionsAddIn.ServiceProvider),
|
||||
"dxfexport" => new DxfTool(RhSolutionsAddIn.ServiceProvider),
|
||||
"Guessexport" => new GuessTool(RhSolutionsAddIn.ServiceProvider),
|
||||
_ => throw new Exception("Неизвестный инструмент"),
|
||||
_ => throw new Exception($"Неизвестный инструмент {toolName}"),
|
||||
};
|
||||
return tool;
|
||||
}
|
||||
|
@ -8,13 +8,15 @@ namespace RhSolutions.Tests;
|
||||
public class CanDoGuess : IDisposable
|
||||
{
|
||||
private RhSolutionsAddIn _addIn;
|
||||
private IReader _guessReader;
|
||||
private IReader _reader;
|
||||
|
||||
public CanDoGuess()
|
||||
{
|
||||
_addIn = new();
|
||||
_addIn.AutoOpen();
|
||||
_reader = new GuessReader(Util.Application);
|
||||
_guessReader = new GuessReader(Util.Application);
|
||||
_reader = new ExcelReader(Util.Application, RhSolutionsAddIn.Configuration);
|
||||
}
|
||||
|
||||
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\TestSpecificationGuess.xlsx")]
|
||||
@ -22,7 +24,7 @@ public class CanDoGuess : IDisposable
|
||||
{
|
||||
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationGuess.xlsx"));
|
||||
var products = _reader.ReadProducts(new[] { sourceSheet });
|
||||
var products = _guessReader.ReadProducts(new[] { sourceSheet });
|
||||
var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||
_writer.WriteProducts(products);
|
||||
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
||||
@ -39,7 +41,7 @@ public class CanDoGuess : IDisposable
|
||||
{
|
||||
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationGuessOneRow.xlsx"));
|
||||
var products = _reader.ReadProducts(new[] { sourceSheet });
|
||||
var products = _guessReader.ReadProducts(new[] { sourceSheet });
|
||||
var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||
_writer.WriteProducts(products);
|
||||
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user