コード例 #1
0
ファイル: Postnet.cs プロジェクト: ssor/csharpDemos
        }//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
コード例 #2
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
コード例 #3
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);
        }
コード例 #4
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
コード例 #5
0
        /// <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
コード例 #6
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);
        }
コード例 #7
0
ファイル: Postnet.cs プロジェクト: sonuame/BAR-Code-Generator
        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);
        }
コード例 #8
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);
        }
コード例 #9
0
ファイル: Code11.cs プロジェクト: vhung156/TVHRM_PROJECT
        }//Code11

        /// <summary>
        /// Encode the raw data using the Code 11 algorithm.
        /// </summary>
        private string Encode_Code11()
        {
            if (!BarcodeLib.Barcode.CheckNumericOnly(Raw_Data.Replace("-", "")))
            {
                Error("EC11-1: Numeric data and '-' Only");
            }

            //calculate the checksums
            int    weight = 1;
            int    CTotal = 0;
            string Data_To_Encode_with_Checksums = Raw_Data;

            //figure the C checksum
            for (int i = Raw_Data.Length - 1; i >= 0; i--)
            {
                //C checksum weights go 1-10
                if (weight == 10)
                {
                    weight = 1;
                }

                if (Raw_Data[i] != '-')
                {
                    CTotal += Int32.Parse(Raw_Data[i].ToString()) * weight++;
                }
                else
                {
                    CTotal += 10 * weight++;
                }
            }//for
            int checksumC = CTotal % 11;

            Data_To_Encode_with_Checksums += checksumC.ToString();

            //K checksums are recommended on any message length greater than or equal to 10
            if (Raw_Data.Length >= 1)
            {
                weight = 1;
                int KTotal = 0;

                //calculate K checksum
                for (int i = Data_To_Encode_with_Checksums.Length - 1; i >= 0; i--)
                {
                    //K checksum weights go 1-9
                    if (weight == 9)
                    {
                        weight = 1;
                    }

                    if (Data_To_Encode_with_Checksums[i] != '-')
                    {
                        KTotal += Int32.Parse(Data_To_Encode_with_Checksums[i].ToString()) * weight++;
                    }
                    else
                    {
                        KTotal += 10 * weight++;
                    }
                }//for
                int checksumK = KTotal % 11;
                Data_To_Encode_with_Checksums += checksumK.ToString();
            }//if

            //encode data
            string space  = "0";
            string result = C11_Code[11] + space; //start-stop char + interchar space

            foreach (char c in Data_To_Encode_with_Checksums)
            {
                int index = (c == '-' ? 10 : Int32.Parse(c.ToString()));
                result += C11_Code[index];

                //inter-character space
                result += space;
            }//foreach

            //stop bars
            result += C11_Code[11];

            return(result);
        }//Encode_Code11
コード例 #10
0
        private string Encode_Code11()
        {
            if (!CheckNumericOnly(Raw_Data.Replace("-", "")))
            {
                Error("EC11-1: Numeric data and '-' Only");
            }

            int    weight = 1;
            int    CTotal = 0;
            string Data_To_Encode_with_Checksums = Raw_Data;

            for (int i = Raw_Data.Length - 1; i >= 0; i--)
            {
                if (weight == 10)
                {
                    weight = 1;
                }

                if (Raw_Data[i] != '-')
                {
                    CTotal += Int32.Parse(Raw_Data[i].ToString()) * weight++;
                }
                else
                {
                    CTotal += 10 * weight++;
                }
            }
            int checksumC = CTotal % 11;

            Data_To_Encode_with_Checksums += checksumC.ToString();

            if (Raw_Data.Length >= 10)
            {
                weight = 1;
                int KTotal = 0;

                for (int i = Data_To_Encode_with_Checksums.Length - 1; i >= 0; i--)
                {
                    if (weight == 9)
                    {
                        weight = 1;
                    }

                    if (Data_To_Encode_with_Checksums[i] != '-')
                    {
                        KTotal += Int32.Parse(Data_To_Encode_with_Checksums[i].ToString()) * weight++;
                    }
                    else
                    {
                        KTotal += 10 * weight++;
                    }
                }
                int checksumK = KTotal % 11;
                Data_To_Encode_with_Checksums += checksumK.ToString();
            }

            string space  = "0";
            string result = C11_Code[11] + space;

            foreach (char c in Data_To_Encode_with_Checksums)
            {
                int index = (c == '-' ? 10 : Int32.Parse(c.ToString()));
                result += C11_Code[index];

                result += space;
            }

            result += C11_Code[11];

            return(result);
        }
コード例 #11
0
ファイル: Code11.cs プロジェクト: shixb/barcodelib
        }//Code11

        /// <summary>
        /// Encode the raw data using the Code 11 algorithm.
        /// </summary>
        private string Encode_Code11()
        {
            if (!CheckNumericOnly(Raw_Data.Replace("-", "")))
            {
                Error("EC11-1: Numeric data and '-' Only");
            }

            //calculate the checksums
            var weight = 1;
            var cTotal = 0;
            var dataToEncodeWithChecksums = Raw_Data;

            //figure the C checksum
            for (var i = Raw_Data.Length - 1; i >= 0; i--)
            {
                //C checksum weights go 1-10
                if (weight == 10)
                {
                    weight = 1;
                }

                if (Raw_Data[i] != '-')
                {
                    cTotal += Int32.Parse(Raw_Data[i].ToString()) * weight++;
                }
                else
                {
                    cTotal += 10 * weight++;
                }
            }//for
            var checksumC = cTotal % 11;

            dataToEncodeWithChecksums += checksumC.ToString();

            //K checksums are recommended on any message length greater than or equal to 10
            if (Raw_Data.Length >= 10)
            {
                weight = 1;
                var kTotal = 0;

                //calculate K checksum
                for (var i = dataToEncodeWithChecksums.Length - 1; i >= 0; i--)
                {
                    //K checksum weights go 1-9
                    if (weight == 9)
                    {
                        weight = 1;
                    }

                    if (dataToEncodeWithChecksums[i] != '-')
                    {
                        kTotal += Int32.Parse(dataToEncodeWithChecksums[i].ToString()) * weight++;
                    }
                    else
                    {
                        kTotal += 10 * weight++;
                    }
                }//for
                var checksumK = kTotal % 11;
                dataToEncodeWithChecksums += checksumK.ToString();
            }//if

            //encode data
            var space  = "0";
            var result = C11_Code[11] + space; //start-stop char + interchar space

            foreach (var c in dataToEncodeWithChecksums)
            {
                var index = (c == '-' ? 10 : Int32.Parse(c.ToString()));
                result += C11_Code[index];

                //inter-character space
                result += space;
            }//foreach

            //stop bars
            result += C11_Code[11];

            return(result);
        }//Encode_Code11
コード例 #12
0
        /// <summary>
        ///     Encode the raw data using the Code 11 algorithm.
        /// </summary>
        private string Encode_Code11()
        {
            if (!Barcode.CheckNumericOnly(Raw_Data.Replace("-", string.Empty)))
            {
                throw new Exception("EC11-1: Numeric data and '-' Only");
            }

            //calculate the checksums
            var weight = 1;
            var CTotal = 0;
            var Data_To_Encode_with_Checksums = Raw_Data;

            //figure the C checksum
            for (var i = Raw_Data.Length - 1; i >= 0; i--)
            {
                //C checksum weights go 1-10
                if (weight == 10)
                {
                    weight = 1;
                }

                if (Raw_Data[i] != '-')
                {
                    CTotal += int.Parse(Raw_Data[i].ToString()) * weight++;
                }
                else
                {
                    CTotal += 10 * weight++;
                }
            }
            var checksumC = CTotal % 11;

            Data_To_Encode_with_Checksums += checksumC.ToString();

            //K checksums are recommended on any message length greater than or equal to 10
            if (Raw_Data.Length >= 1)
            {
                weight = 1;
                var KTotal = 0;

                //calculate K checksum
                for (var i = Data_To_Encode_with_Checksums.Length - 1; i >= 0; i--)
                {
                    //K checksum weights go 1-9
                    if (weight == 9)
                    {
                        weight = 1;
                    }

                    if (Data_To_Encode_with_Checksums[i] != '-')
                    {
                        KTotal += int.Parse(Data_To_Encode_with_Checksums[i].ToString()) * weight++;
                    }
                    else
                    {
                        KTotal += 10 * weight++;
                    }
                }
                var checksumK = KTotal % 11;
                Data_To_Encode_with_Checksums += checksumK.ToString();
            }

            //encode data
            var space  = "0";
            var result = C11_Code[11] + space; //start-stop char + interchar space

            foreach (var c in Data_To_Encode_with_Checksums)
            {
                var index = c == '-' ? 10 : int.Parse(c.ToString());
                result += C11_Code[index];

                //inter-character space
                result += space;
            }

            //stop bars
            result += C11_Code[11];

            return(result);
        }