2021-12-24 16:22:03 +03:00
|
|
|
|
using ExcelDna.Integration;
|
|
|
|
|
using Microsoft.Office.Interop.Excel;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace RehauSku.PriceListTools
|
|
|
|
|
{
|
2022-01-07 19:04:07 +03:00
|
|
|
|
class MergeTool : ConjoinTool, IDisposable, IConjoinTool
|
2021-12-24 16:22:03 +03:00
|
|
|
|
{
|
2022-01-07 19:04:07 +03:00
|
|
|
|
private Dictionary<string, double> SkuAmount { get; set; }
|
2021-12-24 16:22:03 +03:00
|
|
|
|
|
|
|
|
|
public MergeTool()
|
|
|
|
|
{
|
2022-01-07 19:04:07 +03:00
|
|
|
|
ExcelApp = (Application)ExcelDnaUtil.Application;
|
|
|
|
|
SkuAmount = new Dictionary<string, double>();
|
2021-12-24 16:22:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-07 19:04:07 +03:00
|
|
|
|
public void CollectSkuAmount(string[] files)
|
2021-12-24 16:22:03 +03:00
|
|
|
|
{
|
|
|
|
|
ExcelApp.ScreenUpdating = false;
|
|
|
|
|
foreach (string file in files)
|
|
|
|
|
{
|
|
|
|
|
Workbook wb = ExcelApp.Workbooks.Open(file);
|
|
|
|
|
|
2021-12-24 17:42:20 +03:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
PriceList priceList = new PriceList(wb);
|
2022-01-07 19:04:07 +03:00
|
|
|
|
SkuAmount.AddValuesFromPriceList(priceList);
|
2021-12-24 17:42:20 +03:00
|
|
|
|
}
|
2021-12-24 16:22:03 +03:00
|
|
|
|
|
2021-12-24 17:42:20 +03:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
System.Windows.Forms.MessageBox.Show
|
2022-01-07 19:04:07 +03:00
|
|
|
|
($"{wb.Name} не является файлом прайс-листа \n\n {ex.Message}",
|
2021-12-24 17:42:20 +03:00
|
|
|
|
"Неверный файл прайс-листа!",
|
|
|
|
|
System.Windows.Forms.MessageBoxButtons.OK,
|
|
|
|
|
System.Windows.Forms.MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
wb.Close();
|
|
|
|
|
}
|
2021-12-24 16:22:03 +03:00
|
|
|
|
}
|
|
|
|
|
ExcelApp.ScreenUpdating = true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-07 19:04:07 +03:00
|
|
|
|
public void ExportToFile(string exportFile)
|
2021-12-24 16:22:03 +03:00
|
|
|
|
{
|
2021-12-24 17:42:20 +03:00
|
|
|
|
if (SkuAmount.Count < 1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-24 16:22:03 +03:00
|
|
|
|
Workbook wb = ExcelApp.Workbooks.Open(exportFile);
|
2021-12-24 17:42:20 +03:00
|
|
|
|
PriceList priceList;
|
2021-12-24 16:22:03 +03:00
|
|
|
|
|
2021-12-24 17:42:20 +03:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
priceList = new PriceList(wb);
|
2022-01-07 19:04:07 +03:00
|
|
|
|
priceList.FillWithValues(SkuAmount);
|
2021-12-24 17:42:20 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
System.Windows.Forms.MessageBox.Show
|
2021-12-26 18:22:32 +03:00
|
|
|
|
($"{RegistryUtil.PriceListPath} не является файлом прайс-листа \n\n {ex.Message}",
|
2021-12-24 17:42:20 +03:00
|
|
|
|
"Неверный файл прайс-листа!",
|
|
|
|
|
System.Windows.Forms.MessageBoxButtons.OK,
|
|
|
|
|
System.Windows.Forms.MessageBoxIcon.Error);
|
|
|
|
|
|
|
|
|
|
wb.Close();
|
|
|
|
|
}
|
2021-12-24 16:22:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Dispose(true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|