aboutsummaryrefslogtreecommitdiff
path: root/src/PriceListTools/CombineTool.cs
diff options
context:
space:
mode:
authorSerghei Cebotari <51533848+schebotar@users.noreply.github.com>2022-01-28 18:20:30 +0300
committerGitHub <noreply@github.com>2022-01-28 18:20:30 +0300
commitec1d38f2d4926ddd89dc8f17d29617ea4ddefa82 (patch)
tree9fd3a44e58693dc9bbc8d0e406ba4de21b39ec86 /src/PriceListTools/CombineTool.cs
parentd688578a46e3a3383371c1df952fa2898c828a9a (diff)
parent2ad016bb4c332ecad6d12d824a84f15616ecea38 (diff)
Merge pull request #12 from schebotar/dev
Dev
Diffstat (limited to 'src/PriceListTools/CombineTool.cs')
-rw-r--r--src/PriceListTools/CombineTool.cs75
1 files changed, 16 insertions, 59 deletions
diff --git a/src/PriceListTools/CombineTool.cs b/src/PriceListTools/CombineTool.cs
index cf02059..dc0f2af 100644
--- a/src/PriceListTools/CombineTool.cs
+++ b/src/PriceListTools/CombineTool.cs
@@ -1,76 +1,33 @@
using Microsoft.Office.Interop.Excel;
-using System;
+using System.Collections.Generic;
namespace RehauSku.PriceListTools
{
- internal class CombineTool : AbstractPriceListTool, IDisposable
+ internal class CombineTool : PriceListTool
{
- public override void FillPriceList()
- {
- PriceListSheet offer = NewPriceList.OfferSheet;
- offer.Sheet.Activate();
+ public List<Source> SourceFiles;
- int exportedValues = 0;
- int exportedLists = 0;
+ public void FillTarget()
+ {
+ ExcelApp.ScreenUpdating = false;
- foreach (var priceList in sourcePriceLists)
+ foreach (Source source in SourceFiles)
{
- foreach (var sheet in priceList.Sheets)
- {
- if (sheet.SkuAmount.Count == 0)
- continue;
-
- offer.Sheet.Columns[offer.amountColumnNumber]
- .EntireColumn
- .Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow);
-
- exportedLists++;
-
- foreach (var kvp in sheet.SkuAmount)
- {
- 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];
+ TargetFile.Sheet.Columns[TargetFile.amountCell.Column]
+ .EntireColumn
+ .Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow);
- if (sumCell.Value2 == null)
- sumCell.Value2 = kvp.Value;
- else
- sumCell.Value2 += kvp.Value;
+ Range newColumnHeader = TargetFile.Sheet.Cells[TargetFile.amountCell.Row, TargetFile.amountCell.Column - 1];
+ newColumnHeader.Value2 = $"{source.Name}";
+ newColumnHeader.WrapText = true;
- exportedValues++;
- }
-
- offer.Sheet.Cells[offer.headerRowNumber, offer.amountColumnNumber].Value2 = $"{priceList.Name}\n{sheet.Name}";
- }
- }
+ FillColumnsWithDictionary(source.PositionAmount, TargetFile.amountCell.Column - 1, TargetFile.amountCell.Column);
}
- AutoFilter filter = offer.Sheet.AutoFilter;
- int firstFilterColumn = filter.Range.Column;
-
- filter.Range.AutoFilter(offer.amountColumnNumber - firstFilterColumn + 1 + exportedLists, "<>");
- offer.Sheet.Range["A1"].Activate();
-
- AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов";
+ FilterByAmount();
+ ExcelApp.ScreenUpdating = true;
Forms.Dialog.SaveWorkbookAs();
}
-
- public void Dispose()
- {
- GC.SuppressFinalize(this);
- }
}
}