From 06799119fb83cb6b75721c5cf60f4051e50976a7 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 2 Feb 2022 09:46:47 +0300 Subject: Add Interface namespace --- src/PriceListTools/CombineTool.cs | 2 +- src/PriceListTools/ConvertTool.cs | 5 +++-- src/PriceListTools/ExportTool.cs | 2 +- src/PriceListTools/MergeTool.cs | 5 +++-- 4 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src/PriceListTools') diff --git a/src/PriceListTools/CombineTool.cs b/src/PriceListTools/CombineTool.cs index da29e4d..e637fef 100644 --- a/src/PriceListTools/CombineTool.cs +++ b/src/PriceListTools/CombineTool.cs @@ -25,7 +25,7 @@ namespace RehauSku.PriceListTools FilterByAmount(); - Forms.Dialog.SaveWorkbookAs(); + Interface.Dialog.SaveWorkbookAs(); } } } diff --git a/src/PriceListTools/ConvertTool.cs b/src/PriceListTools/ConvertTool.cs index f37bfe2..d43b30d 100644 --- a/src/PriceListTools/ConvertTool.cs +++ b/src/PriceListTools/ConvertTool.cs @@ -1,4 +1,5 @@ -using System; +using RehauSku.Interface; +using System; namespace RehauSku.PriceListTools { @@ -31,7 +32,7 @@ namespace RehauSku.PriceListTools FilterByAmount(); - Forms.Dialog.SaveWorkbookAs(); + Dialog.SaveWorkbookAs(); } } } \ No newline at end of file diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs index bfb3d8a..119a289 100644 --- a/src/PriceListTools/ExportTool.cs +++ b/src/PriceListTools/ExportTool.cs @@ -31,7 +31,7 @@ namespace RehauSku.PriceListTools FilterByAmount(); - Forms.Dialog.SaveWorkbookAs(); + Interface.Dialog.SaveWorkbookAs(); } private void GetSelected() diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs index e196b3a..895740c 100644 --- a/src/PriceListTools/MergeTool.cs +++ b/src/PriceListTools/MergeTool.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using RehauSku.Interface; +using System.Collections.Generic; namespace RehauSku.PriceListTools { @@ -16,7 +17,7 @@ namespace RehauSku.PriceListTools FilterByAmount(); - Forms.Dialog.SaveWorkbookAs(); + Dialog.SaveWorkbookAs(); } } } -- cgit v1.2.3 From 120eee0231d02e90d9d195ebc38327a58d4564a8 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 2 Feb 2022 10:23:50 +0300 Subject: Add Excel statusbar progress message --- src/PriceListTools/CombineTool.cs | 9 ++++++++- src/PriceListTools/ConvertTool.cs | 5 +++++ src/PriceListTools/ExportTool.cs | 5 ++++- src/PriceListTools/MergeTool.cs | 6 ++++++ src/PriceListTools/Source.cs | 4 ++++ 5 files changed, 27 insertions(+), 2 deletions(-) (limited to 'src/PriceListTools') diff --git a/src/PriceListTools/CombineTool.cs b/src/PriceListTools/CombineTool.cs index e637fef..cb47379 100644 --- a/src/PriceListTools/CombineTool.cs +++ b/src/PriceListTools/CombineTool.cs @@ -1,5 +1,7 @@ using Microsoft.Office.Interop.Excel; using System.Collections.Generic; +using RehauSku.Interface; +using System.Linq; namespace RehauSku.PriceListTools { @@ -9,6 +11,8 @@ namespace RehauSku.PriceListTools public void FillTarget() { + ProgressBar bar = new ProgressBar(SourceFiles.Sum(file => file.PositionAmount.Count)); + foreach (Source source in SourceFiles) { TargetFile.Sheet.Columns[TargetFile.amountCell.Column] @@ -19,8 +23,11 @@ namespace RehauSku.PriceListTools newColumnHeader.Value2 = $"{source.Name}"; newColumnHeader.WrapText = true; - foreach(var kvp in source.PositionAmount) + foreach (var kvp in source.PositionAmount) + { FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column - 1, TargetFile.amountCell.Column); + bar.DoProgress(); + } } FilterByAmount(); diff --git a/src/PriceListTools/ConvertTool.cs b/src/PriceListTools/ConvertTool.cs index d43b30d..d10d65e 100644 --- a/src/PriceListTools/ConvertTool.cs +++ b/src/PriceListTools/ConvertTool.cs @@ -27,8 +27,13 @@ namespace RehauSku.PriceListTools public void FillTarget() { + ProgressBar bar = new ProgressBar(Current.PositionAmount.Count); + foreach (var kvp in Current.PositionAmount) + { FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column); + bar.DoProgress(); + } FilterByAmount(); diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs index 119a289..568145d 100644 --- a/src/PriceListTools/ExportTool.cs +++ b/src/PriceListTools/ExportTool.cs @@ -2,6 +2,7 @@ using RehauSku.Assistant; using System; using System.Collections.Generic; +using RehauSku.Interface; namespace RehauSku.PriceListTools { @@ -23,10 +24,12 @@ namespace RehauSku.PriceListTools public void FillTarget() { GetSelected(); - + ProgressBar bar = new ProgressBar(PositionAmount.Count); + foreach (var kvp in PositionAmount) { FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column); + bar.DoProgress(); } FilterByAmount(); diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs index 895740c..a51b9b7 100644 --- a/src/PriceListTools/MergeTool.cs +++ b/src/PriceListTools/MergeTool.cs @@ -1,5 +1,6 @@ using RehauSku.Interface; using System.Collections.Generic; +using System.Linq; namespace RehauSku.PriceListTools { @@ -9,10 +10,15 @@ namespace RehauSku.PriceListTools public void FillTarget() { + ProgressBar bar = new ProgressBar(SourceFiles.Sum(x => x.PositionAmount.Count)); + foreach (Source source in SourceFiles) { foreach (var kvp in source.PositionAmount) + { FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column); + bar.DoProgress(); + } } FilterByAmount(); diff --git a/src/PriceListTools/Source.cs b/src/PriceListTools/Source.cs index 7cf56be..fe5ee9b 100644 --- a/src/PriceListTools/Source.cs +++ b/src/PriceListTools/Source.cs @@ -3,6 +3,7 @@ using Microsoft.Office.Interop.Excel; using System; using System.Collections.Generic; using System.Linq; +using RehauSku.Interface; namespace RehauSku.PriceListTools { @@ -39,6 +40,7 @@ namespace RehauSku.PriceListTools public static List GetSourceLists(string[] files) { var ExcelApp = (Application)ExcelDnaUtil.Application; + ProgressBar bar = new ProgressBar(files.Length); List sourceFiles = new List(); @@ -51,6 +53,7 @@ namespace RehauSku.PriceListTools Source priceList = new Source(wb); sourceFiles.Add(priceList); wb.Close(); + bar.DoProgress(); } catch (Exception ex) { @@ -60,6 +63,7 @@ namespace RehauSku.PriceListTools System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); wb.Close(); + bar.DoProgress(); } ExcelApp.ScreenUpdating = true; } -- cgit v1.2.3 From cb5fee18918b5a29ccff23a0fb74bb13151f2e42 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 2 Feb 2022 18:02:17 +0300 Subject: Rename Abstract tool --- src/PriceListTools/AbstractTool.cs | 175 ++++++++++++++++++++++++++++++++++++ src/PriceListTools/CombineTool.cs | 2 +- src/PriceListTools/ConvertTool.cs | 2 +- src/PriceListTools/ExportTool.cs | 2 +- src/PriceListTools/MergeTool.cs | 2 +- src/PriceListTools/PriceListTool.cs | 175 ------------------------------------ 6 files changed, 179 insertions(+), 179 deletions(-) create mode 100644 src/PriceListTools/AbstractTool.cs delete mode 100644 src/PriceListTools/PriceListTool.cs (limited to 'src/PriceListTools') diff --git a/src/PriceListTools/AbstractTool.cs b/src/PriceListTools/AbstractTool.cs new file mode 100644 index 0000000..77dc63c --- /dev/null +++ b/src/PriceListTools/AbstractTool.cs @@ -0,0 +1,175 @@ +using ExcelDna.Integration; +using Microsoft.Office.Interop.Excel; +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using Application = Microsoft.Office.Interop.Excel.Application; + +namespace RehauSku.PriceListTools +{ + internal abstract class AbstractTool + { + protected private Application ExcelApp = (Application)ExcelDnaUtil.Application; + protected private Target TargetFile; + + public void OpenNewPrice() + { + Workbook wb = ExcelApp.Workbooks.Open(RegistryUtil.PriceListPath); + + try + { + TargetFile = new Target(wb); + } + + catch (Exception ex) + { + MessageBox.Show + (ex.Message, + "Ошибка открытия шаблонного прайс-листа", + MessageBoxButtons.OK, + MessageBoxIcon.Information); + wb.Close(); + throw ex; + } + } + + protected private void FillColumnsWithDictionary(KeyValuePair positionAmount, params int[] columns) + { + int? row = GetPositionRow(positionAmount.Key.Sku, positionAmount.Key.Group, TargetFile.skuCell.Column); + + if (row != null) + { + foreach (int column in columns) + { + Range sumCell = TargetFile.Sheet.Cells[row, column]; + + if (sumCell.Value2 == null) + { + sumCell.Value2 = positionAmount.Value; + } + + else + { + sumCell.Value2 += positionAmount.Value; + } + } + } + + else + { + string sku = positionAmount.Key.Sku.Substring(1, 6); + + row = GetPositionRow(sku, positionAmount.Key.Group, TargetFile.skuCell.Column); + + if (row != null) + { + foreach (int column in columns) + { + Range amountCell = TargetFile.Sheet.Cells[row, column]; + + if (amountCell.Value2 == null) + { + amountCell.Value2 = positionAmount.Value; + } + + else + { + amountCell.Value2 += positionAmount.Value; + } + + Range oldSkuCell = TargetFile.Sheet.Cells[row, TargetFile.oldSkuCell.Column]; + oldSkuCell.Value2 = positionAmount.Key.Sku; + } + } + + else + { + FillMissing(positionAmount, columns); + } + } + } + + protected private void FillMissing(KeyValuePair positionAmount, params int[] columns) + { + Range foundCell = TargetFile.oldSkuCell.EntireColumn.Find(positionAmount.Key.Sku); + int row; + + if (foundCell == null) + { + row = TargetFile.Sheet.Cells[TargetFile.Sheet.Rows.Count, TargetFile.skuCell.Column] + .End[XlDirection.xlUp] + .Row + 1; + + TargetFile.Sheet.Rows[row] + .EntireRow + .Insert(XlInsertShiftDirection.xlShiftDown, XlInsertFormatOrigin.xlFormatFromLeftOrAbove); + + Range previous = TargetFile.Sheet.Rows[row - 1]; + Range current = TargetFile.Sheet.Rows[row]; + + previous.Copy(current); + current.ClearContents(); + + TargetFile.Sheet.Cells[row, TargetFile.groupCell.Column].Value2 = positionAmount.Key.Group; + TargetFile.Sheet.Cells[row, TargetFile.oldSkuCell.Column].Value2 = positionAmount.Key.Sku; + TargetFile.Sheet.Cells[row, TargetFile.nameCell.Column].Value2 = positionAmount.Key.Name; + TargetFile.Sheet.Cells[row, TargetFile.skuCell.Column].Value2 = "Не найден"; + } + + else + { + row = foundCell.Row; + } + + foreach (int column in columns) + { + if (TargetFile.Sheet.Cells[row, column].Value2 == null) + { + TargetFile.Sheet.Cells[row, column].Value2 = positionAmount.Value; + } + + else + { + TargetFile.Sheet.Cells[row, column].Value2 += positionAmount.Value; + } + } + } + + protected private int? GetPositionRow(string sku, string group, int column) + { + int? row = null; + Range foundCell = TargetFile.Sheet.Columns[column].Find(sku); + string foundGroupValue; + + if (foundCell == null) return null; + + else + { + row = foundCell.Row; + foundGroupValue = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString(); + } + + if (string.IsNullOrEmpty(group) || group.Equals(foundGroupValue)) + return row; + + else + while (true) + { + foundCell = TargetFile.skuCell.EntireColumn.FindNext(foundCell); + if (foundCell == null) return row; + + foundGroupValue = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString(); + if (group.Equals(foundGroupValue)) return foundCell.Row; + } + } + + protected private void FilterByAmount() + { + AutoFilter filter = TargetFile.Sheet.AutoFilter; + int startColumn = filter.Range.Column; + + filter.Range.AutoFilter(TargetFile.amountCell.Column - startColumn + 1, "<>"); + TargetFile.Sheet.Range["A1"].Activate(); + } + } +} \ No newline at end of file diff --git a/src/PriceListTools/CombineTool.cs b/src/PriceListTools/CombineTool.cs index cb47379..3222dae 100644 --- a/src/PriceListTools/CombineTool.cs +++ b/src/PriceListTools/CombineTool.cs @@ -5,7 +5,7 @@ using System.Linq; namespace RehauSku.PriceListTools { - internal class CombineTool : PriceListTool + internal class CombineTool : AbstractTool { public List SourceFiles; diff --git a/src/PriceListTools/ConvertTool.cs b/src/PriceListTools/ConvertTool.cs index d10d65e..7308be9 100644 --- a/src/PriceListTools/ConvertTool.cs +++ b/src/PriceListTools/ConvertTool.cs @@ -3,7 +3,7 @@ using System; namespace RehauSku.PriceListTools { - internal class ConvertTool : PriceListTool + internal class ConvertTool : AbstractTool { private Source Current; diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs index 568145d..562c1b2 100644 --- a/src/PriceListTools/ExportTool.cs +++ b/src/PriceListTools/ExportTool.cs @@ -6,7 +6,7 @@ using RehauSku.Interface; namespace RehauSku.PriceListTools { - internal class ExportTool : PriceListTool + internal class ExportTool : AbstractTool { private Dictionary PositionAmount; private Range Selection; diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs index a51b9b7..d31cc8a 100644 --- a/src/PriceListTools/MergeTool.cs +++ b/src/PriceListTools/MergeTool.cs @@ -4,7 +4,7 @@ using System.Linq; namespace RehauSku.PriceListTools { - internal class MergeTool : PriceListTool + internal class MergeTool : AbstractTool { public List SourceFiles; diff --git a/src/PriceListTools/PriceListTool.cs b/src/PriceListTools/PriceListTool.cs deleted file mode 100644 index 0a82a41..0000000 --- a/src/PriceListTools/PriceListTool.cs +++ /dev/null @@ -1,175 +0,0 @@ -using ExcelDna.Integration; -using Microsoft.Office.Interop.Excel; -using System; -using System.Collections.Generic; -using System.Windows.Forms; -using Application = Microsoft.Office.Interop.Excel.Application; - -namespace RehauSku.PriceListTools -{ - internal abstract class PriceListTool - { - protected private Application ExcelApp = (Application)ExcelDnaUtil.Application; - protected private Target TargetFile; - - public void OpenNewPrice() - { - Workbook wb = ExcelApp.Workbooks.Open(RegistryUtil.PriceListPath); - - try - { - TargetFile = new Target(wb); - } - - catch (Exception ex) - { - MessageBox.Show - (ex.Message, - "Ошибка открытия шаблонного прайс-листа", - MessageBoxButtons.OK, - MessageBoxIcon.Information); - wb.Close(); - throw ex; - } - } - - protected private void FillColumnsWithDictionary(KeyValuePair positionAmount, params int[] columns) - { - int? row = GetPositionRow(positionAmount.Key.Sku, positionAmount.Key.Group, TargetFile.skuCell.Column); - - if (row != null) - { - foreach (int column in columns) - { - Range sumCell = TargetFile.Sheet.Cells[row, column]; - - if (sumCell.Value2 == null) - { - sumCell.Value2 = positionAmount.Value; - } - - else - { - sumCell.Value2 += positionAmount.Value; - } - } - } - - else - { - string sku = positionAmount.Key.Sku.Substring(1, 6); - - row = GetPositionRow(sku, positionAmount.Key.Group, TargetFile.skuCell.Column); - - if (row != null) - { - foreach (int column in columns) - { - Range amountCell = TargetFile.Sheet.Cells[row, column]; - - if (amountCell.Value2 == null) - { - amountCell.Value2 = positionAmount.Value; - } - - else - { - amountCell.Value2 += positionAmount.Value; - } - - Range oldSkuCell = TargetFile.Sheet.Cells[row, TargetFile.oldSkuCell.Column]; - oldSkuCell.Value2 = positionAmount.Key.Sku; - } - } - - else - { - FillMissing(positionAmount, columns); - } - } - } - - protected private void FillMissing(KeyValuePair positionAmount, params int[] columns) - { - Range foundCell = TargetFile.oldSkuCell.EntireColumn.Find(positionAmount.Key.Sku); - int row; - - if (foundCell == null) - { - row = TargetFile.Sheet.Cells[TargetFile.Sheet.Rows.Count, TargetFile.skuCell.Column] - .End[XlDirection.xlUp] - .Row + 1; - - TargetFile.Sheet.Rows[row] - .EntireRow - .Insert(XlInsertShiftDirection.xlShiftDown, XlInsertFormatOrigin.xlFormatFromLeftOrAbove); - - Range previous = TargetFile.Sheet.Rows[row - 1]; - Range current = TargetFile.Sheet.Rows[row]; - - previous.Copy(current); - current.ClearContents(); - - TargetFile.Sheet.Cells[row, TargetFile.groupCell.Column].Value2 = positionAmount.Key.Group; - TargetFile.Sheet.Cells[row, TargetFile.oldSkuCell.Column].Value2 = positionAmount.Key.Sku; - TargetFile.Sheet.Cells[row, TargetFile.nameCell.Column].Value2 = positionAmount.Key.Name; - TargetFile.Sheet.Cells[row, TargetFile.skuCell.Column].Value2 = "Не найден"; - } - - else - { - row = foundCell.Row; - } - - foreach (int column in columns) - { - if (TargetFile.Sheet.Cells[row, column].Value2 == null) - { - TargetFile.Sheet.Cells[row, column].Value2 = positionAmount.Value; - } - - else - { - TargetFile.Sheet.Cells[row, column].Value2 += positionAmount.Value; - } - } - } - - protected private int? GetPositionRow(string sku, string group, int column) - { - int? row = null; - Range foundCell = TargetFile.Sheet.Columns[column].Find(sku); - string foundGroupValue; - - if (foundCell == null) return null; - - else - { - row = foundCell.Row; - foundGroupValue = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString(); - } - - if (string.IsNullOrEmpty(group) || group.Equals(foundGroupValue)) - return row; - - else - while (true) - { - foundCell = TargetFile.skuCell.EntireColumn.FindNext(foundCell); - if (foundCell == null) return row; - - foundGroupValue = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString(); - if (group.Equals(foundGroupValue)) return foundCell.Row; - } - } - - protected private void FilterByAmount() - { - AutoFilter filter = TargetFile.Sheet.AutoFilter; - int startColumn = filter.Range.Column; - - filter.Range.AutoFilter(TargetFile.amountCell.Column - startColumn + 1, "<>"); - TargetFile.Sheet.Range["A1"].Activate(); - } - } -} \ No newline at end of file -- cgit v1.2.3 From bf2e187e6625ca4d19a6d48000843c9813a3efa5 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 2 Feb 2022 18:03:49 +0300 Subject: Make base PriceList class abstract --- src/PriceListTools/AbstractPriceList.cs | 20 ++++++++++++++++++++ src/PriceListTools/PriceList.cs | 20 -------------------- src/PriceListTools/Source.cs | 2 +- src/PriceListTools/Target.cs | 2 +- 4 files changed, 22 insertions(+), 22 deletions(-) create mode 100644 src/PriceListTools/AbstractPriceList.cs delete mode 100644 src/PriceListTools/PriceList.cs (limited to 'src/PriceListTools') diff --git a/src/PriceListTools/AbstractPriceList.cs b/src/PriceListTools/AbstractPriceList.cs new file mode 100644 index 0000000..06427a0 --- /dev/null +++ b/src/PriceListTools/AbstractPriceList.cs @@ -0,0 +1,20 @@ +using Microsoft.Office.Interop.Excel; + +namespace RehauSku.PriceListTools +{ + internal abstract class AbstractPriceList + { + protected const string amountHeader = "Кол-во"; + protected const string skuHeader = "Актуальный материал"; + protected const string groupHeader = "Программа"; + protected const string nameHeader = "Наименование"; + + public Range amountCell { get; protected set; } + public Range skuCell { get; protected set; } + public Range groupCell { get; protected set; } + public Range nameCell { get; protected set; } + + public Worksheet Sheet { get; protected set; } + public string Name { get; protected set; } + } +} \ No newline at end of file diff --git a/src/PriceListTools/PriceList.cs b/src/PriceListTools/PriceList.cs deleted file mode 100644 index 65ff3df..0000000 --- a/src/PriceListTools/PriceList.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Microsoft.Office.Interop.Excel; - -namespace RehauSku.PriceListTools -{ - internal class PriceList - { - protected const string amountHeader = "Кол-во"; - protected const string skuHeader = "Актуальный материал"; - protected const string groupHeader = "Программа"; - protected const string nameHeader = "Наименование"; - - public Range amountCell { get; protected set; } - public Range skuCell { get; protected set; } - public Range groupCell { get; protected set; } - public Range nameCell { get; protected set; } - - public Worksheet Sheet { get; protected set; } - public string Name { get; protected set; } - } -} \ No newline at end of file diff --git a/src/PriceListTools/Source.cs b/src/PriceListTools/Source.cs index fe5ee9b..a20ad81 100644 --- a/src/PriceListTools/Source.cs +++ b/src/PriceListTools/Source.cs @@ -7,7 +7,7 @@ using RehauSku.Interface; namespace RehauSku.PriceListTools { - internal class Source : PriceList + internal class Source : AbstractPriceList { public Dictionary PositionAmount { get; private set; } diff --git a/src/PriceListTools/Target.cs b/src/PriceListTools/Target.cs index 996a092..ac91544 100644 --- a/src/PriceListTools/Target.cs +++ b/src/PriceListTools/Target.cs @@ -4,7 +4,7 @@ using System.Linq; namespace RehauSku.PriceListTools { - internal class Target : PriceList + internal class Target : AbstractPriceList { private const string oldSkuHeader = "Прежний материал"; public Range oldSkuCell { get; private set; } -- cgit v1.2.3 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/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 +++++++++++ 8 files changed, 145 insertions(+), 145 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/PriceListTools') 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 } не является прайс-листом"); + } + } + } +} + -- cgit v1.2.3 From 99d1fb6740e93d7d81f0171885ac8f788b56dcfc Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Thu, 3 Feb 2022 21:44:24 +0300 Subject: Rename method --- src/PriceListTools/AbstractTool.cs | 2 +- src/PriceListTools/CombineTool.cs | 2 +- src/PriceListTools/ConvertTool.cs | 2 +- src/PriceListTools/ExportTool.cs | 2 +- src/PriceListTools/MergeTool.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/PriceListTools') diff --git a/src/PriceListTools/AbstractTool.cs b/src/PriceListTools/AbstractTool.cs index a86fd95..0d185f9 100644 --- a/src/PriceListTools/AbstractTool.cs +++ b/src/PriceListTools/AbstractTool.cs @@ -33,7 +33,7 @@ namespace RehauSku.PriceListTools } } - protected private void FillColumnsWithDictionary(KeyValuePair positionAmount, params int[] columns) + protected private void FillPositionAmountToColumns(KeyValuePair positionAmount, params int[] columns) { int? row = GetPositionRow(positionAmount.Key.Sku, positionAmount.Key.Group, TargetFile.skuCell.Column); diff --git a/src/PriceListTools/CombineTool.cs b/src/PriceListTools/CombineTool.cs index 80c7a67..28bcd7c 100644 --- a/src/PriceListTools/CombineTool.cs +++ b/src/PriceListTools/CombineTool.cs @@ -25,7 +25,7 @@ namespace RehauSku.PriceListTools foreach (var kvp in source.PositionAmount) { - FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column - 1, TargetFile.amountCell.Column); + FillPositionAmountToColumns(kvp, TargetFile.amountCell.Column - 1, TargetFile.amountCell.Column); bar.DoProgress(); } } diff --git a/src/PriceListTools/ConvertTool.cs b/src/PriceListTools/ConvertTool.cs index 58044ed..f84f445 100644 --- a/src/PriceListTools/ConvertTool.cs +++ b/src/PriceListTools/ConvertTool.cs @@ -31,7 +31,7 @@ namespace RehauSku.PriceListTools foreach (var kvp in Current.PositionAmount) { - FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column); + FillPositionAmountToColumns(kvp, TargetFile.amountCell.Column); bar.DoProgress(); } diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs index 562c1b2..f2454f5 100644 --- a/src/PriceListTools/ExportTool.cs +++ b/src/PriceListTools/ExportTool.cs @@ -28,7 +28,7 @@ namespace RehauSku.PriceListTools foreach (var kvp in PositionAmount) { - FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column); + FillPositionAmountToColumns(kvp, TargetFile.amountCell.Column); bar.DoProgress(); } diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs index 22e443f..8a99294 100644 --- a/src/PriceListTools/MergeTool.cs +++ b/src/PriceListTools/MergeTool.cs @@ -16,7 +16,7 @@ namespace RehauSku.PriceListTools { foreach (var kvp in source.PositionAmount) { - FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column); + FillPositionAmountToColumns(kvp, TargetFile.amountCell.Column); bar.DoProgress(); } } -- 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/CombineTool.cs | 2 +- src/PriceListTools/ConvertTool.cs | 2 +- src/PriceListTools/ExportTool.cs | 2 +- src/PriceListTools/MergeTool.cs | 2 +- src/PriceListTools/SourcePriceList.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/PriceListTools') diff --git a/src/PriceListTools/CombineTool.cs b/src/PriceListTools/CombineTool.cs index 28bcd7c..6b3dcb2 100644 --- a/src/PriceListTools/CombineTool.cs +++ b/src/PriceListTools/CombineTool.cs @@ -11,7 +11,7 @@ namespace RehauSku.PriceListTools public void FillTarget() { - ProgressBar bar = new ProgressBar(SourceFiles.Sum(file => file.PositionAmount.Count)); + ProgressBar bar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(file => file.PositionAmount.Count)); foreach (SourcePriceList source in SourceFiles) { diff --git a/src/PriceListTools/ConvertTool.cs b/src/PriceListTools/ConvertTool.cs index f84f445..3b634eb 100644 --- a/src/PriceListTools/ConvertTool.cs +++ b/src/PriceListTools/ConvertTool.cs @@ -27,7 +27,7 @@ namespace RehauSku.PriceListTools public void FillTarget() { - ProgressBar bar = new ProgressBar(Current.PositionAmount.Count); + ProgressBar bar = new ProgressBar("Заполняю строки...", Current.PositionAmount.Count); foreach (var kvp in Current.PositionAmount) { diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs index f2454f5..024cb3c 100644 --- a/src/PriceListTools/ExportTool.cs +++ b/src/PriceListTools/ExportTool.cs @@ -24,7 +24,7 @@ namespace RehauSku.PriceListTools public void FillTarget() { GetSelected(); - ProgressBar bar = new ProgressBar(PositionAmount.Count); + ProgressBar bar = new ProgressBar("Заполняю строки...", PositionAmount.Count); foreach (var kvp in PositionAmount) { diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs index 8a99294..8f3f6fc 100644 --- a/src/PriceListTools/MergeTool.cs +++ b/src/PriceListTools/MergeTool.cs @@ -10,7 +10,7 @@ namespace RehauSku.PriceListTools public void FillTarget() { - ProgressBar bar = new ProgressBar(SourceFiles.Sum(x => x.PositionAmount.Count)); + ProgressBar bar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(x => x.PositionAmount.Count)); foreach (SourcePriceList source in SourceFiles) { 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/AbstractTool.cs | 94 +++++++++++++++++++++++------------ src/PriceListTools/CombineTool.cs | 7 ++- src/PriceListTools/ConvertTool.cs | 7 ++- src/PriceListTools/ExportTool.cs | 7 ++- src/PriceListTools/MergeTool.cs | 7 ++- src/PriceListTools/SourcePriceList.cs | 11 +++- src/PriceListTools/TargetPriceList.cs | 5 +- 7 files changed, 93 insertions(+), 45 deletions(-) (limited to 'src/PriceListTools') diff --git a/src/PriceListTools/AbstractTool.cs b/src/PriceListTools/AbstractTool.cs index 0d185f9..b4e34cc 100644 --- a/src/PriceListTools/AbstractTool.cs +++ b/src/PriceListTools/AbstractTool.cs @@ -1,9 +1,11 @@ using ExcelDna.Integration; using Microsoft.Office.Interop.Excel; +using RehauSku.Interface; using System; using System.Collections.Generic; using System.Windows.Forms; using Application = Microsoft.Office.Interop.Excel.Application; +using ProgressBar = RehauSku.Interface.ProgressBar; namespace RehauSku.PriceListTools { @@ -11,6 +13,8 @@ namespace RehauSku.PriceListTools { protected private Application ExcelApp = (Application)ExcelDnaUtil.Application; protected private TargetPriceList TargetFile; + protected private ResultBar ResultBar { get; set; } + protected private ProgressBar ProgressBar { get; set; } public void OpenNewPrice() { @@ -53,72 +57,96 @@ namespace RehauSku.PriceListTools sumCell.Value2 += positionAmount.Value; } } + + ResultBar.IncrementSuccess(); + return; } - else + if (TargetFile.oldSkuCell != null) { - string sku = positionAmount.Key.Sku.Substring(1, 6); + Range foundCell = TargetFile.oldSkuCell.EntireColumn.Find(positionAmount.Key.Sku); - row = GetPositionRow(sku, positionAmount.Key.Group, TargetFile.skuCell.Column); - - if (row != null) + if (foundCell != null) { + row = foundCell.Row; + foreach (int column in columns) { - Range amountCell = TargetFile.Sheet.Cells[row, column]; - - if (amountCell.Value2 == null) + if (TargetFile.Sheet.Cells[row, column].Value2 == null) { - amountCell.Value2 = positionAmount.Value; + TargetFile.Sheet.Cells[row, column].Value2 = positionAmount.Value; } else { - amountCell.Value2 += positionAmount.Value; + TargetFile.Sheet.Cells[row, column].Value2 += positionAmount.Value; } - - Range oldSkuCell = TargetFile.Sheet.Cells[row, TargetFile.oldSkuCell.Column]; - oldSkuCell.Value2 = positionAmount.Key.Sku; } + + ResultBar.IncrementReplaced(); + return; } + } - else + string sku = positionAmount.Key.Sku.Substring(1, 6); + row = GetPositionRow(sku, positionAmount.Key.Group, TargetFile.skuCell.Column); + + if (row != null) + { + foreach (int column in columns) { - FillMissing(positionAmount, columns); + Range amountCell = TargetFile.Sheet.Cells[row, column]; + + if (amountCell.Value2 == null) + { + amountCell.Value2 = positionAmount.Value; + } + + else + { + amountCell.Value2 += positionAmount.Value; + } } + + ResultBar.IncrementReplaced(); + return; + } + + else + { + FillMissing(positionAmount, columns); + ResultBar.IncrementNotFound(); } } protected private void FillMissing(KeyValuePair positionAmount, params int[] columns) { - Range foundCell = TargetFile.oldSkuCell.EntireColumn.Find(positionAmount.Key.Sku); - int row; + int row = TargetFile.Sheet.Cells[TargetFile.Sheet.Rows.Count, TargetFile.skuCell.Column] + .End[XlDirection.xlUp] + .Row + 1; - if (foundCell == null) - { - row = TargetFile.Sheet.Cells[TargetFile.Sheet.Rows.Count, TargetFile.skuCell.Column] - .End[XlDirection.xlUp] - .Row + 1; + TargetFile.Sheet.Rows[row] + .EntireRow + .Insert(XlInsertShiftDirection.xlShiftDown, XlInsertFormatOrigin.xlFormatFromLeftOrAbove); - TargetFile.Sheet.Rows[row] - .EntireRow - .Insert(XlInsertShiftDirection.xlShiftDown, XlInsertFormatOrigin.xlFormatFromLeftOrAbove); + Range previous = TargetFile.Sheet.Rows[row - 1]; + Range current = TargetFile.Sheet.Rows[row]; - Range previous = TargetFile.Sheet.Rows[row - 1]; - Range current = TargetFile.Sheet.Rows[row]; + previous.Copy(current); + current.ClearContents(); - previous.Copy(current); - current.ClearContents(); + TargetFile.Sheet.Cells[row, TargetFile.groupCell.Column].Value2 = positionAmount.Key.Group; + TargetFile.Sheet.Cells[row, TargetFile.nameCell.Column].Value2 = positionAmount.Key.Name; - TargetFile.Sheet.Cells[row, TargetFile.groupCell.Column].Value2 = positionAmount.Key.Group; - TargetFile.Sheet.Cells[row, TargetFile.oldSkuCell.Column].Value2 = positionAmount.Key.Sku; - TargetFile.Sheet.Cells[row, TargetFile.nameCell.Column].Value2 = positionAmount.Key.Name; + if (TargetFile.oldSkuCell != null) + { TargetFile.Sheet.Cells[row, TargetFile.skuCell.Column].Value2 = "Не найден"; + TargetFile.Sheet.Cells[row, TargetFile.oldSkuCell.Column].Value2 = positionAmount.Key.Sku; } else { - row = foundCell.Row; + TargetFile.Sheet.Cells[row, TargetFile.skuCell.Column].Value2 = positionAmount.Key.Sku; } foreach (int column in columns) diff --git a/src/PriceListTools/CombineTool.cs b/src/PriceListTools/CombineTool.cs index 6b3dcb2..af9378c 100644 --- a/src/PriceListTools/CombineTool.cs +++ b/src/PriceListTools/CombineTool.cs @@ -11,7 +11,8 @@ namespace RehauSku.PriceListTools public void FillTarget() { - ProgressBar bar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(file => file.PositionAmount.Count)); + ProgressBar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(file => file.PositionAmount.Count)); + ResultBar = new ResultBar(); foreach (SourcePriceList source in SourceFiles) { @@ -26,13 +27,15 @@ namespace RehauSku.PriceListTools foreach (var kvp in source.PositionAmount) { FillPositionAmountToColumns(kvp, TargetFile.amountCell.Column - 1, TargetFile.amountCell.Column); - bar.DoProgress(); + ProgressBar.Update(); } } FilterByAmount(); + ResultBar.Update(); Interface.Dialog.SaveWorkbookAs(); + ExcelApp.StatusBar = false; } } } diff --git a/src/PriceListTools/ConvertTool.cs b/src/PriceListTools/ConvertTool.cs index 3b634eb..d13c803 100644 --- a/src/PriceListTools/ConvertTool.cs +++ b/src/PriceListTools/ConvertTool.cs @@ -27,17 +27,20 @@ namespace RehauSku.PriceListTools public void FillTarget() { - ProgressBar bar = new ProgressBar("Заполняю строки...", Current.PositionAmount.Count); + ProgressBar = new ProgressBar("Заполняю строки...", Current.PositionAmount.Count); + ResultBar = new ResultBar(); foreach (var kvp in Current.PositionAmount) { FillPositionAmountToColumns(kvp, TargetFile.amountCell.Column); - bar.DoProgress(); + ProgressBar.Update(); } FilterByAmount(); + ResultBar.Update(); Dialog.SaveWorkbookAs(); + ExcelApp.StatusBar = false; } } } \ No newline at end of file diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs index 024cb3c..b36bf09 100644 --- a/src/PriceListTools/ExportTool.cs +++ b/src/PriceListTools/ExportTool.cs @@ -24,17 +24,20 @@ namespace RehauSku.PriceListTools public void FillTarget() { GetSelected(); - ProgressBar bar = new ProgressBar("Заполняю строки...", PositionAmount.Count); + ProgressBar = new ProgressBar("Заполняю строки...", PositionAmount.Count); + ResultBar = new ResultBar(); foreach (var kvp in PositionAmount) { FillPositionAmountToColumns(kvp, TargetFile.amountCell.Column); - bar.DoProgress(); + ProgressBar.Update(); } FilterByAmount(); + ResultBar.Update(); Interface.Dialog.SaveWorkbookAs(); + ExcelApp.StatusBar = false; } private void GetSelected() diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs index 8f3f6fc..0e3f1dc 100644 --- a/src/PriceListTools/MergeTool.cs +++ b/src/PriceListTools/MergeTool.cs @@ -10,20 +10,23 @@ namespace RehauSku.PriceListTools public void FillTarget() { - ProgressBar bar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(x => x.PositionAmount.Count)); + ProgressBar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(x => x.PositionAmount.Count)); + ResultBar = new ResultBar(); foreach (SourcePriceList source in SourceFiles) { foreach (var kvp in source.PositionAmount) { FillPositionAmountToColumns(kvp, TargetFile.amountCell.Column); - bar.DoProgress(); + ProgressBar.Update(); } } FilterByAmount(); + ResultBar.Update(); Dialog.SaveWorkbookAs(); + ExcelApp.StatusBar = false; } } } 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)) diff --git a/src/PriceListTools/TargetPriceList.cs b/src/PriceListTools/TargetPriceList.cs index 2c2f029..32b071c 100644 --- a/src/PriceListTools/TargetPriceList.cs +++ b/src/PriceListTools/TargetPriceList.cs @@ -19,10 +19,11 @@ namespace RehauSku.PriceListTools 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) + nameCell = Sheet.Cells.Find(nameHeader) }; + oldSkuCell = Sheet.Cells.Find(oldSkuHeader); + if (cells.Any(x => x == null)) { throw new ArgumentException($"Шаблон { Name } не является прайс-листом"); -- 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/ExportTool.cs | 1 - src/PriceListTools/SourcePriceList.cs | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'src/PriceListTools') diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs index b36bf09..82fd86a 100644 --- a/src/PriceListTools/ExportTool.cs +++ b/src/PriceListTools/ExportTool.cs @@ -1,5 +1,4 @@ using Microsoft.Office.Interop.Excel; -using RehauSku.Assistant; using System; using System.Collections.Generic; using RehauSku.Interface; 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 From 5a45c59b92c885cf20c5c69b1769273f3a124530 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Sat, 5 Feb 2022 13:04:18 +0300 Subject: Remove Selection check --- src/PriceListTools/ExportTool.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'src/PriceListTools') diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs index 82fd86a..f341671 100644 --- a/src/PriceListTools/ExportTool.cs +++ b/src/PriceListTools/ExportTool.cs @@ -10,14 +10,9 @@ namespace RehauSku.PriceListTools private Dictionary PositionAmount; private Range Selection; - public void TryGetSelection() + public ExportTool() { Selection = ExcelApp.Selection; - - if (Selection == null || Selection.Columns.Count != 2) - { - throw new Exception("Неверный диапазон"); - } } public void FillTarget() -- cgit v1.2.3