From 24024b5729c1c44bb01cb29813868743d1753e31 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Fri, 24 Dec 2021 16:22:03 +0300 Subject: MergeTool, MemoryUtil anf stuff --- Source/DataExport/ExportTool.cs | 129 ---------------------------------------- 1 file changed, 129 deletions(-) delete mode 100644 Source/DataExport/ExportTool.cs (limited to 'Source/DataExport/ExportTool.cs') diff --git a/Source/DataExport/ExportTool.cs b/Source/DataExport/ExportTool.cs deleted file mode 100644 index 8ea65cd..0000000 --- a/Source/DataExport/ExportTool.cs +++ /dev/null @@ -1,129 +0,0 @@ -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 ExportTool : IDisposable - { - private Application xlApp; - private Dictionary SkuAmount { get; set; } - private Range Selection { get; set; } - private string CurrentFilePath { get; set; } - - public ExportTool() - { - this.xlApp = (Application)ExcelDnaUtil.Application; - this.CurrentFilePath = xlApp.ActiveWorkbook.FullName; - - _GetSelectedCells(); - } - - private void _GetSelectedCells() - { - Selection = xlApp.Selection; - } - - public bool IsRangeValid() - { - return Selection.Columns.Count == 2; - } - - private void FillSkuAmountDict() - { - object[,] cells = Selection.Value2; - SkuAmount = new Dictionary(); - int rowsCount = Selection.Rows.Count; - - for (int row = 1; row <= rowsCount; row++) - { - if (cells[row, 1] == null || cells[row, 2] == null) - continue; - - string sku = null; - double? amount = null; - - for (int column = 1; column <= 2; column++) - { - object current = cells[row, column]; - - if (current.GetType() == typeof(string) - && ((string)current).IsRehauSku()) - 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 FillNewPriceList() - { - const string amountHeader = "Кол-во"; - const string skuHeader = "Актуальный материал"; - - FillSkuAmountDict(); - string exportFile = _GetExportFullPath(); - File.Copy(RegistryUtil.PriceListPath, exportFile, true); - - Workbook wb = xlApp.Workbooks.Open(exportFile); - Worksheet ws = wb.Sheets["КП"]; - ws.Activate(); - - int amountColumn = ws.Cells.Find(amountHeader).Column; - int skuColumn = ws.Cells.Find(skuHeader).Column; - - foreach (KeyValuePair kvp in SkuAmount) - { - Range cell = ws.Columns[skuColumn].Find(kvp.Key); - ws.Cells[cell.Row, amountColumn].Value = kvp.Value; - } - - AutoFilter filter = ws.AutoFilter; - int firstFilterColumn = filter.Range.Column; - - filter.Range.AutoFilter(amountColumn - firstFilterColumn + 1, "<>"); - ws.Range["A1"].Activate(); - } - - private string _GetExportFullPath() - { - string fileExtension = Path.GetExtension(RegistryUtil.PriceListPath); - - return Path.GetTempFileName() + fileExtension; - } - - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - - } - } - - class SelectionCheck - { - - } -} - -- cgit v1.2.3