67 lines
1.8 KiB
ObjectPascal
67 lines
1.8 KiB
ObjectPascal
|
|
unit uReferenciasUtils;
|
|||
|
|
|
|||
|
|
interface
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
uDAInterfaces, uDADataTable, uDABusinessProcessor;
|
|||
|
|
|
|||
|
|
function darReferenciaSiguiente(const Referencia: String): String;
|
|||
|
|
|
|||
|
|
implementation
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
SysUtils;
|
|||
|
|
|
|||
|
|
{ Se utiliza en las reglas de negocio del servidor y
|
|||
|
|
devuelve la conexi<EFBFBD>n utilizada por el BusinessProcessor para
|
|||
|
|
procesar los deltas. }
|
|||
|
|
function darReferenciaSiguiente(const Referencia: String): String;
|
|||
|
|
var
|
|||
|
|
ParteEntera, ParteCaracter: String;
|
|||
|
|
Semaforo: Boolean;
|
|||
|
|
i, LongitudParteEntera: Integer;
|
|||
|
|
begin
|
|||
|
|
//Por defecto la parte caracter ser<65> todo
|
|||
|
|
ParteCaracter := Copy(Referencia, 1, length(Referencia));
|
|||
|
|
Semaforo:= false;
|
|||
|
|
for i := 0 to length(Referencia) do
|
|||
|
|
begin
|
|||
|
|
if (Referencia[i] in ['0','1','2','3','4','5','6','7','8','9']) then
|
|||
|
|
begin
|
|||
|
|
if not Semaforo then
|
|||
|
|
begin
|
|||
|
|
//Cogemos el resto de la cadena suponiendo que no hay m<>s caracter
|
|||
|
|
ParteEntera := Copy(Referencia, i, length(Referencia)+1);
|
|||
|
|
Semaforo := true;
|
|||
|
|
end;
|
|||
|
|
end
|
|||
|
|
else
|
|||
|
|
begin
|
|||
|
|
//Volvemos a asignar la parte caracter ya que hemos encontrado otro
|
|||
|
|
//e inicializamos el sem<65>foro para volver a coger la parte entera si encontramos
|
|||
|
|
//alg<6C>n n<>mero
|
|||
|
|
ParteCaracter := Copy(Referencia, 1, i);
|
|||
|
|
Semaforo := False;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
LongitudParteEntera := Length(ParteEntera);
|
|||
|
|
//Si no tenemos ning<6E>n n<>mero en parte entera asignamos 1 por defecto
|
|||
|
|
try
|
|||
|
|
i := StrToInt(ParteEntera);
|
|||
|
|
except
|
|||
|
|
i := 1;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
//Incrementamos y rellenamos con ceros, en el caso de ser necesario
|
|||
|
|
Inc(i);
|
|||
|
|
ParteEntera := IntToStr(i);
|
|||
|
|
for i:=Length(ParteEntera) to LongitudParteEntera-1 do
|
|||
|
|
ParteEntera := '0' + ParteEntera;
|
|||
|
|
|
|||
|
|
Result := ParteCaracter + ParteEntera;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
|
|||
|
|
end.
|