diff options
author | Sergey Chebotar <s.chebotar@gmail.com> | 2021-12-22 17:07:37 +0300 |
---|---|---|
committer | Sergey Chebotar <s.chebotar@gmail.com> | 2021-12-22 17:07:37 +0300 |
commit | ce5597d042062c820288c63b4e571ee77ac23ab0 (patch) | |
tree | 9400511fce89ae4b6d4df205b605f560778dcb57 | |
parent | f97d344f39c46b5e2f883765e8859e78007a11b0 (diff) |
RegistryUtil and some fixes
-rw-r--r-- | RehauSku.Assist.csproj | 3 | ||||
-rw-r--r-- | RehauSku.Assist.sln | 10 | ||||
-rw-r--r-- | Source/AddIn/AddIn.cs | 1 | ||||
-rw-r--r-- | Source/AddIn/FileDialog.cs | 24 | ||||
-rw-r--r-- | Source/AddIn/RegistryUtil.cs | 57 | ||||
-rw-r--r-- | Source/Assistant/ParseUtil.cs | 45 | ||||
-rw-r--r-- | Source/Assistant/SkuExtensions.cs (renamed from Source/Assistant/SkuExtension.cs) | 2 | ||||
-rw-r--r-- | Source/DataExport/Exporter.cs | 12 | ||||
-rw-r--r-- | Source/Ribbon/RibbonController.cs | 7 | ||||
-rw-r--r-- | Source/Settings/SettingsForm.cs | 7 |
10 files changed, 95 insertions, 73 deletions
diff --git a/RehauSku.Assist.csproj b/RehauSku.Assist.csproj index 1497201..411a8b2 100644 --- a/RehauSku.Assist.csproj +++ b/RehauSku.Assist.csproj @@ -100,11 +100,12 @@ <Reference Include="WindowsBase" /> </ItemGroup> <ItemGroup> + <Compile Include="Source\AddIn\FileDialog.cs" /> <Compile Include="Source\AddIn\RegistryUtil.cs" /> <Compile Include="Source\Assistant\MemoryCacheExtensions.cs" /> <Compile Include="Source\Assistant\ParseUtil.cs" /> <Compile Include="Source\Assistant\RequestModifier.cs" /> - <Compile Include="Source\Assistant\SkuExtension.cs" /> + <Compile Include="Source\Assistant\SkuExtensions.cs" /> <Compile Include="Source\Ribbon\RibbonController.cs" /> <Compile Include="Source\Assistant\HttpClientUtil.cs" /> <Compile Include="Source\Assistant\StoreResponse.cs" /> diff --git a/RehauSku.Assist.sln b/RehauSku.Assist.sln index e37e8b4..1fe96c1 100644 --- a/RehauSku.Assist.sln +++ b/RehauSku.Assist.sln @@ -1,12 +1,10 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31829.152 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.32014.148 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RehauSku.Assist", "RehauSku.Assist.csproj", "{18A2FF67-0E46-4A86-B872-29F2B3F23ADF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RehauSku.Testing", "..\RehauSku.Testing\RehauSku.Testing.csproj", "{3D257D07-0D29-4B5E-82E4-B341769E1B3F}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -17,10 +15,6 @@ Global {18A2FF67-0E46-4A86-B872-29F2B3F23ADF}.Debug|Any CPU.Build.0 = Debug|Any CPU {18A2FF67-0E46-4A86-B872-29F2B3F23ADF}.Release|Any CPU.ActiveCfg = Release|Any CPU {18A2FF67-0E46-4A86-B872-29F2B3F23ADF}.Release|Any CPU.Build.0 = Release|Any CPU - {3D257D07-0D29-4B5E-82E4-B341769E1B3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3D257D07-0D29-4B5E-82E4-B341769E1B3F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3D257D07-0D29-4B5E-82E4-B341769E1B3F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3D257D07-0D29-4B5E-82E4-B341769E1B3F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Source/AddIn/AddIn.cs b/Source/AddIn/AddIn.cs index 4a26f55..08b6dcf 100644 --- a/Source/AddIn/AddIn.cs +++ b/Source/AddIn/AddIn.cs @@ -22,6 +22,7 @@ namespace RehauSku { RegisterFunctions(); IntelliSenseServer.Install(); + RegistryUtil.Initialize(); } public void AutoClose() diff --git a/Source/AddIn/FileDialog.cs b/Source/AddIn/FileDialog.cs new file mode 100644 index 0000000..a7e2144 --- /dev/null +++ b/Source/AddIn/FileDialog.cs @@ -0,0 +1,24 @@ +using System.Windows.Forms; + +namespace RehauSku +{ + static class FileDialog + { + public static string GetFilePath() + { + string filePath = string.Empty; + + using (OpenFileDialog dialog = new OpenFileDialog()) + { + dialog.Filter = "Все файлы (*.*)|*.*"; + + if (dialog.ShowDialog() == DialogResult.OK) + { + filePath = dialog.FileName; + } + } + + return filePath; + } + } +} diff --git a/Source/AddIn/RegistryUtil.cs b/Source/AddIn/RegistryUtil.cs index 6ab7682..19f48b8 100644 --- a/Source/AddIn/RegistryUtil.cs +++ b/Source/AddIn/RegistryUtil.cs @@ -1,42 +1,61 @@ using Microsoft.Win32; +using System.IO; namespace RehauSku { static class RegistryUtil { - public static string PriceListPath + private static string _priceListPath; + private static int? _storeResponseOrder; + private static RegistryKey _RootKey { get; set; } + + public static void Initialize() { - get => (string)_RootKey.GetValue("PriceListPath"); + _RootKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\REHAU\SkuAssist"); + _priceListPath = _RootKey.GetValue("PriceListPath") as string; + _storeResponseOrder = _RootKey.GetValue("StoreResponseOrder") as int?; } - public static ResponseOrder StoreResponseOrder + public static bool IsPriceListPathEmpty() { - get => (ResponseOrder)_RootKey.GetValue("StoreResponseOrder"); + return string.IsNullOrEmpty(_priceListPath); } - private static RegistryKey _RootKey + public static string PriceListPath { get { - return _OpenRootKey() ?? _CreateRootKey(); - } - } + if (IsPriceListPathEmpty() || !File.Exists(_priceListPath)) + { + string fileName = FileDialog.GetFilePath(); + _priceListPath = fileName; + _RootKey.SetValue("PriceListPath", fileName); + return _priceListPath; + } - private static RegistryKey _OpenRootKey() - { - return Registry.CurrentUser - .OpenSubKey(@"SOFTWARE\REHAU\SkuAssist"); + else + { + return _priceListPath; + } + } } - private static RegistryKey _CreateRootKey() + public static ResponseOrder StoreResponseOrder { - RegistryKey key = Registry.CurrentUser - .CreateSubKey(@"SOFTWARE\REHAU\SkuAssist"); - - key.SetValue("PriceListPath", @"D:\Dropbox\Рабочее\Таблица заказов ИС EAE_2021.xlsm"); - key.SetValue("StoreResponseOrder", 0); + get + { + if (_storeResponseOrder == null) + { + _RootKey.SetValue("StoreResponseOrder", (int)ResponseOrder.Default); + _storeResponseOrder = (int)ResponseOrder.Default; + return (ResponseOrder)_storeResponseOrder.Value; + } - return key; + else + { + return (ResponseOrder)_storeResponseOrder.Value; + } + } } } } diff --git a/Source/Assistant/ParseUtil.cs b/Source/Assistant/ParseUtil.cs index 571c6b0..a93c658 100644 --- a/Source/Assistant/ParseUtil.cs +++ b/Source/Assistant/ParseUtil.cs @@ -1,10 +1,8 @@ using AngleSharp; using AngleSharp.Dom; using Newtonsoft.Json; -using System; using System.Linq; using System.Threading.Tasks; -using System.Windows.Forms; namespace RehauSku.Assistant { @@ -20,36 +18,27 @@ namespace RehauSku.Assistant public static IProduct GetProduct(IDocument document) { - try - { - string script = document - .Scripts - .Where(s => s.InnerHtml.Contains("dataLayer")) - .FirstOrDefault() - .InnerHtml; + string script = document + .Scripts + .Where(s => s.InnerHtml.Contains("dataLayer")) + .FirstOrDefault() + .InnerHtml; - string json = script - .Substring(script.IndexOf("push(") + 5) - .TrimEnd(new[] { ')', ';', '\n', ' ' }); + string json = script + .Substring(script.IndexOf("push(") + 5) + .TrimEnd(new[] { ')', ';', '\n', ' ' }); - if (!json.Contains("impressions")) - return null; - - StoreResponce storeResponse = JsonConvert.DeserializeObject<StoreResponce>(json); - IProduct product = storeResponse - .Ecommerce - .Impressions - .Where(p => p.Id.IsRehauSku()) - .FirstOrDefault(); + if (!json.Contains("impressions")) + return null; - return product; - } + StoreResponce storeResponse = JsonConvert.DeserializeObject<StoreResponce>(json); + IProduct product = storeResponse + .Ecommerce + .Impressions + .Where(p => p.Id.IsRehauSku()) + .FirstOrDefault(); - catch (NullReferenceException e) - { - MessageBox.Show(e.Message, "Ошибка получения данных", MessageBoxButtons.OK, MessageBoxIcon.Error); - return null; - } + return product; } } }
\ No newline at end of file diff --git a/Source/Assistant/SkuExtension.cs b/Source/Assistant/SkuExtensions.cs index 51aaf6c..e39807b 100644 --- a/Source/Assistant/SkuExtension.cs +++ b/Source/Assistant/SkuExtensions.cs @@ -2,7 +2,7 @@ namespace RehauSku.Assistant { - static class SkuExtension + static class SkuExtensions { public static bool IsRehauSku(this string line) { diff --git a/Source/DataExport/Exporter.cs b/Source/DataExport/Exporter.cs index 483dd0e..95b3186 100644 --- a/Source/DataExport/Exporter.cs +++ b/Source/DataExport/Exporter.cs @@ -34,7 +34,7 @@ namespace RehauSku.DataExport SelectedCells.GetLength(1) == 2; } - public void FillSkuAmountDict() + private void FillSkuAmountDict() { SkuAmount = new Dictionary<string, double>(); int rowsCount = SelectedCells.GetLength(0); @@ -73,20 +73,22 @@ namespace RehauSku.DataExport } } - public void FillPriceList() + public void FillNewPriceList() { + FillSkuAmountDict(); string exportFile = _GetExportFullPath(); File.Copy(RegistryUtil.PriceListPath, exportFile, true); Workbook wb = xlApp.Workbooks.Open(exportFile); Worksheet ws = wb.ActiveSheet; - Range amountCell = ws.Cells.Find("Кол-во"); + int amountColumn = ws.Cells.Find("Кол-во").Column; + int skuColumn = ws.Cells.Find("Актуальный материал").Column; foreach (KeyValuePair<string, double> kvp in SkuAmount) { - Range cell = ws.Cells.Find(kvp.Key); - ws.Cells[cell.Row, amountCell.Column].Value = kvp.Value; + Range cell = ws.Columns[skuColumn].Find(kvp.Key); + ws.Cells[cell.Row, amountColumn].Value = kvp.Value; } ws.Cells.AutoFilter(7, "<>"); diff --git a/Source/Ribbon/RibbonController.cs b/Source/Ribbon/RibbonController.cs index 7e15d09..cfe4532 100644 --- a/Source/Ribbon/RibbonController.cs +++ b/Source/Ribbon/RibbonController.cs @@ -42,16 +42,15 @@ namespace RehauSku.Ribbon else { - dw.FillSkuAmountDict(); - dw.FillPriceList(); + dw.FillNewPriceList(); } } } - public void OnSettingsPressed(IRibbonControl control) { - Application.Run(new Settings.SettingsForm()); + Form settingsForm = new Settings.SettingsForm(); + settingsForm.Show(); } } } diff --git a/Source/Settings/SettingsForm.cs b/Source/Settings/SettingsForm.cs index b87ac5c..59edf22 100644 --- a/Source/Settings/SettingsForm.cs +++ b/Source/Settings/SettingsForm.cs @@ -15,13 +15,6 @@ namespace RehauSku.Settings public SettingsForm() { InitializeComponent(); - - FormClosing += (sender, eventArgs) => - { - MessageBox.Show("ok"); - }; - - } private void button1_Click(object sender, EventArgs e) |