diff options
Diffstat (limited to 'src')
27 files changed, 0 insertions, 1399 deletions
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<SourcePriceList> 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<Product, double> 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<Product, double>(); - - 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<SourcePriceList> 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 @" - <customUI onLoad='RibbonLoad' xmlns='http://schemas.microsoft.com/office/2006/01/customui'> - <ribbon> - <tabs> - <tab id='rau' label='RhSolutions'> - <group id='priceList' label='Прайс-лист'> - <button id='export' getEnabled='GetExportEnabled' label='Экспорт в новый файл' size='normal' imageMso='PivotExportToExcel' onAction='OnToolPressed'/> - <button id='convert' getEnabled='GetConvertEnabled' label='Актуализировать' size='normal' imageMso='FileUpdate' onAction='OnToolPressed'/> - <menu id='conjoinMenu' label='Объединить' imageMso='Copy'> - <button id='merge' label='Сложить' onAction='OnToolPressed'/> - <button id='combine' label='По колонкам' onAction='OnToolPressed'/> - </menu> - </group> - <group id='rausettings' getLabel='GetVersionLabel'> - <button id='setPriceList' getLabel='GetPriceListPathLabel' size='large' imageMso='TableExcelSpreadsheetInsert' onAction='OnSetPricePressed'/> - </group> - </tab> - </tabs> - </ribbon> - </customUI>"; - } - - public void RibbonLoad(IRibbonUI sender) - { - ribbonUi = sender; - } - - public static void RefreshControl(string id) - { - if (ribbonUi != null) - { - ribbonUi.InvalidateControl(id); - } - } - public void OnSetPricePressed(IRibbonControl control) - { - string path = Models.Dialog.GetFilePath(); - - if (!string.IsNullOrEmpty(path)) - { - RegistryUtil.PriceListPath = path; - } - } - - public void OnToolPressed(IRibbonControl control) - { - try - { - ToolBase tool; - switch (control.Id) - { - case "export": - tool = new ExportTool(); - break; - case "convert": - tool = new ConvertTool(); - break; - case "merge": - tool = new MergeTool(); - break; - case "combine": - tool = new CombineTool(); - break; - default: - throw new Exception("Неизвестный инструмент"); - } - - tool.OpenNewPrice(); - tool.FillTarget(); - } - - catch (Exception exception) - { - MessageBox.Show(exception.Message, - "Ошибка", - MessageBoxButtons.OK, - MessageBoxIcon.Information); - RhSolutionsAddIn.Excel.StatusBar = false; - return; - } - } - - public bool GetConvertEnabled(IRibbonControl control) - { - if (RhSolutionsAddIn.Excel.ActiveWorkbook == null) - return false; - - else - { - Worksheet worksheet = RhSolutionsAddIn.Excel.ActiveWorkbook.ActiveSheet; - return worksheet.IsRehauSource(); - } - } - - public bool GetExportEnabled(IRibbonControl control) - { - if (RhSolutionsAddIn.Excel.ActiveWorkbook == null) - return false; - - else - { - Range selection = RhSolutionsAddIn.Excel.Selection; - return selection.Columns.Count == 2; - } - } - - public string GetVersionLabel(IRibbonControl control) - { - string version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); - return $"v{version}"; - } - - public string GetPriceListPathLabel(IRibbonControl control) - { - string name = RegistryUtil.GetPriceListName(); - return string.IsNullOrEmpty(name) ? "Нет файла шаблона!" : name; - } - } -} diff --git a/src/Controllers/ToolBase.cs b/src/Controllers/ToolBase.cs deleted file mode 100644 index 08493d4..0000000 --- a/src/Controllers/ToolBase.cs +++ /dev/null @@ -1,190 +0,0 @@ -using Microsoft.Office.Interop.Excel; -using RhSolutions.AddIn; -using RhSolutions.Models; -using RhSolutions.Services; -using System; -using System.Collections.Generic; -using System.Linq; -using Range = Microsoft.Office.Interop.Excel.Range; - -namespace RhSolutions.Controllers -{ - internal abstract class ToolBase - { - protected Application ExcelApp = RhSolutionsAddIn.Excel; - protected TargetPriceList TargetFile { get; set; } - protected ResultBar ResultBar { get; set; } - protected ProgressBar ProgressBar { get; set; } - - public abstract void FillTarget(); - - public void OpenNewPrice() - { - if (ExcelApp.Workbooks - .Cast<Workbook>() - .FirstOrDefault(w => w.FullName == RegistryUtil.PriceListPath) != null) - { - throw new ArgumentException("Шаблонный файл редактируется в другом месте"); - } - - Workbook wb = ExcelApp.Workbooks.Open(RegistryUtil.PriceListPath, null, true); - - try - { - TargetFile = new TargetPriceList(wb); - } - - catch (Exception exception) - { - if (wb != null) - { - wb.Close(); - } - - throw exception; - } - } - - protected void FillPositionAmountToColumns(KeyValuePair<Product, double> positionAmount, params int[] columns) - { - Range worksheetCells = TargetFile.Sheet.Cells; - Range skuColumn = TargetFile.SkuCell.EntireColumn; - - int? row = GetPositionRow(skuColumn, positionAmount.Key.ProductSku, positionAmount.Key.ProductLine); - - if (row != null) - { - foreach (int column in columns) - { - Range cell = worksheetCells[row, column]; - cell.AddValue(positionAmount.Value); - } - - ResultBar.IncrementSuccess(); - return; - } - - if (TargetFile.OldSkuCell != null) - { - row = GetPositionRow(TargetFile.OldSkuCell.EntireColumn, positionAmount.Key.ProductSku, positionAmount.Key.ProductLine); - - if (row != null) - { - foreach (int column in columns) - { - Range cell = worksheetCells[row, column]; - cell.AddValue(positionAmount.Value); - } - - ResultBar.IncrementReplaced(); - return; - } - } - - string sku = positionAmount.Key.ProductSku.Substring(1, 6); - row = GetPositionRow(skuColumn, sku, positionAmount.Key.ProductLine); - - if (row != null) - { - foreach (int column in columns) - { - Range cell = worksheetCells[row, column]; - cell.AddValue(positionAmount.Value); - } - - ResultBar.IncrementReplaced(); - return; - } - - FillMissing(positionAmount, columns); - ResultBar.IncrementNotFound(); - } - - protected void FillMissing(KeyValuePair<Product, double> positionAmount, params int[] columns) - { - Range worksheetCells = TargetFile.Sheet.Cells; - Range worksheetRows = TargetFile.Sheet.Rows; - int skuColumn = TargetFile.SkuCell.Column; - int groupColumn = TargetFile.GroupCell.Column; - int nameColumn = TargetFile.NameCell.Column; - - int row = worksheetCells[worksheetRows.Count, skuColumn] - .End[XlDirection.xlUp] - .Row + 1; - - worksheetRows[row] - .EntireRow - .Insert(XlInsertShiftDirection.xlShiftDown, XlInsertFormatOrigin.xlFormatFromLeftOrAbove); - - Range previous = worksheetRows[row - 1]; - Range current = worksheetRows[row]; - - previous.Copy(current); - current.ClearContents(); - - worksheetCells[row, groupColumn].Value2 = positionAmount.Key.ProductLine; - worksheetCells[row, nameColumn].Value2 = positionAmount.Key.Name; - - if (TargetFile.OldSkuCell != null) - { - worksheetCells[row, skuColumn].Value2 = "Не найден"; - worksheetCells[row, TargetFile.OldSkuCell.Column].Value2 = positionAmount.Key.ProductSku; - } - - else - { - worksheetCells[row, skuColumn].Value2 = positionAmount.Key.ProductSku; - } - - foreach (int column in columns) - { - Range cell = worksheetCells[row, column]; - cell.AddValue(positionAmount.Value); - } - } - - protected int? GetPositionRow(Range range, string sku, string group) - { - Range found = range.Find(sku); - string foundGroupValue; - - if (found == null) - { - return null; - } - - int firstFoundRow = found.Row; - - if (string.IsNullOrEmpty(group)) - { - return found.Row; - } - - while (true) - { - foundGroupValue = TargetFile.Sheet.Cells[found.Row, TargetFile.GroupCell.Column].Value2.ToString(); - - if (group.Equals(foundGroupValue)) - { - return found.Row; - } - - found = range.FindNext(found); - - if (found.Row == firstFoundRow) - { - return null; - } - } - } - - protected void FilterByAmount() - { - AutoFilter filter = TargetFile.Sheet.AutoFilter; - int startColumn = filter.Range.Column; - - filter.Range.AutoFilter(TargetFile.AmountCell.Column - startColumn + 1, "<>0", XlAutoFilterOperator.xlAnd, "<>"); - TargetFile.Sheet.Range["A1"].Activate(); - } - } -}
\ No newline at end of file diff --git a/src/Models/Dialog.cs b/src/Models/Dialog.cs deleted file mode 100644 index abc89b8..0000000 --- a/src/Models/Dialog.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Microsoft.Office.Interop.Excel; -using System.Collections.Generic; -using System.Windows.Forms; - -namespace RhSolutions.Models -{ - static class Dialog - { - public static string GetFilePath() - { - using (OpenFileDialog dialog = new OpenFileDialog()) - { - dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm"; - - if (dialog.ShowDialog() == DialogResult.OK) - { - return dialog.FileName; - } - - else return string.Empty; - } - } - - public static string[] GetMultiplyFiles() - { - using (OpenFileDialog dialog = new OpenFileDialog()) - { - dialog.Filter = "Файлы Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm"; - dialog.Multiselect = true; - - if (dialog.ShowDialog() == DialogResult.OK) - { - return dialog.FileNames; - } - - else return null; - } - } - } -} diff --git a/src/Models/PriceListBase.cs b/src/Models/PriceListBase.cs deleted file mode 100644 index 95f385d..0000000 --- a/src/Models/PriceListBase.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Microsoft.Office.Interop.Excel; - -namespace RhSolutions.Models -{ - internal abstract class PriceListBase - { - public Range AmountCell { get; protected set; } - public Range SkuCell { get; protected set; } - public Range GroupCell { get; protected set; } - public Range NameCell { get; protected set; } - - public Worksheet Sheet { get; protected set; } - public string Name { get; protected set; } - } -}
\ No newline at end of file diff --git a/src/Models/PriceListHeaders.cs b/src/Models/PriceListHeaders.cs deleted file mode 100644 index c9a8370..0000000 --- a/src/Models/PriceListHeaders.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace RhSolutions.Models -{ - internal static class PriceListHeaders - { - public static readonly string Amount = "Кол-во"; - public static readonly string OldSku = "Прежний материал"; - public static readonly string Sku = "Актуальный материал"; - public static readonly string Group = "Программа"; - public static readonly string Name = "Наименование"; - } -}
\ No newline at end of file diff --git a/src/Models/Product.cs b/src/Models/Product.cs deleted file mode 100644 index 2f092d1..0000000 --- a/src/Models/Product.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Linq; - -namespace RhSolutions.Models -{ - public class Product - { - public string ProductLine { get; set; } - public string ProductSku { get; set; } - public string Name { get; set; } - - public override bool Equals(object obj) - { - if (obj as Product == null) - return false; - - Product other = obj as Product; - - return ProductLine == other.ProductLine && - ProductSku == other.ProductSku && - Name == other.Name; - } - - public override int GetHashCode() - { - string[] properties = new[] - { - ProductLine, - ProductSku, - Name - }; - - return string.Concat(properties.Where(p => p != null)).GetHashCode(); - } - } -}
\ No newline at end of file diff --git a/src/Models/ProgressBar.cs b/src/Models/ProgressBar.cs deleted file mode 100644 index 82012e5..0000000 --- a/src/Models/ProgressBar.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace RhSolutions.Models -{ - internal class ProgressBar : StatusbarBase - { - private double CurrentProgress { get; set; } - private readonly double TaskWeight; - private readonly string Message; - - public ProgressBar(string message, int weight) - { - Message = message; - TaskWeight = weight; - CurrentProgress = 0; - } - - public override void Update() - { - double percent = ++CurrentProgress / TaskWeight * 100; - Excel.StatusBar = $"{Message} Выполнено {percent:#.#} %"; - } - } -} diff --git a/src/Models/ResultBar.cs b/src/Models/ResultBar.cs deleted file mode 100644 index 655540c..0000000 --- a/src/Models/ResultBar.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Text; - -namespace RhSolutions.Models -{ - internal class ResultBar : StatusbarBase - { - private int Success { get; set; } - private int Replaced { get; set; } - private int NotFound { get; set; } - - public ResultBar() - { - Success = 0; - Replaced = 0; - NotFound = 0; - } - - public void IncrementSuccess() => Success++; - public void IncrementReplaced() => Replaced++; - public void IncrementNotFound() => NotFound++; - - public override void Update() - { - StringBuilder sb = new StringBuilder(); - - if (Success > 0) - { - sb.Append($"Успешно экспортировано {Success} артикулов. "); - } - - if (Replaced > 0) - { - sb.Append($"Заменено {Replaced} артикулов. "); - } - - if (NotFound > 0) - { - sb.Append($"Не найдено {NotFound} артикулов."); - } - - Excel.StatusBar = sb.ToString(); - } - } -} diff --git a/src/Models/SourcePriceList.cs b/src/Models/SourcePriceList.cs deleted file mode 100644 index dc950eb..0000000 --- a/src/Models/SourcePriceList.cs +++ /dev/null @@ -1,116 +0,0 @@ -using ExcelDna.Integration; -using Microsoft.Office.Interop.Excel; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Range = Microsoft.Office.Interop.Excel.Range; - -namespace RhSolutions.Models -{ - internal class SourcePriceList : PriceListBase - { - public Dictionary<Product, double> PositionAmount { get; private set; } - - public SourcePriceList(Workbook workbook) - { - if (workbook == null) - { - throw new ArgumentException($"Нет рабочего файла"); - } - - Sheet = workbook.ActiveSheet; - Name = Path.GetFileNameWithoutExtension(workbook.FullName); - - Range[] cells = new[] - { - AmountCell = Sheet.Cells.Find(PriceListHeaders.Amount), - SkuCell = Sheet.Cells.Find(PriceListHeaders.Sku), - GroupCell = Sheet.Cells.Find(PriceListHeaders.Group), - NameCell = Sheet.Cells.Find(PriceListHeaders.Name) - }; - - if (cells.Any(x => x == null)) - { - throw new ArgumentException($"Файл {Name} не распознан"); - } - - CreatePositionsDict(); - } - - public static List<SourcePriceList> GetSourceLists(string[] files) - { - var ExcelApp = (Application)ExcelDnaUtil.Application; - ProgressBar bar = new ProgressBar("Открываю исходные файлы...", files.Length); - - List<SourcePriceList> sourceFiles = new List<SourcePriceList>(); - - foreach (string file in files) - { - ExcelApp.ScreenUpdating = false; - Workbook wb = ExcelApp.Workbooks.Open(file); - try - { - SourcePriceList priceList = new SourcePriceList(wb); - sourceFiles.Add(priceList); - wb.Close(); - bar.Update(); - } - catch (Exception ex) - { - System.Windows.Forms.MessageBox.Show - (ex.Message, - "Ошибка открытия исходного прайс-листа", - System.Windows.Forms.MessageBoxButtons.OK, - System.Windows.Forms.MessageBoxIcon.Information); - wb.Close(); - bar.Update(); - } - ExcelApp.ScreenUpdating = true; - } - - return sourceFiles; - } - - private void CreatePositionsDict() - { - PositionAmount = new Dictionary<Product, double>(); - - for (int row = AmountCell.Row + 1; row <= Sheet.Cells[Sheet.Rows.Count, AmountCell.Column].End[XlDirection.xlUp].Row; row++) - { - double? amount = Sheet.Cells[row, AmountCell.Column].Value2 as double?; - - if (amount != null && amount.Value != 0) - { - object group = Sheet.Cells[row, GroupCell.Column].Value2; - object name = Sheet.Cells[row, NameCell.Column].Value2; - object sku = Sheet.Cells[row, SkuCell.Column].Value2; - - if (group == null || name == null || sku == null) - continue; - - if (!Sku.TryParse(sku.ToString(), out _)) - continue; - - Product p = new Product - { - ProductSku = sku.ToString(), - ProductLine = group.ToString(), - Name = name.ToString() - }; - - if (PositionAmount.ContainsKey(p)) - { - PositionAmount[p] += amount.Value; - } - - else - { - PositionAmount.Add(p, amount.Value); - } - } - } - } - } -} - diff --git a/src/Models/StatusbarBase.cs b/src/Models/StatusbarBase.cs deleted file mode 100644 index fbec70e..0000000 --- a/src/Models/StatusbarBase.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Microsoft.Office.Interop.Excel; -using RhSolutions.AddIn; -using System; - -namespace RhSolutions.Models -{ - internal abstract class StatusbarBase : IDisposable - { - protected Application Excel = RhSolutionsAddIn.Excel; - - public abstract void Update(); - - public void Dispose() - { - Excel.OnTime(DateTime.Now + new TimeSpan(0, 0, 5), "_ResetStatusBar"); - } - } -} diff --git a/src/Models/TargetPriceList.cs b/src/Models/TargetPriceList.cs deleted file mode 100644 index 2dcd48e..0000000 --- a/src/Models/TargetPriceList.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Microsoft.Office.Interop.Excel; -using System; -using System.IO; -using System.Linq; -using Range = Microsoft.Office.Interop.Excel.Range; - -namespace RhSolutions.Models -{ - internal class TargetPriceList : PriceListBase - { - public Range OldSkuCell { get; private set; } - - public TargetPriceList(Workbook workbook) - { - if (workbook == null) - { - throw new ArgumentException("Невозможно открыть книгу шаблонного файла. " + - "Возможно открыт файл с именем, совпадающим с именем шаблонного файла."); - } - - Sheet = workbook.ActiveSheet; - Name = Path.GetFileNameWithoutExtension(workbook.FullName); - - Range[] cells = new[] - { - AmountCell = Sheet.Cells.Find(PriceListHeaders.Amount), - SkuCell = Sheet.Cells.Find(PriceListHeaders.Sku), - GroupCell = Sheet.Cells.Find(PriceListHeaders.Group), - NameCell = Sheet.Cells.Find(PriceListHeaders.Name) - }; - - OldSkuCell = Sheet.Cells.Find(PriceListHeaders.OldSku); - - if (cells.Any(x => x == null)) - { - throw new ArgumentException($"Шаблон {Name} не является прайс-листом"); - } - } - } -} - diff --git a/src/Models/WorksheetExtensions.cs b/src/Models/WorksheetExtensions.cs deleted file mode 100644 index 6b5fc3e..0000000 --- a/src/Models/WorksheetExtensions.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Microsoft.Office.Interop.Excel; -using RhSolutions.Models; -using System.Linq; - -namespace RhSolutions.Services -{ - 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; - } - } - } -} - diff --git a/src/Properties/AssemblyInfo.cs b/src/Properties/AssemblyInfo.cs deleted file mode 100644 index 78f4a31..0000000 --- a/src/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Versioning; - -// 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("RhSolutions.AddIn")] -[assembly: AssemblyDescription("Excel AddIn for RhSolutions")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("RhSolutions")] -[assembly: AssemblyProduct("RhSolutions.AddIn")] -[assembly: AssemblyCopyright("Copyright © 2021-2023")] -[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.2.4.0")] -[assembly: AssemblyFileVersion("1.2.4.0")] diff --git a/src/Properties/ExcelDna.Build.props b/src/Properties/ExcelDna.Build.props deleted file mode 100644 index f5fdab1..0000000 --- a/src/Properties/ExcelDna.Build.props +++ /dev/null @@ -1,86 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="ExcelDnaProps"> -<!-- - If you change properties in this file, they may not come into effect until you: - * Rebuild the solution/project - - or - - * Close Visual Studio - * Delete .vs folder, if exists - * Delete ProjectName.csproj.user (or equivalent for VB, F#, etc.), if exists - * Delete SolutionName.suo, if exists - * Open your solution/project again in Visual Studio - --> - - <!-- - Configuration properties for debugging Excel-DNA add-ins - --> - <PropertyGroup> - <!-- - Enable/Disable setting the debug options when building the project - --> - <RunExcelDnaSetDebuggerOptions Condition="'$(RunExcelDnaSetDebuggerOptions)' == ''">true</RunExcelDnaSetDebuggerOptions> - - <!-- - Override the path of EXCEL.EXE used for debugging the project, if you need - By default, it will use the latest version of Excel it can find on the machine - --> - <ExcelDnaExcelExePath Condition="'$(ExcelDnaExcelExePath)' == ''"></ExcelDnaExcelExePath> - - <!-- - Override the name of the .XLL add-in to use when debugging the project, if you need - By default, it will use the first unpacked .xll add-in that matches the bitness of EXCEL.EXE - --> - <ExcelDnaAddInForDebugging Condition="'$(ExcelDnaAddInForDebugging)' == ''"></ExcelDnaAddInForDebugging> - </PropertyGroup> - - <!-- - Configuration properties for building .dna files - --> - <PropertyGroup> - <!-- - Enable/Disable automatic generation of platform-specific versions of .dna files - --> - <ExcelDnaCreate32BitAddIn Condition="'$(ExcelDnaCreate32BitAddIn)' == ''">true</ExcelDnaCreate32BitAddIn> - <ExcelDnaCreate64BitAddIn Condition="'$(ExcelDnaCreate64BitAddIn)' == ''">true</ExcelDnaCreate64BitAddIn> - - <!-- - Define the suffix used for each platform-specific file e.g. MyAddIn64.dna - --> - <ExcelDna32BitAddInSuffix Condition="'$(ExcelDna32BitAddInSuffix)' == ''"></ExcelDna32BitAddInSuffix> - <ExcelDna64BitAddInSuffix Condition="'$(ExcelDna64BitAddInSuffix)' == ''">64</ExcelDna64BitAddInSuffix> - </PropertyGroup> - - <PropertyGroup> - <!-- - Enable/Disable using Excel-DNA with PackageReference projects (not officially supported) - --> - <ExcelDnaAllowPackageReferenceProjectStyle Condition="'$(ExcelDnaAllowPackageReferenceProjectStyle)' == ''">false</ExcelDnaAllowPackageReferenceProjectStyle> - </PropertyGroup> - - <!-- - Configuration properties for packing .dna files - --> - <PropertyGroup> - <!-- - Enable/Disable packing of .dna files - --> - <RunExcelDnaPack Condition="'$(RunExcelDnaPack)' == ''">true</RunExcelDnaPack> - - <!-- - Suffix used for packed .xll files e.g. MyAddIn-packed.xll - --> - <ExcelDnaPackXllSuffix Condition="'$(ExcelDnaPackXllSuffix)' == ''">-packed</ExcelDnaPackXllSuffix> - - <!-- - Options used when packing .xll files. - When in trouble with your virus scanner, try uncommenting at least the resource compression properties. - The default is true for both compression and multithreaded runs when not specified. - --> - <!--<ExcelDnaPackCompressResources Condition="'$(ConfigurationName)' == 'Debug'">false</ExcelDnaPackCompressResources>--> - <!--<ExcelDnaPackRunMultithreaded Condition="'$(ConfigurationName)' == 'Debug'">false</ExcelDnaPackRunMultithreaded>--> - <!--<ExcelDnaPackCompressResources Condition="'$(ConfigurationName)' == 'Release'">false</ExcelDnaPackCompressResources>--> - <!--<ExcelDnaPackRunMultithreaded Condition="'$(ConfigurationName)' == 'Release'">false</ExcelDnaPackRunMultithreaded>--> - </PropertyGroup> -</Project> diff --git a/src/Properties/launchSettings.json b/src/Properties/launchSettings.json deleted file mode 100644 index c36dbc3..0000000 --- a/src/Properties/launchSettings.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "profiles": { - "Excel": { - "commandName": "Executable", - "executablePath": "C:\\Program Files\\Microsoft Office\\root\\Office16\\EXCEL.EXE", - "commandLineArgs": "RhSolutions-AddIn64.xll" - } - } -}
\ No newline at end of file diff --git a/src/RhSolutions-AddIn.dna b/src/RhSolutions-AddIn.dna deleted file mode 100644 index 5322868..0000000 --- a/src/RhSolutions-AddIn.dna +++ /dev/null @@ -1,26 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<DnaLibrary Name="RhSolutions Add-In" RuntimeVersion="v4.0" xmlns="http://schemas.excel-dna.net/addin/2020/07/dnalibrary"> - <ExternalLibrary Path="RhSolutions.AddIn.dll" ExplicitExports="false" LoadFromBytes="true" Pack="true" IncludePdb="false" /> - <Reference Path="ExcelDna.IntelliSense.dll" Pack="true" /> - <Reference Path="Newtonsoft.Json.dll" Pack="true" /> - <Reference Path="RhSolutions.Sku.dll" Pack="true" /> - - - <!-- - The RuntimeVersion attribute above allows only the following setting: - * RuntimeVersion="v4.0" - for .NET 4.5 or higher - - You can have IntelliSense (autocomplete) and validation for this file. - See https://github.com/Excel-DNA/ExcelDna/tree/master/Distribution/XmlSchemas/ - - Additional referenced assemblies can be specified by adding 'Reference' tags. - These libraries will not be examined and registered with Excel as add-in libraries, - but will be packed into the -packed.xll file and loaded at runtime as needed. - For example: - - <Reference Path="Another.Library.dll" Pack="true" /> - - Excel-DNA also allows the XML for ribbon UI extensions to be specified in the .dna file. - See the main Excel-DNA site at https://excel-dna.net for downloads of the full distribution. - --> -</DnaLibrary> diff --git a/src/RhSolutions.csproj b/src/RhSolutions.csproj deleted file mode 100644 index 60182f6..0000000 --- a/src/RhSolutions.csproj +++ /dev/null @@ -1,23 +0,0 @@ -<Project Sdk="Microsoft.NET.Sdk"> - <PropertyGroup> - <TargetFrameworks>net472;net6.0-windows</TargetFrameworks> - <OutputType>Library</OutputType> - <RootNamespace>RhSolutions.AddIn</RootNamespace> - <AssemblyName>RhSolutions.AddIn</AssemblyName> - <GenerateAssemblyInfo>false</GenerateAssemblyInfo> - <UseWindowsForms>true</UseWindowsForms> - <ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets> - </PropertyGroup> - <PropertyGroup> - <StartupObject /> - </PropertyGroup> - <ItemGroup> - <PackageReference Include="ExcelDna.AddIn" Version="1.6.0" /> - <PackageReference Include="ExcelDna.IntelliSense" Version="1.6.0" /> - <PackageReference Include="ExcelDna.Interop" Version="15.0.0" /> - <PackageReference Include="Microsoft.CSharp" Version="4.7.0" /> - <PackageReference Include="Newtonsoft.Json" Version="13.0.2" /> - <PackageReference Include="RhSolutions.Sku" Version="0.1.1" /> - <PackageReference Include="System.Net.Http" Version="4.3.4" /> - </ItemGroup> -</Project>
\ No newline at end of file diff --git a/src/Services/EventsUtil.cs b/src/Services/EventsUtil.cs deleted file mode 100644 index bb37125..0000000 --- a/src/Services/EventsUtil.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Microsoft.Office.Interop.Excel; -using RhSolutions.AddIn; -using RhSolutions.Controllers; - -namespace RhSolutions.Services -{ - internal static class EventsUtil - { - private static readonly Application Excel = RhSolutionsAddIn.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) - { - RibbonController.RefreshControl("convert"); - } - - private static void RefreshExportButton(object sh, Range target) - { - RibbonController.RefreshControl("export"); - } - } -} diff --git a/src/Services/RegistryUtil.cs b/src/Services/RegistryUtil.cs deleted file mode 100644 index 8b165ea..0000000 --- a/src/Services/RegistryUtil.cs +++ /dev/null @@ -1,74 +0,0 @@ -using Microsoft.Win32; -using RhSolutions.Controllers; -using RhSolutions.Models; -using System; -using System.IO; -using System.Windows.Forms; - -namespace RhSolutions.Services -{ - 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/Services/RhDatabaseClient.cs b/src/Services/RhDatabaseClient.cs deleted file mode 100644 index 70530ae..0000000 --- a/src/Services/RhDatabaseClient.cs +++ /dev/null @@ -1,52 +0,0 @@ -using Newtonsoft.Json; -using RhSolutions.AddIn; -using RhSolutions.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Threading.Tasks; - -namespace RhSolutions.Services -{ - public static class RhDatabaseClient - { - public static async Task<object> GetProduct(string line) - { - string request; - - if (Sku.TryParse(line, out var skus)) - { - request = @"https://rh.cebotari.ru/api/products/" + skus.FirstOrDefault().ToString(); - } - - else - { - request = @"https://rh.cebotari.ru/api/search?query=" + line; - } - - var response = await RhSolutionsAddIn.HttpClient.GetAsync(request); - - try - { - response.EnsureSuccessStatusCode(); - string json = await response.Content.ReadAsStringAsync(); - var product = JsonConvert.DeserializeObject<IEnumerable<Product>>(json) - .FirstOrDefault(); - - if (product == null) - { - return null; - } - else - { - return $"{product.ProductSku} {product.Name}"; - } - } - catch - { - return $"Ошибка сервера {response.StatusCode}"; - } - } - } -}
\ No newline at end of file diff --git a/src/app.config b/src/app.config deleted file mode 100644 index eaef242..0000000 --- a/src/app.config +++ /dev/null @@ -1,19 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<configuration> - <runtime> - <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> - <dependentAssembly> - <assemblyIdentity name="System.Text.Encoding.CodePages" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> - <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> - </dependentAssembly> - <dependentAssembly> - <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> - <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> - </dependentAssembly> - <dependentAssembly> - <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> - <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" /> - </dependentAssembly> - </assemblyBinding> - </runtime> -<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /></startup></configuration> |