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/PriceListTools/SourcePriceList.cs | 104 ++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/PriceListTools/SourcePriceList.cs (limited to 'src/PriceListTools/SourcePriceList.cs') 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); + } + } + } + } + } +} + -- cgit v1.2.3 From ef04747df50da1fbb5124fc9c02f1869d93864f5 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Thu, 3 Feb 2022 21:56:14 +0300 Subject: Additional message to statusbar --- src/PriceListTools/SourcePriceList.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/PriceListTools/SourcePriceList.cs') diff --git a/src/PriceListTools/SourcePriceList.cs b/src/PriceListTools/SourcePriceList.cs index a5ee73a..ebd4d6a 100644 --- a/src/PriceListTools/SourcePriceList.cs +++ b/src/PriceListTools/SourcePriceList.cs @@ -40,7 +40,7 @@ namespace RehauSku.PriceListTools public static List GetSourceLists(string[] files) { var ExcelApp = (Application)ExcelDnaUtil.Application; - ProgressBar bar = new ProgressBar(files.Length); + ProgressBar bar = new ProgressBar("Открываю исходные файлы...", files.Length); List sourceFiles = new List(); -- cgit v1.2.3 From 6e889419e2658a3a80fa00582314f1428f6052e5 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Fri, 4 Feb 2022 09:17:12 +0300 Subject: Add Result Statusbar message --- src/PriceListTools/SourcePriceList.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/PriceListTools/SourcePriceList.cs') diff --git a/src/PriceListTools/SourcePriceList.cs b/src/PriceListTools/SourcePriceList.cs index ebd4d6a..ec9025d 100644 --- a/src/PriceListTools/SourcePriceList.cs +++ b/src/PriceListTools/SourcePriceList.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; using RehauSku.Interface; +using RehauSku.Assistant; namespace RehauSku.PriceListTools { @@ -53,7 +54,7 @@ namespace RehauSku.PriceListTools SourcePriceList priceList = new SourcePriceList(wb); sourceFiles.Add(priceList); wb.Close(); - bar.DoProgress(); + bar.Update(); } catch (Exception ex) { @@ -63,7 +64,7 @@ namespace RehauSku.PriceListTools System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); wb.Close(); - bar.DoProgress(); + bar.Update(); } ExcelApp.ScreenUpdating = true; } @@ -85,6 +86,12 @@ namespace RehauSku.PriceListTools object name = Sheet.Cells[row, nameCell.Column].Value2; object sku = Sheet.Cells[row, skuCell.Column].Value2; + if (group == null || name == null || sku == null) + continue; + + if (!sku.ToString().IsRehauSku()) + continue; + Position p = new Position(group.ToString(), sku.ToString(), name.ToString()); if (PositionAmount.ContainsKey(p)) -- cgit v1.2.3 From cc96e1ebe7255c7278c70cef0f951103e9844487 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Fri, 4 Feb 2022 17:13:47 +0300 Subject: Implement Enable/Disable tools buttons events --- src/PriceListTools/SourcePriceList.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/PriceListTools/SourcePriceList.cs') diff --git a/src/PriceListTools/SourcePriceList.cs b/src/PriceListTools/SourcePriceList.cs index ec9025d..01637f8 100644 --- a/src/PriceListTools/SourcePriceList.cs +++ b/src/PriceListTools/SourcePriceList.cs @@ -4,10 +4,10 @@ using System; using System.Collections.Generic; using System.Linq; using RehauSku.Interface; -using RehauSku.Assistant; namespace RehauSku.PriceListTools { + internal class SourcePriceList : AbstractPriceList { public Dictionary PositionAmount { get; private set; } @@ -22,7 +22,7 @@ namespace RehauSku.PriceListTools Sheet = workbook.ActiveSheet; Name = workbook.Name; - Range[] cells = new [] + Range[] cells = new[] { amountCell = Sheet.Cells.Find(amountHeader), skuCell = Sheet.Cells.Find(skuHeader), @@ -30,7 +30,7 @@ namespace RehauSku.PriceListTools nameCell = Sheet.Cells.Find(nameHeader) }; - if (cells.Any(x => x == null)) + if (cells.Any(x => x == null)) { throw new ArgumentException($"Файл {Name} не распознан"); } -- cgit v1.2.3