From dc1fc8b221e9324fe0f82c4ea4a32d87d282bd25 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 8 Dec 2021 14:45:14 +0300 Subject: refactoring namespaces --- RehauSku.Assist.csproj | 2 +- Source/AddIn/AddIn.cs | 2 +- Source/AddIn/Functions.cs | 3 +- Source/Assistant/HttpClientUtil.cs | 2 +- Source/Assistant/IProduct.cs | 2 +- Source/Assistant/RequestModifier.cs | 2 +- Source/Assistant/SkuAssist.cs | 2 +- Source/Assistant/StoreResponse.cs | 2 +- Source/DataExport/DataWriter.cs | 113 ----------------------------------- Source/DataExport/Exporter.cs | 114 ++++++++++++++++++++++++++++++++++++ Source/Ribbon/RibbonController.cs | 6 +- 11 files changed, 126 insertions(+), 124 deletions(-) delete mode 100644 Source/DataExport/DataWriter.cs create mode 100644 Source/DataExport/Exporter.cs diff --git a/RehauSku.Assist.csproj b/RehauSku.Assist.csproj index 5fd5051..63b4063 100644 --- a/RehauSku.Assist.csproj +++ b/RehauSku.Assist.csproj @@ -100,7 +100,7 @@ - + diff --git a/Source/AddIn/AddIn.cs b/Source/AddIn/AddIn.cs index 3c82406..5255e2e 100644 --- a/Source/AddIn/AddIn.cs +++ b/Source/AddIn/AddIn.cs @@ -3,7 +3,7 @@ using ExcelDna.Registration; using Microsoft.Win32; using System.Net.Http; -namespace RehauSku.Assist +namespace RehauSku { public enum ResponseOrder { diff --git a/Source/AddIn/Functions.cs b/Source/AddIn/Functions.cs index 6d94e24..c6e9da4 100644 --- a/Source/AddIn/Functions.cs +++ b/Source/AddIn/Functions.cs @@ -1,6 +1,7 @@ using ExcelDna.Integration; +using RehauSku.Assistant; -namespace RehauSku.Assist +namespace RehauSku { public class Functions { diff --git a/Source/Assistant/HttpClientUtil.cs b/Source/Assistant/HttpClientUtil.cs index 57cd060..95a90e9 100644 --- a/Source/Assistant/HttpClientUtil.cs +++ b/Source/Assistant/HttpClientUtil.cs @@ -5,7 +5,7 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; -namespace RehauSku.Assist +namespace RehauSku.Assistant { static class HttpClientUtil { diff --git a/Source/Assistant/IProduct.cs b/Source/Assistant/IProduct.cs index e469ff8..9494eeb 100644 --- a/Source/Assistant/IProduct.cs +++ b/Source/Assistant/IProduct.cs @@ -1,4 +1,4 @@ -namespace RehauSku.Assist +namespace RehauSku.Assistant { interface IProduct { diff --git a/Source/Assistant/RequestModifier.cs b/Source/Assistant/RequestModifier.cs index c479a74..0db0b90 100644 --- a/Source/Assistant/RequestModifier.cs +++ b/Source/Assistant/RequestModifier.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; -namespace RehauSku.Assist +namespace RehauSku.Assistant { public static class RequestModifier { diff --git a/Source/Assistant/SkuAssist.cs b/Source/Assistant/SkuAssist.cs index 775a33c..eddb0cd 100644 --- a/Source/Assistant/SkuAssist.cs +++ b/Source/Assistant/SkuAssist.cs @@ -9,7 +9,7 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; -namespace RehauSku.Assist +namespace RehauSku.Assistant { public enum ProductField { diff --git a/Source/Assistant/StoreResponse.cs b/Source/Assistant/StoreResponse.cs index ef1f05d..8e1759d 100644 --- a/Source/Assistant/StoreResponse.cs +++ b/Source/Assistant/StoreResponse.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace RehauSku.Assist +namespace RehauSku.Assistant { public class StoreResponce { diff --git a/Source/DataExport/DataWriter.cs b/Source/DataExport/DataWriter.cs deleted file mode 100644 index cf18c9e..0000000 --- a/Source/DataExport/DataWriter.cs +++ /dev/null @@ -1,113 +0,0 @@ -using ExcelDna.Integration; -using Microsoft.Office.Interop.Excel; -using System; -using System.Collections.Generic; -using System.IO; - -namespace RehauSku.Assist -{ - public class DataWriter : IDisposable - { - private Application xlApp; - private Dictionary SkuAmount { get; set; } - private object[,] SelectedCells { get; set; } - private string WorkingFileName { get; set; } - - public DataWriter() - { - this.xlApp = (Application)ExcelDnaUtil.Application; - this.WorkingFileName = xlApp.ActiveWorkbook.FullName; - - GetSelectedCells(); - } - - private void GetSelectedCells() - { - Range selection = xlApp.Selection; - this.SelectedCells = (object[,])selection.Value2; - } - - public bool IsRangeValid() - { - return SelectedCells != null && - SelectedCells.GetLength(1) == 2; - } - - public void FillSkuAmountDict() - { - SkuAmount = new Dictionary(); - int rowsCount = SelectedCells.GetLength(0); - - for (int row = 1; row <= rowsCount; row++) - { - if (SelectedCells[row, 1] == null || SelectedCells[row, 2] == null) - continue; - - string sku = null; - double? amount = null; - - for (int column = 1; column <= 2; column++) - { - object current = SelectedCells[row, column]; - - if (current.GetType() == typeof(string) - && SkuAssist.IsRehauSku((string)current)) - sku = (string)current; - - else if (current.GetType() == typeof(string) - && double.TryParse((string)current, out _)) - amount = double.Parse((string)current); - - else if (current.GetType() == typeof(double)) - amount = (double)current; - } - - if (sku == null || amount == null) - continue; - - if (SkuAmount.ContainsKey(sku)) - SkuAmount[sku] += amount.Value; - else - SkuAmount.Add(sku, amount.Value); - } - } - - //public void FillPriceList() - //{ - // string exportFileName = "rehau-export_" + DateTime.Now + ".xlsm"; - // string workingDir = xlApp.ActiveWorkbook.Path; - - // //File.Copy(Path.GetFullPath(PriceListFilePath), Path.Combine(WorkingFileName, exportFileName + ".xlsm")); - - - // Workbook wb = xlApp.Workbooks.Open(PriceListFilePath); - // Worksheet ws = wb.ActiveSheet; - - // Range amountCell = ws.Cells.Find("Кол-во"); - - // foreach (KeyValuePair kvp in SkuAmount) - // { - // Range cell = ws.Cells.Find(kvp.Key); - // ws.Cells[cell.Row, amountCell.Column].Value = kvp.Value; - // } - - // //Range filter = ws.Range["H16:H4058"]; - // ws.Cells.AutoFilter(7, "<>"); - - // //wb.Save(); - // //wb.Close(); - //} - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - - } - } -} - diff --git a/Source/DataExport/Exporter.cs b/Source/DataExport/Exporter.cs new file mode 100644 index 0000000..d8b8380 --- /dev/null +++ b/Source/DataExport/Exporter.cs @@ -0,0 +1,114 @@ +using ExcelDna.Integration; +using Microsoft.Office.Interop.Excel; +using System; +using System.Collections.Generic; +using System.IO; +using RehauSku.Assistant; + +namespace RehauSku.DataExport +{ + public class Exporter : IDisposable + { + private Application xlApp; + private Dictionary SkuAmount { get; set; } + private object[,] SelectedCells { get; set; } + private string WorkingFileName { get; set; } + + public Exporter() + { + this.xlApp = (Application)ExcelDnaUtil.Application; + this.WorkingFileName = xlApp.ActiveWorkbook.FullName; + + GetSelectedCells(); + } + + private void GetSelectedCells() + { + Range selection = xlApp.Selection; + this.SelectedCells = (object[,])selection.Value2; + } + + public bool IsRangeValid() + { + return SelectedCells != null && + SelectedCells.GetLength(1) == 2; + } + + public void FillSkuAmountDict() + { + SkuAmount = new Dictionary(); + int rowsCount = SelectedCells.GetLength(0); + + for (int row = 1; row <= rowsCount; row++) + { + if (SelectedCells[row, 1] == null || SelectedCells[row, 2] == null) + continue; + + string sku = null; + double? amount = null; + + for (int column = 1; column <= 2; column++) + { + object current = SelectedCells[row, column]; + + if (current.GetType() == typeof(string) + && SkuAssist.IsRehauSku((string)current)) + sku = (string)current; + + else if (current.GetType() == typeof(string) + && double.TryParse((string)current, out _)) + amount = double.Parse((string)current); + + else if (current.GetType() == typeof(double)) + amount = (double)current; + } + + if (sku == null || amount == null) + continue; + + if (SkuAmount.ContainsKey(sku)) + SkuAmount[sku] += amount.Value; + else + SkuAmount.Add(sku, amount.Value); + } + } + + //public void FillPriceList() + //{ + // string exportFileName = "rehau-export_" + DateTime.Now + ".xlsm"; + // string workingDir = xlApp.ActiveWorkbook.Path; + + // //File.Copy(Path.GetFullPath(PriceListFilePath), Path.Combine(WorkingFileName, exportFileName + ".xlsm")); + + + // Workbook wb = xlApp.Workbooks.Open(PriceListFilePath); + // Worksheet ws = wb.ActiveSheet; + + // Range amountCell = ws.Cells.Find("Кол-во"); + + // foreach (KeyValuePair kvp in SkuAmount) + // { + // Range cell = ws.Cells.Find(kvp.Key); + // ws.Cells[cell.Row, amountCell.Column].Value = kvp.Value; + // } + + // //Range filter = ws.Range["H16:H4058"]; + // ws.Cells.AutoFilter(7, "<>"); + + // //wb.Save(); + // //wb.Close(); + //} + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + + } + } +} + diff --git a/Source/Ribbon/RibbonController.cs b/Source/Ribbon/RibbonController.cs index c4ca6d7..7402a09 100644 --- a/Source/Ribbon/RibbonController.cs +++ b/Source/Ribbon/RibbonController.cs @@ -1,9 +1,9 @@ using System.Runtime.InteropServices; using System.Windows.Forms; using ExcelDna.Integration.CustomUI; -using RehauSku.Assist; +using RehauSku.DataExport; -namespace Ribbon +namespace RehauSku.Ribbon { [ComVisible(true)] public class RibbonController : ExcelRibbon @@ -26,7 +26,7 @@ namespace Ribbon public void OnButtonPressed(IRibbonControl control) { - using (DataWriter dw = new DataWriter()) + using (Exporter dw = new Exporter()) { if (!dw.IsRangeValid()) { -- cgit v1.2.3