├── README.md ├── GS1Parser ├── GS1Parser.sln └── GS1Parser │ ├── Properties │ └── AssemblyInfo.cs │ ├── GS1Parser.csproj │ └── GS1.cs ├── LICENSE ├── .gitattributes └── .gitignore /README.md: -------------------------------------------------------------------------------- 1 | # GS1Parser 2 | A GS1 Parser for C# 3 | 4 | Input a string, get a dictionary of GS1 Application Identifiers. 5 | 6 | Originally developed from a Stackoverflow Answer 7 | 8 | http://stackoverflow.com/questions/9721718/ean128-or-gs1-128-decode-c-sharp/28854802#28854802 -------------------------------------------------------------------------------- /GS1Parser/GS1Parser.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GS1Parser", "GS1Parser\GS1Parser.csproj", "{0C089F3C-680F-4AD0-8070-715C4A4C3850}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {0C089F3C-680F-4AD0-8070-715C4A4C3850}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {0C089F3C-680F-4AD0-8070-715C4A4C3850}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {0C089F3C-680F-4AD0-8070-715C4A4C3850}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {0C089F3C-680F-4AD0-8070-715C4A4C3850}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Israel Lopez 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /GS1Parser/GS1Parser/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("GS1Parser")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("GS1Parser")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("d527a178-b78f-4ca1-97f4-df88ccc2efff")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /GS1Parser/GS1Parser/GS1Parser.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {0C089F3C-680F-4AD0-8070-715C4A4C3850} 8 | Library 9 | Properties 10 | GS1Parser 11 | GS1Parser 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 53 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | build/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studo 2015 cache/options directory 26 | .vs/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | # NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | *_i.c 42 | *_p.c 43 | *_i.h 44 | *.ilk 45 | *.meta 46 | *.obj 47 | *.pch 48 | *.pdb 49 | *.pgc 50 | *.pgd 51 | *.rsp 52 | *.sbr 53 | *.tlb 54 | *.tli 55 | *.tlh 56 | *.tmp 57 | *.tmp_proj 58 | *.log 59 | *.vspscc 60 | *.vssscc 61 | .builds 62 | *.pidb 63 | *.svclog 64 | *.scc 65 | 66 | # Chutzpah Test files 67 | _Chutzpah* 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | *.cachefile 76 | 77 | # Visual Studio profiler 78 | *.psess 79 | *.vsp 80 | *.vspx 81 | 82 | # TFS 2012 Local Workspace 83 | $tf/ 84 | 85 | # Guidance Automation Toolkit 86 | *.gpState 87 | 88 | # ReSharper is a .NET coding add-in 89 | _ReSharper*/ 90 | *.[Rr]e[Ss]harper 91 | *.DotSettings.user 92 | 93 | # JustCode is a .NET coding addin-in 94 | .JustCode 95 | 96 | # TeamCity is a build add-in 97 | _TeamCity* 98 | 99 | # DotCover is a Code Coverage Tool 100 | *.dotCover 101 | 102 | # NCrunch 103 | _NCrunch_* 104 | .*crunch*.local.xml 105 | 106 | # MightyMoose 107 | *.mm.* 108 | AutoTest.Net/ 109 | 110 | # Web workbench (sass) 111 | .sass-cache/ 112 | 113 | # Installshield output folder 114 | [Ee]xpress/ 115 | 116 | # DocProject is a documentation generator add-in 117 | DocProject/buildhelp/ 118 | DocProject/Help/*.HxT 119 | DocProject/Help/*.HxC 120 | DocProject/Help/*.hhc 121 | DocProject/Help/*.hhk 122 | DocProject/Help/*.hhp 123 | DocProject/Help/Html2 124 | DocProject/Help/html 125 | 126 | # Click-Once directory 127 | publish/ 128 | 129 | # Publish Web Output 130 | *.[Pp]ublish.xml 131 | *.azurePubxml 132 | # TODO: Comment the next line if you want to checkin your web deploy settings 133 | # but database connection strings (with potential passwords) will be unencrypted 134 | *.pubxml 135 | *.publishproj 136 | 137 | # NuGet Packages 138 | *.nupkg 139 | # The packages folder can be ignored because of Package Restore 140 | **/packages/* 141 | # except build/, which is used as an MSBuild target. 142 | !**/packages/build/ 143 | # Uncomment if necessary however generally it will be regenerated when needed 144 | #!**/packages/repositories.config 145 | 146 | # Windows Azure Build Output 147 | csx/ 148 | *.build.csdef 149 | 150 | # Windows Store app package directory 151 | AppPackages/ 152 | 153 | # Others 154 | *.[Cc]ache 155 | ClientBin/ 156 | [Ss]tyle[Cc]op.* 157 | ~$* 158 | *~ 159 | *.dbmdl 160 | *.dbproj.schemaview 161 | *.pfx 162 | *.publishsettings 163 | node_modules/ 164 | bower_components/ 165 | 166 | # RIA/Silverlight projects 167 | Generated_Code/ 168 | 169 | # Backup & report files from converting an old project file 170 | # to a newer Visual Studio version. Backup files are not needed, 171 | # because we have git ;-) 172 | _UpgradeReport_Files/ 173 | Backup*/ 174 | UpgradeLog*.XML 175 | UpgradeLog*.htm 176 | 177 | # SQL Server files 178 | *.mdf 179 | *.ldf 180 | 181 | # Business Intelligence projects 182 | *.rdl.data 183 | *.bim.layout 184 | *.bim_*.settings 185 | 186 | # Microsoft Fakes 187 | FakesAssemblies/ 188 | 189 | # Node.js Tools for Visual Studio 190 | .ntvs_analysis.dat 191 | 192 | # Visual Studio 6 build log 193 | *.plg 194 | 195 | # Visual Studio 6 workspace options file 196 | *.opt 197 | -------------------------------------------------------------------------------- /GS1Parser/GS1Parser/GS1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace GS1Parser 8 | { 9 | public static class GS1 10 | { 11 | public enum DataType 12 | { 13 | Numeric, 14 | Alphanumeric 15 | } 16 | 17 | /// 18 | /// Information Class for an Application Identifier (AI) 19 | /// 20 | public class AII 21 | { 22 | public string AI { get; set; } 23 | public string Description { get; set; } 24 | public int LengthOfAI { get; set; } 25 | public DataType DataDescription { get; set; } 26 | public int LengthOfData { get; set; } 27 | public bool FNC1 { get; set; } 28 | 29 | public AII(string AI, string Description, int LengthOfAI, DataType DataDescription, int LengthOfData, bool FNC1) 30 | { 31 | this.AI = AI; 32 | this.Description = Description; 33 | this.LengthOfAI = LengthOfAI; 34 | this.DataDescription = DataDescription; 35 | this.LengthOfData = LengthOfData; 36 | this.FNC1 = FNC1; 37 | } 38 | 39 | public override string ToString() 40 | { 41 | return String.Format("{0} [{1}]", AI, Description); 42 | } 43 | } 44 | 45 | private static SortedDictionary aiiDict = new SortedDictionary(); 46 | private static string[] aiis; 47 | private static int minLengthOfAI = 1; 48 | private static int maxLengthOfAI = 4; 49 | private static char groupSeparator = (char)29; 50 | private static string ean128StartCode = "]C1"; 51 | private static bool hasCheckSum = true; 52 | 53 | public static bool HasCheckSum 54 | { 55 | get { return GS1.hasCheckSum; } 56 | set { GS1.hasCheckSum = value; } 57 | } 58 | 59 | public static char GroupSeparator 60 | { 61 | get { return GS1.groupSeparator; } 62 | set { GS1.groupSeparator = value; } 63 | } 64 | 65 | public static string EAN128StartCode 66 | { 67 | get { return GS1.ean128StartCode; } 68 | set { GS1.ean128StartCode = value; } 69 | } 70 | 71 | static GS1() 72 | { 73 | Add("00", "SerialShippingContainerCode", 2, DataType.Numeric, 18, false); 74 | Add("01", "EAN-NumberOfTradingUnit", 2, DataType.Numeric, 14, false); 75 | Add("02", "EAN-NumberOfTheWaresInTheShippingUnit", 2, DataType.Numeric, 14, false); 76 | Add("10", "Charge_Number", 2, DataType.Alphanumeric, 20, true); 77 | Add("11", "ProducerDate_JJMMDD", 2, DataType.Numeric, 6, false); 78 | Add("12", "DueDate_JJMMDD", 2, DataType.Numeric, 6, false); 79 | Add("13", "PackingDate_JJMMDD", 2, DataType.Numeric, 6, false); 80 | Add("15", "MinimumDurabilityDate_JJMMDD", 2, DataType.Numeric, 6, false); 81 | Add("17", "ExpiryDate_JJMMDD", 2, DataType.Numeric, 6, false); 82 | Add("20", "ProductModel", 2, DataType.Numeric, 2, false); 83 | Add("21", "SerialNumber", 2, DataType.Alphanumeric, 20, true); 84 | Add("22", "HIBCCNumber", 2, DataType.Alphanumeric, 29, false); 85 | Add("240", "PruductIdentificationOfProducer", 3, DataType.Alphanumeric, 30, true); 86 | Add("241", "CustomerPartsNumber", 3, DataType.Alphanumeric, 30, true); 87 | Add("250", "SerialNumberOfAIntegratedModule", 3, DataType.Alphanumeric, 30, true); 88 | Add("251", "ReferenceToTheBasisUnit", 3, DataType.Alphanumeric, 30, true); 89 | Add("252", "GlobalIdentifierSerialisedForTrade", 3, DataType.Numeric, 2, false); 90 | Add("30", "AmountInParts", 2, DataType.Numeric, 8, true); 91 | Add("310d", "NetWeight_Kilogram", 4, DataType.Numeric, 6, false); 92 | Add("311d", "Length_Meter", 4, DataType.Numeric, 6, false); 93 | Add("312d", "Width_Meter", 4, DataType.Numeric, 6, false); 94 | Add("313d", "Heigth_Meter", 4, DataType.Numeric, 6, false); 95 | Add("314d", "Surface_SquareMeter", 4, DataType.Numeric, 6, false); 96 | Add("315d", "NetVolume_Liters", 4, DataType.Numeric, 6, false); 97 | Add("316d", "NetVolume_CubicMeters", 4, DataType.Numeric, 6, false); 98 | Add("320d", "NetWeight_Pounds", 4, DataType.Numeric, 6, false); 99 | Add("321d", "Length_Inches", 4, DataType.Numeric, 6, false); 100 | Add("322d", "Length_Feet", 4, DataType.Numeric, 6, false); 101 | Add("323d", "Length_Yards", 4, DataType.Numeric, 6, false); 102 | Add("324d", "Width_Inches", 4, DataType.Numeric, 6, false); 103 | Add("325d", "Width_Feed", 4, DataType.Numeric, 6, false); 104 | Add("326d", "Width_Yards", 4, DataType.Numeric, 6, false); 105 | Add("327d", "Heigth_Inches", 4, DataType.Numeric, 6, false); 106 | Add("328d", "Heigth_Feed", 4, DataType.Numeric, 6, false); 107 | Add("329d", "Heigth_Yards", 4, DataType.Numeric, 6, false); 108 | Add("330d", "GrossWeight_Kilogram", 4, DataType.Numeric, 6, false); 109 | Add("331d", "Length_Meter", 4, DataType.Numeric, 6, false); 110 | Add("332d", "Width_Meter", 4, DataType.Numeric, 6, false); 111 | Add("333d", "Heigth_Meter", 4, DataType.Numeric, 6, false); 112 | Add("334d", "Surface_SquareMeter", 4, DataType.Numeric, 6, false); 113 | Add("335d", "GrossVolume_Liters", 4, DataType.Numeric, 6, false); 114 | Add("336d", "GrossVolume_CubicMeters", 4, DataType.Numeric, 6, false); 115 | Add("337d", "KilogramPerSquareMeter", 4, DataType.Numeric, 6, false); 116 | Add("340d", "GrossWeight_Pounds", 4, DataType.Numeric, 6, false); 117 | Add("341d", "Length_Inches", 4, DataType.Numeric, 6, false); 118 | Add("342d", "Length_Feet", 4, DataType.Numeric, 6, false); 119 | Add("343d", "Length_Yards", 4, DataType.Numeric, 6, false); 120 | Add("344d", "Width_Inches", 4, DataType.Numeric, 6, false); 121 | Add("345d", "Width_Feed", 4, DataType.Numeric, 6, false); 122 | Add("346d", "Width_Yards", 4, DataType.Numeric, 6, false); 123 | Add("347d", "Heigth_Inches", 4, DataType.Numeric, 6, false); 124 | Add("348d", "Heigth_Feed", 4, DataType.Numeric, 6, false); 125 | Add("349d", "Heigth_Yards", 4, DataType.Numeric, 6, false); 126 | Add("350d", "Surface_SquareInches", 4, DataType.Numeric, 6, false); 127 | Add("351d", "Surface_SquareFeet", 4, DataType.Numeric, 6, false); 128 | Add("352d", "Surface_SquareYards", 4, DataType.Numeric, 6, false); 129 | Add("353d", "Surface_SquareInches", 4, DataType.Numeric, 6, false); 130 | Add("354d", "Surface_SquareFeed", 4, DataType.Numeric, 6, false); 131 | Add("355d", "Surface_SquareYards", 4, DataType.Numeric, 6, false); 132 | Add("356d", "NetWeight_TroyOunces", 4, DataType.Numeric, 6, false); 133 | Add("357d", "NetVolume_Ounces", 4, DataType.Numeric, 6, false); 134 | Add("360d", "NetVolume_Quarts", 4, DataType.Numeric, 6, false); 135 | Add("361d", "NetVolume_Gallonen", 4, DataType.Numeric, 6, false); 136 | Add("362d", "GrossVolume_Quarts", 4, DataType.Numeric, 6, false); 137 | Add("363d", "GrossVolume_Gallonen", 4, DataType.Numeric, 6, false); 138 | Add("364d", "NetVolume_CubicInches", 4, DataType.Numeric, 6, false); 139 | Add("365d", "NetVolume_CubicFeet", 4, DataType.Numeric, 6, false); 140 | Add("366d", "NetVolume_CubicYards", 4, DataType.Numeric, 6, false); 141 | Add("367d", "GrossVolume_CubicInches", 4, DataType.Numeric, 6, false); 142 | Add("368d", "GrossVolume_CubicFeet", 4, DataType.Numeric, 6, false); 143 | Add("369d", "GrossVolume_CubicYards", 4, DataType.Numeric, 6, false); 144 | Add("37", "QuantityInParts", 2, DataType.Numeric, 8, true); 145 | Add("390d", "AmountDue_DefinedValutaBand", 4, DataType.Numeric, 15, true); 146 | Add("391d", "AmountDue_WithISOValutaCode", 4, DataType.Numeric, 18, true); 147 | Add("392d", "BePayingAmount_DefinedValutaBand", 4, DataType.Numeric, 15, true); 148 | Add("393d", "BePayingAmount_WithISOValutaCode", 4, DataType.Numeric, 18, true); 149 | Add("400", "JobNumberOfGoodsRecipient", 3, DataType.Alphanumeric, 30, true); 150 | Add("401", "ShippingNumber", 3, DataType.Alphanumeric, 30, true); 151 | Add("402", "DeliveryNumber", 3, DataType.Numeric, 17, false); 152 | Add("403", "RoutingCode", 3, DataType.Alphanumeric, 30, true); 153 | Add("410", "EAN_UCC_GlobalLocationNumber(GLN)_GoodsRecipient", 3, DataType.Numeric, 13, false); 154 | Add("411", "EAN_UCC_GlobalLocationNumber(GLN)_InvoiceRecipient", 3, DataType.Numeric, 13, false); 155 | Add("412", "EAN_UCC_GlobalLocationNumber(GLN)_Distributor", 3, DataType.Numeric, 13, false); 156 | Add("413", "EAN_UCC_GlobalLocationNumber(GLN)_FinalRecipient", 3, DataType.Numeric, 13, false); 157 | Add("414", "EAN_UCC_GlobalLocationNumber(GLN)_PhysicalLocation", 3, DataType.Numeric, 13, false); 158 | Add("415", "EAN_UCC_GlobalLocationNumber(GLN)_ToBilligParticipant", 3, DataType.Numeric, 13, false); 159 | Add("420", "ZipCodeOfRecipient_withoutCountryCode", 3, DataType.Alphanumeric, 20, true); 160 | Add("421", "ZipCodeOfRecipient_withCountryCode", 3, DataType.Alphanumeric, 12, true); 161 | Add("422", "BasisCountryOfTheWares_ISO3166Format", 3, DataType.Numeric, 3, false); 162 | Add("7001", "Nato Stock Number", 4, DataType.Numeric, 13, false); 163 | Add("8001", "RolesProducts", 4, DataType.Numeric, 14, false); 164 | Add("8002", "SerialNumberForMobilePhones", 4, DataType.Alphanumeric, 20, true); 165 | Add("8003", "GlobalReturnableAssetIdentifier", 4, DataType.Alphanumeric, 34, true); 166 | Add("8004", "GlobalIndividualAssetIdentifier", 4, DataType.Numeric, 30, true); 167 | Add("8005", "SalesPricePerUnit", 4, DataType.Numeric, 6, false); 168 | Add("8006", "IdentifikationOfAProductComponent", 4, DataType.Numeric, 18, false); 169 | Add("8007", "IBAN", 4, DataType.Alphanumeric, 30, true); 170 | Add("8008", "DataAndTimeOfManufacturing", 4, DataType.Numeric, 12, true); 171 | Add("8018", "GlobalServiceRelationNumber", 4, DataType.Numeric, 18, false); 172 | Add("8020", "NumberBillCoverNumber", 4, DataType.Alphanumeric, 25, false); 173 | Add("8100", "CouponExtendedCode_NSC_offerCcode", 4, DataType.Numeric, 10, false); 174 | Add("8101", "CouponExtendedCode_NSC_offerCcode_EndOfOfferCode", 4, DataType.Numeric, 14, false); 175 | Add("8102", "CouponExtendedCode_NSC", 4, DataType.Numeric, 6, false); 176 | Add("90", "InformationForBilateralCoordinatedApplications", 2, DataType.Alphanumeric, 30, true); 177 | //Add("91", "Company specific", 2, DataType.Alphanumeric, 30, true); 178 | //Add("92", "Company specific", 2, DataType.Alphanumeric, 30, true); 179 | //Add("93", "Company specific", 2, DataType.Alphanumeric, 30, true); 180 | //Add("94", "Company specific", 2, DataType.Alphanumeric, 30, true); 181 | //Add("95", "Company specific", 2, DataType.Alphanumeric, 30, true); 182 | //Add("96", "Company specific", 2, DataType.Alphanumeric, 30, true); 183 | //Add("97", "Company specific", 2, DataType.Alphanumeric, 30, true); 184 | //Add("98", "Company specific", 2, DataType.Alphanumeric, 30, true); 185 | //Add("99", "Company specific", 2, DataType.Alphanumeric, 30, true); 186 | aiis = aiiDict.Keys.ToArray(); 187 | minLengthOfAI = aiiDict.Values.Min(el => el.LengthOfAI); 188 | maxLengthOfAI = aiiDict.Values.Max(el => el.LengthOfAI); 189 | 190 | } 191 | /// 192 | /// Add an Application Identifier (AI) 193 | /// 194 | /// Number of the AI 195 | /// 196 | /// 197 | /// The type of the content 198 | /// The max lenght of the content 199 | /// Support a group seperator 200 | public static void Add(string AI, string Description, int LengthOfAI, DataType DataDescription, int LengthOfData, bool FNC1) 201 | { 202 | aiiDict[AI] = new AII(AI, Description, LengthOfAI, DataDescription, LengthOfData, FNC1); 203 | } 204 | 205 | /// 206 | /// Parse the ean128 code 207 | /// 208 | /// The raw scanner data 209 | /// If an exception will be thrown if an AI cannot be found 210 | /// The different parts of the ean128 code 211 | public static Dictionary Parse(string data, bool throwException = false) 212 | { 213 | // cut off the EAN128 start code 214 | if (data.StartsWith(EAN128StartCode)) 215 | data = data.Substring(EAN128StartCode.Length); 216 | // cut off the check sum 217 | if (HasCheckSum) 218 | data = data.Substring(0, data.Length - 2); 219 | 220 | Dictionary result = new Dictionary(); 221 | int index = 0; 222 | // walkk through the EAN128 code 223 | while (index < data.Length) 224 | { 225 | // try to get the AI at the current position 226 | var ai = GetAI(data, ref index); 227 | if (ai == null) 228 | { 229 | if (throwException) 230 | throw new InvalidOperationException("AI not found"); 231 | return result; 232 | } 233 | // get the data to the current AI 234 | string code = GetCode(data, ai, ref index); 235 | result[ai] = code; 236 | } 237 | 238 | return result; 239 | } 240 | 241 | /// 242 | /// Try to get the AI at the current position 243 | /// 244 | /// The row data from the scanner 245 | /// The refrence of the current position 246 | /// Sets if the last character of the AI should replaced with a placehoder ("d") 247 | /// The current AI or null if no match was found 248 | private static AII GetAI(string data, ref int index, bool usePlaceHolder = false) 249 | { 250 | AII result = null; 251 | // Step through the different lenghts of the AIs 252 | for (int i = minLengthOfAI; i <= maxLengthOfAI; i++) 253 | { 254 | // get the AI sub string 255 | string ai = data.Substring(index, i); 256 | if (usePlaceHolder) 257 | ai = ai.Remove(ai.Length - 1) + "d"; 258 | // try to get the ai from the dictionary 259 | if (aiiDict.TryGetValue(ai, out result)) 260 | { 261 | // Shift the index to the next 262 | index += i; 263 | return result; 264 | } 265 | // if no AI found, try it with the next lenght 266 | } 267 | // if no AI found here, than try it with placeholders. Assumed that is the first sep where usePlaceHolder is false 268 | if (!usePlaceHolder) 269 | result = GetAI(data, ref index, true); 270 | return result; 271 | } 272 | 273 | /// 274 | /// Get the current code to the AI 275 | /// 276 | /// The row data from the scanner 277 | /// The current AI 278 | /// The refrence of the current position 279 | /// the data to the current AI 280 | private static string GetCode(string data, AII ai, ref int index) 281 | { 282 | // get the max lenght to read. 283 | int lenghtToRead = Math.Min(ai.LengthOfData, data.Length - index); 284 | // get the data of the current AI 285 | string result = data.Substring(index, lenghtToRead); 286 | // check if the AI support a group seperator 287 | if (ai.FNC1) 288 | { 289 | // try to find the index of the group seperator 290 | int indexOfGroupTermination = result.IndexOf(GroupSeparator); 291 | if (indexOfGroupTermination >= 0) 292 | lenghtToRead = indexOfGroupTermination + 1; 293 | // get the data of the current AI till the gorup seperator 294 | result = data.Substring(index, lenghtToRead); 295 | } 296 | 297 | // Shift the index to the next 298 | index += lenghtToRead; 299 | return result; 300 | } 301 | } 302 | } 303 | --------------------------------------------------------------------------------