From 54fc3320e7d64d7903b4d091fe0d5c15df01fd78 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Sun, 26 Dec 2021 18:22:32 +0300 Subject: Move to /src --- Properties/AssemblyInfo.cs | 36 --------- Properties/ExcelDna.Build.props | 77 ------------------ RehauSku.Assist-AddIn.dna | 13 --- RehauSku.Assist.csproj | 143 --------------------------------- RehauSku.Assist.sln | 25 ------ Source/AddIn/AddIn.cs | 47 ----------- Source/AddIn/Functions.cs | 56 ------------- Source/AddIn/MemoryCacheUtil.cs | 37 --------- Source/AddIn/RegistryUtil.cs | 76 ------------------ Source/Assistant/HttpClientUtil.cs | 53 ------------ Source/Assistant/IProduct.cs | 9 --- Source/Assistant/ParseUtil.cs | 44 ---------- Source/Assistant/RequestModifier.cs | 67 --------------- Source/Assistant/SkuAssist.cs | 22 ----- Source/Assistant/SkuExtensions.cs | 12 --- Source/Assistant/StoreResponse.cs | 21 ----- Source/Forms/Dialog.cs | 46 ----------- Source/Forms/SettingsForm.Designer.cs | 46 ----------- Source/Forms/SettingsForm.cs | 21 ----- Source/Forms/SettingsForm.resx | 120 --------------------------- Source/PriceListTools/ExportTool.cs | 115 -------------------------- Source/PriceListTools/MergeTool.cs | 88 -------------------- Source/PriceListTools/PriceList.cs | 87 -------------------- Source/PriceListTools/PriceListUtil.cs | 41 ---------- Source/Ribbon/RibbonController.cs | 69 ---------------- app.config | 15 ---- packages.config | 15 ---- src/AddIn/AddIn.cs | 47 +++++++++++ src/AddIn/Functions.cs | 56 +++++++++++++ src/AddIn/MemoryCacheUtil.cs | 37 +++++++++ src/AddIn/RegistryUtil.cs | 76 ++++++++++++++++++ src/Assistant/HttpClientUtil.cs | 53 ++++++++++++ src/Assistant/IProduct.cs | 9 +++ src/Assistant/ParseUtil.cs | 44 ++++++++++ src/Assistant/RequestModifier.cs | 67 +++++++++++++++ src/Assistant/SkuAssist.cs | 22 +++++ src/Assistant/SkuExtensions.cs | 12 +++ src/Assistant/StoreResponse.cs | 21 +++++ src/Forms/Dialog.cs | 46 +++++++++++ src/Forms/SettingsForm.Designer.cs | 46 +++++++++++ src/Forms/SettingsForm.cs | 21 +++++ src/Forms/SettingsForm.resx | 120 +++++++++++++++++++++++++++ src/PriceListTools/ExportTool.cs | 115 ++++++++++++++++++++++++++ src/PriceListTools/MergeTool.cs | 88 ++++++++++++++++++++ src/PriceListTools/PriceList.cs | 87 ++++++++++++++++++++ src/PriceListTools/PriceListUtil.cs | 41 ++++++++++ src/Properties/AssemblyInfo.cs | 36 +++++++++ src/Properties/ExcelDna.Build.props | 77 ++++++++++++++++++ src/RehauSku.Assist-AddIn.dna | 13 +++ src/RehauSku.Assist.csproj | 143 +++++++++++++++++++++++++++++++++ src/RehauSku.Assist.sln | 25 ++++++ src/Ribbon/RibbonController.cs | 69 ++++++++++++++++ src/app.config | 15 ++++ src/packages.config | 15 ++++ 54 files changed, 1401 insertions(+), 1401 deletions(-) delete mode 100644 Properties/AssemblyInfo.cs delete mode 100644 Properties/ExcelDna.Build.props delete mode 100644 RehauSku.Assist-AddIn.dna delete mode 100644 RehauSku.Assist.csproj delete mode 100644 RehauSku.Assist.sln delete mode 100644 Source/AddIn/AddIn.cs delete mode 100644 Source/AddIn/Functions.cs delete mode 100644 Source/AddIn/MemoryCacheUtil.cs delete mode 100644 Source/AddIn/RegistryUtil.cs delete mode 100644 Source/Assistant/HttpClientUtil.cs delete mode 100644 Source/Assistant/IProduct.cs delete mode 100644 Source/Assistant/ParseUtil.cs delete mode 100644 Source/Assistant/RequestModifier.cs delete mode 100644 Source/Assistant/SkuAssist.cs delete mode 100644 Source/Assistant/SkuExtensions.cs delete mode 100644 Source/Assistant/StoreResponse.cs delete mode 100644 Source/Forms/Dialog.cs delete mode 100644 Source/Forms/SettingsForm.Designer.cs delete mode 100644 Source/Forms/SettingsForm.cs delete mode 100644 Source/Forms/SettingsForm.resx delete mode 100644 Source/PriceListTools/ExportTool.cs delete mode 100644 Source/PriceListTools/MergeTool.cs delete mode 100644 Source/PriceListTools/PriceList.cs delete mode 100644 Source/PriceListTools/PriceListUtil.cs delete mode 100644 Source/Ribbon/RibbonController.cs delete mode 100644 app.config delete mode 100644 packages.config create mode 100644 src/AddIn/AddIn.cs create mode 100644 src/AddIn/Functions.cs create mode 100644 src/AddIn/MemoryCacheUtil.cs create mode 100644 src/AddIn/RegistryUtil.cs create mode 100644 src/Assistant/HttpClientUtil.cs create mode 100644 src/Assistant/IProduct.cs create mode 100644 src/Assistant/ParseUtil.cs create mode 100644 src/Assistant/RequestModifier.cs create mode 100644 src/Assistant/SkuAssist.cs create mode 100644 src/Assistant/SkuExtensions.cs create mode 100644 src/Assistant/StoreResponse.cs create mode 100644 src/Forms/Dialog.cs create mode 100644 src/Forms/SettingsForm.Designer.cs create mode 100644 src/Forms/SettingsForm.cs create mode 100644 src/Forms/SettingsForm.resx create mode 100644 src/PriceListTools/ExportTool.cs create mode 100644 src/PriceListTools/MergeTool.cs create mode 100644 src/PriceListTools/PriceList.cs create mode 100644 src/PriceListTools/PriceListUtil.cs create mode 100644 src/Properties/AssemblyInfo.cs create mode 100644 src/Properties/ExcelDna.Build.props create mode 100644 src/RehauSku.Assist-AddIn.dna create mode 100644 src/RehauSku.Assist.csproj create mode 100644 src/RehauSku.Assist.sln create mode 100644 src/Ribbon/RibbonController.cs create mode 100644 src/app.config create mode 100644 src/packages.config diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs deleted file mode 100644 index b0cc560..0000000 --- a/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("RehauSku.Assist")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("RehauSku.Assist")] -[assembly: AssemblyCopyright("Copyright © 2021")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("18a2ff67-0e46-4a86-b872-29f2b3f23adf")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Properties/ExcelDna.Build.props b/Properties/ExcelDna.Build.props deleted file mode 100644 index 1fed993..0000000 --- a/Properties/ExcelDna.Build.props +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - true - - - - - - - - - - - - true - true - - - - 64 - - - - - false - - - - - - true - - - -packed - - - diff --git a/RehauSku.Assist-AddIn.dna b/RehauSku.Assist-AddIn.dna deleted file mode 100644 index 1bef6e1..0000000 --- a/RehauSku.Assist-AddIn.dna +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/RehauSku.Assist.csproj b/RehauSku.Assist.csproj deleted file mode 100644 index e8ba584..0000000 --- a/RehauSku.Assist.csproj +++ /dev/null @@ -1,143 +0,0 @@ - - - - - Debug - AnyCPU - {18A2FF67-0E46-4A86-B872-29F2B3F23ADF} - Library - Properties - RehauSku.Assist - RehauSku.Assist - v4.8 - 512 - true - - - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - packages\AngleSharp.0.16.1\lib\net472\AngleSharp.dll - True - - - packages\ExcelDna.Integration.1.5.0\lib\net452\ExcelDna.Integration.dll - False - - - packages\ExcelDna.IntelliSense.1.5.0\lib\net452\ExcelDna.IntelliSense.dll - - - packages\ExcelDna.Registration.1.5.0\lib\net452\ExcelDna.Registration.dll - True - - - packages\ExcelDna.Interop.14.0.1\lib\Microsoft.Office.Interop.Excel.dll - True - - - packages\ExcelDna.Interop.14.0.1\lib\Microsoft.Vbe.Interop.dll - True - - - packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll - - - packages\ExcelDna.Interop.14.0.1\lib\Office.dll - True - - - - packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll - - - - - - - packages\System.Memory.4.5.4\lib\net461\System.Memory.dll - - - - - packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll - - - - packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll - - - - - packages\System.Text.Encoding.CodePages.6.0.0\lib\net461\System.Text.Encoding.CodePages.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Form - - - SettingsForm.cs - - - - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - \ No newline at end of file diff --git a/RehauSku.Assist.sln b/RehauSku.Assist.sln deleted file mode 100644 index 1fe96c1..0000000 --- a/RehauSku.Assist.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# 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 -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {18A2FF67-0E46-4A86-B872-29F2B3F23ADF}.Debug|Any CPU.ActiveCfg = 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.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {3CF61093-14A6-4A2D-AC13-53EBA2253BAA} - EndGlobalSection -EndGlobal diff --git a/Source/AddIn/AddIn.cs b/Source/AddIn/AddIn.cs deleted file mode 100644 index 67cdcc8..0000000 --- a/Source/AddIn/AddIn.cs +++ /dev/null @@ -1,47 +0,0 @@ -using ExcelDna.Integration; -using ExcelDna.IntelliSense; -using ExcelDna.Registration; -using System.Net.Http; -using System.Runtime.Caching; - - -namespace RehauSku -{ - public enum ResponseOrder - { - Default, - Relevance, - Name, - Price, - Series - } - - public class AddIn : IExcelAddIn - { - public static HttpClient httpClient; - public static MemoryCache memoryCache; - - public void AutoOpen() - { - httpClient = new HttpClient(); - memoryCache = new MemoryCache("RehauSku"); - RegisterFunctions(); - IntelliSenseServer.Install(); - RegistryUtil.Initialize(); - } - - public void AutoClose() - { - IntelliSenseServer.Uninstall(); - RegistryUtil.Uninitialize(); - memoryCache.Dispose(); - } - - void RegisterFunctions() - { - ExcelRegistration.GetExcelFunctions() - .ProcessAsyncRegistrations(nativeAsyncIfAvailable: false) - .RegisterFunctions(); - } - } -} diff --git a/Source/AddIn/Functions.cs b/Source/AddIn/Functions.cs deleted file mode 100644 index 618d17d..0000000 --- a/Source/AddIn/Functions.cs +++ /dev/null @@ -1,56 +0,0 @@ -using ExcelDna.Integration; -using RehauSku.Assistant; - -namespace RehauSku -{ - public class Functions - { - [ExcelFunction(description: "Получение названия первого продукта в поиске")] - public static object RAUNAME([ExcelArgument(Name = "\"Запрос\"", Description = "в свободной форме или ячейка с запросом")] string request) - => MakeRequest(request, ProductField.Name); - - [ExcelFunction(Description = "Получение артикула первого продукта в поиске")] - public static object RAUSKU([ExcelArgument(Name = "\"Запрос\"", Description = "в свободной форме или ячейка с запросом")] string request) - => MakeRequest(request, ProductField.Id); - - [ExcelFunction(Description = "Получение цены первого продукта в поиске")] - public static object RAUPRICE([ExcelArgument(Name = "\"Запрос\"", Description = "в свободной форме или ячейка с запросом")] string request) - => MakeRequest(request, ProductField.Price); - - private static object MakeRequest(string request, ProductField field) - { - object result; - - if (request.IsCached()) - result = request.GetFromCache(); - - else - { - result = ExcelAsyncUtil.Run("Request", request, delegate - { - return request.RequestAndCache().GetAwaiter().GetResult(); - }); - } - - if (result == null) - return "Не найдено :("; - - if (result.Equals(ExcelError.ExcelErrorNA)) - return "Загрузка..."; - - IProduct product = result as IProduct; - - switch (field) - { - case ProductField.Name: - return product.Name; - case ProductField.Id: - return product.Id; - case ProductField.Price: - return double.Parse(product.Price, System.Globalization.CultureInfo.InvariantCulture); - default: - return null; - } - } - } -} \ No newline at end of file diff --git a/Source/AddIn/MemoryCacheUtil.cs b/Source/AddIn/MemoryCacheUtil.cs deleted file mode 100644 index 1d42e14..0000000 --- a/Source/AddIn/MemoryCacheUtil.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Runtime.Caching; -using System.Threading.Tasks; -using RehauSku.Assistant; - -namespace RehauSku -{ - static class MemoryCacheUtil - { - public static bool IsCached(this string request) - { - return AddIn.memoryCache.Contains(request); - } - - public static IProduct GetFromCache(this string request) - { - return AddIn.memoryCache[request] as IProduct; - } - - public static async Task RequestAndCache(this string request) - { - IProduct product = await SkuAssist.GetProductAsync(request); - - if (product == null) - return null; - - AddIn.memoryCache.Add(request, product, DateTime.Now.AddMinutes(10)); - return product; - } - - public static void ClearCache() - { - AddIn.memoryCache.Dispose(); - AddIn.memoryCache = new MemoryCache("RehauSku"); - } - } -} \ No newline at end of file diff --git a/Source/AddIn/RegistryUtil.cs b/Source/AddIn/RegistryUtil.cs deleted file mode 100644 index 40d0ec2..0000000 --- a/Source/AddIn/RegistryUtil.cs +++ /dev/null @@ -1,76 +0,0 @@ -using Microsoft.Win32; -using System.IO; -using RehauSku.Forms; -using System.Windows.Forms; - -namespace RehauSku -{ - 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 void Uninitialize() - { - _RootKey.Close(); - - } - - public static bool IsPriceListPathEmpty() - { - return string.IsNullOrEmpty(_priceListPath); - } - - public static string PriceListPath - { - get - { - if (IsPriceListPathEmpty() || !File.Exists(_priceListPath)) - { - MessageBox.Show("Прайс-лист отсутствует или неверный файл прайс-листа", "Укажите файл прайс-листа", MessageBoxButtons.OK, MessageBoxIcon.Warning); - string fileName = Dialog.GetFilePath(); - _priceListPath = fileName; - _RootKey.SetValue("PriceListPath", fileName); - return _priceListPath; - } - - else - { - return _priceListPath; - } - } - - set - { - _priceListPath = value; - _RootKey.SetValue("PriceListPath", value); - } - } - - public static ResponseOrder StoreResponseOrder - { - get - { - if (_storeResponseOrder == null) - { - _RootKey.SetValue("StoreResponseOrder", (int)ResponseOrder.Default); - _storeResponseOrder = (int)ResponseOrder.Default; - return (ResponseOrder)_storeResponseOrder.Value; - } - - else - { - return (ResponseOrder)_storeResponseOrder.Value; - } - } - } - } -} diff --git a/Source/Assistant/HttpClientUtil.cs b/Source/Assistant/HttpClientUtil.cs deleted file mode 100644 index 316ea07..0000000 --- a/Source/Assistant/HttpClientUtil.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using System.Net; -using System.Net.Http; -using System.Threading.Tasks; - -namespace RehauSku.Assistant -{ - static class HttpClientUtil - { - private static HttpClient _httpClient = AddIn.httpClient; - - public async static Task GetContentByRequest(string request) - { - Uri uri = request.ConvertToUri(); - - ServicePointManager.SecurityProtocol = - SecurityProtocolType.Tls12 | - SecurityProtocolType.Tls11 | - SecurityProtocolType.Tls; - - return await _httpClient.GetStringAsync(uri); - } - - private static Uri ConvertToUri(this string request) - { - UriBuilder baseUri = new UriBuilder("https", "shop-rehau.ru"); - - baseUri.Path = "/catalogsearch/result/index/"; - string cleanedRequest = request.CleanRequest(); - - switch (RegistryUtil.StoreResponseOrder) - { - case ResponseOrder.Relevance: - baseUri.Query = "dir=asc&order=relevance&q=" + cleanedRequest; - break; - case ResponseOrder.Name: - baseUri.Query = "dir=asc&order=name&q=" + cleanedRequest; - break; - case ResponseOrder.Price: - baseUri.Query = "dir=asc&order=price&q=" + cleanedRequest; - break; - case ResponseOrder.Series: - baseUri.Query = "dir=asc&order=sch_product_series&q=" + cleanedRequest; - break; - default: - baseUri.Query = "q=" + cleanedRequest; - break; - } - - return baseUri.Uri; - } - } -} \ No newline at end of file diff --git a/Source/Assistant/IProduct.cs b/Source/Assistant/IProduct.cs deleted file mode 100644 index 9494eeb..0000000 --- a/Source/Assistant/IProduct.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace RehauSku.Assistant -{ - interface IProduct - { - string Id { get; } - string Name { get; } - string Price { get; } - } -} diff --git a/Source/Assistant/ParseUtil.cs b/Source/Assistant/ParseUtil.cs deleted file mode 100644 index a93c658..0000000 --- a/Source/Assistant/ParseUtil.cs +++ /dev/null @@ -1,44 +0,0 @@ -using AngleSharp; -using AngleSharp.Dom; -using Newtonsoft.Json; -using System.Linq; -using System.Threading.Tasks; - -namespace RehauSku.Assistant -{ - static class ParseUtil - { - public async static Task ContentToDocAsync(string content) - { - IConfiguration config = Configuration.Default; - IBrowsingContext context = BrowsingContext.New(config); - - return await context.OpenAsync(req => req.Content(content)); - } - - public static IProduct GetProduct(IDocument document) - { - string script = document - .Scripts - .Where(s => s.InnerHtml.Contains("dataLayer")) - .FirstOrDefault() - .InnerHtml; - - string json = script - .Substring(script.IndexOf("push(") + 5) - .TrimEnd(new[] { ')', ';', '\n', ' ' }); - - if (!json.Contains("impressions")) - return null; - - StoreResponce storeResponse = JsonConvert.DeserializeObject(json); - IProduct product = storeResponse - .Ecommerce - .Impressions - .Where(p => p.Id.IsRehauSku()) - .FirstOrDefault(); - - return product; - } - } -} \ No newline at end of file diff --git a/Source/Assistant/RequestModifier.cs b/Source/Assistant/RequestModifier.cs deleted file mode 100644 index 9f42e71..0000000 --- a/Source/Assistant/RequestModifier.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; - -namespace RehauSku.Assistant -{ - public static class RequestModifier - { - public static string CleanRequest(this string input) - { - string replace = new StringBuilder(input) - .Replace("+", " plus ") - .Replace("РХ", "") - .Replace("º", " ") - .Replace(".", " ") - .Replace("Ø", " ") - .ToString(); - - return replace._tPieceNormalize(); - } - - private static string _tPieceNormalize(this string line) - { - Regex regex = new Regex(@"\d{2}.\d{2}.\d{2}"); - - if (!regex.IsMatch(line)) - return line; - - string match = regex.Match(line).Value; - - int side = int.Parse($"{match[3]}{match[4]}"); - int[] endFaces = new int[] - { - int.Parse($"{match[0]}{match[1]}"), - int.Parse($"{match[6]}{match[7]}") - }; - - if (new[] { endFaces[0], endFaces[1], side }.Any(x => x == 45 || x == 90 || x == 87)) - return line; - - List additions = new List(); - - if (endFaces.All(x => x < side)) - additions.Add("увеличенный боковой"); - - else - { - if (new[] { endFaces[0], endFaces[1], side }.Distinct().Count() == 1) - additions.Add("равнопроходной"); - else - additions.Add("уменьшенный"); - - if (endFaces.Any(x => x > side)) - additions.Add("боковой"); - - if (endFaces[0] != endFaces[1]) - additions.Add("торцевой"); - } - - string piece = $" {endFaces.Max()}-{side}-{endFaces.Min()} "; - string modifiedMatch = string.Join(" ", additions) + piece; - - return line.Replace(match, modifiedMatch); - } - } -} \ No newline at end of file diff --git a/Source/Assistant/SkuAssist.cs b/Source/Assistant/SkuAssist.cs deleted file mode 100644 index 6c68288..0000000 --- a/Source/Assistant/SkuAssist.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Threading.Tasks; - -namespace RehauSku.Assistant -{ - public enum ProductField - { - Name, - Id, - Price - } - - static class SkuAssist - { - public static async Task GetProductAsync(string request) - { - var content = await HttpClientUtil.GetContentByRequest(request); - var document = await ParseUtil.ContentToDocAsync(content); - - return ParseUtil.GetProduct(document); - } - } -} \ No newline at end of file diff --git a/Source/Assistant/SkuExtensions.cs b/Source/Assistant/SkuExtensions.cs deleted file mode 100644 index e39807b..0000000 --- a/Source/Assistant/SkuExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Text.RegularExpressions; - -namespace RehauSku.Assistant -{ - static class SkuExtensions - { - public static bool IsRehauSku(this string line) - { - return Regex.IsMatch(line, @"^[1]\d{6}[1]\d{3}$"); - } - } -} \ No newline at end of file diff --git a/Source/Assistant/StoreResponse.cs b/Source/Assistant/StoreResponse.cs deleted file mode 100644 index 8e1759d..0000000 --- a/Source/Assistant/StoreResponse.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Collections.Generic; - -namespace RehauSku.Assistant -{ - public class StoreResponce - { - public Ecommerce Ecommerce { get; set; } - } - - public class Ecommerce - { - public List Impressions { get; set; } - } - - public class Product : IProduct - { - public string Id { get; set; } - public string Name { get; set; } - public string Price { get; set; } - } -} \ No newline at end of file diff --git a/Source/Forms/Dialog.cs b/Source/Forms/Dialog.cs deleted file mode 100644 index 170cc81..0000000 --- a/Source/Forms/Dialog.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.Collections.Generic; -using System.Windows.Forms; - -namespace RehauSku.Forms -{ - static class Dialog - { - public static string GetFilePath() - { - string filePath = string.Empty; - - using (OpenFileDialog dialog = new OpenFileDialog()) - { - dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm"; - - if (dialog.ShowDialog() == DialogResult.OK) - { - filePath = dialog.FileName; - } - } - - return filePath; - } - - public static string[] GetMultiplyFiles() - { - List fileNames = new List(); - - using (OpenFileDialog dialog = new OpenFileDialog()) - { - dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm"; - dialog.Multiselect = true; - - if (dialog.ShowDialog() == DialogResult.OK) - { - foreach (string file in dialog.FileNames) - { - fileNames.Add(file); - } - } - } - - return fileNames.ToArray(); - } - } -} diff --git a/Source/Forms/SettingsForm.Designer.cs b/Source/Forms/SettingsForm.Designer.cs deleted file mode 100644 index 669406e..0000000 --- a/Source/Forms/SettingsForm.Designer.cs +++ /dev/null @@ -1,46 +0,0 @@ -namespace RehauSku.Forms -{ - partial class SettingsForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.SuspendLayout(); - // - // SettingsForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Name = "SettingsForm"; - this.Text = "SettingsForm"; - this.ResumeLayout(false); - - } - - #endregion - } -} \ No newline at end of file diff --git a/Source/Forms/SettingsForm.cs b/Source/Forms/SettingsForm.cs deleted file mode 100644 index 4dffadb..0000000 --- a/Source/Forms/SettingsForm.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace RehauSku.Forms -{ - public partial class SettingsForm : Form - { - public SettingsForm() - { - InitializeComponent(); - } - - } -} diff --git a/Source/Forms/SettingsForm.resx b/Source/Forms/SettingsForm.resx deleted file mode 100644 index 1af7de1..0000000 --- a/Source/Forms/SettingsForm.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/Source/PriceListTools/ExportTool.cs b/Source/PriceListTools/ExportTool.cs deleted file mode 100644 index 0a28bf3..0000000 --- a/Source/PriceListTools/ExportTool.cs +++ /dev/null @@ -1,115 +0,0 @@ -using ExcelDna.Integration; -using Microsoft.Office.Interop.Excel; -using RehauSku.Assistant; -using System; -using System.Collections.Generic; - -namespace RehauSku.PriceListTools -{ - class ExportTool : IDisposable - { - private Application ExcelApp; - private Dictionary SkuAmount { get; set; } - private Range Selection { get; set; } - - public ExportTool() - { - this.ExcelApp = (Application)ExcelDnaUtil.Application; - Selection = ExcelApp.Selection; - - if (IsRangeValid()) - _FillSkuAmountDict(); - } - - public bool IsRangeValid() - { - return Selection != null && - Selection.Columns.Count == 2; - } - - private void _FillSkuAmountDict() - { - object[,] cells = Selection.Value2; - SkuAmount = new Dictionary(); - int rowsCount = Selection.Rows.Count; - - for (int row = 1; row <= rowsCount; row++) - { - if (cells[row, 1] == null || cells[row, 2] == null) - continue; - - string sku = null; - double? amount = null; - - for (int column = 1; column <= 2; column++) - { - object current = cells[row, column]; - - if (current.ToString().IsRehauSku()) - { - sku = current.ToString(); - } - - else if (current.GetType() == typeof(string) - && double.TryParse(current.ToString(), out _)) - { - amount = double.Parse((string)current); - } - - else if (current.GetType() == typeof(double)) - { - amount = (double)current; - } - } - - if (sku == null || amount == null) - continue; - - if (SkuAmount.ContainsKey(sku)) - SkuAmount[sku] += amount.Value; - else - SkuAmount.Add(sku, amount.Value); - } - } - - public void ExportToNewFile() - { - if (SkuAmount.Count < 1) - { - return; - } - - string exportFile = PriceListUtil.CreateNewExportFile(); - Workbook wb = ExcelApp.Workbooks.Open(exportFile); - - 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() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - - } - } -} - diff --git a/Source/PriceListTools/MergeTool.cs b/Source/PriceListTools/MergeTool.cs deleted file mode 100644 index 6b0644d..0000000 --- a/Source/PriceListTools/MergeTool.cs +++ /dev/null @@ -1,88 +0,0 @@ -using ExcelDna.Integration; -using Microsoft.Office.Interop.Excel; -using System; -using System.Collections.Generic; - -namespace RehauSku.PriceListTools -{ - class MergeTool : IDisposable - { - private Application ExcelApp; - private Dictionary SkuAmount { get; set; } - - public MergeTool() - { - this.ExcelApp = (Application)ExcelDnaUtil.Application; - this.SkuAmount = new Dictionary(); - } - - public void AddSkuAmountToDict(string[] files) - { - ExcelApp.ScreenUpdating = false; - foreach (string file in files) - { - Workbook wb = ExcelApp.Workbooks.Open(file); - - try - { - PriceList priceList = new PriceList(wb); - SkuAmount.AddValues(priceList); - } - - 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; - - 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() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - - } - } -} diff --git a/Source/PriceListTools/PriceList.cs b/Source/PriceListTools/PriceList.cs deleted file mode 100644 index 1460c07..0000000 --- a/Source/PriceListTools/PriceList.cs +++ /dev/null @@ -1,87 +0,0 @@ -using Microsoft.Office.Interop.Excel; -using System.Collections.Generic; - -namespace RehauSku.PriceListTools -{ - class PriceList - { - public readonly Workbook Workbook; - public readonly PriceListSheet OfferSheet; - public readonly PriceListSheet ActiveSheet; - - private const string _amountHeader = "Кол-во"; - private const string _skuHeader = "Актуальный материал"; - private const string _offerSheetHeader = "КП"; - - public PriceList(Workbook workbook) - { - Workbook = workbook; - OfferSheet = new PriceListSheet(workbook.Sheets[_offerSheetHeader]); - - Worksheet active = workbook.ActiveSheet; - - if (active.Name == _offerSheetHeader) - ActiveSheet = OfferSheet; - - else - ActiveSheet = new PriceListSheet(active); - } - - public bool IsValid() - { - return OfferSheet.IsValid() && - ActiveSheet.IsValid(); - } - - public void Fill(Dictionary values) - { - Worksheet ws = OfferSheet.sheet; - ws.Activate(); - - int amountColumn = OfferSheet.amountColumn.Value; - int skuColumn = OfferSheet.skuColumn.Value; - - foreach (KeyValuePair kvp in values) - { - Range cell = ws.Columns[skuColumn].Find(kvp.Key); - ws.Cells[cell.Row, amountColumn].Value = kvp.Value; - } - - AutoFilter filter = ws.AutoFilter; - int firstFilterColumn = filter.Range.Column; - - filter.Range.AutoFilter(amountColumn - firstFilterColumn + 1, "<>"); - ws.Range["A1"].Activate(); - } - - public class PriceListSheet - { - public readonly Worksheet sheet; - public readonly int? headerRow; - public readonly int? amountColumn; - public readonly int? skuColumn; - public object[,] amountCells; - public object[,] skuCells; - - public PriceListSheet(Worksheet sheet) - { - this.sheet = sheet; - headerRow = sheet.Cells.Find(_amountHeader).Row; - amountColumn = sheet.Cells.Find(_amountHeader).Column; - skuColumn = sheet.Cells.Find(_skuHeader).Column; - - amountCells = sheet.Columns[amountColumn].Value2; - skuCells = sheet.Columns[skuColumn].Value2; - } - - public bool IsValid() - { - return sheet != null && - headerRow != null && - amountColumn != null && - skuColumn != null; - } - } - } -} - diff --git a/Source/PriceListTools/PriceListUtil.cs b/Source/PriceListTools/PriceListUtil.cs deleted file mode 100644 index 14797d9..0000000 --- a/Source/PriceListTools/PriceListUtil.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System.Collections.Generic; -using System.IO; - -namespace RehauSku.PriceListTools -{ - static class PriceListUtil - { - public static string CreateNewExportFile() - { - string fileExtension = Path.GetExtension(RegistryUtil.PriceListPath); - string path = Path.GetTempFileName() + fileExtension; - - File.Copy(RegistryUtil.PriceListPath, path); - return path; - } - - public static void AddValues(this Dictionary SkuAmount, PriceList priceList) - { - object[,] amountCells = priceList.ActiveSheet.amountCells; - object[,] skuCells = priceList.ActiveSheet.skuCells; - - for (int row = priceList.ActiveSheet.headerRow.Value + 1; row < amountCells.GetLength(0); row++) - { - object amount = amountCells[row, 1]; - object sku = skuCells[row, 1]; - - if (amount != null && (double)amount != 0) - { - if (SkuAmount.ContainsKey(sku.ToString())) - { - SkuAmount[sku.ToString()] += (double)amount; - } - - else - SkuAmount.Add(sku.ToString(), (double)amount); - } - } - } - } -} - diff --git a/Source/Ribbon/RibbonController.cs b/Source/Ribbon/RibbonController.cs deleted file mode 100644 index df6f327..0000000 --- a/Source/Ribbon/RibbonController.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System.Runtime.InteropServices; -using System.Windows.Forms; -using ExcelDna.Integration.CustomUI; -using RehauSku.PriceListTools; -using RehauSku.Forms; - -namespace RehauSku.Ribbon -{ - [ComVisible(true)] - public class RibbonController : ExcelRibbon - { - public override string GetCustomUI(string RibbonID) - { - return @" - - - - - -