unit uSQLThread.SQLGetUser;
interface
uses System.Classes, System.SysUtils, System.Types, uUser, uCallings,
ZAbstractConnection, ZConnection, ZAbstractRODataset, ZDataset, Data.DB, uDBSettings;
type
TOnThreadFinished=procedure(Sender: TObject)
of object;
TOnUpdateUserList=procedure(Sender: TObject; UserList: TUserList)
of object;
TSQLGetUser=class(TThread)
private
FViewRange: TViewRange;
FStartdate, FEnddate: TDateTime;
FDBSettings: TDBSettings;
FOnThreadFinished: TOnThreadFinished;
FOnUpdateUserList: TOnUpdateUserList;
procedure DoThreadFinished;
procedure DoUpdateUserList(UserList: TUserList);
published
property OnThreadFhinished: TOnThreadFinished
read FOnThreadFinished
write FOnThreadFinished;
property OnUpdateUserList: TOnUpdateUserList
read FOnUpdateUserList
write FOnUpdateUserList;
public
constructor Create(Suspended: Boolean; DBSettings: TDBSettings; ViewRange: TViewRange; Startdate, Enddate: TDateTime);
protected
procedure Execute;
override;
end;
const
DebuggingName = '
SQLGetUser';
implementation
{ TSQLTemplate }
constructor TSQLGetUser.Create(Suspended: Boolean; DBSettings: TDBSettings; ViewRange: TViewRange; Startdate, Enddate: TDateTime);
begin
inherited Create(Suspended);
FDBSettings:=TDBSettings.Create;
DBSettings.AssignTo(FDBSettings);
self.FViewRange:=ViewRange;
self.FStartdate:=Startdate;
self.FEnddate:=Enddate;
end;
procedure TSQLGetUser.DoThreadFinished;
begin
if Assigned(FOnThreadFinished)
then
Synchronize(
procedure
begin
FOnThreadFinished(Self);
end);
end;
procedure TSQLGetUser.DoUpdateUserList(UserList: TUserList);
begin
if Assigned(FOnUpdateUserList)
then
Synchronize(
procedure
begin
FOnUpdateUserList(Self, UserList);
end);
end;
procedure TSQLGetUser.Execute;
var
FConnection: TZConnection;
FUserList: TUserList;
begin
self.NameThreadForDebugging(DebuggingName);
Self.FreeOnTerminate:=True;
FConnection:=TZConnection.Create(
nil);
FUserList:=TUSerList.Create(True);
try
FConnection.HostName:=FDBSettings.Hostname;
FConnection.Port:=FDBSettings.Port;
FConnection.User:=FDBSettings.UserName;
FConnection.Password:=FDBSettings.Password;
FConnection.Protocol:=FDBSettings.Provider;
FConnection.Database:=FDBSettings.Databasename;
FConnection.LoginPrompt:=False;
FConnection.Connect;
if not Self.Terminated
then
begin
FUserList.LoadFromDB(FConnection, FViewRange, FStartdate, FEnddate);
DoUpdateUserList(FUserList);
end;
finally
FUserList.Free;
FConnection.Free;
FDBSettings.Free;
DoThreadFinished;
end;
end;
end.