aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2021-12-23 15:31:23 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2021-12-23 15:31:23 +0300
commit0513ac5ad7c7de498b794c27728c2c8ff306f941 (patch)
tree2b55e7a387a8ab18371d008f6c23308caaa41d4f
parentce5597d042062c820288c63b4e571ee77ac23ab0 (diff)
Rename to ExportTool
-rw-r--r--Source/AddIn/AddIn.cs1
-rw-r--r--Source/AddIn/RegistryUtil.cs5
-rw-r--r--Source/DataExport/ExportTool.cs (renamed from Source/DataExport/Exporter.cs)40
-rw-r--r--Source/Ribbon/RibbonController.cs2
4 files changed, 33 insertions, 15 deletions
diff --git a/Source/AddIn/AddIn.cs b/Source/AddIn/AddIn.cs
index 08b6dcf..014b607 100644
--- a/Source/AddIn/AddIn.cs
+++ b/Source/AddIn/AddIn.cs
@@ -28,6 +28,7 @@ namespace RehauSku
public void AutoClose()
{
IntelliSenseServer.Uninstall();
+ RegistryUtil.Uninitialize();
}
void RegisterFunctions()
diff --git a/Source/AddIn/RegistryUtil.cs b/Source/AddIn/RegistryUtil.cs
index 19f48b8..ef1398e 100644
--- a/Source/AddIn/RegistryUtil.cs
+++ b/Source/AddIn/RegistryUtil.cs
@@ -16,6 +16,11 @@ namespace RehauSku
_storeResponseOrder = _RootKey.GetValue("StoreResponseOrder") as int?;
}
+ public static void Uninitialize()
+ {
+ _RootKey.Close();
+ }
+
public static bool IsPriceListPathEmpty()
{
return string.IsNullOrEmpty(_priceListPath);
diff --git a/Source/DataExport/Exporter.cs b/Source/DataExport/ExportTool.cs
index 95b3186..8ea65cd 100644
--- a/Source/DataExport/Exporter.cs
+++ b/Source/DataExport/ExportTool.cs
@@ -7,14 +7,14 @@ using RehauSku.Assistant;
namespace RehauSku.DataExport
{
- public class Exporter : IDisposable
+ public class ExportTool : IDisposable
{
private Application xlApp;
private Dictionary<string, double> SkuAmount { get; set; }
- private object[,] SelectedCells { get; set; }
+ private Range Selection { get; set; }
private string CurrentFilePath { get; set; }
- public Exporter()
+ public ExportTool()
{
this.xlApp = (Application)ExcelDnaUtil.Application;
this.CurrentFilePath = xlApp.ActiveWorkbook.FullName;
@@ -24,24 +24,23 @@ namespace RehauSku.DataExport
private void _GetSelectedCells()
{
- Range selection = xlApp.Selection;
- this.SelectedCells = (object[,])selection.Value2;
+ Selection = xlApp.Selection;
}
public bool IsRangeValid()
{
- return SelectedCells != null &&
- SelectedCells.GetLength(1) == 2;
+ return Selection.Columns.Count == 2;
}
private void FillSkuAmountDict()
{
+ object[,] cells = Selection.Value2;
SkuAmount = new Dictionary<string, double>();
- int rowsCount = SelectedCells.GetLength(0);
+ int rowsCount = Selection.Rows.Count;
for (int row = 1; row <= rowsCount; row++)
{
- if (SelectedCells[row, 1] == null || SelectedCells[row, 2] == null)
+ if (cells[row, 1] == null || cells[row, 2] == null)
continue;
string sku = null;
@@ -49,7 +48,7 @@ namespace RehauSku.DataExport
for (int column = 1; column <= 2; column++)
{
- object current = SelectedCells[row, column];
+ object current = cells[row, column];
if (current.GetType() == typeof(string)
&& ((string)current).IsRehauSku())
@@ -75,15 +74,19 @@ namespace RehauSku.DataExport
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.ActiveSheet;
+ Worksheet ws = wb.Sheets["КП"];
+ ws.Activate();
- int amountColumn = ws.Cells.Find("Кол-во").Column;
- int skuColumn = ws.Cells.Find("Актуальный материал").Column;
+ int amountColumn = ws.Cells.Find(amountHeader).Column;
+ int skuColumn = ws.Cells.Find(skuHeader).Column;
foreach (KeyValuePair<string, double> kvp in SkuAmount)
{
@@ -91,7 +94,11 @@ namespace RehauSku.DataExport
ws.Cells[cell.Row, amountColumn].Value = kvp.Value;
}
- ws.Cells.AutoFilter(7, "<>");
+ AutoFilter filter = ws.AutoFilter;
+ int firstFilterColumn = filter.Range.Column;
+
+ filter.Range.AutoFilter(amountColumn - firstFilterColumn + 1, "<>");
+ ws.Range["A1"].Activate();
}
private string _GetExportFullPath()
@@ -113,5 +120,10 @@ namespace RehauSku.DataExport
}
}
+
+ class SelectionCheck
+ {
+
+ }
}
diff --git a/Source/Ribbon/RibbonController.cs b/Source/Ribbon/RibbonController.cs
index cfe4532..325b4c6 100644
--- a/Source/Ribbon/RibbonController.cs
+++ b/Source/Ribbon/RibbonController.cs
@@ -29,7 +29,7 @@ namespace RehauSku.Ribbon
public void OnExportPressed(IRibbonControl control)
{
- using (Exporter dw = new Exporter())
+ using (ExportTool dw = new ExportTool())
{
if (!dw.IsRangeValid())
{