aboutsummaryrefslogtreecommitdiff
path: root/src/PriceListTools/SourceUtil.cs
blob: 5c575f622b67afab27b941e285a88f437550684c (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
using ExcelDna.Integration;
using Microsoft.Office.Interop.Excel;
using System;
using System.Collections.Generic;

namespace RehauSku.PriceListTools
{
    internal static class SourceUtil
    {
        public static List<Source> GetSourceLists(string[] files)
        {
            var ExcelApp = (Application)ExcelDnaUtil.Application;

            List<Source> sourceFiles = new List<Source>();

            ExcelApp.ScreenUpdating = false;
            foreach (string file in files)
            {
                Workbook wb = ExcelApp.Workbooks.Open(file);
                try
                {
                    Source priceList = new Source(wb);
                    sourceFiles.Add(priceList);
                    wb.Close();
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show
                        (ex.Message,
                        "Ошибка открытия исходного прайс-листа",
                        System.Windows.Forms.MessageBoxButtons.OK,
                        System.Windows.Forms.MessageBoxIcon.Information);
                    wb.Close();
                }
            }
            ExcelApp.ScreenUpdating = true;

            return sourceFiles;
        }
    }
}