├── .gitattributes ├── .gitignore ├── BarcodeGenerator.sln ├── BarcodeGenerator ├── BarcodeGenerator.csproj ├── Code128GS1 │ ├── BarcodeImage.cs │ └── Encoder.cs └── Properties │ └── AssemblyInfo.cs ├── BarcodeGeneratorGUI ├── App.config ├── BarcodeGeneratorGUI.csproj ├── Form1.Designer.cs ├── Form1.cs ├── Form1.resx ├── Program.cs └── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── BarcodeGeneratorTest ├── BarcodeGeneratorTest.csproj ├── Properties │ └── AssemblyInfo.cs └── UnitTest1.cs └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # Visual Studio files 21 | **/bin 22 | **/obj 23 | **/*.suo 24 | **/*.vsp 25 | 26 | # ========================= 27 | # Operating System Files 28 | # ========================= 29 | 30 | # OSX 31 | # ========================= 32 | 33 | .DS_Store 34 | .AppleDouble 35 | .LSOverride 36 | 37 | # Thumbnails 38 | ._* 39 | 40 | # Files that might appear on external disk 41 | .Spotlight-V100 42 | .Trashes 43 | 44 | # Directories potentially created on remote AFP share 45 | .AppleDB 46 | .AppleDesktop 47 | Network Trash Folder 48 | Temporary Items 49 | .apdisk 50 | -------------------------------------------------------------------------------- /BarcodeGenerator.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BarcodeGenerator", "BarcodeGenerator\BarcodeGenerator.csproj", "{F8A89CA7-5DDF-4EA4-B80D-E04686A584D8}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BarcodeGeneratorGUI", "BarcodeGeneratorGUI\BarcodeGeneratorGUI.csproj", "{F94554B3-D1BD-448C-ABF8-348E47C7FA7E}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BarcodeGeneratorTest", "BarcodeGeneratorTest\BarcodeGeneratorTest.csproj", "{AFC5D390-4E80-45F1-802C-3F942857DA43}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {F8A89CA7-5DDF-4EA4-B80D-E04686A584D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {F8A89CA7-5DDF-4EA4-B80D-E04686A584D8}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {F8A89CA7-5DDF-4EA4-B80D-E04686A584D8}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {F8A89CA7-5DDF-4EA4-B80D-E04686A584D8}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {F94554B3-D1BD-448C-ABF8-348E47C7FA7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {F94554B3-D1BD-448C-ABF8-348E47C7FA7E}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {F94554B3-D1BD-448C-ABF8-348E47C7FA7E}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {F94554B3-D1BD-448C-ABF8-348E47C7FA7E}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {AFC5D390-4E80-45F1-802C-3F942857DA43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {AFC5D390-4E80-45F1-802C-3F942857DA43}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {AFC5D390-4E80-45F1-802C-3F942857DA43}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {AFC5D390-4E80-45F1-802C-3F942857DA43}.Release|Any CPU.Build.0 = Release|Any CPU 28 | EndGlobalSection 29 | GlobalSection(SolutionProperties) = preSolution 30 | HideSolutionNode = FALSE 31 | EndGlobalSection 32 | EndGlobal 33 | -------------------------------------------------------------------------------- /BarcodeGenerator/BarcodeGenerator.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {F8A89CA7-5DDF-4EA4-B80D-E04686A584D8} 8 | Library 9 | Properties 10 | BarcodeGenerator 11 | BarcodeGenerator 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 | 47 | 48 | 49 | 50 | 51 | 52 | 59 | -------------------------------------------------------------------------------- /BarcodeGenerator/Code128GS1/BarcodeImage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.Diagnostics; 4 | 5 | namespace BarcodeGenerator.Code128GS1 6 | { 7 | /// 8 | /// Summary description for Image. 9 | /// 10 | public class BarcodeImage 11 | { 12 | #region Code patterns 13 | 14 | // in principle these rows should each have 6 elements 15 | // however, the last one -- STOP -- has 7. The cost of the 16 | // extra integers is trivial, and this lets the code flow 17 | // much more elegantly 18 | private readonly int[,] cPatterns = 19 | { 20 | {2,1,2,2,2,2,0,0}, // 0 21 | {2,2,2,1,2,2,0,0}, // 1 22 | {2,2,2,2,2,1,0,0}, // 2 23 | {1,2,1,2,2,3,0,0}, // 3 24 | {1,2,1,3,2,2,0,0}, // 4 25 | {1,3,1,2,2,2,0,0}, // 5 26 | {1,2,2,2,1,3,0,0}, // 6 27 | {1,2,2,3,1,2,0,0}, // 7 28 | {1,3,2,2,1,2,0,0}, // 8 29 | {2,2,1,2,1,3,0,0}, // 9 30 | {2,2,1,3,1,2,0,0}, // 10 31 | {2,3,1,2,1,2,0,0}, // 11 32 | {1,1,2,2,3,2,0,0}, // 12 33 | {1,2,2,1,3,2,0,0}, // 13 34 | {1,2,2,2,3,1,0,0}, // 14 35 | {1,1,3,2,2,2,0,0}, // 15 36 | {1,2,3,1,2,2,0,0}, // 16 37 | {1,2,3,2,2,1,0,0}, // 17 38 | {2,2,3,2,1,1,0,0}, // 18 39 | {2,2,1,1,3,2,0,0}, // 19 40 | {2,2,1,2,3,1,0,0}, // 20 41 | {2,1,3,2,1,2,0,0}, // 21 42 | {2,2,3,1,1,2,0,0}, // 22 43 | {3,1,2,1,3,1,0,0}, // 23 44 | {3,1,1,2,2,2,0,0}, // 24 45 | {3,2,1,1,2,2,0,0}, // 25 46 | {3,2,1,2,2,1,0,0}, // 26 47 | {3,1,2,2,1,2,0,0}, // 27 48 | {3,2,2,1,1,2,0,0}, // 28 49 | {3,2,2,2,1,1,0,0}, // 29 50 | {2,1,2,1,2,3,0,0}, // 30 51 | {2,1,2,3,2,1,0,0}, // 31 52 | {2,3,2,1,2,1,0,0}, // 32 53 | {1,1,1,3,2,3,0,0}, // 33 54 | {1,3,1,1,2,3,0,0}, // 34 55 | {1,3,1,3,2,1,0,0}, // 35 56 | {1,1,2,3,1,3,0,0}, // 36 57 | {1,3,2,1,1,3,0,0}, // 37 58 | {1,3,2,3,1,1,0,0}, // 38 59 | {2,1,1,3,1,3,0,0}, // 39 60 | {2,3,1,1,1,3,0,0}, // 40 61 | {2,3,1,3,1,1,0,0}, // 41 62 | {1,1,2,1,3,3,0,0}, // 42 63 | {1,1,2,3,3,1,0,0}, // 43 64 | {1,3,2,1,3,1,0,0}, // 44 65 | {1,1,3,1,2,3,0,0}, // 45 66 | {1,1,3,3,2,1,0,0}, // 46 67 | {1,3,3,1,2,1,0,0}, // 47 68 | {3,1,3,1,2,1,0,0}, // 48 69 | {2,1,1,3,3,1,0,0}, // 49 70 | {2,3,1,1,3,1,0,0}, // 50 71 | {2,1,3,1,1,3,0,0}, // 51 72 | {2,1,3,3,1,1,0,0}, // 52 73 | {2,1,3,1,3,1,0,0}, // 53 74 | {3,1,1,1,2,3,0,0}, // 54 75 | {3,1,1,3,2,1,0,0}, // 55 76 | {3,3,1,1,2,1,0,0}, // 56 77 | {3,1,2,1,1,3,0,0}, // 57 78 | {3,1,2,3,1,1,0,0}, // 58 79 | {3,3,2,1,1,1,0,0}, // 59 80 | {3,1,4,1,1,1,0,0}, // 60 81 | {2,2,1,4,1,1,0,0}, // 61 82 | {4,3,1,1,1,1,0,0}, // 62 83 | {1,1,1,2,2,4,0,0}, // 63 84 | {1,1,1,4,2,2,0,0}, // 64 85 | {1,2,1,1,2,4,0,0}, // 65 86 | {1,2,1,4,2,1,0,0}, // 66 87 | {1,4,1,1,2,2,0,0}, // 67 88 | {1,4,1,2,2,1,0,0}, // 68 89 | {1,1,2,2,1,4,0,0}, // 69 90 | {1,1,2,4,1,2,0,0}, // 70 91 | {1,2,2,1,1,4,0,0}, // 71 92 | {1,2,2,4,1,1,0,0}, // 72 93 | {1,4,2,1,1,2,0,0}, // 73 94 | {1,4,2,2,1,1,0,0}, // 74 95 | {2,4,1,2,1,1,0,0}, // 75 96 | {2,2,1,1,1,4,0,0}, // 76 97 | {4,1,3,1,1,1,0,0}, // 77 98 | {2,4,1,1,1,2,0,0}, // 78 99 | {1,3,4,1,1,1,0,0}, // 79 100 | {1,1,1,2,4,2,0,0}, // 80 101 | {1,2,1,1,4,2,0,0}, // 81 102 | {1,2,1,2,4,1,0,0}, // 82 103 | {1,1,4,2,1,2,0,0}, // 83 104 | {1,2,4,1,1,2,0,0}, // 84 105 | {1,2,4,2,1,1,0,0}, // 85 106 | {4,1,1,2,1,2,0,0}, // 86 107 | {4,2,1,1,1,2,0,0}, // 87 108 | {4,2,1,2,1,1,0,0}, // 88 109 | {2,1,2,1,4,1,0,0}, // 89 110 | {2,1,4,1,2,1,0,0}, // 90 111 | {4,1,2,1,2,1,0,0}, // 91 112 | {1,1,1,1,4,3,0,0}, // 92 113 | {1,1,1,3,4,1,0,0}, // 93 114 | {1,3,1,1,4,1,0,0}, // 94 115 | {1,1,4,1,1,3,0,0}, // 95 116 | {1,1,4,3,1,1,0,0}, // 96 117 | {4,1,1,1,1,3,0,0}, // 97 118 | {4,1,1,3,1,1,0,0}, // 98 119 | {1,1,3,1,4,1,0,0}, // 99 120 | {1,1,4,1,3,1,0,0}, // 100 121 | {3,1,1,1,4,1,0,0}, // 101 122 | {4,1,1,1,3,1,0,0}, // 102 123 | {2,1,1,4,1,2,0,0}, // 103 124 | {2,1,1,2,1,4,0,0}, // 104 125 | {2,1,1,2,3,2,0,0}, // 105 126 | {2,3,3,1,1,1,2,0} // 106 127 | }; 128 | 129 | #endregion Code patterns 130 | 131 | private const int cQuietWidth = 10; 132 | 133 | /// 134 | /// Make an image of a Code128 barcode for a given string 135 | /// 136 | /// Message to be encoded 137 | /// Base thickness for bar width (1 or 2 works well) 138 | /// Add required horiz margins (use if output is tight) 139 | /// An Image of the Code128 barcode representing the message 140 | public Image CreateImage(int[] codes, int BarWeight, bool AddQuietZone) 141 | { 142 | // get the Code128 codes to represent the message 143 | //Encoder content = new Encoder(InputData); 144 | //int[] codes = content.Codes; 145 | 146 | int width, height; 147 | width = ((codes.Length - 3) * 11 + 35) * BarWeight; 148 | height = Convert.ToInt32(System.Math.Ceiling(Convert.ToSingle(width) * .15F)); 149 | 150 | if (AddQuietZone) 151 | { 152 | width += 2 * cQuietWidth * BarWeight; // on both sides 153 | } 154 | 155 | // get surface to draw on 156 | Image myimg = new System.Drawing.Bitmap(width, height); 157 | using (Graphics gr = Graphics.FromImage(myimg)) 158 | { 159 | 160 | // set to white so we don't have to fill the spaces with white 161 | gr.FillRectangle(System.Drawing.Brushes.White, 0, 0, width, height); 162 | 163 | // skip quiet zone 164 | int cursor = AddQuietZone ? cQuietWidth * BarWeight : 0; 165 | 166 | for (int codeidx = 0; codeidx < codes.Length; codeidx++) 167 | { 168 | int code = codes[codeidx]; 169 | 170 | // take the bars two at a time: a black and a white 171 | for (int bar = 0; bar < 8; bar += 2) 172 | { 173 | int barwidth = cPatterns[code, bar] * BarWeight; 174 | int spcwidth = cPatterns[code, bar + 1] * BarWeight; 175 | 176 | // if width is zero, don't try to draw it 177 | if (barwidth > 0) 178 | { 179 | gr.FillRectangle(System.Drawing.Brushes.Black, cursor, 0, barwidth, height); 180 | } 181 | 182 | // note that we never need to draw the space, since we 183 | // initialized the graphics to all white 184 | 185 | // advance cursor beyond this pair 186 | cursor += (barwidth + spcwidth); 187 | } 188 | } 189 | } 190 | 191 | return myimg; 192 | } 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /BarcodeGenerator/Code128GS1/Encoder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace BarcodeGenerator.Code128GS1 9 | { 10 | internal enum CodeSet 11 | { 12 | None, 13 | CodeA, 14 | CodeB, 15 | CodeC 16 | } 17 | 18 | internal enum CodeFunction 19 | { 20 | FNC1, 21 | FNC2, 22 | FNC3, 23 | FNC4, 24 | CodeA, 25 | CodeB, 26 | CodeC, 27 | ShiftA, 28 | ShiftB, 29 | StartA, 30 | StartB, 31 | StartC, 32 | Stop 33 | } 34 | 35 | internal class CodeSetEntry 36 | { 37 | #region Private fields 38 | 39 | private CodeSet codeSet; 40 | private List values = new List(); 41 | private bool setFNC1 = false; 42 | 43 | #endregion 44 | 45 | #region Public properties 46 | 47 | public List Values 48 | { 49 | get { return this.values; } 50 | } 51 | 52 | public CodeSet CodeSet 53 | { 54 | get { return this.codeSet; } 55 | set { this.codeSet = value; } 56 | } 57 | 58 | public bool SetFNC1 59 | { 60 | get { return this.setFNC1; } 61 | } 62 | 63 | #endregion 64 | 65 | #region Constructor(s) 66 | 67 | public CodeSetEntry(CodeSet codeSet, bool setFNC1) 68 | { 69 | this.codeSet = codeSet; 70 | this.setFNC1 = setFNC1; 71 | } 72 | 73 | #endregion 74 | } 75 | 76 | public class Encoder 77 | { 78 | #region Constants 79 | 80 | private const string CODE_A_VALID_CHARS = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 81 | private const string CODE_B_VALID_CHARS = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ'abcdefghijklmnopqrstuvwxyz{|}~"; 82 | private const string CODE_C_VALID_CHARS = "0123456789"; 83 | 84 | #endregion 85 | 86 | #region Fields 87 | 88 | private Dictionary> codeSetToFunctionMap = 89 | new Dictionary>() 90 | { 91 | { CodeSet.CodeA, new Dictionary() { 92 | { CodeFunction.FNC3, 96 }, 93 | { CodeFunction.FNC2, 97 }, 94 | { CodeFunction.ShiftB, 98 }, 95 | { CodeFunction.CodeC, 99 }, 96 | { CodeFunction.CodeB, 100 }, 97 | { CodeFunction.FNC4, 101 }, 98 | { CodeFunction.FNC1, 102 }, 99 | { CodeFunction.StartA, 103 }, 100 | { CodeFunction.StartB, 104 }, 101 | { CodeFunction.StartC, 105 }, 102 | { CodeFunction.Stop, 106 } } }, 103 | { CodeSet.CodeB, new Dictionary() { 104 | { CodeFunction.FNC3, 96 }, 105 | { CodeFunction.FNC2, 97 }, 106 | { CodeFunction.ShiftA, 98 }, 107 | { CodeFunction.CodeC, 99 }, 108 | { CodeFunction.FNC4, 100 }, 109 | { CodeFunction.CodeA, 101 }, 110 | { CodeFunction.FNC1, 102 }, 111 | { CodeFunction.StartA, 103 }, 112 | { CodeFunction.StartB, 104 }, 113 | { CodeFunction.StartC, 105 }, 114 | { CodeFunction.Stop, 106 } } }, 115 | { CodeSet.CodeC, new Dictionary() { 116 | { CodeFunction.CodeB, 100 }, 117 | { CodeFunction.CodeA, 101 }, 118 | { CodeFunction.FNC1, 102 }, 119 | { CodeFunction.StartA, 103 }, 120 | { CodeFunction.StartB, 104 }, 121 | { CodeFunction.StartC, 105 }, 122 | { CodeFunction.Stop, 106 } } } 123 | }; 124 | 125 | #endregion 126 | 127 | #region Private methods 128 | 129 | 130 | private int[] GenerateBarcodeValues(List codeSetEntries) 131 | { 132 | List values = new List(); 133 | CodeSet currentCodeSet = CodeSet.None; 134 | 135 | for(int i = 0; i < codeSetEntries.Count; i++) 136 | { 137 | CodeSetEntry entry = codeSetEntries[i]; 138 | 139 | if (entry.CodeSet != currentCodeSet) 140 | { 141 | if(i == 0) 142 | { 143 | CodeFunction codeFunction = 144 | entry.CodeSet == CodeSet.CodeA ? 145 | CodeFunction.StartA : 146 | entry.CodeSet == CodeSet.CodeB ? 147 | CodeFunction.StartB : 148 | CodeFunction.StartC; 149 | values.Add(codeSetToFunctionMap[entry.CodeSet][codeFunction]); 150 | } 151 | else 152 | { 153 | CodeFunction codeFunction = 154 | entry.CodeSet == CodeSet.CodeA ? 155 | CodeFunction.CodeA : 156 | entry.CodeSet == CodeSet.CodeB ? 157 | CodeFunction.CodeB : 158 | CodeFunction.CodeC; 159 | values.Add(codeSetToFunctionMap[currentCodeSet][codeFunction]); 160 | } 161 | currentCodeSet = entry.CodeSet; 162 | } 163 | if (entry.SetFNC1) 164 | { 165 | values.Add(codeSetToFunctionMap[currentCodeSet][CodeFunction.FNC1]); 166 | } 167 | if (entry.CodeSet == CodeSet.CodeC) 168 | { 169 | for (int j = 0; j < entry.Values.Count; j += 2) 170 | { 171 | int value = int.Parse(string.Format( 172 | "{0}{1}", 173 | Convert.ToChar(entry.Values[j]), 174 | Convert.ToChar(entry.Values[j + 1]))); 175 | values.Add(value); 176 | } 177 | } 178 | else 179 | { 180 | for (int j = 0; j < entry.Values.Count; j++) 181 | { 182 | values.Add(GetCodeValueForChar(entry.Values[j])); 183 | } 184 | } 185 | } 186 | values.Add(CalculateChecksum(values)); 187 | values.Add(codeSetToFunctionMap[CodeSet.CodeA][CodeFunction.Stop]); 188 | return values.ToArray(); 189 | } 190 | 191 | internal int CalculateChecksum(List values) 192 | { 193 | int sum = values[0]; 194 | for (int i = 1; i < values.Count; i++) 195 | { 196 | sum += (i * values[i]); 197 | } 198 | return sum % 103; 199 | } 200 | 201 | private List OptimizeCodeSetEntries(List codeSetEntries) 202 | { 203 | List optimizedEntryList = new List(); 204 | 205 | for (int i = 0; i < codeSetEntries.Count; i++) 206 | { 207 | CodeSetEntry entry = codeSetEntries[i]; 208 | 209 | if (entry.CodeSet == CodeSet.CodeC) 210 | { 211 | if (i == 0) 212 | { 213 | if (entry.Values.Count < 4) 214 | { 215 | entry.CodeSet = codeSetEntries[i + 1].CodeSet; 216 | } 217 | } 218 | else if (i > 0 && i < codeSetEntries.Count - 1) 219 | { 220 | if (entry.Values.Count < 6) 221 | { 222 | entry.CodeSet = codeSetEntries[i - 1].CodeSet; 223 | } 224 | } 225 | else if (i == codeSetEntries.Count - 1) 226 | { 227 | if (entry.Values.Count < 4) 228 | { 229 | entry.CodeSet = codeSetEntries[i - 1].CodeSet; 230 | } 231 | } 232 | } 233 | optimizedEntryList.Add(entry); 234 | } 235 | 236 | return optimizedEntryList; 237 | } 238 | 239 | private List AnalyzeInputString(byte[] asciiBytes) 240 | { 241 | List codeSetEntries = new List(); 242 | int index = 0; 243 | CodeSet currentCodeSet = CodeSet.None; 244 | CodeSetEntry entry = null; 245 | bool setFNC1 = false; 246 | do 247 | { 248 | char currentChar = Convert.ToChar(asciiBytes[index]); 249 | if (currentChar == '(') 250 | { 251 | index++; 252 | setFNC1 = true; 253 | continue; 254 | } 255 | char nextChar = index + 1 < asciiBytes.Length ? Convert.ToChar(asciiBytes[index + 1]) : '^'; 256 | if (CODE_C_VALID_CHARS.Contains(currentChar) && 257 | CODE_C_VALID_CHARS.Contains(nextChar)) 258 | { 259 | if (currentCodeSet == CodeSet.CodeC && !setFNC1) 260 | { 261 | entry = codeSetEntries[codeSetEntries.Count - 1]; 262 | } 263 | else 264 | { 265 | entry = new CodeSetEntry(CodeSet.CodeC, setFNC1); 266 | codeSetEntries.Add(entry); 267 | currentCodeSet = CodeSet.CodeC; 268 | } 269 | entry.Values.Add(asciiBytes[index++]); 270 | entry.Values.Add(asciiBytes[index++]); 271 | } 272 | else if (CODE_A_VALID_CHARS.Contains(currentChar)) 273 | { 274 | if (currentCodeSet == CodeSet.CodeA && !setFNC1) 275 | { 276 | entry = codeSetEntries[codeSetEntries.Count - 1]; 277 | } 278 | else 279 | { 280 | entry = new CodeSetEntry(CodeSet.CodeA, setFNC1); 281 | codeSetEntries.Add(entry); 282 | currentCodeSet = CodeSet.CodeA; 283 | } 284 | entry.Values.Add(asciiBytes[index++]); 285 | } 286 | else if (CODE_B_VALID_CHARS.Contains(currentChar)) 287 | { 288 | if (currentCodeSet == CodeSet.CodeB && !setFNC1) 289 | { 290 | entry = codeSetEntries[codeSetEntries.Count - 1]; 291 | } 292 | else 293 | { 294 | entry = new CodeSetEntry(CodeSet.CodeB, setFNC1); 295 | codeSetEntries.Add(entry); 296 | currentCodeSet = CodeSet.CodeB; 297 | } 298 | entry.Values.Add(asciiBytes[index++]); 299 | } 300 | else 301 | { 302 | // TODO: Implement exception handling! 303 | } 304 | setFNC1 = false; 305 | } while (index < asciiBytes.Length); 306 | 307 | return codeSetEntries; 308 | } 309 | 310 | internal int GetCodeValueForChar(int asciiCode) 311 | { 312 | return (asciiCode >= 32) ? asciiCode - 32 : asciiCode + 64; 313 | } 314 | 315 | #endregion 316 | 317 | #region Public methods 318 | 319 | public int[] Encode(string value) 320 | { 321 | byte[] asciiBytes = Encoding.ASCII.GetBytes(value.Replace(")","")); 322 | 323 | List codeSetEntries = AnalyzeInputString(asciiBytes); 324 | codeSetEntries = OptimizeCodeSetEntries(codeSetEntries); 325 | int[] values = GenerateBarcodeValues(codeSetEntries); 326 | 327 | return values; 328 | } 329 | 330 | #endregion 331 | } 332 | } 333 | -------------------------------------------------------------------------------- /BarcodeGenerator/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // Make internal methods visible to unit-test project 6 | [assembly: InternalsVisibleTo("BarcodeGeneratorTest")] 7 | 8 | // General Information about an assembly is controlled through the following 9 | // set of attributes. Change these attribute values to modify the information 10 | // associated with an assembly. 11 | [assembly: AssemblyTitle("BarcodeGenerator")] 12 | [assembly: AssemblyDescription("")] 13 | [assembly: AssemblyConfiguration("")] 14 | [assembly: AssemblyCompany("")] 15 | [assembly: AssemblyProduct("BarcodeGenerator")] 16 | [assembly: AssemblyCopyright("Copyright © 2015")] 17 | [assembly: AssemblyTrademark("")] 18 | [assembly: AssemblyCulture("")] 19 | 20 | // Setting ComVisible to false makes the types in this assembly not visible 21 | // to COM components. If you need to access a type in this assembly from 22 | // COM, set the ComVisible attribute to true on that type. 23 | [assembly: ComVisible(false)] 24 | 25 | // The following GUID is for the ID of the typelib if this project is exposed to COM 26 | [assembly: Guid("aab6d1e7-d357-4fa3-9da8-c93d6e4a1b5b")] 27 | 28 | // Version information for an assembly consists of the following four values: 29 | // 30 | // Major Version 31 | // Minor Version 32 | // Build Number 33 | // Revision 34 | // 35 | // You can specify all the values or you can default the Build and Revision Numbers 36 | // by using the '*' as shown below: 37 | // [assembly: AssemblyVersion("1.0.*")] 38 | [assembly: AssemblyVersion("1.0.0.0")] 39 | [assembly: AssemblyFileVersion("1.0.0.0")] 40 | -------------------------------------------------------------------------------- /BarcodeGeneratorGUI/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /BarcodeGeneratorGUI/BarcodeGeneratorGUI.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {F94554B3-D1BD-448C-ABF8-348E47C7FA7E} 8 | WinExe 9 | Properties 10 | BarcodeGeneratorGUI 11 | BarcodeGeneratorGUI 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | Form 49 | 50 | 51 | Form1.cs 52 | 53 | 54 | 55 | 56 | Form1.cs 57 | 58 | 59 | ResXFileCodeGenerator 60 | Resources.Designer.cs 61 | Designer 62 | 63 | 64 | True 65 | Resources.resx 66 | True 67 | 68 | 69 | SettingsSingleFileGenerator 70 | Settings.Designer.cs 71 | 72 | 73 | True 74 | Settings.settings 75 | True 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | {f8a89ca7-5ddf-4ea4-b80d-e04686a584d8} 84 | BarcodeGenerator 85 | 86 | 87 | 88 | 95 | -------------------------------------------------------------------------------- /BarcodeGeneratorGUI/Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace BarcodeGenerator.GUI 2 | { 3 | partial class Form1 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.btnGenerate = new System.Windows.Forms.Button(); 32 | this.label1 = new System.Windows.Forms.Label(); 33 | this.txtInput = new System.Windows.Forms.TextBox(); 34 | this.picBarcode = new System.Windows.Forms.PictureBox(); 35 | ((System.ComponentModel.ISupportInitialize)(this.picBarcode)).BeginInit(); 36 | this.SuspendLayout(); 37 | // 38 | // btnGenerate 39 | // 40 | this.btnGenerate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 41 | this.btnGenerate.Location = new System.Drawing.Point(477, 22); 42 | this.btnGenerate.Name = "btnGenerate"; 43 | this.btnGenerate.Size = new System.Drawing.Size(75, 23); 44 | this.btnGenerate.TabIndex = 0; 45 | this.btnGenerate.Text = "Generate"; 46 | this.btnGenerate.UseVisualStyleBackColor = true; 47 | this.btnGenerate.Click += new System.EventHandler(this.button1_Click); 48 | // 49 | // label1 50 | // 51 | this.label1.AutoSize = true; 52 | this.label1.Location = new System.Drawing.Point(12, 9); 53 | this.label1.Name = "label1"; 54 | this.label1.Size = new System.Drawing.Size(76, 13); 55 | this.label1.TabIndex = 1; 56 | this.label1.Text = "Barcode value"; 57 | // 58 | // txtInput 59 | // 60 | this.txtInput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 61 | | System.Windows.Forms.AnchorStyles.Right))); 62 | this.txtInput.Location = new System.Drawing.Point(12, 25); 63 | this.txtInput.Name = "txtInput"; 64 | this.txtInput.Size = new System.Drawing.Size(459, 20); 65 | this.txtInput.TabIndex = 2; 66 | // 67 | // picBarcode 68 | // 69 | this.picBarcode.Location = new System.Drawing.Point(12, 51); 70 | this.picBarcode.Name = "picBarcode"; 71 | this.picBarcode.Size = new System.Drawing.Size(540, 216); 72 | this.picBarcode.TabIndex = 3; 73 | this.picBarcode.TabStop = false; 74 | // 75 | // Form1 76 | // 77 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 78 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 79 | this.ClientSize = new System.Drawing.Size(564, 279); 80 | this.Controls.Add(this.picBarcode); 81 | this.Controls.Add(this.txtInput); 82 | this.Controls.Add(this.label1); 83 | this.Controls.Add(this.btnGenerate); 84 | this.Name = "Form1"; 85 | this.Text = "Form1"; 86 | ((System.ComponentModel.ISupportInitialize)(this.picBarcode)).EndInit(); 87 | this.ResumeLayout(false); 88 | this.PerformLayout(); 89 | 90 | } 91 | 92 | #endregion 93 | 94 | private System.Windows.Forms.Button btnGenerate; 95 | private System.Windows.Forms.Label label1; 96 | private System.Windows.Forms.TextBox txtInput; 97 | private System.Windows.Forms.PictureBox picBarcode; 98 | } 99 | } 100 | 101 | -------------------------------------------------------------------------------- /BarcodeGeneratorGUI/Form1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows.Forms; 10 | 11 | namespace BarcodeGenerator.GUI 12 | { 13 | public partial class Form1 : Form 14 | { 15 | public Form1() 16 | { 17 | InitializeComponent(); 18 | } 19 | 20 | private void button1_Click(object sender, EventArgs e) 21 | { 22 | BarcodeGenerator.Code128GS1.Encoder c128 = new BarcodeGenerator.Code128GS1.Encoder(); 23 | BarcodeGenerator.Code128GS1.BarcodeImage barcodeImage = new BarcodeGenerator.Code128GS1.BarcodeImage(); 24 | picBarcode.Image = barcodeImage.CreateImage( 25 | c128.Encode(txtInput.Text), 26 | 1, 27 | true); 28 | 29 | // 098X1234567Y23 30 | // [Start B] 16 25 24 56 17 [Code C] 23 45 67 [Code B] 57 18 19 [checksum] [Stop] 31 | 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /BarcodeGeneratorGUI/Form1.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /BarcodeGeneratorGUI/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace BarcodeGenerator.GUI 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// The main entry point for the application. 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new Form1()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /BarcodeGeneratorGUI/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("BarcodeGeneratorGUI")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("BarcodeGeneratorGUI")] 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("bfbc5a60-2080-4dcb-909e-5ec8130cf4e5")] 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 | -------------------------------------------------------------------------------- /BarcodeGeneratorGUI/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.34209 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace BarcodeGeneratorGUI.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("BarcodeGeneratorGUI.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /BarcodeGeneratorGUI/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /BarcodeGeneratorGUI/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.34209 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace BarcodeGeneratorGUI.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /BarcodeGeneratorGUI/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /BarcodeGeneratorTest/BarcodeGeneratorTest.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | {AFC5D390-4E80-45F1-802C-3F942857DA43} 7 | Library 8 | Properties 9 | BarcodeGeneratorTest 10 | BarcodeGeneratorTest 11 | v4.5 12 | 512 13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 10.0 15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 17 | False 18 | UnitTest 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\Debug\ 25 | DEBUG;TRACE 26 | prompt 27 | 4 28 | 29 | 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | {f8a89ca7-5ddf-4ea4-b80d-e04686a584d8} 59 | BarcodeGenerator 60 | 61 | 62 | 63 | 64 | 65 | 66 | False 67 | 68 | 69 | False 70 | 71 | 72 | False 73 | 74 | 75 | False 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | taskkill /F /IM vstest.discoveryengine.x86.exe /FI "MEMUSAGE gt 1" 84 | taskkill /F /IM vstest.discoveryengine.exe /FI "MEMUSAGE gt 1" 85 | taskkill /F /IM vstest.executionengine.x86.exe /FI "MEMUSAGE gt 1" 86 | taskkill /F /IM vstest.executionengine.exe /FI "MEMUSAGE gt 1" 87 | 88 | 89 | 90 | 97 | -------------------------------------------------------------------------------- /BarcodeGeneratorTest/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("BarcodeGeneratorTest")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("BarcodeGeneratorTest")] 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("4a6b9053-9764-4f44-8336-0552c3f36989")] 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 | -------------------------------------------------------------------------------- /BarcodeGeneratorTest/UnitTest1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Collections.Generic; 4 | using Microsoft.VisualStudio.TestTools.UnitTesting; 5 | 6 | namespace BarcodeGeneratorTest 7 | { 8 | [TestClass] 9 | public class UnitTest1 10 | { 11 | BarcodeGenerator.Code128GS1.Encoder encoder; 12 | 13 | [TestInitialize] 14 | public void TestSetup() 15 | { 16 | encoder = new BarcodeGenerator.Code128GS1.Encoder(); 17 | } 18 | 19 | [TestCleanup] 20 | public void TestExit() 21 | { 22 | encoder = null; 23 | } 24 | 25 | [TestMethod] 26 | [TestCategory("Misc methods")] 27 | public void Test_CalculateChecksum() 28 | { 29 | Assert.IsNotNull(encoder); 30 | 31 | // 10, 20, 30, 40 = 10 + (1*20) + (2*30) + (3*40) = 210 % 103 = 4 32 | Assert.AreEqual(4, encoder.CalculateChecksum(new List(new int[] { 10, 20, 30, 40 }))); 33 | 34 | // 35, 29, 115, 94 = 35 + (1*29) + (2*115) + (3*94) = 576 % 103 = 61 35 | Assert.AreEqual(61, encoder.CalculateChecksum(new List(new int[] { 35, 29, 115, 94 }))); 36 | } 37 | 38 | [TestMethod] 39 | [TestCategory("Misc methods")] 40 | public void Test_GetCodeValueForChar() 41 | { 42 | Assert.IsNotNull(encoder); 43 | 44 | // (asciiCode >= 32) ? asciiCode - 32 : asciiCode + 64; 45 | Assert.AreEqual(50 - 32, encoder.GetCodeValueForChar(50)); 46 | Assert.AreEqual(20 + 64, encoder.GetCodeValueForChar(20)); 47 | } 48 | 49 | [TestMethod] 50 | [TestCategory("Encoding")] 51 | public void Test_Encode_AutodetectOptimize() 52 | { 53 | Assert.IsNotNull(encoder); 54 | 55 | int[] validationValues1 = new int[] { 105, 102, 0, 1, 23, 45, 67, 89, 7, 106 }; 56 | int[] encodeResult1 = encoder.Encode("(00)0123456789"); 57 | 58 | Assert.IsTrue(encodeResult1.SequenceEqual(validationValues1)); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BarcodeGenerator 2 | Code128 GS1 barcode generator for .NET 3 | 4 | Based on the GenCode128 project by Chris Wuestefeld (http://www.codeproject.com/Articles/14409/GenCode-A-Code-Barcode-Generator) 5 | 6 | Features: 7 | * Supports CodeSet A/B/C 8 | * Analyzes input and calculates the best codeset to use 9 | 10 | Todo: 11 | * Exception-handling 12 | * Use fixed codeset 13 | * and much more.. 14 | 15 | Feel free to use it as you want. 16 | --------------------------------------------------------------------------------