1 | unit ORDtTmRng;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
---|
7 | StdCtrls, ORFn, OR2006Compatibility, ORDtTm;
|
---|
8 |
|
---|
9 | type
|
---|
10 | TORfrmDateRange = class(Tfrm2006Compatibility)
|
---|
11 | lblStart: TLabel;
|
---|
12 | lblStop: TLabel;
|
---|
13 | cmdOK: TButton;
|
---|
14 | cmdCancel: TButton;
|
---|
15 | lblInstruct: TLabel;
|
---|
16 | procedure cmdOKClick(Sender: TObject);
|
---|
17 | procedure cmdCancelClick(Sender: TObject);
|
---|
18 | procedure FormCreate(Sender: TObject);
|
---|
19 | procedure FormDestroy(Sender: TObject);
|
---|
20 | private
|
---|
21 | FCalStart: TORDateBox;
|
---|
22 | FCalStop: TORDateBox;
|
---|
23 | protected
|
---|
24 | procedure Loaded; override;
|
---|
25 | end;
|
---|
26 |
|
---|
27 | TORDateRangeDlg = class(TComponent)
|
---|
28 | private
|
---|
29 | FTextOfStart: string;
|
---|
30 | FTextOfStop: string;
|
---|
31 | FFMDateStart: TFMDateTime;
|
---|
32 | FFMDateStop: TFMDateTime;
|
---|
33 | FRelativeStart: string;
|
---|
34 | FRelativeStop: string;
|
---|
35 | FDateOnly: Boolean;
|
---|
36 | FRequireTime: Boolean;
|
---|
37 | FInstruction: string;
|
---|
38 | FLabelStart: string;
|
---|
39 | FLabelStop: string;
|
---|
40 | FFormat: string;
|
---|
41 | procedure SetDateOnly(Value: Boolean);
|
---|
42 | procedure SetFMDateStart(Value: TFMDateTime);
|
---|
43 | procedure SetFMDateStop(Value: TFMDateTime);
|
---|
44 | procedure SetTextOfStart(const Value: string);
|
---|
45 | procedure SetTextOfStop(const Value: string);
|
---|
46 | procedure SetRequireTime(Value: Boolean);
|
---|
47 | public
|
---|
48 | constructor Create(AOwner: TComponent); override;
|
---|
49 | function Execute: Boolean;
|
---|
50 | property RelativeStart: string read FRelativeStart;
|
---|
51 | property RelativeStop: string read FRelativeStop;
|
---|
52 | published
|
---|
53 | property DateOnly: Boolean read FDateOnly write SetDateOnly;
|
---|
54 | property FMDateStart: TFMDateTime read FFMDateStart write SetFMDateStart;
|
---|
55 | property FMDateStop: TFMDateTime read FFMDateStop write SetFMDateStop;
|
---|
56 | property Instruction: string read FInstruction write FInstruction;
|
---|
57 | property LabelStart: string read FLabelStart write FLabelStart;
|
---|
58 | property LabelStop: string read FLabelStop write FLabelStop;
|
---|
59 | property RequireTime: Boolean read FRequireTime write SetRequireTime;
|
---|
60 | property Format: string read FFormat write FFormat;
|
---|
61 | property TextOfStart: string read FTextOfStart write SetTextOfStart;
|
---|
62 | property TextOfStop: string read FTextOfStop write SetTextOfStop;
|
---|
63 | end;
|
---|
64 |
|
---|
65 | procedure Register;
|
---|
66 |
|
---|
67 | implementation
|
---|
68 |
|
---|
69 | {$R *.DFM}
|
---|
70 |
|
---|
71 | const
|
---|
72 | FMT_DATETIME = 'mmm d,yy@hh:nn';
|
---|
73 | FMT_DATEONLY = 'mmm d,yy';
|
---|
74 |
|
---|
75 | { TORDateRangeDlg --------------------------------------------------------------------------- }
|
---|
76 |
|
---|
77 | constructor TORDateRangeDlg.Create(AOwner: TComponent);
|
---|
78 | begin
|
---|
79 | inherited Create(AOwner);
|
---|
80 | FInstruction := 'Enter a date range -';
|
---|
81 | FLabelStart := 'Begin Date';
|
---|
82 | FLabelStop := 'End Date';
|
---|
83 | FFormat := FMT_DATETIME;
|
---|
84 | end;
|
---|
85 |
|
---|
86 | function TORDateRangeDlg.Execute: Boolean;
|
---|
87 | var
|
---|
88 | frmDateRange: TORfrmDateRange;
|
---|
89 | begin
|
---|
90 | frmDateRange := TORfrmDateRange.Create(Application);
|
---|
91 | try
|
---|
92 | with frmDateRange do
|
---|
93 | begin
|
---|
94 | FCalStart.Text := FTextOfStart;
|
---|
95 | FCalStop.Text := FTextOfStop;
|
---|
96 | if FFMDateStart > 0 then
|
---|
97 | begin
|
---|
98 | FCalStart.FMDateTime := FFMDateStart;
|
---|
99 | FCalStart.Text := FormatFMDateTime(FFormat, FFMDateStart);
|
---|
100 | end;
|
---|
101 | if FFMDateStop > 0 then
|
---|
102 | begin
|
---|
103 | FCalStop.FMDateTime := FFMDateStop;
|
---|
104 | FCalStop.Text := FormatFMDateTime(FFormat, FFMDateStop);
|
---|
105 | end;
|
---|
106 | FCalStart.DateOnly := FDateOnly;
|
---|
107 | FCalStop.DateOnly := FDateOnly;
|
---|
108 | FCalStart.RequireTime := FRequireTime;
|
---|
109 | FCalStop.RequireTime := FRequireTime;
|
---|
110 | lblInstruct.Caption := FInstruction;
|
---|
111 | lblStart.Caption := FLabelStart;
|
---|
112 | lblStop.Caption := FLabelStop;
|
---|
113 |
|
---|
114 | Result := (ShowModal = IDOK);
|
---|
115 | if Result then
|
---|
116 | begin
|
---|
117 | FTextOfStart := FCalStart.Text;
|
---|
118 | FTextOfStop := FCalStop.Text;
|
---|
119 | FFMDateStart := FCalStart.FMDateTime;
|
---|
120 | FFMDateStop := FCalStop.FMDateTime;
|
---|
121 | FRelativeStart := FCalStart.RelativeTime;
|
---|
122 | FRelativeStop := FCalStop.RelativeTime;
|
---|
123 | end;
|
---|
124 | end;
|
---|
125 | finally
|
---|
126 | frmDateRange.Free;
|
---|
127 | end;
|
---|
128 | end;
|
---|
129 |
|
---|
130 | procedure TORDateRangeDlg.SetDateOnly(Value: Boolean);
|
---|
131 | begin
|
---|
132 | FDateOnly := Value;
|
---|
133 | if FDateOnly then
|
---|
134 | begin
|
---|
135 | FRequireTime := False;
|
---|
136 | FMDateStart := Int(FFMDateStart);
|
---|
137 | FMDateStop := Int(FFMDateStop);
|
---|
138 | if FFormat = FMT_DATETIME then FFormat := FMT_DATEONLY;
|
---|
139 | end;
|
---|
140 | end;
|
---|
141 |
|
---|
142 | procedure TORDateRangeDlg.SetRequireTime(Value: Boolean);
|
---|
143 | begin
|
---|
144 | FRequireTime := Value;
|
---|
145 | if FRequireTime then
|
---|
146 | begin
|
---|
147 | if FFormat = FMT_DATEONLY then FFormat := FMT_DATETIME;
|
---|
148 | SetDateOnly(False);
|
---|
149 | end;
|
---|
150 | end;
|
---|
151 |
|
---|
152 | procedure TORDateRangeDlg.SetFMDateStart(Value: TFMDateTime);
|
---|
153 | begin
|
---|
154 | FFMDateStart := Value;
|
---|
155 | FTextOfStart := FormatFMDateTime(FFormat, FFMDateStart);
|
---|
156 | end;
|
---|
157 |
|
---|
158 | procedure TORDateRangeDlg.SetFMDateStop(Value: TFMDateTime);
|
---|
159 | begin
|
---|
160 | FFMDateStop := Value;
|
---|
161 | FTextOfStop := FormatFMDateTime(FFormat, FFMDateStop);
|
---|
162 | end;
|
---|
163 |
|
---|
164 | procedure TORDateRangeDlg.SetTextOfStart(const Value: string);
|
---|
165 | begin
|
---|
166 | FTextOfStart := Value;
|
---|
167 | FFMDateStart := 0;
|
---|
168 | end;
|
---|
169 |
|
---|
170 | procedure TORDateRangeDlg.SetTextOfStop(const Value: string);
|
---|
171 | begin
|
---|
172 | FTextOfStop := Value;
|
---|
173 | FFMDateStop := 0;
|
---|
174 | end;
|
---|
175 |
|
---|
176 |
|
---|
177 | { TORfrmDateRange --------------------------------------------------------------------------- }
|
---|
178 |
|
---|
179 | procedure TORfrmDateRange.cmdOKClick(Sender: TObject);
|
---|
180 | var
|
---|
181 | ErrMsg: string;
|
---|
182 | begin
|
---|
183 | FCalStart.Validate(ErrMsg);
|
---|
184 | if ErrMsg <> '' then
|
---|
185 | begin
|
---|
186 | Application.MessageBox(PChar(ErrMsg), 'Start Date Error', MB_OK);
|
---|
187 | Exit;
|
---|
188 | end;
|
---|
189 | FCalStop.Validate(ErrMsg);
|
---|
190 | if ErrMsg <> '' then
|
---|
191 | begin
|
---|
192 | Application.MessageBox(PChar(ErrMsg), 'Stop Date Error', MB_OK);
|
---|
193 | Exit;
|
---|
194 | end;
|
---|
195 | ModalResult := mrOK;
|
---|
196 | end;
|
---|
197 |
|
---|
198 | procedure TORfrmDateRange.cmdCancelClick(Sender: TObject);
|
---|
199 | begin
|
---|
200 | ModalResult := mrCancel;
|
---|
201 | end;
|
---|
202 |
|
---|
203 | procedure Register;
|
---|
204 | { used by Delphi to put components on the Palette }
|
---|
205 | begin
|
---|
206 | RegisterComponents('CPRS', [TORDateRangeDlg]);
|
---|
207 | end;
|
---|
208 |
|
---|
209 | procedure TORfrmDateRange.FormCreate(Sender: TObject);
|
---|
210 | { Create date boxes here to avoid problem where TORDateBox is not already on component palette. }
|
---|
211 | begin
|
---|
212 | FCalStart := TORDateBox.Create(Self);
|
---|
213 | FCalStart.Parent := Self;
|
---|
214 | FCalStart.SetBounds(8, 58, 121, 21);
|
---|
215 | FCalStart.TabOrder := 0;
|
---|
216 | FCalStop := TORDateBox.Create(Self);
|
---|
217 | FCalStop.Parent := Self;
|
---|
218 | FCalStop.SetBounds(145, 58, 121, 21);
|
---|
219 | FCalStop.TabOrder := 1;
|
---|
220 | ResizeAnchoredFormToFont(self);
|
---|
221 | UpdateColorsFor508Compliance(self);
|
---|
222 | end;
|
---|
223 |
|
---|
224 | procedure TORfrmDateRange.FormDestroy(Sender: TObject);
|
---|
225 | begin
|
---|
226 | FCalStart.Free;
|
---|
227 | FCalStop.Free;
|
---|
228 | end;
|
---|
229 |
|
---|
230 | procedure TORfrmDateRange.Loaded;
|
---|
231 | begin
|
---|
232 | inherited Loaded;
|
---|
233 | UpdateColorsFor508Compliance(Self);
|
---|
234 | end;
|
---|
235 |
|
---|
236 | end.
|
---|