RegistryUtil and some fixes
This commit is contained in:
parent
f97d344f39
commit
ce5597d042
@ -100,11 +100,12 @@
|
|||||||
<Reference Include="WindowsBase" />
|
<Reference Include="WindowsBase" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Source\AddIn\FileDialog.cs" />
|
||||||
<Compile Include="Source\AddIn\RegistryUtil.cs" />
|
<Compile Include="Source\AddIn\RegistryUtil.cs" />
|
||||||
<Compile Include="Source\Assistant\MemoryCacheExtensions.cs" />
|
<Compile Include="Source\Assistant\MemoryCacheExtensions.cs" />
|
||||||
<Compile Include="Source\Assistant\ParseUtil.cs" />
|
<Compile Include="Source\Assistant\ParseUtil.cs" />
|
||||||
<Compile Include="Source\Assistant\RequestModifier.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\Ribbon\RibbonController.cs" />
|
||||||
<Compile Include="Source\Assistant\HttpClientUtil.cs" />
|
<Compile Include="Source\Assistant\HttpClientUtil.cs" />
|
||||||
<Compile Include="Source\Assistant\StoreResponse.cs" />
|
<Compile Include="Source\Assistant\StoreResponse.cs" />
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 16
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 16.0.31829.152
|
VisualStudioVersion = 17.0.32014.148
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RehauSku.Assist", "RehauSku.Assist.csproj", "{18A2FF67-0E46-4A86-B872-29F2B3F23ADF}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RehauSku.Assist", "RehauSku.Assist.csproj", "{18A2FF67-0E46-4A86-B872-29F2B3F23ADF}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RehauSku.Testing", "..\RehauSku.Testing\RehauSku.Testing.csproj", "{3D257D07-0D29-4B5E-82E4-B341769E1B3F}"
|
|
||||||
EndProject
|
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
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}.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.ActiveCfg = Release|Any CPU
|
||||||
{18A2FF67-0E46-4A86-B872-29F2B3F23ADF}.Release|Any CPU.Build.0 = 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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -22,6 +22,7 @@ namespace RehauSku
|
|||||||
{
|
{
|
||||||
RegisterFunctions();
|
RegisterFunctions();
|
||||||
IntelliSenseServer.Install();
|
IntelliSenseServer.Install();
|
||||||
|
RegistryUtil.Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AutoClose()
|
public void AutoClose()
|
||||||
|
24
Source/AddIn/FileDialog.cs
Normal file
24
Source/AddIn/FileDialog.cs
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,42 +1,61 @@
|
|||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace RehauSku
|
namespace RehauSku
|
||||||
{
|
{
|
||||||
static class RegistryUtil
|
static class RegistryUtil
|
||||||
{
|
{
|
||||||
|
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?;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsPriceListPathEmpty()
|
||||||
|
{
|
||||||
|
return string.IsNullOrEmpty(_priceListPath);
|
||||||
|
}
|
||||||
|
|
||||||
public static string PriceListPath
|
public static string PriceListPath
|
||||||
{
|
{
|
||||||
get => (string)_RootKey.GetValue("PriceListPath");
|
get
|
||||||
|
{
|
||||||
|
if (IsPriceListPathEmpty() || !File.Exists(_priceListPath))
|
||||||
|
{
|
||||||
|
string fileName = FileDialog.GetFilePath();
|
||||||
|
_priceListPath = fileName;
|
||||||
|
_RootKey.SetValue("PriceListPath", fileName);
|
||||||
|
return _priceListPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return _priceListPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResponseOrder StoreResponseOrder
|
public static ResponseOrder StoreResponseOrder
|
||||||
{
|
|
||||||
get => (ResponseOrder)_RootKey.GetValue("StoreResponseOrder");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static RegistryKey _RootKey
|
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _OpenRootKey() ?? _CreateRootKey();
|
if (_storeResponseOrder == null)
|
||||||
|
{
|
||||||
|
_RootKey.SetValue("StoreResponseOrder", (int)ResponseOrder.Default);
|
||||||
|
_storeResponseOrder = (int)ResponseOrder.Default;
|
||||||
|
return (ResponseOrder)_storeResponseOrder.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (ResponseOrder)_storeResponseOrder.Value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static RegistryKey _OpenRootKey()
|
|
||||||
{
|
|
||||||
return Registry.CurrentUser
|
|
||||||
.OpenSubKey(@"SOFTWARE\REHAU\SkuAssist");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static RegistryKey _CreateRootKey()
|
|
||||||
{
|
|
||||||
RegistryKey key = Registry.CurrentUser
|
|
||||||
.CreateSubKey(@"SOFTWARE\REHAU\SkuAssist");
|
|
||||||
|
|
||||||
key.SetValue("PriceListPath", @"D:\Dropbox\Рабочее\Таблица заказов ИС EAE_2021.xlsm");
|
|
||||||
key.SetValue("StoreResponseOrder", 0);
|
|
||||||
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
using AngleSharp;
|
using AngleSharp;
|
||||||
using AngleSharp.Dom;
|
using AngleSharp.Dom;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace RehauSku.Assistant
|
namespace RehauSku.Assistant
|
||||||
{
|
{
|
||||||
@ -20,36 +18,27 @@ namespace RehauSku.Assistant
|
|||||||
|
|
||||||
public static IProduct GetProduct(IDocument document)
|
public static IProduct GetProduct(IDocument document)
|
||||||
{
|
{
|
||||||
try
|
string script = document
|
||||||
{
|
.Scripts
|
||||||
string script = document
|
.Where(s => s.InnerHtml.Contains("dataLayer"))
|
||||||
.Scripts
|
.FirstOrDefault()
|
||||||
.Where(s => s.InnerHtml.Contains("dataLayer"))
|
.InnerHtml;
|
||||||
.FirstOrDefault()
|
|
||||||
.InnerHtml;
|
|
||||||
|
|
||||||
string json = script
|
string json = script
|
||||||
.Substring(script.IndexOf("push(") + 5)
|
.Substring(script.IndexOf("push(") + 5)
|
||||||
.TrimEnd(new[] { ')', ';', '\n', ' ' });
|
.TrimEnd(new[] { ')', ';', '\n', ' ' });
|
||||||
|
|
||||||
if (!json.Contains("impressions"))
|
if (!json.Contains("impressions"))
|
||||||
return null;
|
|
||||||
|
|
||||||
StoreResponce storeResponse = JsonConvert.DeserializeObject<StoreResponce>(json);
|
|
||||||
IProduct product = storeResponse
|
|
||||||
.Ecommerce
|
|
||||||
.Impressions
|
|
||||||
.Where(p => p.Id.IsRehauSku())
|
|
||||||
.FirstOrDefault();
|
|
||||||
|
|
||||||
return product;
|
|
||||||
}
|
|
||||||
|
|
||||||
catch (NullReferenceException e)
|
|
||||||
{
|
|
||||||
MessageBox.Show(e.Message, "Ошибка получения данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
|
StoreResponce storeResponse = JsonConvert.DeserializeObject<StoreResponce>(json);
|
||||||
|
IProduct product = storeResponse
|
||||||
|
.Ecommerce
|
||||||
|
.Impressions
|
||||||
|
.Where(p => p.Id.IsRehauSku())
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
return product;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace RehauSku.Assistant
|
namespace RehauSku.Assistant
|
||||||
{
|
{
|
||||||
static class SkuExtension
|
static class SkuExtensions
|
||||||
{
|
{
|
||||||
public static bool IsRehauSku(this string line)
|
public static bool IsRehauSku(this string line)
|
||||||
{
|
{
|
@ -34,7 +34,7 @@ namespace RehauSku.DataExport
|
|||||||
SelectedCells.GetLength(1) == 2;
|
SelectedCells.GetLength(1) == 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FillSkuAmountDict()
|
private void FillSkuAmountDict()
|
||||||
{
|
{
|
||||||
SkuAmount = new Dictionary<string, double>();
|
SkuAmount = new Dictionary<string, double>();
|
||||||
int rowsCount = SelectedCells.GetLength(0);
|
int rowsCount = SelectedCells.GetLength(0);
|
||||||
@ -73,20 +73,22 @@ namespace RehauSku.DataExport
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FillPriceList()
|
public void FillNewPriceList()
|
||||||
{
|
{
|
||||||
|
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.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)
|
foreach (KeyValuePair<string, double> kvp in SkuAmount)
|
||||||
{
|
{
|
||||||
Range cell = ws.Cells.Find(kvp.Key);
|
Range cell = ws.Columns[skuColumn].Find(kvp.Key);
|
||||||
ws.Cells[cell.Row, amountCell.Column].Value = kvp.Value;
|
ws.Cells[cell.Row, amountColumn].Value = kvp.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
ws.Cells.AutoFilter(7, "<>");
|
ws.Cells.AutoFilter(7, "<>");
|
||||||
|
@ -42,16 +42,15 @@ namespace RehauSku.Ribbon
|
|||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dw.FillSkuAmountDict();
|
dw.FillNewPriceList();
|
||||||
dw.FillPriceList();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void OnSettingsPressed(IRibbonControl control)
|
public void OnSettingsPressed(IRibbonControl control)
|
||||||
{
|
{
|
||||||
Application.Run(new Settings.SettingsForm());
|
Form settingsForm = new Settings.SettingsForm();
|
||||||
|
settingsForm.Show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,13 +15,6 @@ namespace RehauSku.Settings
|
|||||||
public SettingsForm()
|
public SettingsForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
FormClosing += (sender, eventArgs) =>
|
|
||||||
{
|
|
||||||
MessageBox.Show("ok");
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void button1_Click(object sender, EventArgs e)
|
private void button1_Click(object sender, EventArgs e)
|
||||||
|
Loading…
Reference in New Issue
Block a user