unit uThread2;
interface
uses Classes,Windows, SysUtils, Variants;
type
TUpdateLocation = (ulDatabaseActive, ulDatabaseDeActive, ulTimestamp, ulMemo, ulTable3Active, ulTable3First, ulTable3DeActivate, UploadSchlangeTableDelete, UploadSchlangeTableNext);
TUpdateLocations =
set of TUpdateLocation;
TThread2 =
class(TThread)
private
UpdateString:
string;
UpdateLocations: TUpdateLocations;
procedure MySynchronizeEx;
procedure MySynchronize(astring:
string; AUpdateLocation: TUpdateLocations);
protected
procedure Execute;
override;
end;
implementation
uses uMain, IdFTPCommon;
const
UnixStartDate: TDateTime = 25569.0;
function DateTimeToUnix(ConvDate: TDateTime): Longint;
begin
Result := Round((ConvDate - UnixStartDate) * 86400);
end;
function UnixToDateTime(USec: Longint): TDateTime;
begin
Result := (Usec / 86400) + UnixStartDate;
end;
procedure TThread2.Execute;
var
iStart: Cardinal;
iEnde: Cardinal;
uploadid, port: integer;
server,user,password,qpath,spath:
string;
begin
repeat
iStart := getTickCount;
try
if not MainForm.ABSDatabase1.Connected
then
begin
MySynchronize('
',[ulDatabaseActive]);
end;
if not MainForm.UploadSchlangeTable2.Active
then
begin
MySynchronize('
',[ulTable3Active,ulTable3First]);
end;
while not MainForm.UploadSchlangeTable2.Eof
do
begin
uploadid := MainForm.UploadSchlangeTable2.FieldByName('
iID').AsInteger;
server := MainForm.UploadSchlangeTable2.Lookup('
iID',uploadid,'
sServer');
port := MainForm.UploadSchlangeTable2.Lookup('
iID',uploadid,'
iPort');
user := MainForm.UploadSchlangeTable2.Lookup('
iID',uploadid,'
sUser');
password := MainForm.UploadSchlangeTable2.Lookup('
iID',uploadid,'
sPassword');
spath := MainForm.UploadSchlangeTable2.Lookup('
iID',uploadid,'
sSpath');
qpath := MainForm.UploadSchlangeTable2.Lookup('
iID',uploadid,'
sQPath');
// Beginne Upload-Prozess
MySynchronize('
--------------- starting upload '+inttostr(uploadid)+'
on '+DateToStr (Date) + '
- ' + TimeToStr (Time)+'
-----',[ulMemo]);
MainForm.UploadFTP.Host := server;
MainForm.UploadFTP.Port := port;
MainForm.UploadFTP.Username := user;
MainForm.UploadFTP.Password := password;
MySynchronize('
===== connecting to '+server+'
=====',[ulMemo]);
try
MainForm.UploadFTP.Connect;
MySynchronize('
===== connection established =====',[ulMemo]);
except
MySynchronize('
===== connection failed =====',[ulMemo]);
end;
if MainForm.UploadFTP.Connected
then
begin
MainForm.UploadFTP.ChangeDir(spath);
MySynchronize('
===== uploading =====',[ulMemo]);
try
MainForm.UploadFTP.Put(qpath,ExtractFileName(qpath));
MySynchronize('
===== upload successful =====',[ulMemo]);
except
MySynchronize('
===== upload failed =====',[ulMemo]);
end;
MainForm.UploadFTP.Disconnect;
MySynchronize('
===== connection closed =====',[ulMemo]);
end;
MainForm.UploadSchlangeTable2.Delete;