diff --git a/src/AddIn/Functions.cs b/src/AddIn/Functions.cs index 618d17d..867e246 100644 --- a/src/AddIn/Functions.cs +++ b/src/AddIn/Functions.cs @@ -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; + } } } \ No newline at end of file diff --git a/src/AddIn/RehauSku.cs b/src/AddIn/RehauSku.cs new file mode 100644 index 0000000..40e5d30 --- /dev/null +++ b/src/AddIn/RehauSku.cs @@ -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}"; + } + } +} \ No newline at end of file diff --git a/src/Properties/AssemblyInfo.cs b/src/Properties/AssemblyInfo.cs index d254dfc..6a5c3a2 100644 --- a/src/Properties/AssemblyInfo.cs +++ b/src/Properties/AssemblyInfo.cs @@ -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")] diff --git a/src/RehauSku.Assist.csproj b/src/RehauSku.Assist.csproj index 8a2990b..16ae27e 100644 --- a/src/RehauSku.Assist.csproj +++ b/src/RehauSku.Assist.csproj @@ -116,6 +116,7 @@ +