Subversion Repositories ExamClock

Rev

Rev 9 | Rev 12 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9 ron.wellst 1
unit mainunit;
2
 
3
{$mode objfpc}{$H+}
4
 
5
interface
6
 
7
uses
8
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
9
  LCLType, StdCtrls, ExtCtrls, ComCtrls, EditBtn, Buttons, unit1, unit2;
10
 
11
type
12
 
13
  { TMainForm }
14
 
15
  TMainForm = class(TForm)
16
    StartButton: TBitBtn;
17
    CurrentTimeLabel: TLabel;
18
    AdvancedLabel: TLabel;
19
    AdvancedTimeLabel: TLabel;
20
    Label1: TLabel;
21
    FoundationLabel: TLabel;
22
    FoundationTimeLabel: TLabel;
23
    IntermediateLabel: TLabel;
24
    IntermediateTimeLabel: TLabel;
25
    MainMenu: TMainMenu;
26
    FileMenu: TMenuItem;
27
    FileExit: TMenuItem;
28
    HelpMenu: TMenuItem;
29
    HelpAbout: TMenuItem;
30
    CurrentTimePanel: TPanel;
31
    FoundationPanel: TPanel;
32
    IntermediatePanel: TPanel;
33
    AdvancedPanel: TPanel;
34
    FileExams: TMenuItem;
35
    FileSeperator1: TMenuItem;
36
    StatusBar: TStatusBar;
37
    Timer1: TTimer;
38
    procedure FileExamsClick(Sender: TObject);
39
    procedure FileExitClick(Sender: TObject);
40
    procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
41
    procedure FormCreate(Sender: TObject);
42
    procedure FormResize(Sender: TObject);
43
    procedure FormShow(Sender: TObject);
44
    procedure HelpAboutClick(Sender: TObject);
45
    procedure StartButtonClick(Sender: TObject);
46
    procedure Timer1Timer(Sender: TObject);
47
  private
48
    { private declarations }
49
    ClockRunning: Boolean;
50
    FoundationDuration, FoundationHalfTime: TDateTime;
51
    IntermediateDuration, IntermediateHalfTime: TDateTime;
52
    AdvancedDuration, AdvancedHalfTime: TDateTime;
53
    Sec, TenMins, ZeroHour: TDateTime;
54
    FoundationCaption, IntermediateCaption, AdvancedCaption: String;
55
  public
56
    { public declarations }
57
  end;
58
 
59
var
60
  MainForm: TMainForm;
61
 
62
implementation
63
 
64
{$R *.lfm}
65
 
66
{ TMainForm }
67
 
68
procedure TMainForm.FileExitClick(Sender: TObject);
69
begin
70
  Close;
71
end;
72
 
73
procedure TMainForm.FileExamsClick(Sender: TObject);
74
begin
75
  if Form2.ShowModal = ID_OK then
76
  begin
77
    FoundationPanel.Enabled := Form2.FoundationCheckBox.Checked;
78
    FoundationLabel.Visible := Form2.FoundationCheckBox.Checked;
79
    FoundationTimeLabel.Visible := Form2.FoundationCheckBox.Checked;
80
    IntermediatePanel.Enabled := Form2.IntermediateCheckBox.Checked;
81
    IntermediateLabel.Visible := Form2.IntermediateCheckBox.Checked;
82
    IntermediateTimeLabel.Visible := Form2.IntermediateCheckBox.Checked;
83
    AdvancedPanel.Enabled := Form2.AdvancedCheckBox.Checked;
84
    AdvancedLabel.Visible := Form2.AdvancedCheckBox.Checked;
85
    AdvancedTimeLabel.Visible := Form2.AdvancedCheckBox.Checked;
86
  end;
87
end;
88
 
89
procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: boolean);
90
begin
91
  CanClose := Application.MessageBox('Confirm application exit?',
92
           'Confirm Exit', MB_ICONQUESTION+MB_YESNO) = IDYES;
93
end;
94
 
95
procedure TMainForm.FormCreate(Sender: TObject);
96
begin
97
  // Initalise variables
98
  ClockRunning := False;
10 ron.wellst 99
  { Values for testing }
100
{  FoundationDuration := StrToTime('00:01:00');
101
  FoundationHalfTime := StrToTime('00:00:30');
102
  IntermediateDuration := StrToTime('00:02:00');
103
  IntermediateHalfTime := StrToTime('00:01:00');
104
  AdvancedDuration := StrToTime('00:03:00');
105
  AdvancedHalfTime := StrToTime('00:01:30');
106
  TenMins := StrToTime('00:00:10');}
107
  { Live values }
9 ron.wellst 108
  FoundationDuration := StrToTime('00:55:00');
10 ron.wellst 109
  FoundationHalfTime := StrToTime('00:30:00');
9 ron.wellst 110
  IntermediateDuration := StrToTime('01:25:00');
111
  IntermediateHalfTime := StrToTime('00:42:30');
112
  AdvancedDuration := StrToTime('02:00:00');
113
  AdvancedHalfTime := StrToTime('01:00:00');
10 ron.wellst 114
  TenMins := StrToTime('00:10:00');
9 ron.wellst 115
  Sec := StrToTime('00:00:01');
116
  ZeroHour := StrToTime('00:00:00');
117
end;
118
 
119
procedure TMainForm.FormResize(Sender: TObject);
120
var
121
  h: Integer;
122
begin
123
  // set panel heights to fit screen
124
  h := (Height - 2 * StatusBar.Height) div 4;
125
  CurrentTimePanel.Height := h;
126
  FoundationPanel.Height := h;
127
  IntermediatePanel.Height := h;
128
  AdvancedPanel.Height := h;
129
  Label1.Caption := 'Time Now:';
130
  FoundationLabel.Caption := FoundationCaption;
131
  IntermediateLabel.Caption := IntermediateCaption;
132
  AdvancedLabel.Caption := AdvancedCaption;
133
  Application.ProcessMessages;
134
end;
135
 
136
procedure TMainForm.FormShow(Sender: TObject);
137
var
138
  h: Integer;
139
begin
140
  // set panel heights to fit screen
141
  h := (Height - 2 * StatusBar.Height) div 4;
142
  CurrentTimePanel.Height := h;
143
  FoundationPanel.Height := h;
144
  IntermediatePanel.Height := h;
145
  AdvancedPanel.Height := h;
146
 
147
  CurrentTimeLabel.Caption := TimeToStr(Time);
148
  StatusBar.Panels[0].Text := DateToStr(Date);
149
  FoundationCaption := 'Foundation:';
150
  FoundationCaption := FoundationCaption + sLineBreak + 'Duration: ' +
151
                    TimeToStr(FoundationDuration);
152
  FoundationCaption := FoundationCaption + sLineBreak + 'Half Time: ' +
153
                    TimeToStr(FoundationHalfTime);
154
  FoundationLabel.Caption := FoundationCaption;
155
  FoundationTimeLabel.Caption := TimeToStr(FoundationDuration);
156
  IntermediateCaption := 'Intermediate:';
157
  IntermediateCaption := IntermediateCaption + sLineBreak + 'Duration: ' +
158
                      TimeToStr(IntermediateDuration);
159
  IntermediateCaption := IntermediateCaption + sLineBreak + 'Half Time: ' +
160
                      TimeToStr(IntermediateHalfTime);
161
  IntermediateLabel.Caption := IntermediateCaption;
162
  IntermediateTimeLabel.Caption := TimeToStr(IntermediateDuration);
163
  AdvancedCaption := 'Advanced:';
164
  AdvancedCaption := AdvancedCaption + sLineBreak + 'Duration: ' +
165
                  TimeToStr(AdvancedDuration);
166
  AdvancedCaption := AdvancedCaption + sLineBreak + 'Half Time: ' +
167
                  TimeToStr(AdvancedHalfTime);
168
  AdvancedLabel.Caption := AdvancedCaption;
169
  AdvancedTimeLabel.Caption := TimeToStr(AdvancedDuration);
170
end;
171
 
172
procedure TMainForm.HelpAboutClick(Sender: TObject);
173
begin
174
  Form1.ShowModal;
175
end;
176
 
177
procedure TMainForm.StartButtonClick(Sender: TObject);
178
var
179
  start: TDateTime;
180
begin
181
  start := Time;
182
  FoundationCaption := 'Foundation:';
183
  FoundationCaption := FoundationCaption + sLineBreak + 'Duration: ' +
184
                    TimeToStr(FoundationDuration);
185
  FoundationCaption := FoundationCaption + sLineBreak + 'Half Time: ' +
186
                    TimeToStr(start + FoundationHalfTime);
187
  FoundationCaption := FoundationCaption + sLineBreak + 'End Time: ' +
188
                    TimeToStr(start + FoundationDuration);
189
  FoundationLabel.Caption := FoundationCaption;
190
  IntermediateCaption := 'Intermediate:';
191
  IntermediateCaption := IntermediateCaption + sLineBreak + 'Duration: ' +
192
                      TimeToStr(IntermediateDuration);
193
  IntermediateCaption := IntermediateCaption + sLineBreak + 'Half Time: ' +
194
                      TimeToStr(start + IntermediateHalfTime);
195
  IntermediateCaption := IntermediateCaption + sLineBreak + 'End Time: ' +
196
                      TimeToStr(start + IntermediateDuration);
197
  IntermediateLabel.Caption := IntermediateCaption;
198
  AdvancedCaption := 'Advanced:';
199
  AdvancedCaption := AdvancedCaption + sLineBreak + 'Duration: ' +
200
                  TimeToStr(AdvancedDuration);
201
  AdvancedCaption := AdvancedCaption + sLineBreak + 'Half Time: ' +
202
                  TimeToStr(start + AdvancedHalfTime);
203
  AdvancedCaption := AdvancedCaption + sLineBreak + 'End Time: '+
204
                  TimeToStr(start + AdvancedDuration);
205
  AdvancedLabel.Caption := AdvancedCaption;
206
 
207
  // start the clock
208
  ClockRunning := True;
209
  StartButton.Enabled := False;
210
end;
211
 
212
procedure TMainForm.Timer1Timer(Sender: TObject);
213
begin
214
  CurrentTimeLabel.Caption := TimeToStr(Time);
215
  StatusBar.Panels[0].Text := DateToStr(Date);
216
  if ClockRunning then
217
  begin
10 ron.wellst 218
    { update the display
219
      first the Foundation display }
220
    if FoundationDuration > ZeroHour then
9 ron.wellst 221
    begin
222
      FoundationDuration := FoundationDuration - Sec;
10 ron.wellst 223
      if FoundationDuration <= TenMins then
224
         FoundationTimeLabel.Color := clFuchsia
9 ron.wellst 225
      else
226
      begin
10 ron.wellst 227
        if FoundationDuration <= FoundationHalfTime then
228
        FoundationTimeLabel.Color := clYellow;
9 ron.wellst 229
      end;
10 ron.wellst 230
    end
231
    else
232
    begin
233
      FoundationDuration := ZeroHour;
234
      FoundationTimeLabel.Color := clRed;
235
      FoundationPanel.Enabled := False;
9 ron.wellst 236
    end;
10 ron.wellst 237
    FoundationTimeLabel.Caption := TimeToStr(FoundationDuration);
238
    { update the Intermediate display }
239
    if IntermediateDuration > ZeroHour then
9 ron.wellst 240
    begin
241
      IntermediateDuration := IntermediateDuration - Sec;
10 ron.wellst 242
      if IntermediateDuration <= TenMins then
243
         IntermediateTimeLabel.Color := clFuchsia
9 ron.wellst 244
      else
245
      begin
10 ron.wellst 246
        if IntermediateDuration <= IntermediateHalfTime then
247
        IntermediateTimeLabel.Color := clYellow;
9 ron.wellst 248
      end;
10 ron.wellst 249
    end
250
    else
251
    begin
252
      IntermediateDuration := ZeroHour;
253
      IntermediateTimeLabel.Color := clRed;
254
      IntermediatePanel.Enabled := False;
9 ron.wellst 255
    end;
10 ron.wellst 256
    IntermediateTimeLabel.Caption := TimeToStr(IntermediateDuration);
257
    { update the Advanced display }
258
    if AdvancedDuration > ZeroHour then
9 ron.wellst 259
    begin
10 ron.wellst 260
      AdvancedDuration := AdvancedDuration - Sec;
261
      if AdvancedDuration <= TenMins then
262
         AdvancedTimeLabel.Color := clFuchsia
9 ron.wellst 263
      else
264
      begin
10 ron.wellst 265
        if AdvancedDuration <= AdvancedHalfTime then
266
        AdvancedTimeLabel.Color := clYellow;
9 ron.wellst 267
      end;
10 ron.wellst 268
    end
269
    else
270
    begin
271
      AdvancedDuration := ZeroHour;
272
      AdvancedTimeLabel.Color := clRed;
273
      AdvancedPanel.Enabled := False;
9 ron.wellst 274
    end;
10 ron.wellst 275
    AdvancedTimeLabel.Caption := TimeToStr(AdvancedDuration);
9 ron.wellst 276
  end;
277
  Label1.Caption := 'Time Now:';
278
  FoundationLabel.Caption := FoundationCaption;
279
  IntermediateLabel.Caption := IntermediateCaption;
280
  AdvancedLabel.Caption := AdvancedCaption;
281
  Application.ProcessMessages;
282
end;
283
 
284
end.
285