Ver Mensaje Individual
  #7  
Antiguo 14-02-2014
cardanver cardanver is offline
Miembro
NULL
 
Registrado: feb 2012
Ubicación: Entre Ríos, Argentina
Posts: 14
Reputación: 0
cardanver Va por buen camino
el codigoooo

Estimados buen dia.
Como lo prometi subo el codigo para que si otro lo necesita lo tenga.
Le hice un par de ediciones que estan aclaradas en el mismo codigo.
A modo aclarativo el archivo1 es el log de un lector biometrico y el archivo2 es lo que necesita un soft de gestion para calcular las jornadas de los operarios.
Hay un par de lineas que se deben a que el archivo original es asi:

AC-No. Estado

102 06/02/2014 5:57
102 06/02/2014 5:57
102 06/02/2014 15:57
19 06/02/2014 6:07
19 06/02/2014 16:07
8 06/02/2014 8:25
8 06/02/2014 18:25

y en el archivo final no debe estar el titulo ni el espacio en blanco.
Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    OpenDialog1: TOpenDialog;
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    Label3: TLabel;
    Label4: TLabel;
    Button3: TButton;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Label1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button2Click(Sender: TObject);

var
  InputFile : TStringList;
  OutputFile : TStringList;
  AuxFile : TStringList;
  AuxStr : String;
  i : Integer;
  IFileName :String;
  OFileName :String;
begin
  IFileName := Edit1.Text; //aqui se toma el path seleccionado por el usuario.
  OFileName := GetCurrentdir+'\'+'final.txt'; //aqui se determina el path del archivo final que es el mismo directorio de donde se saco el archivo original.
  try
    InputFile := TStringList.Create;
    OutputFile := TStringList.Create;
    AuxFile := TStringList.Create;
    InputFile.LoadFromFile(IFileName);
    InputFile.Delete (0);
    InputFile.Delete (1);
    for i := 2 to InputFile.Count - 1 do
    begin
      ExtractStrings([' ',':'], [], PChar(InputFile[i]), AuxFile);
      AuxFile[0] := Format('%.3d',[StrToInt(AuxFile[0])]);
      AuxFile[2] := Format('%.2d',[StrToInt(AuxFile[2])]);
      AuxFile[3] := Format('%.2d',[StrToInt(AuxFile[3])]);
      AuxStr := AuxFile[0] + ' ' + AuxFile[1] + ' ' + AuxFile[2] + ':' + AuxFile[3];
      OutputFile.Add(AuxStr);
      AuxFile.Clear;
    end;
    OutputFile.SaveToFile(OFileName);
    MessageDlg('Archivo de Salida Generado Satisfactoriamente',mtInformation,[mbYes],0);
  finally
   InputFile.Free;
   OutputFile.Free;
   AuxFile.Free;
  end;

  Label3.Visible:=true;
  Label4.Visible:=true;
  Label4.Caption:=OFileName;
  Button3.Visible:=true;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  If OpenDialog1.Execute then
    Edit1.Text:=OpenDialog1.FileName;
    Button2.Visible:=true;
  end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Form1.Close;
end;
procedure TForm1.Label1Click(Sender: TObject);
begin

end;

Ahora estoy viendo como puedo hacer para que solo figuren la entrada y salida, ya que, a veces tengo en un mismo dia varias marcadas y solo son necesarias la primera y la ultima.
Si alguien tiene alguna idea, le agradeceria que la comente.
Si logro hacerlo andar vuelvo a subir el codigo completo.

Saludos y muchas gracias a todos por su ayuda.
Responder Con Cita