Subversion Repositories ExamClock

Rev

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