commit
ad7234fda7
@ -11,12 +11,12 @@
|
||||
- Отображение артикула с помощью `=RAUSKU()`
|
||||
- Отображение цены с помощью формулы `=RAUPRICE()`
|
||||
- Экспорт массива ячеек вида "Артикул - Количество" в прайс-лист
|
||||
- Актуализация прайс-листа
|
||||
- Актуализация прайс-листа до последней версии
|
||||
- Объединение нескольких прайс-листов в один файл
|
||||
- Сложением всех позиций по артикулам
|
||||
- С разнесением данных по колонкам в конечном файле
|
||||
|
||||
*Для работы функций "Экспорт" и "Объединение" требуется указать путь к файлу пустого прайс-листа REHAU*
|
||||
*Для работы функций "Экспорт", "Актуализация" и "Объединение" требуется указать путь к файлу пустого прайс-листа REHAU*
|
||||
|
||||
## Работа без установки
|
||||
1. Запустить файл `RehauSku.Assist-AddIn-packed.xll` или `RehauSku.Assist-AddIn64-packed.xll` в зависимости от архитектуры приложения
|
||||
|
@ -5,10 +5,9 @@ using Microsoft.Office.Interop.Excel;
|
||||
using System.Net.Http;
|
||||
using System.Runtime.Caching;
|
||||
|
||||
|
||||
namespace RehauSku
|
||||
{
|
||||
public enum ResponseOrder
|
||||
enum ResponseOrder
|
||||
{
|
||||
Default,
|
||||
Relevance,
|
||||
@ -17,7 +16,7 @@ namespace RehauSku
|
||||
Series
|
||||
}
|
||||
|
||||
public class AddIn : IExcelAddIn
|
||||
class AddIn : IExcelAddIn
|
||||
{
|
||||
public static HttpClient httpClient;
|
||||
public static MemoryCache memoryCache;
|
||||
@ -27,16 +26,18 @@ namespace RehauSku
|
||||
{
|
||||
httpClient = new HttpClient();
|
||||
memoryCache = new MemoryCache("RehauSku");
|
||||
Excel = (Application)ExcelDnaUtil.Application;
|
||||
RegisterFunctions();
|
||||
IntelliSenseServer.Install();
|
||||
RegistryUtil.Initialize();
|
||||
Excel = (Application)ExcelDnaUtil.Application;
|
||||
EventsUtil.Initialize();
|
||||
}
|
||||
|
||||
public void AutoClose()
|
||||
{
|
||||
IntelliSenseServer.Uninstall();
|
||||
RegistryUtil.Uninitialize();
|
||||
EventsUtil.Uninitialize();
|
||||
memoryCache.Dispose();
|
||||
}
|
||||
|
||||
|
33
src/AddIn/EventsUtil.cs
Normal file
33
src/AddIn/EventsUtil.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using Microsoft.Office.Interop.Excel;
|
||||
|
||||
namespace RehauSku
|
||||
{
|
||||
internal static class EventsUtil
|
||||
{
|
||||
private static Application Excel = AddIn.Excel;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
Excel.SheetSelectionChange += RefreshExportButton;
|
||||
Excel.SheetActivate += RefreshConvertButton;
|
||||
Excel.WorkbookActivate += RefreshConvertButton;
|
||||
}
|
||||
|
||||
public static void Uninitialize()
|
||||
{
|
||||
Excel.SheetSelectionChange -= RefreshExportButton;
|
||||
Excel.SheetActivate -= RefreshConvertButton;
|
||||
Excel.WorkbookActivate -= RefreshConvertButton;
|
||||
}
|
||||
|
||||
private static void RefreshConvertButton(object sh)
|
||||
{
|
||||
Interface.RibbonController.RefreshControl("convertPrice");
|
||||
}
|
||||
|
||||
private static void RefreshExportButton(object sh, Range target)
|
||||
{
|
||||
Interface.RibbonController.RefreshControl("exportToPrice");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
using Microsoft.Win32;
|
||||
using RehauSku.Forms;
|
||||
using RehauSku.Interface;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
@ -38,6 +38,12 @@ namespace RehauSku
|
||||
if (result == DialogResult.OK)
|
||||
{
|
||||
string fileName = Dialog.GetFilePath();
|
||||
|
||||
if (string.IsNullOrEmpty(fileName))
|
||||
{
|
||||
throw new Exception("Нет файла шаблона");
|
||||
}
|
||||
|
||||
priceListPath = fileName;
|
||||
RootKey.SetValue("PriceListPath", fileName);
|
||||
return priceListPath;
|
||||
|
@ -1,6 +1,6 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace RehauSku.Assistant
|
||||
namespace RehauSku
|
||||
{
|
||||
static class SkuExtensions
|
||||
{
|
32
src/AddIn/WorksheetExtensions.cs
Normal file
32
src/AddIn/WorksheetExtensions.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using Microsoft.Office.Interop.Excel;
|
||||
using System.Linq;
|
||||
|
||||
namespace RehauSku
|
||||
{
|
||||
public static class WorksheetExtensions
|
||||
{
|
||||
private static string amountHeader = "Кол-во";
|
||||
private static string skuHeader = "Актуальный материал";
|
||||
private static string groupHeader = "Программа";
|
||||
private static string nameHeader = "Наименование";
|
||||
|
||||
public static bool IsRehauSource(this Worksheet worksheet)
|
||||
{
|
||||
Range amountCell;
|
||||
Range skuCell;
|
||||
Range groupCell;
|
||||
Range nameCell;
|
||||
|
||||
Range[] cells = new[]
|
||||
{
|
||||
amountCell = worksheet.Cells.Find(amountHeader),
|
||||
skuCell = worksheet.Cells.Find(skuHeader),
|
||||
groupCell = worksheet.Cells.Find(groupHeader),
|
||||
nameCell = worksheet.Cells.Find(nameHeader)
|
||||
};
|
||||
|
||||
return cells.All(x => x != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ using System.Text.RegularExpressions;
|
||||
|
||||
namespace RehauSku.Assistant
|
||||
{
|
||||
public static class RequestModifier
|
||||
static class RequestModifier
|
||||
{
|
||||
public static string CleanRequest(this string input)
|
||||
{
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace RehauSku.Assistant
|
||||
{
|
||||
public enum ProductField
|
||||
enum ProductField
|
||||
{
|
||||
Name,
|
||||
Id,
|
||||
|
@ -2,17 +2,17 @@
|
||||
|
||||
namespace RehauSku.Assistant
|
||||
{
|
||||
public class StoreResponce
|
||||
class StoreResponce
|
||||
{
|
||||
public Ecommerce Ecommerce { get; set; }
|
||||
}
|
||||
|
||||
public class Ecommerce
|
||||
class Ecommerce
|
||||
{
|
||||
public List<Product> Impressions { get; set; }
|
||||
}
|
||||
|
||||
public class Product : IProduct
|
||||
class Product : IProduct
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
11
src/Interface/AbstractBar.cs
Normal file
11
src/Interface/AbstractBar.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using Microsoft.Office.Interop.Excel;
|
||||
|
||||
namespace RehauSku.Interface
|
||||
{
|
||||
internal abstract class AbstractBar
|
||||
{
|
||||
protected Application Excel = AddIn.Excel;
|
||||
|
||||
public abstract void Update();
|
||||
}
|
||||
}
|
@ -2,31 +2,27 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace RehauSku.Forms
|
||||
namespace RehauSku.Interface
|
||||
{
|
||||
static class Dialog
|
||||
{
|
||||
public static string GetFilePath()
|
||||
{
|
||||
string filePath = string.Empty;
|
||||
|
||||
using (OpenFileDialog dialog = new OpenFileDialog())
|
||||
{
|
||||
dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm";
|
||||
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
filePath = dialog.FileName;
|
||||
return dialog.FileName;
|
||||
}
|
||||
}
|
||||
|
||||
return filePath;
|
||||
else return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public static string[] GetMultiplyFiles()
|
||||
{
|
||||
List<string> fileNames = new List<string>();
|
||||
|
||||
using (OpenFileDialog dialog = new OpenFileDialog())
|
||||
{
|
||||
dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm";
|
||||
@ -34,29 +30,33 @@ namespace RehauSku.Forms
|
||||
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
foreach (string file in dialog.FileNames)
|
||||
{
|
||||
fileNames.Add(file);
|
||||
}
|
||||
return dialog.FileNames;
|
||||
}
|
||||
}
|
||||
|
||||
return fileNames.ToArray();
|
||||
else return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveWorkbookAs()
|
||||
{
|
||||
Workbook wb = AddIn.Excel.ActiveWorkbook;
|
||||
string currentFilename = wb.FullName;
|
||||
string fileFilter = "Файлы Excel (*.xls;*.xlsx;*.xlsm),*.xls;*.xlsx;*.xlsm";
|
||||
Workbook workbook = AddIn.Excel.ActiveWorkbook;
|
||||
|
||||
object fileName = AddIn.Excel.GetSaveAsFilename(currentFilename, fileFilter);
|
||||
using (SaveFileDialog dialog = new SaveFileDialog())
|
||||
{
|
||||
dialog.FileName = workbook.Name;
|
||||
dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm";
|
||||
|
||||
if (fileName.GetType() == typeof(string))
|
||||
wb.SaveAs(fileName);
|
||||
if (dialog.ShowDialog() == DialogResult.Cancel)
|
||||
{
|
||||
workbook.Close(false);
|
||||
}
|
||||
|
||||
else
|
||||
wb.Close(false);
|
||||
else
|
||||
{
|
||||
string fileName = dialog.FileName;
|
||||
workbook.SaveAs(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
31
src/Interface/ProgressBar.cs
Normal file
31
src/Interface/ProgressBar.cs
Normal file
@ -0,0 +1,31 @@
|
||||
namespace RehauSku.Interface
|
||||
{
|
||||
internal class ProgressBar : AbstractBar
|
||||
{
|
||||
private double CurrentProgress { get; set; }
|
||||
private readonly double TaskWeight;
|
||||
private readonly string Message;
|
||||
|
||||
public ProgressBar(string message, int weight)
|
||||
{
|
||||
Message = message;
|
||||
TaskWeight = weight;
|
||||
CurrentProgress = 0;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
double percent = (++CurrentProgress / TaskWeight) * 100;
|
||||
|
||||
if (percent < 100)
|
||||
{
|
||||
Excel.StatusBar = $"{Message} Выполнено {percent.ToString("#.#")} %";
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Excel.StatusBar = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
44
src/Interface/ResultBar.cs
Normal file
44
src/Interface/ResultBar.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System.Text;
|
||||
|
||||
namespace RehauSku.Interface
|
||||
{
|
||||
internal class ResultBar : AbstractBar
|
||||
{
|
||||
private int Success { get; set; }
|
||||
private int Replaced { get; set; }
|
||||
private int NotFound { get; set; }
|
||||
|
||||
public ResultBar()
|
||||
{
|
||||
Success = 0;
|
||||
Replaced = 0;
|
||||
NotFound = 0;
|
||||
}
|
||||
|
||||
public void IncrementSuccess() => Success++;
|
||||
public void IncrementReplaced() => Replaced++;
|
||||
public void IncrementNotFound() => NotFound++;
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (Success > 0)
|
||||
{
|
||||
sb.Append($"Успешно экспортировано {Success} артикулов. ");
|
||||
}
|
||||
|
||||
if (Replaced > 0)
|
||||
{
|
||||
sb.Append($"Заменено {Replaced} артикулов. ");
|
||||
}
|
||||
|
||||
if (NotFound > 0)
|
||||
{
|
||||
sb.Append($"Не найдено {NotFound} артикулов.");
|
||||
}
|
||||
|
||||
Excel.StatusBar = sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,25 +1,27 @@
|
||||
using ExcelDna.Integration.CustomUI;
|
||||
using RehauSku.Forms;
|
||||
using Microsoft.Office.Interop.Excel;
|
||||
using RehauSku.PriceListTools;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace RehauSku.Ribbon
|
||||
namespace RehauSku.Interface
|
||||
{
|
||||
[ComVisible(true)]
|
||||
public class RibbonController : ExcelRibbon
|
||||
{
|
||||
private static IRibbonUI ribbonUi;
|
||||
|
||||
public override string GetCustomUI(string RibbonID)
|
||||
{
|
||||
return @"
|
||||
<customUI xmlns='http://schemas.microsoft.com/office/2006/01/customui'>
|
||||
<customUI onLoad='RibbonLoad' xmlns='http://schemas.microsoft.com/office/2006/01/customui'>
|
||||
<ribbon>
|
||||
<tabs>
|
||||
<tab id='rau' label='REHAU'>
|
||||
<group id='priceList' label='Прайс-лист'>
|
||||
<button id='exportToPrice' label='Экспорт в новый файл' size='normal' imageMso='PivotExportToExcel' onAction='OnExportPressed'/>
|
||||
<button id='convertPrice' label='Актуализировать' size='normal' imageMso='FileUpdate' onAction='OnConvertPressed'/>
|
||||
<button id='exportToPrice' getEnabled='GetExportEnabled' label='Экспорт в новый файл' size='normal' imageMso='PivotExportToExcel' onAction='OnExportPressed'/>
|
||||
<button id='convertPrice' getEnabled='GetConvertEnabled' label='Актуализировать' size='normal' imageMso='FileUpdate' onAction='OnConvertPressed'/>
|
||||
<menu id='conjoinMenu' label='Объединить' imageMso='Copy'>
|
||||
<button id='mergeFiles' label='Сложить' onAction='OnMergePressed'/>
|
||||
<button id='combineFiles' label='По колонкам' onAction='OnCombinePressed'/>
|
||||
@ -34,14 +36,27 @@ namespace RehauSku.Ribbon
|
||||
</customUI>";
|
||||
}
|
||||
|
||||
public void RibbonLoad(IRibbonUI sender)
|
||||
{
|
||||
ribbonUi = sender;
|
||||
}
|
||||
|
||||
public static void RefreshControl(string id)
|
||||
{
|
||||
if (ribbonUi != null)
|
||||
{
|
||||
ribbonUi.InvalidateControl(id);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMergePressed(IRibbonControl control)
|
||||
{
|
||||
MergeTool mergeTool = new MergeTool();
|
||||
string[] files = Dialog.GetMultiplyFiles();
|
||||
|
||||
if (files.Length != 0)
|
||||
if (files != null)
|
||||
{
|
||||
mergeTool.SourceFiles = Source.GetSourceLists(files);
|
||||
mergeTool.SourceFiles = SourcePriceList.GetSourceLists(files);
|
||||
mergeTool.OpenNewPrice();
|
||||
mergeTool.FillTarget();
|
||||
}
|
||||
@ -52,20 +67,31 @@ namespace RehauSku.Ribbon
|
||||
CombineTool combineTool = new CombineTool();
|
||||
string[] files = Dialog.GetMultiplyFiles();
|
||||
|
||||
if (files.Length != 0)
|
||||
if (files != null)
|
||||
{
|
||||
combineTool.SourceFiles = Source.GetSourceLists(files);
|
||||
combineTool.SourceFiles = SourcePriceList.GetSourceLists(files);
|
||||
combineTool.OpenNewPrice();
|
||||
combineTool.FillTarget();
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetConvertEnabled(IRibbonControl control)
|
||||
{
|
||||
if (AddIn.Excel.ActiveWorkbook == null)
|
||||
return false;
|
||||
|
||||
else
|
||||
{
|
||||
Worksheet worksheet = AddIn.Excel.ActiveWorkbook.ActiveSheet;
|
||||
return worksheet.IsRehauSource();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnExportPressed(IRibbonControl control)
|
||||
{
|
||||
try
|
||||
{
|
||||
ExportTool exportTool = new ExportTool();
|
||||
exportTool.TryGetSelection();
|
||||
exportTool.OpenNewPrice();
|
||||
exportTool.FillTarget();
|
||||
}
|
||||
@ -80,6 +106,18 @@ namespace RehauSku.Ribbon
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetExportEnabled(IRibbonControl control)
|
||||
{
|
||||
if (AddIn.Excel.ActiveWorkbook == null)
|
||||
return false;
|
||||
|
||||
else
|
||||
{
|
||||
Range selection = AddIn.Excel.Selection;
|
||||
return selection.Columns.Count == 2;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnConvertPressed(IRibbonControl control)
|
||||
{
|
||||
ConvertTool convertTool = new ConvertTool();
|
||||
@ -92,7 +130,11 @@ namespace RehauSku.Ribbon
|
||||
public void OnSetPricePressed(IRibbonControl control)
|
||||
{
|
||||
string path = Dialog.GetFilePath();
|
||||
RegistryUtil.PriceListPath = path;
|
||||
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
RegistryUtil.PriceListPath = path;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace RehauSku.PriceListTools
|
||||
{
|
||||
internal class PriceList
|
||||
internal abstract class AbstractPriceList
|
||||
{
|
||||
protected const string amountHeader = "Кол-во";
|
||||
protected const string skuHeader = "Актуальный материал";
|
@ -1,16 +1,20 @@
|
||||
using ExcelDna.Integration;
|
||||
using Microsoft.Office.Interop.Excel;
|
||||
using RehauSku.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using Application = Microsoft.Office.Interop.Excel.Application;
|
||||
using ProgressBar = RehauSku.Interface.ProgressBar;
|
||||
|
||||
namespace RehauSku.PriceListTools
|
||||
{
|
||||
internal abstract class PriceListTool
|
||||
internal abstract class AbstractTool
|
||||
{
|
||||
protected private Application ExcelApp = (Application)ExcelDnaUtil.Application;
|
||||
protected private Target TargetFile;
|
||||
protected private TargetPriceList TargetFile;
|
||||
protected private ResultBar ResultBar { get; set; }
|
||||
protected private ProgressBar ProgressBar { get; set; }
|
||||
|
||||
public void OpenNewPrice()
|
||||
{
|
||||
@ -18,7 +22,7 @@ namespace RehauSku.PriceListTools
|
||||
|
||||
try
|
||||
{
|
||||
TargetFile = new Target(wb);
|
||||
TargetFile = new TargetPriceList(wb);
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
@ -33,7 +37,7 @@ namespace RehauSku.PriceListTools
|
||||
}
|
||||
}
|
||||
|
||||
protected private void FillColumnsWithDictionary(KeyValuePair<Position, double> positionAmount, params int[] columns)
|
||||
protected private void FillPositionAmountToColumns(KeyValuePair<Position, double> positionAmount, params int[] columns)
|
||||
{
|
||||
int? row = GetPositionRow(positionAmount.Key.Sku, positionAmount.Key.Group, TargetFile.skuCell.Column);
|
||||
|
||||
@ -53,72 +57,96 @@ namespace RehauSku.PriceListTools
|
||||
sumCell.Value2 += positionAmount.Value;
|
||||
}
|
||||
}
|
||||
|
||||
ResultBar.IncrementSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
else
|
||||
if (TargetFile.oldSkuCell != null)
|
||||
{
|
||||
string sku = positionAmount.Key.Sku.Substring(1, 6);
|
||||
Range foundCell = TargetFile.oldSkuCell.EntireColumn.Find(positionAmount.Key.Sku);
|
||||
|
||||
row = GetPositionRow(sku, positionAmount.Key.Group, TargetFile.skuCell.Column);
|
||||
|
||||
if (row != null)
|
||||
if (foundCell != null)
|
||||
{
|
||||
row = foundCell.Row;
|
||||
|
||||
foreach (int column in columns)
|
||||
{
|
||||
Range amountCell = TargetFile.Sheet.Cells[row, column];
|
||||
|
||||
if (amountCell.Value2 == null)
|
||||
if (TargetFile.Sheet.Cells[row, column].Value2 == null)
|
||||
{
|
||||
amountCell.Value2 = positionAmount.Value;
|
||||
TargetFile.Sheet.Cells[row, column].Value2 = positionAmount.Value;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
amountCell.Value2 += positionAmount.Value;
|
||||
TargetFile.Sheet.Cells[row, column].Value2 += positionAmount.Value;
|
||||
}
|
||||
}
|
||||
|
||||
Range oldSkuCell = TargetFile.Sheet.Cells[row, TargetFile.oldSkuCell.Column];
|
||||
oldSkuCell.Value2 = positionAmount.Key.Sku;
|
||||
ResultBar.IncrementReplaced();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
string sku = positionAmount.Key.Sku.Substring(1, 6);
|
||||
row = GetPositionRow(sku, positionAmount.Key.Group, TargetFile.skuCell.Column);
|
||||
|
||||
if (row != null)
|
||||
{
|
||||
foreach (int column in columns)
|
||||
{
|
||||
Range amountCell = TargetFile.Sheet.Cells[row, column];
|
||||
|
||||
if (amountCell.Value2 == null)
|
||||
{
|
||||
amountCell.Value2 = positionAmount.Value;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
amountCell.Value2 += positionAmount.Value;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
FillMissing(positionAmount, columns);
|
||||
}
|
||||
ResultBar.IncrementReplaced();
|
||||
return;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
FillMissing(positionAmount, columns);
|
||||
ResultBar.IncrementNotFound();
|
||||
}
|
||||
}
|
||||
|
||||
protected private void FillMissing(KeyValuePair<Position, double> positionAmount, params int[] columns)
|
||||
{
|
||||
Range foundCell = TargetFile.oldSkuCell.EntireColumn.Find(positionAmount.Key.Sku);
|
||||
int row;
|
||||
int row = TargetFile.Sheet.Cells[TargetFile.Sheet.Rows.Count, TargetFile.skuCell.Column]
|
||||
.End[XlDirection.xlUp]
|
||||
.Row + 1;
|
||||
|
||||
if (foundCell == null)
|
||||
TargetFile.Sheet.Rows[row]
|
||||
.EntireRow
|
||||
.Insert(XlInsertShiftDirection.xlShiftDown, XlInsertFormatOrigin.xlFormatFromLeftOrAbove);
|
||||
|
||||
Range previous = TargetFile.Sheet.Rows[row - 1];
|
||||
Range current = TargetFile.Sheet.Rows[row];
|
||||
|
||||
previous.Copy(current);
|
||||
current.ClearContents();
|
||||
|
||||
TargetFile.Sheet.Cells[row, TargetFile.groupCell.Column].Value2 = positionAmount.Key.Group;
|
||||
TargetFile.Sheet.Cells[row, TargetFile.nameCell.Column].Value2 = positionAmount.Key.Name;
|
||||
|
||||
if (TargetFile.oldSkuCell != null)
|
||||
{
|
||||
row = TargetFile.Sheet.Cells[TargetFile.Sheet.Rows.Count, TargetFile.skuCell.Column]
|
||||
.End[XlDirection.xlUp]
|
||||
.Row + 1;
|
||||
|
||||
TargetFile.Sheet.Rows[row]
|
||||
.EntireRow
|
||||
.Insert(XlInsertShiftDirection.xlShiftDown, XlInsertFormatOrigin.xlFormatFromLeftOrAbove);
|
||||
|
||||
Range previous = TargetFile.Sheet.Rows[row - 1];
|
||||
Range current = TargetFile.Sheet.Rows[row];
|
||||
|
||||
previous.Copy(current);
|
||||
current.ClearContents();
|
||||
|
||||
TargetFile.Sheet.Cells[row, TargetFile.groupCell.Column].Value2 = positionAmount.Key.Group;
|
||||
TargetFile.Sheet.Cells[row, TargetFile.oldSkuCell.Column].Value2 = positionAmount.Key.Sku;
|
||||
TargetFile.Sheet.Cells[row, TargetFile.nameCell.Column].Value2 = positionAmount.Key.Name;
|
||||
TargetFile.Sheet.Cells[row, TargetFile.skuCell.Column].Value2 = "Не найден";
|
||||
TargetFile.Sheet.Cells[row, TargetFile.oldSkuCell.Column].Value2 = positionAmount.Key.Sku;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
row = foundCell.Row;
|
||||
TargetFile.Sheet.Cells[row, TargetFile.skuCell.Column].Value2 = positionAmount.Key.Sku;
|
||||
}
|
||||
|
||||
foreach (int column in columns)
|
@ -1,15 +1,20 @@
|
||||
using Microsoft.Office.Interop.Excel;
|
||||
using System.Collections.Generic;
|
||||
using RehauSku.Interface;
|
||||
using System.Linq;
|
||||
|
||||
namespace RehauSku.PriceListTools
|
||||
{
|
||||
internal class CombineTool : PriceListTool
|
||||
internal class CombineTool : AbstractTool
|
||||
{
|
||||
public List<Source> SourceFiles;
|
||||
public List<SourcePriceList> SourceFiles;
|
||||
|
||||
public void FillTarget()
|
||||
{
|
||||
foreach (Source source in SourceFiles)
|
||||
ProgressBar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(file => file.PositionAmount.Count));
|
||||
ResultBar = new ResultBar();
|
||||
|
||||
foreach (SourcePriceList source in SourceFiles)
|
||||
{
|
||||
TargetFile.Sheet.Columns[TargetFile.amountCell.Column]
|
||||
.EntireColumn
|
||||
@ -19,13 +24,18 @@ namespace RehauSku.PriceListTools
|
||||
newColumnHeader.Value2 = $"{source.Name}";
|
||||
newColumnHeader.WrapText = true;
|
||||
|
||||
foreach(var kvp in source.PositionAmount)
|
||||
FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column - 1, TargetFile.amountCell.Column);
|
||||
foreach (var kvp in source.PositionAmount)
|
||||
{
|
||||
FillPositionAmountToColumns(kvp, TargetFile.amountCell.Column - 1, TargetFile.amountCell.Column);
|
||||
ProgressBar.Update();
|
||||
}
|
||||
}
|
||||
|
||||
FilterByAmount();
|
||||
ResultBar.Update();
|
||||
|
||||
Forms.Dialog.SaveWorkbookAs();
|
||||
Interface.Dialog.SaveWorkbookAs();
|
||||
ExcelApp.StatusBar = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,17 @@
|
||||
using System;
|
||||
using RehauSku.Interface;
|
||||
using System;
|
||||
|
||||
namespace RehauSku.PriceListTools
|
||||
{
|
||||
internal class ConvertTool : PriceListTool
|
||||
internal class ConvertTool : AbstractTool
|
||||
{
|
||||
private Source Current;
|
||||
private SourcePriceList Current;
|
||||
|
||||
public void GetCurrent()
|
||||
{
|
||||
try
|
||||
{
|
||||
Current = new Source(ExcelApp.ActiveWorkbook);
|
||||
Current = new SourcePriceList(ExcelApp.ActiveWorkbook);
|
||||
}
|
||||
|
||||
catch (Exception exception)
|
||||
@ -26,12 +27,20 @@ namespace RehauSku.PriceListTools
|
||||
|
||||
public void FillTarget()
|
||||
{
|
||||
ProgressBar = new ProgressBar("Заполняю строки...", Current.PositionAmount.Count);
|
||||
ResultBar = new ResultBar();
|
||||
|
||||
foreach (var kvp in Current.PositionAmount)
|
||||
FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column);
|
||||
{
|
||||
FillPositionAmountToColumns(kvp, TargetFile.amountCell.Column);
|
||||
ProgressBar.Update();
|
||||
}
|
||||
|
||||
FilterByAmount();
|
||||
ResultBar.Update();
|
||||
|
||||
Forms.Dialog.SaveWorkbookAs();
|
||||
Dialog.SaveWorkbookAs();
|
||||
ExcelApp.StatusBar = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,37 +1,37 @@
|
||||
using Microsoft.Office.Interop.Excel;
|
||||
using RehauSku.Assistant;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RehauSku.Interface;
|
||||
|
||||
namespace RehauSku.PriceListTools
|
||||
{
|
||||
internal class ExportTool : PriceListTool
|
||||
internal class ExportTool : AbstractTool
|
||||
{
|
||||
private Dictionary<Position, double> PositionAmount;
|
||||
private Range Selection;
|
||||
|
||||
public void TryGetSelection()
|
||||
public ExportTool()
|
||||
{
|
||||
Selection = ExcelApp.Selection;
|
||||
|
||||
if (Selection == null || Selection.Columns.Count != 2)
|
||||
{
|
||||
throw new Exception("Неверный диапазон");
|
||||
}
|
||||
}
|
||||
|
||||
public void FillTarget()
|
||||
{
|
||||
GetSelected();
|
||||
|
||||
ProgressBar = new ProgressBar("Заполняю строки...", PositionAmount.Count);
|
||||
ResultBar = new ResultBar();
|
||||
|
||||
foreach (var kvp in PositionAmount)
|
||||
{
|
||||
FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column);
|
||||
FillPositionAmountToColumns(kvp, TargetFile.amountCell.Column);
|
||||
ProgressBar.Update();
|
||||
}
|
||||
|
||||
FilterByAmount();
|
||||
ResultBar.Update();
|
||||
|
||||
Forms.Dialog.SaveWorkbookAs();
|
||||
Interface.Dialog.SaveWorkbookAs();
|
||||
ExcelApp.StatusBar = false;
|
||||
}
|
||||
|
||||
private void GetSelected()
|
||||
|
@ -1,22 +1,32 @@
|
||||
using System.Collections.Generic;
|
||||
using RehauSku.Interface;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace RehauSku.PriceListTools
|
||||
{
|
||||
internal class MergeTool : PriceListTool
|
||||
internal class MergeTool : AbstractTool
|
||||
{
|
||||
public List<Source> SourceFiles;
|
||||
public List<SourcePriceList> SourceFiles;
|
||||
|
||||
public void FillTarget()
|
||||
{
|
||||
foreach (Source source in SourceFiles)
|
||||
ProgressBar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(x => x.PositionAmount.Count));
|
||||
ResultBar = new ResultBar();
|
||||
|
||||
foreach (SourcePriceList source in SourceFiles)
|
||||
{
|
||||
foreach (var kvp in source.PositionAmount)
|
||||
FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column);
|
||||
{
|
||||
FillPositionAmountToColumns(kvp, TargetFile.amountCell.Column);
|
||||
ProgressBar.Update();
|
||||
}
|
||||
}
|
||||
|
||||
FilterByAmount();
|
||||
ResultBar.Update();
|
||||
|
||||
Forms.Dialog.SaveWorkbookAs();
|
||||
Dialog.SaveWorkbookAs();
|
||||
ExcelApp.StatusBar = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,14 +3,16 @@ using Microsoft.Office.Interop.Excel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RehauSku.Interface;
|
||||
|
||||
namespace RehauSku.PriceListTools
|
||||
{
|
||||
internal class Source : PriceList
|
||||
|
||||
internal class SourcePriceList : AbstractPriceList
|
||||
{
|
||||
public Dictionary<Position, double> PositionAmount { get; private set; }
|
||||
|
||||
public Source(Workbook workbook)
|
||||
public SourcePriceList(Workbook workbook)
|
||||
{
|
||||
if (workbook == null)
|
||||
{
|
||||
@ -20,7 +22,7 @@ namespace RehauSku.PriceListTools
|
||||
Sheet = workbook.ActiveSheet;
|
||||
Name = workbook.Name;
|
||||
|
||||
Range[] cells = new []
|
||||
Range[] cells = new[]
|
||||
{
|
||||
amountCell = Sheet.Cells.Find(amountHeader),
|
||||
skuCell = Sheet.Cells.Find(skuHeader),
|
||||
@ -28,7 +30,7 @@ namespace RehauSku.PriceListTools
|
||||
nameCell = Sheet.Cells.Find(nameHeader)
|
||||
};
|
||||
|
||||
if (cells.Any(x => x == null))
|
||||
if (cells.Any(x => x == null))
|
||||
{
|
||||
throw new ArgumentException($"Файл {Name} не распознан");
|
||||
}
|
||||
@ -36,11 +38,12 @@ namespace RehauSku.PriceListTools
|
||||
CreatePositionsDict();
|
||||
}
|
||||
|
||||
public static List<Source> GetSourceLists(string[] files)
|
||||
public static List<SourcePriceList> GetSourceLists(string[] files)
|
||||
{
|
||||
var ExcelApp = (Application)ExcelDnaUtil.Application;
|
||||
ProgressBar bar = new ProgressBar("Открываю исходные файлы...", files.Length);
|
||||
|
||||
List<Source> sourceFiles = new List<Source>();
|
||||
List<SourcePriceList> sourceFiles = new List<SourcePriceList>();
|
||||
|
||||
foreach (string file in files)
|
||||
{
|
||||
@ -48,9 +51,10 @@ namespace RehauSku.PriceListTools
|
||||
Workbook wb = ExcelApp.Workbooks.Open(file);
|
||||
try
|
||||
{
|
||||
Source priceList = new Source(wb);
|
||||
SourcePriceList priceList = new SourcePriceList(wb);
|
||||
sourceFiles.Add(priceList);
|
||||
wb.Close();
|
||||
bar.Update();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -60,6 +64,7 @@ namespace RehauSku.PriceListTools
|
||||
System.Windows.Forms.MessageBoxButtons.OK,
|
||||
System.Windows.Forms.MessageBoxIcon.Information);
|
||||
wb.Close();
|
||||
bar.Update();
|
||||
}
|
||||
ExcelApp.ScreenUpdating = true;
|
||||
}
|
||||
@ -81,6 +86,12 @@ namespace RehauSku.PriceListTools
|
||||
object name = Sheet.Cells[row, nameCell.Column].Value2;
|
||||
object sku = Sheet.Cells[row, skuCell.Column].Value2;
|
||||
|
||||
if (group == null || name == null || sku == null)
|
||||
continue;
|
||||
|
||||
if (!sku.ToString().IsRehauSku())
|
||||
continue;
|
||||
|
||||
Position p = new Position(group.ToString(), sku.ToString(), name.ToString());
|
||||
|
||||
if (PositionAmount.ContainsKey(p))
|
@ -4,12 +4,12 @@ using System.Linq;
|
||||
|
||||
namespace RehauSku.PriceListTools
|
||||
{
|
||||
internal class Target : PriceList
|
||||
internal class TargetPriceList : AbstractPriceList
|
||||
{
|
||||
private const string oldSkuHeader = "Прежний материал";
|
||||
public Range oldSkuCell { get; private set; }
|
||||
|
||||
public Target(Workbook workbook)
|
||||
public TargetPriceList(Workbook workbook)
|
||||
{
|
||||
Sheet = workbook.ActiveSheet;
|
||||
Name = workbook.FullName;
|
||||
@ -19,10 +19,11 @@ namespace RehauSku.PriceListTools
|
||||
amountCell = Sheet.Cells.Find(amountHeader),
|
||||
skuCell = Sheet.Cells.Find(skuHeader),
|
||||
groupCell = Sheet.Cells.Find(groupHeader),
|
||||
nameCell = Sheet.Cells.Find(nameHeader),
|
||||
oldSkuCell = Sheet.Cells.Find(oldSkuHeader)
|
||||
nameCell = Sheet.Cells.Find(nameHeader)
|
||||
};
|
||||
|
||||
oldSkuCell = Sheet.Cells.Find(oldSkuHeader);
|
||||
|
||||
if (cells.Any(x => x == null))
|
||||
{
|
||||
throw new ArgumentException($"Шаблон { Name } не является прайс-листом");
|
@ -115,27 +115,32 @@
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Forms\Dialog.cs" />
|
||||
<Compile Include="AddIn\EventsUtil.cs" />
|
||||
<Compile Include="Interface\AbstractBar.cs" />
|
||||
<Compile Include="Interface\Dialog.cs" />
|
||||
<Compile Include="AddIn\RegistryUtil.cs" />
|
||||
<Compile Include="AddIn\MemoryCacheUtil.cs" />
|
||||
<Compile Include="Assistant\ParseUtil.cs" />
|
||||
<Compile Include="Assistant\RequestModifier.cs" />
|
||||
<Compile Include="Assistant\SkuExtensions.cs" />
|
||||
<Compile Include="AddIn\SkuExtensions.cs" />
|
||||
<Compile Include="Interface\ProgressBar.cs" />
|
||||
<Compile Include="Interface\ResultBar.cs" />
|
||||
<Compile Include="PriceListTools\CombineTool.cs" />
|
||||
<Compile Include="PriceListTools\ConvertTool.cs" />
|
||||
<Compile Include="PriceListTools\Position.cs" />
|
||||
<Compile Include="PriceListTools\PriceListTool.cs" />
|
||||
<Compile Include="PriceListTools\AbstractTool.cs" />
|
||||
<Compile Include="PriceListTools\MergeTool.cs" />
|
||||
<Compile Include="PriceListTools\PriceList.cs" />
|
||||
<Compile Include="PriceListTools\Source.cs" />
|
||||
<Compile Include="PriceListTools\Target.cs" />
|
||||
<Compile Include="Ribbon\RibbonController.cs" />
|
||||
<Compile Include="PriceListTools\AbstractPriceList.cs" />
|
||||
<Compile Include="PriceListTools\SourcePriceList.cs" />
|
||||
<Compile Include="PriceListTools\TargetPriceList.cs" />
|
||||
<Compile Include="Interface\RibbonController.cs" />
|
||||
<Compile Include="Assistant\HttpClientUtil.cs" />
|
||||
<Compile Include="Assistant\StoreResponse.cs" />
|
||||
<Compile Include="PriceListTools\ExportTool.cs" />
|
||||
<Compile Include="AddIn\AddIn.cs" />
|
||||
<Compile Include="Assistant\IProduct.cs" />
|
||||
<Compile Include="AddIn\Functions.cs" />
|
||||
<Compile Include="AddIn\WorksheetExtensions.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Assistant\SkuAssist.cs" />
|
||||
</ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user