📄 dxjs_reportworks.pas
字号:
////////////////////////////////////////////////////////////////////////////
// Component: TDXJS_REPORTWORKS
// Author: Alexander Baranovsky (ab@virtlabor.donbass.com)
// G.E. Ozz Nixon Jr. (staff@bpdx.com)
// ========================================================================
// Source Owner: DX, Inc. 2002, 2004
// Copyright: All code is the property of DX, Inc. Licensed for
// resell by Brain Patchwork DX (tm) and part of the
// DX (r) product lines, which are (c) 1999-2002
// DX, Inc. Source may not be distributed without
// written permission from both Brain Patchwork DX,
// and DX, Inc.
// License: (Reminder), None of this code can be added to other
// developer products without permission. This includes
// but not limited to DCU's, DCP's, DLL's, OCX's, or
// any other form of merging our technologies. All of
// your products released to a public consumer be it
// shareware, freeware, commercial, etc. must contain a
// license notification somewhere visible in the
// application.
// Code Version: (3rd Generation)
// ========================================================================
// Description: wrapper around the freeware printer component called
// REPORTWORKS. REPORTWORKS appears to be a dead product now, but we feel
// the way the author made TPrinter more useful was a good layer for us
// to show people how to make a "scriptable reporting" component.
// ========================================================================
////////////////////////////////////////////////////////////////////////////
unit DXJS_REPORTWORKS;
interface
{$I DXJavaScript.def}
uses
{$ifdef VARIANTS}
variants,
{$endif}
db,
Printers,
RptWrks2,
DXJavaScript,
SysUtils,
Classes,
Forms;
type
TScriptSQLEvent = procedure(const SQL:String) of object;
TScriptStringPromptEvent = procedure(const WhichType,Caption:String) of object;
TDXJS_REPORTWORKS = class(TComponent)
private
{ Private declarations }
JavaScript:TDXJavaScript;
fParent:TForm;
fReportWorks:TReportWorks;
fRefresh:TNotifyEvent;
fGenerate:TNotifyEvent;
fPreview:Boolean;
fOnSetSQL:TScriptSQLEvent;
fDataSource:TDataSource;
fStartDate:TDateTime;
fEndDate:TDateTime;
fOnDateRange:TNotifyEvent;
fStringPrompt:String;
fOnStringPrompt:TScriptStringPromptEvent;
fCanPrompt:Boolean;
fFirstPage:Integer;
fLastPage:Integer;
protected
{ Protected declarations }
Function getCurrentPage:Integer;
Procedure setCurrentPage(value:Integer);
Procedure JSBeforeRun(Sender:TObject);
Procedure JSAfterRun(Sender:TObject);
public
{ Public declarations }
fWantedFields:TStringList;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure RunScript(Script:TStream);
Procedure GotoFirstPage;
Procedure GotoPriorPage;
Procedure GotoNextPage;
Procedure GotoLastPage;
Function TotalPages:Integer;
Procedure SetZoom(Percent:Integer);
Procedure DatabaseJustOpened;
Procedure DatabaseJustScrolled;
Procedure ReportDone;
Procedure SetDateRange(StartDate,EndDate:TDateTime);
Procedure SetStringPrompt(S:String);
published
{ Published declarations }
property DataSource:TDataSource read fDataSource write fDataSource;
property Preview:Boolean read fPreview write fPreview;
property CurrentPage:Integer read getCurrentPage write setCurrentPage;
property OnRefresh:TNotifyEvent read fRefresh write fRefresh;
property OnSetSQL:TScriptSQLEvent read fOnSetSQL write fOnSetSQL;
property OnGenerate:TNotifyEvent read fGenerate write fGenerate;
property OnDateRange:TNotifyEvent read fOnDateRange write fOnDateRange;
property OnStringPrompt:TScriptStringPromptEvent read fOnStringPrompt write fOnStringPrompt;
property PageToPrintFirst:Integer read fFirstPage write fFirstPage;
property PageToPrintLast:Integer read fLastPage write fLastPage;
end;
procedure Register;
implementation
Uses
DXString,
Graphics;
Var
PublicAccessToReportWorks:TReportWorks;
This:TDXJS_REPORTWORKS;
WantedFields:TStringList;
FieldValues:TStringList;
procedure Register;
begin
RegisterComponents('BPDX JavaScript', [TDXJS_REPORTWORKS]);
end;
// Parameters from the Script must be:
// TITLE:String - Shown by Print Server for this Report
// LANDSCAPE:Boolean - True=Landscape, False=Portrait
// *OPTIONAL PARAMETER:
// FONTNAME:String - Defaults to Courier
// FONTSIZE:Integer - Defaults to 8
function __InitializeEngine(const Parameters: array of Variant): Variant;
begin
// Default Values
PublicAccessToReportWorks.TextStyle:=tsTransparent;
PublicAccessToReportWorks.PageBorder:=True;
PublicAccessToReportWorks.LineMeasure:=lmLinesPerInch;
PublicAccessToReportWorks.Units:=uInch;
PublicAccessToReportWorks.LinesPerInch:=6;
// Scriptable Values
PublicAccessToReportWorks.Title:=TDXJavaScript.ToString(Parameters[0]);
Case TDXJavaScript.ToInteger(Parameters[1]) of
0:try
PublicAccessToReportWorks.Orientation:=poLandScape;
except
ShowMessageWindow('','No default printer found!');
end;
1:try
PublicAccessToReportWorks.Orientation:=poPortrait;
except
ShowMessageWindow('','No default printer found!');
end;
End;
If Length(Parameters)>2 then Begin
PublicAccessToReportWorks.SetFont(TDXJavaScript.ToString(Parameters[2]),
TDXJavaScript.ToInteger(Parameters[3]));
End
Else Begin
PublicAccessToReportWorks.SetFont('Arial',10);
End;
PublicAccessToReportWorks.StartDoc;
end;
function __DrawLine(const Parameters: array of Variant): Variant;
begin
PublicAccessToReportWorks.DrawLine;
End;
function __NextLine(const Parameters: array of Variant): Variant;
begin
PublicAccessToReportWorks.NextLine;
End;
function __FontBold(const Parameters: array of Variant): Variant;
begin
PublicAccessToReportWorks.FontBold;
End;
function __FontItalic(const Parameters: array of Variant): Variant;
begin
PublicAccessToReportWorks.FontItalic;
End;
function __FontUnderline(const Parameters: array of Variant): Variant;
begin
PublicAccessToReportWorks.FontUnderline;
End;
function __FontRegular(const Parameters: array of Variant): Variant;
begin
PublicAccessToReportWorks.FontRegular;
End;
function __Print(const Parameters: array of Variant): Variant;
begin
PublicAccessToReportWorks.Print(TDXJavaScript.ToString(Parameters[0]));
End;
function __PrintLn(const Parameters: array of Variant): Variant;
begin
PublicAccessToReportWorks.PrintLine(TDXJavaScript.ToString(Parameters[0]));
End;
function __PrintCenter(const Parameters: array of Variant): Variant;
begin
PublicAccessToReportWorks.PrintCenter(TDXJavaScript.ToString(Parameters[0]));
End;
function __ShadeLine(const Parameters: array of Variant): Variant;
begin
PublicAccessToReportWorks.ShadeLine($00E0E0E0);
End;
function __ResetColumns(const Parameters: array of Variant): Variant;
begin
PublicAccessToReportWorks.ClearTabs;
End;
function __NewColumn(const Parameters: array of Variant): Variant;
begin
If Length(Parameters)=2 then Begin
Case TDXJavaScript.ToInteger(Parameters[1]) of
0:PublicAccessToReportWorks.SetTab(
TDXJavaScript.ToNumber(Parameters[0]),jLeft);
1:PublicAccessToReportWorks.SetTab(
TDXJavaScript.ToNumber(Parameters[0]),jCenter);
2:PublicAccessToReportWorks.SetTab(
TDXJavaScript.ToNumber(Parameters[0]),jRight);
End;
End;
End;
function __PrintColumn(const Parameters: array of Variant): Variant;
begin
If Length(Parameters)=2 then Begin
PublicAccessToReportWorks.PrintTab(
TDXJavaScript.ToInteger(Parameters[0]),
TDXJavaScript.ToString(Parameters[1]));
End;
End;
function __NewPage(const Parameters: array of Variant): Variant;
begin
PublicAccessToReportWorks.NewPage;
End;
function __IsPageEnd(const Parameters: array of Variant): Variant;
begin
Result:=PublicAccessToReportWorks.IsPageEnd;
End;
function __GoToPageTop(const Parameters: array of Variant): Variant;
begin
PublicAccessToReportWorks.GoToPageTop;
End;
function __GoToPageBottom(const Parameters: array of Variant): Variant;
begin
PublicAccessToReportWorks.GoToPageBottom;
End;
function __PreviousLine(const Parameters: array of Variant): Variant;
begin
PublicAccessToReportWorks.PreviousLine;
End;
function __LineNumber(const Parameters: array of Variant): Variant;
begin
Result:=PublicAccessToReportWorks.LineNum;
End;
function __PageNumber(const Parameters: array of Variant): Variant;
begin
Result:=PublicAccessToReportWorks.PageNum;
End;
function __PageTotal(const Parameters: array of Variant): Variant;
begin
Result:=PublicAccessToReportWorks.PageTotal;
End;
function __GoToTab(const Parameters: array of Variant): Variant;
begin
PublicAccessToReportWorks.GoToTab(TDXJavaScript.ToInteger(Parameters[0]));
End;
function __DeinitializeEngine(const Parameters: array of Variant): Variant;
begin
PublicAccessToReportWorks.EndDoc;
End;
function __SetSQL(const Parameters: array of Variant): Variant;
begin
PublicAccessToReportWorks.Hint:=TDXJavaScript.ToString(Parameters[0]);
End;
function __SetFields(const Parameters: array of Variant): Variant;
Var
Loop:Integer;
begin
WantedFields.Clear;
For Loop:=1 to Length(Parameters) do
WantedFields.Add(TDXJavaScript.ToString(Parameters[Loop-1]));
End;
function __GetField(const Parameters: array of Variant): Variant;
Var
Loop:Integer;
begin
Result:='';
For Loop:=1 to WantedFields.Count do
If WantedFields[Loop-1]=TDXJavaScript.ToString(Parameters[0]) then
Result:=FieldValues[Loop-1];
End;
function __DatePrompt(const Parameters: array of Variant): Variant;
begin
If This.fCanPrompt then
If Assigned(This.fOnDateRange) then
This.fOnDateRange(This);
End;
function __StartDate(const Parameters: array of Variant): Variant;
begin
Result:=DateToStr(This.fStartDate);
End;
function __EndDate(const Parameters: array of Variant): Variant;
begin
Result:=DateToStr(This.fEndDate);
End;
function __StringPrompt(const Parameters: array of Variant): Variant;
begin
Result:=This.fStringPrompt;
If This.fCanPrompt then Begin
If Assigned(This.fOnStringPrompt) then Begin
This.fOnStringPrompt(TDXJavaScript.ToString(Parameters[0]),
TDXJavaScript.ToString(Parameters[1]));
Result:=This.fStringPrompt;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -