aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2022-01-27 10:22:30 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2022-01-27 10:22:30 +0300
commit72ac236b15603e84f18ec346749186b6cb2c2bdf (patch)
treebf47c7f4e92e1008fe1b4a34851b642d15ee0c98
parent8e3dff1788905c203509f866921957b027cb2643 (diff)
Refactoring tolls classes
-rw-r--r--src/PriceListTools/AbstractPriceListTool.cs83
-rw-r--r--src/PriceListTools/CombineTool.cs9
-rw-r--r--src/PriceListTools/ExportTool.cs11
-rw-r--r--src/PriceListTools/MergeTool.cs55
-rw-r--r--src/PriceListTools/PriceListTool.cs129
-rw-r--r--src/PriceListTools/Source.cs (renamed from src/PriceListTools/SourceFile.cs)30
-rw-r--r--src/PriceListTools/Target.cs46
-rw-r--r--src/RehauSku.Assist.csproj5
-rw-r--r--src/Ribbon/RibbonController.cs10
9 files changed, 194 insertions, 184 deletions
diff --git a/src/PriceListTools/AbstractPriceListTool.cs b/src/PriceListTools/AbstractPriceListTool.cs
deleted file mode 100644
index 437450c..0000000
--- a/src/PriceListTools/AbstractPriceListTool.cs
+++ /dev/null
@@ -1,83 +0,0 @@
-using ExcelDna.Integration;
-using Microsoft.Office.Interop.Excel;
-using System;
-using System.Collections.Generic;
-
-namespace RehauSku.PriceListTools
-{
- internal abstract class AbstractPriceListTool
- {
- protected private Application ExcelApp;
- protected private SourceFile NewPriceList;
- protected private List<SourceFile> sourcePriceLists;
-
- public AbstractPriceListTool()
- {
- ExcelApp = (Application)ExcelDnaUtil.Application;
- sourcePriceLists = new List<SourceFile>();
- }
-
- protected private void FilterByAmount()
- {
- AutoFilter filter = NewPriceList.Sheet.AutoFilter;
-
- filter.Range.AutoFilter(NewPriceList.amountCell.Column, "<>");
- NewPriceList.Sheet.Range["A1"].Activate();
- }
-
- public void OpenNewPrice(string path)
- {
- Workbook wb = ExcelApp.Workbooks.Open(path);
-
- try
- {
- NewPriceList = new SourceFile(wb);
- }
-
- catch (Exception ex)
- {
- System.Windows.Forms.MessageBox.Show
- (ex.Message,
- "Ошибка открытия шаблонного прайс-листа",
- System.Windows.Forms.MessageBoxButtons.OK,
- System.Windows.Forms.MessageBoxIcon.Information);
- wb.Close();
- }
- }
-
- public virtual void GetSource()
- {
- throw new NotImplementedException();
- }
-
- public virtual void GetSource(string[] files)
- {
- ExcelApp.ScreenUpdating = false;
- foreach (string file in files)
- {
- Workbook wb = ExcelApp.Workbooks.Open(file);
- try
- {
- SourceFile priceList = new SourceFile(wb);
- sourcePriceLists.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;
- }
-
- public virtual void FillPriceList()
- {
- throw new NotImplementedException();
- }
- }
-} \ No newline at end of file
diff --git a/src/PriceListTools/CombineTool.cs b/src/PriceListTools/CombineTool.cs
index 2e5995c..39d3b98 100644
--- a/src/PriceListTools/CombineTool.cs
+++ b/src/PriceListTools/CombineTool.cs
@@ -3,9 +3,9 @@ using System;
namespace RehauSku.PriceListTools
{
- internal class CombineTool : AbstractPriceListTool, IDisposable
+ internal class CombineTool : PriceListTool
{
- public override void FillPriceList()
+ public override void FillTarget()
{
int exportedValues = 0;
@@ -52,10 +52,5 @@ namespace RehauSku.PriceListTools
AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов";
Forms.Dialog.SaveWorkbookAs();
}
-
- public void Dispose()
- {
- GC.SuppressFinalize(this);
- }
}
}
diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs
index 2dc673b..b36fd13 100644
--- a/src/PriceListTools/ExportTool.cs
+++ b/src/PriceListTools/ExportTool.cs
@@ -6,7 +6,7 @@ using System.Collections.Generic;
namespace RehauSku.PriceListTools
{
- internal class ExportTool : AbstractPriceListTool, IDisposable
+ internal class ExportTool : PriceListTool
{
private Dictionary<string, double> SkuAmount { get; set; }
private Range Selection;
@@ -25,7 +25,7 @@ namespace RehauSku.PriceListTools
else throw new Exception("Неверный диапазон");
}
- public override void GetSource(string[] files)
+ public override void GetSourceLists(string[] files)
=> GetSource();
private void FillSkuAmountDict()
@@ -73,7 +73,7 @@ namespace RehauSku.PriceListTools
}
}
- public override void FillPriceList()
+ public override void FillTarget()
{
if (SkuAmount.Count < 1)
return;
@@ -114,11 +114,6 @@ namespace RehauSku.PriceListTools
AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {SkuAmount.Count}";
Forms.Dialog.SaveWorkbookAs();
}
-
- public void Dispose()
- {
- GC.SuppressFinalize(this);
- }
}
}
diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs
index 0e98b95..51884dd 100644
--- a/src/PriceListTools/MergeTool.cs
+++ b/src/PriceListTools/MergeTool.cs
@@ -1,58 +1,7 @@
-using Microsoft.Office.Interop.Excel;
-using System;
-
-namespace RehauSku.PriceListTools
+namespace RehauSku.PriceListTools
{
- internal class MergeTool : AbstractPriceListTool, IDisposable
+ internal class MergeTool : PriceListTool
{
- public override void FillPriceList()
- {
- int exportedValues = 0;
-
- ExcelApp.ScreenUpdating = false;
-
- foreach (var sheet in sourcePriceLists)
- {
- if (sheet.SkuAmount.Count == 0)
- continue;
-
- foreach (var kvp in sheet.SkuAmount)
- {
- Range cell = NewPriceList.Sheet.Columns[NewPriceList.skuCell.Column].Find(kvp.Key);
-
- if (cell == null)
- {
- System.Windows.Forms.MessageBox.Show
- ($"Артикул {kvp.Key} отсутствует в таблице заказов {RegistryUtil.PriceListPath}",
- "Отсутствует позиция в конечной таблице заказов",
- System.Windows.Forms.MessageBoxButtons.OK,
- System.Windows.Forms.MessageBoxIcon.Information);
- }
-
- else
- {
- Range sumCell = NewPriceList.Sheet.Cells[cell.Row, NewPriceList.amountCell.Column];
-
- if (sumCell.Value2 == null)
- sumCell.Value2 = kvp.Value;
- else
- sumCell.Value2 += kvp.Value;
-
- exportedValues++;
- }
- }
- }
-
- FilterByAmount();
- ExcelApp.ScreenUpdating = true;
-
- AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов";
- Forms.Dialog.SaveWorkbookAs();
- }
- public void Dispose()
- {
- GC.SuppressFinalize(this);
- }
}
}
diff --git a/src/PriceListTools/PriceListTool.cs b/src/PriceListTools/PriceListTool.cs
new file mode 100644
index 0000000..5ccd31a
--- /dev/null
+++ b/src/PriceListTools/PriceListTool.cs
@@ -0,0 +1,129 @@
+using ExcelDna.Integration;
+using Microsoft.Office.Interop.Excel;
+using System;
+using System.Collections.Generic;
+
+namespace RehauSku.PriceListTools
+{
+ internal abstract class PriceListTool : IDisposable
+ {
+ protected private Application ExcelApp;
+ protected private Target NewPriceList;
+ protected private List<Source> sourcePriceLists;
+
+ public PriceListTool()
+ {
+ ExcelApp = (Application)ExcelDnaUtil.Application;
+ sourcePriceLists = new List<Source>();
+ }
+
+ public void OpenNewPrice(string path)
+ {
+ Workbook wb = ExcelApp.Workbooks.Open(path);
+
+ try
+ {
+ NewPriceList = new Target(wb);
+ }
+
+ catch (Exception ex)
+ {
+ System.Windows.Forms.MessageBox.Show
+ (ex.Message,
+ "Ошибка открытия шаблонного прайс-листа",
+ System.Windows.Forms.MessageBoxButtons.OK,
+ System.Windows.Forms.MessageBoxIcon.Information);
+ wb.Close();
+ }
+ }
+
+ public virtual void GetSource()
+ {
+ throw new NotImplementedException();
+ }
+
+ public virtual void GetSourceLists(string[] files)
+ {
+ ExcelApp.ScreenUpdating = false;
+ foreach (string file in files)
+ {
+ Workbook wb = ExcelApp.Workbooks.Open(file);
+ try
+ {
+ Source priceList = new Source(wb);
+ sourcePriceLists.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;
+ }
+
+ public virtual void FillTarget()
+ {
+ ExcelApp.ScreenUpdating = false;
+ FillAmountColumn();
+ FilterByAmount();
+ ExcelApp.ScreenUpdating = true;
+
+ Forms.Dialog.SaveWorkbookAs();
+ }
+
+ protected private void FillAmountColumn()
+ {
+ int exportedValues = 0;
+ foreach (var sheet in sourcePriceLists)
+ {
+ if (sheet.SkuAmount.Count == 0)
+ continue;
+
+ foreach (var kvp in sheet.SkuAmount)
+ {
+ Range cell = NewPriceList.Sheet.Columns[NewPriceList.skuCell.Column].Find(kvp.Key);
+
+ if (cell == null)
+ {
+ System.Windows.Forms.MessageBox.Show
+ ($"Артикул {kvp.Key} отсутствует в таблице заказов {RegistryUtil.PriceListPath}",
+ "Отсутствует позиция в конечной таблице заказов",
+ System.Windows.Forms.MessageBoxButtons.OK,
+ System.Windows.Forms.MessageBoxIcon.Information);
+ }
+
+ else
+ {
+ Range sumCell = NewPriceList.Sheet.Cells[cell.Row, NewPriceList.amountCell.Column];
+
+ if (sumCell.Value2 == null)
+ sumCell.Value2 = kvp.Value;
+ else
+ sumCell.Value2 += kvp.Value;
+
+ exportedValues++;
+ }
+ }
+ }
+ }
+
+ protected private void FilterByAmount()
+ {
+ AutoFilter filter = NewPriceList.Sheet.AutoFilter;
+
+ filter.Range.AutoFilter(NewPriceList.amountCell.Column, "<>");
+ NewPriceList.Sheet.Range["A1"].Activate();
+ }
+
+ public void Dispose()
+ {
+ GC.SuppressFinalize(this);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/PriceListTools/SourceFile.cs b/src/PriceListTools/Source.cs
index 20d110d..40ac257 100644
--- a/src/PriceListTools/SourceFile.cs
+++ b/src/PriceListTools/Source.cs
@@ -1,17 +1,17 @@
using Microsoft.Office.Interop.Excel;
-using System.Collections.Generic;
using System;
+using System.Collections.Generic;
namespace RehauSku.PriceListTools
{
- internal class SourceFile : PriceList
+ internal class Source : PriceList
{
public Dictionary<string, double> SkuAmount { get; private set; }
- public SourceFile(Workbook workbook)
+ public Source(Workbook workbook)
{
Sheet = workbook.ActiveSheet;
- Name = workbook.Name + '\n' + Sheet.Name;
+ Name = workbook.Name;
amountCell = Sheet.Cells.Find(amountHeader);
skuCell = Sheet.Cells.Find(skuHeader);
@@ -48,27 +48,5 @@ namespace RehauSku.PriceListTools
}
}
}
-
- internal class NewFile : PriceList
- {
- public Dictionary<PriceListPosition, Range> Map { get; private set; }
-
- public void CreateMap()
- {
- Range amountCell = Sheet.Cells.Find(amountHeader);
- Range skuCell = Sheet.Cells.Find(skuHeader);
- Range groupCell = Sheet.Cells.Find(groupHeader);
-
- //headerRowNumber = amountCell.Row;
- //skuColumnNumber = skuCell.Column;
- //amountColumnNumber = amountCell.Column;
- //groupColumnNumber = groupCell.Column;
-
- //for (int row = headerRowNumber + 1; row < skuCell.Rows.Count; row++)
- //{
- // string sku =
- //}
- }
- }
}
diff --git a/src/PriceListTools/Target.cs b/src/PriceListTools/Target.cs
new file mode 100644
index 0000000..b9eb856
--- /dev/null
+++ b/src/PriceListTools/Target.cs
@@ -0,0 +1,46 @@
+using Microsoft.Office.Interop.Excel;
+using System;
+using System.Collections.Generic;
+
+namespace RehauSku.PriceListTools
+{
+ internal class Target : PriceList
+ {
+ public Dictionary<PriceListPosition, Range> Map { get; private set; }
+
+ public Target(Workbook workbook)
+ {
+ Sheet = workbook.ActiveSheet;
+ Name = workbook.Name;
+
+ amountCell = Sheet.Cells.Find(amountHeader);
+ skuCell = Sheet.Cells.Find(skuHeader);
+ groupCell = Sheet.Cells.Find(groupHeader);
+
+ if (amountCell == null || skuCell == null || groupCell == null)
+ {
+ throw new ArgumentException($"Лист { Name } не распознан");
+ }
+
+ CreateMap();
+ }
+
+ private void CreateMap()
+ {
+ Range amountCell = Sheet.Cells.Find(amountHeader);
+ Range skuCell = Sheet.Cells.Find(skuHeader);
+ Range groupCell = Sheet.Cells.Find(groupHeader);
+
+ //headerRowNumber = amountCell.Row;
+ //skuColumnNumber = skuCell.Column;
+ //amountColumnNumber = amountCell.Column;
+ //groupColumnNumber = groupCell.Column;
+
+ //for (int row = headerRowNumber + 1; row < skuCell.Rows.Count; row++)
+ //{
+ // string sku =
+ //}
+ }
+ }
+}
+
diff --git a/src/RehauSku.Assist.csproj b/src/RehauSku.Assist.csproj
index 4d8c9d5..74d6df8 100644
--- a/src/RehauSku.Assist.csproj
+++ b/src/RehauSku.Assist.csproj
@@ -122,11 +122,12 @@
<Compile Include="Assistant\RequestModifier.cs" />
<Compile Include="Assistant\SkuExtensions.cs" />
<Compile Include="PriceListTools\CombineTool.cs" />
- <Compile Include="PriceListTools\AbstractPriceListTool.cs" />
+ <Compile Include="PriceListTools\PriceListTool.cs" />
<Compile Include="PriceListTools\MergeTool.cs" />
<Compile Include="PriceListTools\PriceList.cs" />
<Compile Include="PriceListTools\PriceListPosition.cs" />
- <Compile Include="PriceListTools\SourceFile.cs" />
+ <Compile Include="PriceListTools\Source.cs" />
+ <Compile Include="PriceListTools\Target.cs" />
<Compile Include="Ribbon\RibbonController.cs" />
<Compile Include="Assistant\HttpClientUtil.cs" />
<Compile Include="Assistant\StoreResponse.cs" />
diff --git a/src/Ribbon/RibbonController.cs b/src/Ribbon/RibbonController.cs
index ed59541..d17426b 100644
--- a/src/Ribbon/RibbonController.cs
+++ b/src/Ribbon/RibbonController.cs
@@ -42,10 +42,10 @@ namespace RehauSku.Ribbon
string[] files = Dialog.GetMultiplyFiles();
if (files.Length != 0)
{
- mergeTool.GetSource(files);
+ mergeTool.GetSourceLists(files);
string exportFile = RegistryUtil.PriceListPath;
mergeTool.OpenNewPrice(exportFile);
- mergeTool.FillPriceList();
+ mergeTool.FillTarget();
}
}
}
@@ -57,10 +57,10 @@ namespace RehauSku.Ribbon
string[] files = Dialog.GetMultiplyFiles();
if (files.Length != 0)
{
- combineTool.GetSource(files);
+ combineTool.GetSourceLists(files);
string exportFile = RegistryUtil.PriceListPath;
combineTool.OpenNewPrice(exportFile);
- combineTool.FillPriceList();
+ combineTool.FillTarget();
}
}
}
@@ -74,7 +74,7 @@ namespace RehauSku.Ribbon
exportTool.GetSource();
string exportFile = RegistryUtil.PriceListPath;
exportTool.OpenNewPrice(exportFile);
- exportTool.FillPriceList();
+ exportTool.FillTarget();
}
}
catch (Exception ex)