When writing these three types of bar codes, Baidu came to Baidu on the Internet, that is, no clear definition of code128a, code128b, and code128c was found, then, according to the general statement on the internet, only the corresponding character set is used to write this part.Code
Codea
Public class code128a: abscode128 {// <summary> // code128a barcode. Only the 128 Character Set A (numbers, uppercase letters, and control characters) is supported) /// </Summary> /// <Param name = "encodeddata"> </param> Public code128a (string rawdata): Base (rawdata) {} protected override bool rawdatacheck () {// the ASCII code range of Character Set A is 0 ~ 95 foreach (char C in this. _ rawdata) {byte tempc = (byte) C; If (tempc <= 95) {continue;} else {return false ;}} return true;} protected override string getencodeddata () {stringbuilder tempbuilder = new stringbuilder (); tempbuilder. append (code128.bslist [code128.starta]); // Add the start character starta byte sindex; int checknum = code128.starta; // check character for (INT I = 0; I <this. _ rawdata. length; I ++) {sindex = code128.getsindexfroma (this. _ rawdata [I]); tempbuilder. append (code128.bslist [sindex]); checknum + = (I + 1) * sindex;} checknum % = 103; tempbuilder. append (code128.bslist [checknum]); // Add the verification character tempbuilder. append (code128.bslist [code128.stop]); // Add the terminator return tempbuilder. tostring ();}}
code128b
/// <Summary> /// code128b barcode. Only the 128 Character Set B (numbers, letters, and characters) is supported. /// </Summary> public class code128b: abscode128 {public code128b (string rawdata): Base (rawdata) {} protected override bool rawdatacheck () {// the ASCII code range of Character Set B is 32 ~ 127 foreach (char C in this. _ rawdata) {byte tempc = (byte) C; If (tempc >=32 & tempc <= 127) {continue;} else {return false;} return true ;} protected override string getencodeddata () {stringbuilder tempbuilder = new stringbuilder (); tempbuilder. append (code128.bslist [code128.startb]); // Add the start character startb byte sindex; int checknum = code128.startb; // check the character for (INT I = 0; I <this. _ rawdata. length; I ++) {sindex = code128.getsindexfromb (this. _ rawdata [I]); // the ASCII code in Character Set B minus 32, which is equal to the character value tempbuilder. append (code128.bslist [sindex]); checknum + = (I + 1) * sindex;} checknum % = 103; tempbuilder. append (code128.bslist [checknum]); // Add the verification character tempbuilder. append (code128.bslist [code128.stop]); // Add the terminator return tempbuilder. tostring ();}}
code128c
/// <Summary> // code128c barcode. Only the 128 character set C (double digit) is supported. /// </Summary> public class code128c: abscode128 {public code128c (string rawdata): Base (rawdata) {} protected override bool rawdatacheck () {return RegEx. ismatch (this. _ rawdata, @ "^ \ D {2, 96} $") & this. _ rawdata. length % 2 = 0; // code128c two digits represent a data character, so a maximum of 96 digits can be entered.} protected override string getencodeddata () {stringbuilder tempbuilder = new stringbuilder (); tempbuilder. append (code128.bslist [code128.startc]); // Add the start character startc byte sindex; int checknum = code128.startc; // check character, startc is 105 for (INT I = 0; I <this. _ rawdata. length/2; I ++) {sindex = byte. parse (this. _ rawdata. substring (I * 2, 2); tempbuilder. append (code128.bslist [sindex]); checknum + = (I + 1) * sindex;} checknum % = 103; tempbuilder. append (code128.bslist [checknum]); // Add the verification character tempbuilder. append (code128.bslist [code128.stop]); // Add the terminator return tempbuilder. tostring ();}}