Ver Mensaje Individual
  #14  
Antiguo 15-07-2008
ginasil ginasil is offline
Miembro
 
Registrado: jun 2004
Posts: 20
Reputación: 0
ginasil Va por buen camino
oye gracias...es un codigo al que le hago mantenimiento y no cabe...... revise como me dijiste y separé el código de los hilos .......

parte i

unit Unit6;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls,inifiles, ExtCtrls, CheckLst,QDialogs,
Buttons,math, Grids, DBGrids, Psock, NMFtp, Menus, Mask, FileCtrl, SBSftpCommon,
SBSimpleSftp, SBX509, SBCustomCertStorage, SBPGPKeys,SBSSHKeyStorage,SBSSHConstants,
SBUtils,DateUtils,registry,db,dbtables;
const SFTP_BLOCK_SIZE = $10000;
type Tordenesdias = array[1..7] of string;
type
Thilo_mostrandoestados = class(TThread)
private
FBox: TCheckListBox;
Fcajon,mensaje,codruta,accion,tipo_de_sinc : String;
// estadocomparando : integer;
protected
procedure Execute; override;
procedure MostrarProgreso;
procedure MostrarProgreso2;
public
constructor Create(Box: TCheckListBox;cajon : string);
// destructor Destroy; override;
end;
type
Thilo_mostrandoestados2 = class(TThread)
private
FBox: TStringGrid;
Fcajon,mensaje,codruta,accion,tipo_de_sinc : String;
estadocomparando : integer;
protected
procedure Execute; override;
procedure MostrarProgreso;
procedure MostrarProgreso2;
public
constructor Create(Box: TStringGrid;cajon : string);
end;

type
TForm6 = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
StringGrid3: TStringGrid;
StringGrid2: TStringGrid;
CheckListBox2: TCheckListBox;
CheckListBox6: TCheckListBox;
CheckListBox3: TCheckListBox;
CheckListBox5: TCheckListBox;
CheckListBox4: TCheckListBox;
CheckListBox7: TCheckListBox;
CheckListBox1: TCheckListBox;
SpeedButton28: TSpeedButton;
ProgressBar10: TProgressBar;
ProgressBar7: TProgressBar;
ProgressBar6: TProgressBar;
ProgressBar8: TProgressBar;
ProgressBar9: TProgressBar;
ProgressBar5: TProgressBar;
ProgressBar4: TProgressBar;
ProgressBar1: TProgressBar;
StringGrid5: TStringGrid;
Memomostrarhilo: TMemo;
BitBtn1: TBitBtn;
procedure FormActivate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure SpeedButton28Click(Sender: TObject);
procedure listarrutas;
procedure insertarpaso(ruta,paso,tipoproceso,agentes : string);
function rutas_en_cajones(posiciones : Tstrings): string;
function aumentar(barra : TProgressBar) : boolean;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
hilo0 : Thilo_mostrandoestados2;
hilo1,hilo2,hilo3,hilo4,hilo5,hilo6,hilo9 : Thilo_mostrandoestados;
{ Public declarations }
end;
var
Form6: TForm6;
implementation
uses Unit2, Unit3;
{$R *.dfm}
procedure TForm6.FormActivate(Sender: TObject);
begin
hilo0.Resume;
hilo1.Resume;
hilo2.Resume;
hilo3.Resume;
hilo4.Resume;
hilo5.Resume;
hilo6.Resume;
hilo9.Resume;
end;
procedure TForm6.FormShow(Sender: TObject);
begin
StringGrid3.Cells[0,0] := 'Ruta';
StringGrid3.Cells[1,0] := 'P';
StringGrid3.Cells[2,0] := 'A';
StringGrid3.Cells[3,0] := 'E';
end;
procedure TForm6.SpeedButton28Click(Sender: TObject);
begin
listarrutas;
hilo0.Resume;
hilo1.Resume;
hilo2.Resume;
hilo3.Resume;
hilo4.Resume;
hilo5.Resume;
hilo6.Resume;
hilo9.Resume;
end;

procedure TForm6.listarrutas;
var
i,j,verificador : integer;
primero : boolean;
begin
dt.qbusca.Active := false;
dt.qbusca.SQL.Clear;
dt.qbusca.SQL.Add('select count(*) as contador from sincronizadas ');
dt.qbusca.Active := true;
dt.qbusca.First;
verificador := dt.qbusca.FieldByName('contador').AsInteger;
if verificador = 0 then
begin
// inicia de ceros
for i := 0 to StringGrid2.RowCount - 1 do
begin
for j := 0 to StringGrid2.ColCount - 1 do
begin
StringGrid2.Cells[j,i] := '';
end;
end;
dt.qbusca.Active := false;
dt.qbusca.SQL.Clear;
dt.qbusca.SQL.Add('select codigo from ruta where tienehh = "s" and activo = "1" and modem = "n" order by codigo ');
try
dt.qbusca.Active := true;
except
dt.qbusca.SQL.Clear;
dt.qbusca.SQL.Add('select codigo from ruta where tienehh = "s" and activo = "1" order by codigo ');
dt.qbusca.Active := true;
end;
dt.qbusca.First;
StringGrid2.RowCount := dt.qbusca.RecordCount;
for i := 0 to dt.qbusca.RecordCount - 1 do
begin
StringGrid2.Cells[0,i] := dt.qbusca.fieldbyname('codigo').AsString;
StringGrid2.Cells[1,i] := '';
insertarpaso(dt.qbusca.fieldbyname('codigo').AsString,'0','-','-');
dt.qbusca.Next;
end;
StringGrid2.Enabled := true;
//creartablashh;
end //no es nuevo
else
begin
//
dt.qbusca.Active := false;
dt.qbusca.SQL.Clear;
dt.qbusca.SQL.Add(' select * from sincronizadas ');
dt.qbusca.Active := true;
dt.qbusca.First;
StringGrid2.RowCount := 0;
primero := true;

CheckListBox1.Items.Clear;
CheckListBox2.Items.Clear;
CheckListBox3.Items.Clear;
CheckListBox4.Items.Clear;
CheckListBox5.Items.Clear;
CheckListBox6.Items.Clear;
CheckListBox7.Items.Clear;
// CheckListBox10.Items.Clear;
// CheckListBox11.Items.Clear;
for i := 0 to StringGrid2.RowCount - 1 do
begin
for j := 0 to StringGrid2.ColCount - 1 do
begin
StringGrid2.Cells[j,i] := '';
end;
end;
for i := 0 to StringGrid5.RowCount - 1 do
begin
for j := 0 to StringGrid5.ColCount - 1 do
begin
StringGrid5.Cells[j,i] := '';
end;
end;
StringGrid5.RowCount := dt.qbusca.RecordCount;

for i := 0 to dt.qbusca.RecordCount - 1 do
begin
StringGrid5.Cells[0,i] := dt.qbusca.FieldByName('codruta').AsString;
StringGrid5.Cells[1,i] := dt.qbusca.FieldByName('tipo_de_sinc').AsString;
if dt.qbusca.FieldByName('estado').AsInteger = 0 then
begin
if primero then
begin
StringGrid2.Cells[0,StringGrid2.RowCount - 1] := dt.qbusca.FieldByName('codruta').AsString;
StringGrid2.Cells[1,StringGrid2.RowCount - 1] := '';
primero := false;
end
else
begin
StringGrid2.RowCount := StringGrid2.RowCount + 1;
StringGrid2.Cells[0,StringGrid2.RowCount - 1] := dt.qbusca.FieldByName('codruta').AsString;
StringGrid2.Cells[1,StringGrid2.RowCount - 1] := '';
end;

end
else if dt.qbusca.FieldByName('estado').AsInteger = 1 then
begin
CheckListBox2.Items.Add(dt.qbusca.FieldByName('codruta').AsString);
end
else if dt.qbusca.FieldByName('estado').AsInteger = 2 then
begin
CheckListBox6.Items.Add(dt.qbusca.FieldByName('codruta').AsString);
end
else if dt.qbusca.FieldByName('estado').AsInteger = 3 then
begin
CheckListBox3.Items.Add(dt.qbusca.FieldByName('codruta').AsString);
end
else if dt.qbusca.FieldByName('estado').AsInteger = 4 then
begin
CheckListBox5.Items.Add(dt.qbusca.FieldByName('codruta').AsString);
end
else if dt.qbusca.FieldByName('estado').AsInteger = 5 then
begin
CheckListBox4.Items.Add(dt.qbusca.FieldByName('codruta').AsString);
end
else if dt.qbusca.FieldByName('estado').AsInteger = 6 then
begin
CheckListBox7.Items.Add(dt.qbusca.FieldByName('codruta').AsString);
end
else if dt.qbusca.FieldByName('estado').AsInteger = 7 then
begin
CheckListBox1.Items.Add(dt.qbusca.FieldByName('codruta').AsString);
end;

dt.qbusca.Next;
end;

end;
dt.qbusca.Active := false;
dt.qbusca.SQL.Clear;
dt.qbusca.SQL.Add(' select count(r.codigo) as contador from ruta r left join sincronizadas s on r.codigo = s.codruta ');
dt.qbusca.SQL.Add(' where s.codruta is null and r.tienehh = "s" and r.modem = "n" ');
try
dt.qbusca.Active := true;
except
dt.qbusca.SQL.Clear;
dt.qbusca.SQL.Add(' select count(r.codigo) as contador from ruta r left join sincronizadas s on r.codigo = s.codruta ');
dt.qbusca.SQL.Add(' where s.codruta is null and r.tienehh = "s" ');
dt.qbusca.Active := true;
end;
dt.qbusca.First;
verificador := dt.qbusca.FieldByName('contador').AsInteger;
if verificador > 0 then
begin
// showmessage('13');
dt.qins.Active := false;
dt.qins.SQL.Clear;
dt.qins.SQL.Add(' insert into sincronizadas ');
dt.qins.SQL.Add(' select r.codigo,"0","-","-" from ruta r left join sincronizadas s on r.codigo = s.codruta ');
dt.qins.SQL.Add(' where s.codruta is null and r.tienehh = "s" and r.modem = "n" ');
try
dt.qins.ExecSQL;
except
dt.qins.SQL.Add(' insert into sincronizadas ');
dt.qins.SQL.Add(' select r.codigo,"0","-","-" from ruta r left join sincronizadas s on r.codigo = s.codruta ');
dt.qins.SQL.Add(' where s.codruta is null and r.tienehh = "s" ');
dt.qins.ExecSQL;
end;


ShowMessage('ESTA APLICACION HA DETECTADO RUTAS NUEVAS, SE CERRARA... INGRESE NUEVAMENTE..');
Application.Terminate;
end;
if not Assigned(hilo0) then hilo0 := Thilo_mostrandoestados2.Create(StringGrid2,'0');
if not Assigned(hilo1) then hilo1 := Thilo_mostrandoestados.Create(CheckListBox2,'1');
if not Assigned(hilo2) then hilo2 := Thilo_mostrandoestados.Create(CheckListBox6,'2');
if not Assigned(hilo3) then hilo3 := Thilo_mostrandoestados.Create(CheckListBox3,'3');
if not Assigned(hilo4) then hilo4 := Thilo_mostrandoestados.Create(CheckListBox5,'4');
if not Assigned(hilo5) then hilo5 := Thilo_mostrandoestados.Create(CheckListBox4,'5');
if not Assigned(hilo6) then hilo6 := Thilo_mostrandoestados.Create(CheckListBox7,'6');
if not Assigned(hilo9) then hilo9 := Thilo_mostrandoestados.Create(CheckListBox1,'7');
end;
Responder Con Cita