aboutsummaryrefslogtreecommitdiff
path: root/Source/DataExport/ExportTool.cs
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2021-12-24 16:22:03 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2021-12-24 16:22:03 +0300
commit24024b5729c1c44bb01cb29813868743d1753e31 (patch)
tree673a1c1102e04adee36be8ded4934d2e40794fef /Source/DataExport/ExportTool.cs
parent2a4076d6eef1b4556f6af8cb074638d440927c5e (diff)
MergeTool, MemoryUtil anf stuff
Diffstat (limited to 'Source/DataExport/ExportTool.cs')
-rw-r--r--Source/DataExport/ExportTool.cs129
1 files changed, 0 insertions, 129 deletions
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<string, double> 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<string, double>();
- 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<string, double> 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
- {
-
- }
-}
-