-
Notifications
You must be signed in to change notification settings - Fork 11
/
YOTM.Form.SelectLabels.pas
209 lines (188 loc) · 5.48 KB
/
YOTM.Form.SelectLabels.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
205
206
207
208
unit YOTM.Form.SelectLabels;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
YOTM.Form.ModalEdit, Vcl.ExtCtrls, HGM.Button, Vcl.StdCtrls, Vcl.Grids,
HGM.Controls.VirtualTable, YOTM.DB.LabelTypes, YOTM.DB, YOTM.DB.Labels,
HGM.Controls.PanelExt;
type
TFormSelectLabels = class(TFormModalEdit)
TableExLabels: TTableEx;
PanelTaskAdd: TPanel;
EditNewLabel: TEdit;
ButtonFlatNewLabel: TButtonFlat;
ButtonFlatLabelColor: TButtonFlat;
ColorDialog: TColorDialog;
ButtonFlatDelete: TButtonFlat;
procedure FormCreate(Sender: TObject);
procedure TableExLabelsGetData(FCol, FRow: Integer; var Value: string);
procedure ButtonFlatNewLabelClick(Sender: TObject);
procedure ButtonFlatLabelColorClick(Sender: TObject);
procedure TableExLabelsDrawCellData(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
procedure ButtonFlatDeleteClick(Sender: TObject);
procedure TableExLabelsItemColClick(Sender: TObject; MouseButton: TMouseButton; const Index: Integer);
procedure FormDestroy(Sender: TObject);
private
FLabelTypes: TLabelTypes;
public
class function Select(Items: TLabelItems; TaskID: Integer): Boolean;
class procedure OpenForEdit;
end;
var
FormSelectLabels: TFormSelectLabels;
implementation
uses
YOTM.Main, YOTM.Form.Dialog;
{$R *.dfm}
procedure TFormSelectLabels.ButtonFlatDeleteClick(Sender: TObject);
var
i: Integer;
begin
if FLabelTypes.CheckedCount > 0 then
begin
if TFormAnswer.GetAnswer('Óäàëèòü âûáðàííûå ìåòêè?') then
begin
i := 0;
repeat
if FLabelTypes.Checked[i] then
FLabelTypes.Delete(i)
else
Inc(i);
until FLabelTypes.CheckedCount <= 0;
end;
end
else
begin
if not IndexInList(TableExLabels.ItemIndex, FLabelTypes.Count) then
Exit;
if TFormAnswer.GetAnswer('Óäàëèòü âûáðàííóþ ìåòêó?') then
FLabelTypes.Delete(TableExLabels.ItemIndex);
end;
end;
procedure TFormSelectLabels.ButtonFlatLabelColorClick(Sender: TObject);
begin
ColorDialog.Color := ButtonFlatLabelColor.ColorNormal;
if ColorDialog.Execute(Handle) then
ButtonFlatLabelColor.ColorNormal := ColorDialog.Color;
end;
procedure TFormSelectLabels.ButtonFlatNewLabelClick(Sender: TObject);
var
Item: TLabelType;
begin
if EditNewLabel.Text = '' then
Exit;
Item := TLabelType.Create(FLabelTypes);
Item.Name := EditNewLabel.Text;
Item.Color := ButtonFlatLabelColor.ColorNormal;
FLabelTypes.Insert(0, Item);
FLabelTypes.Update(0);
end;
procedure TFormSelectLabels.FormCreate(Sender: TObject);
begin
inherited;
FLabelTypes := TLabelTypes.Create(FDB, TableExLabels);
end;
procedure TFormSelectLabels.FormDestroy(Sender: TObject);
begin
FLabelTypes.Clear;
FLabelTypes.Free;
inherited;
end;
class procedure TFormSelectLabels.OpenForEdit;
begin
with TFormSelectLabels.Create(nil) do
begin
ButtonFlatCancel.Visible := False;
ButtonFlatOK.Left := 0;
FLabelTypes.Reload;
ShowModal;
Free;
end;
end;
class function TFormSelectLabels.Select(Items: TLabelItems; TaskID: Integer): Boolean;
var
i, j: Integer;
Item: TLabelItem;
begin
Result := False;
with TFormSelectLabels.Create(nil) do
begin
FLabelTypes.Reload;
if Assigned(Items) then
begin
for i := 0 to Items.Count - 1 do
for j := 0 to FLabelTypes.Count - 1 do
if Items[i].TypeID = FLabelTypes[j].ID then
begin
FLabelTypes.Checked[j] := True;
Break;
end;
end;
if ShowModal = mrOK then
begin
if Assigned(Items) then
begin
if Items.Count > 0 then
Items.DropAll(TaskID);
for i := 0 to FLabelTypes.Count - 1 do
begin
if FLabelTypes.Checked[i] then
begin
Item := TLabelItem.Create(FLabelTypes[i]);
Item.Task := TaskID;
Items.New(Item);
end;
end;
end;
Result := True;
end;
Free;
end;
end;
procedure TFormSelectLabels.TableExLabelsDrawCellData(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
function CheckImage(Value: Boolean): Integer;
begin
if Value then
Exit(18)
else
Exit(19);
end;
begin
if not IndexInList(ARow, FLabelTypes.Count) then
Exit;
if ACol = 1 then
with TableExLabels.Canvas do
begin
Brush.Color := FLabelTypes[ARow].Color;
Rect.Left := Rect.Left + 3;
Rect.Width := 34;
Rect.Inflate(0, -2);
FillRect(Rect);
end;
if ACol = 0 then
with TableExLabels.Canvas do
begin //18 t 19 f
FormMain.ImageList24.Draw(TableExLabels.Canvas, Rect.Left + (Rect.Width div 2 - FormMain.ImageList24.Width div 2), Rect.Top + (Rect.Height div 2 - FormMain.ImageList24.Height div 2), CheckImage(FLabelTypes.Checked[ARow]));
end;
end;
procedure TFormSelectLabels.TableExLabelsGetData(FCol, FRow: Integer; var Value: string);
begin
if not IndexInList(FRow, FLabelTypes.Count) then
Exit;
Value := '';
case FCol of
2:
Value := FLabelTypes[FRow].Name;
end;
end;
procedure TFormSelectLabels.TableExLabelsItemColClick(Sender: TObject; MouseButton: TMouseButton; const Index: Integer);
begin
if not IndexInList(TableExLabels.ItemIndex, FLabelTypes.Count) then
Exit;
case Index of
0:
FLabelTypes.Checked[TableExLabels.ItemIndex] := not FLabelTypes.Checked[TableExLabels.ItemIndex];
end;
end;
end.