Пример #1
0
        }//Encode_ITF14

        private void CheckDigit()
        {
            //calculate and include checksum if it is necessary
            if (Raw_Data.Length == 13)
            {
                int even = 0;
                int odd  = 0;

                //odd
                for (int i = 0; i <= 10; i += 2)
                {
                    odd += Int32.Parse(Raw_Data.Substring(i, 1));
                }//for

                //even
                for (int i = 1; i <= 11; i += 2)
                {
                    even += Int32.Parse(Raw_Data.Substring(i, 1)) * 3;
                }//for

                int total = even + odd;
                int cs    = total % 10;
                cs = 10 - cs;
                if (cs == 10)
                {
                    cs = 0;
                }

                this.Raw_Data += cs.ToString();
            }//if
        }
        private void CheckDigit()
        {
            try
            {
                string RawDataHolder = Raw_Data.Substring(0, 11);

                //calculate check digit
                int even = 0;
                int odd = 0;

                for (int i = 0; i < RawDataHolder.Length; i++)
                {
                    if (i % 2 == 0)
                        odd += Int32.Parse(RawDataHolder.Substring(i, 1)) * 3;
                    else
                        even += Int32.Parse(RawDataHolder.Substring(i, 1));
                }//for

                int total = even + odd;
                int cs = total % 10;
                cs = 10 - cs;
                if (cs == 10)
                    cs = 0;

                Raw_Data = RawDataHolder + cs.ToString()[0];
            }//try
            catch
            {
                Error("EUPCA-4: Error calculating check digit.");
            }//catch
        }
Пример #3
0
        private void CheckDigit()
        {
            //calculate and add check digit if necessary
            if (Raw_Data.Length == 12)
            {
                var even = 0;
                var odd  = 0;

                //odd
                for (var i = 0; i <= 10; i += 2)
                {
                    odd += int.Parse(Raw_Data.Substring(i, 1));
                }

                //even
                for (var i = 1; i <= 11; i += 2)
                {
                    even += int.Parse(Raw_Data.Substring(i, 1)) * 3;
                }

                var total = even + odd;
                var cs    = total % 10;
                cs = 10 - cs;
                if (cs == 10)
                {
                    cs = 0;
                }

                Raw_Data += cs.ToString();
            }
        }
Пример #4
0
        private void CheckDigit()
        {
            if (Raw_Data.Length == 7)
            {
                int even = 0;
                int odd  = 0;

                for (int i = 0; i <= 6; i += 2)
                {
                    odd += Int32.Parse(Raw_Data.Substring(i, 1)) * 3;
                }

                for (int i = 1; i <= 5; i += 2)
                {
                    even += Int32.Parse(Raw_Data.Substring(i, 1));
                }

                int total    = even + odd;
                int checksum = total % 10;
                checksum = 10 - checksum;
                if (checksum == 10)
                {
                    checksum = 0;
                }

                Raw_Data += checksum.ToString();
            }
        }
Пример #5
0
        }//init_CountryCodes

        private void CheckDigit()
        {
            try
            {
                var rawDataHolder = Raw_Data.Substring(0, 11);

                //calculate check digit
                var sum = 0;

                for (var i = 0; i < rawDataHolder.Length; i++)
                {
                    if (i % 2 == 0)
                    {
                        sum += Int32.Parse(rawDataHolder.Substring(i, 1)) * 3;
                    }
                    else
                    {
                        sum += Int32.Parse(rawDataHolder.Substring(i, 1));
                    }
                }//for

                int cs = (10 - sum % 10) % 10;

                //replace checksum if provided by the user and replace with the calculated checksum
                Raw_Data = rawDataHolder + cs;
            }//try
            catch
            {
                Error("EUPCA-4: Error calculating check digit.");
            } //catch
        }     //CheckDigit
Пример #6
0
        }//Encode_EAN8

        private void CheckDigit()
        {
            //calculate the checksum digit if necessary
            if (Raw_Data.Length == 7)
            {
                //calculate the checksum digit
                int even = 0;
                int odd  = 0;

                //odd
                for (int i = 0; i <= 6; i += 2)
                {
                    odd += Int32.Parse(Raw_Data.Substring(i, 1)) * 3;
                }//for

                //even
                for (int i = 1; i <= 5; i += 2)
                {
                    even += Int32.Parse(Raw_Data.Substring(i, 1));
                }//for

                int total    = even + odd;
                int checksum = total % 10;
                checksum = 10 - checksum;
                if (checksum == 10)
                {
                    checksum = 0;
                }

                //add the checksum to the end of the
                Raw_Data += checksum.ToString();
            }//if
        }
Пример #7
0
        /// <summary>
        /// Encode the raw data using the JAN-13 algorithm.
        /// </summary>
        private string Encode_JAN13()
        {
            if (!Raw_Data.StartsWith("49")) Error("EJAN13-1: Invalid Country Code for JAN13 (49 required)");
            if (!BarcodeLib.CheckNumericOnly(Raw_Data))
                Error("EJAN13-2: Numeric Data Only");

            EAN13 ean13 = new EAN13(Raw_Data);
            return ean13.Encoded_Value;
        }//Encode_JAN13
Пример #8
0
        private string Encode_UPCSupplemental_5()
        {
            if (Raw_Data.Length != 5)
            {
                Error("EUPC-SUP5-1: Invalid data length. (Length = 5 required)");
            }

            if (!CheckNumericOnly(Raw_Data))
            {
                Error("EUPCA-2: Numeric Data Only");
            }

            int even = 0;
            int odd  = 0;

            for (int i = 0; i <= 4; i += 2)
            {
                odd += Int32.Parse(Raw_Data.Substring(i, 1)) * 3;
            }

            for (int i = 1; i < 4; i += 2)
            {
                even += Int32.Parse(Raw_Data.Substring(i, 1)) * 9;
            }

            int total = even + odd;
            int cs    = total % 10;

            string pattern = UPC_SUPP_5[cs];

            string result = "";

            int pos = 0;

            foreach (char c in pattern)
            {
                if (pos == 0)
                {
                    result += "1011";
                }
                else
                {
                    result += "01";
                }

                if (c == 'a')
                {
                    result += EAN_CodeA[Int32.Parse(Raw_Data[pos].ToString())];
                }
                else if (c == 'b')
                {
                    result += EAN_CodeB[Int32.Parse(Raw_Data[pos].ToString())];
                }
                pos++;
            }
            return(result);
        }
Пример #9
0
        }//Codabar

        /// <summary>
        /// Encode the raw data using the Codabar algorithm.
        /// </summary>
        private string Encode_Codabar()
        {
            if (Raw_Data.Length < 2)
            {
                Error("ECODABAR-1: Data format invalid. (Invalid length)");
            }

            //check first char to make sure its a start/stop char
            switch (Raw_Data[0].ToString().ToUpper().Trim())
            {
            case "A": break;

            case "B": break;

            case "C": break;

            case "D": break;

            default: Error("ECODABAR-2: Data format invalid. (Invalid START character)");
                break;
            }//switch

            //check the ending char to make sure its a start/stop char
            switch (Raw_Data[Raw_Data.Trim().Length - 1].ToString().ToUpper().Trim())
            {
            case "A": break;

            case "B": break;

            case "C": break;

            case "D": break;

            default: Error("ECODABAR-3: Data format invalid. (Invalid STOP character)");
                break;
            }//switch

            string result = "";

            //populate the hashtable to begin the process
            this.init_Codabar();

            foreach (char c in Raw_Data)
            {
                result += Codabar_Code[c].ToString();
                result += "0"; //inter-character space
            }//foreach

            //remove the extra 0 at the end of the result
            result = result.Remove(result.Length - 1);

            //clears the hashtable so it no longer takes up memory
            this.Codabar_Code.Clear();

            return(result);
        }//Encode_Codabar
Пример #10
0
        /// <summary>
        /// Encode the raw data using the UPC-A algorithm.
        /// </summary>
        private string Encode_UPCA()
        {
            //check length of input
            if (Raw_Data.Length != 11 && Raw_Data.Length != 12)
                Error("EUPCA-1: Data length invalid. (Length must be 11 or 12)");

            if (!CheckNumericOnly(Raw_Data))
                Error("EUPCA-2: Numeric Data Only");

            CheckDigit();

            string result = "101"; //start with guard bars

            //first number
            result += UPC_CodeA[Int32.Parse(Raw_Data[0].ToString())];

            //second (group) of numbers
            int pos = 0;
            while (pos < 5)
            {
                result += UPC_CodeA[Int32.Parse(Raw_Data[pos + 1].ToString())];
                pos++;
            }//while

            //add divider bars
            result += "01010";

            //third (group) of numbers
            pos = 0;
            while (pos < 5)
            {
                result += UPC_CodeB[Int32.Parse(Raw_Data[(pos++) + 6].ToString())];
            }//while

            //forth
            result += UPC_CodeB[Int32.Parse(Raw_Data[Raw_Data.Length - 1].ToString())];

            //add ending guard bars
            result += "101";

            //get the manufacturer assigning country
            this.init_CountryCodes();
            string twodigitCode = "0" + Raw_Data.Substring(0, 1);
            try
            {
                _Country_Assigning_Manufacturer_Code = CountryCodes[twodigitCode].ToString();
            }//try
            catch
            {
                Error("EUPCA-3: Country assigning manufacturer code not found.");
            }//catch
            finally { CountryCodes.Clear(); }

            return result;
        }
Пример #11
0
        private string Encode_UPCA()
        {
            if (Raw_Data.Length != 11 && Raw_Data.Length != 12)
            {
                Error("EUPCA-1: Data length invalid. (Length must be 11 or 12)");
            }

            if (!CheckNumericOnly(Raw_Data))
            {
                Error("EUPCA-2: Numeric Data Only");
            }

            CheckDigit();

            string result = "101";

            result += UPC_CodeA[Int32.Parse(Raw_Data[0].ToString())];

            int pos = 0;

            while (pos < 5)
            {
                result += UPC_CodeA[Int32.Parse(Raw_Data[pos + 1].ToString())];
                pos++;
            }

            result += "01010";

            pos = 0;
            while (pos < 5)
            {
                result += UPC_CodeB[Int32.Parse(Raw_Data[(pos++) + 6].ToString())];
            }

            result += UPC_CodeB[Int32.Parse(Raw_Data[Raw_Data.Length - 1].ToString())];

            result += "101";

            this.init_CountryCodes();
            string twodigitCode = "0" + Raw_Data.Substring(0, 1);

            try
            {
                _Country_Assigning_Manufacturer_Code = CountryCodes[twodigitCode].ToString();
            }
            catch
            {
                Error("EUPCA-3: Country assigning manufacturer code not found.");
            }
            finally { CountryCodes.Clear(); }

            return(result);
        }
Пример #12
0
        /// <summary>
        ///     Encode the raw data using the JAN-13 algorithm.
        /// </summary>
        private string Encode_JAN13()
        {
            if (!Raw_Data.StartsWith("49"))
            {
                throw new Exception("EJAN13-1: Invalid Country Code for JAN13 (49 required)");
            }
            if (!Barcode.CheckNumericOnly(Raw_Data))
            {
                throw new Exception("EJAN13-2: Numeric Data Only");
            }

            var ean13 = new EAN13(Raw_Data);

            return(ean13.Encoded_Value);
        }
        /// <summary>
        /// Encode the raw data using the JAN-13 algorithm.
        /// </summary>
        private string Encode_JAN13()
        {
            if (!Raw_Data.StartsWith("49"))
            {
                Error("EJAN13-1: Invalid Country Code for JAN13 (49 required)");
            }
            if (!BarcodeLib.Barcode.CheckNumericOnly(Raw_Data))
            {
                Error("EJAN13-2: нои УбоЧу");
            }

            EAN13 ean13 = new EAN13(Raw_Data);

            return(ean13.Encoded_Value);
        }//Encode_JAN13
Пример #14
0
        }//Postnet

        /// <summary>
        /// Encode the raw data using the PostNet algorithm.
        /// </summary>
        private string Encode_Postnet()
        {
            //remove dashes if present
            Raw_Data = Raw_Data.Replace("-", "");

            switch (Raw_Data.Length)
            {
            case 5:
            case 6:
            case 9:
            case 11: break;

            default: Error("数据长度不正确(数据长度5,6,9或11)");
                //default: Error("EPOSTNET-2: Invalid data length. (5, 6, 9, or 11 digits only)");
                break;
            }//switch

            //Note: 0 = half bar and 1 = full bar
            //initialize the result with the starting bar
            string result        = "1";
            int    checkdigitsum = 0;

            foreach (char c in Raw_Data)
            {
                try
                {
                    int index = Convert.ToInt32(c.ToString());
                    result        += POSTNET_Code[index];
                    checkdigitsum += index;
                }//try
                catch (Exception ex)
                {
                    Error("无效数据(只支持数字) --> " + ex.Message);
                    //Error("EPOSTNET-2: Invalid data. (Numeric only) --> " + ex.Message);
                } //catch
            }     //foreach

            //calculate and add check digit
            int temp       = checkdigitsum % 10;
            int checkdigit = 10 - (temp == 0 ? 10 : temp);

            result += POSTNET_Code[checkdigit];

            //ending bar
            result += "1";

            return(result);
        }//Encode_PostNet
Пример #15
0
        /// <summary>
        /// Encode the raw data using the Code 39 algorithm.
        /// </summary>
        private string Encode_Code39()
        {
            this.init_Code39();
            this.init_ExtendedCode39();

            while (Raw_Data.Length < 3)
            {
                Raw_Data = "0" + Raw_Data;
            }

            string strFormattedData = "*" + Raw_Data.Replace("*", "") + "*";

            if (_AllowExtended)
            {
                InsertExtendedCharsIfNeeded(ref strFormattedData);
            }

            string result = "";

            //foreach (char c in this.FormattedData)
            foreach (char c in strFormattedData)
            {
                try
                {
                    result += C39_Code[c].ToString();
                    result += "0";//whitespace
                }//try
                catch
                {
                    if (_AllowExtended)
                    {
                        Error("EC39-1: Invalid data.");
                    }
                    else
                    {
                        Error("EC39-1: Invalid data. (Try using Extended Code39)");
                    }
                } //catch
            }     //foreach

            result = result.Substring(0, result.Length - 1);

            //clear the hashtable so it no longer takes up memory
            this.C39_Code.Clear();

            return(result);
        }//Encode_Code39
Пример #16
0
        /// <summary>
        /// Encode the raw data using the UPC Supplemental 2-digit algorithm.
        /// </summary>
        private string Encode_UPCSupplemental_2()
        {
            if (Raw_Data.Length != 2)
            {
                Error("输入数据长度无效,长度应该为2");
            }
            //if (Raw_Data.Length != 2) Error("EUPC-SUP2-1: Invalid data length. (Length = 2 required)");

            if (!CheckNumericOnly(Raw_Data))
            {
                Error("只识别数字数据");
            }
            //Error("EUPC-SUP2-2: Numeric Data Only");

            string pattern = "";

            try
            {
                pattern = this.UPC_SUPP_2[Int32.Parse(Raw_Data.Trim()) % 4];
            }//try
            catch { Error("数据无效(只识别数字)"); }
            //catch { Error("EUPC-SUP2-3: Invalid Data. (Numeric only)"); }

            string result = "1011";

            int pos = 0;

            foreach (char c in pattern)
            {
                if (c == 'a')
                {
                    //encode using odd parity
                    result += EAN_CodeA[Int32.Parse(Raw_Data[pos].ToString())];
                }//if
                else if (c == 'b')
                {
                    //encode using even parity
                    result += EAN_CodeB[Int32.Parse(Raw_Data[pos].ToString())];
                }//else if

                if (pos++ == 0)
                {
                    result += "01";             //Inter-character separator
                }
            }//foreach
            return(result);
        }//Encode_UPSSupplemental_2
        /// <summary>
        ///     Encode the raw data using the UPC Supplemental 2-digit algorithm.
        /// </summary>
        private string Encode_UPCSupplemental_2()
        {
            if (Raw_Data.Length != 2)
            {
                throw new Exception("EUPC-SUP2-1: Invalid data length. (Length = 2 required)");
            }

            if (!Barcode.CheckNumericOnly(Raw_Data))
            {
                throw new Exception("EUPC-SUP2-2: Numeric Data Only");
            }

            var pattern = string.Empty;

            try
            {
                pattern = UPC_SUPP_2[int.Parse(Raw_Data.Trim()) % 4];
            }
            catch
            {
                throw new Exception("EUPC-SUP2-3: Invalid Data. (Numeric only)");
            }

            var result = "1011";

            var pos = 0;

            foreach (var c in pattern)
            {
                if (c == 'a')
                {
                    //encode using odd parity
                    result += EAN_CodeA[int.Parse(Raw_Data[pos].ToString())];
                }
                else if (c == 'b')
                {
                    //encode using even parity
                    result += EAN_CodeB[int.Parse(Raw_Data[pos].ToString())];
                }

                if (pos++ == 0)
                {
                    result += "01";             //Inter-character separator
                }
            }
            return(result);
        }
Пример #18
0
        /// <summary>
        ///     Encode the raw data using the PostNet algorithm.
        /// </summary>
        private string Encode_Postnet()
        {
            //remove dashes if present
            Raw_Data = Raw_Data.Replace("-", "");

            switch (Raw_Data.Length)
            {
            case 5:
            case 6:
            case 9:
            case 11:
                break;

            default:
                throw new Exception("EPOSTNET-2: Invalid data length. (5, 6, 9, or 11 digits only)");
            }

            //Note: 0 = half bar and 1 = full bar
            //initialize the result with the starting bar
            var result        = "1";
            var checkdigitsum = 0;

            foreach (var c in Raw_Data)
            {
                try
                {
                    var index = Convert.ToInt32(c.ToString());
                    result        += POSTNET_Code[index];
                    checkdigitsum += index;
                }
                catch (Exception ex)
                {
                    throw new Exception("EPOSTNET-2: Invalid data. (Numeric only) --> " + ex.Message);
                }
            }

            //calculate and add check digit
            var temp       = checkdigitsum % 10;
            var checkdigit = 10 - (temp == 0 ? 10 : temp);

            result += POSTNET_Code[checkdigit];

            //ending bar
            result += "1";

            return(result);
        }
Пример #19
0
        /// <summary>
        /// Encode the raw data using the JAN-13 algorithm.
        /// </summary>
        private string Encode_JAN13()
        {
            if (!Raw_Data.StartsWith("49"))
            {
                Error("无效国家编码!");
            }
            //if (!Raw_Data.StartsWith("49")) Error("EJAN13-1: Invalid Country Code for JAN13 (49 required)");
            if (!CheckNumericOnly(Raw_Data))
            {
                Error("只识别数字数据");
            }
            //Error("EJAN13-2: Numeric Data Only");

            EAN13 ean13 = new EAN13(Raw_Data);

            return(ean13.Encoded_Value);
        }//Encode_JAN13
Пример #20
0
        /// <summary>
        /// Encode the raw data using the Bookland/ISBN algorithm.
        /// </summary>
        private string Encode_ISBN_Bookland()
        {
            if (!CheckNumericOnly(Raw_Data))
            {
                Error("EBOOKLANDISBN-1: Numeric Data Only");
            }

            var type = "UNKNOWN";

            switch (Raw_Data.Length)
            {
            case 10:
            case 9:
            {
                if (Raw_Data.Length == 10)
                {
                    Raw_Data = Raw_Data.Remove(9, 1);
                }
                Raw_Data = "978" + Raw_Data;
                type     = "ISBN";     //if
                break;
            }

            case 12 when Raw_Data.StartsWith("978"):
                type = "BOOKLAND-NOCHECKDIGIT";     //else if

                break;

            case 13 when Raw_Data.StartsWith("978"):
                type = "BOOKLAND-CHECKDIGIT";

                Raw_Data = Raw_Data.Remove(12, 1);     //else if
                break;
            }

            //check to see if its an unknown type
            if (type == "UNKNOWN")
            {
                Error("EBOOKLANDISBN-2: Invalid input.  Must start with 978 and be length must be 9, 10, 12, 13 characters.");
            }

            var ean13 = new EAN13(Raw_Data);

            return(ean13.Encoded_Value);
        }//Encode_ISBN_Bookland
Пример #21
0
        /// <summary>
        /// Encode the raw data using the UPC Supplemental 2-digit algorithm.
        /// </summary>
        private string Encode_UPCSupplemental_2()
        {
            if (Raw_Data.Length != 2)
            {
                Error("ицс Чсфе ЧсуисцШ 2");
            }

            if (!BarcodeLib.Barcode.CheckNumericOnly(Raw_Data))
            {
                Error("EUPC-SUP2-2:УбоЧу они");
            }

            string pattern = "";

            try
            {
                pattern = this.UPC_SUPP_2[Int32.Parse(Raw_Data.Trim()) % 4];
            }//try
            catch { Error("УбоЧу они"); }

            string result = "1011";

            int pos = 0;

            foreach (char c in pattern)
            {
                if (c == 'a')
                {
                    //encode using odd parity
                    result += EAN_CodeA[Int32.Parse(Raw_Data[pos].ToString())];
                }//if
                else if (c == 'b')
                {
                    //encode using even parity
                    result += EAN_CodeB[Int32.Parse(Raw_Data[pos].ToString())];
                }//else if

                if (pos++ == 0)
                {
                    result += "01";             //Inter-character separator
                }
            }//foreach
            return(result);
        }//Encode_UPSSupplemental_2
Пример #22
0
        /// <summary>
        /// Encode the raw data using the Code 39 algorithm.
        /// </summary>
        private string Encode_Code39()
        {
            init_Code39();
            init_ExtendedCode39();

            var strNoAstr        = Raw_Data.Replace("*", "");
            var strFormattedData = "*" + strNoAstr + (_enableChecksum ? GetChecksumChar(strNoAstr).ToString() : String.Empty) + "*";

            if (_allowExtended)
            {
                InsertExtendedCharsIfNeeded(ref strFormattedData);
            }

            var result = "";

            //foreach (char c in this.FormattedData)
            foreach (var c in strFormattedData)
            {
                try
                {
                    result += C39_Code[c].ToString();
                    result += "0";//whitespace
                }//try
                catch
                {
                    if (_allowExtended)
                    {
                        Error("EC39-1: Invalid data.");
                    }
                    else
                    {
                        Error("EC39-1: Invalid data. (Try using Extended Code39)");
                    }
                } //catch
            }     //foreach

            result = result.Substring(0, result.Length - 1);

            //clear the hashtable so it no longer takes up memory
            C39_Code.Clear();

            return(result);
        }//Encode_Code39
        /// <summary>
        /// Encode the raw data using the Code 39 algorithm.
        /// </summary>
        private string Encode_Code39()
        {
            this.init_Code39();
            this.init_ExtendedCode39();

            string strFormattedData = "*" + Raw_Data.Replace("*", "") + "*";

            if (_AllowExtended)
            {
                InsertExtendedCharsIfNeeded(ref strFormattedData);
            }

            string result = "";

            //foreach (char c in this.FormattedData)
            foreach (char c in strFormattedData)
            {
                try
                {
                    result += C39_Code[c].ToString();
                    result += "0";//whitespace
                }//try
                catch
                {
                    if (_AllowExtended)
                    {
                        Error("EC39-1:   ÈíÇäÇÊ ÛíÑ äÙÇãíÉ.");
                    }
                    else
                    {
                        Error("EC39-1: ÈíÇäÇÊ ÛíÑ äÙÇãíÉ ÍÇæá ÇÓÊÎÏÇã äãØ ÇáÊÔÝíÑ ßæÏ39");
                    }
                } //catch
            }     //foreach

            result = result.Substring(0, result.Length - 1);

            //clear the hashtable so it no longer takes up memory
            this.C39_Code.Clear();

            return(result);
        }//Encode_Code39
Пример #24
0
        private string Encode_UPCSupplemental_2()
        {
            if (Raw_Data.Length != 2)
            {
                Error("EUPC-SUP2-1: Invalid data length. (Length = 2 required)");
            }

            if (!CheckNumericOnly(Raw_Data))
            {
                Error("EUPC-SUP2-2: Numeric Data Only");
            }

            string pattern = "";

            try
            {
                pattern = this.UPC_SUPP_2[Int32.Parse(Raw_Data.Trim()) % 4];
            }
            catch { Error("EUPC-SUP2-3: Invalid Data. (Numeric only)"); }

            string result = "1011";

            int pos = 0;

            foreach (char c in pattern)
            {
                if (c == 'a')
                {
                    result += EAN_CodeA[Int32.Parse(Raw_Data[pos].ToString())];
                }
                else if (c == 'b')
                {
                    result += EAN_CodeB[Int32.Parse(Raw_Data[pos].ToString())];
                }

                if (pos++ == 0)
                {
                    result += "01";
                }
            }
            return(result);
        }
Пример #25
0
        private string Encode_Code39()
        {
            this.init_Code39();
            this.init_ExtendedCode39();

            string strNoAstr        = Raw_Data.Replace("*", "");
            string strFormattedData = "*" + strNoAstr + (_EnableChecksum ? getChecksumChar(strNoAstr).ToString() : String.Empty) + "*";

            if (_AllowExtended)
            {
                InsertExtendedCharsIfNeeded(ref strFormattedData);
            }

            string result = "";

            foreach (char c in strFormattedData)
            {
                try
                {
                    result += C39_Code[c].ToString();
                    result += "0";
                }
                catch
                {
                    if (_AllowExtended)
                    {
                        Error("EC39-1: Invalid data.");
                    }
                    else
                    {
                        Error("EC39-1: Invalid data. (Try using Extended Code39)");
                    }
                }
            }

            result = result.Substring(0, result.Length - 1);

            this.C39_Code.Clear();

            return(result);
        }
Пример #26
0
        private string Encode_Postnet()
        {
            Raw_Data = Raw_Data.Replace("-", "");

            switch (Raw_Data.Length)
            {
            case 5:
            case 6:
            case 9:
            case 11: break;

            default: Error("EPOSTNET-2: Invalid data length. (5, 6, 9, or 11 digits only)");
                break;
            }

            string result        = "1";
            int    checkdigitsum = 0;

            foreach (char c in Raw_Data)
            {
                try
                {
                    int index = Convert.ToInt32(c.ToString());
                    result        += POSTNET_Code[index];
                    checkdigitsum += index;
                }
                catch (Exception ex)
                {
                    Error("EPOSTNET-2: Invalid data. (Numeric only) --> " + ex.Message);
                }
            }

            int temp       = checkdigitsum % 10;
            int checkdigit = 10 - (temp == 0 ? 10 : temp);

            result += POSTNET_Code[checkdigit];

            result += "1";

            return(result);
        }
Пример #27
0
        /// <summary>
        ///     Encode the raw data using the Code 39 algorithm.
        /// </summary>
        private string Encode_Code39()
        {
            init_Code39();
            init_ExtendedCode39();

            var strFormattedData = "*" + Raw_Data.Replace("*", "") + "*";

            if (_AllowExtended)
            {
                InsertExtendedCharsIfNeeded(ref strFormattedData);
            }

            FormattedData = strFormattedData;

            var result = "";

            foreach (var c in FormattedData)
            {
                try
                {
                    result += C39_Code[c].ToString();
                    result += "0"; //whitespace
                }
                catch
                {
                    if (_AllowExtended)
                    {
                        throw new Exception("EC39-1: Invalid data.");
                    }
                    throw new Exception("EC39-1: Invalid data. (Try using Extended Code39)");
                }
            }

            result = result.Substring(0, result.Length - 1);

            //clear the hashtable so it no longer takes up memory
            C39_Code.Clear();

            return(result);
        }
Пример #28
0
        /// <summary>
        /// Encode the raw data using the Bookland/ISBN algorithm.
        /// </summary>
        private string Encode_ISBN_Bookland()
        {
            if (!CheckNumericOnly(Raw_Data))
            {
                Error("只识别数字数据");
            }
            //Error("EBOOKLANDISBN-1: Numeric Data Only");

            string type = "UNKNOWN";

            if (Raw_Data.Length == 10 || Raw_Data.Length == 9)
            {
                if (Raw_Data.Length == 10)
                {
                    Raw_Data = Raw_Data.Remove(9, 1);
                }
                Raw_Data = "978" + Raw_Data;
                type     = "ISBN";
            }//if
            else if (Raw_Data.Length == 12 && Raw_Data.StartsWith("978"))
            {
                type = "BOOKLAND-NOCHECKDIGIT";
            }//else if
            else if (Raw_Data.Length == 13 && Raw_Data.StartsWith("978"))
            {
                type     = "BOOKLAND-CHECKDIGIT";
                Raw_Data = Raw_Data.Remove(12, 1);
            }//else if

            //check to see if its an unknown type
            if (type == "UNKNOWN")
            {
                Error("无效输入,必须以 978 开始,并且长度必须为9,10,12,13个字符");
            }
            //if (type == "UNKNOWN") Error("EBOOKLANDISBN-2: Invalid input.  Must start with 978 and be length must be 9, 10, 12, 13 characters.");

            EAN13 ean13 = new EAN13(Raw_Data);

            return(ean13.Encoded_Value);
        }//Encode_ISBN_Bookland
Пример #29
0
        private void CheckDigit()
        {
            if (Raw_Data.Length == 13)
            {
                int total = 0;

                for (int i = 0; i <= Raw_Data.Length - 1; i++)
                {
                    int temp = Int32.Parse(Raw_Data.Substring(i, 1));
                    total += temp * ((i == 0 || i % 2 == 0) ? 3 : 1);
                }

                int cs = total % 10;
                cs = 10 - cs;
                if (cs == 10)
                {
                    cs = 0;
                }

                this.Raw_Data += cs.ToString();
            }
        }
Пример #30
0
        /// <summary>
        ///     Encode the raw data using the Bookland/ISBN algorithm.
        /// </summary>
        private string Encode_ISBN_Bookland()
        {
            if (!Barcode.CheckNumericOnly(Raw_Data))
            {
                throw new Exception("EBOOKLANDISBN-1: Numeric Data Only");
            }

            var type = "UNKNOWN";

            if (Raw_Data.Length == 10 || Raw_Data.Length == 9)
            {
                if (Raw_Data.Length == 10)
                {
                    Raw_Data = Raw_Data.Remove(9, 1);
                }
                Raw_Data = "978" + Raw_Data;
                type     = "ISBN";
            }
            else if (Raw_Data.Length == 12 && Raw_Data.StartsWith("978"))
            {
                type = "BOOKLAND-NOCHECKDIGIT";
            }
            else if (Raw_Data.Length == 13 && Raw_Data.StartsWith("978"))
            {
                type     = "BOOKLAND-CHECKDIGIT";
                Raw_Data = Raw_Data.Remove(12, 1);
            }

            //check to see if its an unknown type
            if (type == "UNKNOWN")
            {
                throw new Exception(
                          "EBOOKLANDISBN-2: Invalid input.  Must start with 978 and be length must be 9, 10, 12, 13 characters.");
            }

            var ean13 = new EAN13(Raw_Data);

            return(ean13.Encoded_Value);
        }