Ver Mensaje Individual
  #15  
Antiguo 15-07-2008
ginasil ginasil is offline
Miembro
 
Registrado: jun 2004
Posts: 20
Reputación: 0
ginasil Va por buen camino
parte ii

constructor Thilo_mostrandoestados.Create(Box: TCheckListBox;cajon : string);
begin
FBox := Box;
FCajon := cajon;
// FreeOnTerminate := True;
inherited Create(true);
Priority := tpHigher; // tpNormal;
end;
constructor Thilo_mostrandoestados2.Create(Box: TStringGrid ;cajon : string);
begin
FBox := Box;
FCajon := cajon;
// FreeOnTerminate := True;
inherited Create(true);
Priority := tpHigher;
end;

procedure Thilo_mostrandoestados.Execute;
var
consulta : TQuery;
// basededatos_1 : TDatabase;
// session_1 : TSession;
rutas,consulta2: string;
k,i : integer;
begin
if (self) = nil then Showmessage('no asignado');
try
while not Terminated do
begin
consulta := TQuery.create(Application);
consulta.Active := false;
consulta.DatabaseName := 'inase';
rutas := Form6.rutas_en_cajones(FBox.Items);
if rutas <> '' then
begin
consulta2 := ' and codruta in (' +rutas+ ')';
end
else
begin
consulta2 := '';
end;
if consulta2 <> '' then
begin
consulta.SQL.Clear;
consulta.SQL.Add(' select codruta,tipo_de_sinc from sincronizadas ');
consulta.SQL.Add(' where estado <> '+Fcajon + ' ' + consulta2 );
consulta.Active := true;
consulta.First;
for k := 0 to consulta.RecordCount - 1 do
begin
accion := 'borrar';
codruta := consulta.FieldByName('codruta').AsString;
tipo_de_sinc := consulta.FieldByName('tipo_de_sinc').AsString;
Synchronize( MostrarProgreso );
Sleep(100);
consulta.Next;
end;
end;

if rutas <> '' then
begin
consulta2 := ' and codruta not in (' +rutas+ ')';
end
else
begin
consulta2 := '';
end;

consulta.SQL.Clear;
consulta.SQL.Add(' select codruta,tipo_de_sinc from sincronizadas ');
consulta.SQL.Add(' where estado = '+Fcajon + ' ' + consulta2 );
consulta.Active := true;
consulta.First;
for k := 0 to consulta.RecordCount - 1 do
begin
if FBox.Items.IndexOf(consulta.FieldByName('codruta').AsString) = -1 then
begin
accion := 'agregar';
codruta := consulta.FieldByName('codruta').AsString;
tipo_de_sinc := consulta.FieldByName('tipo_de_sinc').AsString;
Sleep(50);
Synchronize( MostrarProgreso );

end;
consulta.Next;
end;

consulta.Close;
consulta.Destroy;
Synchronize( MostrarProgreso2 );
Sleep(300);
end;
finally
// consulta.Destroy;
// FBox.Free;
// Form6.RichEdit1.Lines.Add(' se cerro el hilo del cajon = ' + Fcajon);
end;
end;
procedure Thilo_mostrandoestados2.Execute;
var
consulta : TQuery;
rutas,consulta2: string;
k,l,posicion : integer;
begin
if (self) = nil then Showmessage('no asignado');
try
while not Terminated do
begin
consulta := TQuery.create(Application);
consulta.Active := false;
consulta.DatabaseName := 'inase';
rutas := Form6.rutas_en_cajones(FBox.Cols[0]);
if (rutas <> ',') or (rutas <> '') then
begin
consulta2 := ' and codruta in (' +rutas+ ')';
end
else
begin
consulta2 := '';
end;
if consulta2 = ' and codruta in ()' then
begin
consulta2 := '';
end;
consulta.SQL.Clear;
consulta.SQL.Add(' select codruta,tipo_de_sinc from sincronizadas ');
consulta.SQL.Add(' where estado <> ' + Fcajon + ' ' + consulta2 );
consulta.Active := true;
consulta.First;
for k := 0 to consulta.RecordCount - 1 do
begin
accion := 'borrar';
codruta := consulta.FieldByName('codruta').AsString;
tipo_de_sinc := consulta.FieldByName('tipo_de_sinc').AsString;
Synchronize( MostrarProgreso );
Sleep(50);
consulta.Next;
end;
if rutas <> '' then
begin
consulta2 := ' and codruta not in (' +rutas+ ')';
end
else
begin
consulta2 := '';
end;
consulta.SQL.Clear;
consulta.SQL.Add(' select codruta,tipo_de_sinc from sincronizadas ');
consulta.SQL.Add(' where estado = '+Fcajon + ' ' + consulta2 );
consulta.Active := true;
consulta.First;
for k := 0 to consulta.RecordCount - 1 do
begin
if FBox.Cells[0,FBox.RowCount - 1] <> '' then
begin
accion := 'agregar';
codruta := consulta.FieldByName('codruta').AsString;
tipo_de_sinc := consulta.FieldByName('tipo_de_sinc').AsString;
Synchronize( MostrarProgreso );
Sleep(50);
end;
consulta.Next;
end;

consulta.Close;
consulta.Destroy;
Synchronize( MostrarProgreso2 );
Sleep(400);
end;

finally
end;
end;

procedure Thilo_mostrandoestados.MostrarProgreso;
begin
if Terminated then exit;
if mensaje <> '' then
begin
Form6.Memomostrarhilo.Lines.Add(mensaje + ' <=> ' + FormatDateTime('hh:nn:ss',now));
end;
if accion = 'borrar' then
begin
FBox.Items.Delete(FBox.items.Indexof(codruta));
end;
if accion = 'agregar' then
begin
FBox.Items.Add(codruta);
end;
if Form6.StringGrid5.Cols[0].IndexOf(codruta) >= 0 then
begin
Form6.StringGrid5.Cells[1,Form6.StringGrid5.Cols[0].IndexOf(codruta)] := tipo_de_sinc;
end
else
begin
Form6.StringGrid5.RowCount := Form6.StringGrid5.RowCount + 1;
Form6.StringGrid5.Cells[0,Form6.StringGrid5.RowCount - 1] := codruta;
Form6.StringGrid5.Cells[1,Form6.StringGrid5.RowCount - 1] := tipo_de_sinc;
end;

// FBox.Repaint;
if Fcajon = '1' then Form6.aumentar(Form6.ProgressBar10);
if Fcajon = '2' then Form6.aumentar(Form6.ProgressBar9);
if Fcajon = '3' then Form6.aumentar(Form6.ProgressBar8);
if Fcajon = '4' then Form6.aumentar(Form6.ProgressBar7);
if Fcajon = '5' then Form6.aumentar(Form6.ProgressBar6);
if Fcajon = '6' then Form6.aumentar(Form6.ProgressBar5);
if Fcajon = '7' then Form6.aumentar(Form6.ProgressBar4);

end;
procedure Thilo_mostrandoestados.MostrarProgreso2;
begin
if Terminated then exit;
if mensaje <> '' then
begin
Form6.Memomostrarhilo.Lines.Add(mensaje + ' <=> ' + FormatDateTime('hh:nn:ss',now));
end;
// FBox.Repaint;
if Fcajon = '1' then Form6.aumentar(Form6.ProgressBar10);
if Fcajon = '2' then Form6.aumentar(Form6.ProgressBar9);
if Fcajon = '3' then Form6.aumentar(Form6.ProgressBar8);
if Fcajon = '4' then Form6.aumentar(Form6.ProgressBar7);
if Fcajon = '5' then Form6.aumentar(Form6.ProgressBar6);
if Fcajon = '6' then Form6.aumentar(Form6.ProgressBar5);
if Fcajon = '7' then Form6.aumentar(Form6.ProgressBar4);

end;

procedure Thilo_mostrandoestados2.MostrarProgreso;
var
posicion,l : integer;
begin
if Terminated then exit;
if mensaje <> '' then
begin
Form6.Memomostrarhilo.Lines.Add(mensaje + ' <=> ' + FormatDateTime('hh:nn:ss',now));
end;
if accion = 'borrar' then
begin
posicion := FBox.Cols[0].IndexOf(codruta);
for l := posicion to Form6.StringGrid2.RowCount - 1 do
begin
Form6.StringGrid2.Cells[0,l] := Form6.StringGrid2.Cells[0,l + 1];
Form6.StringGrid2.Cells[1,l] := Form6.StringGrid2.Cells[1,l + 1];
Form6.StringGrid2.Cells[2,l] := Form6.StringGrid2.Cells[2,l + 1];
Form6.StringGrid2.Cells[3,l] := Form6.StringGrid2.Cells[2,l + 1];
end;
Form6.StringGrid2.RowCount := Form6.StringGrid2.RowCount - 1;
end;
if accion = 'agregar' then
begin
Form6.StringGrid2.RowCount := FBox.RowCount + 1;
Form6.StringGrid2.Cells[0,Form6.StringGrid2.RowCount - 1] := codruta;
Form6.StringGrid2.Cells[1,Form6.StringGrid2.RowCount - 1] := '';
Form6.StringGrid2.Cells[2,Form6.StringGrid2.RowCount - 1] := '';
Form6.StringGrid2.Cells[3,Form6.StringGrid2.RowCount - 1] := '';
end;


if Form6.StringGrid5.Cols[0].IndexOf(codruta) >= 0 then
begin
Form6.StringGrid5.Cells[1,Form6.StringGrid5.Cols[0].IndexOf(codruta)] := tipo_de_sinc;
end
else
begin
Form6.StringGrid5.RowCount := Form6.StringGrid5.RowCount + 1;
Form6.StringGrid5.Cells[0,Form6.StringGrid5.RowCount - 1] := codruta;
Form6.StringGrid5.Cells[1,Form6.StringGrid5.RowCount - 1] := tipo_de_sinc;
end;
// FBox.Repaint;
if Form6.ProgressBar1.Position = 499 then
begin
Form6.ProgressBar1.Position := 0;
end;
Form6.ProgressBar1.Position := Form6.ProgressBar1.Position + 1;
end;
procedure Thilo_mostrandoestados2.MostrarProgreso2;
var
posicion,l : integer;
begin
if Terminated then exit;
if mensaje <> '' then
begin
Form6.Memomostrarhilo.Lines.Add(mensaje + ' <=> ' + FormatDateTime('hh:nn:ss',now));
end;

// FBox.Repaint;
if Form6.ProgressBar1.Position = 499 then
begin
Form6.ProgressBar1.Position := 0;
end;
Form6.ProgressBar1.Position := Form6.ProgressBar1.Position + 1;
end;
procedure TForm6.insertarpaso(ruta,paso,tipoproceso,agentes : string);
var
id_log_ipegasohh_move : string;
begin
dt.Qrf.Active := false;
dt.Qrf.SQL.Clear;
dt.Qrf.SQL.Add(' replace into sincronizadas values ("' +ruta+ '","' +paso+ '","' +tipoproceso+ '","' +agentes+ '")');
dt.Qrf.ExecSQL;
if StringGrid5.Cols[0].IndexOf(ruta) >= 0 then
begin
StringGrid5.Cells[1,StringGrid5.Cols[0].IndexOf(ruta)] := tipoproceso;
end
else
begin
StringGrid5.RowCount := StringGrid5.RowCount + 1;
StringGrid5.Cells[0,StringGrid5.RowCount - 1] := ruta;
StringGrid5.Cells[1,StringGrid5.RowCount - 1] := tipoproceso;
end;

dt.Qrf.Active := false;
dt.Qrf.SQL.Clear;
dt.Qrf.SQL.Add(' insert into log_ipegasohh_move_movimientos_2 (usuario,comentario,codruta,fecha,transmision,estado,proceso) values ( ');
dt.Qrf.SQL.Add('"' +Form3.Edit1.Text +'",');
dt.Qrf.SQL.Add('"N/A",');
dt.Qrf.SQL.Add('"' +ruta+ '",');
dt.Qrf.SQL.Add('"' +FormatDateTime('yyyy-mm-dd hh:nn:ss',now)+ '", ');
dt.Qrf.SQL.Add('"N",');
dt.Qrf.SQL.Add('"' +paso+ '",');
dt.Qrf.SQL.Add('"' +tipoproceso+ '")');
dt.Qrf.ExecSQL
end;
function TForm6.rutas_en_cajones(posiciones : TStrings): string;
var
i : integer;
resultado : string;
begin
resultado := '';
for i := 0 to posiciones.Count - 1 do
begin
resultado :=resultado + posiciones.Strings[i] + ',';
end;
resultado := Copy(resultado,0,length(resultado) - 1);
result := resultado;
end;
function TForm6.aumentar(barra : TProgressBar) : boolean;
begin
if barra.Position = 499 then
begin
barra.Position := 0;
end;
barra.Position := barra.Position + 1;
end;
procedure TForm6.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if hilo0 <> nil then
begin
hilo0.Terminate;
hilo0.WaitFor;
hilo0.Free;
hilo0 := nil;
end;
if hilo1 <> nil then
begin
hilo1.Terminate;
hilo1.WaitFor;
hilo1.Free;
hilo1 := nil;
end;
if hilo2 <> nil then
begin
hilo2.Terminate;
hilo2.WaitFor;
hilo2.Free;
hilo2 := nil;
end;
if hilo3 <> nil then
begin
hilo3.Terminate;
hilo3.WaitFor;
hilo3.Free;
hilo3 := nil;
end;
if hilo4 <> nil then
begin
hilo4.Terminate;
hilo4.WaitFor;
hilo4.Free;
hilo4 := nil;
end;
if hilo5 <> nil then
begin
hilo5.Terminate;
hilo5.WaitFor;
hilo5.Free;
hilo5 := nil;
end;
if hilo6 <> nil then
begin
hilo6.Terminate;
hilo6.WaitFor;
hilo6.Free;
hilo6 := nil;
end;
if hilo9 <> nil then
begin
hilo9.Terminate;
hilo9.WaitFor;
hilo9.Free;
hilo9 := nil;
end;
Sleep(1000);
end;
procedure TForm6.BitBtn1Click(Sender: TObject);
begin
listarrutas;
PageControl1.ActivePageIndex := 0;
end;
end.
Responder Con Cita