Ver Mensaje Individual
  #1  
Antiguo 22-03-2015
giulichajari giulichajari is offline
Miembro
 
Registrado: nov 2012
Posts: 306
Reputación: 12
giulichajari Va por buen camino
Recorrer directorio y trabajar con archivos

Buenas amigos, tengo una aplicacion cliente servidor en datasnap con delphi.

Del lado del cliente cuando no hay conexion los tickets y presupuestos se guardan en xml, con el metodo savetofile del clientdataset, ya que trabajo con este componente.

Entonces cuando retorna la conexion, necesito recorrer el directorio tickets por ejemplo y cargar los mismo en la base de datos, para lo mismo se usa el procedimiento del server que se usa siempre.

Código Delphi [-]
function cantticket():integer;
var
  rec: TSearchRec;
  carpeta:string;
  cant:integer;

begin
    carpeta :=ExtractFilePath(Application.ExeName)+'tickets';
    cant:=0;
    if FindFirst(carpeta, faAnyFile,rec) = 0 then
      begin
        try
        repeat

          if (rec.Attr and faDirectory = 0)
            or (rec.Name <> '.')
              and (rec.Name <> '..') then
                inc(cant);
        until FindNext(rec) <> 0;
     except
        FindClose(rec);
      end;
      FindClose(rec);
    end;
Result:=cant;
ShowMessage(inttostr(cant));
end;

Pense contar la cantidad de archivos primero, pero me identifica 1(uno solo), y por ende no envia nada.

Código Delphi [-]
procedure LeerDirectorio();
var
  rec: TSearchRec;
  carpeta:string;
  t,x:integer;
  nombrearchivo,nombrecopia:string;
  a:TServerMethods1Client;
l:integer;
fechae,horae:string;
cantidad,importe,preciou,efectivo,vueltoouble;
idc,ids,idprodu,numero:Integer;
nuevoticket:string;
begin
    if ClientModule1.SQLConnection1.Connected then
    begin
       a:=TServerMethods1Client.Create(ClientModule1.SQLConnection1.DBXConnection);

        if (cantticket(carpeta)>0) then
            begin
              t:=cantticket(carpeta);


              carpeta := ExtractFilePath(Application.ExeName)+'tickets';
              SetCurrentDir(carpeta);
            for x := 0 to t do

                begin

                  if FindFirst(carpeta,FaAnyfile,rec)=0 then
                  begin
                  nombrearchivo:=rec.Name;
                  ShowMessage(nombrearchivo);
                  ClientModule1.cdsticketpendiente.LoadFromFile(nombrearchivo);
                  nombrecopia:=ExtractFileName(Application.ExeName) + 'ticketscopia\' + nombrearchivo;
                  CopyFile(Pchar(nombrearchivo),Pchar(nombrecopia),True);
                  idc:=1;
                  ids:=1;
                  numero:=1;
                  importe:=ClientModule1.cdsticketpendiente.FieldByName('total').Value;
                  fechae:=ClientModule1.cdsticketpendientefechae.AsString;
                  horae:=ClientModule1.cdsticketpendientehorae.AsString;
                  efectivo:=ClientModule1.cdsticketpendienteefectivo.AsFloat;
                  vuelto:=efectivo - importe;
                   a.nuevoticket(numero,ids,idc,importe,efectivo,vuelto,fechae,horae);

                end;
                end;

      end
      else
      begin
       ShowMessage('no quedan transacciones pendientes');
      end;
        end
        else
        begin
          ShowMessage('no hay conexion para enviar los datos');
        end;
end;

Lo que hice lo saque de ejemplos del foro y de la web, pero me esta costando.
Saludos
Responder Con Cita