Watch only current sheets in files

This commit is contained in:
Sergey Chebotar 2022-01-26 17:41:46 +03:00
parent d688578a46
commit 4a2ca16d8b
8 changed files with 148 additions and 89 deletions

View File

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

View File

@ -7,7 +7,7 @@ namespace RehauSku.PriceListTools
{
public override void FillPriceList()
{
PriceListSheet offer = NewPriceList.OfferSheet;
PriceListSheet offer = NewPriceList.Sheet;
offer.Sheet.Activate();
int exportedValues = 0;
@ -15,45 +15,44 @@ namespace RehauSku.PriceListTools
foreach (var priceList in sourcePriceLists)
{
foreach (var sheet in priceList.Sheets)
PriceListSheet sheet = priceList.Sheet;
if (sheet.SkuAmount.Count == 0)
continue;
offer.Sheet.Columns[offer.amountColumnNumber]
.EntireColumn
.Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow);
exportedLists++;
foreach (var kvp in sheet.SkuAmount)
{
if (sheet.SkuAmount.Count == 0)
continue;
Range cell = offer.Sheet.Columns[offer.skuColumnNumber].Find(kvp.Key);
offer.Sheet.Columns[offer.amountColumnNumber]
.EntireColumn
.Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow);
exportedLists++;
foreach (var kvp in sheet.SkuAmount)
if (cell == null)
{
Range cell = offer.Sheet.Columns[offer.skuColumnNumber].Find(kvp.Key);
if (cell == null)
{
System.Windows.Forms.MessageBox.Show
($"Артикул {kvp.Key} отсутствует в таблице заказов {RegistryUtil.PriceListPath}",
"Отсутствует позиция в конечной таблице заказов",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information);
}
else
{
offer.Sheet.Cells[cell.Row, offer.amountColumnNumber].Value2 = kvp.Value;
Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountColumnNumber + exportedLists];
if (sumCell.Value2 == null)
sumCell.Value2 = kvp.Value;
else
sumCell.Value2 += kvp.Value;
exportedValues++;
}
offer.Sheet.Cells[offer.headerRowNumber, offer.amountColumnNumber].Value2 = $"{priceList.Name}\n{sheet.Name}";
System.Windows.Forms.MessageBox.Show
($"Артикул {kvp.Key} отсутствует в таблице заказов {RegistryUtil.PriceListPath}",
"Отсутствует позиция в конечной таблице заказов",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information);
}
else
{
offer.Sheet.Cells[cell.Row, offer.amountColumnNumber].Value2 = kvp.Value;
Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountColumnNumber + exportedLists];
if (sumCell.Value2 == null)
sumCell.Value2 = kvp.Value;
else
sumCell.Value2 += kvp.Value;
exportedValues++;
}
offer.Sheet.Cells[offer.headerRowNumber, offer.amountColumnNumber].Value2 = $"{priceList.Name}\n{sheet.Name}";
}
}

View File

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

View File

@ -7,42 +7,41 @@ namespace RehauSku.PriceListTools
{
public override void FillPriceList()
{
PriceListSheet offer = NewPriceList.OfferSheet;
PriceListSheet offer = NewPriceList.Sheet;
offer.Sheet.Activate();
int exportedValues = 0;
foreach (var priceList in sourcePriceLists)
{
foreach (var sheet in priceList.Sheets)
PriceListSheet sheet = priceList.Sheet;
if (sheet.SkuAmount.Count == 0)
continue;
foreach (var kvp in sheet.SkuAmount)
{
if (sheet.SkuAmount.Count == 0)
continue;
Range cell = offer.Sheet.Columns[offer.skuColumnNumber].Find(kvp.Key);
foreach (var kvp in sheet.SkuAmount)
if (cell == null)
{
Range cell = offer.Sheet.Columns[offer.skuColumnNumber].Find(kvp.Key);
System.Windows.Forms.MessageBox.Show
($"Артикул {kvp.Key} отсутствует в таблице заказов {RegistryUtil.PriceListPath}",
"Отсутствует позиция в конечной таблице заказов",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information);
}
if (cell == null)
{
System.Windows.Forms.MessageBox.Show
($"Артикул {kvp.Key} отсутствует в таблице заказов {RegistryUtil.PriceListPath}",
"Отсутствует позиция в конечной таблице заказов",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information);
}
else
{
Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountColumnNumber];
if (sumCell.Value2 == null)
sumCell.Value2 = kvp.Value;
else
{
Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountColumnNumber];
sumCell.Value2 += kvp.Value;
if (sumCell.Value2 == null)
sumCell.Value2 = kvp.Value;
else
sumCell.Value2 += kvp.Value;
exportedValues++;
}
exportedValues++;
}
}
}

View File

@ -1,4 +1,5 @@
using Microsoft.Office.Interop.Excel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@ -8,25 +9,34 @@ namespace RehauSku.PriceListTools
internal class PriceList
{
public readonly string Name;
public readonly PriceListSheet OfferSheet;
public List<PriceListSheet> Sheets { get; private set; }
//public readonly PriceListSheet OfferSheet;
public PriceListSheet Sheet { get; private set; }
private const string offerSheetHeader = "КП";
//private const string offerSheetHeader = "КП";
public PriceList(Workbook workbook)
{
Name = workbook.Name;
Sheets = new List<PriceListSheet>();
Sheet = new PriceListSheet(workbook.ActiveSheet);
foreach (Worksheet worksheet in workbook.Sheets)
{
PriceListSheet priceListSheet = new PriceListSheet(worksheet);
//foreach (Worksheet worksheet in workbook.Sheets)
//{
// try
// {
// PriceListSheet priceListSheet = new PriceListSheet(worksheet);
// //priceListSheet.FillSkuAmount();
// Sheets.Add(priceListSheet);
// }
// catch (Exception ex)
// {
// throw ex;
// }
//}
if (priceListSheet.FillSkuAmount())
Sheets.Add(priceListSheet);
}
OfferSheet = Sheets.Where(s => s.Name == offerSheetHeader).FirstOrDefault();
//OfferSheet = Sheet.Where(s => s.Name == offerSheetHeader).FirstOrDefault();
}
public static string CreateNewFile()

View File

@ -0,0 +1,23 @@
using RehauSku.Assistant;
using System;
namespace RehauSku.PriceListTools
{
internal class PriceListPosition
{
public readonly string Group;
public readonly string Sku;
public PriceListPosition(string group, string sku)
{
if (!sku.IsRehauSku())
throw new ArgumentException("Wrong SKU");
else
{
Group = group;
Sku = sku;
}
}
}
}

View File

@ -1,5 +1,6 @@
using Microsoft.Office.Interop.Excel;
using System.Collections.Generic;
using System;
namespace RehauSku.PriceListTools
{
@ -7,13 +8,22 @@ namespace RehauSku.PriceListTools
{
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; }
Range amountCell { get; set; }
Range skuCell { get; set; }
Range groupCell { get; set; }
public int headerRowNumber { get; private set; }
public int amountColumnNumber { get; private set; }
public int skuColumnNumber { get; private set; }
public int groupColumnNumber { get; private set; }
public Dictionary<PriceListPosition, Range> Map { get; private set; }
public PriceListSheet(Worksheet sheet)
{
@ -21,28 +31,28 @@ namespace RehauSku.PriceListTools
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();
}
public bool FillSkuAmount()
private void FillSkuAmount()
{
Range amountCell = Sheet.Cells.Find(amountHeader);
Range skuCell = Sheet.Cells.Find(skuHeader);
if (amountCell == null || skuCell == null)
{
AddIn.Excel.StatusBar = $"Лист {Name} не распознан";
return false;
}
headerRowNumber = amountCell.Row;
skuColumnNumber = skuCell.Column;
amountColumnNumber = amountCell.Column;
object[,] amountColumn = Sheet.Columns[amountColumnNumber].Value2;
object[,] skuColumn = Sheet.Columns[skuColumnNumber].Value2;
object[,] amountColumn = Sheet.Columns[amountCell.Column].Value2;
object[,] skuColumn = Sheet.Columns[skuCell.Column].Value2;
for (int row = headerRowNumber + 1; row < amountColumn.GetLength(0); row++)
for (int row = amountCell.Row + 1; row < amountColumn.GetLength(0); row++)
{
object amount = amountColumn[row, 1];
object sku = skuColumn[row, 1];
@ -56,8 +66,25 @@ namespace RehauSku.PriceListTools
SkuAmount.Add(sku.ToString(), (double)amount);
}
}
return true;
}
//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

@ -125,6 +125,7 @@
<Compile Include="PriceListTools\AbstractPriceListTool.cs" />
<Compile Include="PriceListTools\MergeTool.cs" />
<Compile Include="PriceListTools\PriceList.cs" />
<Compile Include="PriceListTools\PriceListPosition.cs" />
<Compile Include="PriceListTools\PriceListSheet.cs" />
<Compile Include="Ribbon\RibbonController.cs" />
<Compile Include="Assistant\HttpClientUtil.cs" />