diff options
Diffstat (limited to 'src/AddIn')
-rw-r--r-- | src/AddIn/AddIn.cs | 30 | ||||
-rw-r--r-- | src/AddIn/EventsUtil.cs | 33 | ||||
-rw-r--r-- | src/AddIn/Functions.cs | 31 | ||||
-rw-r--r-- | src/AddIn/RegistryUtil.cs | 73 | ||||
-rw-r--r-- | src/AddIn/RhDatabaseClient.cs | 45 | ||||
-rw-r--r-- | src/AddIn/Sku.cs | 67 | ||||
-rw-r--r-- | src/AddIn/SkuExtensions.cs | 12 | ||||
-rw-r--r-- | src/AddIn/WorksheetExtensions.cs | 41 |
8 files changed, 0 insertions, 332 deletions
diff --git a/src/AddIn/AddIn.cs b/src/AddIn/AddIn.cs deleted file mode 100644 index b8bfd21..0000000 --- a/src/AddIn/AddIn.cs +++ /dev/null @@ -1,30 +0,0 @@ -using ExcelDna.Integration; -using ExcelDna.IntelliSense; -using Microsoft.Office.Interop.Excel; -using System.Net.Http; -using System.Runtime.Caching; - -namespace RhSolutions -{ - class AddIn : IExcelAddIn - { - public static Application Excel; - public static HttpClient httpClient; - - public void AutoOpen() - { - Excel = (Application)ExcelDnaUtil.Application; - httpClient = new HttpClient(); - IntelliSenseServer.Install(); - RegistryUtil.Initialize(); - EventsUtil.Initialize(); - } - - public void AutoClose() - { - IntelliSenseServer.Uninstall(); - RegistryUtil.Uninitialize(); - EventsUtil.Uninitialize(); - } - } -} diff --git a/src/AddIn/EventsUtil.cs b/src/AddIn/EventsUtil.cs deleted file mode 100644 index 3ceccfd..0000000 --- a/src/AddIn/EventsUtil.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.Office.Interop.Excel; - -namespace RhSolutions -{ - internal static class EventsUtil - { - private static readonly Application Excel = AddIn.Excel; - - public static void Initialize() - { - Excel.SheetSelectionChange += RefreshExportButton; - Excel.SheetActivate += RefreshConvertButton; - Excel.WorkbookActivate += RefreshConvertButton; - } - - public static void Uninitialize() - { - Excel.SheetSelectionChange -= RefreshExportButton; - Excel.SheetActivate -= RefreshConvertButton; - Excel.WorkbookActivate -= RefreshConvertButton; - } - - private static void RefreshConvertButton(object sh) - { - Interface.RibbonController.RefreshControl("convert"); - } - - private static void RefreshExportButton(object sh, Range target) - { - Interface.RibbonController.RefreshControl("export"); - } - } -} diff --git a/src/AddIn/Functions.cs b/src/AddIn/Functions.cs deleted file mode 100644 index 5bcfd45..0000000 --- a/src/AddIn/Functions.cs +++ /dev/null @@ -1,31 +0,0 @@ -using ExcelDna.Integration; -using System; - -namespace RhSolutions -{ - public class Functions - { - [ExcelFunction(Description = "Запрос в удаленную базу данных")] - public static object RHSOLUTIONS([ExcelArgument(Name = "Запрос")] string line) - { - object result; - - result = ExcelAsyncUtil.Run("Database request", line, delegate - { - return RhDatabaseClient.GetProduct(line).GetAwaiter().GetResult(); - }); - - if (result == null) - { - return ExcelError.ExcelErrorNA; - } - - if (result.Equals(ExcelError.ExcelErrorNA)) - { - return "Загрузка..."; - } - - return result; - } - } -}
\ No newline at end of file diff --git a/src/AddIn/RegistryUtil.cs b/src/AddIn/RegistryUtil.cs deleted file mode 100644 index e848462..0000000 --- a/src/AddIn/RegistryUtil.cs +++ /dev/null @@ -1,73 +0,0 @@ -using Microsoft.Win32; -using RhSolutions.Interface; -using System; -using System.IO; -using System.Windows.Forms; - -namespace RhSolutions -{ - static class RegistryUtil - { - private static string priceListPath; - private static RegistryKey RootKey { get; set; } - - public static void Initialize() - { - RootKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\REHAU\SkuAssist"); - priceListPath = RootKey.GetValue("PriceListPath") as string; - } - - public static void Uninitialize() - { - RootKey.Close(); - } - - public static string PriceListPath - { - get - { - if (string.IsNullOrEmpty(priceListPath) || !File.Exists(priceListPath)) - { - DialogResult result = MessageBox.Show("Прайс-лист отсутствует или неверный файл шаблона прайс-листа. " + - "Укажите файл шаблона прайс-листа.", - "Нет файла шаблона", - MessageBoxButtons.OK, MessageBoxIcon.Warning); - - if (result == DialogResult.OK) - { - string fileName = Dialog.GetFilePath(); - - if (string.IsNullOrEmpty(fileName)) - { - throw new Exception("Нет файла шаблона"); - } - - priceListPath = fileName; - RootKey.SetValue("PriceListPath", fileName); - return priceListPath; - } - - else - throw new Exception("Нет файла шаблона"); - } - - else - { - return priceListPath; - } - } - - set - { - priceListPath = value; - RootKey.SetValue("PriceListPath", value); - RibbonController.RefreshControl("setPriceList"); - } - } - - public static string GetPriceListName() - { - return Path.GetFileName(priceListPath); - } - } -} diff --git a/src/AddIn/RhDatabaseClient.cs b/src/AddIn/RhDatabaseClient.cs deleted file mode 100644 index 3a2de5c..0000000 --- a/src/AddIn/RhDatabaseClient.cs +++ /dev/null @@ -1,45 +0,0 @@ -using Newtonsoft.Json; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Threading.Tasks; - -namespace RhSolutions -{ - public static class RhDatabaseClient - { - private static HttpClient httpClient = AddIn.httpClient; - - public static async Task<object> GetProduct(string line) - { - string request = @"https://rh.cebotari.ru/api/search?query=" + line; - - ServicePointManager.SecurityProtocol = - SecurityProtocolType.Tls12 | - SecurityProtocolType.Tls11 | - SecurityProtocolType.Tls; - - string response = await httpClient.GetStringAsync(request); - - var products = JsonConvert.DeserializeObject<IEnumerable<DbProduct>>(response); - - var product = products.FirstOrDefault(); - - if (product == null) - { - return null; - } - else - { - return $"{product.productSku} {product.name}"; - } - } - - private class DbProduct - { - public string productSku { get; set; } - public string name { get; set; } - } - } -}
\ No newline at end of file diff --git a/src/AddIn/Sku.cs b/src/AddIn/Sku.cs deleted file mode 100644 index aaf5937..0000000 --- a/src/AddIn/Sku.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System.Text.RegularExpressions; - -namespace RhSolutions -{ - internal class Sku - { - public string Article { get; private set; } - public string Variant { get; private set; } - - public Sku(string article, string variant) - { - Article = article; - Variant = variant; - } - - public static bool TryParse(string line, out Sku rehauSku) - { - Match match; - match = Regex.Match(line, @"\b[1]\d{6}[1]\d{3}\b"); - if (match.Success) - { - string sku = match.Value.Substring(1, 6); - string variant = match.Value.Substring(8, 3); - rehauSku = new Sku(sku, variant); - return true; - } - - match = Regex.Match(line, @"\b\d{6}\D\d{3}\b"); - if (match.Success) - { - string sku = match.Value.Substring(0, 6); - string variant = match.Value.Substring(7, 3); - rehauSku = new Sku(sku, variant); - return true; - } - - match = Regex.Match(line, @"\b\d{9}\b"); - if (match.Success) - { - string sku = match.Value.Substring(0, 6); - string variant = match.Value.Substring(6, 3); - rehauSku = new Sku(sku, variant); - return true; - } - - match = Regex.Match(line, @"\b\d{6}\b"); - if (match.Success) - { - string sku = match.Value.Substring(0, 6); - string variant = "001"; - rehauSku = new Sku(sku, variant); - return true; - } - - else - { - rehauSku = null; - return false; - } - } - - public override string ToString() - { - return $"1{Article}1{Variant}"; - } - } -}
\ No newline at end of file diff --git a/src/AddIn/SkuExtensions.cs b/src/AddIn/SkuExtensions.cs deleted file mode 100644 index 2e97406..0000000 --- a/src/AddIn/SkuExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Text.RegularExpressions; - -namespace RhSolutions -{ - 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/src/AddIn/WorksheetExtensions.cs b/src/AddIn/WorksheetExtensions.cs deleted file mode 100644 index b07e2c1..0000000 --- a/src/AddIn/WorksheetExtensions.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Microsoft.Office.Interop.Excel; -using RhSolutions.PriceListTools; -using System.Linq; - -namespace RhSolutions -{ - public static class WorksheetExtensions - { - public static bool IsRehauSource(this Worksheet worksheet) - { - Range amountCell; - Range skuCell; - Range groupCell; - Range nameCell; - - Range[] cells = new[] - { - amountCell = worksheet.Cells.Find(PriceListHeaders.Amount), - skuCell = worksheet.Cells.Find(PriceListHeaders.Sku), - groupCell = worksheet.Cells.Find(PriceListHeaders.Group), - nameCell = worksheet.Cells.Find(PriceListHeaders.Name) - }; - - return cells.All(x => x != null); - } - - public static void AddValue(this Range range, double value) - { - if (range.Value2 == null) - { - range.Value2 = value; - } - - else - { - range.Value2 += value; - } - } - } -} - |