-
Notifications
You must be signed in to change notification settings - Fork 1
/
WispReportEditor.pas
215 lines (188 loc) · 5.13 KB
/
WispReportEditor.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
unit WispReportEditor;
interface
uses
Dialogs,
Forms,
StdCtrls,
ExtCtrls,
Graphics,
Controls,
Classes,
SysUtils,
ZDataset,
cxTextEdit,
cxButtons,
WispEditBox,
WispDatePicker,
WispLookUpComboBox,
WispEntity,
WispEntityGrid,
WispArrayTools,
WispEntityManager,
WispQueryTools,
WispDbConnection,
WispTimeTools,
WispAccesManager,
WispCheckBox,
WispVisualComponent,
WispTimePicker,
WispStrTools,
WispMathTools,
cxPC,
Messages,
Windows,
frxClass,
frxDesgn,
frxDBSet,
DB,
Printers,
WispStyleManager,
WispConstantManager,
WispImageTools,
WispButton;
Const
EdtWidth = 320;
type
TReportEditor = Class(TObject)
private
// Entity Editor
CurrentID: String;
Report: TFrxReport;
ReportDesigner: TfrxDesigner;
TmpQ: TZQuery;
BoxEntityEditor: TScrollBox;
BtnOk: TcxButton;
Tab: TcxTabSheet;
protected
public
Constructor Create(ParamOwner: TComponent; ParamParent: TWinControl;
ParamId: string = '0');
procedure Save;
procedure CloseDesigner;
procedure TabOnShow(Sender: TObject);
end;
implementation
uses WispMainMenuManager;
// =============================================================================
Constructor TReportEditor.Create(ParamOwner: TComponent;
ParamParent: TWinControl; ParamId: string = '0');
var
I, TmpI, H, YOffset: integer;
S, TmpName: string;
FrxDataSet: TFrxDBDataSet;
DataBand: TfrxMasterData;
Band: TfrxBand;
GroupFooter: TfrxGroupFooter;
Stream: TStream;
Page: TfrxReportPage;
TmpBoolean: Boolean;
begin
// ...
CurrentID := ParamId;
// The editor is owned and drawn on a tab
Tab := TcxTabSheet(ParamOwner); // So basicly tab is ParamOwner
Tab.OnShow := Self.TabOnShow;
// Create the entity editor form
BoxEntityEditor := TScrollBox.Create(ParamOwner);
with BoxEntityEditor do
begin
Width := 320;
Height := H;
BorderStyle := bsNone;
Parent := ParamParent;
Color := clGray;
Align := alClient;
Global_Singleton_MainMenuManager.CurrentFocusedScrollBox :=
Self.BoxEntityEditor;
end;
Report := TFrxReport.Create(ParamOwner);
TmpQ := OpenQuery(Global_Singleton_DbConnection,
'SELECT NAME,REPORT FROM wisp_reports WHERE ID=' + ParamId + ';').ZQuery;
TmpName := TmpQ.FieldByName('NAME').AsString;
Stream := TmpQ.CreateBlobStream(TmpQ.FieldByName('REPORT'), bmRead);
Stream.Position := 0;
Report.LoadFromStream(Stream);
TmpQ.Free;
S := Global_Singleton_EntityManager.GetEntityByName(TmpName)
.GetInstanceQueryString('0');
TmpQ := OpenQuery(Global_Singleton_DbConnection, S).ZQuery;
FrxDataSet := TFrxDBDataSet.Create(Global_Singleton_DbConnection);
FrxDataSet.DataSet := TmpQ;
FrxDataSet.UserName := 'Report';
// FrxDataSet.Enabled := TRUE;
if Report.DataSets.Count = 0 then
begin
Report.DataSets.Add(FrxDataSet);
Report.DataSets.Items[0].DataSet.Enabled := TRUE;
Report.DataSets.Items[0].DataSet.First;
end
else if Report.DataSets.Count = 1 then
begin
Report.DataSets.Items[0].DataSet := FrxDataSet;
Report.DataSets.Items[0].DataSet.First;
end;
if Report.PagesCount = 1 Then
begin
Page := TfrxReportPage.Create(Report);
Page.CreateUniqueName;
Page.SetDefaults;
Page.PaperSize := DMPAPER_LETTER;
// Page.Orientation := poLandscape;
// Add report title band
Band := TfrxReportTitle.Create(Page);
Band.CreateUniqueName;
Band.Top := 0;
Band.Height := 20;
// Add masterdata band
DataBand := TfrxMasterData.Create(Page);
DataBand.CreateUniqueName;
DataBand.DataSet := FrxDataSet;
DataBand.Top := 30;
DataBand.Height := 20;
// Group footer creation
{
GroupFooter := TfrxGroupFooter.Create(Page);
GroupFooter.Parent := Page;
with GroupFooter do
begin
CreateUniqueName;
// SetBounds(0, 0, Page.Width - 75.6, 20);
Top := 60;
Height := 20;
end;
}
end;
Report.DesignReportInPanel(BoxEntityEditor);
// ...
BoxEntityEditor.Show;
// ...
// Report.DesignReportInPanel(BoxEntityEditor);
end;
// =============================================================================
procedure TReportEditor.Save;
var
Stream: TMemoryStream;
// FileStream: TFileStream;
begin
Stream := TMemoryStream.Create;
Report.SaveToStream(Stream);
Stream.Seek(0, soFromBeginning);
TmpQ.SQL.Clear;
TmpQ.SQL.Text := 'UPDATE wisp_reports SET REPORT=:blobparam WHERE ID=' +
CurrentID + ';';
TmpQ.ParamByName('blobparam').LoadFromStream(Stream, ftBlob);
TmpQ.ExecSQL;
end;
// =============================================================================
procedure TReportEditor.CloseDesigner;
begin
Report.Designer.Modified := FALSE;
Report.Designer.Close;
end;
// =============================================================================
procedure TReportEditor.TabOnShow(Sender: TObject);
begin
Global_Singleton_MainMenuManager.CurrentFocusedScrollBox :=
Self.BoxEntityEditor;
end;
end.