TDatabase =
class(TObject)
private
FWQuery : TZQuery;
FDQuery : TZQuery;
FCQuery : TZQuery;
FMQuery : TZQuery;
FSqlConnection : TZConnection;
public
constructor Create();
function DBSearch(Criteria: Model.TAttributes)
: TObjectList;
virtual;
abstract;
procedure DBCreate();
virtual;
abstract;
procedure DBEdit();
virtual;
abstract;
procedure DBDelete();
virtual;
abstract;
end;
TDockingstationSearch =
class(TDatabase)
private
public
function DBSearch(Modus:
String; Criteria: Model.TDockingstationAttributes)
: TObjectList;
Overload;
end;
TComputerSearch =
class(TDatabase)
private
public
function DBSearch(Modus:
String; Criteria: Model.TComputerAttributes)
: TObjectList;
Overload;
end;
implementation
constructor TDatabase.Create();
begin
FSqlConnection := TZConnection.Create(FSqlConnection);
FSqlConnection.HostName := '
';
//Server
FSqlConnection.User := '
';
//Benutzername
FSqlConnection.Password := '
';
//Passwort
FSqlConnection.Database := '
';
//Name der Datenbank
FSqlConnection.Protocol := '
mysql-4.1';
FSqlConnection.Port := 3306;
FDQuery := TZQuery.Create(FDQuery);
FDQuery.Connection := FSqlConnection;
FCQuery := TZQuery.Create(FCQuery);
FCQuery.Connection := FSqlConnection;
end;
function TDockingstationSearch.DBSearch(Modus:
String;
Criteria: Model.TDockingstationAttributes): TObjectList;
var
FDSList: TObjectList;
I: Integer;
FEqual1,FEqual2 :
String;
FMyDockingstation: Model.TDockingstation;
begin
FDSList := TObjectList.Create;
FMyDockingstation := Model.TDockingstation.Create;
//...
// Search in the database for dockingstations by using the criteria
FDQuery.Close;
FDQuery.SQL.Text := '
SELECT * FROM Dockingstation';
FDQuery.SQL.Add('
WHERE (1=1');
//...
FDQuery.SQL.Add('
)');
FDQuery.Open;
while not FDQuery.EOF
do
begin
// Use search result to create a new dockingstation object
FMyDockingstation.SetAttributes('
','
',
FDQuery.FieldByName('
DockingstationID').AsInteger,'
',
);
// Add dockingstation to a list of dockingstation ojects
FDSList.Add(FMyDockingstation);
FDQuery.Next;
end;
FDQuery.Free;
Result := FDSList;
end;
function TComputerSearch.DBSearch(Modus:
String;
Criteria: Model.TComputerAttributes): TObjectList;
var
//..
begin
//..
FCList := TObjectList.Create;
//..
// Search in the database for computers by using the criteria
FCQuery.Close;
FCQuery.SQL.Text := '
SELECT';
FCQuery.SQL.Add('
....');
//...
FCQuery.Open;
while not FCQuery.EOF
do
begin
FMyComputer := Model.TComputer.Create;
// Use search result to create a new computer object
FMyID := FCQuery.FieldByName('
RechnerID').AsInteger;
FMyComment := FCQuery.FieldByName('
Bemerkungen').AsString;
FMyGraphicCard := FCQuery.FieldByName('
Grafikkarte').AsString;
//...
// HIER KOENNTE DER FEHLER LIEGEN WEIL ICH HIER WIEDER EINE DOCKINGSTATIONSEARCH ERZEUGE UND DAS GANZE IN DER GROSSEN WHILE SCHLEIFE VOM FCSQLQUERY ---------------------
if (FCQuery.FieldByName('
DockingstationID').AsInteger > 0)
then
begin
FMyDSearch := TDockingstationSearch.Create;
FMyDCriteria := TDockingstationAttributes.Create;
// Search for the dockingstation that is used by the computer
FMyDCriteria.SetID(
FCQuery.FieldByName('
DockingstationID').AsInteger);
FDList := FMyDSearch.DBSearch('
vague',FMyDCriteria);
// Create the dockingstation object for the computer object
FMyDockingstation := FDList[0]
as Model.TDockingstation;
end;
//---------------------
// Set all the information of the computer object
FMyComputer.SetAttributes(...,FMyComment,...,FMyGraphicCard,.., FMyDockingstation...);
// Add computer object to a list of computer ojects
FCList.Add(FMyComputer);
FCQuery.Next;
end;
FCQuery.Free;
Result := FCList;
end;