D7zzHanglin/A00标签打印/U_ClientPrintRmf.pas
DESKTOP-E401PHE\Administrator 0f9beb9b62 Apply new .gitignore
2025-09-22 15:07:39 +08:00

298 lines
7.6 KiB
ObjectPascal
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

unit U_ClientPrintRmf;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
cxEdit, DB, cxDBData, ToolWin, ComCtrls, cxGridCustomTableView,
cxGridTableView, cxGridDBTableView, cxGridLevel, cxClasses, cxControls,
cxGridCustomView, cxGrid, DBClient, ADODB, ImgList, StdCtrls, ExtCtrls,
cxTextEdit, cxGridCustomPopupMenu, cxGridPopupMenu, cxLookAndFeels,
cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu, RM_Common, RM_Class,
RM_GridReport, RM_Dataset, RM_E_llPDF, RM_BarCode, RM_e_Graphic, RM_e_Jpeg,
RM_e_Xls, cxContainer, cxMaskEdit, cxDropDownEdit, cxMRUEdit, dxSkinsCore,
dxSkinsDefaultPainters, cxProgressBar, cxButtons, RM_System;
type
TfrmClientPrintRmf = class(TForm)
ADOQueryTemp: TADOQuery;
ADOConnection1: TADOConnection;
ImageList1: TImageList;
RMDB_1: TRMDBDataSet;
RM1: TRMGridReport;
RMDB_2: TRMDBDataSet;
CDS_Label: TClientDataSet;
ADO_Prt: TADOQuery;
RMDB_3: TRMDBDataSet;
RMXLSExport1: TRMXLSExport;
RMJPEGExport1: TRMJPEGExport;
RMBarCodeObject1: TRMBarCodeObject;
ADOQueryCmd: TADOQuery;
ADO_While: TADOQuery;
RMDB_4: TRMDBDataSet;
RMDB_5: TRMDBDataSet;
ADOQueryReport: TADOQuery;
CDS_1: TClientDataSet;
CDS_2: TClientDataSet;
CDS_3: TClientDataSet;
CDS_4: TClientDataSet;
CDS_5: TClientDataSet;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure TV1DblClick(Sender: TObject);
private
IsDebug, FPreviewPrint, fIsPreview: Boolean;
FLMType, FLBName, FQrCodeField: string;
FExportFileType, FExportFileName: string;
SqlStr1, SqlStr2, SqlStr3, SqlStr4, SqlStr5: string;
FSuccessfulFun: string;
FparamBlclid: string;
procedure PrintReport();
procedure ExportReport();
procedure GetPrtData(Ado: TADOQuery; Cds: TClientDataSet; SqlStr: string);
procedure InitArgs();
{ Private declarations }
public
FPrintJson: PChar;
FJsonOut: PChar;
DConString, DCode, DName: string;
constructor Create(AOwner: TComponent; JsonArgs: PChar);
{ Public declarations }
end;
var
frmClientPrintRmf: TfrmClientPrintRmf;
implementation
uses
U_RTFun, superobject, U_QrCodeFun;
{$R *.dfm}
constructor TfrmClientPrintRmf.Create(AOwner: TComponent; JsonArgs: PChar);
begin
inherited Create(AOwner);
FPrintJson := JsonArgs;
end;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ά<EFBFBD><CEAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>
procedure TfrmClientPrintRmf.InitArgs;
var
JSONObject, item: ISuperObject;
jsonArray: TSuperArray;
i, loopCount: Integer;
begin
// <20><><EFBFBD><EFBFBD> JSON <20>ַ<EFBFBD><D6B7><EFBFBD>
JSONObject := SO(FPrintJson);
if JSONObject = nil then
begin
Application.MessageBox('PrintJson<6F><6E>ʽ<EFBFBD>쳣!', '<27><>ʾ', 0);
Exit;
end;
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>
fIsPreview := JSONObject.B['IsPreview'];
IsDebug := JSONObject.B['IsDebug'];
FSuccessfulFun := JSONObject.S['SuccessfulFun'];
FLMType := JSONObject.S['LMType'];
FPreviewPrint := JSONObject.B['PreviewPrint'];
FLBName := JSONObject.S['LBName'];
FExportFileType := JSONObject.S['ExportFileType'];
FExportFileName := JSONObject.S['ExportFileName'];
FQrCodeField := JSONObject.S['QrCodeField'];
DConString := JSONObject.S['DConString'];
DCode := JSONObject.S['DCode'];
DName := JSONObject.S['DName'];
// <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
if Trim(FExportFileName) = '' then
FExportFileName := FLBName;
// <20><>ʼ<EFBFBD><CABC> SQL <20>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SqlStr1 := '';
SqlStr2 := '';
SqlStr3 := '';
SqlStr4 := '';
SqlStr5 := '';
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> PrtArgs <20><><EFBFBD><EFBFBD>
jsonArray := JSONObject.A['PrtArgs'];
if Assigned(jsonArray) then
begin
// ȷ<><C8B7>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>5<EFBFBD><35>Ԫ<EFBFBD>أ<EFBFBD>
loopCount := jsonArray.Length;
for i := 0 to loopCount - 1 do
begin
item := jsonArray.O[i];
case i of
0:
SqlStr1 := item.S['SqlStr'];
1:
SqlStr2 := item.S['SqlStr'];
2:
SqlStr3 := item.S['SqlStr'];
3:
SqlStr4 := item.S['SqlStr'];
4:
SqlStr5 := item.S['SqlStr'];
end;
end;
end;
// <20><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>ť
// if FPreviewPrint then
// RM1.PreviewButtons := [rmpbZoom, rmpbLoad, rmpbSave, rmpbPrint, rmpbFind, rmpbPageSetup, rmpbExit, rmpbSaveToXLS, rmpbExport, rmpbNavigator]
// else
// RM1.PreviewButtons := [rmpbZoom, rmpbLoad, rmpbSave, rmpbFind, rmpbPageSetup, rmpbExit, rmpbSaveToXLS, rmpbExport, rmpbNavigator];
end;
procedure TfrmClientPrintRmf.GetPrtData(Ado: TADOQuery; Cds: TClientDataSet; SqlStr: string);
begin
if Trim(SqlStr) = '' then
Exit;
// ִ<><D6B4>ADO<44><4F>ѯ
with Ado do
begin
Close;
SQL.Clear;
SQL.Add(SqlStr);
if IsDebug then
ShowMessage(sql.Text);
Open;
end;
IintCDS(Ado, Cds);
SetQrCodePath(Cds, FQrCodeField);
end;
procedure TfrmClientPrintRmf.ExportReport();
var
fPrintFile, fExportPath: string;
begin
fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + FLBName + '.rmf';
if FileExists(fPrintFile) then
begin
RM1.LoadFromFile(fPrintFile);
RMVariables['LBPrtCode'] := dcode;
RMVariables['LBPrtName'] := dname;
fExportPath := ExtractFilePath(Application.ExeName) + FExportFileName + '.' + FExportFileType;
if not DirectoryExists(ExtractFileDir(fExportPath)) then
CreateDir(ExtractFileDir(fExportPath));
RM1.PrepareReport; //ֱ<>ӵ<EFBFBD><D3B5><EFBFBD>
// if FExportFileType = 'pdf' then
// RM1.ExportTo(RMllPDFExport1, fExportPath)
// else
RM1.ExportTo(RMXLSExport1, fExportPath);
FJsonOut := '{"success":true,"message":"<22><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>!"}';
end
else
begin
FJsonOut := '{"success":false,"message":"<22><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>û<EFBFBD>ҵ<EFBFBD>!"}';
end;
end;
procedure TfrmClientPrintRmf.PrintReport();
var
fPrintFile: string;
begin
fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + FLBName + '.rmf';
if FileExists(fPrintFile) then
begin
RM1.LoadFromFile(fPrintFile);
// RM1.DefaultCopies := StrToIntDef(ComboBox1.Text, 1);
RMVariables['LBPrtCode'] := dcode;
RMVariables['LBPrtName'] := dname;
if fIsPreview then
RM1.ShowReport
else
RM1.PrintReport;
FJsonOut := '{"success":true,"message":"<22><>ӡ<EFBFBD>ɹ<EFBFBD>!"}';
end
else
begin
FJsonOut := '{"success":false,"message":"<22><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>û<EFBFBD>ҵ<EFBFBD>!"}';
end;
end;
procedure TfrmClientPrintRmf.FormCreate(Sender: TObject);
begin
FPreviewPrint := True;
InitArgs();
with ADOConnection1 do
begin
Connected := false;
ConnectionString := DConString;
Connected := true;
end;
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֲ<EFBFBD><D6B2>
ExportFtErpFile(FLBName + '.rmf', ADOQueryReport);
EnsureQrCodeDirectory();
ClearQrCodeDirectory();
end;
procedure TfrmClientPrintRmf.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := cafree;
end;
procedure TfrmClientPrintRmf.FormShow(Sender: TObject);
begin
if flbName = '' then
begin
FJsonOut := '{"success":false,"message":"δ<><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡ<EFBFBD><D3A1>ǩ!"}';
self.Close;
exit;
end;
if SqlStr1 = '' then
begin
FJsonOut := '{"success":false,"message":"δ<><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>!"}';
self.Close;
exit;
end;
GetPrtData(ADO_Prt, CDS_1, SqlStr1);
GetPrtData(ADO_Prt, CDS_2, SqlStr2);
GetPrtData(ADO_Prt, CDS_3, SqlStr3);
GetPrtData(ADO_Prt, CDS_4, SqlStr4);
GetPrtData(ADO_Prt, CDS_5, SqlStr5);
if FExportFileType = '' then
begin
PrintReport();
end
else
ExportReport();
self.Close;
end;
procedure TfrmClientPrintRmf.TV1DblClick(Sender: TObject);
begin
ModalResult := 1;
end;
procedure TfrmClientPrintRmf.FormDestroy(Sender: TObject);
begin
frmClientPrintRmf := nil;
end;
end.