aboutsummaryrefslogtreecommitdiff
path: root/Source/PriceListTools
diff options
context:
space:
mode:
Diffstat (limited to 'Source/PriceListTools')
-rw-r--r--Source/PriceListTools/ExportTool.cs115
-rw-r--r--Source/PriceListTools/MergeTool.cs88
-rw-r--r--Source/PriceListTools/PriceList.cs87
-rw-r--r--Source/PriceListTools/PriceListUtil.cs41
4 files changed, 0 insertions, 331 deletions
diff --git a/Source/PriceListTools/ExportTool.cs b/Source/PriceListTools/ExportTool.cs
deleted file mode 100644
index 0a28bf3..0000000
--- a/Source/PriceListTools/ExportTool.cs
+++ /dev/null
@@ -1,115 +0,0 @@
-using ExcelDna.Integration;
-using Microsoft.Office.Interop.Excel;
-using RehauSku.Assistant;
-using System;
-using System.Collections.Generic;
-
-namespace RehauSku.PriceListTools
-{
- class ExportTool : IDisposable
- {
- private Application ExcelApp;
- private Dictionary<string, double> SkuAmount { get; set; }
- private Range Selection { get; set; }
-
- public ExportTool()
- {
- this.ExcelApp = (Application)ExcelDnaUtil.Application;
- Selection = ExcelApp.Selection;
-
- if (IsRangeValid())
- _FillSkuAmountDict();
- }
-
- public bool IsRangeValid()
- {
- return Selection != null &&
- 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.ToString().IsRehauSku())
- {
- sku = current.ToString();
- }
-
- else if (current.GetType() == typeof(string)
- && double.TryParse(current.ToString(), 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 ExportToNewFile()
- {
- if (SkuAmount.Count < 1)
- {
- return;
- }
-
- string exportFile = PriceListUtil.CreateNewExportFile();
- Workbook wb = ExcelApp.Workbooks.Open(exportFile);
-
- try
- {
- PriceList priceList = new PriceList(wb);
- priceList.Fill(SkuAmount);
- }
-
- catch(Exception ex)
- {
- System.Windows.Forms.MessageBox.Show
- ($"{RegistryUtil.PriceListPath} не является файлом прайслиста \n\n {ex.Message}",
- "Неверный файл прайс-листа!",
- System.Windows.Forms.MessageBoxButtons.OK,
- System.Windows.Forms.MessageBoxIcon.Error);
-
- wb.Close();
- }
- }
-
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- protected virtual void Dispose(bool disposing)
- {
-
- }
- }
-}
-
diff --git a/Source/PriceListTools/MergeTool.cs b/Source/PriceListTools/MergeTool.cs
deleted file mode 100644
index 6b0644d..0000000
--- a/Source/PriceListTools/MergeTool.cs
+++ /dev/null
@@ -1,88 +0,0 @@
-using ExcelDna.Integration;
-using Microsoft.Office.Interop.Excel;
-using System;
-using System.Collections.Generic;
-
-namespace RehauSku.PriceListTools
-{
- class MergeTool : IDisposable
- {
- private Application ExcelApp;
- private Dictionary<string, double> SkuAmount { get; set; }
-
- public MergeTool()
- {
- this.ExcelApp = (Application)ExcelDnaUtil.Application;
- this.SkuAmount = new Dictionary<string, double>();
- }
-
- public void AddSkuAmountToDict(string[] files)
- {
- ExcelApp.ScreenUpdating = false;
- foreach (string file in files)
- {
- Workbook wb = ExcelApp.Workbooks.Open(file);
-
- try
- {
- PriceList priceList = new PriceList(wb);
- SkuAmount.AddValues(priceList);
- }
-
- catch (Exception ex)
- {
- System.Windows.Forms.MessageBox.Show
- ( $"{wb.Name} не является файлом прайслиста \n\n {ex.Message}",
- "Неверный файл прайс-листа!",
- System.Windows.Forms.MessageBoxButtons.OK,
- System.Windows.Forms.MessageBoxIcon.Error);
- }
-
- finally
- {
- wb.Close();
- }
- }
- ExcelApp.ScreenUpdating = true;
- }
-
- public void ExportToNewFile(string exportFile)
- {
- if (SkuAmount.Count < 1)
- {
- return;
- }
-
- Workbook wb = ExcelApp.Workbooks.Open(exportFile);
- PriceList priceList;
-
- try
- {
- priceList = new PriceList(wb);
- priceList.Fill(SkuAmount);
- }
-
- catch (Exception ex)
- {
- System.Windows.Forms.MessageBox.Show
- ($"{RegistryUtil.PriceListPath} не является файлом прайслиста \n\n {ex.Message}",
- "Неверный файл прайс-листа!",
- System.Windows.Forms.MessageBoxButtons.OK,
- System.Windows.Forms.MessageBoxIcon.Error);
-
- wb.Close();
- }
- }
-
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- protected virtual void Dispose(bool disposing)
- {
-
- }
- }
-}
diff --git a/Source/PriceListTools/PriceList.cs b/Source/PriceListTools/PriceList.cs
deleted file mode 100644
index 1460c07..0000000
--- a/Source/PriceListTools/PriceList.cs
+++ /dev/null
@@ -1,87 +0,0 @@
-using Microsoft.Office.Interop.Excel;
-using System.Collections.Generic;
-
-namespace RehauSku.PriceListTools
-{
- class PriceList
- {
- public readonly Workbook Workbook;
- public readonly PriceListSheet OfferSheet;
- public readonly PriceListSheet ActiveSheet;
-
- private const string _amountHeader = "Кол-во";
- private const string _skuHeader = "Актуальный материал";
- private const string _offerSheetHeader = "КП";
-
- public PriceList(Workbook workbook)
- {
- Workbook = workbook;
- OfferSheet = new PriceListSheet(workbook.Sheets[_offerSheetHeader]);
-
- Worksheet active = workbook.ActiveSheet;
-
- if (active.Name == _offerSheetHeader)
- ActiveSheet = OfferSheet;
-
- else
- ActiveSheet = new PriceListSheet(active);
- }
-
- public bool IsValid()
- {
- return OfferSheet.IsValid() &&
- ActiveSheet.IsValid();
- }
-
- public void Fill(Dictionary<string, double> values)
- {
- Worksheet ws = OfferSheet.sheet;
- ws.Activate();
-
- int amountColumn = OfferSheet.amountColumn.Value;
- int skuColumn = OfferSheet.skuColumn.Value;
-
- foreach (KeyValuePair<string, double> kvp in values)
- {
- 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();
- }
-
- public class PriceListSheet
- {
- public readonly Worksheet sheet;
- public readonly int? headerRow;
- public readonly int? amountColumn;
- public readonly int? skuColumn;
- public object[,] amountCells;
- public object[,] skuCells;
-
- public PriceListSheet(Worksheet sheet)
- {
- this.sheet = sheet;
- headerRow = sheet.Cells.Find(_amountHeader).Row;
- amountColumn = sheet.Cells.Find(_amountHeader).Column;
- skuColumn = sheet.Cells.Find(_skuHeader).Column;
-
- amountCells = sheet.Columns[amountColumn].Value2;
- skuCells = sheet.Columns[skuColumn].Value2;
- }
-
- public bool IsValid()
- {
- return sheet != null &&
- headerRow != null &&
- amountColumn != null &&
- skuColumn != null;
- }
- }
- }
-}
-
diff --git a/Source/PriceListTools/PriceListUtil.cs b/Source/PriceListTools/PriceListUtil.cs
deleted file mode 100644
index 14797d9..0000000
--- a/Source/PriceListTools/PriceListUtil.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-using System.Collections.Generic;
-using System.IO;
-
-namespace RehauSku.PriceListTools
-{
- static class PriceListUtil
- {
- public static string CreateNewExportFile()
- {
- string fileExtension = Path.GetExtension(RegistryUtil.PriceListPath);
- string path = Path.GetTempFileName() + fileExtension;
-
- File.Copy(RegistryUtil.PriceListPath, path);
- return path;
- }
-
- public static void AddValues(this Dictionary<string, double> SkuAmount, PriceList priceList)
- {
- object[,] amountCells = priceList.ActiveSheet.amountCells;
- object[,] skuCells = priceList.ActiveSheet.skuCells;
-
- for (int row = priceList.ActiveSheet.headerRow.Value + 1; row < amountCells.GetLength(0); row++)
- {
- object amount = amountCells[row, 1];
- object sku = skuCells[row, 1];
-
- if (amount != null && (double)amount != 0)
- {
- if (SkuAmount.ContainsKey(sku.ToString()))
- {
- SkuAmount[sku.ToString()] += (double)amount;
- }
-
- else
- SkuAmount.Add(sku.ToString(), (double)amount);
- }
- }
- }
- }
-}
-