unit Hauptkalkulation;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls,
DB, ADODB, BetterADODataSet, jpeg, ExtCtrls, StdCtrls,
Mask, DBCtrls, Grids, DBGrids, VirtualTrees;
type
PTreeData = ^TTreeData;
TTreeData =
record
FObject : TObject;
end;
TTreeDataClass =
class
private
FKunde:
string;
FObjektnummer:
string;
FObjektbeschreibung:
string;
published
property Kunde:
string read FKunde
write Fkunde;
property Objektnummer:
string read FObjektnummer
write FObjektnummer;
property Objektbeschreibung:
string read FObjektbeschreibung
write FObjektbeschreibung;
end;
TKalk =
class(TForm)
Label1: TLabel;
Label2: TLabel;
Image1: TImage;
ADO_kunden: TADOConnection;
db_kunden: TBetterADODataSet;
db_kundenNummer: TWideStringField;
db_kundenUIDNummer: TWideStringField;
db_kundenAnrede: TWideStringField;
db_kundenAnrede2: TWideStringField;
db_kundenGrad: TWideStringField;
db_kundenVorname: TWideStringField;
db_kundenNachname: TWideStringField;
db_kundenName: TWideStringField;
db_kundenBranche: TWideStringField;
db_kundenBranche2: TWideStringField;
db_kundenStrasse: TWideStringField;
db_kundenLKZ: TWideStringField;
db_kundenPLZ: TWideStringField;
db_kundenOrt: TWideStringField;
db_kundenTelefon: TWideStringField;
db_kundenTelefon2: TWideStringField;
db_kundenTelefax: TWideStringField;
Kunden: TDataSource;
Seitenwahl: TPageControl;
Objektauswahl: TTabSheet;
Kundendaten: TTabSheet;
ADO_objektkunde: TADOConnection;
ADO_objektarchitekt: TADOConnection;
ADO_objektparameter: TADOConnection;
ADO_Objektbetrag: TADOConnection;
ADO_Objektverlauf: TADOConnection;
db_objektkunde: TBetterADODataSet;
db_objektarchitekt: TBetterADODataSet;
db_objektparameter: TBetterADODataSet;
db_objektbetrag: TBetterADODataSet;
db_objektverlauf: TBetterADODataSet;
Objektkunde: TDataSource;
objektarchitekt: TDataSource;
Objektparameter: TDataSource;
Objektbetrag: TDataSource;
Objektverlauf: TDataSource;
db_objektkundeObjektnummer: TWideStringField;
db_objektkundeKundennummer: TWideStringField;
db_objektkundeObjektbeschreibung: TWideStringField;
db_objektkundeAnrede: TWideStringField;
db_objektkundeKunde: TWideStringField;
db_objektkundeSuchname: TWideStringField;
db_objektkundeBranche: TWideStringField;
db_objektkundeBranche2: TWideStringField;
db_objektkundeStrasse: TWideStringField;
db_objektkundeOrt: TWideStringField;
db_objektkundeTelefonnummer: TWideStringField;
db_objektkundeTelefonnummer2: TWideStringField;
db_objektkundeTelefaxnummer: TWideStringField;
db_objektkundeHandynummer: TWideStringField;
db_objektverlaufObjektnummer: TWideStringField;
db_objektverlaufKundennummer: TWideStringField;
db_objektverlaufArtdesObjektes: TWideStringField;
db_objektverlaufArtdesObjektesNummer: TWideStringField;
db_objektverlaufBezeichnung: TWideStringField;
db_objektverlaufDatum: TDateTimeField;
db_objektverlaufDateiablage: TWideStringField;
db_objektkundeNummerbeschreibung: TWideStringField;
db_kundenSuchname: TWideStringField;
vst: TVirtualStringTree;
function AddVSTObject(avst: TCustomVirtualStringTree; aNode: PVirtualNode;
aObject: TObject): PVirtualNode;
procedure vstFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure vstCompareNodes(Sender: TBaseVirtualTree; Node1,
Node2: PVirtualNode; Column: TColumnIndex;
var Result: Integer);
procedure vstHeaderClick(Sender: TVTHeader; Column: TColumnIndex;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure vstGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType;
var CellText: WideString);
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Kalk: TKalk;
implementation
{$R *.dfm}
function Tkalk.AddVSTObject(avst: TCustomVirtualStringTree; aNode: PVirtualNode;
aObject: TObject): PVirtualNode;
var
Data: PTreeData;
begin
Result := avst.Addchild(aNode);
data := avst.GetNodeData(Result);
avst.ValidateNode(Result, False);
data^.FObject := aObject;
end;
procedure Tkalk.vstFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
var
Data: PTreeData;
begin
Data := vst.GetNodeData(Node);
if not Assigned(Data)
then
exit;
Data.FObject.Free;
end;
procedure TKalk.vstCompareNodes(Sender: TBaseVirtualTree; Node1,
Node2: PVirtualNode; Column: TColumnIndex;
var Result: Integer);
var
Data1, Data2: PTreeData;
begin
Data1 := Sender.GetNodeData(Node1);
Data2 := Sender.GetNodeData(Node2);
case Column
of
0:
Result := CompareText(TtreeDataClass(Data1.FObject).FKunde,
TtreeDataClass(Data2.FObject).FKunde);
1:
Result := CompareText(TTreeDataClass(Data1.FObject).FObjektnummer,
TtreeDataClass(Data2.FObject).FObjektnummer);
2:
Result := CompareText(TTreeDataClass(Data1.FObject).FObjektbeschreibung,
TtreeDataClass(Data2.FObject).FObjektbeschreibung);
end;
end;
procedure TKalk.vstHeaderClick(Sender: TVTHeader; Column: TColumnIndex;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft
then
begin
with Sender, TreeView
do
begin
if SortColumn > NoColumn
then
Columns[SortColumn].Options := Columns[SortColumn].Options + [coParentColor];
if Column = 0
then
SortColumn := NoColumn
else
begin
if (SortColumn = NoColumn)
or (SortColumn <> Column)
then
begin
SortColumn := Column;
SortDirection := sdAscending;
end
else
if SortDirection = sdAscending
then
SortDirection := sdDescending
else
SortDirection := sdAscending;
Columns[SortColumn].Color := $F7F7F7;
SortTree(SortColumn, SortDirection, False);
end;
end;
end;
end;
procedure TKalk.vstGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType;
var CellText: WideString);
var
Data: PTreeData;
begin
Data := Sender.GetNodeData(Node);
if data.FObject <>
nil then
begin
case Column
of
0:
begin
if Node.Parent = Sender.RootNode
then
celltext := TTreeDataClass(Data.FObject).FKunde
else
celltext := TTreeDataClass(Data.FObject).FKunde
end;
1:
if Node.Parent = Sender.RootNode
then
celltext := '
'
else
celltext := TTreeDataClass(Data.FObject).FObjektnummer;
2:
if Node.Parent = Sender.RootNode
then
celltext := '
'
else
celltext := TTreeDataClass(Data.FObject).FObjektbeschreibung;
end;
end;
end;
procedure TKalk.FormCreate(Sender: TObject);
var
TreeObject: TTreeDataClass;
Wurzel: PVirtualNode;
begin
vst.BeginUpdate;
vst.NodeDataSize := SizeOf(TTreeData);
vst.DeleteChildren(vst.RootNode, true);
TreeObject := TTreeDataClass.Create;
while not db_kunden.Eof
do
begin
TreeObject.Kunde := db_kunden.fieldByName('
Name').AsString;
Wurzel := AddVSTObject(VST,
Nil, TreeObject);
while not db_objektkunde.eof
do
begin
TreeObject.Objektnummer := db_objektkunde.fieldbyName('
Objektnummer').AsString;
TreeObject.Objektbeschreibung := db_objektkunde.fieldbyName('
Objektbeschreibung').AsString;
addvstObject(vst, Wurzel, TreeObject);
db_objektkunde.next;
end;
db_kunden.next;
end;
end;
end.