2022-02-01 20:32:29 +03:00
|
|
|
|
using ExcelDna.Integration.CustomUI;
|
2022-02-14 11:06:40 +03:00
|
|
|
|
using System.Reflection;
|
2022-02-01 20:32:29 +03:00
|
|
|
|
using System.Runtime.InteropServices;
|
2023-04-06 08:29:39 +03:00
|
|
|
|
#if! NET472
|
|
|
|
|
using System.Runtime.Versioning;
|
|
|
|
|
#endif
|
2022-02-01 20:32:29 +03:00
|
|
|
|
using System.Windows.Forms;
|
2021-12-05 16:55:36 +03:00
|
|
|
|
|
2023-03-28 10:36:36 +03:00
|
|
|
|
namespace RhSolutions.Controllers;
|
|
|
|
|
|
2023-04-06 08:29:39 +03:00
|
|
|
|
#if !NET472
|
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
|
|
|
#endif
|
2023-03-28 10:36:36 +03:00
|
|
|
|
[ComVisible(true)]
|
|
|
|
|
public class RibbonController : ExcelRibbon
|
2021-12-05 16:55:36 +03:00
|
|
|
|
{
|
2023-03-28 10:36:36 +03:00
|
|
|
|
private static IRibbonUI ribbonUi;
|
2022-02-04 17:13:47 +03:00
|
|
|
|
|
2023-03-28 10:36: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>
|
2022-12-19 08:44:32 +03:00
|
|
|
|
<tab id='rau' label='RhSolutions'>
|
2021-12-09 14:08:26 +03:00
|
|
|
|
<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'/>
|
2023-04-06 08:29:39 +03:00
|
|
|
|
<button id='merge' label='Объединить' size='normal' imageMso='Copy' onAction='OnToolPressed'/>
|
2023-05-23 07:55:58 +03:00
|
|
|
|
<button id='Guessexport' getEnabled='GetGuessEnabled' label='Найти и экспортировать' size='normal' imageMso='ControlWizards' onAction='OnToolPressed'/>
|
2023-04-07 08:10:51 +03:00
|
|
|
|
<button id='dxfexport' getEnabled='GetDxfEnabled' label='Экспортировать в DXF' size='normal' imageMso='ExportExcel' onAction='OnToolPressed'/>
|
2021-12-09 14:08:26 +03:00
|
|
|
|
</group>
|
2022-02-14 11:06:40 +03:00
|
|
|
|
<group id='rausettings' getLabel='GetVersionLabel'>
|
|
|
|
|
<button id='setPriceList' getLabel='GetPriceListPathLabel' size='large' imageMso='TableExcelSpreadsheetInsert' onAction='OnSetPricePressed'/>
|
2021-12-09 14:08:26 +03:00
|
|
|
|
</group>
|
2021-12-05 16:55:36 +03:00
|
|
|
|
</tab>
|
|
|
|
|
</tabs>
|
|
|
|
|
</ribbon>
|
|
|
|
|
</customUI>";
|
2023-03-28 10:36:36 +03:00
|
|
|
|
}
|
2021-12-07 08:28:21 +03:00
|
|
|
|
|
2023-03-28 10:36:36 +03:00
|
|
|
|
public void RibbonLoad(IRibbonUI sender)
|
|
|
|
|
{
|
|
|
|
|
ribbonUi = sender;
|
|
|
|
|
}
|
2022-02-04 17:13:47 +03:00
|
|
|
|
|
2023-03-28 10:36:36 +03:00
|
|
|
|
public static void RefreshControl(string id)
|
|
|
|
|
{
|
2023-04-06 08:29:39 +03:00
|
|
|
|
ribbonUi?.InvalidateControl(id);
|
2023-03-28 10:36:36 +03:00
|
|
|
|
}
|
2023-03-28 07:25:10 +03:00
|
|
|
|
|
2023-03-28 10:36:36 +03:00
|
|
|
|
public void OnSetPricePressed(IRibbonControl control)
|
|
|
|
|
{
|
2023-04-06 08:29:39 +03:00
|
|
|
|
IFileDialog dialog = RhSolutionsAddIn.ServiceProvider.GetService<IFileDialog>();
|
|
|
|
|
string file = dialog.GetFile();
|
2022-01-07 19:04:07 +03:00
|
|
|
|
|
2023-04-06 08:29:39 +03:00
|
|
|
|
if (!string.IsNullOrEmpty(file))
|
2022-01-07 19:04:07 +03:00
|
|
|
|
{
|
2023-04-06 08:29:39 +03:00
|
|
|
|
RhSolutionsAddIn.Configuration.SetPriceListPath(file);
|
2023-03-28 10:36:36 +03:00
|
|
|
|
RhSolutionsAddIn.Configuration.SaveSettings();
|
2021-12-24 16:22:03 +03:00
|
|
|
|
}
|
2023-03-28 10:36:36 +03:00
|
|
|
|
}
|
2021-12-24 16:22:03 +03:00
|
|
|
|
|
2023-03-28 10:36:36 +03:00
|
|
|
|
public void OnToolPressed(IRibbonControl control)
|
|
|
|
|
{
|
|
|
|
|
try
|
2022-02-04 17:13:47 +03:00
|
|
|
|
{
|
2023-04-14 08:08:46 +03:00
|
|
|
|
var toolFactory = RhSolutionsAddIn.ServiceProvider.GetService<ToolFactory>();
|
|
|
|
|
using Tool tool = toolFactory.GetTool(control.Id);
|
2023-04-06 08:29:39 +03:00
|
|
|
|
tool.Execute();
|
2022-02-04 17:13:47 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-28 10:36:36 +03:00
|
|
|
|
catch (Exception exception)
|
2022-02-04 17:13:47 +03:00
|
|
|
|
{
|
2023-03-28 10:36:36 +03:00
|
|
|
|
MessageBox.Show(exception.Message,
|
|
|
|
|
"Ошибка",
|
|
|
|
|
MessageBoxButtons.OK,
|
|
|
|
|
MessageBoxIcon.Information);
|
|
|
|
|
RhSolutionsAddIn.Excel.StatusBar = false;
|
|
|
|
|
return;
|
2022-02-04 17:13:47 +03:00
|
|
|
|
}
|
2023-03-28 10:36:36 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool GetConvertEnabled(IRibbonControl control)
|
|
|
|
|
{
|
|
|
|
|
if (RhSolutionsAddIn.Excel.ActiveWorkbook == null)
|
|
|
|
|
return false;
|
2022-02-14 11:06:40 +03:00
|
|
|
|
|
2023-03-28 10:36:36 +03:00
|
|
|
|
else
|
2022-02-14 11:06:40 +03:00
|
|
|
|
{
|
2023-03-28 10:36:36 +03:00
|
|
|
|
Worksheet worksheet = RhSolutionsAddIn.Excel.ActiveWorkbook.ActiveSheet;
|
2023-04-06 08:49:12 +03:00
|
|
|
|
return worksheet.IsValidSource();
|
2022-02-14 11:06:40 +03:00
|
|
|
|
}
|
2023-03-28 10:36:36 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool GetExportEnabled(IRibbonControl control)
|
|
|
|
|
{
|
|
|
|
|
if (RhSolutionsAddIn.Excel.ActiveWorkbook == null)
|
|
|
|
|
return false;
|
2022-02-14 11:06:40 +03:00
|
|
|
|
|
2023-03-28 10:36:36 +03:00
|
|
|
|
else
|
2022-02-14 11:06:40 +03:00
|
|
|
|
{
|
2023-03-28 10:36:36 +03:00
|
|
|
|
Range selection = RhSolutionsAddIn.Excel.Selection;
|
|
|
|
|
return selection.Columns.Count == 2;
|
2022-02-14 11:06:40 +03:00
|
|
|
|
}
|
2021-12-05 16:55:36 +03:00
|
|
|
|
}
|
2023-03-28 10:36:36 +03:00
|
|
|
|
|
2023-04-07 08:10:51 +03:00
|
|
|
|
public bool GetDxfEnabled(IRibbonControl control)
|
|
|
|
|
{
|
|
|
|
|
if (RhSolutionsAddIn.Excel.ActiveWorkbook == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Worksheet worksheet = RhSolutionsAddIn.Excel.ActiveWorkbook.ActiveSheet;
|
|
|
|
|
return worksheet.IsValidSource();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 07:55:58 +03:00
|
|
|
|
public bool GetGuessEnabled(IRibbonControl control)
|
|
|
|
|
{
|
|
|
|
|
if (RhSolutionsAddIn.Excel.ActiveWorkbook == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Worksheet worksheet = RhSolutionsAddIn.Excel.ActiveWorkbook.ActiveSheet;
|
|
|
|
|
return !worksheet.IsValidSource();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-28 10:36:36 +03:00
|
|
|
|
public string GetVersionLabel(IRibbonControl control)
|
|
|
|
|
{
|
|
|
|
|
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
|
|
|
|
return $"v{version}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetPriceListPathLabel(IRibbonControl control)
|
|
|
|
|
{
|
|
|
|
|
string name = RhSolutionsAddIn.Configuration.GetPriceListFileName();
|
2023-04-06 08:29:39 +03:00
|
|
|
|
return string.IsNullOrEmpty(name) ? "Шаблонный файл" : name;
|
2023-03-28 10:36:36 +03:00
|
|
|
|
}
|
2021-12-05 16:55:36 +03:00
|
|
|
|
}
|