Subversion Repositories ExamClock

Rev

Rev 12 | 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 }
12 ron 108
  FoundationDuration := StrToTime('01:00:00');
10 ron.wellst 109
  FoundationHalfTime := StrToTime('00:30:00');
12 ron 110
  IntermediateDuration := StrToTime('01:30:00');
111
  IntermediateHalfTime := StrToTime('00:45:00');
9 ron.wellst 112
  AdvancedDuration := StrToTime('02:00:00');
113
  AdvancedHalfTime := StrToTime('01:00:00');
10 ron.wellst 114
  TenMins := StrToTime('00:10:00');
12 ron 115
 
9 ron.wellst 116
  Sec := StrToTime('00:00:01');
117
  ZeroHour := StrToTime('00:00:00');
118
end;
119
 
120
procedure TMainForm.FormResize(Sender: TObject);
121
var
122
  h: Integer;
123
begin
124
  // set panel heights to fit screen
125
  h := (Height - 2 * StatusBar.Height) div 4;
126
  CurrentTimePanel.Height := h;
127
  FoundationPanel.Height := h;
128
  IntermediatePanel.Height := h;
129
  AdvancedPanel.Height := h;
130
  Label1.Caption := 'Time Now:';
131
  FoundationLabel.Caption := FoundationCaption;
132
  IntermediateLabel.Caption := IntermediateCaption;
133
  AdvancedLabel.Caption := AdvancedCaption;
134
  Application.ProcessMessages;
135
end;
136
 
137
procedure TMainForm.FormShow(Sender: TObject);
138
var
139
  h: Integer;
140
begin
141
  // set panel heights to fit screen
142
  h := (Height - 2 * StatusBar.Height) div 4;
143
  CurrentTimePanel.Height := h;
144
  FoundationPanel.Height := h;
145
  IntermediatePanel.Height := h;
146
  AdvancedPanel.Height := h;
147
 
148
  CurrentTimeLabel.Caption := TimeToStr(Time);
149
  StatusBar.Panels[0].Text := DateToStr(Date);
150
  FoundationCaption := 'Foundation:';
151
  FoundationCaption := FoundationCaption + sLineBreak + 'Duration: ' +
152
                    TimeToStr(FoundationDuration);
153
  FoundationCaption := FoundationCaption + sLineBreak + 'Half Time: ' +
154
                    TimeToStr(FoundationHalfTime);
155
  FoundationLabel.Caption := FoundationCaption;
156
  FoundationTimeLabel.Caption := TimeToStr(FoundationDuration);
157
  IntermediateCaption := 'Intermediate:';
158
  IntermediateCaption := IntermediateCaption + sLineBreak + 'Duration: ' +
159
                      TimeToStr(IntermediateDuration);
160
  IntermediateCaption := IntermediateCaption + sLineBreak + 'Half Time: ' +
161
                      TimeToStr(IntermediateHalfTime);
162
  IntermediateLabel.Caption := IntermediateCaption;
163
  IntermediateTimeLabel.Caption := TimeToStr(IntermediateDuration);
164
  AdvancedCaption := 'Advanced:';
165
  AdvancedCaption := AdvancedCaption + sLineBreak + 'Duration: ' +
166
                  TimeToStr(AdvancedDuration);
167
  AdvancedCaption := AdvancedCaption + sLineBreak + 'Half Time: ' +
168
                  TimeToStr(AdvancedHalfTime);
169
  AdvancedLabel.Caption := AdvancedCaption;
170
  AdvancedTimeLabel.Caption := TimeToStr(AdvancedDuration);
171
end;
172
 
173
procedure TMainForm.HelpAboutClick(Sender: TObject);
174
begin
175
  Form1.ShowModal;
176
end;
177
 
178
procedure TMainForm.StartButtonClick(Sender: TObject);
179
var
180
  start: TDateTime;
181
begin
182
  start := Time;
183
  FoundationCaption := 'Foundation:';
184
  FoundationCaption := FoundationCaption + sLineBreak + 'Duration: ' +
185
                    TimeToStr(FoundationDuration);
186
  FoundationCaption := FoundationCaption + sLineBreak + 'Half Time: ' +
187
                    TimeToStr(start + FoundationHalfTime);
188
  FoundationCaption := FoundationCaption + sLineBreak + 'End Time: ' +
189
                    TimeToStr(start + FoundationDuration);
190
  FoundationLabel.Caption := FoundationCaption;
191
  IntermediateCaption := 'Intermediate:';
192
  IntermediateCaption := IntermediateCaption + sLineBreak + 'Duration: ' +
193
                      TimeToStr(IntermediateDuration);
194
  IntermediateCaption := IntermediateCaption + sLineBreak + 'Half Time: ' +
195
                      TimeToStr(start + IntermediateHalfTime);
196
  IntermediateCaption := IntermediateCaption + sLineBreak + 'End Time: ' +
197
                      TimeToStr(start + IntermediateDuration);
198
  IntermediateLabel.Caption := IntermediateCaption;
199
  AdvancedCaption := 'Advanced:';
200
  AdvancedCaption := AdvancedCaption + sLineBreak + 'Duration: ' +
201
                  TimeToStr(AdvancedDuration);
202
  AdvancedCaption := AdvancedCaption + sLineBreak + 'Half Time: ' +
203
                  TimeToStr(start + AdvancedHalfTime);
204
  AdvancedCaption := AdvancedCaption + sLineBreak + 'End Time: '+
205
                  TimeToStr(start + AdvancedDuration);
206
  AdvancedLabel.Caption := AdvancedCaption;
207
 
208
  // start the clock
209
  ClockRunning := True;
210
  StartButton.Enabled := False;
211
end;
212
 
213
procedure TMainForm.Timer1Timer(Sender: TObject);
214
begin
215
  CurrentTimeLabel.Caption := TimeToStr(Time);
216
  StatusBar.Panels[0].Text := DateToStr(Date);
217
  if ClockRunning then
218
  begin
10 ron.wellst 219
    { update the display
220
      first the Foundation display }
221
    if FoundationDuration > ZeroHour then
9 ron.wellst 222
    begin
223
      FoundationDuration := FoundationDuration - Sec;
10 ron.wellst 224
      if FoundationDuration <= TenMins then
14 ron 225
           FoundationTimeLabel.Color := clFuchsia
9 ron.wellst 226
      else
227
      begin
10 ron.wellst 228
        if FoundationDuration <= FoundationHalfTime then
14 ron 229
          FoundationTimeLabel.Color := clYellow;
9 ron.wellst 230
      end;
10 ron.wellst 231
    end
232
    else
233
    begin
234
      FoundationDuration := ZeroHour;
235
      FoundationTimeLabel.Color := clRed;
236
      FoundationPanel.Enabled := False;
9 ron.wellst 237
    end;
10 ron.wellst 238
    FoundationTimeLabel.Caption := TimeToStr(FoundationDuration);
239
    { update the Intermediate display }
240
    if IntermediateDuration > ZeroHour then
9 ron.wellst 241
    begin
242
      IntermediateDuration := IntermediateDuration - Sec;
10 ron.wellst 243
      if IntermediateDuration <= TenMins then
14 ron 244
           IntermediateTimeLabel.Color := clFuchsia
9 ron.wellst 245
      else
246
      begin
10 ron.wellst 247
        if IntermediateDuration <= IntermediateHalfTime then
14 ron 248
          IntermediateTimeLabel.Color := clYellow;
9 ron.wellst 249
      end;
10 ron.wellst 250
    end
251
    else
252
    begin
253
      IntermediateDuration := ZeroHour;
254
      IntermediateTimeLabel.Color := clRed;
255
      IntermediatePanel.Enabled := False;
9 ron.wellst 256
    end;
10 ron.wellst 257
    IntermediateTimeLabel.Caption := TimeToStr(IntermediateDuration);
258
    { update the Advanced display }
259
    if AdvancedDuration > ZeroHour then
9 ron.wellst 260
    begin
10 ron.wellst 261
      AdvancedDuration := AdvancedDuration - Sec;
262
      if AdvancedDuration <= TenMins then
14 ron 263
        AdvancedTimeLabel.Color := clFuchsia
9 ron.wellst 264
      else
265
      begin
10 ron.wellst 266
        if AdvancedDuration <= AdvancedHalfTime then
14 ron 267
          AdvancedTimeLabel.Color := clYellow;
9 ron.wellst 268
      end;
10 ron.wellst 269
    end
270
    else
271
    begin
272
      AdvancedDuration := ZeroHour;
273
      AdvancedTimeLabel.Color := clRed;
274
      AdvancedPanel.Enabled := False;
9 ron.wellst 275
    end;
10 ron.wellst 276
    AdvancedTimeLabel.Caption := TimeToStr(AdvancedDuration);
9 ron.wellst 277
  end;
278
  Label1.Caption := 'Time Now:';
279
  FoundationLabel.Caption := FoundationCaption;
280
  IntermediateLabel.Caption := IntermediateCaption;
281
  AdvancedLabel.Caption := AdvancedCaption;
282
  Application.ProcessMessages;
283
end;
284
 
285
end.
286