Remove PriceList class

This commit is contained in:
Sergey Chebotar 2022-01-26 18:17:44 +03:00
parent c0139ca228
commit 55bbd801a5
7 changed files with 96 additions and 115 deletions

View File

@ -24,12 +24,6 @@ namespace RehauSku.PriceListTools
try try
{ {
NewPriceList = new PriceList(wb); NewPriceList = new PriceList(wb);
//if (NewPriceList.Sheet.Count == 0)
// throw new ArgumentException($"Не найдены листы с артикулами в {wb.Name}");
//if (NewPriceList.OfferSheet == null)
// throw new ArgumentException($"Нет листа для коммерческого предложения в {wb.Name}");
} }
catch (Exception ex) catch (Exception ex)

View File

@ -7,16 +7,13 @@ namespace RehauSku.PriceListTools
{ {
public override void FillPriceList() public override void FillPriceList()
{ {
PriceListSheet offer = NewPriceList.Sheet; PriceList offer = NewPriceList;
offer.Sheet.Activate(); offer.Sheet.Activate();
int exportedValues = 0; int exportedValues = 0;
int exportedLists = 0;
foreach (var priceList in sourcePriceLists) foreach (var sheet in sourcePriceLists)
{ {
PriceListSheet sheet = priceList.Sheet;
if (sheet.SkuAmount.Count == 0) if (sheet.SkuAmount.Count == 0)
continue; continue;
@ -24,8 +21,6 @@ namespace RehauSku.PriceListTools
.EntireColumn .EntireColumn
.Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow); .Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow);
exportedLists++;
foreach (var kvp in sheet.SkuAmount) foreach (var kvp in sheet.SkuAmount)
{ {
Range cell = offer.Sheet.Columns[offer.skuCell.Column].Find(kvp.Key); Range cell = offer.Sheet.Columns[offer.skuCell.Column].Find(kvp.Key);
@ -41,8 +36,8 @@ namespace RehauSku.PriceListTools
else else
{ {
offer.Sheet.Cells[cell.Row, offer.amountCell.Column].Value2 = kvp.Value; offer.Sheet.Cells[cell.Row, offer.amountCell.Column - 1].Value2 = kvp.Value;
Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountCell.Column + exportedLists]; Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountCell.Column];
if (sumCell.Value2 == null) if (sumCell.Value2 == null)
sumCell.Value2 = kvp.Value; sumCell.Value2 = kvp.Value;
@ -52,14 +47,13 @@ namespace RehauSku.PriceListTools
exportedValues++; exportedValues++;
} }
offer.Sheet.Cells[offer.amountCell.Row, offer.amountCell.Column].Value2 = $"{priceList.Name}\n{sheet.Name}"; offer.Sheet.Cells[offer.amountCell.Row, offer.amountCell.Column - 1].Value2 = $"{sheet.Name}";
} }
} }
AutoFilter filter = offer.Sheet.AutoFilter; AutoFilter filter = offer.Sheet.AutoFilter;
int firstFilterColumn = filter.Range.Column;
filter.Range.AutoFilter(offer.amountCell.Column - firstFilterColumn + 1 + exportedLists, "<>"); filter.Range.AutoFilter(offer.amountCell.Column, "<>");
offer.Sheet.Range["A1"].Activate(); offer.Sheet.Range["A1"].Activate();
AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов"; AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов";

View File

@ -77,7 +77,7 @@ namespace RehauSku.PriceListTools
{ {
if (SkuAmount.Count < 1) return; if (SkuAmount.Count < 1) return;
PriceListSheet offer = NewPriceList.Sheet; PriceList offer = NewPriceList;
offer.Sheet.Activate(); offer.Sheet.Activate();
int exportedValues = 0; int exportedValues = 0;

View File

@ -7,15 +7,13 @@ namespace RehauSku.PriceListTools
{ {
public override void FillPriceList() public override void FillPriceList()
{ {
PriceListSheet offer = NewPriceList.Sheet; PriceList offer = NewPriceList;
offer.Sheet.Activate(); offer.Sheet.Activate();
int exportedValues = 0; int exportedValues = 0;
foreach (var priceList in sourcePriceLists) foreach (var sheet in sourcePriceLists)
{ {
PriceListSheet sheet = priceList.Sheet;
if (sheet.SkuAmount.Count == 0) if (sheet.SkuAmount.Count == 0)
continue; continue;
@ -47,9 +45,8 @@ namespace RehauSku.PriceListTools
} }
AutoFilter filter = offer.Sheet.AutoFilter; AutoFilter filter = offer.Sheet.AutoFilter;
int firstFilterColumn = filter.Range.Column;
filter.Range.AutoFilter(offer.amountCell.Column - firstFilterColumn + 1, "<>"); filter.Range.AutoFilter(offer.amountCell.Column, "<>");
offer.Sheet.Range["A1"].Activate(); offer.Sheet.Range["A1"].Activate();
AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов"; AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов";

View File

@ -1,21 +1,100 @@
using Microsoft.Office.Interop.Excel; using Microsoft.Office.Interop.Excel;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System;
using System.Linq;
namespace RehauSku.PriceListTools namespace RehauSku.PriceListTools
{ {
internal class PriceList internal class PriceList
{ {
private const string amountHeader = "Кол-во";
private const string skuHeader = "Актуальный материал";
private const string groupHeader = "Программа";
public readonly Worksheet Sheet;
public readonly string Name; public readonly string Name;
public PriceListSheet Sheet { get; private set; } public Dictionary<string, double> SkuAmount { get; private set; }
public readonly Range amountCell;
public readonly Range skuCell;
public readonly Range groupCell;
public Dictionary<PriceListPosition, Range> Map { get; private set; }
public PriceList(Worksheet sheet)
{
Sheet = sheet;
Name = 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();
}
public PriceList(Workbook workbook) public PriceList(Workbook workbook)
{ {
Name = workbook.Name; Sheet = workbook.ActiveSheet;
Sheet = new PriceListSheet(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 =
// }
//}
}
} }

View File

@ -1,82 +0,0 @@
using Microsoft.Office.Interop.Excel;
using System.Collections.Generic;
using System;
namespace RehauSku.PriceListTools
{
internal class PriceListSheet
{
private const string amountHeader = "Кол-во";
private const string skuHeader = "Актуальный материал";
private const string groupHeader = "Программа";
public readonly Worksheet Sheet;
public readonly string Name;
public Dictionary<string, double> SkuAmount { get; private set; }
public readonly Range amountCell;
public readonly Range skuCell;
public readonly Range groupCell;
public Dictionary<PriceListPosition, Range> Map { get; private set; }
public PriceListSheet(Worksheet sheet)
{
Sheet = sheet;
Name = sheet.Name;
SkuAmount = new Dictionary<string, double>();
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()
{
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 =
// }
//}
}
}

View File

@ -124,9 +124,8 @@
<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\PriceList.cs" />
<Compile Include="PriceListTools\PriceListPosition.cs" /> <Compile Include="PriceListTools\PriceListPosition.cs" />
<Compile Include="PriceListTools\PriceListSheet.cs" /> <Compile Include="PriceListTools\PriceList.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" />