D7myYunxiang/A00标签打印/U_LabelPrint.pas

458 lines
12 KiB
ObjectPascal
Raw Permalink Normal View History

2025-08-07 11:08:39 +08:00
unit U_LabelPrint;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
2025-10-29 09:55:52 +08:00
IniFiles, Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
cxDataStorage, Printers, 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,
dxSkinBlack, dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee,
dxSkinDarkRoom, dxSkinDarkSide, dxSkinDevExpressDarkStyle,
dxSkinDevExpressStyle, dxSkinFoggy, dxSkinGlassOceans, dxSkinHighContrast,
dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky,
dxSkinMcSkin, dxSkinMetropolis, dxSkinMetropolisDark, dxSkinMoneyTwins,
dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinPumpkin, dxSkinSeven,
dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus, dxSkinSilver,
dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008, dxSkinTheAsphaltWorld,
dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue, RM_System,
Buttons;
2025-08-07 11:08:39 +08:00
type
TfrmLabelPrint = class(TForm)
ADOQueryTemp: TADOQuery;
ADOConnection1: TADOConnection;
Panel1: TPanel;
ImageList1: TImageList;
RMDB_1: TRMDBDataSet;
RM1: TRMGridReport;
RMDB_2: TRMDBDataSet;
CDS_Label: TClientDataSet;
2025-08-30 14:29:28 +08:00
ADO_Prt: TADOQuery;
2025-08-07 11:08:39 +08:00
btnShow: TSpeedButton;
RMDB_3: TRMDBDataSet;
RMXLSExport1: TRMXLSExport;
RMJPEGExport1: TRMJPEGExport;
RMBarCodeObject1: TRMBarCodeObject;
CheckBox1: TCheckBox;
Label1: TLabel;
cbbLab: TcxMRUEdit;
CheckBox2: TCheckBox;
ADOQueryCmd: TADOQuery;
ADO_While: TADOQuery;
ComboBox1: TcxComboBox;
btnPrint: TSpeedButton;
RMDB_4: TRMDBDataSet;
RMDB_5: TRMDBDataSet;
2025-08-30 14:29:28 +08:00
CDS_1: TClientDataSet;
CDS_2: TClientDataSet;
CDS_3: TClientDataSet;
CDS_4: TClientDataSet;
CDS_5: TClientDataSet;
2025-10-21 14:07:46 +08:00
ComboBox_Print: TComboBox;
2025-08-07 11:08:39 +08:00
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure TV1DblClick(Sender: TObject);
procedure btnPrintClick(Sender: TObject);
procedure btnShowClick(Sender: TObject);
procedure cbbLabPropertiesButtonClick(Sender: TObject);
private
IsDebug, FPreviewPrint, IsSql1, IsSql2, IsSql3, IsSql4, IsSql5: Boolean;
2025-10-29 09:55:52 +08:00
FLMType, FQrCodeField, PrintSetFileName: string;
2025-08-07 11:08:39 +08:00
FFiltration1, FFiltration2, FFiltration3, FFiltration4, FFiltration5: string;
FSuccessfulFun: string;
FparamBlclid: string;
procedure InitGrid();
procedure PrintLabel(MIsShow: Boolean);
2025-08-30 14:29:28 +08:00
procedure GetPrtData(Ado: TADOQuery; Cds: TClientDataSet; IsSql: Boolean; LMSql, FFiltration: string);
2025-08-07 11:08:39 +08:00
procedure InitArgs();
{ Private declarations }
public
FPrintJson: PChar;
FJsonOut: PChar;
2025-08-07 12:49:00 +08:00
DConString, DCode, DName: string;
2025-08-07 11:08:39 +08:00
constructor Create(AOwner: TComponent; JsonArgs: PChar);
2025-10-29 09:55:52 +08:00
procedure WriteINIFile();
procedure ReadINIFile();
2025-08-07 11:08:39 +08:00
{ Public declarations }
end;
var
frmLabelPrint: TfrmLabelPrint;
implementation
uses
2025-08-30 14:29:28 +08:00
U_RTFun, U_LabelMapSet, superobject, U_QrCodeFun;
2025-08-07 11:08:39 +08:00
{$R *.dfm}
2025-10-29 09:55:52 +08:00
procedure TfrmLabelPrint.ReadINIFile();
var
programIni: Tinifile; //<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
begin
PrintSetFileName := ExtractFilePath(Paramstr(0)) + '/printset.INI';
programIni := Tinifile.create(PrintSetFileName);
ComboBox_Print.ItemIndex := strtoint(programIni.ReadString(FLMType, 'dyj', '0'));
ComboBox1.ItemIndex := strtoint(programIni.ReadString(FLMType, 'bqfs', '1'));
programIni.Free;
end;
//////////////////////////////////////////////////////////////////
//д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>INI<4E>ļ<EFBFBD>
//<2F><><EFBFBD><EFBFBD>
//////////////////////////////////////////////////////////////////
procedure TfrmLabelPrint.WriteINIFile();
var
programIni: Tinifile; //<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
begin
PrintSetFileName := ExtractFilePath(Paramstr(0)) + '/printset.INI';
programIni := Tinifile.create(PrintSetFileName);
programIni.WriteString(FLMType, 'dyj', IntToStr(ComboBox_Print.ItemIndex));
programIni.WriteString(FLMType, 'bqfs', IntToStr(ComboBox1.ItemIndex));
programIni.Free;
end;
2025-08-07 11:08:39 +08:00
constructor TfrmLabelPrint.Create(AOwner: TComponent; JsonArgs: PChar);
begin
inherited Create(AOwner);
FPrintJson := JsonArgs;
// fFormID := mFormID;
// fBLCLID := recid;
// if CopyNumber > 0 then
// fCopyNumber := CopyNumber
// else
// fCopyNumber := 1;
// fIsPreview := IsPreview;
// fprinterIndex := printerIndex;
// fexportFileType := exportFileType;
end;
procedure TfrmLabelPrint.InitArgs;
var
JSONObject, item: ISuperObject; // SuperObject <20>ӿ<EFBFBD><D3BF><EFBFBD><EFBFBD><EFBFBD>
jsonArray: TSuperArray;
i: 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>
IsDebug := JSONObject.B['IsDebug'];
FSuccessfulFun := JSONObject.S['SuccessfulFun'];
FLMType := JSONObject.S['LMType'];
FPreviewPrint := JSONObject.B['PreviewPrint'];
2025-08-30 14:29:28 +08:00
FQrCodeField := JSONObject.S['QrCodeField'];
2025-08-07 12:49:00 +08:00
DConString := JSONObject.S['DConString'];
DCode := JSONObject.S['DCode'];
DName := JSONObject.S['DName'];
2025-08-07 11:08:39 +08:00
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
jsonArray := JSONObject.A['PrtArgs'];
if jsonArray = nil then // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E9B2BB><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>
begin
Application.MessageBox('PrtArgs<67><73><EFBFBD><EFBFBD>ȱʧ!', '<27><>ʾ', 0);
Exit;
end;
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ
FFiltration1 := '';
FFiltration2 := '';
FFiltration3 := '';
FFiltration4 := '';
FFiltration5 := '';
// <20><><EFBFBD><EFBFBD>JSON<4F><4E><EFBFBD><EFBFBD><E9A3A8><EFBFBD><EFBFBD><E0B4A6>5<EFBFBD><35>Ԫ<EFBFBD>أ<EFBFBD>
for i := 0 to jsonArray.Length - 1 do
begin
item := jsonArray.O[i];
case i of
0:
begin
IsSql1 := item.B['IsSql'];
FFiltration1 := item.S['Filtration'];
end;
1:
begin
IsSql2 := item.B['IsSql'];
FFiltration2 := item.S['Filtration'];
end;
2:
begin
IsSql3 := item.B['IsSql'];
FFiltration3 := item.S['Filtration'];
end;
3:
begin
IsSql4 := item.B['IsSql'];
FFiltration4 := item.S['Filtration'];
end;
4:
begin
IsSql5 := item.B['IsSql'];
FFiltration5 := item.S['Filtration'];
end;
end;
end;
// <20><>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD>߼<EFBFBD>
if Trim(FFiltration2) = '' then
begin
IsSql2 := IsSql1;
FFiltration2 := FFiltration1;
end;
if Trim(FFiltration3) = '' then
begin
IsSql3 := IsSql1;
FFiltration3 := FFiltration1;
end;
if Trim(FFiltration4) = '' then
begin
IsSql4 := IsSql1;
FFiltration4 := FFiltration1;
end;
if Trim(FFiltration5) = '' then
begin
IsSql5 := IsSql1;
FFiltration5 := FFiltration1;
end;
end;
2025-08-30 14:29:28 +08:00
procedure TfrmLabelPrint.GetPrtData(Ado: TADOQuery; Cds: TClientDataSet; IsSql: Boolean; LMSql, FFiltration: string);
2025-08-07 11:08:39 +08:00
begin
with Ado do
begin
Close;
sql.Clear;
if IsSql then
begin
sql.add('exec ' + trim(CDS_Label.fieldbyname(LMSql).AsString));
sql.add(FFiltration);
end
else
begin
sql.add('exec ' + trim(CDS_Label.fieldbyname(LMSql).AsString) + ' ' + quotedstr(Trim(FFiltration)));
end;
if IsDebug then
ShowMessage(sql.Text);
Open;
end;
2025-08-30 14:29:28 +08:00
IintCDS(Ado, Cds);
SetQrCodePath(Cds, FQrCodeField);
2025-08-07 11:08:39 +08:00
end;
procedure TfrmLabelPrint.PrintLabel(MIsShow: Boolean);
var
fPrintFile, fPrintFile10, FMainID, LBName: string;
begin
if CDS_Label.IsEmpty then
begin
Application.MessageBox(PChar('<27><><EFBFBD><EFBFBD>' + FLMType + <><C3BB><EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD>ǩ!'), '<27><>ʾ', 0);
Exit;
end;
RMJPEGExport1.ShowDialog := CheckBox2.Checked;
RMXLSExport1.ShowDialog := CheckBox2.Checked;
RM1.ShowPrintDialog := CheckBox1.Checked;
LBName := cbbLab.text;
ExportFtErpFile(LBName + '.rmf', ADOQueryTemp);
if CDS_Label.Locate('LMName', LBName, []) then
begin
if trim(CDS_Label.fieldbyname('LMSql1').AsString) <> '' then
2025-08-30 14:29:28 +08:00
GetPrtData(ADO_Prt, CDS_1, IsSql1, 'LMSql1', FFiltration1);
2025-08-07 11:08:39 +08:00
if trim(CDS_Label.fieldbyname('LMSql2').AsString) <> '' then
2025-08-30 14:29:28 +08:00
GetPrtData(ADO_Prt, CDS_2, IsSql2, 'LMSql2', FFiltration2);
2025-08-07 11:08:39 +08:00
if trim(CDS_Label.fieldbyname('LMSql3').AsString) <> '' then
2025-08-30 14:29:28 +08:00
GetPrtData(ADO_Prt, CDS_3, IsSql3, 'LMSql3', FFiltration3);
2025-08-07 11:08:39 +08:00
if trim(CDS_Label.fieldbyname('LMSql4').AsString) <> '' then
2025-08-30 14:29:28 +08:00
GetPrtData(ADO_Prt, CDS_4, IsSql4, 'LMSql4', FFiltration4);
2025-08-07 11:08:39 +08:00
if trim(CDS_Label.fieldbyname('LMSql5').AsString) <> '' then
2025-08-30 14:29:28 +08:00
GetPrtData(ADO_Prt, CDS_5, IsSql5, 'LMSql5', FFiltration5);
2025-08-07 11:08:39 +08:00
end;
fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + LBName + '.rmf';
if FileExists(fPrintFile) then
begin
RM1.LoadFromFile(fPrintFile);
RM1.DefaultCopies := StrToIntDef(ComboBox1.Text, 1);
RMVariables['LBPrtCode'] := dcode;
RMVariables['LBPrtName'] := dname;
if MIsShow then
RM1.ShowReport
else
2025-10-21 14:07:46 +08:00
RM1.PrintReportL(ComboBox_Print.Text);
;
2025-08-07 11:08:39 +08:00
end
else
begin
Application.MessageBox(PChar(<><C3BB><EFBFBD><EFBFBD>' + fPrintFile), '<27><>ʾ', 0);
end;
end;
procedure TfrmLabelPrint.FormCreate(Sender: TObject);
begin
FPreviewPrint := True;
2025-10-21 14:07:46 +08:00
ComboBox_Print.Items.Assign(Printer.Printers);
// ComboBox2.ItemIndex := 0; //ָ<><D6B8><EFBFBD><EFBFBD>һ̨<D2BB><CCA8>ӡ<EFBFBD><D3A1>
ComboBox_Print.Items.Add(<>ϴ<EFBFBD>ӡ<EFBFBD><D3A1>');
ComboBox_Print.ItemIndex := Self.ComboBox_Print.Items.IndexOf(trim(<>ϴ<EFBFBD>ӡ<EFBFBD><D3A1>'));
2025-08-07 12:49:00 +08:00
InitArgs();
with ADOConnection1 do
begin
Connected := false;
ConnectionString := DConString;
Connected := true;
2025-08-07 11:08:39 +08:00
end;
2025-08-30 14:29:28 +08:00
EnsureQrCodeDirectory();
ClearQrCodeDirectory();
2025-08-07 11:08:39 +08:00
end;
procedure TfrmLabelPrint.btnPrintClick(Sender: TObject);
begin
PrintLabel(False);
2025-08-07 12:49:00 +08:00
FJsonOut := '{"success":true}';
2025-08-07 11:08:39 +08:00
ModalResult := 1;
2025-10-29 09:55:52 +08:00
WriteINIFile();
2025-08-07 11:08:39 +08:00
end;
procedure TfrmLabelPrint.btnShowClick(Sender: TObject);
begin
PrintLabel(true);
2025-08-07 12:49:00 +08:00
FJsonOut := '{"success":true,"ShowFlag":true}';
2025-08-07 11:08:39 +08:00
end;
procedure TfrmLabelPrint.cbbLabPropertiesButtonClick(Sender: TObject);
begin
try
frmLabelMapSet := TfrmLabelMapSet.Create(Application);
with frmLabelMapSet do
begin
IsSql1 := self.IsSql1;
IsSql2 := self.IsSql2;
IsSql3 := self.IsSql3;
IsSql4 := self.IsSql4;
IsSql5 := self.IsSql5;
FFiltration1 := self.FFiltration1;
FFiltration2 := self.FFiltration2;
FFiltration3 := self.FFiltration3;
FFiltration4 := self.FFiltration4;
FFiltration5 := self.FFiltration5;
FLMType := self.FLMType;
if ShowModal = 1 then
begin
Self.InitGrid();
end;
end;
finally
frmLabelMapSet.Free;
end;
end;
procedure TfrmLabelPrint.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := cahide;
end;
procedure TfrmLabelPrint.InitGrid();
begin
with ADOQueryTemp do
begin
close;
sql.Clear;
sql.Add('select LMName name from BS_Label_Map where LMType=' + QuotedStr(TRIM(FLMType)));
sql.Add(' order by SerialNo ');
Open;
if isEmpty then
begin
exit;
end;
cbbLab.Properties.LookupItems.Clear;
while not Eof do
begin
cbbLab.Properties.LookupItems.Add(Trim(fieldByName('Name').AsString));
Next;
end;
cbbLab.ItemIndex := 0;
end;
with ADOQueryTemp do
begin
Filtered := False;
Close;
sql.Clear;
Sql.Add('select * from BS_Label_Map where LMType=' + QuotedStr(TRIM(FLMType)));
Open;
end;
SCreateCDS20(ADOQueryTemp, CDS_Label);
SInitCDSData20(ADOQueryTemp, CDS_Label);
if CDS_Label.IsEmpty then
begin
Application.MessageBox(PChar('<27><><EFBFBD><EFBFBD>' + FLMType + <><C3BB><EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD>ǩ!'), '<27><>ʾ', 0);
Exit;
end;
end;
procedure TfrmLabelPrint.FormShow(Sender: TObject);
begin
2025-08-07 12:49:00 +08:00
2025-08-07 11:08:39 +08:00
// 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];
// ComboBox_Print.Properties.Items.Assign(printer.Printers);
InitGrid();
2025-10-29 09:55:52 +08:00
ReadINIFile();
2025-08-07 11:08:39 +08:00
end;
procedure TfrmLabelPrint.TV1DblClick(Sender: TObject);
begin
ModalResult := 1;
end;
procedure TfrmLabelPrint.FormDestroy(Sender: TObject);
begin
frmLabelPrint := nil;
end;
end.