unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons,
DB, StdCtrls, Mask, DBCtrls, DBTables, ExtCtrls, Grids,
DBGrids;
type
TMietverwaltung =
class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Table1: TTable;
Table2: TTable;
Table1Whg: TAutoIncField;
Table1Name: TStringField;
Table1Vorname: TStringField;
Table1Mietbegin: TDateField;
Table1Bemerkung: TStringField;
Table1Telefon: TIntegerField;
Table1Bruttomiete: TCurrencyField;
Table1Nettomiete: TCurrencyField;
Table1Nebenkosten: TCurrencyField;
Table1Kaltwasser: TCurrencyField;
Table1Warmwasser: TCurrencyField;
Table1Mll: TCurrencyField;
Table1Fernwrme: TCurrencyField;
Table1Antenne: TCurrencyField;
Table1HMservice: TCurrencyField;
Label1: TLabel;
E_whg: TDBEdit;
DataSource1: TDataSource;
Label2: TLabel;
E_name: TDBEdit;
Label3: TLabel;
E_vorname: TDBEdit;
Label4: TLabel;
E_mietbeg: TDBEdit;
Label5: TLabel;
E_Bemerk: TDBEdit;
Label6: TLabel;
E_tel: TDBEdit;
Label7: TLabel;
E_brutto: TDBEdit;
Label8: TLabel;
E_netto: TDBEdit;
Label9: TLabel;
E_neben: TDBEdit;
Sp_schlies: TSpeedButton;
Sp_off: TSpeedButton;
DBGrid1: TDBGrid;
first: TBitBtn;
prior: TBitBtn;
next: TBitBtn;
last: TBitBtn;
store: TButton;
delete: TButton;
new: TButton;
cancel: TButton;
Table2Id: TIntegerField;
Table2Datum: TDateField;
Table2Bruttomiete: TCurrencyField;
Table2Bezahlt: TStringField;
DataSource2: TDataSource;
Button1: TButton;
Button2: TButton;
DBNavigator1: TDBNavigator;
Button3: TButton;
procedure Sp_offClick(Sender: TObject);
procedure Sp_schliesClick(Sender: TObject);
procedure firstClick(Sender: TObject);
procedure priorClick(Sender: TObject);
procedure nextClick(Sender: TObject);
procedure lastClick(Sender: TObject);
procedure storeClick(Sender: TObject);
procedure deleteClick(Sender: TObject);
procedure newClick(Sender: TObject);
procedure cancelClick(Sender: TObject);
procedure DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
procedure FormShow(Sender: TObject);
procedure E_nameChange(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
procedure setbuttons(m: Byte);
public
{ Public-Deklarationen }
end;
var
Mietverwaltung: TMietverwaltung;
pos: TBookmark;
implementation
uses Unit2;
{$R *.dfm}
procedure TMietverwaltung.Sp_offClick(Sender: TObject);
begin
sp_schlies.Visible:=true;
sp_off.Visible:=false;
form2.Show;
end;
procedure TMietverwaltung.Sp_schliesClick(Sender: TObject);
begin
sp_schlies.Visible:=false;
sp_off.Visible:=true;
form2.close;
end;
procedure TMietverwaltung.setbuttons(m: Byte);
begin
case m
of
0:
begin
new.Enabled:=false;
store.Enabled:=false;
delete.Enabled:=false;
cancel.Enabled:=false;
end;
1:
begin
new.Enabled:=true;
store.Enabled:=false;
delete.Enabled:=true;
cancel.Enabled:=false;
end;
2:
begin
new.Enabled:=false;
store.Enabled:=true;
delete.Enabled:=false;
cancel.Enabled:=true
end
end
end;
procedure TMietverwaltung.firstClick(Sender: TObject);
begin
Table1.first;
first.Enabled:=false;
prior.Enabled:=false;
next.Enabled:=true;
last.Enabled:=true;
table2.Filtered:=false;
table2.Filter:='
id = '+Table1.Fields[0].AsString;
table2.Filtered:=true;
end;
procedure TMietverwaltung.priorClick(Sender: TObject);
begin
Table1.prior;
next.Enabled:=true;
last.Enabled:=true;
if table1.Bof
then firstclick(self);
table2.Filtered:=false;
table2.Filter:='
id = '+Table1.Fields[0].AsString;
table2.Filtered:=true;
end;
procedure TMietverwaltung.nextClick(Sender: TObject);
begin
Table1.next;
prior.Enabled:=true;
first.Enabled:=true;
if table1.Bof
then lastclick(self);
table2.Filtered:=false;
table2.Filter:='
id = '+Table1.Fields[0].AsString;
table2.Filtered:=true;
end;
procedure TMietverwaltung.lastClick(Sender: TObject);
begin
Table1.last;
first.Enabled:=True;
prior.Enabled:=True;
next.Enabled:=false;
last.Enabled:=false;
table2.Filtered:=false;
table2.Filter:='
id = '+Table1.Fields[0].AsString;
table2.Filtered:=true;
end;
procedure TMietverwaltung.storeClick(Sender: TObject);
begin
if Table1.State=dsEdit
then Table1.Post;
setbuttons(1);
table1.Refresh
end;
procedure TMietverwaltung.deleteClick(Sender: TObject);
begin
if messagedlg('
Wollen sie den mieter wirklich löschen??',
mtwarning,[mbyes, mbno], 0) = mryes
then
begin
Table1.Delete;
Table1.Edit
end
end;
procedure TMietverwaltung.newClick(Sender: TObject);
begin
table1.Edit;
table1['
Mietbegin']:=formatdatetime('
dd.mm.yyyy', now);
table1.post;
setbuttons(2);
table2.Filtered:=false;
table2.Filter:='
id = '+Table1.Fields[0].AsString;
table2.Filtered:=true;
end;
procedure TMietverwaltung.cancelClick(Sender: TObject);
begin
if Table1.State=dsEdit
then Table1.Cancel;
setbuttons(1);
table1.Refresh
end;
procedure TMietverwaltung.DBNavigator1Click(Sender: TObject;
Button: TNavigateBtn);
begin
table2.Edit;
table2['
id']:=table1['
Whg'];
table2.Post;
end;
procedure TMietverwaltung.FormShow(Sender: TObject);
var i:integer;
begin
setbuttons(1);
end;
procedure TMietverwaltung.E_nameChange(Sender: TObject);
begin
setbuttons(2)
end;
procedure TMietverwaltung.Button3Click(Sender: TObject);
var i:integer;
begin
for i:=1
to 100
do
with Table1
do begin
Append;
FieldByName('
Whg').AsInteger := i;
Post;
end;
end;
end.