aboutsummaryrefslogtreecommitdiff
path: root/src/Ribbon/RibbonController.cs
blob: 9011a43773221b7ba97370e5f3b54ad2b081e649 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System.Runtime.InteropServices;
using System.Windows.Forms;
using ExcelDna.Integration.CustomUI;
using RehauSku.PriceListTools;
using RehauSku.Forms;
using System;
using System.Collections.Generic;

namespace RehauSku.Ribbon
{
    [ComVisible(true)]
    public class RibbonController : ExcelRibbon
    {
        public override string GetCustomUI(string RibbonID)
        {
            return @"
      <customUI 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'/> 
                <menu id='conjoinMenu' label='Объединить' imageMso='Copy'>
                    <button id='mergeFiles' label='Сложить' onAction='OnMergePressed'/>    
                    <button id='combineFiles' label='По колонкам' onAction='OnCombinePressed'/>   
                </menu>
            </group>
            <group id='rausettings' label='Настройки'>
                <button id='setPriceList' label='Указать путь к шаблону' size='large' imageMso='CurrentViewSettings' onAction='OnSetPricePressed'/>
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>";
        }

        public void OnMergePressed(IRibbonControl control)
        {
            MergeTool mergeTool = new MergeTool();
            string[] files = Dialog.GetMultiplyFiles();

            if (files.Length != 0)
            {
                mergeTool.SourceFiles = Source.GetSourceLists(files);
                mergeTool.OpenNewPrice();
                mergeTool.FillTarget();
            }
        }

        public void OnCombinePressed(IRibbonControl control)
        {
            CombineTool combineTool = new CombineTool();
            string[] files = Dialog.GetMultiplyFiles();

            if (files.Length != 0)
            {
                combineTool.SourceFiles = Source.GetSourceLists(files);
                combineTool.OpenNewPrice();
                combineTool.FillTarget();
            }
        }

        public void OnExportPressed(IRibbonControl control)
        {
            try
            {
                ExportTool exportTool = new ExportTool();
                exportTool.TryGetSelection();
                exportTool.OpenNewPrice();
                exportTool.FillTarget();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,
                    "Ошибка",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
                return;
            }
        }

        public void OnConvertPressed(IRibbonControl control)
        {
            ConvertTool convertTool = new ConvertTool();

            convertTool.GetCurrent();
            convertTool.OpenNewPrice();
            convertTool.FillTarget();
        }

        public void OnSetPricePressed(IRibbonControl control)
        {
            string path = Dialog.GetFilePath();
            RegistryUtil.PriceListPath = path;
        }
    }
}