Rename to ExportTool

This commit is contained in:
Sergey Chebotar 2021-12-23 15:31:23 +03:00
parent ce5597d042
commit 0513ac5ad7
4 changed files with 33 additions and 15 deletions

View File

@ -28,6 +28,7 @@ namespace RehauSku
public void AutoClose() public void AutoClose()
{ {
IntelliSenseServer.Uninstall(); IntelliSenseServer.Uninstall();
RegistryUtil.Uninitialize();
} }
void RegisterFunctions() void RegisterFunctions()

View File

@ -16,6 +16,11 @@ namespace RehauSku
_storeResponseOrder = _RootKey.GetValue("StoreResponseOrder") as int?; _storeResponseOrder = _RootKey.GetValue("StoreResponseOrder") as int?;
} }
public static void Uninitialize()
{
_RootKey.Close();
}
public static bool IsPriceListPathEmpty() public static bool IsPriceListPathEmpty()
{ {
return string.IsNullOrEmpty(_priceListPath); return string.IsNullOrEmpty(_priceListPath);

View File

@ -7,14 +7,14 @@ using RehauSku.Assistant;
namespace RehauSku.DataExport namespace RehauSku.DataExport
{ {
public class Exporter : IDisposable public class ExportTool : IDisposable
{ {
private Application xlApp; private Application xlApp;
private Dictionary<string, double> SkuAmount { get; set; } private Dictionary<string, double> SkuAmount { get; set; }
private object[,] SelectedCells { get; set; } private Range Selection { get; set; }
private string CurrentFilePath { get; set; } private string CurrentFilePath { get; set; }
public Exporter() public ExportTool()
{ {
this.xlApp = (Application)ExcelDnaUtil.Application; this.xlApp = (Application)ExcelDnaUtil.Application;
this.CurrentFilePath = xlApp.ActiveWorkbook.FullName; this.CurrentFilePath = xlApp.ActiveWorkbook.FullName;
@ -24,24 +24,23 @@ namespace RehauSku.DataExport
private void _GetSelectedCells() private void _GetSelectedCells()
{ {
Range selection = xlApp.Selection; Selection = xlApp.Selection;
this.SelectedCells = (object[,])selection.Value2;
} }
public bool IsRangeValid() public bool IsRangeValid()
{ {
return SelectedCells != null && return Selection.Columns.Count == 2;
SelectedCells.GetLength(1) == 2;
} }
private void FillSkuAmountDict() private void FillSkuAmountDict()
{ {
object[,] cells = Selection.Value2;
SkuAmount = new Dictionary<string, double>(); SkuAmount = new Dictionary<string, double>();
int rowsCount = SelectedCells.GetLength(0); int rowsCount = Selection.Rows.Count;
for (int row = 1; row <= rowsCount; row++) 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; continue;
string sku = null; string sku = null;
@ -49,7 +48,7 @@ namespace RehauSku.DataExport
for (int column = 1; column <= 2; column++) for (int column = 1; column <= 2; column++)
{ {
object current = SelectedCells[row, column]; object current = cells[row, column];
if (current.GetType() == typeof(string) if (current.GetType() == typeof(string)
&& ((string)current).IsRehauSku()) && ((string)current).IsRehauSku())
@ -75,15 +74,19 @@ namespace RehauSku.DataExport
public void FillNewPriceList() public void FillNewPriceList()
{ {
const string amountHeader = "Кол-во";
const string skuHeader = "Актуальный материал";
FillSkuAmountDict(); FillSkuAmountDict();
string exportFile = _GetExportFullPath(); string exportFile = _GetExportFullPath();
File.Copy(RegistryUtil.PriceListPath, exportFile, true); File.Copy(RegistryUtil.PriceListPath, exportFile, true);
Workbook wb = xlApp.Workbooks.Open(exportFile); Workbook wb = xlApp.Workbooks.Open(exportFile);
Worksheet ws = wb.ActiveSheet; Worksheet ws = wb.Sheets["КП"];
ws.Activate();
int amountColumn = ws.Cells.Find("Кол-во").Column; int amountColumn = ws.Cells.Find(amountHeader).Column;
int skuColumn = ws.Cells.Find("Актуальный материал").Column; int skuColumn = ws.Cells.Find(skuHeader).Column;
foreach (KeyValuePair<string, double> kvp in SkuAmount) foreach (KeyValuePair<string, double> kvp in SkuAmount)
{ {
@ -91,7 +94,11 @@ namespace RehauSku.DataExport
ws.Cells[cell.Row, amountColumn].Value = kvp.Value; 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() private string _GetExportFullPath()
@ -113,5 +120,10 @@ namespace RehauSku.DataExport
} }
} }
class SelectionCheck
{
}
} }

View File

@ -29,7 +29,7 @@ namespace RehauSku.Ribbon
public void OnExportPressed(IRibbonControl control) public void OnExportPressed(IRibbonControl control)
{ {
using (Exporter dw = new Exporter()) using (ExportTool dw = new ExportTool())
{ {
if (!dw.IsRangeValid()) if (!dw.IsRangeValid())
{ {