-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathYOTM.DB.Comments.pas
205 lines (181 loc) · 4.41 KB
/
YOTM.DB.Comments.pas
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
unit YOTM.DB.Comments;
interface
uses
HGM.SQLang, HGM.SQLite, System.Generics.Collections, HGM.Controls.VirtualTable,
YOTM.DB;
type
//Êîììåíòàðèè ê çàäà÷å
TCommentItem = class;
TCommentItems = class;
TCommentItem = class(TObject)
private
FOwner: TCommentItems;
FID: Integer;
FTask: Integer;
FText: string;
FDate: TDate;
procedure SetOwner(const Value: TCommentItems);
procedure SetText(const Value: string);
procedure SetID(const Value: Integer);
procedure SetDate(const Value: TDate);
procedure SetTask(const Value: Integer);
public
constructor Create(AOwner: TCommentItems);
property Owner: TCommentItems read FOwner write SetOwner;
property Text: string read FText write SetText;
property Date: TDate read FDate write SetDate;
property ID: Integer read FID write SetID;
property Task: Integer read FTask write SetTask;
end;
TCommentItems = class(TTableData<TCommentItem>)
const
tnTable = 'CommentItems';
fnID = 'cmID';
fnTask = 'cmTask';
fnText = 'cmText';
fnDate = 'cmDate';
private
FDataBase: TDB;
procedure SetDataBase(const Value: TDB);
public
constructor Create(ADataBase: TDB; ATableEx: TTableEx);
procedure Reload(TaskID: Integer);
procedure Update(Index: Integer);
procedure Delete(Index: Integer); override;
procedure Save;
procedure Clear; override;
property DataBase: TDB read FDataBase write SetDataBase;
end;
implementation
{ TTimeItem }
constructor TCommentItem.Create(AOwner: TCommentItems);
begin
inherited Create;
FID := -1;
FTask := -1;
Owner := AOwner;
end;
procedure TCommentItem.SetDate(const Value: TDate);
begin
FDate := Value;
end;
procedure TCommentItem.SetText(const Value: string);
begin
FText := Value;
end;
procedure TCommentItem.SetID(const Value: Integer);
begin
FID := Value;
end;
procedure TCommentItem.SetOwner(const Value: TCommentItems);
begin
FOwner := Value;
end;
procedure TCommentItem.SetTask(const Value: Integer);
begin
FTask := Value;
end;
{ TTimeItems }
procedure TCommentItems.Clear;
var
i: Integer;
begin
for i := 0 to Count - 1 do
Items[i].Free;
inherited;
end;
constructor TCommentItems.Create(ADataBase: TDB; ATableEx: TTableEx);
begin
inherited Create(ATableEx);
FDataBase := ADataBase;
if not FDataBase.DB.TableExists(tnTable) then
with SQL.CreateTable(tnTable) do
begin
AddField(fnID, ftInteger, True, True);
AddField(fnTask, ftInteger);
AddField(fnText, ftString);
AddField(fnDate, ftDateTime);
FDataBase.DB.ExecSQL(GetSQL);
EndCreate;
end;
end;
procedure TCommentItems.Delete(Index: Integer);
begin
with SQL.Delete(tnTable) do
begin
WhereFieldEqual(fnID, Items[Index].ID);
DataBase.DB.ExecSQL(GetSQL);
EndCreate;
end;
Items[Index].Free;
inherited;
end;
procedure TCommentItems.Reload;
var
Table: TSQLiteTable;
Item: TCommentItem;
begin
BeginUpdate;
Clear;
try
with SQL.Select(tnTable) do
begin
AddField(fnID);
AddField(fnTask);
AddField(fnText);
AddField(fnDate);
WhereFieldEqual(fnTask, TaskID);
Table := FDataBase.DB.GetTable(GetSQL);
EndCreate;
Table.MoveFirst;
while not Table.EOF do
begin
Item := TCommentItem.Create(Self);
Item.ID := Table.FieldAsInteger(0);
Item.Task := Table.FieldAsInteger(1);
Item.Text := Table.FieldAsString(2);
Item.Date := Table.FieldAsDateTime(3);
Add(Item);
Table.Next;
end;
Table.Free;
end;
finally
EndUpdate;
end;
end;
procedure TCommentItems.Update(Index: Integer);
begin
if Items[Index].ID < 0 then
with SQL.InsertInto(tnTable) do
begin
AddValue(fnTask, Items[Index].Task);
AddValue(fnText, Items[Index].Text);
AddValue(fnDate, Items[Index].Date);
DataBase.DB.ExecSQL(GetSQL);
Items[Index].ID := DataBase.DB.LastInsertRowID;
EndCreate;
end
else
with SQL.Update(tnTable) do
begin
AddValue(fnTask, Items[Index].Task);
AddValue(fnText, Items[Index].Text);
AddValue(fnDate, Items[Index].Date);
WhereFieldEqual(fnID, Items[Index].ID);
DataBase.DB.ExecSQL(GetSQL);
EndCreate;
end;
end;
procedure TCommentItems.Save;
var
i: Integer;
begin
for i := 0 to Count - 1 do
Update(i);
end;
procedure TCommentItems.SetDataBase(const Value: TDB);
begin
FDataBase := Value;
end;
end.