aboutsummaryrefslogtreecommitdiff
path: root/src/PriceListTools/MergeTool.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/PriceListTools/MergeTool.cs')
-rw-r--r--src/PriceListTools/MergeTool.cs103
1 files changed, 40 insertions, 63 deletions
diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs
index ddf74d2..493f8a8 100644
--- a/src/PriceListTools/MergeTool.cs
+++ b/src/PriceListTools/MergeTool.cs
@@ -1,88 +1,65 @@
-using ExcelDna.Integration;
-using Microsoft.Office.Interop.Excel;
+using Microsoft.Office.Interop.Excel;
using System;
-using System.Collections.Generic;
namespace RehauSku.PriceListTools
{
- class MergeTool : IDisposable
+ internal class MergeTool : AbstractPriceListTool, IDisposable
{
- private Application ExcelApp;
- private Dictionary<string, double> SkuAmount { get; set; }
-
- public MergeTool()
+ public override void FillPriceList()
{
- this.ExcelApp = (Application)ExcelDnaUtil.Application;
- this.SkuAmount = new Dictionary<string, double>();
- }
+ PriceListSheet offer = NewPriceList.OfferSheet;
+ offer.Sheet.Activate();
- public void AddSkuAmountToDict(string[] files)
- {
- ExcelApp.ScreenUpdating = false;
- foreach (string file in files)
- {
- Workbook wb = ExcelApp.Workbooks.Open(file);
+ int exportedValues = 0;
- try
+ foreach (var priceList in sourcePriceLists)
+ {
+ foreach (var sheet in priceList.Sheets)
{
- PriceList priceList = new PriceList(wb);
- SkuAmount.AddValues(priceList);
- }
+ if (sheet.SkuAmount.Count == 0)
+ continue;
- catch (Exception ex)
- {
- System.Windows.Forms.MessageBox.Show
- ( $"{wb.Name} не является файлом прайс-листа \n\n {ex.Message}",
- "Неверный файл прайс-листа!",
- System.Windows.Forms.MessageBoxButtons.OK,
- System.Windows.Forms.MessageBoxIcon.Error);
- }
+ foreach (var kvp in sheet.SkuAmount)
+ {
+ Range cell = offer.Sheet.Columns[offer.skuColumnNumber].Find(kvp.Key);
- finally
- {
- wb.Close();
- }
- }
- ExcelApp.ScreenUpdating = true;
- }
+ if (cell == null)
+ {
+ System.Windows.Forms.MessageBox.Show
+ ($"Артикул {kvp.Key} отсутствует в таблице заказов {RegistryUtil.PriceListPath}",
+ "Отсутствует позиция в конечной таблице заказов",
+ System.Windows.Forms.MessageBoxButtons.OK,
+ System.Windows.Forms.MessageBoxIcon.Information);
+ }
- public void ExportToNewFile(string exportFile)
- {
- if (SkuAmount.Count < 1)
- {
- return;
- }
+ else
+ {
+ Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountColumnNumber];
- Workbook wb = ExcelApp.Workbooks.Open(exportFile);
- PriceList priceList;
+ if (sumCell.Value2 == null)
+ sumCell.Value2 = kvp.Value;
+ else
+ sumCell.Value2 += kvp.Value;
- try
- {
- priceList = new PriceList(wb);
- priceList.Fill(SkuAmount);
+ exportedValues++;
+ }
+ }
+ }
}
- catch (Exception ex)
- {
- System.Windows.Forms.MessageBox.Show
- ($"{RegistryUtil.PriceListPath} не является файлом прайс-листа \n\n {ex.Message}",
- "Неверный файл прайс-листа!",
- System.Windows.Forms.MessageBoxButtons.OK,
- System.Windows.Forms.MessageBoxIcon.Error);
+ AutoFilter filter = offer.Sheet.AutoFilter;
+ int firstFilterColumn = filter.Range.Column;
- wb.Close();
- }
+ filter.Range.AutoFilter(offer.amountColumnNumber - firstFilterColumn + 1, "<>");
+ offer.Sheet.Range["A1"].Activate();
+ AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов";
+
+ Forms.Dialog.SaveWorkbookAs();
}
public void Dispose()
{
- Dispose(true);
GC.SuppressFinalize(this);
}
-
- protected virtual void Dispose(bool disposing)
- {
-
- }
}
}