-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUKomunikator.pas
235 lines (198 loc) · 5.92 KB
/
UKomunikator.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
unit UKomunikator;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, db, FileUtil, ZDataset, ZSqlUpdate, RichMemo, rxdbgrid,
Forms, Controls, Graphics, Dialogs, ComCtrls, ExtCtrls, Buttons, StdCtrls,
Menus, datamodule, LR_Class, rxdbutils;
type
{ TKomunikator }
TKomunikator = class(TForm)
btnDrukujZaznaczone: TBitBtn;
btnNowaWiadomosc: TBitBtn;
btnOdpisz: TBitBtn;
btnDrukuj: TBitBtn;
btnOdswiez: TBitBtn;
DSKomOdebrane: TDataSource;
DSKomWyslane: TDataSource;
DSKomOdbiorcy: TDataSource;
MenuItemKopiuj: TMenuItem;
PageControl1: TPageControl;
Panel1: TPanel;
Panel2: TPanel;
PopupMenu1: TPopupMenu;
RichMemo1: TRichMemo;
RichMemo2: TRichMemo;
RxDBGrid1: TRxDBGrid;
RxDBGrid2: TRxDBGrid;
RxDBGrid3: TRxDBGrid;
Splitter1: TSplitter;
Splitter2: TSplitter;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
ZQKomOdebrane: TZQuery;
ZQKomWyslane: TZQuery;
ZQKomOdbiorcy: TZQuery;
ZUKomOdebrane: TZUpdateSQL;
procedure btnDrukujClick(Sender: TObject);
procedure btnDrukujZaznaczoneClick(Sender: TObject);
procedure btnNowaWiadomoscClick(Sender: TObject);
procedure btnOdpiszClick(Sender: TObject);
procedure btnOdswiezClick(Sender: TObject);
procedure DSKomOdebraneDataChange(Sender: TObject; Field: TField);
procedure DSKomWyslaneDataChange(Sender: TObject; Field: TField);
procedure FormCreate(Sender: TObject);
procedure MenuItemKopiujClick(Sender: TObject);
procedure RxDBGrid1DblClick(Sender: TObject);
private
public
end;
//var
// Komunikator: TKomunikator;
implementation
uses UKomunikatorNowaWiad;
{$R *.frm}
{ TKomunikator }
procedure TKomunikator.DSKomOdebraneDataChange(Sender: TObject; Field: TField);
var str: string;
begin
if IsDataSetEmpty(ZQKomOdebrane) then
begin
RichMemo1.Text:= '';
exit;
end;
if ZQKomOdebrane.FieldByName('dataOdebrania').IsNull then
begin
ZQKomOdebrane.DisableControls;
ZQKomOdebrane.Edit;
ZQKomOdebrane.FieldByName('dataOdebrania').AsDateTime:= Now();
ZQKomOdebrane.Post;
ZQKomOdebrane.EnableControls;
end;
str:= ZQKomOdebrane.FieldByName('komunikat').AsString;
if Copy(str,0,5) = '{\rtf' then
//if Pos('{\rtf', str)>0 then
RichMemo1.Rtf:= str
else
RichMemo1.Text:= str;
end;
procedure TKomunikator.btnOdswiezClick(Sender: TObject);
begin
ZQKomOdebrane.Close;
ZQKomOdebrane.Open;
ZQKomWyslane.Close;
ZQKomWyslane.Open;
end;
procedure TKomunikator.btnNowaWiadomoscClick(Sender: TObject);
begin
with TKomunikatorNowaWiad.Create(Self) do
begin
ShowModal;
Free;
ZQKomOdbiorcy.Close;
ZQKomWyslane.Close;
ZQKomWyslane.Open;
ZQKomOdbiorcy.Open;
end;
end;
procedure TKomunikator.btnDrukujClick(Sender: TObject);
var print_parameters: TPrintParams;
begin
print_parameters.JobTitle := 'OTIS';
print_parameters.Margins.Top := 10;
print_parameters.Margins.Bottom := 10;
print_parameters.Margins.Left := 10;
print_parameters.Margins.Right := 10;
print_parameters.SelStart := 0;
print_parameters.SelLength := 0;
if PageControl1.ActivePageIndex = 0 then
RichMemo1.Print( print_parameters )
else
RichMemo2.Print( print_parameters );
// frReport1.LoadFromFile(DM.Path_Raporty + 'pen_komunikat.lrf');
// DM.SetMemoReport(frReport1, 'Memo2', RichMemo1.Text );
// frReport1.ShowReport;
end;
procedure TKomunikator.btnDrukujZaznaczoneClick(Sender: TObject);
var print_parameters: TPrintParams;
begin
print_parameters.JobTitle := 'OTIS';
print_parameters.Margins.Top := 10;
print_parameters.Margins.Bottom := 10;
print_parameters.Margins.Left := 10;
print_parameters.Margins.Right := 10;
print_parameters.SelStart := RichMemo1.SelStart;
print_parameters.SelLength := RichMemo1.SelLength;
RichMemo1.Print( print_parameters );
end;
procedure TKomunikator.btnOdpiszClick(Sender: TObject);
begin
with TKomunikatorNowaWiad.Create(Self) do
begin
if PageControl1.ActivePageIndex = 0 then
OdpiszDo( ZQKomOdebrane.FieldByName('nadawca').AsString)
else
OdpiszDo( ZQKomOdbiorcy.FieldByName('odbiorca').AsString);
ShowModal;
Free;
ZQKomOdbiorcy.Close;
ZQKomWyslane.Close;
ZQKomWyslane.Open;
ZQKomOdbiorcy.Open;
end;
end;
procedure TKomunikator.DSKomWyslaneDataChange(Sender: TObject; Field: TField);
var str: string;
begin
if IsDataSetEmpty(ZQKomWyslane) then
begin
RichMemo2.Text:='';
exit;
end;
str:= ZQKomWyslane.FieldByName('komunikat').AsString;
if Copy(str,0,5) = '{\rtf' then
// if Pos('{\rtf', str)>0 then
RichMemo2.Rtf:= str
else
RichMemo2.Text:= str;
end;
procedure TKomunikator.FormCreate(Sender: TObject);
begin
ZQKomOdebrane.ParamByName('odbiorca').AsString := DM.login;
ZQKomOdebrane.Open;
ZQKomWyslane.ParamByName('nadawca').AsString := DM.login;
ZQKomWyslane.Open;
ZQKomOdbiorcy.Open;
end;
procedure TKomunikator.MenuItemKopiujClick(Sender: TObject);
begin
RichMemo1.CopyToClipboard;
end;
procedure TKomunikator.RxDBGrid1DblClick(Sender: TObject);
var id_tresc: integer;
ZQPom: TZQueryPom;
odbiorcy: string;
begin
if ZQKomOdebrane.IsEmpty then exit;
try
id_tresc:= ZQKomOdebrane.FieldByName('ID_tresc').AsInteger;
ZQPom:= TZQueryPom.Create(Self);
ZQPom.SQL.Text:= 'SELECT odb.ID_tresc, upr.Full_name FROM kom_odbiorcy odb'+
' LEFT OUTER JOIN uprawnienia upr ON (upr.user = odb.odbiorca)'+
' WHERE (odb.ID_tresc=:id_tresc)';
ZQPom.ParamByName('id_tresc').AsInteger:= id_tresc;
ZQPom.Open;
if ZQPom.IsEmpty then exit;
odbiorcy:= '';
while not ZQPom.EOF do
begin
if odbiorcy<>'' then odbiorcy+= '; ';
odbiorcy+= ZQPom.FieldByName('Full_name').AsString;
ZQPom.Next;
end;
finally
FreeAndNil(ZQPom);
end;
MessageDlg('Odbiorcy wiadomości:'+ LineEnding+ odbiorcy, mtInformation, [mbOK],0);
end;
end.