Обробка штрихкоду елементу виробу
ШК містить у собі ID елементу та порядковий виробу.
Формування штрихкоду
function IDToBarCode(ID:string; Q:integer; D10 : boolean = false) : string;
Var ID, CID, BID, QQ : string;
Q : integer;
D10 : boolean;
begin
if pos('_', ID) = 0 then
result := ID else
begin
CID := copy(ID, 1, pos('_', ID) - 1);
BID := copy(ID, pos('_', ID) + 1);
QQ := IntTo26(Q, 1);
result := 'E' + CID + STRFormB(BID, 3, '0') + StrFormB(QQ, 3 , '0');
if (length(BID) = 1) and (length(QQ) = 1) then result := 'A' + CID + BID + QQ
else
if (length(BID) = 2) and (length(QQ) = 1) then result := 'B' + CID + BID + QQ
else
if (length(BID) = 1) and (length(QQ) = 2) then result := 'C' + CID + BID + QQ
else
if (length(BID) = 2) and (length(QQ) = 2) then result := 'D' + CID + BID + QQ;
if D10 then
result := '4' + IntToStr( s26ToInt(CID) ) + FormatFloat('00', s26ToInt(BID) ) + FormatFloat('00', s26ToInt(QQ) );
end;
end;
Const
nos: array [0 .. 35] of char = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
Function s26toInt(s: string): int64;
Var
SL: TStringList;
i, k : integer;
begin
try
SL := TStringList.Create;
result := 0;
for i := 0 to 35 do
SL.add(nos[i]);
for i := 1 to length(s) do
begin
k := SL.IndexOf(s[i]);
if k = -1 then
raise Exception.Create('Numver conversion error: ' + s)
else
result := result * 36 + SL.IndexOf(s[i]);
end;
finally
SL.Free;
end;
end;
Function IntTo26(n: int64; d: integer): string;
Var
b: int64;
a : integer;
begin
result := '';
while n > 0 do
begin
b := n mod 36;
n := n div 36;
result := nos[b] + result;
end;
for a := length(result) + 1 to d do
result := '0' + result;
end;
Приклад використання:
BarCode := IdToBarCode('31_1', 1);