-
Notifications
You must be signed in to change notification settings - Fork 0
/
UKwatPlanWyjazdow.pas
272 lines (230 loc) · 7.8 KB
/
UKwatPlanWyjazdow.pas
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
unit UKwatPlanWyjazdow;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,
Buttons, ComCtrls, DBCtrls, TplGradientUnit, UWeekView, DB, ZDataset,
rxdbgrid, DateUtils, datamodule, LR_Class, LR_DBSet, DateTimePicker;
type
{ TKwatPlanWyjazdow }
TKwatPlanWyjazdow = class(TForm)
btnUsun: TBitBtn;
btnZaplanuj: TBitBtn;
btnModyfikuj: TBitBtn;
btnDrukuj: TBitBtn;
dtpSelectedDate: TDateTimePicker;
DBMemoUwagi: TDBMemo;
DBNavigator1: TDBNavigator;
DSPlanWyjazdow: TDataSource;
DSUwagi: TDataSource;
frDBDataSet1: TfrDBDataSet;
frReport1: TfrReport;
Image1: TImage;
Label1: TLabel;
lblWeekDate: TLabel;
PageControl1: TPageControl;
Panel1: TPanel;
Panel4: TPanel;
RxDBGrid1: TRxDBGrid;
Splitter2: TSplitter;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
WeekPanel: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Panel5: TPanel;
plGradient2: TplGradient;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
ZQPlanWyjazdow: TZQuery;
ZQUwagi: TZQuery;
procedure btnDrukujClick(Sender: TObject);
procedure btnModyfikujClick(Sender: TObject);
procedure btnUsunClick(Sender: TObject);
procedure btnZaplanujClick(Sender: TObject);
procedure dtpSelectedDateChange(Sender: TObject);
procedure DSPlanWyjazdowDataChange(Sender: TObject; Field: TField);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure WeekEventClick(StartDate: TDateTime);
procedure WeekChanged(Sender: TObject);
procedure EventDbClick(Sender: TObject);
procedure EventClick(Sender: TObject);
procedure SelectionEndClick(Sender: TObject);
procedure ZQUwagiBeforePost(DataSet: TDataSet);
private
WeekView: TWeekView;
public
Procedure WczytajDane;
procedure ZaplanujWyjazd(SelectDateTime: TDateTime);
procedure ModyfikujWyjazd(AID: integer);
end;
implementation
uses UKwatPlanWyjazdowAdd;
{$R *.frm}
{ TKwatPlanWyjazdow }
procedure TKwatPlanWyjazdow.FormCreate(Sender: TObject);
begin
WeekView:= TWeekView.Create(WeekPanel);
WeekView.Parent:= WeekPanel;
WeekView.Align := alClient;
WeekView.lblWeekDate:= lblWeekDate;
WeekView.OnDblClick := @WeekEventClick;
WeekView.OnEventDbClick := @EventDbClick;
WeekView.OnEventClick := @EventClick;
WeekView.OnWeekChanged := @WeekChanged;
WeekView.OnSelectionEnd := @SelectionEndClick;
WeekView.Invalidate;
btnZaplanuj.Enabled:= DM.uprawnienia[19];
btnUsun.Enabled := DM.uprawnienia[19];
end;
procedure TKwatPlanWyjazdow.FormDestroy(Sender: TObject);
begin
FreeAndNil(WeekView);
end;
procedure TKwatPlanWyjazdow.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
if ZQUwagi.State in [dsEdit, dsInsert] then ZQUwagi.Post;
end;
procedure TKwatPlanWyjazdow.btnUsunClick(Sender: TObject);
var ZQPom: TZQueryPom;
begin
if ZQPlanWyjazdow.IsEmpty then exit;
if ZQPlanWyjazdow.FieldByName('data_wyjazdu').AsDateTime< Now then
begin
MessageDlg('Nie można usunąć zdarzenia gdyż jego data jest wcześniejsza niż bieżąca.', mtWarning, [mbOK],0);
exit;
end;
if not(MessageDlg('Czy napewno usunąć planowane zdarzenie?', mtConfirmation, [mbYes, mbNo],0) = mrYes) then exit;
try
ZQPom:= TZQueryPom.Create(Self);
ZQPom.SQL.Text:= 'UPDATE kwat_plan_wyjazdow SET user=:user, data_modyfikacji=NOW(), stan="U" WHERE ID=:id';
ZQPom.ParamByName('user').AsString:= DM.PelnaNazwa;
ZQPom.ParamByName('id').AsInteger:= ZQPlanWyjazdow.FieldByName('ID').AsInteger;
ZQPom.ExecSQL;
finally
FreeAndNil(ZQPom);
end;
WczytajDane;
end;
procedure TKwatPlanWyjazdow.btnModyfikujClick(Sender: TObject);
begin
ModyfikujWyjazd( ZQPlanWyjazdow.FieldByName('ID').AsInteger );
end;
procedure TKwatPlanWyjazdow.btnDrukujClick(Sender: TObject);
begin
frReport1.LoadFromFile(DM.Path_Raporty + 'kwat_wykazWyjazdow.lrf');
frReport1.ShowReport;
end;
procedure TKwatPlanWyjazdow.btnZaplanujClick(Sender: TObject);
begin
ZaplanujWyjazd(WeekView.SelectDateTime);
end;
procedure TKwatPlanWyjazdow.dtpSelectedDateChange(Sender: TObject);
begin
WeekView.SelectDate:= dtpSelectedDate.Date;
end;
procedure TKwatPlanWyjazdow.DSPlanWyjazdowDataChange(Sender: TObject; Field: TField);
begin
btnUsun.Enabled:= (DM.uprawnienia[19])and
(not ZQPlanWyjazdow.IsEmpty)and
(ZQPlanWyjazdow.FieldByName('data_wyjazdu').AsDateTime>IncDay(Now(), -2));
btnModyfikuj.Enabled:= btnUsun.Enabled;
if not ZQPlanWyjazdow.IsEmpty then WeekView.SelectEvent(ZQPlanWyjazdow.FieldByName('ID').AsInteger);
end;
procedure TKwatPlanWyjazdow.FormShow(Sender: TObject);
begin
WeekChanged(Self);
end;
procedure TKwatPlanWyjazdow.SpeedButton1Click(Sender: TObject);
begin
WeekView.PrevWeek;
end;
procedure TKwatPlanWyjazdow.SpeedButton2Click(Sender: TObject);
begin
WeekView.NextWeek;
end;
procedure TKwatPlanWyjazdow.WeekEventClick(StartDate: TDateTime);
begin
ZaplanujWyjazd(StartDate);
end;
procedure TKwatPlanWyjazdow.WeekChanged(Sender: TObject);
begin
dtpSelectedDate.Date:= WeekView.SelectDate;
WczytajDane; // ZQPlanWyjazdow;
// zapisz uwagi jeśli są nowe
if ZQUwagi.State in [dsEdit, dsInsert] then ZQUwagi.Post;
ZQUwagi.Close;
ZQUwagi.ParamByName('data_start').AsDate:= WeekView.BeginWeekDate;
ZQUwagi.Open;
end;
procedure TKwatPlanWyjazdow.EventDbClick(Sender: TObject);
begin
// Dostęp do Wciśniętego Eventa
if btnModyfikuj.Enabled then
ModyfikujWyjazd(TEventWeek(Sender).ID);
end;
procedure TKwatPlanWyjazdow.EventClick(Sender: TObject);
begin
// select pos in DB by Event ID
ZQPlanWyjazdow.Locate('ID', TEventWeek(Sender).ID, []);
end;
procedure TKwatPlanWyjazdow.SelectionEndClick(Sender: TObject);
begin
dtpSelectedDate.Date:= WeekView.SelectDate;
end;
procedure TKwatPlanWyjazdow.ZQUwagiBeforePost(DataSet: TDataSet);
begin
if ZQUwagi.State in [dsInsert] then // zapisz zmiany jeśli są
ZQUwagi.FieldByName('data').AsDateTime:= ZQUwagi.ParamByName('data_start').AsDate;
end;
procedure TKwatPlanWyjazdow.WczytajDane;
var EventRecord: TEventRecord;
begin
ShowSQLWait;
try
WeekView.ClearEvent;
ZQPlanWyjazdow.Close;
ZQPlanWyjazdow.ParamByName('data_start').AsDate:= WeekView.BeginWeekDate;
ZQPlanWyjazdow.ParamByName('data_end').AsDate:= EndOfTheWeek(WeekView.BeginWeekDate);
ZQPlanWyjazdow.Open;
while not ZQPlanWyjazdow.EOF do
begin
EventRecord.ID := ZQPlanWyjazdow.FieldByName('ID').AsInteger;
EventRecord.StartDate:= ZQPlanWyjazdow.FieldByName('data_wyjazdu').AsDateTime;
EventRecord.EndDate := ZQPlanWyjazdow.FieldByName('data_powrotu').AsDateTime;
EventRecord.Title := ZQPlanWyjazdow.FieldByName('Nazwa').AsString+ ' - ' +ZQPlanWyjazdow.FieldByName('Kierowca').AsString;
EventRecord.Cel := ZQPlanWyjazdow.FieldByName('Cel').AsString;
EventRecord.Uwagi := ZQPlanWyjazdow.FieldByName('Uwagi').AsString;
EventRecord.BgColor := StringToColorDef(ZQPlanWyjazdow.FieldByName('Event_color').AsString, clSkyBlue);
WeekView.AddEvent(EventRecord, false);
ZQPlanWyjazdow.Next;
end;
WeekView.CalcColumEvent;
finally
HideSQLWait;
end;
end;
procedure TKwatPlanWyjazdow.ZaplanujWyjazd(SelectDateTime: TDateTime);
begin
with TKwatPlanWyjazdowAdd.Create(Self) do
begin
ZaplanujWyjazd( SelectDateTime );
if ShowModal=mrOK then WczytajDane;
Free;
end;
end;
procedure TKwatPlanWyjazdow.ModyfikujWyjazd(AID: integer);
begin
with TKwatPlanWyjazdowAdd.Create(Self) do
begin
ModyfikujWyjazd( AID );
if ShowModal=mrOK then WczytajDane;
Free;
end;
end;
end.