From 1dfbfaa461479a14cd75c6fc5f6a5082e61c6371 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 2 Feb 2022 18:05:49 +0300 Subject: Rename Abstract PriceList inheritors --- src/Interface/RibbonController.cs | 4 +- src/PriceListTools/AbstractTool.cs | 4 +- src/PriceListTools/CombineTool.cs | 4 +- src/PriceListTools/ConvertTool.cs | 4 +- src/PriceListTools/MergeTool.cs | 4 +- src/PriceListTools/Source.cs | 104 ---------------------------------- src/PriceListTools/SourcePriceList.cs | 104 ++++++++++++++++++++++++++++++++++ src/PriceListTools/Target.cs | 33 ----------- src/PriceListTools/TargetPriceList.cs | 33 +++++++++++ src/RehauSku.Assist.csproj | 4 +- 10 files changed, 149 insertions(+), 149 deletions(-) delete mode 100644 src/PriceListTools/Source.cs create mode 100644 src/PriceListTools/SourcePriceList.cs delete mode 100644 src/PriceListTools/Target.cs create mode 100644 src/PriceListTools/TargetPriceList.cs (limited to 'src') diff --git a/src/Interface/RibbonController.cs b/src/Interface/RibbonController.cs index cd7058d..2b1fd6b 100644 --- a/src/Interface/RibbonController.cs +++ b/src/Interface/RibbonController.cs @@ -40,7 +40,7 @@ namespace RehauSku.Interface if (files.Length != 0) { - mergeTool.SourceFiles = Source.GetSourceLists(files); + mergeTool.SourceFiles = SourcePriceList.GetSourceLists(files); mergeTool.OpenNewPrice(); mergeTool.FillTarget(); } @@ -53,7 +53,7 @@ namespace RehauSku.Interface if (files.Length != 0) { - combineTool.SourceFiles = Source.GetSourceLists(files); + combineTool.SourceFiles = SourcePriceList.GetSourceLists(files); combineTool.OpenNewPrice(); combineTool.FillTarget(); } diff --git a/src/PriceListTools/AbstractTool.cs b/src/PriceListTools/AbstractTool.cs index 77dc63c..a86fd95 100644 --- a/src/PriceListTools/AbstractTool.cs +++ b/src/PriceListTools/AbstractTool.cs @@ -10,7 +10,7 @@ namespace RehauSku.PriceListTools internal abstract class AbstractTool { protected private Application ExcelApp = (Application)ExcelDnaUtil.Application; - protected private Target TargetFile; + protected private TargetPriceList TargetFile; public void OpenNewPrice() { @@ -18,7 +18,7 @@ namespace RehauSku.PriceListTools try { - TargetFile = new Target(wb); + TargetFile = new TargetPriceList(wb); } catch (Exception ex) diff --git a/src/PriceListTools/CombineTool.cs b/src/PriceListTools/CombineTool.cs index 3222dae..80c7a67 100644 --- a/src/PriceListTools/CombineTool.cs +++ b/src/PriceListTools/CombineTool.cs @@ -7,13 +7,13 @@ namespace RehauSku.PriceListTools { internal class CombineTool : AbstractTool { - public List SourceFiles; + public List SourceFiles; public void FillTarget() { ProgressBar bar = new ProgressBar(SourceFiles.Sum(file => file.PositionAmount.Count)); - foreach (Source source in SourceFiles) + foreach (SourcePriceList source in SourceFiles) { TargetFile.Sheet.Columns[TargetFile.amountCell.Column] .EntireColumn diff --git a/src/PriceListTools/ConvertTool.cs b/src/PriceListTools/ConvertTool.cs index 7308be9..58044ed 100644 --- a/src/PriceListTools/ConvertTool.cs +++ b/src/PriceListTools/ConvertTool.cs @@ -5,13 +5,13 @@ namespace RehauSku.PriceListTools { internal class ConvertTool : AbstractTool { - private Source Current; + private SourcePriceList Current; public void GetCurrent() { try { - Current = new Source(ExcelApp.ActiveWorkbook); + Current = new SourcePriceList(ExcelApp.ActiveWorkbook); } catch (Exception exception) diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs index d31cc8a..22e443f 100644 --- a/src/PriceListTools/MergeTool.cs +++ b/src/PriceListTools/MergeTool.cs @@ -6,13 +6,13 @@ namespace RehauSku.PriceListTools { internal class MergeTool : AbstractTool { - public List SourceFiles; + public List SourceFiles; public void FillTarget() { ProgressBar bar = new ProgressBar(SourceFiles.Sum(x => x.PositionAmount.Count)); - foreach (Source source in SourceFiles) + foreach (SourcePriceList source in SourceFiles) { foreach (var kvp in source.PositionAmount) { 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 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 GetSourceLists(string[] files) - { - var ExcelApp = (Application)ExcelDnaUtil.Application; - ProgressBar bar = new ProgressBar(files.Length); - - List sourceFiles = new List(); - - 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(); - - 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); - } - } - } - } - } -} - diff --git a/src/PriceListTools/SourcePriceList.cs b/src/PriceListTools/SourcePriceList.cs new file mode 100644 index 0000000..a5ee73a --- /dev/null +++ b/src/PriceListTools/SourcePriceList.cs @@ -0,0 +1,104 @@ +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 SourcePriceList : AbstractPriceList + { + public Dictionary PositionAmount { get; private set; } + + public SourcePriceList(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 GetSourceLists(string[] files) + { + var ExcelApp = (Application)ExcelDnaUtil.Application; + ProgressBar bar = new ProgressBar(files.Length); + + List sourceFiles = new List(); + + foreach (string file in files) + { + ExcelApp.ScreenUpdating = false; + Workbook wb = ExcelApp.Workbooks.Open(file); + try + { + SourcePriceList priceList = new SourcePriceList(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(); + + 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); + } + } + } + } + } +} + diff --git a/src/PriceListTools/Target.cs b/src/PriceListTools/Target.cs deleted file mode 100644 index ac91544..0000000 --- a/src/PriceListTools/Target.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.Office.Interop.Excel; -using System; -using System.Linq; - -namespace RehauSku.PriceListTools -{ - internal class Target : AbstractPriceList - { - private const string oldSkuHeader = "Прежний материал"; - public Range oldSkuCell { get; private set; } - - public Target(Workbook workbook) - { - Sheet = workbook.ActiveSheet; - Name = workbook.FullName; - - Range[] cells = new[] - { - amountCell = Sheet.Cells.Find(amountHeader), - skuCell = Sheet.Cells.Find(skuHeader), - groupCell = Sheet.Cells.Find(groupHeader), - nameCell = Sheet.Cells.Find(nameHeader), - oldSkuCell = Sheet.Cells.Find(oldSkuHeader) - }; - - if (cells.Any(x => x == null)) - { - throw new ArgumentException($"Шаблон { Name } не является прайс-листом"); - } - } - } -} - diff --git a/src/PriceListTools/TargetPriceList.cs b/src/PriceListTools/TargetPriceList.cs new file mode 100644 index 0000000..2c2f029 --- /dev/null +++ b/src/PriceListTools/TargetPriceList.cs @@ -0,0 +1,33 @@ +using Microsoft.Office.Interop.Excel; +using System; +using System.Linq; + +namespace RehauSku.PriceListTools +{ + internal class TargetPriceList : AbstractPriceList + { + private const string oldSkuHeader = "Прежний материал"; + public Range oldSkuCell { get; private set; } + + public TargetPriceList(Workbook workbook) + { + Sheet = workbook.ActiveSheet; + Name = workbook.FullName; + + Range[] cells = new[] + { + amountCell = Sheet.Cells.Find(amountHeader), + skuCell = Sheet.Cells.Find(skuHeader), + groupCell = Sheet.Cells.Find(groupHeader), + nameCell = Sheet.Cells.Find(nameHeader), + oldSkuCell = Sheet.Cells.Find(oldSkuHeader) + }; + + if (cells.Any(x => x == null)) + { + throw new ArgumentException($"Шаблон { Name } не является прайс-листом"); + } + } + } +} + diff --git a/src/RehauSku.Assist.csproj b/src/RehauSku.Assist.csproj index 6edbc2c..25fa5a5 100644 --- a/src/RehauSku.Assist.csproj +++ b/src/RehauSku.Assist.csproj @@ -128,8 +128,8 @@ - - + + -- cgit v1.2.3