示例#1
0
        /// <summary>
        /// Inizializza un nuovo algoritmo per il parsing di uno specifico barcode
        /// </summary>
        /// <param name="barcode"></param>
        public GS1Algorithm(char[] barcode)
        {
            _ai = "";
            _state = GS1State.E;
            Index = 0;

            _barcode = barcode;
        }
示例#2
0
        /// <summary>
        /// Fa avanzare l'algoritmo per il riconoscimento dell'AI
        /// </summary>
        /// <param name="next">Il carattere successivo</param>
        /// <returns></returns>
        /// <exception cref="Drkstr.GS1AlgorithmException" /> in caso di errore
        private GS1Algorithm SetNextChar(char next)
        {
            if (State == GS1State.E)
            {
                _state = GS1State.L2;
                _ai = _ai + next;
            }
            else if (State == GS1State.L2)
            {
                if (AI.Equals("0"))
                {
                    if (next == '0' || next == '1' || next == '2')
                    {
                        _state = GS1State.EXT;
                        _ai = _ai + next;
                    }
                    else
                    {
                        throw new GS1AlgorithmException(Index);
                    }
                }
                else if (AI.Equals("1"))
                {
                    if (CharEquals(next, new char[] { '0', '1', '2', '3', '5', '7' }))
                    {
                        _state = GS1State.EXT;
                        _ai = _ai + next;
                    }
                    else
                    {
                        throw new GS1AlgorithmException(Index);
                    }
                }
                else if (AI.Equals("2"))
                {
                    if (CharEquals(next, new char[] { '0', '1', '2' }))
                    {
                        _state = GS1State.EXT;
                        _ai = _ai + next;
                    }
                    else if (CharEquals(next, new char[] { '4', '5' }))
                    {
                        _state = GS1State.L3;
                        _ai = _ai + next;
                    }
                    else
                    {
                        throw new GS1AlgorithmException(Index);
                    }
                }
                else if (AI.Equals("3"))
                {
                    if (CharEquals(next, new char[] { '0', '7' }))
                    {
                        _state = GS1State.EXT;
                        _ai = _ai + next;
                    }
                    else if (CharEquals(next, new char[] { '0', '1', '2', '3', '4', '5', '6', '9' }))
                    {
                        _state = GS1State.L3;
                        _ai = _ai + next;
                    }
                    else
                    {
                        throw new GS1AlgorithmException(Index);
                    }
                }
                else if (StringEquals(AI, new string[] { "4", "7", "8" }))
                {
                    if (CharEquals(next, new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }))
                    {
                        _state = GS1State.L2;
                        _ai = _ai + next;
                    }
                    else
                    {
                        throw new GS1AlgorithmException(Index);
                    }
                }
                else if (AI.Equals("9"))
                {
                    if (CharEquals(next, new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }))
                    {
                        _state = GS1State.EXT;
                        _ai = _ai + next;
                    }
                    else
                    {
                        throw new GS1AlgorithmException(Index);
                    }
                }
                else if (StringEquals(AI, new string[] { "40", "41", "42" }))
                {
                    if (CharEquals(next, new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }))
                    {
                        _state = GS1State.EXT;
                        _ai = _ai + next;
                    }
                    else
                    {
                        throw new GS1AlgorithmException(Index);
                    }
                }
                else if (StringEquals(AI, new string[] { "70", "80", "81", "82" }))
                {
                    if (CharEquals(next, new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }))
                    {
                        _state = GS1State.L4;
                        _ai = _ai + next;
                    }
                    else
                    {
                        throw new GS1AlgorithmException(Index);
                    }
                }
            }
            else if (State == GS1State.L3)
            {
                if (AI.Equals("24"))
                {
                    if (CharEquals(next, new char[] { '0', '1', '2' }))
                    {
                        _state = GS1State.EXT;
                        _ai = _ai + next;
                    }
                    else
                    {
                        throw new GS1AlgorithmException(Index);
                    }
                }
                else if (AI.Equals("25"))
                {
                    if (CharEquals(next, new char[] { '0', '1' , '3', '4'}))
                    {
                        _state = GS1State.EXT;
                        _ai = _ai + next;
                    }
                    else
                    {
                        throw new GS1AlgorithmException(Index);
                    }
                }
                else if (AI.Equals("25"))
                {
                    if (CharEquals(next, new char[] { '0', '1', '3', '5' }))
                    {
                        _state = GS1State.EXT;
                        _ai = _ai + next;
                    }
                    else
                    {
                        throw new GS1AlgorithmException(Index);
                    }
                }
                else if (StringEquals(AI, new string[] { "31", "32", "33", "34", "35", "36", "39" }))
                {
                    if (CharEquals(next, new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }))
                    {
                        _state = GS1State.EXT;
                        _ai = _ai + next;
                    }
                    else
                    {
                        throw new GS1AlgorithmException(Index);
                    }
                }
            }
            else if (State == GS1State.L4)
            {
                if(CharEquals(next, new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 's' }))
                {
                    _state = GS1State.EXT;
                    _ai = _ai + next;
                }
                else
                {
                    throw new GS1AlgorithmException(Index);
                }
            }

            return this;
        }
示例#3
0
 /// <summary>
 /// Esegue il reset dell'avanzamento del corrente algoritmo ma non cambia il barcode
 /// N.B.: per utilizzare l'algoritmo su un altro barcode è necessario istanziarne uno nuovo
 /// </summary>
 public void ResetAI()
 {
     _ai = "";
     _state = GS1State.E;
 }