Extract PriceList Base Class
This commit is contained in:
parent
233c91c71b
commit
8e3dff1788
@ -8,13 +8,13 @@ namespace RehauSku.PriceListTools
|
|||||||
internal abstract class AbstractPriceListTool
|
internal abstract class AbstractPriceListTool
|
||||||
{
|
{
|
||||||
protected private Application ExcelApp;
|
protected private Application ExcelApp;
|
||||||
protected private PriceList NewPriceList;
|
protected private SourceFile NewPriceList;
|
||||||
protected private List<PriceList> sourcePriceLists;
|
protected private List<SourceFile> sourcePriceLists;
|
||||||
|
|
||||||
public AbstractPriceListTool()
|
public AbstractPriceListTool()
|
||||||
{
|
{
|
||||||
ExcelApp = (Application)ExcelDnaUtil.Application;
|
ExcelApp = (Application)ExcelDnaUtil.Application;
|
||||||
sourcePriceLists = new List<PriceList>();
|
sourcePriceLists = new List<SourceFile>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected private void FilterByAmount()
|
protected private void FilterByAmount()
|
||||||
@ -31,7 +31,7 @@ namespace RehauSku.PriceListTools
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NewPriceList = new PriceList(wb);
|
NewPriceList = new SourceFile(wb);
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -58,7 +58,7 @@ namespace RehauSku.PriceListTools
|
|||||||
Workbook wb = ExcelApp.Workbooks.Open(file);
|
Workbook wb = ExcelApp.Workbooks.Open(file);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PriceList priceList = new PriceList(wb);
|
SourceFile priceList = new SourceFile(wb);
|
||||||
sourcePriceLists.Add(priceList);
|
sourcePriceLists.Add(priceList);
|
||||||
wb.Close();
|
wb.Close();
|
||||||
}
|
}
|
||||||
|
@ -1,83 +1,18 @@
|
|||||||
using Microsoft.Office.Interop.Excel;
|
using Microsoft.Office.Interop.Excel;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace RehauSku.PriceListTools
|
namespace RehauSku.PriceListTools
|
||||||
{
|
{
|
||||||
internal class PriceList
|
internal class PriceList
|
||||||
{
|
{
|
||||||
private const string amountHeader = "Кол-во";
|
protected const string amountHeader = "Кол-во";
|
||||||
private const string skuHeader = "Актуальный материал";
|
protected const string skuHeader = "Актуальный материал";
|
||||||
private const string groupHeader = "Программа";
|
protected const string groupHeader = "Программа";
|
||||||
|
|
||||||
public readonly Worksheet Sheet;
|
public Range amountCell { get; protected set; }
|
||||||
public readonly string Name;
|
public Range skuCell { get; protected set; }
|
||||||
public Dictionary<string, double> SkuAmount { get; private set; }
|
public Range groupCell { get; protected set; }
|
||||||
|
|
||||||
public readonly Range amountCell;
|
public Worksheet Sheet { get; protected set; }
|
||||||
public readonly Range skuCell;
|
public string Name { get; protected set; }
|
||||||
public readonly Range groupCell;
|
|
||||||
|
|
||||||
//public Dictionary<PriceListPosition, Range> Map { get; private set; }
|
|
||||||
|
|
||||||
public PriceList(Workbook workbook)
|
|
||||||
{
|
|
||||||
Sheet = workbook.ActiveSheet;
|
|
||||||
Name = workbook.Name + '\n' + Sheet.Name;
|
|
||||||
|
|
||||||
amountCell = Sheet.Cells.Find(amountHeader);
|
|
||||||
skuCell = Sheet.Cells.Find(skuHeader);
|
|
||||||
groupCell = Sheet.Cells.Find(groupHeader);
|
|
||||||
|
|
||||||
if (amountCell == null || skuCell == null || groupCell == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentException($"Лист { Name } не распознан");
|
|
||||||
}
|
|
||||||
|
|
||||||
FillSkuAmount();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FillSkuAmount()
|
|
||||||
{
|
|
||||||
SkuAmount = new Dictionary<string, double>();
|
|
||||||
|
|
||||||
object[,] amountColumn = Sheet.Columns[amountCell.Column].Value2;
|
|
||||||
object[,] skuColumn = Sheet.Columns[skuCell.Column].Value2;
|
|
||||||
|
|
||||||
for (int row = amountCell.Row + 1; row < amountColumn.GetLength(0); row++)
|
|
||||||
{
|
|
||||||
object amount = amountColumn[row, 1];
|
|
||||||
object sku = skuColumn[row, 1];
|
|
||||||
|
|
||||||
if (amount != null && (double)amount != 0)
|
|
||||||
{
|
|
||||||
if (SkuAmount.ContainsKey(sku.ToString()))
|
|
||||||
SkuAmount[sku.ToString()] += (double)amount;
|
|
||||||
|
|
||||||
else
|
|
||||||
SkuAmount.Add(sku.ToString(), (double)amount);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//public void CreateMap()
|
|
||||||
//{
|
|
||||||
// Range amountCell = Sheet.Cells.Find(amountHeader);
|
|
||||||
// Range skuCell = Sheet.Cells.Find(skuHeader);
|
|
||||||
// Range groupCell = Sheet.Cells.Find(groupHeader);
|
|
||||||
|
|
||||||
// headerRowNumber = amountCell.Row;
|
|
||||||
// skuColumnNumber = skuCell.Column;
|
|
||||||
// amountColumnNumber = amountCell.Column;
|
|
||||||
// groupColumnNumber = groupCell.Column;
|
|
||||||
|
|
||||||
// for (int row = headerRowNumber + 1; row < skuCell.Rows.Count; row++)
|
|
||||||
// {
|
|
||||||
// string sku =
|
|
||||||
// }
|
|
||||||
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
74
src/PriceListTools/SourceFile.cs
Normal file
74
src/PriceListTools/SourceFile.cs
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
using Microsoft.Office.Interop.Excel;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace RehauSku.PriceListTools
|
||||||
|
{
|
||||||
|
internal class SourceFile : PriceList
|
||||||
|
{
|
||||||
|
public Dictionary<string, double> SkuAmount { get; private set; }
|
||||||
|
|
||||||
|
public SourceFile(Workbook workbook)
|
||||||
|
{
|
||||||
|
Sheet = workbook.ActiveSheet;
|
||||||
|
Name = workbook.Name + '\n' + Sheet.Name;
|
||||||
|
|
||||||
|
amountCell = Sheet.Cells.Find(amountHeader);
|
||||||
|
skuCell = Sheet.Cells.Find(skuHeader);
|
||||||
|
groupCell = Sheet.Cells.Find(groupHeader);
|
||||||
|
|
||||||
|
if (amountCell == null || skuCell == null || groupCell == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"Лист { Name } не распознан");
|
||||||
|
}
|
||||||
|
|
||||||
|
CreateAmountDict();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateAmountDict()
|
||||||
|
{
|
||||||
|
SkuAmount = new Dictionary<string, double>();
|
||||||
|
|
||||||
|
object[,] amountColumn = Sheet.Columns[amountCell.Column].Value2;
|
||||||
|
object[,] skuColumn = Sheet.Columns[skuCell.Column].Value2;
|
||||||
|
|
||||||
|
for (int row = amountCell.Row + 1; row < amountColumn.GetLength(0); row++)
|
||||||
|
{
|
||||||
|
object amount = amountColumn[row, 1];
|
||||||
|
object sku = skuColumn[row, 1];
|
||||||
|
|
||||||
|
if (amount != null && (double)amount != 0)
|
||||||
|
{
|
||||||
|
if (SkuAmount.ContainsKey(sku.ToString()))
|
||||||
|
SkuAmount[sku.ToString()] += (double)amount;
|
||||||
|
|
||||||
|
else
|
||||||
|
SkuAmount.Add(sku.ToString(), (double)amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class NewFile : PriceList
|
||||||
|
{
|
||||||
|
public Dictionary<PriceListPosition, Range> Map { get; private set; }
|
||||||
|
|
||||||
|
public void CreateMap()
|
||||||
|
{
|
||||||
|
Range amountCell = Sheet.Cells.Find(amountHeader);
|
||||||
|
Range skuCell = Sheet.Cells.Find(skuHeader);
|
||||||
|
Range groupCell = Sheet.Cells.Find(groupHeader);
|
||||||
|
|
||||||
|
//headerRowNumber = amountCell.Row;
|
||||||
|
//skuColumnNumber = skuCell.Column;
|
||||||
|
//amountColumnNumber = amountCell.Column;
|
||||||
|
//groupColumnNumber = groupCell.Column;
|
||||||
|
|
||||||
|
//for (int row = headerRowNumber + 1; row < skuCell.Rows.Count; row++)
|
||||||
|
//{
|
||||||
|
// string sku =
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -124,8 +124,9 @@
|
|||||||
<Compile Include="PriceListTools\CombineTool.cs" />
|
<Compile Include="PriceListTools\CombineTool.cs" />
|
||||||
<Compile Include="PriceListTools\AbstractPriceListTool.cs" />
|
<Compile Include="PriceListTools\AbstractPriceListTool.cs" />
|
||||||
<Compile Include="PriceListTools\MergeTool.cs" />
|
<Compile Include="PriceListTools\MergeTool.cs" />
|
||||||
<Compile Include="PriceListTools\PriceListPosition.cs" />
|
|
||||||
<Compile Include="PriceListTools\PriceList.cs" />
|
<Compile Include="PriceListTools\PriceList.cs" />
|
||||||
|
<Compile Include="PriceListTools\PriceListPosition.cs" />
|
||||||
|
<Compile Include="PriceListTools\SourceFile.cs" />
|
||||||
<Compile Include="Ribbon\RibbonController.cs" />
|
<Compile Include="Ribbon\RibbonController.cs" />
|
||||||
<Compile Include="Assistant\HttpClientUtil.cs" />
|
<Compile Include="Assistant\HttpClientUtil.cs" />
|
||||||
<Compile Include="Assistant\StoreResponse.cs" />
|
<Compile Include="Assistant\StoreResponse.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user