From dc1fc8b221e9324fe0f82c4ea4a32d87d282bd25 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 8 Dec 2021 14:45:14 +0300 Subject: refactoring namespaces --- Source/DataExport/DataWriter.cs | 113 --------------------------------------- Source/DataExport/Exporter.cs | 114 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 113 deletions(-) delete mode 100644 Source/DataExport/DataWriter.cs create mode 100644 Source/DataExport/Exporter.cs (limited to 'Source/DataExport') 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) + { + + } + } +} + -- cgit v1.2.3