aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2022-07-04 09:08:02 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2022-07-04 09:08:02 +0300
commit538d83257a71a0795071d104343ac3b1e35a1569 (patch)
tree252957b0da3ee402d910dddecd799bab683a7287
parentf0dc286f9020146a95471506385a4d99d7200595 (diff)
Add SKU Parser Function
-rw-r--r--src/AddIn/Functions.cs13
-rw-r--r--src/AddIn/RehauSku.cs67
-rw-r--r--src/Properties/AssemblyInfo.cs4
-rw-r--r--src/RehauSku.Assist.csproj1
4 files changed, 83 insertions, 2 deletions
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 @@
</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" />