Add SKU Parser Function
This commit is contained in:
parent
f0dc286f90
commit
538d83257a
@ -52,5 +52,18 @@ namespace RehauSku
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
[ExcelFunction(Description = "Получение корректного артикула из строки")]
|
||||
public static object GETRAUSKU([ExcelArgument(Name = "\"Строка\"", Description = "строка, содержащая актикул")] string line)
|
||||
{
|
||||
RauSku rausku;
|
||||
|
||||
if (RauSku.TryParse(line, out rausku))
|
||||
{
|
||||
return rausku.ToString();
|
||||
}
|
||||
|
||||
else return ExcelError.ExcelErrorNA;
|
||||
}
|
||||
}
|
||||
}
|
67
src/AddIn/RehauSku.cs
Normal file
67
src/AddIn/RehauSku.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace RehauSku
|
||||
{
|
||||
internal class RauSku
|
||||
{
|
||||
public string Sku { get; private set; }
|
||||
public string Variant { get; private set; }
|
||||
|
||||
public RauSku(string sku, string variant)
|
||||
{
|
||||
Sku = sku;
|
||||
Variant = variant;
|
||||
}
|
||||
|
||||
public static bool TryParse(string line, out RauSku rehauSku)
|
||||
{
|
||||
Match match;
|
||||
match = Regex.Match(line, @"\b[1]\d{6}[1]\d{3}\b");
|
||||
if (match.Success)
|
||||
{
|
||||
string sku = match.Value.Substring(1, 6);
|
||||
string variant = match.Value.Substring(8, 3);
|
||||
rehauSku = new RauSku(sku, variant);
|
||||
return true;
|
||||
}
|
||||
|
||||
match = Regex.Match(line, @"\b\d{6}\D\d{3}\b");
|
||||
if (match.Success)
|
||||
{
|
||||
string sku = match.Value.Substring(0, 6);
|
||||
string variant = match.Value.Substring(7, 3);
|
||||
rehauSku = new RauSku(sku, variant);
|
||||
return true;
|
||||
}
|
||||
|
||||
match = Regex.Match(line, @"\b\d{9}\b");
|
||||
if (match.Success)
|
||||
{
|
||||
string sku = match.Value.Substring(0, 6);
|
||||
string variant = match.Value.Substring(6, 3);
|
||||
rehauSku = new RauSku(sku, variant);
|
||||
return true;
|
||||
}
|
||||
|
||||
match = Regex.Match(line, @"\b\d{6}\b");
|
||||
if (match.Success)
|
||||
{
|
||||
string sku = match.Value.Substring(0, 6);
|
||||
string variant = "001";
|
||||
rehauSku = new RauSku(sku, variant);
|
||||
return true;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
rehauSku = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"1{Sku}1{Variant}";
|
||||
}
|
||||
}
|
||||
}
|
@ -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.4.3")]
|
||||
[assembly: AssemblyFileVersion("1.0.4.3")]
|
||||
[assembly: AssemblyVersion("1.0.5.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.5.0")]
|
||||
|
@ -116,6 +116,7 @@
|
||||
</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" />
|
||||
|
Loading…
Reference in New Issue
Block a user