Beispiel #1
0
        private int[] GenerateBarcodeValues(List <CodeSetEntry> codeSetEntries)
        {
            List <int> values         = new List <int>();
            CodeSet    currentCodeSet = CodeSet.None;

            for (int i = 0; i < codeSetEntries.Count; i++)
            {
                CodeSetEntry entry = codeSetEntries[i];

                if (entry.CodeSet != currentCodeSet)
                {
                    if (i == 0)
                    {
                        CodeFunction codeFunction =
                            entry.CodeSet == CodeSet.CodeA ?
                            CodeFunction.StartA :
                            entry.CodeSet == CodeSet.CodeB ?
                            CodeFunction.StartB :
                            CodeFunction.StartC;
                        values.Add(codeSetToFunctionMap[entry.CodeSet][codeFunction]);
                    }
                    else
                    {
                        CodeFunction codeFunction =
                            entry.CodeSet == CodeSet.CodeA ?
                            CodeFunction.CodeA :
                            entry.CodeSet == CodeSet.CodeB ?
                            CodeFunction.CodeB :
                            CodeFunction.CodeC;
                        values.Add(codeSetToFunctionMap[currentCodeSet][codeFunction]);
                    }
                    currentCodeSet = entry.CodeSet;
                }
                if (entry.SetFNC1)
                {
                    values.Add(codeSetToFunctionMap[currentCodeSet][CodeFunction.FNC1]);
                }
                if (entry.CodeSet == CodeSet.CodeC)
                {
                    for (int j = 0; j < entry.Values.Count; j += 2)
                    {
                        int value = int.Parse(string.Format(
                                                  "{0}{1}",
                                                  Convert.ToChar(entry.Values[j]),
                                                  Convert.ToChar(entry.Values[j + 1])));
                        values.Add(value);
                    }
                }
                else
                {
                    for (int j = 0; j < entry.Values.Count; j++)
                    {
                        values.Add(GetCodeValueForChar(entry.Values[j]));
                    }
                }
            }
            values.Add(CalculateChecksum(values));
            values.Add(codeSetToFunctionMap[CodeSet.CodeA][CodeFunction.Stop]);
            return(values.ToArray());
        }
Beispiel #2
0
        private List <CodeSetEntry> OptimizeCodeSetEntries(List <CodeSetEntry> codeSetEntries)
        {
            List <CodeSetEntry> optimizedEntryList = new List <CodeSetEntry>();

            for (int i = 0; i < codeSetEntries.Count; i++)
            {
                CodeSetEntry entry = codeSetEntries[i];

                if (entry.CodeSet == CodeSet.CodeC)
                {
                    if (i == 0)
                    {
                        if (entry.Values.Count < 4)
                        {
                            entry.CodeSet = codeSetEntries[i + 1].CodeSet;
                        }
                    }
                    else if (i > 0 && i < codeSetEntries.Count - 1)
                    {
                        if (entry.Values.Count < 6)
                        {
                            entry.CodeSet = codeSetEntries[i - 1].CodeSet;
                        }
                    }
                    else if (i == codeSetEntries.Count - 1)
                    {
                        if (entry.Values.Count < 4)
                        {
                            entry.CodeSet = codeSetEntries[i - 1].CodeSet;
                        }
                    }
                }
                optimizedEntryList.Add(entry);
            }

            return(optimizedEntryList);
        }
Beispiel #3
0
        private List <CodeSetEntry> AnalyzeInputString(byte[] asciiBytes)
        {
            List <CodeSetEntry> codeSetEntries = new List <CodeSetEntry>();
            int          index          = 0;
            CodeSet      currentCodeSet = CodeSet.None;
            CodeSetEntry entry          = null;
            bool         setFNC1        = false;

            do
            {
                char currentChar = Convert.ToChar(asciiBytes[index]);
                if (currentChar == '(')
                {
                    index++;
                    setFNC1 = true;
                    continue;
                }
                char nextChar = index + 1 < asciiBytes.Length ? Convert.ToChar(asciiBytes[index + 1]) : '^';
                if (CODE_C_VALID_CHARS.Contains(currentChar) &&
                    CODE_C_VALID_CHARS.Contains(nextChar))
                {
                    if (currentCodeSet == CodeSet.CodeC && !setFNC1)
                    {
                        entry = codeSetEntries[codeSetEntries.Count - 1];
                    }
                    else
                    {
                        entry = new CodeSetEntry(CodeSet.CodeC, setFNC1);
                        codeSetEntries.Add(entry);
                        currentCodeSet = CodeSet.CodeC;
                    }
                    entry.Values.Add(asciiBytes[index++]);
                    entry.Values.Add(asciiBytes[index++]);
                }
                else if (CODE_A_VALID_CHARS.Contains(currentChar))
                {
                    if (currentCodeSet == CodeSet.CodeA && !setFNC1)
                    {
                        entry = codeSetEntries[codeSetEntries.Count - 1];
                    }
                    else
                    {
                        entry = new CodeSetEntry(CodeSet.CodeA, setFNC1);
                        codeSetEntries.Add(entry);
                        currentCodeSet = CodeSet.CodeA;
                    }
                    entry.Values.Add(asciiBytes[index++]);
                }
                else if (CODE_B_VALID_CHARS.Contains(currentChar))
                {
                    if (currentCodeSet == CodeSet.CodeB && !setFNC1)
                    {
                        entry = codeSetEntries[codeSetEntries.Count - 1];
                    }
                    else
                    {
                        entry = new CodeSetEntry(CodeSet.CodeB, setFNC1);
                        codeSetEntries.Add(entry);
                        currentCodeSet = CodeSet.CodeB;
                    }
                    entry.Values.Add(asciiBytes[index++]);
                }
                else
                {
                    // TODO: Implement exception handling!
                }
                setFNC1 = false;
            } while (index < asciiBytes.Length);

            return(codeSetEntries);
        }