Compare commits

...

12 Commits

Author SHA1 Message Date
Sergey Chebotar
8ac3234473 Implement fast product search by sku 2022-12-21 08:02:42 +03:00
Sergey Chebotar
c91f231892 Remove temporary DbProduct class 2022-12-20 13:00:16 +03:00
Sergey Chebotar
a9ffc5510d Move Serurity protocol changer 2022-12-20 12:58:30 +03:00
Sergey Chebotar
64d0abd006 Version change 2022-12-20 12:57:44 +03:00
Sergey Chebotar
6137433aef Refactoring 2022-12-20 12:41:46 +03:00
Sergey Chebotar
73569a4364 Namespace refactoring 2022-12-20 12:27:47 +03:00
Sergey Chebotar
3d186c22e8 Rename Sku class 2022-12-20 12:03:20 +03:00
Sergey Chebotar
bfada8d605 RhDatabase Client extract class 2022-12-20 12:03:05 +03:00
Sergey Chebotar
e427d63e77 Project file 2022-12-20 11:54:29 +03:00
Sergey Chebotar
36c4d4480d Rename Abstract classes 2022-12-20 11:53:55 +03:00
Sergey Chebotar
84137845fd Statusbar reset method edit 2022-12-20 08:31:38 +03:00
Sergey Chebotar
3c7e24ecfe Rename Position to Product 2022-12-20 08:30:58 +03:00
28 changed files with 258 additions and 233 deletions

View File

@ -1,12 +1,13 @@
using ExcelDna.Integration; using ExcelDna.Integration;
using ExcelDna.IntelliSense; using ExcelDna.IntelliSense;
using Microsoft.Office.Interop.Excel; using Microsoft.Office.Interop.Excel;
using RhSolutions.Services;
using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Runtime.Caching;
namespace RhSolutions namespace RhSolutions.AddIn
{ {
class AddIn : IExcelAddIn class RhSolutionsAddIn : IExcelAddIn
{ {
public static Application Excel; public static Application Excel;
public static HttpClient httpClient; public static HttpClient httpClient;
@ -18,6 +19,11 @@ namespace RhSolutions
IntelliSenseServer.Install(); IntelliSenseServer.Install();
RegistryUtil.Initialize(); RegistryUtil.Initialize();
EventsUtil.Initialize(); EventsUtil.Initialize();
ServicePointManager.SecurityProtocol =
SecurityProtocolType.Tls12 |
SecurityProtocolType.Tls11 |
SecurityProtocolType.Tls;
} }
public void AutoClose() public void AutoClose()

View File

@ -1,27 +1,10 @@
using ExcelDna.Integration; using ExcelDna.Integration;
using Newtonsoft.Json; using RhSolutions.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
namespace RhSolutions namespace RhSolutions.AddIn
{ {
public class Functions public class Functions
{ {
[ExcelFunction(Description = "Получение корректного артикула из строки")]
public static object GETRAUSKU([ExcelArgument(Name = "\"Строка\"", Description = "строка, содержащая актикул")] string line)
{
if (RauSku.TryParse(line, out RauSku rausku))
{
return rausku.ToString();
}
else return ExcelError.ExcelErrorNA;
}
[ExcelFunction(Description = "Запрос в удаленную базу данных")] [ExcelFunction(Description = "Запрос в удаленную базу данных")]
public static object RHSOLUTIONS([ExcelArgument(Name = "Запрос")] string line) public static object RHSOLUTIONS([ExcelArgument(Name = "Запрос")] string line)
{ {
@ -45,40 +28,4 @@ namespace RhSolutions
return result; return result;
} }
} }
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; }
}
}
} }

View File

@ -1,13 +1,13 @@
using Microsoft.Office.Interop.Excel; using Microsoft.Office.Interop.Excel;
using RhSolutions.Interface; using RhSolutions.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Dialog = RhSolutions.Interface.Dialog; using Dialog = RhSolutions.Models.Dialog;
namespace RhSolutions.PriceListTools namespace RhSolutions.Controllers
{ {
internal class CombineTool : AbstractTool internal class CombineTool : ToolBase
{ {
private List<SourcePriceList> SourceFiles { get; set; } private List<SourcePriceList> SourceFiles { get; set; }

View File

@ -1,8 +1,8 @@
using RhSolutions.Interface; using RhSolutions.Models;
namespace RhSolutions.PriceListTools namespace RhSolutions.Controllers
{ {
internal class ConvertTool : AbstractTool internal class ConvertTool : ToolBase
{ {
private SourcePriceList Current { get; set; } private SourcePriceList Current { get; set; }

View File

@ -1,13 +1,13 @@
using Microsoft.Office.Interop.Excel; using Microsoft.Office.Interop.Excel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using RhSolutions.Interface; using RhSolutions.Models;
namespace RhSolutions.PriceListTools namespace RhSolutions.Controllers
{ {
internal class ExportTool : AbstractTool internal class ExportTool : ToolBase
{ {
private Dictionary<Position, double> PositionAmount; private Dictionary<Product, double> PositionAmount;
private readonly Range Selection; private readonly Range Selection;
public ExportTool() public ExportTool()
@ -40,7 +40,7 @@ namespace RhSolutions.PriceListTools
private void GetSelected() private void GetSelected()
{ {
object[,] cells = Selection.Value2; object[,] cells = Selection.Value2;
PositionAmount = new Dictionary<Position, double>(); PositionAmount = new Dictionary<Product, double>();
int rowsCount = Selection.Rows.Count; int rowsCount = Selection.Rows.Count;
@ -56,7 +56,7 @@ namespace RhSolutions.PriceListTools
{ {
object current = cells[row, column]; object current = cells[row, column];
if (RauSku.TryParse(current.ToString(), out RauSku rauSku)) if (Sku.TryParse(current.ToString(), out Sku rauSku))
{ {
sku = rauSku.ToString(); sku = rauSku.ToString();
} }
@ -78,7 +78,10 @@ namespace RhSolutions.PriceListTools
continue; continue;
} }
Position position = new Position(null, sku, null); Product position = new Product
{
ProductSku = sku
};
if (PositionAmount.ContainsKey(position)) if (PositionAmount.ContainsKey(position))
{ {

View File

@ -1,11 +1,11 @@
using RhSolutions.Interface; using RhSolutions.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace RhSolutions.PriceListTools namespace RhSolutions.Controllers
{ {
internal class MergeTool : AbstractTool internal class MergeTool : ToolBase
{ {
private List<SourcePriceList> SourceFiles { get; set; } private List<SourcePriceList> SourceFiles { get; set; }

View File

@ -1,13 +1,14 @@
using ExcelDna.Integration.CustomUI; using ExcelDna.Integration.CustomUI;
using Microsoft.Office.Interop.Excel; using Microsoft.Office.Interop.Excel;
using RhSolutions.PriceListTools; using RhSolutions.AddIn;
using RhSolutions.Services;
using System; using System;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Windows.Forms; using System.Windows.Forms;
namespace RhSolutions.Interface namespace RhSolutions.Controllers
{ {
[ComVisible(true)] [ComVisible(true)]
public class RibbonController : ExcelRibbon public class RibbonController : ExcelRibbon
@ -52,7 +53,7 @@ namespace RhSolutions.Interface
} }
public void OnSetPricePressed(IRibbonControl control) public void OnSetPricePressed(IRibbonControl control)
{ {
string path = Dialog.GetFilePath(); string path = Models.Dialog.GetFilePath();
if (!string.IsNullOrEmpty(path)) if (!string.IsNullOrEmpty(path))
{ {
@ -64,7 +65,7 @@ namespace RhSolutions.Interface
{ {
try try
{ {
AbstractTool tool; ToolBase tool;
switch (control.Id) switch (control.Id)
{ {
case "export": case "export":
@ -93,31 +94,31 @@ namespace RhSolutions.Interface
"Ошибка", "Ошибка",
MessageBoxButtons.OK, MessageBoxButtons.OK,
MessageBoxIcon.Information); MessageBoxIcon.Information);
AddIn.Excel.StatusBar = false; RhSolutionsAddIn.Excel.StatusBar = false;
return; return;
} }
} }
public bool GetConvertEnabled(IRibbonControl control) public bool GetConvertEnabled(IRibbonControl control)
{ {
if (AddIn.Excel.ActiveWorkbook == null) if (RhSolutionsAddIn.Excel.ActiveWorkbook == null)
return false; return false;
else else
{ {
Worksheet worksheet = AddIn.Excel.ActiveWorkbook.ActiveSheet; Worksheet worksheet = RhSolutionsAddIn.Excel.ActiveWorkbook.ActiveSheet;
return worksheet.IsRehauSource(); return worksheet.IsRehauSource();
} }
} }
public bool GetExportEnabled(IRibbonControl control) public bool GetExportEnabled(IRibbonControl control)
{ {
if (AddIn.Excel.ActiveWorkbook == null) if (RhSolutionsAddIn.Excel.ActiveWorkbook == null)
return false; return false;
else else
{ {
Range selection = AddIn.Excel.Selection; Range selection = RhSolutionsAddIn.Excel.Selection;
return selection.Columns.Count == 2; return selection.Columns.Count == 2;
} }
} }

View File

@ -1,15 +1,16 @@
using Microsoft.Office.Interop.Excel; using Microsoft.Office.Interop.Excel;
using RhSolutions.Interface; using RhSolutions.AddIn;
using RhSolutions.Models;
using RhSolutions.Services;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using ProgressBar = RhSolutions.Interface.ProgressBar;
namespace RhSolutions.PriceListTools namespace RhSolutions.Controllers
{ {
internal abstract class AbstractTool internal abstract class ToolBase
{ {
protected Application ExcelApp = AddIn.Excel; protected Application ExcelApp = RhSolutionsAddIn.Excel;
protected TargetPriceList TargetFile { get; set; } protected TargetPriceList TargetFile { get; set; }
protected ResultBar ResultBar { get; set; } protected ResultBar ResultBar { get; set; }
protected ProgressBar ProgressBar { get; set; } protected ProgressBar ProgressBar { get; set; }
@ -43,13 +44,13 @@ namespace RhSolutions.PriceListTools
} }
} }
protected void FillPositionAmountToColumns(KeyValuePair<Position, double> positionAmount, params int[] columns) protected void FillPositionAmountToColumns(KeyValuePair<Product, double> positionAmount, params int[] columns)
{ {
Range worksheetCells = TargetFile.Sheet.Cells; Range worksheetCells = TargetFile.Sheet.Cells;
Range skuColumn = TargetFile.SkuCell.EntireColumn; Range skuColumn = TargetFile.SkuCell.EntireColumn;
Range oldSkuColumn = TargetFile.OldSkuCell.EntireColumn; Range oldSkuColumn = TargetFile.OldSkuCell.EntireColumn;
int? row = GetPositionRow(skuColumn, positionAmount.Key.Sku, positionAmount.Key.Group); int? row = GetPositionRow(skuColumn, positionAmount.Key.ProductSku, positionAmount.Key.ProductLine);
if (row != null) if (row != null)
{ {
@ -65,7 +66,7 @@ namespace RhSolutions.PriceListTools
if (TargetFile.OldSkuCell != null) if (TargetFile.OldSkuCell != null)
{ {
row = GetPositionRow(oldSkuColumn, positionAmount.Key.Sku, positionAmount.Key.Group); row = GetPositionRow(oldSkuColumn, positionAmount.Key.ProductSku, positionAmount.Key.ProductLine);
if (row != null) if (row != null)
{ {
@ -80,8 +81,8 @@ namespace RhSolutions.PriceListTools
} }
} }
string sku = positionAmount.Key.Sku.Substring(1, 6); string sku = positionAmount.Key.ProductSku.Substring(1, 6);
row = GetPositionRow(skuColumn, sku, positionAmount.Key.Group); row = GetPositionRow(skuColumn, sku, positionAmount.Key.ProductLine);
if (row != null) if (row != null)
{ {
@ -99,7 +100,7 @@ namespace RhSolutions.PriceListTools
ResultBar.IncrementNotFound(); ResultBar.IncrementNotFound();
} }
protected void FillMissing(KeyValuePair<Position, double> positionAmount, params int[] columns) protected void FillMissing(KeyValuePair<Product, double> positionAmount, params int[] columns)
{ {
Range worksheetCells = TargetFile.Sheet.Cells; Range worksheetCells = TargetFile.Sheet.Cells;
Range worksheetRows = TargetFile.Sheet.Rows; Range worksheetRows = TargetFile.Sheet.Rows;
@ -121,18 +122,18 @@ namespace RhSolutions.PriceListTools
previous.Copy(current); previous.Copy(current);
current.ClearContents(); current.ClearContents();
worksheetCells[row, groupColumn].Value2 = positionAmount.Key.Group; worksheetCells[row, groupColumn].Value2 = positionAmount.Key.ProductLine;
worksheetCells[row, nameColumn].Value2 = positionAmount.Key.Name; worksheetCells[row, nameColumn].Value2 = positionAmount.Key.Name;
if (TargetFile.OldSkuCell != null) if (TargetFile.OldSkuCell != null)
{ {
worksheetCells[row, skuColumn].Value2 = "Не найден"; worksheetCells[row, skuColumn].Value2 = "Не найден";
worksheetCells[row, TargetFile.OldSkuCell.Column].Value2 = positionAmount.Key.Sku; worksheetCells[row, TargetFile.OldSkuCell.Column].Value2 = positionAmount.Key.ProductSku;
} }
else else
{ {
worksheetCells[row, skuColumn].Value2 = positionAmount.Key.Sku; worksheetCells[row, skuColumn].Value2 = positionAmount.Key.ProductSku;
} }
foreach (int column in columns) foreach (int column in columns)

View File

@ -1,24 +0,0 @@
using ExcelDna.Integration;
using Microsoft.Office.Interop.Excel;
using System;
namespace RhSolutions.Interface
{
internal abstract class AbstractBar : IDisposable
{
protected Application Excel = AddIn.Excel;
public abstract void Update();
[ExcelFunction]
public static void ResetStatusBar()
{
AddIn.Excel.StatusBar = false;
}
public void Dispose()
{
AddIn.Excel.OnTime(DateTime.Now + new TimeSpan(0, 0, 5), "ResetStatusBar");
}
}
}

View File

@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows.Forms; using System.Windows.Forms;
namespace RhSolutions.Interface namespace RhSolutions.Models
{ {
static class Dialog static class Dialog
{ {

View File

@ -1,8 +1,8 @@
using Microsoft.Office.Interop.Excel; using Microsoft.Office.Interop.Excel;
namespace RhSolutions.PriceListTools namespace RhSolutions.Models
{ {
internal abstract class AbstractPriceList internal abstract class PriceListBase
{ {
public Range AmountCell { get; protected set; } public Range AmountCell { get; protected set; }
public Range SkuCell { get; protected set; } public Range SkuCell { get; protected set; }

View File

@ -1,4 +1,4 @@
namespace RhSolutions.PriceListTools namespace RhSolutions.Models
{ {
internal static class PriceListHeaders internal static class PriceListHeaders
{ {

35
src/Models/Product.cs Normal file
View File

@ -0,0 +1,35 @@
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();
}
}
}

View File

@ -1,6 +1,6 @@
namespace RhSolutions.Interface namespace RhSolutions.Models
{ {
internal class ProgressBar : AbstractBar internal class ProgressBar : StatusbarBase
{ {
private double CurrentProgress { get; set; } private double CurrentProgress { get; set; }
private readonly double TaskWeight; private readonly double TaskWeight;
@ -15,7 +15,7 @@
public override void Update() public override void Update()
{ {
double percent = (++CurrentProgress / TaskWeight) * 100; double percent = ++CurrentProgress / TaskWeight * 100;
Excel.StatusBar = $"{Message} Выполнено {percent:#.#} %"; Excel.StatusBar = $"{Message} Выполнено {percent:#.#} %";
} }
} }

View File

@ -1,9 +1,9 @@
using System; using System;
using System.Text; using System.Text;
namespace RhSolutions.Interface namespace RhSolutions.Models
{ {
internal class ResultBar : AbstractBar internal class ResultBar : StatusbarBase
{ {
private int Success { get; set; } private int Success { get; set; }
private int Replaced { get; set; } private int Replaced { get; set; }

View File

@ -1,19 +1,19 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace RhSolutions namespace RhSolutions.Models
{ {
internal class RauSku internal class Sku
{ {
public string Sku { get; private set; } public string Article { get; private set; }
public string Variant { get; private set; } public string Variant { get; private set; }
public RauSku(string sku, string variant) public Sku(string article, string variant)
{ {
Sku = sku; Article = article;
Variant = variant; Variant = variant;
} }
public static bool TryParse(string line, out RauSku rehauSku) public static bool TryParse(string line, out Sku rehauSku)
{ {
Match match; Match match;
match = Regex.Match(line, @"\b[1]\d{6}[1]\d{3}\b"); match = Regex.Match(line, @"\b[1]\d{6}[1]\d{3}\b");
@ -21,7 +21,7 @@ namespace RhSolutions
{ {
string sku = match.Value.Substring(1, 6); string sku = match.Value.Substring(1, 6);
string variant = match.Value.Substring(8, 3); string variant = match.Value.Substring(8, 3);
rehauSku = new RauSku(sku, variant); rehauSku = new Sku(sku, variant);
return true; return true;
} }
@ -30,7 +30,7 @@ namespace RhSolutions
{ {
string sku = match.Value.Substring(0, 6); string sku = match.Value.Substring(0, 6);
string variant = match.Value.Substring(7, 3); string variant = match.Value.Substring(7, 3);
rehauSku = new RauSku(sku, variant); rehauSku = new Sku(sku, variant);
return true; return true;
} }
@ -39,7 +39,7 @@ namespace RhSolutions
{ {
string sku = match.Value.Substring(0, 6); string sku = match.Value.Substring(0, 6);
string variant = match.Value.Substring(6, 3); string variant = match.Value.Substring(6, 3);
rehauSku = new RauSku(sku, variant); rehauSku = new Sku(sku, variant);
return true; return true;
} }
@ -48,7 +48,7 @@ namespace RhSolutions
{ {
string sku = match.Value.Substring(0, 6); string sku = match.Value.Substring(0, 6);
string variant = "001"; string variant = "001";
rehauSku = new RauSku(sku, variant); rehauSku = new Sku(sku, variant);
return true; return true;
} }
@ -61,7 +61,7 @@ namespace RhSolutions
public override string ToString() public override string ToString()
{ {
return $"1{Sku}1{Variant}"; return $"1{Article}1{Variant}";
} }
} }
} }

View File

@ -1,6 +1,6 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace RhSolutions namespace RhSolutions.Models
{ {
static class SkuExtensions static class SkuExtensions
{ {

View File

@ -3,13 +3,12 @@ using Microsoft.Office.Interop.Excel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using RhSolutions.Interface;
namespace RhSolutions.PriceListTools namespace RhSolutions.Models
{ {
internal class SourcePriceList : AbstractPriceList internal class SourcePriceList : PriceListBase
{ {
public Dictionary<Position, double> PositionAmount { get; private set; } public Dictionary<Product, double> PositionAmount { get; private set; }
public SourcePriceList(Workbook workbook) public SourcePriceList(Workbook workbook)
{ {
@ -73,7 +72,7 @@ namespace RhSolutions.PriceListTools
private void CreatePositionsDict() private void CreatePositionsDict()
{ {
PositionAmount = new Dictionary<Position, double>(); PositionAmount = new Dictionary<Product, double>();
for (int row = AmountCell.Row + 1; row <= Sheet.Cells[Sheet.Rows.Count, AmountCell.Column].End[XlDirection.xlUp].Row; row++) for (int row = AmountCell.Row + 1; row <= Sheet.Cells[Sheet.Rows.Count, AmountCell.Column].End[XlDirection.xlUp].Row; row++)
{ {
@ -91,7 +90,12 @@ namespace RhSolutions.PriceListTools
if (!sku.ToString().IsRehauSku()) if (!sku.ToString().IsRehauSku())
continue; continue;
Position p = new Position(group.ToString(), sku.ToString(), name.ToString()); Product p = new Product
{
ProductSku = sku.ToString(),
ProductLine = group.ToString(),
Name = name.ToString()
};
if (PositionAmount.ContainsKey(p)) if (PositionAmount.ContainsKey(p))
{ {

View File

@ -0,0 +1,26 @@
using ExcelDna.Integration;
using Microsoft.Office.Interop.Excel;
using RhSolutions.AddIn;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace RhSolutions.Models
{
internal abstract class StatusbarBase : IDisposable
{
protected Application Excel = RhSolutionsAddIn.Excel;
public abstract void Update();
private static void ResetStatusBar()
{
RhSolutionsAddIn.Excel.StatusBar = false;
}
public void Dispose()
{
Task.Delay(5000).ContinueWith(t => ResetStatusBar());
}
}
}

View File

@ -2,9 +2,9 @@
using System; using System;
using System.Linq; using System.Linq;
namespace RhSolutions.PriceListTools namespace RhSolutions.Models
{ {
internal class TargetPriceList : AbstractPriceList internal class TargetPriceList : PriceListBase
{ {
public Range OldSkuCell { get; private set; } public Range OldSkuCell { get; private set; }
@ -31,7 +31,7 @@ namespace RhSolutions.PriceListTools
if (cells.Any(x => x == null)) if (cells.Any(x => x == null))
{ {
throw new ArgumentException($"Шаблон { Name } не является прайс-листом"); throw new ArgumentException($"Шаблон {Name} не является прайс-листом");
} }
} }
} }

View File

@ -1,8 +1,8 @@
using Microsoft.Office.Interop.Excel; using Microsoft.Office.Interop.Excel;
using RhSolutions.PriceListTools; using RhSolutions.Models;
using System.Linq; using System.Linq;
namespace RhSolutions namespace RhSolutions.Services
{ {
public static class WorksheetExtensions public static class WorksheetExtensions
{ {

View File

@ -1,42 +0,0 @@
using System.Linq;
namespace RhSolutions.PriceListTools
{
public class Position
{
public string Group { get; private set; }
public string Sku { get; private set; }
public string Name { get; private set; }
public Position(string group, string sku, string name)
{
Group = group;
Sku = sku;
Name = name;
}
public override bool Equals(object obj)
{
if (obj as Position == null)
return false;
Position other = obj as Position;
return Group == other.Group &&
Sku == other.Sku &&
Name == other.Name;
}
public override int GetHashCode()
{
string[] properties = new[]
{
Group,
Sku,
Name
};
return string.Concat(properties.Where(p => p != null)).GetHashCode();
}
}
}

View File

@ -5,10 +5,10 @@ using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("RhXlPLugin")] [assembly: AssemblyTitle("RhSolutions.AddIn")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("Excel AddIn for RhSolutions")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("RhSolutions")]
[assembly: AssemblyProduct("RhXlPLugin")] [assembly: AssemblyProduct("RhXlPLugin")]
[assembly: AssemblyCopyright("Copyright © 2021-2023")] [assembly: AssemblyCopyright("Copyright © 2021-2023")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.5.0")] [assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.0.5.0")] [assembly: AssemblyFileVersion("1.2.0.0")]

View File

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?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"> <DnaLibrary Name="RhSolutions Add-In" RuntimeVersion="v4.0" xmlns="http://schemas.excel-dna.net/addin/2020/07/dnalibrary">
<ExternalLibrary Path="RhExcelAddin.dll" ExplicitExports="false" LoadFromBytes="true" Pack="true" IncludePdb="false" /> <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" />
<!-- <!--
The RuntimeVersion attribute above allows only the following setting: The RuntimeVersion attribute above allows only the following setting:

View File

@ -8,8 +8,8 @@
<ProjectGuid>{18A2FF67-0E46-4A86-B872-29F2B3F23ADF}</ProjectGuid> <ProjectGuid>{18A2FF67-0E46-4A86-B872-29F2B3F23ADF}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>RhExcelAddin</RootNamespace> <RootNamespace>RhSolutions.AddIn</RootNamespace>
<AssemblyName>RhExcelAddin</AssemblyName> <AssemblyName>RhSolutions.AddIn</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion> <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic> <Deterministic>true</Deterministic>
@ -77,28 +77,29 @@
<Reference Include="WindowsBase" /> <Reference Include="WindowsBase" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AddIn\EventsUtil.cs" /> <Compile Include="Services\EventsUtil.cs" />
<Compile Include="AddIn\RehauSku.cs" /> <Compile Include="Services\RhDatabaseClient.cs" />
<Compile Include="Interface\AbstractBar.cs" /> <Compile Include="Models\Sku.cs" />
<Compile Include="Interface\Dialog.cs" /> <Compile Include="Models\StatusbarBase.cs" />
<Compile Include="AddIn\RegistryUtil.cs" /> <Compile Include="Models\Dialog.cs" />
<Compile Include="AddIn\SkuExtensions.cs" /> <Compile Include="Services\RegistryUtil.cs" />
<Compile Include="Interface\ProgressBar.cs" /> <Compile Include="Models\SkuExtensions.cs" />
<Compile Include="Interface\ResultBar.cs" /> <Compile Include="Models\ProgressBar.cs" />
<Compile Include="PriceListTools\CombineTool.cs" /> <Compile Include="Models\ResultBar.cs" />
<Compile Include="PriceListTools\ConvertTool.cs" /> <Compile Include="Controllers\CombineTool.cs" />
<Compile Include="PriceListTools\Position.cs" /> <Compile Include="Controllers\ConvertTool.cs" />
<Compile Include="PriceListTools\AbstractTool.cs" /> <Compile Include="Models\Product.cs" />
<Compile Include="PriceListTools\MergeTool.cs" /> <Compile Include="Controllers\ToolBase.cs" />
<Compile Include="PriceListTools\AbstractPriceList.cs" /> <Compile Include="Controllers\MergeTool.cs" />
<Compile Include="PriceListTools\PriceListHeaders.cs" /> <Compile Include="Models\PriceListBase.cs" />
<Compile Include="PriceListTools\SourcePriceList.cs" /> <Compile Include="Models\PriceListHeaders.cs" />
<Compile Include="PriceListTools\TargetPriceList.cs" /> <Compile Include="Models\SourcePriceList.cs" />
<Compile Include="Interface\RibbonController.cs" /> <Compile Include="Models\TargetPriceList.cs" />
<Compile Include="PriceListTools\ExportTool.cs" /> <Compile Include="Controllers\RibbonController.cs" />
<Compile Include="Controllers\ExportTool.cs" />
<Compile Include="AddIn\AddIn.cs" /> <Compile Include="AddIn\AddIn.cs" />
<Compile Include="AddIn\Functions.cs" /> <Compile Include="AddIn\Functions.cs" />
<Compile Include="AddIn\WorksheetExtensions.cs" /> <Compile Include="Models\WorksheetExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -1,10 +1,12 @@
using Microsoft.Office.Interop.Excel; using Microsoft.Office.Interop.Excel;
using RhSolutions.AddIn;
using RhSolutions.Controllers;
namespace RhSolutions namespace RhSolutions.Services
{ {
internal static class EventsUtil internal static class EventsUtil
{ {
private static readonly Application Excel = AddIn.Excel; private static readonly Application Excel = RhSolutionsAddIn.Excel;
public static void Initialize() public static void Initialize()
{ {
@ -22,12 +24,12 @@ namespace RhSolutions
private static void RefreshConvertButton(object sh) private static void RefreshConvertButton(object sh)
{ {
Interface.RibbonController.RefreshControl("convert"); RibbonController.RefreshControl("convert");
} }
private static void RefreshExportButton(object sh, Range target) private static void RefreshExportButton(object sh, Range target)
{ {
Interface.RibbonController.RefreshControl("export"); RibbonController.RefreshControl("export");
} }
} }
} }

View File

@ -1,10 +1,11 @@
using Microsoft.Win32; using Microsoft.Win32;
using RhSolutions.Interface; using RhSolutions.Controllers;
using RhSolutions.Models;
using System; using System;
using System.IO; using System.IO;
using System.Windows.Forms; using System.Windows.Forms;
namespace RhSolutions namespace RhSolutions.Services
{ {
static class RegistryUtil static class RegistryUtil
{ {

View File

@ -0,0 +1,62 @@
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
{
private static HttpClient httpClient = RhSolutionsAddIn.httpClient;
public static async Task<object> GetProduct(string line)
{
string request = string.Empty;
if (line.IsRehauSku())
{
request = @"https://rh.cebotari.ru/api/products/" + line;
}
else
{
request = @"https://rh.cebotari.ru/api/search?query=" + line;
}
var response = await 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
{
if (line.IsRehauSku())
{
return product.Name;
}
else
{
return $"{product.ProductSku} {product.Name}";
}
}
}
catch
{
return $"Ошибка сервера {response.StatusCode}";
}
}
}
}