-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathYOTM.Form.EditTime.pas
207 lines (183 loc) · 5.41 KB
/
YOTM.Form.EditTime.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
unit YOTM.Form.EditTime;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
YOTM.Form.ModalEdit, Vcl.ComCtrls, Vcl.StdCtrls, Vcl.ExtCtrls, HGM.Button,
HGM.Controls.PanelExt, System.Types, Vcl.Grids, HGM.Controls.VirtualTable,
HGM.Popup;
type
TFormEditTime = class(TFormModalEdit)
Label1: TLabel;
ButtonFlat1: TButtonFlat;
ButtonFlatTimeFromHH: TButtonFlat;
ButtonFlat3: TButtonFlat;
ButtonFlat4: TButtonFlat;
ButtonFlatTimeFromMM: TButtonFlat;
ButtonFlat6: TButtonFlat;
ButtonFlat7: TButtonFlat;
ButtonFlatTimeToHH: TButtonFlat;
ButtonFlat9: TButtonFlat;
ButtonFlat10: TButtonFlat;
ButtonFlatTimeToMM: TButtonFlat;
ButtonFlat12: TButtonFlat;
Label2: TLabel;
Label3: TLabel;
ButtonFlatTask: TButtonFlat;
Panel1: TPanel;
EditText: TRichEdit;
PanelTasks: TPanel;
TableExTasks: TTableEx;
ButtonFlatWithoutTask: TButtonFlat;
procedure ButtonFlatUPDOWNClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ButtonFlatTaskClick(Sender: TObject);
procedure TableExTasksGetData(FCol, FRow: Integer; var Value: string);
procedure TableExTasksItemClick(Sender: TObject; MouseButton: TMouseButton; const Index: Integer);
procedure ButtonFlatWithoutTaskClick(Sender: TObject);
private
FFromHH, FFromMM, FToHH, FToMM: Word;
FTaskID: Integer;
FPopup: TFormPopup;
FTaskColor: TColor;
procedure SetTimeFrom(const Value: TTime);
procedure SetTimeTo(const Value: TTime);
procedure UpdateTime;
function GetTimeFrom: TTime;
function GetTimeTo: TTime;
procedure SetTaskID(const Value: Integer);
function GetTaskID: Integer;
procedure SetTaskColor(const Value: TColor);
public
property TimeFrom: TTime read GetTimeFrom write SetTimeFrom;
property TimeTo: TTime read GetTimeTo write SetTimeTo;
property TaskID: Integer read GetTaskID write SetTaskID;
property TaskColor: TColor read FTaskColor write SetTaskColor;
end;
var
FormEditTime: TFormEditTime;
implementation
uses
YOTM.Main, Math;
{$R *.dfm}
procedure TFormEditTime.ButtonFlatTaskClick(Sender: TObject);
var
pt: TPoint;
begin
pt := ButtonFlatTask.ClientToScreen(Point(0, 0));
PanelTasks.Height := Min(Max(3, TableExTasks.ItemCount), 15) * TableExTasks.DefaultRowHeight + ButtonFlatWithoutTask.Height;
FPopup := TFormPopup.CreatePopup(Self, PanelTasks, nil, pt.X, pt.Y + ButtonFlatTask.Height, []);
end;
procedure TFormEditTime.ButtonFlatUPDOWNClick(Sender: TObject);
begin
case (Sender as TButtonFlat).Tag of
10:
FFromHH := Min(Max(0, FFromHH - 1), 23);
11:
FFromHH := Min(Max(0, FFromHH + 1), 23);
20:
FFromMM := Min(Max(0, FFromMM - 1), 59);
21:
FFromMM := Min(Max(0, FFromMM + 1), 59);
30:
FToHH := Min(Max(0, FToHH - 1), 23);
31:
FToHH := Min(Max(0, FToHH + 1), 23);
40:
FToMM := Min(Max(0, FToMM - 1), 59);
41:
FToMM := Min(Max(0, FToMM + 1), 59);
end;
UpdateTime;
end;
procedure TFormEditTime.ButtonFlatWithoutTaskClick(Sender: TObject);
begin
FPopup.Close;
TaskID := -1;
end;
procedure TFormEditTime.FormCreate(Sender: TObject);
begin
inherited;
TaskID := -1;
TableExTasks.ItemCount := FormMain.TaskItems.Count;
end;
function TFormEditTime.GetTaskID: Integer;
begin
if IndexInList(TableExTasks.ItemIndex, FormMain.TaskItems.Count) then
Result := FormMain.TaskItems[TableExTasks.ItemIndex].ID
else
Result := FTaskID;
end;
function TFormEditTime.GetTimeFrom: TTime;
begin
Result := EncodeTime(FFromHH, FFromMM, 0, 0);
end;
function TFormEditTime.GetTimeTo: TTime;
begin
Result := EncodeTime(FToHH, FToMM, 0, 0);
end;
procedure TFormEditTime.SetTaskColor(const Value: TColor);
begin
FTaskColor := Value;
end;
procedure TFormEditTime.SetTaskID(const Value: Integer);
var
i: Integer;
begin
FTaskID := Value;
if FTaskID <> -1 then
begin
for i := 0 to FormMain.TaskItems.Count - 1 do
if FormMain.TaskItems[i].ID = FTaskID then
begin
ButtonFlatTask.Caption := FormMain.TaskItems[i].Name;
FTaskColor := FormMain.TaskItems[i].Color;
TableExTasks.ItemIndex := i;
Exit;
end;
end
else
begin
ButtonFlatTask.Caption := 'Çàäà÷à íå âûáðàíà';
end;
end;
procedure TFormEditTime.SetTimeFrom(const Value: TTime);
var
S, M: Word;
begin
DecodeTime(Value, FFromHH, FFromMM, S, M);
UpdateTime;
end;
procedure TFormEditTime.SetTimeTo(const Value: TTime);
var
S, M: Word;
begin
DecodeTime(Value, FToHH, FToMM, S, M);
UpdateTime;
end;
procedure TFormEditTime.TableExTasksGetData(FCol, FRow: Integer; var Value: string);
begin
if not IndexInList(FRow, FormMain.TaskItems.Count) then
begin
Value := 'Íåò çàäà÷. Èçìåíèòå ôèëüòð';
Exit;
end;
case FCol of
0:
Value := FormMain.TaskItems[FRow].Name;
end;
end;
procedure TFormEditTime.TableExTasksItemClick(Sender: TObject; MouseButton: TMouseButton; const Index: Integer);
begin
FPopup.Close;
if IndexInList(Index, FormMain.TaskItems.Count) then
TaskID := FormMain.TaskItems[Index].ID;
end;
procedure TFormEditTime.UpdateTime;
begin
ButtonFlatTimeFromHH.Caption := FormatDateTime('HH', TimeFrom);
ButtonFlatTimeFromMM.Caption := FormatDateTime('nn', TimeFrom);
ButtonFlatTimeToHH.Caption := FormatDateTime('HH', TimeTo);
ButtonFlatTimeToMM.Caption := FormatDateTime('nn', TimeTo);
end;
end.