Compare commits
12 Commits
598ffe0d3c
...
8ac3234473
Author | SHA1 | Date | |
---|---|---|---|
|
8ac3234473 | ||
|
c91f231892 | ||
|
a9ffc5510d | ||
|
64d0abd006 | ||
|
6137433aef | ||
|
73569a4364 | ||
|
3d186c22e8 | ||
|
bfada8d605 | ||
|
e427d63e77 | ||
|
36c4d4480d | ||
|
84137845fd | ||
|
3c7e24ecfe |
@ -1,12 +1,13 @@
|
||||
using ExcelDna.Integration;
|
||||
using ExcelDna.IntelliSense;
|
||||
using Microsoft.Office.Interop.Excel;
|
||||
using RhSolutions.Services;
|
||||
using System.Net;
|
||||
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 HttpClient httpClient;
|
||||
@ -18,6 +19,11 @@ namespace RhSolutions
|
||||
IntelliSenseServer.Install();
|
||||
RegistryUtil.Initialize();
|
||||
EventsUtil.Initialize();
|
||||
|
||||
ServicePointManager.SecurityProtocol =
|
||||
SecurityProtocolType.Tls12 |
|
||||
SecurityProtocolType.Tls11 |
|
||||
SecurityProtocolType.Tls;
|
||||
}
|
||||
|
||||
public void AutoClose()
|
||||
|
@ -1,27 +1,10 @@
|
||||
using ExcelDna.Integration;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using RhSolutions.Services;
|
||||
|
||||
namespace RhSolutions
|
||||
namespace RhSolutions.AddIn
|
||||
{
|
||||
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 = "Запрос в удаленную базу данных")]
|
||||
public static object RHSOLUTIONS([ExcelArgument(Name = "Запрос")] string line)
|
||||
{
|
||||
@ -45,40 +28,4 @@ namespace RhSolutions
|
||||
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; }
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
using Microsoft.Office.Interop.Excel;
|
||||
using RhSolutions.Interface;
|
||||
using RhSolutions.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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; }
|
||||
|
@ -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; }
|
||||
|
@ -1,13 +1,13 @@
|
||||
using Microsoft.Office.Interop.Excel;
|
||||
using System;
|
||||
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;
|
||||
|
||||
public ExportTool()
|
||||
@ -40,7 +40,7 @@ namespace RhSolutions.PriceListTools
|
||||
private void GetSelected()
|
||||
{
|
||||
object[,] cells = Selection.Value2;
|
||||
PositionAmount = new Dictionary<Position, double>();
|
||||
PositionAmount = new Dictionary<Product, double>();
|
||||
|
||||
int rowsCount = Selection.Rows.Count;
|
||||
|
||||
@ -56,7 +56,7 @@ namespace RhSolutions.PriceListTools
|
||||
{
|
||||
object current = cells[row, column];
|
||||
|
||||
if (RauSku.TryParse(current.ToString(), out RauSku rauSku))
|
||||
if (Sku.TryParse(current.ToString(), out Sku rauSku))
|
||||
{
|
||||
sku = rauSku.ToString();
|
||||
}
|
||||
@ -78,7 +78,10 @@ namespace RhSolutions.PriceListTools
|
||||
continue;
|
||||
}
|
||||
|
||||
Position position = new Position(null, sku, null);
|
||||
Product position = new Product
|
||||
{
|
||||
ProductSku = sku
|
||||
};
|
||||
|
||||
if (PositionAmount.ContainsKey(position))
|
||||
{
|
@ -1,11 +1,11 @@
|
||||
using RhSolutions.Interface;
|
||||
using RhSolutions.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace RhSolutions.PriceListTools
|
||||
namespace RhSolutions.Controllers
|
||||
{
|
||||
internal class MergeTool : AbstractTool
|
||||
internal class MergeTool : ToolBase
|
||||
{
|
||||
private List<SourcePriceList> SourceFiles { get; set; }
|
||||
|
@ -1,13 +1,14 @@
|
||||
using ExcelDna.Integration.CustomUI;
|
||||
using Microsoft.Office.Interop.Excel;
|
||||
using RhSolutions.PriceListTools;
|
||||
using RhSolutions.AddIn;
|
||||
using RhSolutions.Services;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace RhSolutions.Interface
|
||||
namespace RhSolutions.Controllers
|
||||
{
|
||||
[ComVisible(true)]
|
||||
public class RibbonController : ExcelRibbon
|
||||
@ -52,7 +53,7 @@ namespace RhSolutions.Interface
|
||||
}
|
||||
public void OnSetPricePressed(IRibbonControl control)
|
||||
{
|
||||
string path = Dialog.GetFilePath();
|
||||
string path = Models.Dialog.GetFilePath();
|
||||
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
@ -64,7 +65,7 @@ namespace RhSolutions.Interface
|
||||
{
|
||||
try
|
||||
{
|
||||
AbstractTool tool;
|
||||
ToolBase tool;
|
||||
switch (control.Id)
|
||||
{
|
||||
case "export":
|
||||
@ -93,31 +94,31 @@ namespace RhSolutions.Interface
|
||||
"Ошибка",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Information);
|
||||
AddIn.Excel.StatusBar = false;
|
||||
RhSolutionsAddIn.Excel.StatusBar = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetConvertEnabled(IRibbonControl control)
|
||||
{
|
||||
if (AddIn.Excel.ActiveWorkbook == null)
|
||||
if (RhSolutionsAddIn.Excel.ActiveWorkbook == null)
|
||||
return false;
|
||||
|
||||
else
|
||||
{
|
||||
Worksheet worksheet = AddIn.Excel.ActiveWorkbook.ActiveSheet;
|
||||
Worksheet worksheet = RhSolutionsAddIn.Excel.ActiveWorkbook.ActiveSheet;
|
||||
return worksheet.IsRehauSource();
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetExportEnabled(IRibbonControl control)
|
||||
{
|
||||
if (AddIn.Excel.ActiveWorkbook == null)
|
||||
if (RhSolutionsAddIn.Excel.ActiveWorkbook == null)
|
||||
return false;
|
||||
|
||||
else
|
||||
{
|
||||
Range selection = AddIn.Excel.Selection;
|
||||
Range selection = RhSolutionsAddIn.Excel.Selection;
|
||||
return selection.Columns.Count == 2;
|
||||
}
|
||||
}
|
@ -1,15 +1,16 @@
|
||||
using Microsoft.Office.Interop.Excel;
|
||||
using RhSolutions.Interface;
|
||||
using RhSolutions.AddIn;
|
||||
using RhSolutions.Models;
|
||||
using RhSolutions.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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 ResultBar ResultBar { 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 skuColumn = TargetFile.SkuCell.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)
|
||||
{
|
||||
@ -65,7 +66,7 @@ namespace RhSolutions.PriceListTools
|
||||
|
||||
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)
|
||||
{
|
||||
@ -80,8 +81,8 @@ namespace RhSolutions.PriceListTools
|
||||
}
|
||||
}
|
||||
|
||||
string sku = positionAmount.Key.Sku.Substring(1, 6);
|
||||
row = GetPositionRow(skuColumn, sku, positionAmount.Key.Group);
|
||||
string sku = positionAmount.Key.ProductSku.Substring(1, 6);
|
||||
row = GetPositionRow(skuColumn, sku, positionAmount.Key.ProductLine);
|
||||
|
||||
if (row != null)
|
||||
{
|
||||
@ -99,7 +100,7 @@ namespace RhSolutions.PriceListTools
|
||||
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 worksheetRows = TargetFile.Sheet.Rows;
|
||||
@ -121,18 +122,18 @@ namespace RhSolutions.PriceListTools
|
||||
previous.Copy(current);
|
||||
current.ClearContents();
|
||||
|
||||
worksheetCells[row, groupColumn].Value2 = positionAmount.Key.Group;
|
||||
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.Sku;
|
||||
worksheetCells[row, TargetFile.OldSkuCell.Column].Value2 = positionAmount.Key.ProductSku;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
worksheetCells[row, skuColumn].Value2 = positionAmount.Key.Sku;
|
||||
worksheetCells[row, skuColumn].Value2 = positionAmount.Key.ProductSku;
|
||||
}
|
||||
|
||||
foreach (int column in columns)
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace RhSolutions.Interface
|
||||
namespace RhSolutions.Models
|
||||
{
|
||||
static class Dialog
|
||||
{
|
@ -1,8 +1,8 @@
|
||||
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 SkuCell { get; protected set; }
|
@ -1,4 +1,4 @@
|
||||
namespace RhSolutions.PriceListTools
|
||||
namespace RhSolutions.Models
|
||||
{
|
||||
internal static class PriceListHeaders
|
||||
{
|
35
src/Models/Product.cs
Normal file
35
src/Models/Product.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
namespace RhSolutions.Interface
|
||||
namespace RhSolutions.Models
|
||||
{
|
||||
internal class ProgressBar : AbstractBar
|
||||
internal class ProgressBar : StatusbarBase
|
||||
{
|
||||
private double CurrentProgress { get; set; }
|
||||
private readonly double TaskWeight;
|
||||
@ -15,7 +15,7 @@
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
double percent = (++CurrentProgress / TaskWeight) * 100;
|
||||
double percent = ++CurrentProgress / TaskWeight * 100;
|
||||
Excel.StatusBar = $"{Message} Выполнено {percent:#.#} %";
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace RhSolutions.Interface
|
||||
namespace RhSolutions.Models
|
||||
{
|
||||
internal class ResultBar : AbstractBar
|
||||
internal class ResultBar : StatusbarBase
|
||||
{
|
||||
private int Success { get; set; }
|
||||
private int Replaced { get; set; }
|
@ -1,19 +1,19 @@
|
||||
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 RauSku(string sku, string variant)
|
||||
public Sku(string article, string variant)
|
||||
{
|
||||
Sku = sku;
|
||||
Article = article;
|
||||
Variant = variant;
|
||||
}
|
||||
|
||||
public static bool TryParse(string line, out RauSku rehauSku)
|
||||
public static bool TryParse(string line, out Sku rehauSku)
|
||||
{
|
||||
Match match;
|
||||
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 variant = match.Value.Substring(8, 3);
|
||||
rehauSku = new RauSku(sku, variant);
|
||||
rehauSku = new Sku(sku, variant);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ namespace RhSolutions
|
||||
{
|
||||
string sku = match.Value.Substring(0, 6);
|
||||
string variant = match.Value.Substring(7, 3);
|
||||
rehauSku = new RauSku(sku, variant);
|
||||
rehauSku = new Sku(sku, variant);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ namespace RhSolutions
|
||||
{
|
||||
string sku = match.Value.Substring(0, 6);
|
||||
string variant = match.Value.Substring(6, 3);
|
||||
rehauSku = new RauSku(sku, variant);
|
||||
rehauSku = new Sku(sku, variant);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ namespace RhSolutions
|
||||
{
|
||||
string sku = match.Value.Substring(0, 6);
|
||||
string variant = "001";
|
||||
rehauSku = new RauSku(sku, variant);
|
||||
rehauSku = new Sku(sku, variant);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ namespace RhSolutions
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"1{Sku}1{Variant}";
|
||||
return $"1{Article}1{Variant}";
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace RhSolutions
|
||||
namespace RhSolutions.Models
|
||||
{
|
||||
static class SkuExtensions
|
||||
{
|
@ -3,13 +3,12 @@ using Microsoft.Office.Interop.Excel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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)
|
||||
{
|
||||
@ -73,7 +72,7 @@ namespace RhSolutions.PriceListTools
|
||||
|
||||
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++)
|
||||
{
|
||||
@ -91,7 +90,12 @@ namespace RhSolutions.PriceListTools
|
||||
if (!sku.ToString().IsRehauSku())
|
||||
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))
|
||||
{
|
26
src/Models/StatusbarBase.cs
Normal file
26
src/Models/StatusbarBase.cs
Normal 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());
|
||||
}
|
||||
}
|
||||
}
|
@ -2,9 +2,9 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace RhSolutions.PriceListTools
|
||||
namespace RhSolutions.Models
|
||||
{
|
||||
internal class TargetPriceList : AbstractPriceList
|
||||
internal class TargetPriceList : PriceListBase
|
||||
{
|
||||
public Range OldSkuCell { get; private set; }
|
||||
|
||||
@ -31,7 +31,7 @@ namespace RhSolutions.PriceListTools
|
||||
|
||||
if (cells.Any(x => x == null))
|
||||
{
|
||||
throw new ArgumentException($"Шаблон { Name } не является прайс-листом");
|
||||
throw new ArgumentException($"Шаблон {Name} не является прайс-листом");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
using Microsoft.Office.Interop.Excel;
|
||||
using RhSolutions.PriceListTools;
|
||||
using RhSolutions.Models;
|
||||
using System.Linq;
|
||||
|
||||
namespace RhSolutions
|
||||
namespace RhSolutions.Services
|
||||
{
|
||||
public static class WorksheetExtensions
|
||||
{
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -5,10 +5,10 @@ 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("RhXlPLugin")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyTitle("RhSolutions.AddIn")]
|
||||
[assembly: AssemblyDescription("Excel AddIn for RhSolutions")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyCompany("RhSolutions")]
|
||||
[assembly: AssemblyProduct("RhXlPLugin")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2021-2023")]
|
||||
[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
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.5.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.5.0")]
|
||||
[assembly: AssemblyVersion("1.2.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.2.0.0")]
|
||||
|
@ -1,6 +1,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">
|
||||
<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:
|
||||
|
@ -8,8 +8,8 @@
|
||||
<ProjectGuid>{18A2FF67-0E46-4A86-B872-29F2B3F23ADF}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>RhExcelAddin</RootNamespace>
|
||||
<AssemblyName>RhExcelAddin</AssemblyName>
|
||||
<RootNamespace>RhSolutions.AddIn</RootNamespace>
|
||||
<AssemblyName>RhSolutions.AddIn</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
@ -77,28 +77,29 @@
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AddIn\EventsUtil.cs" />
|
||||
<Compile Include="AddIn\RehauSku.cs" />
|
||||
<Compile Include="Interface\AbstractBar.cs" />
|
||||
<Compile Include="Interface\Dialog.cs" />
|
||||
<Compile Include="AddIn\RegistryUtil.cs" />
|
||||
<Compile Include="AddIn\SkuExtensions.cs" />
|
||||
<Compile Include="Interface\ProgressBar.cs" />
|
||||
<Compile Include="Interface\ResultBar.cs" />
|
||||
<Compile Include="PriceListTools\CombineTool.cs" />
|
||||
<Compile Include="PriceListTools\ConvertTool.cs" />
|
||||
<Compile Include="PriceListTools\Position.cs" />
|
||||
<Compile Include="PriceListTools\AbstractTool.cs" />
|
||||
<Compile Include="PriceListTools\MergeTool.cs" />
|
||||
<Compile Include="PriceListTools\AbstractPriceList.cs" />
|
||||
<Compile Include="PriceListTools\PriceListHeaders.cs" />
|
||||
<Compile Include="PriceListTools\SourcePriceList.cs" />
|
||||
<Compile Include="PriceListTools\TargetPriceList.cs" />
|
||||
<Compile Include="Interface\RibbonController.cs" />
|
||||
<Compile Include="PriceListTools\ExportTool.cs" />
|
||||
<Compile Include="Services\EventsUtil.cs" />
|
||||
<Compile Include="Services\RhDatabaseClient.cs" />
|
||||
<Compile Include="Models\Sku.cs" />
|
||||
<Compile Include="Models\StatusbarBase.cs" />
|
||||
<Compile Include="Models\Dialog.cs" />
|
||||
<Compile Include="Services\RegistryUtil.cs" />
|
||||
<Compile Include="Models\SkuExtensions.cs" />
|
||||
<Compile Include="Models\ProgressBar.cs" />
|
||||
<Compile Include="Models\ResultBar.cs" />
|
||||
<Compile Include="Controllers\CombineTool.cs" />
|
||||
<Compile Include="Controllers\ConvertTool.cs" />
|
||||
<Compile Include="Models\Product.cs" />
|
||||
<Compile Include="Controllers\ToolBase.cs" />
|
||||
<Compile Include="Controllers\MergeTool.cs" />
|
||||
<Compile Include="Models\PriceListBase.cs" />
|
||||
<Compile Include="Models\PriceListHeaders.cs" />
|
||||
<Compile Include="Models\SourcePriceList.cs" />
|
||||
<Compile Include="Models\TargetPriceList.cs" />
|
||||
<Compile Include="Controllers\RibbonController.cs" />
|
||||
<Compile Include="Controllers\ExportTool.cs" />
|
||||
<Compile Include="AddIn\AddIn.cs" />
|
||||
<Compile Include="AddIn\Functions.cs" />
|
||||
<Compile Include="AddIn\WorksheetExtensions.cs" />
|
||||
<Compile Include="Models\WorksheetExtensions.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -1,10 +1,12 @@
|
||||
using Microsoft.Office.Interop.Excel;
|
||||
using RhSolutions.AddIn;
|
||||
using RhSolutions.Controllers;
|
||||
|
||||
namespace RhSolutions
|
||||
namespace RhSolutions.Services
|
||||
{
|
||||
internal static class EventsUtil
|
||||
{
|
||||
private static readonly Application Excel = AddIn.Excel;
|
||||
private static readonly Application Excel = RhSolutionsAddIn.Excel;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
@ -22,12 +24,12 @@ namespace RhSolutions
|
||||
|
||||
private static void RefreshConvertButton(object sh)
|
||||
{
|
||||
Interface.RibbonController.RefreshControl("convert");
|
||||
RibbonController.RefreshControl("convert");
|
||||
}
|
||||
|
||||
private static void RefreshExportButton(object sh, Range target)
|
||||
{
|
||||
Interface.RibbonController.RefreshControl("export");
|
||||
RibbonController.RefreshControl("export");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,11 @@
|
||||
using Microsoft.Win32;
|
||||
using RhSolutions.Interface;
|
||||
using RhSolutions.Controllers;
|
||||
using RhSolutions.Models;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace RhSolutions
|
||||
namespace RhSolutions.Services
|
||||
{
|
||||
static class RegistryUtil
|
||||
{
|
62
src/Services/RhDatabaseClient.cs
Normal file
62
src/Services/RhDatabaseClient.cs
Normal 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}";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user