Esempio n. 1
0
    private int[] StringToCode128(string AsciiData)
    {
        byte[] asciiBytes = Encoding.ASCII.GetBytes(AsciiData);


        Code128Code.CodeSetAllowed csa1 = asciiBytes.Length > 0 ? Code128Code.CodesetAllowedForChar(asciiBytes[0]) : Code128Code.CodeSetAllowed.CodeAorB;
        Code128Code.CodeSetAllowed csa2 = asciiBytes.Length > 1 ? Code128Code.CodesetAllowedForChar(asciiBytes[1]) : Code128Code.CodeSetAllowed.CodeAorB;
        CodeSet currcs = GetBestStartSet(csa1, csa2);


        System.Collections.ArrayList codes = new System.Collections.ArrayList(asciiBytes.Length + 3); // assume no codeset changes, account for start, checksum, and stop
        codes.Add(Code128Code.StartCodeForCodeSet(currcs));

        for (int i = 0; i < asciiBytes.Length; i++)
        {
            int thischar = asciiBytes[i];
            int nextchar = asciiBytes.Length > (i + 1) ? asciiBytes[i + 1] : -1;

            codes.AddRange(Code128Code.CodesForChar(thischar, nextchar, ref currcs));
        }


        int checksum = (int)(codes[0]);

        for (int i = 1; i < codes.Count; i++)
        {
            checksum += i * (int)(codes[i]);
        }
        codes.Add(checksum % 103);

        codes.Add(Code128Code.StopCode());

        int[] result = codes.ToArray(typeof(int)) as int[];
        return(result);
    }
Esempio n. 2
0
        /// <summary>
        /// Transform the string into integers representing the Code128 codes
        /// necessary to represent it
        /// </summary>
        /// <param name="asciiData">String to be encoded</param>
        /// <returns>Code128 representation</returns>
        private int[] StringToCode128(string asciiData)
        {
            // turn the string into ascii byte data
            var asciiBytes = Encoding.ASCII.GetBytes(asciiData);

            // decide which codeset to start with
            var csa1 = asciiBytes.Length > 0
                           ? Code128Code.CodesetAllowedForChar(asciiBytes[0])
                           : Code128Code.CodeSetAllowed.CodeAorB;
            var csa2 = asciiBytes.Length > 1
                           ? Code128Code.CodesetAllowedForChar(asciiBytes[1])
                           : Code128Code.CodeSetAllowed.CodeAorB;
            var currentCodeSet = this.GetBestStartSet(csa1, csa2);

            // set up the beginning of the barcode
            // assume no codeset changes, account for start, checksum, and stop
            var codes = new ArrayList(asciiBytes.Length + 3)
            {
                Code128Code.StartCodeForCodeSet(currentCodeSet)
            };

            // add the codes for each character in the string
            for (var i = 0; i < asciiBytes.Length; i++)
            {
                int thischar = asciiBytes[i];
                var nextchar = asciiBytes.Length > i + 1 ? asciiBytes[i + 1] : -1;

                codes.AddRange(Code128Code.CodesForChar(thischar, nextchar, ref currentCodeSet));
            }

            // calculate the check digit
            var checksum = (int)codes[0];

            for (var i = 1; i < codes.Count; i++)
            {
                checksum += i * (int)codes[i];
            }

            codes.Add(checksum % 103);

            codes.Add(Code128Code.StopCode());

            var result = codes.ToArray(typeof(int)) as int[];

            return(result);
        }
Esempio n. 3
0
    /// <summary>
    /// Transform the string into integers representing the Code128 codes
    /// necessary to represent it
    /// </summary>
    /// <param name="AsciiData">String to be encoded</param>
    /// <returns>Code128 representation</returns>
    private int[] StringToCode128(string AsciiData)
    {
        // turn the string into ascii byte data
        byte[] asciiBytes = Encoding.ASCII.GetBytes(AsciiData);

        // decide which codeset to start with
        Code128Code.CodeSetAllowed csa1 = asciiBytes.Length > 0 ? Code128Code.CodesetAllowedForChar(asciiBytes[0]) : Code128Code.CodeSetAllowed.CodeAorB;
        Code128Code.CodeSetAllowed csa2 = asciiBytes.Length > 0 ? Code128Code.CodesetAllowedForChar(asciiBytes[1]) : Code128Code.CodeSetAllowed.CodeAorB;
        CodeSet currcs = GetBestStartSet(csa1, csa2);

        // set up the beginning of the barcode
        System.Collections.ArrayList codes = new System.Collections.ArrayList(asciiBytes.Length + 3); // assume no codeset changes, account for start, checksum, and stop
        codes.Add(Code128Code.StartCodeForCodeSet(currcs));

        // add the codes for each character in the string
        for (int i = 0; i < asciiBytes.Length; i++)
        {
            int thischar = asciiBytes[i];
            int nextchar = asciiBytes.Length > (i + 1) ? asciiBytes[i + 1] : -1;

            codes.AddRange(Code128Code.CodesForChar(thischar, nextchar, ref currcs));
        }

        // calculate the check digit
        int checksum = (int)(codes[0]);

        for (int i = 1; i < codes.Count; i++)
        {
            checksum += i * (int)(codes[i]);
        }
        codes.Add(checksum % 103);

        codes.Add(Code128Code.StopCode());

        int[] result = codes.ToArray(typeof(int)) as int[];
        return(result);
    }