From 4f448f203471a19a1444555a895f503515ad2fda Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 22 Mar 2023 08:36:13 +0300 Subject: Add basic test --- src/AddIn/Functions.cs | 56 ----------- src/AddIn/RhSolutionsAddIn.cs | 35 ------- src/Controllers/CombineTool.cs | 57 ----------- src/Controllers/ConvertTool.cs | 30 ------ src/Controllers/ExportTool.cs | 101 ------------------- src/Controllers/MergeTool.cs | 46 --------- src/Controllers/RibbonController.cs | 139 -------------------------- src/Controllers/ToolBase.cs | 190 ------------------------------------ src/Models/Dialog.cs | 40 -------- src/Models/PriceListBase.cs | 15 --- src/Models/PriceListHeaders.cs | 11 --- src/Models/Product.cs | 35 ------- src/Models/ProgressBar.cs | 22 ----- src/Models/ResultBar.cs | 45 --------- src/Models/SourcePriceList.cs | 116 ---------------------- src/Models/StatusbarBase.cs | 18 ---- src/Models/TargetPriceList.cs | 41 -------- src/Models/WorksheetExtensions.cs | 41 -------- src/Properties/AssemblyInfo.cs | 37 ------- src/Properties/ExcelDna.Build.props | 86 ---------------- src/Properties/launchSettings.json | 9 -- src/RhSolutions-AddIn.dna | 26 ----- src/RhSolutions.csproj | 23 ----- src/Services/EventsUtil.cs | 35 ------- src/Services/RegistryUtil.cs | 74 -------------- src/Services/RhDatabaseClient.cs | 52 ---------- src/app.config | 19 ---- 27 files changed, 1399 deletions(-) delete mode 100644 src/AddIn/Functions.cs delete mode 100644 src/AddIn/RhSolutionsAddIn.cs delete mode 100644 src/Controllers/CombineTool.cs delete mode 100644 src/Controllers/ConvertTool.cs delete mode 100644 src/Controllers/ExportTool.cs delete mode 100644 src/Controllers/MergeTool.cs delete mode 100644 src/Controllers/RibbonController.cs delete mode 100644 src/Controllers/ToolBase.cs delete mode 100644 src/Models/Dialog.cs delete mode 100644 src/Models/PriceListBase.cs delete mode 100644 src/Models/PriceListHeaders.cs delete mode 100644 src/Models/Product.cs delete mode 100644 src/Models/ProgressBar.cs delete mode 100644 src/Models/ResultBar.cs delete mode 100644 src/Models/SourcePriceList.cs delete mode 100644 src/Models/StatusbarBase.cs delete mode 100644 src/Models/TargetPriceList.cs delete mode 100644 src/Models/WorksheetExtensions.cs delete mode 100644 src/Properties/AssemblyInfo.cs delete mode 100644 src/Properties/ExcelDna.Build.props delete mode 100644 src/Properties/launchSettings.json delete mode 100644 src/RhSolutions-AddIn.dna delete mode 100644 src/RhSolutions.csproj delete mode 100644 src/Services/EventsUtil.cs delete mode 100644 src/Services/RegistryUtil.cs delete mode 100644 src/Services/RhDatabaseClient.cs delete mode 100644 src/app.config (limited to 'src') diff --git a/src/AddIn/Functions.cs b/src/AddIn/Functions.cs deleted file mode 100644 index 6a7fc54..0000000 --- a/src/AddIn/Functions.cs +++ /dev/null @@ -1,56 +0,0 @@ -using ExcelDna.Integration; -using RhSolutions.Models; -using RhSolutions.Services; -using System.Linq; - -namespace RhSolutions.AddIn -{ - 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(); - }); - - string parsedSku = Sku.TryParse(line, out var skus) - ? skus.First().ToString() : string.Empty; - - if (result == null) - { - if (string.IsNullOrEmpty(parsedSku)) - { - return ExcelError.ExcelErrorNA; - } - else - { - return skus.First().ToString(); - } - } - - if (result.Equals(ExcelError.ExcelErrorNA)) - { - if (string.IsNullOrEmpty(parsedSku)) - { - return "Загрузка..."; - } - else - { - return skus.First().ToString(); - } - } - - return result; - } - - [ExcelFunction] - public static void _ResetStatusBar() - { - RhSolutionsAddIn.Excel.StatusBar = false; - } - } -} \ No newline at end of file diff --git a/src/AddIn/RhSolutionsAddIn.cs b/src/AddIn/RhSolutionsAddIn.cs deleted file mode 100644 index a4c6019..0000000 --- a/src/AddIn/RhSolutionsAddIn.cs +++ /dev/null @@ -1,35 +0,0 @@ -using ExcelDna.Integration; -using ExcelDna.IntelliSense; -using Microsoft.Office.Interop.Excel; -using RhSolutions.Services; -using System.Net; -using System.Net.Http; - -namespace RhSolutions.AddIn -{ - class RhSolutionsAddIn : IExcelAddIn - { - public static Application Excel { get; private set; } - public static HttpClient HttpClient { get; private set; } - - public void AutoOpen() - { - Excel = (Application)ExcelDnaUtil.Application; - HttpClient = new HttpClient(); - IntelliSenseServer.Install(); - RegistryUtil.Initialize(); - EventsUtil.Initialize(); - - ServicePointManager.SecurityProtocol = - SecurityProtocolType.Tls12; - } - - public void AutoClose() - { - IntelliSenseServer.Uninstall(); - RegistryUtil.Uninitialize(); - EventsUtil.Uninitialize(); - HttpClient.Dispose(); - } - } -} diff --git a/src/Controllers/CombineTool.cs b/src/Controllers/CombineTool.cs deleted file mode 100644 index 4d84d44..0000000 --- a/src/Controllers/CombineTool.cs +++ /dev/null @@ -1,57 +0,0 @@ -using Microsoft.Office.Interop.Excel; -using RhSolutions.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using Dialog = RhSolutions.Models.Dialog; -using Range = Microsoft.Office.Interop.Excel.Range; - -namespace RhSolutions.Controllers -{ - internal class CombineTool : ToolBase - { - private List SourceFiles { get; set; } - - public CombineTool() - { - string[] files = Dialog.GetMultiplyFiles(); - - if (files != null) - { - SourceFiles = SourcePriceList.GetSourceLists(files); - } - - else - { - throw new Exception("Не выбраны файлы"); - } - } - - public override void FillTarget() - { - using (ProgressBar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(file => file.PositionAmount.Count))) - using (ResultBar = new ResultBar()) - { - foreach (SourcePriceList source in SourceFiles) - { - TargetFile.Sheet.Columns[TargetFile.AmountCell.Column] - .EntireColumn - .Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow); - - Range newColumnHeader = TargetFile.Sheet.Cells[TargetFile.AmountCell.Row, TargetFile.AmountCell.Column - 1]; - newColumnHeader.Value2 = $"{source.Name}"; - newColumnHeader.WrapText = true; - - foreach (var kvp in source.PositionAmount) - { - FillPositionAmountToColumns(kvp, TargetFile.AmountCell.Column - 1, TargetFile.AmountCell.Column); - ProgressBar.Update(); - } - } - - FilterByAmount(); - ResultBar.Update(); - } - } - } -} diff --git a/src/Controllers/ConvertTool.cs b/src/Controllers/ConvertTool.cs deleted file mode 100644 index 5b2cd4d..0000000 --- a/src/Controllers/ConvertTool.cs +++ /dev/null @@ -1,30 +0,0 @@ -using RhSolutions.Models; - -namespace RhSolutions.Controllers -{ - internal class ConvertTool : ToolBase - { - private SourcePriceList Current { get; set; } - - public ConvertTool() - { - Current = new SourcePriceList(ExcelApp.ActiveWorkbook); - } - - public override void FillTarget() - { - using (ProgressBar = new ProgressBar("Заполняю строки...", Current.PositionAmount.Count)) - using (ResultBar = new ResultBar()) - { - foreach (var kvp in Current.PositionAmount) - { - FillPositionAmountToColumns(kvp, TargetFile.AmountCell.Column); - ProgressBar.Update(); - } - - FilterByAmount(); - ResultBar.Update(); - } - } - } -} \ No newline at end of file diff --git a/src/Controllers/ExportTool.cs b/src/Controllers/ExportTool.cs deleted file mode 100644 index e2bbde4..0000000 --- a/src/Controllers/ExportTool.cs +++ /dev/null @@ -1,101 +0,0 @@ -using Microsoft.Office.Interop.Excel; -using System; -using System.Collections.Generic; -using RhSolutions.Models; -using System.Linq; -using Range = Microsoft.Office.Interop.Excel.Range; - -namespace RhSolutions.Controllers -{ - internal class ExportTool : ToolBase - { - private Dictionary PositionAmount; - private readonly Range Selection; - - public ExportTool() - { - Selection = ExcelApp.Selection; - GetSelected(); - - if (PositionAmount.Count == 0) - { - throw new Exception("В выделенном диапазоне не найдены позиции для экспорта"); - } - } - - public override void FillTarget() - { - using (ProgressBar = new ProgressBar("Заполняю строки...", PositionAmount.Count)) - using (ResultBar = new ResultBar()) - { - foreach (var kvp in PositionAmount) - { - FillPositionAmountToColumns(kvp, TargetFile.AmountCell.Column); - ProgressBar.Update(); - } - - FilterByAmount(); - ResultBar.Update(); - } - } - - private void GetSelected() - { - object[,] cells = Selection.Value2; - PositionAmount = 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 (Sku.TryParse(current.ToString(), out var rauSku)) - { - sku = rauSku.FirstOrDefault().ToString() ?? null; - } - - 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; - } - - Product position = new Product - { - ProductSku = sku - }; - - if (PositionAmount.ContainsKey(position)) - { - PositionAmount[position] += amount.Value; - } - - else - { - PositionAmount.Add(position, amount.Value); - } - } - } - } -} - diff --git a/src/Controllers/MergeTool.cs b/src/Controllers/MergeTool.cs deleted file mode 100644 index dec8ff7..0000000 --- a/src/Controllers/MergeTool.cs +++ /dev/null @@ -1,46 +0,0 @@ -using RhSolutions.Models; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace RhSolutions.Controllers -{ - internal class MergeTool : ToolBase - { - private List SourceFiles { get; set; } - - public MergeTool() - { - string[] files = Dialog.GetMultiplyFiles(); - - if (files != null) - { - SourceFiles = SourcePriceList.GetSourceLists(files); - } - - else - { - throw new Exception("Не выбраны файлы"); - } - } - - public override void FillTarget() - { - using (ProgressBar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(x => x.PositionAmount.Count))) - using (ResultBar = new ResultBar()) - { - foreach (SourcePriceList source in SourceFiles) - { - foreach (var kvp in source.PositionAmount) - { - FillPositionAmountToColumns(kvp, TargetFile.AmountCell.Column); - ProgressBar.Update(); - } - } - - FilterByAmount(); - ResultBar.Update(); - } - } - } -} diff --git a/src/Controllers/RibbonController.cs b/src/Controllers/RibbonController.cs deleted file mode 100644 index 148daca..0000000 --- a/src/Controllers/RibbonController.cs +++ /dev/null @@ -1,139 +0,0 @@ -using ExcelDna.Integration.CustomUI; -using Microsoft.Office.Interop.Excel; -using RhSolutions.AddIn; -using RhSolutions.Services; -using System; -using System.IO; -using System.Reflection; -using System.Runtime.InteropServices; -using System.Windows.Forms; -using Range = Microsoft.Office.Interop.Excel.Range; - -namespace RhSolutions.Controllers -{ - [ComVisible(true)] - public class RibbonController : ExcelRibbon - { - private static IRibbonUI ribbonUi; - - public override string GetCustomUI(string RibbonID) - { - return @" - - - - - -