1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
| unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, VirtualTrees, StdCtrls, Oracle;
type
TTask = class
ProjectID : integer;
TaskID : integer;
Name : String;
ParentID : integer;
PreviousID: integer;
NextID : integer;
end;
type
TForm1 = class(TForm)
Edit: TEdit;
Button: TButton;
TaskList: TVirtualStringTree;
OracleSession: TOracleSession;
procedure FormCreate(Sender: TObject);
procedure ButtonClick(Sender: TObject);
procedure TaskListGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType;
var CellText: WideString);
procedure TaskListCompareNodes(Sender: TBaseVirtualTree; Node1,
Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
private
{ Déclarations privées }
public
{ Déclarations publiques }
function FindTask(ParentTask:integer):pVirtualNode;
end;
var
Form1: TForm1;
implementation
uses Math;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
TaskList.NodeDataSize := SizeOf(TTask);
end;
procedure TForm1.ButtonClick(Sender: TObject);
var
NewTask : tTask;
begin
TaskList.Clear;
with TOracleQuery.Create(Self) do
begin
Session:= OracleSession;
Close();
SQL.Clear();
SQL.Add('SELECT * ');
SQL.Add('FROM Taches ');
SQL.Add(' WHERE ProjetID = ' + edit.text + ' ORDER BY TACHEID');
Execute();
First();
While not eof do
begin
NewTask := TTask.Create;
NewTask.ProjectID := StrToInt64(FieldAsString('PROJETID'));
NewTask.TaskID := StrToInt64(FieldAsString('TACHEID'));
NewTask.ParentID := StrToInt64(FieldAsString('PARENTID'));
NewTask.PreviousID:= StrToInt64(FieldAsString('PRECEDENTID'));
NewTask.NextID := StrToInt64(FieldAsString('SUIVANTID'));
Newtask.Name := FieldAsString('NOM');
TaskList.AddChild(FindTask(NewTask.ParentID),NewTask);
Next;
end;
Free;
end;
TaskList.FullExpand(TaskList.GetFirst);
TaskList.Sort(TaskList.GetFirst,1,sdAscending );
end;
function TForm1.FindTask(ParentTask: integer): pVirtualNode;
var
CurrentNode : pVirtualNode;
Data : ^tTask;
begin
Result := nil;
CurrentNode := TaskList.GetFirst;
While CurrentNode <> nil do
begin
Data := TaskList.GetNodeData(currentNode);
if Data.TaskID = ParentTask then
begin
Result := CurrentNode;
exit;
end;
CurrentNode := TaskList.GetNext(CurrentNode);
end;
end;
procedure TForm1.TaskListGetText(Sender: TBaseVirtualTree;
Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
var CellText: WideString);
var
Data : ^Ttask;
begin
Data := Sender.GetNodeData(Node);
case Column of
0: CellText := Data.Name;
1: CellText := IntToStr(Data.TaskID);
end;
end;
procedure TForm1.TaskListCompareNodes(Sender: TBaseVirtualTree; Node1,
Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
var
Data1, Data2 : ^TTask;
begin
Data1 := Sender.GetNodeData(Node1);
Data2 := Sender.GetNodeData(Node2);
Case Column of
1: Result := CompareValue(Data1.PreviousID,Data2.PreviousID);
end;
end;
end. |
Partager