diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/AddIn/RegistryUtil.cs | 6 | ||||
-rw-r--r-- | Source/Forms/Dialog.cs | 4 | ||||
-rw-r--r-- | Source/PriceListTools/ExportTool.cs | 22 | ||||
-rw-r--r-- | Source/PriceListTools/MergeTool.cs | 43 | ||||
-rw-r--r-- | Source/Ribbon/RibbonController.cs | 14 |
5 files changed, 72 insertions, 17 deletions
diff --git a/Source/AddIn/RegistryUtil.cs b/Source/AddIn/RegistryUtil.cs index 3e7c120..40d0ec2 100644 --- a/Source/AddIn/RegistryUtil.cs +++ b/Source/AddIn/RegistryUtil.cs @@ -47,6 +47,12 @@ namespace RehauSku return _priceListPath; } } + + set + { + _priceListPath = value; + _RootKey.SetValue("PriceListPath", value); + } } public static ResponseOrder StoreResponseOrder diff --git a/Source/Forms/Dialog.cs b/Source/Forms/Dialog.cs index 1953816..170cc81 100644 --- a/Source/Forms/Dialog.cs +++ b/Source/Forms/Dialog.cs @@ -11,7 +11,7 @@ namespace RehauSku.Forms using (OpenFileDialog dialog = new OpenFileDialog()) { - dialog.Filter = "Все файлы (*.*)|*.*"; + dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm"; if (dialog.ShowDialog() == DialogResult.OK) { @@ -28,7 +28,7 @@ namespace RehauSku.Forms using (OpenFileDialog dialog = new OpenFileDialog()) { - dialog.Filter = "Все файлы (*.*)|*.*"; + dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm"; dialog.Multiselect = true; if (dialog.ShowDialog() == DialogResult.OK) diff --git a/Source/PriceListTools/ExportTool.cs b/Source/PriceListTools/ExportTool.cs index 02def5b..0a28bf3 100644 --- a/Source/PriceListTools/ExportTool.cs +++ b/Source/PriceListTools/ExportTool.cs @@ -74,12 +74,30 @@ namespace RehauSku.PriceListTools public void ExportToNewFile() { + if (SkuAmount.Count < 1) + { + return; + } + string exportFile = PriceListUtil.CreateNewExportFile(); Workbook wb = ExcelApp.Workbooks.Open(exportFile); - PriceList priceList = new PriceList(wb); - if (priceList.IsValid()) + 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() diff --git a/Source/PriceListTools/MergeTool.cs b/Source/PriceListTools/MergeTool.cs index 21da41d..6b0644d 100644 --- a/Source/PriceListTools/MergeTool.cs +++ b/Source/PriceListTools/MergeTool.cs @@ -22,23 +22,56 @@ namespace RehauSku.PriceListTools foreach (string file in files) { Workbook wb = ExcelApp.Workbooks.Open(file); - PriceList priceList = new PriceList(wb); - if (priceList.IsValid()) + try + { + PriceList priceList = new PriceList(wb); SkuAmount.AddValues(priceList); + } - wb.Close(); + 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 = new PriceList(wb); + PriceList priceList; - if (priceList.IsValid()) + 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() diff --git a/Source/Ribbon/RibbonController.cs b/Source/Ribbon/RibbonController.cs index 0090761..df6f327 100644 --- a/Source/Ribbon/RibbonController.cs +++ b/Source/Ribbon/RibbonController.cs @@ -17,11 +17,11 @@ namespace RehauSku.Ribbon <tabs> <tab id='rau' label='REHAU'> <group id='priceList' label='Прайс-лист'> - <button id='exportToPrice' label='Экспорт' size='large' imageMso='PivotExportToExcel' onAction='OnExportPressed'/> - <button id='mergeFiles' label='Объединить' size='large' imageMso='Copy' onAction='OnMergePressed'/> + <button id='exportToPrice' label='Экспорт в новый файл' size='normal' imageMso='PivotExportToExcel' onAction='OnExportPressed'/> + <button id='mergeFiles' label='Объединить' size='normal' imageMso='Copy' onAction='OnMergePressed'/> </group> <group id='rausettings' label='Настройки'> - <button id='set' label='Настройки' size='large' imageMso='CurrentViewSettings' onAction='OnSettingsPressed'/> + <button id='setPriceList' label='Файл прайс-листа' size='normal' imageMso='CurrentViewSettings' onAction='OnSetPricePressed'/> </group> </tab> </tabs> @@ -60,12 +60,10 @@ namespace RehauSku.Ribbon } } - public void OnSettingsPressed(IRibbonControl control) + public void OnSetPricePressed(IRibbonControl control) { - Form settingsForm = new SettingsForm(); - - settingsForm.Show(); - + string path = Dialog.GetFilePath(); + RegistryUtil.PriceListPath = path; } } } |