Add SaveAs Dialog after export

This commit is contained in:
Sergey Chebotar 2022-01-09 15:47:54 +03:00
parent 0c307e985f
commit 846547d6d9
8 changed files with 67 additions and 36 deletions

View File

@ -1,6 +1,7 @@
using ExcelDna.Integration;
using ExcelDna.IntelliSense;
using ExcelDna.Registration;
using Microsoft.Office.Interop.Excel;
using System.Net.Http;
using System.Runtime.Caching;
@ -20,6 +21,7 @@ namespace RehauSku
{
public static HttpClient httpClient;
public static MemoryCache memoryCache;
public static Application Excel;
public void AutoOpen()
{
@ -28,6 +30,7 @@ namespace RehauSku
RegisterFunctions();
IntelliSenseServer.Install();
RegistryUtil.Initialize();
Excel = (Application)ExcelDnaUtil.Application;
}
public void AutoClose()

View File

@ -2,56 +2,56 @@
using System.IO;
using RehauSku.Forms;
using System.Windows.Forms;
using ExcelDna.Integration;
namespace RehauSku
{
static class RegistryUtil
{
private static string _priceListPath;
private static int? _storeResponseOrder;
private static RegistryKey _RootKey { get; set; }
private static string priceListPath;
private static int? storeResponseOrder;
private static RegistryKey RootKey { get; set; }
public static void Initialize()
{
_RootKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\REHAU\SkuAssist");
_priceListPath = _RootKey.GetValue("PriceListPath") as string;
_storeResponseOrder = _RootKey.GetValue("StoreResponseOrder") as int?;
RootKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\REHAU\SkuAssist");
priceListPath = RootKey.GetValue("PriceListPath") as string;
storeResponseOrder = RootKey.GetValue("StoreResponseOrder") as int?;
}
public static void Uninitialize()
{
_RootKey.Close();
RootKey.Close();
}
public static bool IsPriceListPathEmpty()
{
return string.IsNullOrEmpty(_priceListPath);
return string.IsNullOrEmpty(priceListPath);
}
public static string PriceListPath
{
get
{
if (IsPriceListPathEmpty() || !File.Exists(_priceListPath))
if (IsPriceListPathEmpty() || !File.Exists(priceListPath))
{
MessageBox.Show("Прайс-лист отсутствует или неверный файл прайс-листа", "Укажите файл прайс-листа", MessageBoxButtons.OK, MessageBoxIcon.Warning);
//MessageBox.Show("Прайс-лист отсутствует или неверный файл прайс-листа", "Укажите файл прайс-листа", MessageBoxButtons.OK, MessageBoxIcon.Warning);
string fileName = Dialog.GetFilePath();
_priceListPath = fileName;
_RootKey.SetValue("PriceListPath", fileName);
return _priceListPath;
priceListPath = fileName;
RootKey.SetValue("PriceListPath", fileName);
return priceListPath;
}
else
{
return _priceListPath;
return priceListPath;
}
}
set
{
_priceListPath = value;
_RootKey.SetValue("PriceListPath", value);
priceListPath = value;
RootKey.SetValue("PriceListPath", value);
}
}
@ -59,16 +59,16 @@ namespace RehauSku
{
get
{
if (_storeResponseOrder == null)
if (storeResponseOrder == null)
{
_RootKey.SetValue("StoreResponseOrder", (int)ResponseOrder.Default);
_storeResponseOrder = (int)ResponseOrder.Default;
return (ResponseOrder)_storeResponseOrder.Value;
RootKey.SetValue("StoreResponseOrder", (int)ResponseOrder.Default);
storeResponseOrder = (int)ResponseOrder.Default;
return (ResponseOrder)storeResponseOrder.Value;
}
else
{
return (ResponseOrder)_storeResponseOrder.Value;
return (ResponseOrder)storeResponseOrder.Value;
}
}
}

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using Microsoft.Office.Interop.Excel;
using System.Collections.Generic;
using System.Windows.Forms;
namespace RehauSku.Forms
@ -42,5 +43,20 @@ namespace RehauSku.Forms
return fileNames.ToArray();
}
public static void SaveWorkbookAs()
{
Workbook wb = AddIn.Excel.ActiveWorkbook;
string currentFilename = wb.FullName;
string fileFilter = "Файлы Excel (*.xls;*.xlsx;*.xlsm),*.xls;*.xlsx;*.xlsm";
object fileName = AddIn.Excel.GetSaveAsFilename(currentFilename, fileFilter);
if (fileName.GetType() == typeof(string))
wb.SaveAs(fileName);
else
wb.Close(false);
}
}
}

View File

@ -63,7 +63,9 @@ namespace RehauSku.PriceListTools
filter.Range.AutoFilter(offer.amountColumnNumber - firstFilterColumn + 1 + exportedLists, "<>");
offer.Sheet.Range["A1"].Activate();
offer.Sheet.Application.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов";
AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов";
Forms.Dialog.SaveWorkbookAs();
}
public void Dispose()

View File

@ -113,7 +113,9 @@ namespace RehauSku.PriceListTools
filter.Range.AutoFilter(offer.amountColumnNumber - firstFilterColumn + 1, "<>");
offer.Sheet.Range["A1"].Activate();
offer.Sheet.Application.StatusBar = $"Экспортировано {exportedValues} строк из {SkuAmount.Count}";
AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {SkuAmount.Count}";
Forms.Dialog.SaveWorkbookAs();
}
public void Dispose()

View File

@ -52,7 +52,9 @@ namespace RehauSku.PriceListTools
filter.Range.AutoFilter(offer.amountColumnNumber - firstFilterColumn + 1, "<>");
offer.Sheet.Range["A1"].Activate();
offer.Sheet.Application.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов";
AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов";
Forms.Dialog.SaveWorkbookAs();
}
public void Dispose()

View File

@ -31,7 +31,7 @@ namespace RehauSku.PriceListTools
if (amountCell == null || skuCell == null)
{
Sheet.Application.StatusBar = $"Лист {Name} не распознан";
AddIn.Excel.StatusBar = $"Лист {Name} не распознан";
return false;
}

View File

@ -40,10 +40,13 @@ namespace RehauSku.Ribbon
using (MergeTool mergeTool = new MergeTool())
{
string[] files = Dialog.GetMultiplyFiles();
mergeTool.GetSource(files);
string exportFile = PriceList.CreateNewFile();
mergeTool.OpenNewPrice(exportFile);
mergeTool.FillPriceList();
if (files.Length != 0)
{
mergeTool.GetSource(files);
string exportFile = RegistryUtil.PriceListPath;
mergeTool.OpenNewPrice(exportFile);
mergeTool.FillPriceList();
}
}
}
@ -52,10 +55,13 @@ namespace RehauSku.Ribbon
using (CombineTool combineTool = new CombineTool())
{
string[] files = Dialog.GetMultiplyFiles();
combineTool.GetSource(files);
string exportFile = PriceList.CreateNewFile();
combineTool.OpenNewPrice(exportFile);
combineTool.FillPriceList();
if (files.Length != 0)
{
combineTool.GetSource(files);
string exportFile = RegistryUtil.PriceListPath;
combineTool.OpenNewPrice(exportFile);
combineTool.FillPriceList();
}
}
}
@ -66,7 +72,7 @@ namespace RehauSku.Ribbon
using (ExportTool exportTool = new ExportTool())
{
exportTool.GetSource();
string exportFile = PriceList.CreateNewFile();
string exportFile = RegistryUtil.PriceListPath;
exportTool.OpenNewPrice(exportFile);
exportTool.FillPriceList();
}