-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperiodedef.pas
More file actions
458 lines (419 loc) · 14.8 KB
/
periodedef.pas
File metadata and controls
458 lines (419 loc) · 14.8 KB
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
//***************************************************************************//
// Holbæk //
// Copyright by Claus Moeller 2013-2016 //
// PerioDef //
// Version //
// 18.10.13, 20-12-2016 //
//***************************************************************************//
unit PeriodeDef;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ActnList,
Menus, ComCtrls, ExtCtrls, Grids, EditBtn, StdCtrls, DBGrids, DbCtrls,
ZDataset, db;
type
{ TPeriodeDefForm }
TPeriodeDefForm = class(TForm)
DateEdit1: TDateEdit;
Slet: TAction;
ActionList1: TActionList;
Help: TAction;
ImageList1: TImageList;
Luk: TAction;
MenuItem1: TMenuItem;
Opret: TAction;
PopupMenu1: TPopupMenu;
StringGrid1: TStringGrid;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ZQuery1: TZQuery;
procedure DateEdit1Exit(Sender: TObject);
procedure DateEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure HelpExecute(Sender: TObject);
procedure LukExecute(Sender: TObject);
procedure OpretExecute(Sender: TObject);
procedure SletExecute(Sender: TObject);
procedure StringGrid1CheckboxToggled(sender: TObject; aCol, aRow: Integer;
aState: TCheckboxState);
procedure StringGrid1EditingDone(Sender: TObject);
procedure StringGrid1SelectEditor(Sender: TObject; aCol, aRow: Integer;
var Editor: TWinControl);
private
{ private declarations }
UpdateGrid : Boolean;
NextPeriodListe : TSTringList;
procedure Indstil;
procedure Indlaes;
Procedure GemRowTilTabel;
public
{ public declarations }
end;
var
PeriodeDefForm: TPeriodeDefForm;
implementation
{$R *.lfm}
Uses HolbaekConst, MainData, DateUtils;
Const
PerBet : Integer = 0;
PerBesk : Integer = 1;
PerFra : Integer = 2;
PerTil : Integer = 3;
PerAfsluttet : Integer = 4;
PerNextPeriod : Integer = 5;
PerOption : Integer = 6;
PerId : Integer = 7;
{ TPeriodeDefForm }
//**********************************************************
// Create
//**********************************************************
procedure TPeriodeDefForm.FormCreate(Sender: TObject);
begin
Position := poDesigned;
(*Top := 10;
Left := 30;*)
// Farver
ToolBar1.Color := H_Menu_knapper_Farve;
// StatusBar1.Color := H_Menu_knapper_Farve;;
Color := H_Window_Baggrund;
// Database
ZQuery1.Connection := MainData.MainDataModule.ZConnection1;
// Init
NextPeriodListe := TStringlist.Create;
Indstil;
Indlaes;
// Andet
end;
//**********************************************************
// Destroy
//**********************************************************
procedure TPeriodeDefForm.FormDestroy(Sender: TObject);
begin
NextPeriodListe.Free;
end;
//**********************************************************
// Hjælp
//**********************************************************
procedure TPeriodeDefForm.HelpExecute(Sender: TObject);
begin
MessageDlg('Hjælp',mtInformation,[mbOK],0);
end;
//**********************************************************
// Gem row til tabel
//**********************************************************
Procedure TPeriodeDefForm.GemRowTilTabel;
Var Stop : Boolean;
Begin
If UpdateGrid Then Exit;
// Find Record
Try
With MainDataModule.ZQuery1 do
Begin
SQL.Clear;
SQL.Add('Select * from PeriodeDef where Afd = ' + CurrentAfd +
' and nr = ' + StringGrid1.Cells[PerId,StringGrid1.Row]);
Open;
If RecordCount <> 1 Then
Begin
MessageDlg('Periode kan ikke opdateres!',mtInformation,[mbOk],0);
Exit;
end;
First;
Edit;
FieldByName('Periode').AsString := StringGrid1.Cells[PerBet,StringGrid1.Row];
FieldByName('Beskrivelse').AsString := StringGrid1.Cells[PerBesk,StringGrid1.Row];
FieldByName('DatoFra').AsFloat := DateTimeToJulianDate(StrToDate(StringGrid1.Cells[PerFra,StringGrid1.Row]));
FieldByName('DatoTil').AsFloat := DateTimeToJulianDate(StrToDate(StringGrid1.Cells[PerTil,StringGrid1.Row]));
FieldByName('Afsluttet').AsString := StringGrid1.Cells[PerAfsluttet,StringGrid1.Row];
FieldByName('NextPeriod').AsString := StringGrid1.Cells[PerNextPeriod,StringGrid1.Row];
FieldByName('Option').AsString := StringGrid1.Cells[PerOption,StringGrid1.Row];
Post;
ApplyUpdates;
end;
Except
MainDataModule.ZQuery1.CancelUpdates;
MessageDlg('Periode blev ikke gemt!',mtError,[mbOK],0);
Exit;
End
End;
//**********************************************************
// Indlæs
//**********************************************************
Procedure TPeriodeDefForm.Indlaes;
Var A : Integer;
Begin
UpdateGrid := True;
Try
With MainDataModule.ZQuery1 do
Begin
SQL.Clear;
SQL.Add('Select * from periodedef where Afd = ' + CurrentAfd);
StringGrid1.RowCount := 1;
Open;
If RecordCount = 0 Then
Begin
MessageDlg('Endnu ingen perioder defineret!',mtInformation,[mbOk],0);
Exit;
end;
NextPeriodListe.Clear;
A := 1;
First;
StringGrid1.BeginUpdate;
While Not EOF Do
Begin
StringGrid1.RowCount := StringGrid1.RowCount + 1;
StringGrid1.Cells[PerBet,A] := FieldByName('Periode').AsString;
NextPeriodListe.Add(FieldByName('Periode').AsString);
StringGrid1.Cells[PerBesk,A] := FieldByName('Beskrivelse').AsString;
StringGrid1.Cells[PerFra,A] := FieldByName('DatoFra').AsString;
StringGrid1.Cells[PerTil,A] := FieldByName('DatoTil').AsString;
StringGrid1.Cells[PerAfsluttet,A] := FieldByName('Afsluttet').AsString;
StringGrid1.Cells[PerNextPeriod,A] := FieldByName('NextPeriod').AsString;
StringGrid1.Cells[PerOption,A] := FieldByName('Option').AsString;
StringGrid1.Cells[PerId,A] := FieldByName('Nr').AsString;
Inc(A);
Next;
end;
StringGrid1.EndUpdate;
UpdateGrid := False;
end
Except
end;
end;
//**********************************************************
// Date edit key down
//**********************************************************
procedure TPeriodeDefForm.DateEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=9 then
begin
StringGrid1.EditorMode := false;
if StringGrid1.Col < StringGrid1.ColCount then
StringGrid1.Col := StringGrid1.Col + 1
Else
StringGrid1.Col := 0;
StringGrid1.SetFocus;
end;
end;
//**********************************************************
// Form close
//**********************************************************
procedure TPeriodeDefForm.FormClose(Sender: TObject;
var CloseAction: TCloseAction);
begin
// ZQuery1.Close;
CloseAction := caFree;
end;
//**********************************************************
// Date edit exit
//**********************************************************
procedure TPeriodeDefForm.DateEdit1Exit(Sender: TObject);
begin
StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row] := DateToStr(DateEdit1.Date);
end;
//**********************************************************
// Indstil
//**********************************************************
procedure TPeriodeDefForm.Indstil;
begin
Indstil_StringGrid_Edit(StringGrid1);
StringGrid1.Columns.Clear;
StringGrid1.Columns.Add;
StringGrid1.Columns.Add;
StringGrid1.Columns.Add;
StringGrid1.Columns.Add;
StringGrid1.Columns.Add;
StringGrid1.Columns.Add;
StringGrid1.Columns.Add;
StringGrid1.Columns.Add;
StringGrid1.Columns[PerBet].Title.Caption := 'Beteg.';
StringGrid1.Columns[PerBet].Width := 70;
StringGrid1.Columns[PerBet].Alignment := taLeftJustify;
StringGrid1.Columns[PerBesk].Title.Caption := 'Beskrivelse';
StringGrid1.Columns[PerBesk].Width := 150;
StringGrid1.Columns[PerBesk].Alignment := taLeftJustify;
StringGrid1.Columns[PerFra].Title.Caption := 'Fra';
StringGrid1.Columns[PerFra].Width := 70;
StringGrid1.Columns[PerFra].Alignment := taLeftJustify;
StringGrid1.Columns[PerTil].Title.Caption := 'Til';
StringGrid1.Columns[PerTil].Width := 70;
StringGrid1.Columns[PerTil].Alignment := taLeftJustify;
StringGrid1.Columns[PerAfsluttet].Title.Caption := 'Afsluttet';
StringGrid1.Columns[PerAfsluttet].Width := 50;
StringGrid1.Columns[PerAfsluttet].ButtonStyle := cbsCheckboxColumn;
StringGrid1.Columns[PerNextPeriod].Title.Caption := 'Næste per.';
StringGrid1.Columns[PerNextPeriod].Width := 80;
StringGrid1.Columns[PerNextPeriod].Alignment := taLeftJustify;
StringGrid1.Columns[PerOption].Title.Caption := 'Option';
StringGrid1.Columns[PerOption].Width := 50;
StringGrid1.Columns[PerOption].Alignment := taLeftJustify;
StringGrid1.Columns[PerId].Title.Caption := 'Id';
StringGrid1.Columns[PerId].Width := 50;
StringGrid1.Columns[PerId].Visible := False;
End;
//**********************************************************
// Luk
//**********************************************************
procedure TPeriodeDefForm.LukExecute(Sender: TObject);
begin
Close;
end;
//**********************************************************
// Opret
//**********************************************************
procedure TPeriodeDefForm.OpretExecute(Sender: TObject);
Var HelpNr : Integer;
begin
With ZQuery1.SQL do
Begin
Clear;
Add('Select * from PeriodeDef order by nr');
End;
ZQuery1.Open;
If ZQuery1.RecordCount = 0 Then
Begin
HelpNr := 1;
end
Else
Begin
ZQuery1.Last;
HelpNr := ZQuery1.FieldByName('Nr').AsInteger + 1;
end;
Try
ZQuery1.Append;
ZQuery1.Edit;
ZQuery1.FieldByName('Nr').AsInteger := HelpNr;
ZQuery1.FieldByName('Afd').AsString := CurrentAfd;
// Periode betegnelse 4 tegn
ZQuery1.FieldByName('Periode').AsString := '2014';
// Beskrivelse 40 tegn
ZQuery1.FieldByName('Beskrivelse').AsString := 'Periode beskrivelse';
// Fra dato
ZQuery1.FieldByName('DatoFra').AsString := '01-01-1900';
// Til dato
ZQuery1.FieldByName('DatoTil').AsString := '01-01-2100';
// Afsluttet
ZQuery1.FieldByName('Afsluttet').AsString := '0';
// Next period
ZQuery1.FieldByName('NextPeriod').Clear;
// Option
ZQuery1.FieldByName('Option').Clear;
// Gem
ZQuery1.Post;
ZQuery1.ApplyUpdates;
Except
MessageDlg('Periode kunne ikke oprettes!',mtError,[mbOk],0);
ZQuery1.CancelUpdates;
Exit;
end;
Indlaes;
end;
//**********************************************************
// Slet
//**********************************************************
procedure TPeriodeDefForm.SletExecute(Sender: TObject);
Begin
If StringGrid1.RowCount = 2 Then
Begin
MessageDlg('Der skal min. være defineret en periode!',mtInformation,[mbOk],0);
Exit;
end;
// Find Record
With ZQuery1.SQL do
Begin
Clear;
Add('Select * from PeriodeDef where Afd = ' + CurrentAfd +
' and nr = ' + StringGrid1.Cells[PerId,StringGrid1.Row]);
End;
ZQuery1.Open;
If ZQuery1.RecordCount <> 1 Then
Begin
MessageDlg('Periode kan ikke slettes!',mtInformation,[mbOk],0);
Exit;
end;
ZQuery1.First;
{ TODO : Kan periode slettes? }
Try
ZQuery1.Delete;
Except
MessageDlg('Kan ikke fjerne perioden!',mtError,[mbOk],0);
ZQuery1.CancelUpdates;
Exit;
End;
Indlaes;
end;
//**********************************************************
// StringGrid: Checkbox
//**********************************************************
procedure TPeriodeDefForm.StringGrid1CheckboxToggled(sender: TObject; aCol,
aRow: Integer; aState: TCheckboxState);
begin
GemRowTilTabel;
end;
//**********************************************************
// StringGrid: Editing done
//**********************************************************
procedure TPeriodeDefForm.StringGrid1EditingDone(Sender: TObject);
begin
GemRowTilTabel;
end;
//**********************************************************
// StringGrid: Select Editor
//**********************************************************
procedure TPeriodeDefForm.StringGrid1SelectEditor(Sender: TObject; aCol,
aRow: Integer; var Editor: TWinControl);
begin
If aCol = PerBet Then
Begin
Editor := StringGrid1.EditorByStyle(cbsAuto);
end
Else If acol = PerBesk Then
Begin
Editor := StringGrid1.EditorByStyle(cbsAuto);
end
Else If acol = PerFra Then
Begin
try
DateEdit1.BoundsRect := StringGrid1.CellRect(aCol,aRow);
If StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row] <> '' Then
DateEdit1.Date := StrToDate(StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row]);
Editor := DateEdit1;
Except
end;
end
Else If acol = PerTil Then
Begin
try
DateEdit1.BoundsRect := StringGrid1.CellRect(aCol,aRow);
If StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row] <> '' Then
DateEdit1.Date := StrToDate(StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row]);
Editor := DateEdit1;
Except
end;
end
Else If acol = PerAfsluttet Then
Begin
Editor := StringGrid1.EditorByStyle(cbsCheckboxColumn);
end
Else If acol = PerNextPeriod Then
Begin
Editor := StringGrid1.EditorByStyle(cbsPickList);
TCustomComboBox(Editor).Items.AddStrings(NextPeriodListe);
end
Else If acol = PerOption Then
Begin
Editor := StringGrid1.EditorByStyle(cbsPickList);
TCustomComboBox(Editor).Items.Clear;
TCustomComboBox(Editor).Items.Add('Indsæt');
TCustomComboBox(Editor).Items.Add('Spørg inden');
end
end;
end.