Compare commits
5 Commits
c1949a2159
...
e14d714811
Author | SHA1 | Date | |
---|---|---|---|
e14d714811 | |||
47c3b19a17 | |||
1f5aebe62a | |||
159ac0ec57 | |||
|
d6de208df4 |
@ -1,16 +0,0 @@
|
|||||||
#if !NET472
|
|
||||||
using System.Runtime.Versioning;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace RhSolutions.AddIn;
|
|
||||||
#if !NET472
|
|
||||||
[SupportedOSPlatform("windows")]
|
|
||||||
#endif
|
|
||||||
public static class ResetBarFunction
|
|
||||||
{
|
|
||||||
[ExcelFunction]
|
|
||||||
public static void StatusBarReset()
|
|
||||||
{
|
|
||||||
RhSolutionsAddIn.Excel.StatusBar = false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,6 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using ExcelDna.IntelliSense;
|
using ExcelDna.IntelliSense;
|
||||||
|
using Microsoft.Office.Interop.Excel;
|
||||||
#if !NET472
|
#if !NET472
|
||||||
using System.Runtime.Versioning;
|
using System.Runtime.Versioning;
|
||||||
#endif
|
#endif
|
||||||
|
@ -119,8 +119,8 @@ public class RibbonController : ExcelRibbon
|
|||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Worksheet worksheet = RhSolutionsAddIn.Excel.ActiveWorkbook.ActiveSheet;
|
WorksheetValidator.Validate(RhSolutionsAddIn.Excel.ActiveSheet);
|
||||||
_workbookIsValid = worksheet.IsValidSource();
|
_workbookIsValid = WorksheetValidator.IsValid();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ public class ExcelReader : IReader, IDisposable
|
|||||||
List<(string, Dictionary<Product, double>)> result = new();
|
List<(string, Dictionary<Product, double>)> result = new();
|
||||||
foreach (Worksheet worksheet in worksheets)
|
foreach (Worksheet worksheet in worksheets)
|
||||||
{
|
{
|
||||||
if (!worksheet.IsValidSource())
|
if (!WorksheetValidator.IsValid())
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -93,26 +93,27 @@ public class ExcelReader : IReader, IDisposable
|
|||||||
string wbName = Path.GetFileNameWithoutExtension(
|
string wbName = Path.GetFileNameWithoutExtension(
|
||||||
worksheet.Parent.Name);
|
worksheet.Parent.Name);
|
||||||
|
|
||||||
Range AmountCell = worksheet.Cells.Find(headers["Amount"]),
|
Range amountCell = WorksheetValidator.HeaderCells["Amount"],
|
||||||
SkuCell = worksheet.Cells.Find(headers["Sku"]),
|
skuCell = WorksheetValidator.HeaderCells["Sku"],
|
||||||
ProductLineCell = worksheet.Cells.Find(headers["ProductLine"]),
|
productLineCell = WorksheetValidator.HeaderCells["ProductLine"],
|
||||||
NameCell = worksheet.Cells.Find(headers["Name"]),
|
nameCell = WorksheetValidator.HeaderCells["Name"],
|
||||||
MeasureCell = worksheet.Cells.Find(headers["Measure"]);
|
measureCell = WorksheetValidator.HeaderCells["Measure"];
|
||||||
var lastRowIndex = worksheet.Cells[worksheet.Rows.Count, SkuCell.Column]
|
|
||||||
|
var lastRowIndex = worksheet.Cells[worksheet.Rows.Count, skuCell.Column]
|
||||||
.End[XlDirection.xlUp].Row;
|
.End[XlDirection.xlUp].Row;
|
||||||
|
|
||||||
Dictionary<Product, double> readResult = new();
|
Dictionary<Product, double> readResult = new();
|
||||||
|
|
||||||
for (int row = AmountCell.Row + 1; row <= lastRowIndex; row++)
|
for (int row = amountCell.Row + 1; row <= lastRowIndex; row++)
|
||||||
{
|
{
|
||||||
double? amount = worksheet.Cells[row, AmountCell.Column].Value2 as double?;
|
double? amount = worksheet.Cells[row, amountCell.Column].Value2 as double?;
|
||||||
|
|
||||||
if (amount != null && amount.Value != 0)
|
if (amount != null && amount.Value != 0)
|
||||||
{
|
{
|
||||||
object productLine = worksheet.Cells[row, ProductLineCell.Column].Value2;
|
object productLine = worksheet.Cells[row, productLineCell.Column].Value2;
|
||||||
object name = worksheet.Cells[row, NameCell.Column].Value2;
|
object name = worksheet.Cells[row, nameCell.Column].Value2;
|
||||||
object sku = worksheet.Cells[row, SkuCell.Column].Value2;
|
object sku = worksheet.Cells[row, skuCell.Column].Value2;
|
||||||
object measure = worksheet.Cells[row, MeasureCell.Column].Value2;
|
object measure = worksheet.Cells[row, measureCell.Column].Value2;
|
||||||
var productMeasure = measure?.ToString() switch
|
var productMeasure = measure?.ToString() switch
|
||||||
{
|
{
|
||||||
"м" => Measure.M,
|
"м" => Measure.M,
|
||||||
|
@ -31,7 +31,7 @@ namespace RhSolutions.Services
|
|||||||
|
|
||||||
public void WriteProducts(IEnumerable<(string, Dictionary<Product, double>)> products)
|
public void WriteProducts(IEnumerable<(string, Dictionary<Product, double>)> products)
|
||||||
{
|
{
|
||||||
if (!_worksheet.IsValidSource())
|
if (!WorksheetValidator.IsValid())
|
||||||
{
|
{
|
||||||
_application.ActiveWorkbook.Close();
|
_application.ActiveWorkbook.Close();
|
||||||
throw new ArgumentException(
|
throw new ArgumentException(
|
||||||
@ -40,11 +40,11 @@ namespace RhSolutions.Services
|
|||||||
|
|
||||||
ShowFilteredData();
|
ShowFilteredData();
|
||||||
|
|
||||||
_amountCell = _worksheet.Cells.Find(_headers["Amount"]);
|
_amountCell = WorksheetValidator.HeaderCells["Amount"];
|
||||||
_skuCell = _worksheet.Cells.Find(_headers["Sku"]);
|
_skuCell = WorksheetValidator.HeaderCells["Sku"];
|
||||||
_programLineCell = _worksheet.Cells.Find(_headers["ProductLine"]);
|
_programLineCell = WorksheetValidator.HeaderCells["ProductLine"];
|
||||||
_nameCell = _worksheet.Cells.Find(_headers["Name"]);
|
_nameCell = WorksheetValidator.HeaderCells["Name"];
|
||||||
_oldSkuCell = _worksheet.Cells.Find(_headers["OldSku"]);
|
_oldSkuCell = WorksheetValidator.HeaderCells["OldSku"];
|
||||||
|
|
||||||
_progressBar = new("Заполняю строки...", products
|
_progressBar = new("Заполняю строки...", products
|
||||||
.Select(p => p.Item2)
|
.Select(p => p.Item2)
|
||||||
|
@ -5,7 +5,7 @@ namespace RhSolutions.Services;
|
|||||||
public class SleevesCalculator : ISleevesCalculator
|
public class SleevesCalculator : ISleevesCalculator
|
||||||
{
|
{
|
||||||
private const string doublePattern =
|
private const string doublePattern =
|
||||||
@"((?i)равнопроходная|угольник 90|угольник 45|Т-образная|Комплект трубок(?i))(.+?(?<Sleeve>\b16\b|\b20\b|\b25\b|\b32\b|\b40\b|\b50\b|\b63\b))+";
|
@"((?i)равнопроходная|угольник\s+90|угольник\s+45|Т-образная|Комплект\s+трубок(?i))(.+?(?<Sleeve>\b16\b|\b20\b|\b25\b|\b32\b|\b40\b|\b50\b|\b63\b))+";
|
||||||
private const string singlePattern =
|
private const string singlePattern =
|
||||||
@"((?i)муфта|тройник|переходник|угольник|штуцер|Г-образная|заглушка(?i))(.+?(?<Sleeve>\b16\b|\b20\b|\b25\b|\b32\b|\b40\b|\b50\b|\b63\b))+";
|
@"((?i)муфта|тройник|переходник|угольник|штуцер|Г-образная|заглушка(?i))(.+?(?<Sleeve>\b16\b|\b20\b|\b25\b|\b32\b|\b40\b|\b50\b|\b63\b))+";
|
||||||
|
|
||||||
|
50
RhSolutions.AddIn/Services/WorksheetValidator.cs
Normal file
50
RhSolutions.AddIn/Services/WorksheetValidator.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#if !NET472
|
||||||
|
using System.Runtime.Versioning;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace RhSolutions.Services;
|
||||||
|
|
||||||
|
public static class WorksheetValidator
|
||||||
|
{
|
||||||
|
public static Dictionary<string, Range> HeaderCells { get; private set; }
|
||||||
|
|
||||||
|
public static void Validate(this Worksheet worksheet)
|
||||||
|
{
|
||||||
|
Range headerRow = null;
|
||||||
|
HeaderCells = new();
|
||||||
|
var headers = RhSolutionsAddIn.Configuration.GetPriceListHeaders();
|
||||||
|
|
||||||
|
foreach (var kvp in headers)
|
||||||
|
{
|
||||||
|
Range cell;
|
||||||
|
|
||||||
|
if (headerRow == null)
|
||||||
|
{
|
||||||
|
cell = worksheet.Cells.Find(kvp.Value);
|
||||||
|
if (cell == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
headerRow = cell.EntireRow;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cell = headerRow.Cells.Find(kvp.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (HeaderCells.ContainsKey(kvp.Key))
|
||||||
|
{
|
||||||
|
HeaderCells[kvp.Key] = cell;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HeaderCells.Add(kvp.Key, cell);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsValid()
|
||||||
|
{
|
||||||
|
return HeaderCells.Count >= RhSolutionsAddIn.Configuration.GetPriceListHeaders().Count - 1;
|
||||||
|
}
|
||||||
|
}
|
@ -15,6 +15,12 @@ public abstract class StatusbarBase : IDisposable
|
|||||||
{
|
{
|
||||||
protected Application Excel = RhSolutionsAddIn.Excel;
|
protected Application Excel = RhSolutionsAddIn.Excel;
|
||||||
|
|
||||||
|
[ExcelFunction(IsHidden = true)]
|
||||||
|
public static void StatusBarReset()
|
||||||
|
{
|
||||||
|
RhSolutionsAddIn.Excel.StatusBar = false;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void Update();
|
public abstract void Update();
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
@ -9,29 +9,6 @@ namespace RhSolutions.Tools;
|
|||||||
#endif
|
#endif
|
||||||
public static class WorksheetExtensions
|
public static class WorksheetExtensions
|
||||||
{
|
{
|
||||||
private static readonly Dictionary<string, string> pricelistParameters =
|
|
||||||
RhSolutionsAddIn.Configuration.GetPriceListHeaders();
|
|
||||||
|
|
||||||
public static bool IsValidSource(this Worksheet worksheet)
|
|
||||||
{
|
|
||||||
Range amountCell;
|
|
||||||
Range skuCell;
|
|
||||||
Range programLineCell;
|
|
||||||
Range nameCell;
|
|
||||||
Range measureCell;
|
|
||||||
|
|
||||||
Range[] cells = new[]
|
|
||||||
{
|
|
||||||
amountCell = worksheet.Cells.Find(pricelistParameters["Amount"]),
|
|
||||||
skuCell = worksheet.Cells.Find(pricelistParameters["Sku"]),
|
|
||||||
programLineCell = worksheet.Cells.Find(pricelistParameters["ProductLine"]),
|
|
||||||
nameCell = worksheet.Cells.Find(pricelistParameters["Name"]),
|
|
||||||
measureCell = worksheet.Cells.Find(pricelistParameters["Measure"])
|
|
||||||
};
|
|
||||||
|
|
||||||
return cells.All(x => x != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AddValue(this Range range, double value)
|
public static void AddValue(this Range range, double value)
|
||||||
{
|
{
|
||||||
if (range.Value2 == null)
|
if (range.Value2 == null)
|
||||||
|
@ -23,11 +23,13 @@ public class CanDoGuess : IDisposable
|
|||||||
public void CanWriteMultiplyRows()
|
public void CanWriteMultiplyRows()
|
||||||
{
|
{
|
||||||
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||||
|
sourceSheet.Validate();
|
||||||
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationGuess.xlsx"));
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationGuess.xlsx"));
|
||||||
var products = _guessReader.ReadProducts(new[] { sourceSheet });
|
var products = _guessReader.ReadProducts(new[] { sourceSheet });
|
||||||
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
_writer.WriteProducts(products);
|
_writer.WriteProducts(products);
|
||||||
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
||||||
|
targetSheet.Validate();
|
||||||
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
||||||
|
|
||||||
Assert.Equal("TestSpecificationGuess", products.First().Item1);
|
Assert.Equal("TestSpecificationGuess", products.First().Item1);
|
||||||
@ -40,11 +42,13 @@ public class CanDoGuess : IDisposable
|
|||||||
public void CanWriteOneRow()
|
public void CanWriteOneRow()
|
||||||
{
|
{
|
||||||
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||||
|
sourceSheet.Validate();
|
||||||
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationGuessOneRow.xlsx"));
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationGuessOneRow.xlsx"));
|
||||||
var products = _guessReader.ReadProducts(new[] { sourceSheet });
|
var products = _guessReader.ReadProducts(new[] { sourceSheet });
|
||||||
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
_writer.WriteProducts(products);
|
_writer.WriteProducts(products);
|
||||||
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
||||||
|
targetSheet.Validate();
|
||||||
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
||||||
|
|
||||||
Assert.Equal("TestSpecificationGuessOneRow", products.First().Item1);
|
Assert.Equal("TestSpecificationGuessOneRow", products.First().Item1);
|
||||||
|
@ -24,6 +24,7 @@ public class CanFillSleeves : IDisposable
|
|||||||
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\TestSpecificationSleeves.xlsx")]
|
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\TestSpecificationSleeves.xlsx")]
|
||||||
public void CanCalculateSleeves()
|
public void CanCalculateSleeves()
|
||||||
{
|
{
|
||||||
|
_worksheet.Validate();
|
||||||
var products = _reader.ReadProducts(new[] { _worksheet });
|
var products = _reader.ReadProducts(new[] { _worksheet });
|
||||||
var sleeves = _calculator.CalculateSleeves(products.First().Item2);
|
var sleeves = _calculator.CalculateSleeves(products.First().Item2);
|
||||||
_writer.WriteProducts(sleeves);
|
_writer.WriteProducts(sleeves);
|
||||||
|
@ -22,6 +22,7 @@ public class CanReadProducts : IDisposable
|
|||||||
public void CanReadRange()
|
public void CanReadRange()
|
||||||
{
|
{
|
||||||
Worksheet worksheet = _testWorkbook.Sheets[1];
|
Worksheet worksheet = _testWorkbook.Sheets[1];
|
||||||
|
worksheet.Validate();
|
||||||
worksheet.Range["A1"].Value = "11600011001";
|
worksheet.Range["A1"].Value = "11600011001";
|
||||||
worksheet.Range["A2"].Value = "11600011001";
|
worksheet.Range["A2"].Value = "11600011001";
|
||||||
worksheet.Range["A3"].Value = "160002-001";
|
worksheet.Range["A3"].Value = "160002-001";
|
||||||
@ -49,6 +50,7 @@ public class CanReadProducts : IDisposable
|
|||||||
public void CanReadWorkbook()
|
public void CanReadWorkbook()
|
||||||
{
|
{
|
||||||
Worksheet worksheet = Util.Workbook.Worksheets[1];
|
Worksheet worksheet = Util.Workbook.Worksheets[1];
|
||||||
|
worksheet.Validate();
|
||||||
var result = _reader.ReadProducts(new[] { worksheet });
|
var result = _reader.ReadProducts(new[] { worksheet });
|
||||||
Assert.NotNull(result);
|
Assert.NotNull(result);
|
||||||
Assert.NotEmpty(result);
|
Assert.NotEmpty(result);
|
||||||
|
@ -21,11 +21,13 @@ public class CanWriteProducts : IDisposable
|
|||||||
public void CanWriteSingle()
|
public void CanWriteSingle()
|
||||||
{
|
{
|
||||||
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||||
|
sourceSheet.Validate();
|
||||||
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecification.xlsx"));
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecification.xlsx"));
|
||||||
var products = _reader.ReadProducts(new[] { sourceSheet });
|
var products = _reader.ReadProducts(new[] { sourceSheet });
|
||||||
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
_writer.WriteProducts(products);
|
_writer.WriteProducts(products);
|
||||||
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
||||||
|
targetSheet.Validate();
|
||||||
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
||||||
|
|
||||||
Assert.Equal("TestSpecification", products.First().Item1);
|
Assert.Equal("TestSpecification", products.First().Item1);
|
||||||
@ -38,11 +40,13 @@ public class CanWriteProducts : IDisposable
|
|||||||
public void CanWriteMultipleProductLines()
|
public void CanWriteMultipleProductLines()
|
||||||
{
|
{
|
||||||
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||||
|
sourceSheet.Validate();
|
||||||
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationMultipleProductLines.xlsx"));
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationMultipleProductLines.xlsx"));
|
||||||
var products = _reader.ReadProducts(new[] { sourceSheet });
|
var products = _reader.ReadProducts(new[] { sourceSheet });
|
||||||
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
_writer.WriteProducts(products);
|
_writer.WriteProducts(products);
|
||||||
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
||||||
|
targetSheet.Validate();
|
||||||
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
||||||
|
|
||||||
Assert.Equal("TestSpecificationMultipleProductLines", products.First().Item1);
|
Assert.Equal("TestSpecificationMultipleProductLines", products.First().Item1);
|
||||||
@ -55,11 +59,13 @@ public class CanWriteProducts : IDisposable
|
|||||||
public void CanWriteNotFound()
|
public void CanWriteNotFound()
|
||||||
{
|
{
|
||||||
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||||
|
sourceSheet.Validate();
|
||||||
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationNotFound.xlsx"));
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationNotFound.xlsx"));
|
||||||
var products = _reader.ReadProducts(new[] { sourceSheet });
|
var products = _reader.ReadProducts(new[] { sourceSheet });
|
||||||
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
_writer.WriteProducts(products);
|
_writer.WriteProducts(products);
|
||||||
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
||||||
|
targetSheet.Validate();
|
||||||
|
|
||||||
Assert.Equal("???", targetSheet.Range["B4"].Value2);
|
Assert.Equal("???", targetSheet.Range["B4"].Value2);
|
||||||
Assert.Contains("Молот Тора", targetSheet.Range["C4"].Value2);
|
Assert.Contains("Молот Тора", targetSheet.Range["C4"].Value2);
|
||||||
@ -70,11 +76,13 @@ public class CanWriteProducts : IDisposable
|
|||||||
public void CanWriteReplaced()
|
public void CanWriteReplaced()
|
||||||
{
|
{
|
||||||
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||||
|
sourceSheet.Validate();
|
||||||
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationReplaced.xlsx"));
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationReplaced.xlsx"));
|
||||||
var products = _reader.ReadProducts(new[] { sourceSheet });
|
var products = _reader.ReadProducts(new[] { sourceSheet });
|
||||||
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
_writer.WriteProducts(products);
|
_writer.WriteProducts(products);
|
||||||
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
||||||
|
targetSheet.Validate();
|
||||||
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
||||||
|
|
||||||
Assert.Equal("TestSpecificationReplaced", products.First().Item1);
|
Assert.Equal("TestSpecificationReplaced", products.First().Item1);
|
||||||
@ -92,11 +100,13 @@ public class CanWriteProducts : IDisposable
|
|||||||
public void CanWriteNewVariant()
|
public void CanWriteNewVariant()
|
||||||
{
|
{
|
||||||
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||||
|
sourceSheet.Validate();
|
||||||
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationNewVariant.xlsx"));
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationNewVariant.xlsx"));
|
||||||
var products = _reader.ReadProducts(new[] { sourceSheet });
|
var products = _reader.ReadProducts(new[] { sourceSheet });
|
||||||
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
_writer.WriteProducts(products);
|
_writer.WriteProducts(products);
|
||||||
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
||||||
|
targetSheet.Validate();
|
||||||
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
||||||
|
|
||||||
Assert.Equal("TestSpecificationNewVariant", products.First().Item1);
|
Assert.Equal("TestSpecificationNewVariant", products.First().Item1);
|
||||||
|
@ -21,11 +21,13 @@ public class RealPricelistTest : IDisposable
|
|||||||
public void CanWrite()
|
public void CanWrite()
|
||||||
{
|
{
|
||||||
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
||||||
|
sourceSheet.Validate();
|
||||||
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\RealTargetSpecification.xlsx"));
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\RealTargetSpecification.xlsx"));
|
||||||
var products = _reader.ReadProducts(new[] { sourceSheet });
|
var products = _reader.ReadProducts(new[] { sourceSheet });
|
||||||
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
||||||
_writer.WriteProducts(products);
|
_writer.WriteProducts(products);
|
||||||
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
||||||
|
targetSheet.Validate();
|
||||||
targetSheet.Range["A1"].Formula = "=SUM(H:H)";
|
targetSheet.Range["A1"].Formula = "=SUM(H:H)";
|
||||||
|
|
||||||
Assert.Equal("RealTestSpecification", products.First().Item1);
|
Assert.Equal("RealTestSpecification", products.First().Item1);
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using RhSolutions.AddIn;
|
using RhSolutions.AddIn;
|
||||||
using RhSolutions.Tools;
|
|
||||||
|
|
||||||
namespace RhSolutions.Tests;
|
namespace RhSolutions.Tests;
|
||||||
|
|
||||||
@ -18,15 +17,17 @@ public class WorkbookValidationTests : IDisposable
|
|||||||
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\EmptyTestTable.xlsx")]
|
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\EmptyTestTable.xlsx")]
|
||||||
public void WorksheetIsCorrect()
|
public void WorksheetIsCorrect()
|
||||||
{
|
{
|
||||||
Worksheet worksheet = Util.Workbook.Sheets[1];
|
Worksheet ws = Util.Workbook.Sheets[1];
|
||||||
Assert.True(worksheet.IsValidSource());
|
ws.Validate();
|
||||||
|
Assert.True(WorksheetValidator.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\EmptyWorkbook.xlsx")]
|
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\EmptyWorkbook.xlsx")]
|
||||||
public void EmptyWorkbookIsNotCorrect()
|
public void EmptyWorkbookIsNotCorrect()
|
||||||
{
|
{
|
||||||
Worksheet worksheet = Util.Workbook.Sheets[1];
|
Worksheet ws = Util.Workbook.Sheets[1];
|
||||||
Assert.False(worksheet.IsValidSource());
|
ws.Validate();
|
||||||
|
Assert.False(WorksheetValidator.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user