D10myBiaoqi/T02贸易汇总仓库/U_LabelPrintPV.pas
2025-11-08 10:16:26 +08:00

382 lines
9.9 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_LabelPrintPV;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
cxEdit, DB, cxDBData, ToolWin, ComCtrls, U_BaseHelp, cxGridCustomTableView,
cxGridTableView, cxGridDBTableView, cxGridLevel, cxClasses, cxControls,
cxGridCustomView, cxGrid, DBClient, ADODB, ImgList, StdCtrls, ExtCtrls,
cxTextEdit, cxGridCustomPopupMenu, cxGridPopupMenu, cxLookAndFeels,
cxLookAndFeelPainters, dxSkinsCore, dxSkinsDefaultPainters, cxNavigator,
dxDateRanges, dxBarBuiltInMenu, System.ImageList, U_BaseInput, RM_Common,
RM_Class, RM_GridReport, RM_Dataset, Vcl.Buttons, RM_E_llPDF, RM_BarCode,
RM_e_Graphic, RM_e_Jpeg, RM_e_Xls, cxContainer, cxMaskEdit, cxDropDownEdit,
cxMRUEdit, RM_RichEdit, dxSkinWXI, System.Generics.Collections;
type
TfrmLabelPrintPV = class(TfrmBaseHelp)
ADOQueryTemp: TADOQuery;
ADOConnection1: TADOConnection;
Panel1: TPanel;
ImageList1: TImageList;
RMDB_1: TRMDBDataSet;
RM1: TRMGridReport;
RMDB_2: TRMDBDataSet;
CDS_Label: TClientDataSet;
ADO_1: TADOQuery;
btnPrint: TSpeedButton;
btnShow: TSpeedButton;
ADO_2: TADOQuery;
RMDB_3: TRMDBDataSet;
ADO_3: TADOQuery;
RMXLSExport1: TRMXLSExport;
RMJPEGExport1: TRMJPEGExport;
RMBarCodeObject1: TRMBarCodeObject;
RMllPDFExport1: TRMllPDFExport;
CheckBox1: TCheckBox;
ComboBox1: TComboBox;
Label1: TLabel;
cbbLab: TcxMRUEdit;
CheckBox2: TCheckBox;
Label3: TLabel;
Label4: TLabel;
inputCode: TEdit;
inputNote: TEdit;
RMRichObject1: TRMRichObject;
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
procedure InitGrid();
procedure PrintLabel(MIsShow: Boolean);
function IsFieldUnique(AQuery: TADOQuery; const FieldName: string): Boolean;
{ Private declarations }
public
FPreviewPrint: Boolean;
FLMType: string; //<2F><>ǩ<EFBFBD><C7A9><EFBFBD><EFBFBD>
FFiltration1, FFiltration2, FFiltration3: string;
{ Public declarations }
end;
var
frmLabelPrintPV: TfrmLabelPrintPV;
implementation
uses
U_DataLink, U_RTFun, U_LabelMapSet;
{$R *.dfm}
procedure TfrmLabelPrintPV.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;
RMllPDFExport1.ShowDialog := CheckBox2.Checked;
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
begin
with ADO_1 do
begin
Close;
sql.Clear;
sql.add('exec ' + trim(CDS_Label.fieldbyname('LMSql1').AsString) + ' @Filtration=' + quotedstr(Trim(FFiltration1)));
Open;
end;
end;
if trim(CDS_Label.fieldbyname('LMSql2').AsString) <> '' then
begin
with ADO_2 do
begin
Close;
sql.Clear;
sql.add('exec ' + trim(CDS_Label.fieldbyname('LMSql2').AsString) + ' @Filtration=' + quotedstr(Trim(FFiltration1)));
Open;
end;
end;
if trim(CDS_Label.fieldbyname('LMSql3').AsString) <> '' then
begin
with ADO_3 do
begin
Close;
sql.Clear;
sql.add('exec ' + trim(CDS_Label.fieldbyname('LMSql3').AsString) + ' @Filtration=' + quotedstr(Trim(FFiltration1)));
Open;
end;
end;
end;
fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + LBName + '.rmf';
if FileExists(fPrintFile) then
begin
RM1.LoadFromFile(fPrintFile);
RM1.DefaultCopies := StrToIntDef(ComboBox1.Text, 1);
RMVariables['inputNote'] := Trim(inputNote.Text);
RMVariables['inputcode'] := Trim(inputcode.Text);
if MIsShow then
RM1.ShowReport
else
RM1.PrintReport;
end
else
begin
Application.MessageBox(PChar(<><C3BB><EFBFBD><EFBFBD>' + fPrintFile), '<27><>ʾ', 0);
end;
end;
procedure TfrmLabelPrintPV.FormCreate(Sender: TObject);
begin
inherited;
FPreviewPrint := True;
try
with ADOConnection1 do
begin
Connected := false;
ConnectionString := DConString;
Connected := true;
end;
ADOQueryBaseCmd.Connection := ADOConnection1;
ADOQueryBaseTemp.Connection := ADOConnection1;
except
{if Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>,<2C>Ƿ<EFBFBD>Ҫ<EFBFBD>ٴ<EFBFBD><D9B4><EFBFBD><EFBFBD><EFBFBD>?','<27><>ʾ',32+4)=IDYES then
begin
try
with ADOConnection1 do
begin
Connected:=false;
ConnectionString:=DConString;
//ConnectionString:='23242';
Connected:=true;
end;
except
end;
end; }
end;
end;
procedure TfrmLabelPrintPV.btnPrintClick(Sender: TObject);
var
LBName: string;
begin
LBName := cbbLab.text;
if CDS_Label.Locate('LMName', LBName, []) then
begin
if trim(CDS_Label.fieldbyname('LMSql1').AsString) = 'P_Trade_FinishCloth_Out_Prt2' then
begin
with ADOQueryBaseTemp do
begin
close;
SQL.Clear;
SQL.Add(' exec P_Trade_FinishCloth_Out_Prt2 @Filtration=' + QuotedStr(FFiltration1));
Open;
// showmessage(IntToStr(ADOQueryBaseTemp.RecordCount));
end;
if not IsFieldUnique(ADOQueryBaseTemp, 'IOTime') then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD>ʱ<EFBFBD>䲻Ψһ', '<27><>ʾ', 0);
exit;
end;
if not IsFieldUnique(ADOQueryBaseTemp, 'IOType') then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͳ<EFBFBD>Ψһ', '<27><>ʾ', 0);
exit;
end;
if not IsFieldUnique(ADOQueryBaseTemp, 'ToCoName') then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>Ψһ', '<27><>ʾ', 0);
exit;
end
end;
end;
PrintLabel(False);
ModalResult := 1;
end;
function TfrmLabelPrintPV.IsFieldUnique(AQuery: TADOQuery; const FieldName: string): Boolean;
var
FirstValue: string;
CurrentValue: string;
begin
Result := True; // Ĭ<>ϼ<EFBFBD><CFBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>һ<EFBFBD><D2BB>
// <20><><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
if AQuery.FindField(FieldName) = nil then
Exit(False); // <20>ֶβ<D6B6><CEB2><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD>False
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>Ϊ<EFBFBD>գ<EFBFBD><D5A3><EFBFBD>Ϊ<EFBFBD><CEAA>һ<EFBFBD>µģ<C2B5>û<EFBFBD>в<EFBFBD>ͬ<EFBFBD><CDAC>ֵ<EFBFBD><D6B5>
if AQuery.IsEmpty then
Exit(True);
// <20><>ȡ<EFBFBD><C8A1>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>ֵ<EFBFBD><D6B5>Ϊ<EFBFBD><CEAA>׼
AQuery.First;
FirstValue := AQuery.FieldByName(FieldName).AsString;
// <20>ӵڶ<D3B5><DAB6><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>ʼ<EFBFBD>Ƚ<EFBFBD>
AQuery.Next;
while not AQuery.Eof do
begin
CurrentValue := AQuery.FieldByName(FieldName).AsString;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ֵ<EFBFBD><D6B5>ͬ<EFBFBD><CDAC><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>False
if CurrentValue <> FirstValue then
begin
Result := False;
Exit;
end;
AQuery.Next;
end
end;
procedure TfrmLabelPrintPV.btnShowClick(Sender: TObject);
var
LBName: string;
begin
LBName := cbbLab.text;
if CDS_Label.Locate('LMName', LBName, []) then
begin
if trim(CDS_Label.fieldbyname('LMSql1').AsString) = 'P_Trade_FinishCloth_Out_Prt2' then
begin
with ADOQueryBaseTemp do
begin
close;
SQL.Clear;
SQL.Add(' exec P_Trade_FinishCloth_Out_Prt2 @Filtration=' + QuotedStr(FFiltration1));
Open;
// showmessage(IntToStr(ADOQueryBaseTemp.RecordCount));
end;
if not IsFieldUnique(ADOQueryBaseTemp, 'IOTime') then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD>ʱ<EFBFBD>䲻Ψһ', '<27><>ʾ', 0);
exit;
end;
if not IsFieldUnique(ADOQueryBaseTemp, 'IOType') then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͳ<EFBFBD>Ψһ', '<27><>ʾ', 0);
exit;
end;
if not IsFieldUnique(ADOQueryBaseTemp, 'ToCoName') then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>Ψһ', '<27><>ʾ', 0);
exit;
end
end;
end;
PrintLabel(true);
end;
procedure TfrmLabelPrintPV.cbbLabPropertiesButtonClick(Sender: TObject);
begin
try
frmLabelMapSet := TfrmLabelMapSet.Create(Application);
with frmLabelMapSet do
begin
FFiltration1 := self.FFiltration1;
FFiltration2 := self.FFiltration2;
FFiltration3 := self.FFiltration3;
FLMType := self.FLMType;
if ShowModal = 1 then
begin
Self.InitGrid();
end;
end;
finally
frmLabelMapSet.Free;
end;
end;
procedure TfrmLabelPrintPV.FormClose(Sender: TObject; var Action: TCloseAction);
begin
inherited;
Action := cahide;
end;
procedure TfrmLabelPrintPV.InitGrid();
begin
with ADOQueryTemp do
begin
close;
sql.Clear;
sql.Add('select distinct(LMName) name from BS_Label_Map where LMType=' + QuotedStr(TRIM(FLMType)));
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;
SCreateCDS(ADOQueryTemp, CDS_Label);
SInitCDSData(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 TfrmLabelPrintPV.FormShow(Sender: TObject);
begin
inherited;
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];
InitGrid();
end;
procedure TfrmLabelPrintPV.TV1DblClick(Sender: TObject);
begin
ModalResult := 1;
end;
procedure TfrmLabelPrintPV.FormDestroy(Sender: TObject);
begin
inherited;
frmLabelPrintPV := nil;
end;
end.