aboutsummaryrefslogtreecommitdiff
path: root/src/PriceListTools/Source.cs
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2022-02-02 18:05:49 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2022-02-02 18:05:49 +0300
commit1dfbfaa461479a14cd75c6fc5f6a5082e61c6371 (patch)
tree20b7da671f7da0703de896a957614eadadac6316 /src/PriceListTools/Source.cs
parentbf2e187e6625ca4d19a6d48000843c9813a3efa5 (diff)
Rename Abstract PriceList inheritors
Diffstat (limited to 'src/PriceListTools/Source.cs')
-rw-r--r--src/PriceListTools/Source.cs104
1 files changed, 0 insertions, 104 deletions
diff --git a/src/PriceListTools/Source.cs b/src/PriceListTools/Source.cs
deleted file mode 100644
index a20ad81..0000000
--- a/src/PriceListTools/Source.cs
+++ /dev/null
@@ -1,104 +0,0 @@
-using ExcelDna.Integration;
-using Microsoft.Office.Interop.Excel;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using RehauSku.Interface;
-
-namespace RehauSku.PriceListTools
-{
- internal class Source : AbstractPriceList
- {
- public Dictionary<Position, double> PositionAmount { get; private set; }
-
- public Source(Workbook workbook)
- {
- if (workbook == null)
- {
- throw new ArgumentException($"Нет рабочего файла");
- }
-
- Sheet = workbook.ActiveSheet;
- Name = workbook.Name;
-
- Range[] cells = new []
- {
- amountCell = Sheet.Cells.Find(amountHeader),
- skuCell = Sheet.Cells.Find(skuHeader),
- groupCell = Sheet.Cells.Find(groupHeader),
- nameCell = Sheet.Cells.Find(nameHeader)
- };
-
- if (cells.Any(x => x == null))
- {
- throw new ArgumentException($"Файл {Name} не распознан");
- }
-
- CreatePositionsDict();
- }
-
- public static List<Source> GetSourceLists(string[] files)
- {
- var ExcelApp = (Application)ExcelDnaUtil.Application;
- ProgressBar bar = new ProgressBar(files.Length);
-
- List<Source> sourceFiles = new List<Source>();
-
- foreach (string file in files)
- {
- ExcelApp.ScreenUpdating = false;
- Workbook wb = ExcelApp.Workbooks.Open(file);
- try
- {
- Source priceList = new Source(wb);
- sourceFiles.Add(priceList);
- wb.Close();
- bar.DoProgress();
- }
- catch (Exception ex)
- {
- System.Windows.Forms.MessageBox.Show
- (ex.Message,
- "Ошибка открытия исходного прайс-листа",
- System.Windows.Forms.MessageBoxButtons.OK,
- System.Windows.Forms.MessageBoxIcon.Information);
- wb.Close();
- bar.DoProgress();
- }
- ExcelApp.ScreenUpdating = true;
- }
-
- return sourceFiles;
- }
-
- private void CreatePositionsDict()
- {
- PositionAmount = new Dictionary<Position, double>();
-
- for (int row = amountCell.Row + 1; row <= Sheet.Cells[Sheet.Rows.Count, amountCell.Column].End[XlDirection.xlUp].Row; row++)
- {
- object amount = Sheet.Cells[row, amountCell.Column].Value2;
-
- if (amount != null && (double)amount != 0)
- {
- object group = Sheet.Cells[row, groupCell.Column].Value2;
- object name = Sheet.Cells[row, nameCell.Column].Value2;
- object sku = Sheet.Cells[row, skuCell.Column].Value2;
-
- Position p = new Position(group.ToString(), sku.ToString(), name.ToString());
-
- if (PositionAmount.ContainsKey(p))
- {
- PositionAmount[p] += (double)amount;
- }
-
- else
- {
- PositionAmount.Add(p, (double)amount);
- }
- }
- }
- }
- }
-}
-