Example #1
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
Example #2
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);
        }
Example #4
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
        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);
        }
Example #6
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

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

            //replace non-numeric VALID chars with empty strings before checking for all numerics
            var temp = Raw_Data;

            foreach (char c in Codabar_Code.Keys)
            {
                if (!CheckNumericOnly(c.ToString()))
                {
                    temp = temp.Replace(c, '1');
                } //if
            }     //if

            //now that all the valid non-numeric chars have been replaced with a number check if all numeric exist
            if (!CheckNumericOnly(temp))
            {
                Error("ECODABAR-4: Data contains invalid  characters.");
            }

            var result = "";

            foreach (var 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
            Codabar_Code.Clear();

            //change the Raw_Data to strip out the start stop chars for label purposes
            Raw_Data = Raw_Data.Trim().Substring(1, RawData.Trim().Length - 2);

            return(result);
        }//Encode_Codabar
Example #7
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. (ÇáãÍÑÝ ÇáÃæá íÌÈ Ãä íßæä ÍÑÝÇ ãä  ÇáÇÍÑÝ ÇáÃÑÈÚÉ ÇáÃæáì)");
                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. (ÇáãÍÑÝ ÇáÃÎíÑ íÌÈ Ãä íßæä ÍÑÝÇ ãä  ÇáÇÍÑÝ ÇáÃÑÈÚÉ ÇáÃæáì)");
                break;
            }//switch

            string temp = Raw_Data.Trim().Substring(1, RawData.Trim().Length - 2);

            if (!IsNumeric(temp))
            {
                Error("ECODABAR-4: íÌÈ Ãä Êßæä ÇáãÍÇÑÝ ÃÑÞÇã");
            }

            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();

            //change the Raw_Data to strip out the start stop chars for label purposes
            Raw_Data = Raw_Data.Trim().Substring(1, RawData.Trim().Length - 2);

            return(result);
        }//Encode_Codabar
Example #8
0
        private string Encode_Codabar()
        {
            if (Raw_Data.Length < 2)
            {
                Error("ECODABAR-1: Data format invalid. (Invalid length)");
            }

            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 (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;
            }

            this.init_Codabar();

            string temp = Raw_Data;

            foreach (char c in Codabar_Code.Keys)
            {
                if (!CheckNumericOnly(c.ToString()))
                {
                    temp = temp.Replace(c, '1');
                }
            }

            if (!CheckNumericOnly(temp))
            {
                Error("ECODABAR-4: Data contains invalid  characters.");
            }

            string result = "";

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

            result = result.Remove(result.Length - 1);

            this.Codabar_Code.Clear();

            Raw_Data = Raw_Data.Trim().Substring(1, RawData.Trim().Length - 2);

            return(result);
        }