Exemplo n.º 1
0
        /// <summary>
        /// Try to get the AI at the current position
        /// </summary>
        /// <param name="data">The row data from the scanner</param>
        /// <param name="index">The refrence of the current position</param>
        /// <param name="usePlaceHolder">Sets if the last character of the AI should replaced with a placehoder ("d")</param>
        /// <returns>The current AI or null if no match was found</returns>
        private static AII GetAI(string data, ref int index, bool usePlaceHolder = false)
        {
            AII result = null;

            // Step through the different lenghts of the AIs
            for (int i = minLengthOfAI; i <= maxLengthOfAI; i++)
            {
                // get the AI sub string
                string ai = data.Substring(index, i);
                if (usePlaceHolder)
                {
                    ai = ai.Remove(ai.Length - 1) + "d";
                }
                // try to get the ai from the dictionary
                if (aiiDict.TryGetValue(ai, out result))
                {
                    // Shift the index to the next
                    index += i;
                    return(result);
                }
                // if no AI found, try it with the next lenght
            }
            // if no AI found here, than try it with placeholders. Assumed that is the first sep where usePlaceHolder is false
            if (!usePlaceHolder)
            {
                result = GetAI(data, ref index, true);
            }
            return(result);
        }
Exemplo n.º 2
0
        public AII getAiInfo(String pAi)
        {
            AII naii = new AII();

            if (pAi == "01")
            {
                naii.AICode    = "01";
                naii.minLength = 8;
                naii.maxLength = 14;  // was 14
                return(naii);
            }
            if (pAi == "17")
            {
                naii.AICode    = "17";
                naii.minLength = 6;
                naii.maxLength = 6;
                return(naii);
            }
            if (pAi == "10")
            {
                naii.AICode    = "10";
                naii.minLength = 1;
                naii.maxLength = 20;
            }
            if (pAi == "21")
            {
                naii.AICode    = "21";
                naii.minLength = 1;
                naii.maxLength = 20;
                return(naii);
            }
            return(naii);
        }
Exemplo n.º 3
0
 public AII(AII ai)
 {
     this.AICode    = ai.AICode;
     this.AIDesc    = ai.AIDesc;
     this.minLength = ai.minLength;
     this.maxLength = ai.maxLength;
     this.type      = ai.type;
     this.AIValue   = ai.AIValue;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Get the current code to the AI
        /// </summary>
        /// <param name="data">The row data from the scanner</param>
        /// <param name="ai">The current AI</param>
        /// <param name="index">The refrence of the current position</param>
        /// <returns>the data to the current AI</returns>
        private static string GetCode(string data, AII ai, ref int index)
        {
            var result = string.Empty;

            // get the max lenght to read.
            int lengthToRead = Math.Min(ai.LengthOfData, data.Length - index);

            if (index > data.Length || index + lengthToRead > data.Length)
            {
                return(result);
            }

            // get the data of the current AI
            result = data.Substring(index, lengthToRead);

            // check if the AI support a group seperator
            if (ai.FNC1)
            {
                // try to find the index of the group seperator
                int indexOfGroupTermination = result.IndexOf(GroupSeparator);
                if (indexOfGroupTermination >= 0)
                {
                    lengthToRead = indexOfGroupTermination;
                }
                // get the data of the current AI till the gorup seperator
                result = data.Substring(index, lengthToRead);

                // Shift the index to the next
                index += lengthToRead + 1;
            }
            else
            {
                // Shift the index to the next
                index += lengthToRead;
            }

            return(result);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Add an Application Identifier (AI)
 /// </summary>
 /// <param name="AI">Number of the AI</param>
 /// <param name="Description"></param>
 /// <param name="LengthOfAI"></param>
 /// <param name="DataDescription">The type of the content</param>
 /// <param name="LengthOfData">The max lenght of the content</param>
 /// <param name="FNC1">Support a group seperator</param>
 public static void Add(string AI, string Description, int LengthOfAI, DataType DataDescription, int LengthOfData, bool FNC1)
 {
     aiiDict[AI] = new AII(AI, Description, LengthOfAI, DataDescription, LengthOfData, FNC1);
 }
Exemplo n.º 6
0
        public void GS1DataConvert(string pBarcode)
        {
            String aiFull      = "";
            String aiWCheckSum = "";
            String aiValue     = "";
            //  Int32 aiCheckSum = 0;
            Int32 aiMinLength = 0;
            Int32 aiMaxLength = 0;
            int   index       = 0;

            if (pBarcode.Contains("01"))
            {
                index = pBarcode.IndexOf("01") + 2;
                AII sai = getAiInfo("01");
                aiMinLength = sai.minLength;
                aiMaxLength = sai.maxLength;

                aiFull      = pBarcode.Substring(index - 2, aiMaxLength + 2);
                aiWCheckSum = pBarcode.Substring(index, aiMaxLength);
                aiValue     = aiWCheckSum.Remove(aiWCheckSum.Length - 1, 1);
                //aiCheckSum = Int32.Parse(aiWCheckSum.Substring(aiWCheckSum.Length - 1, 1));
                // if (checkSum(aiValue, aiCheckSum))
                // {
                pBarcode = pBarcode.Replace(aiFull, String.Empty);
                BarcodeDecodeDictionary.Add("01", aiWCheckSum);
                //}
            }
            if (pBarcode.Contains("17"))
            {
                index = pBarcode.IndexOf("17") + 2;
                AII sai = getAiInfo("17");
                aiFull  = pBarcode.Substring(index - 2, sai.minLength + 2);
                aiValue = pBarcode.Substring(index, sai.minLength);
                //if (checkDate(aiValue) > DateTime.MinValue)
                //{

                //}
                pBarcode = pBarcode.Replace(aiFull, String.Empty);
                BarcodeDecodeDictionary.Add("17", aiValue);
            }
            if (pBarcode.Contains("10"))
            {
                index = pBarcode.IndexOf("10") + 2;
                AII sai = getAiInfo("10");
                aiMinLength = sai.minLength;
                aiMaxLength = sai.maxLength;
                aiMaxLength = pBarcode.Length < sai.maxLength ? pBarcode.Length - 2 : sai.maxLength;
                aiFull      = pBarcode.Substring(index - 2, aiMaxLength + 2);
                aiValue     = pBarcode.Substring(index, aiMaxLength);
                pBarcode    = pBarcode.Replace(aiFull, String.Empty);
                BarcodeDecodeDictionary.Add("10", aiValue);
                //BarcodeDecodeDictionary.Add("10", aiFull);
            }

            if (pBarcode.Contains("21"))
            {
                index = pBarcode.IndexOf("21") + 2;
                AII sai = getAiInfo("21");
                aiMinLength = sai.minLength;
                aiMaxLength = pBarcode.Length < sai.maxLength ? pBarcode.Length - 2 : sai.maxLength;
                aiFull      = pBarcode.Substring(index - 2, aiMaxLength);
                aiValue     = pBarcode.Substring(index, aiMaxLength);
                BarcodeDecodeDictionary.Add("21", aiValue);
            }
        }