unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls,
DB, ZSqlMetadata, ZAbstractTable, ZDataset,
ZAbstractRODataset, ZAbstractDataset, DBCtrls, ZConnection, Unit3, Inifiles, jpeg;
type
TForm1 =
class(TForm)
GroupBox1: TGroupBox;
GroupBox3: TGroupBox;
test: TListView;
edVorname: TEdit;
edName: TEdit;
edAdresse: TEdit;
edPLZ: TEdit;
edWohnort: TEdit;
edID: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Button1: TButton;
Button2: TButton;
GroupBox2: TGroupBox;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
edServer: TEdit;
edLogin: TEdit;
edPasswort: TEdit;
edDB: TEdit;
Button3: TButton;
qrMain: TZQuery;
trMain: TZSQLMetadata;
dsMain: TDataSource;
dbmain: TZConnection;
Button5: TButton;
Button6: TButton;
Button4: TButton;
Button8: TButton;
Button9: TButton;
Button10: TButton;
Button11: TButton;
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure testSelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
procedure BilderClick(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button11Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
uses Unit4;
{$R *.dfm}
procedure TForm1.Button3Click(Sender: TObject);
begin
dbMain.Hostname:=edServer.Text;
dbMain.User:=edLogin.Text;
dbMain.Password:=edPasswort.Text;
dbMain.Database:=edDB.Text;
dbMain.Connected:=True;
try
qrMain.SQL.Text:='
CREATE TABLE `adressbuch` ('+
'
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,'+
'
`vorname` TEXT NOT NULL,'+
'
`name` TEXT NOT NULL,'+
'
`adresse` TEXT NOT NULL,'+
'
`wohnort` TEXT NOT NULL,'+
'
`plz` INT NOT NULL'+
'
);';
qrMain.ExecSql;
finally
dbMain.Connected:=False;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
dbMain.Hostname:=edServer.Text;
dbMain.User:=edLogin.Text;
dbMain.Password:=edPasswort.Text;
dbMain.Database:=edDB.Text;
dbMain.Connected:=True;
dbMain.Connected:=True;
//Verbindung herstellen
try
qrMain.SQL.Text:='
INSERT INTO `adressbuch` '+
'
(`id`, `vorname`, `name`, `adresse`, `wohnort`, `plz`)'+
'
VALUES '+
'
(''
''
, ''
'+edVorname.Text+'
''
, ''
'+edName.Text+
'
''
, ''
'+edAdresse.Text+'
''
, ''
'+edWohnort.Text+
'
''
, ''
'+edPLZ.Text+'
''
);';
qrMain.ExecSql;
//SQL-Statement ausführen
finally
dbMain.Connected:=False;
//Verbindung trennen
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
dbMain.Hostname:=edServer.Text;
dbMain.User:=edLogin.Text;
dbMain.Password:=edPasswort.Text;
dbMain.Database:=edDB.Text;
dbMain.Connected:=True;
try
qrMain.SQL.Text:='
DELETE FROM adressbuch WHERE id=''
'+edID.Text+'
''
;';
qrMain.ExecSql;
finally
dbMain.Connected:=False;
end;
end;
procedure TForm1.Button6Click(Sender: TObject);
var ListItem: TListItem;
begin
dbMain.Hostname:=edServer.Text;
dbMain.User:=edLogin.Text;
dbMain.Password:=edPasswort.Text;
dbMain.Database:=edDB.Text;
dbMain.Connected:=True;
try
test.Items.Clear;
qrMain.SQL.Text:='
Select * from `adressbuch` order by name;';
qrMain.Open;
while not qrMain.Eof
do
begin
ListItem := test.Items.Add;
ListItem.Caption:=qrMain.FieldByName('
id').AsString;
ListItem.SubItems.Add(qrMain.FieldByName('
vorname').AsString);
ListItem.SubItems.Add(qrMain.FieldByName('
name').AsString);
ListItem.SubItems.Add(qrMain.FieldByName('
adresse').AsString);
ListItem.SubItems.Add(qrMain.FieldByName('
plz').AsString);
ListItem.SubItems.Add(qrMain.FieldByName('
wohnort').AsString);
qrMain.Next;
end;
finally
dbMain.Connected:=False;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
dbMain.Hostname:=edServer.Text;
dbMain.User:=edLogin.Text;
dbMain.Password:=edPasswort.Text;
dbMain.Database:=edDB.Text;
dbMain.Connected:=True;
try
qrMain.SQL.Text:='
UPDATE `adressbuch` Set `vorname`=''
'+edVorname.Text+'
''
,'+
'
`name`=''
'+edName.Text+'
''
,'+
'
`adresse`=''
'+edAdresse.Text+'
''
,'+
'
`plz`=''
'+edPLZ.Text+'
''
,'+
'
`wohnort`=''
'+edWohnort.Text+'
''
'+
'
WHERE `id`=''
'+edID.Text+'
''
;';
qrMain.ExecSql;
//SQL-Statement ausführen
finally
dbMain.Connected:=False;
end;
end;
procedure TForm1.testSelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
begin
edID.Text := Item.Caption;
edVorname.Text := Item.SubItems[0];
edName.Text := Item.SubItems[1];
edAdresse.Text := Item.SubItems[2];
edPLZ.Text := Item.SubItems[3];
edWohnort.Text := Item.SubItems[4];
end;
procedure TForm1.BilderClick(Sender: TObject);
//var copyedit1: TStrings;
var IniFile: TIniFile;
begin
try
IniFile:=TInifile.Create(ExtractFilePath(ParamStr(0))+'
login.ini');
IniFile.WriteString('
Host','
Host', edServer.Text);
IniFile.WriteString('
User','
Login', edLogin.Text);
IniFile.WriteString('
Pass','
Passwort', edPasswort.Text);
IniFile.WriteString('
Database','
Datenbank', edDB.Text);
finally
IniFile.Free;
end;
//copyedit1:=TStringlist.Create;
//copyedit1.Add(edserver.Text);
//copyedit1.Add(edLogin.Text);
//copyedit1.Add(edPasswort.Text);
//copyedit1.Add(edDB.Text);
//copyedit1.SaveToFile('logindaten.ini');
//copyedit1.Free;
end;
procedure TForm1.Button8Click(Sender: TObject);
begin
Form1.Close;
end;
procedure TForm1.Button9Click(Sender: TObject);
begin
Form3.Show;
end;
procedure TForm1.Button10Click(Sender: TObject);
var IniFile: TIniFile;
begin
try
IniFile:=TInifile.Create(ExtractFilePath(ParamStr(0))+'
login.ini');
edServer.Text:=IniFile.ReadString('
Host','
Host', '
');
edLogin.Text:=IniFile.ReadString('
User','
Login', '
');
edPasswort.Text:=IniFile.ReadString('
Pass','
Passwort', '
');
edDB.Text:=IniFile.ReadString('
Database','
Datenbank', '
');
finally
IniFile.Free;
end;
end;
procedure TForm1.Button11Click(Sender: TObject);
begin
Form4.show;
end;
end.