2022-02-01 20:32:29 +03:00
|
|
|
|
using ExcelDna.Integration.CustomUI;
|
2022-02-04 17:13:47 +03:00
|
|
|
|
using Microsoft.Office.Interop.Excel;
|
2022-02-01 20:32:29 +03:00
|
|
|
|
using RehauSku.PriceListTools;
|
2022-01-09 10:37:25 +03:00
|
|
|
|
using System;
|
2022-02-01 20:32:29 +03:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Windows.Forms;
|
2021-12-05 16:55:36 +03:00
|
|
|
|
|
2022-02-02 09:46:47 +03:00
|
|
|
|
namespace RehauSku.Interface
|
2021-12-05 16:55:36 +03:00
|
|
|
|
{
|
|
|
|
|
[ComVisible(true)]
|
|
|
|
|
public class RibbonController : ExcelRibbon
|
|
|
|
|
{
|
2022-02-04 17:13:47 +03:00
|
|
|
|
private static IRibbonUI ribbonUi;
|
|
|
|
|
|
2021-12-05 16:55:36 +03:00
|
|
|
|
public override string GetCustomUI(string RibbonID)
|
|
|
|
|
{
|
|
|
|
|
return @"
|
2022-02-04 17:13:47 +03:00
|
|
|
|
<customUI onLoad='RibbonLoad' xmlns='http://schemas.microsoft.com/office/2006/01/customui'>
|
2021-12-05 16:55:36 +03:00
|
|
|
|
<ribbon>
|
|
|
|
|
<tabs>
|
2021-12-09 14:08:26 +03:00
|
|
|
|
<tab id='rau' label='REHAU'>
|
|
|
|
|
<group id='priceList' label='Прайс-лист'>
|
2022-02-12 16:57:29 +03:00
|
|
|
|
<button id='export' getEnabled='GetExportEnabled' label='Экспорт в новый файл' size='normal' imageMso='PivotExportToExcel' onAction='OnToolPressed'/>
|
|
|
|
|
<button id='convert' getEnabled='GetConvertEnabled' label='Актуализировать' size='normal' imageMso='FileUpdate' onAction='OnToolPressed'/>
|
2022-01-07 19:04:07 +03:00
|
|
|
|
<menu id='conjoinMenu' label='Объединить' imageMso='Copy'>
|
2022-02-12 16:57:29 +03:00
|
|
|
|
<button id='merge' label='Сложить' onAction='OnToolPressed'/>
|
|
|
|
|
<button id='combine' label='По колонкам' onAction='OnToolPressed'/>
|
2022-01-07 19:04:07 +03:00
|
|
|
|
</menu>
|
2021-12-09 14:08:26 +03:00
|
|
|
|
</group>
|
|
|
|
|
<group id='rausettings' label='Настройки'>
|
2022-01-28 09:08:35 +03:00
|
|
|
|
<button id='setPriceList' label='Указать путь к шаблону' size='large' imageMso='CurrentViewSettings' onAction='OnSetPricePressed'/>
|
2021-12-09 14:08:26 +03:00
|
|
|
|
</group>
|
2021-12-05 16:55:36 +03:00
|
|
|
|
</tab>
|
|
|
|
|
</tabs>
|
|
|
|
|
</ribbon>
|
|
|
|
|
</customUI>";
|
|
|
|
|
}
|
2021-12-07 08:28:21 +03:00
|
|
|
|
|
2022-02-04 17:13:47 +03:00
|
|
|
|
public void RibbonLoad(IRibbonUI sender)
|
|
|
|
|
{
|
|
|
|
|
ribbonUi = sender;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void RefreshControl(string id)
|
|
|
|
|
{
|
|
|
|
|
if (ribbonUi != null)
|
|
|
|
|
{
|
|
|
|
|
ribbonUi.InvalidateControl(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-12 16:02:55 +03:00
|
|
|
|
public void OnSetPricePressed(IRibbonControl control)
|
2021-12-24 16:22:03 +03:00
|
|
|
|
{
|
2022-02-12 16:02:55 +03:00
|
|
|
|
string path = Dialog.GetFilePath();
|
2022-01-27 17:34:03 +03:00
|
|
|
|
|
2022-02-12 16:02:55 +03:00
|
|
|
|
if (!string.IsNullOrEmpty(path))
|
2021-12-24 16:22:03 +03:00
|
|
|
|
{
|
2022-02-12 16:02:55 +03:00
|
|
|
|
RegistryUtil.PriceListPath = path;
|
2022-01-07 19:04:07 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-12 16:02:55 +03:00
|
|
|
|
public void OnToolPressed(IRibbonControl control)
|
2022-01-07 19:04:07 +03:00
|
|
|
|
{
|
2022-02-12 16:02:55 +03:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
AbstractTool tool;
|
|
|
|
|
switch (control.Id)
|
|
|
|
|
{
|
2022-02-12 16:57:29 +03:00
|
|
|
|
case "export":
|
2022-02-12 16:02:55 +03:00
|
|
|
|
tool = new ExportTool();
|
|
|
|
|
break;
|
2022-02-12 16:57:29 +03:00
|
|
|
|
case "convert":
|
2022-02-12 16:02:55 +03:00
|
|
|
|
tool = new ConvertTool();
|
|
|
|
|
break;
|
2022-02-12 16:57:29 +03:00
|
|
|
|
case "merge":
|
2022-02-12 16:02:55 +03:00
|
|
|
|
tool = new MergeTool();
|
|
|
|
|
break;
|
2022-02-12 16:57:29 +03:00
|
|
|
|
case "combine":
|
2022-02-12 16:02:55 +03:00
|
|
|
|
tool = new CombineTool();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new Exception("Неизвестный инструмент");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tool.OpenNewPrice();
|
|
|
|
|
tool.FillTarget();
|
|
|
|
|
}
|
2022-01-27 17:34:03 +03:00
|
|
|
|
|
2022-02-12 16:02:55 +03:00
|
|
|
|
catch (Exception exception)
|
2022-01-07 19:04:07 +03:00
|
|
|
|
{
|
2022-02-12 16:02:55 +03:00
|
|
|
|
MessageBox.Show(exception.Message,
|
|
|
|
|
"Ошибка",
|
|
|
|
|
MessageBoxButtons.OK,
|
|
|
|
|
MessageBoxIcon.Information);
|
|
|
|
|
return;
|
2021-12-24 16:22:03 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-04 17:13:47 +03:00
|
|
|
|
public bool GetConvertEnabled(IRibbonControl control)
|
|
|
|
|
{
|
|
|
|
|
if (AddIn.Excel.ActiveWorkbook == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Worksheet worksheet = AddIn.Excel.ActiveWorkbook.ActiveSheet;
|
|
|
|
|
return worksheet.IsRehauSource();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool GetExportEnabled(IRibbonControl control)
|
|
|
|
|
{
|
|
|
|
|
if (AddIn.Excel.ActiveWorkbook == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Range selection = AddIn.Excel.Selection;
|
|
|
|
|
return selection.Columns.Count == 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-05 16:55:36 +03:00
|
|
|
|
}
|
|
|
|
|
}
|