unit U_TradeInspSet_YJ;

interface

uses
  Windows, Messages, StrUtils, SysUtils, Variants, Classes, Graphics, Controls,
  Forms, Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB,
  ADODB, cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin,
  StdCtrls, cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
  cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP, ShellAPI, IniFiles, cxCheckBox, cxCalendar, cxButtonEdit,
  cxTextEdit, cxDropDownEdit, BtnEdit, cxLookAndFeels, cxLookAndFeelPainters,
  cxNavigator, dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges,
  dxBarBuiltInMenu, U_BaseList, cxContainer, dxCore, cxDateUtils, cxImage,
  cxDBEdit, IdExplicitTLSClientServerBase, RM_Preview, cxPC, U_BaseHelp,
  System.ImageList, Vcl.ImgList, RTComboBox, RM_BarCode, RM_e_Xls, RM_e_Jpeg,
  RM_E_llPDF, RM_e_main, RM_e_htm, RM_e_Tiff, RM_e_emf, RM_e_Graphic, RM_e_bmp,
  RM_e_csv, RM_e_txt, RM_DialogCtls, RM_Cross, RM_Diagonal, RM_ChineseMoneyMemo,
  RM_Ole, RM_CheckBox, RM_RichEdit, RM_AngLbl, RM_FormReport, RM_PDBGrid,
  RMD_Dbx, RMD_ADO, RMD_ReportExplorer, RM_DsgGridReport, RM_Designer;

type
  TfrmTradeInspSet_YJ = class(TfrmBaseHelp)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ToolButton3: TToolButton;
    ScrollBox1: TScrollBox;
    Label14: TLabel;
    Label1: TLabel;
    cxPageControl1: TcxPageControl;
    cxTabSheet4: TcxTabSheet;
    cxTabSheet3: TcxTabSheet;
    RMPreview2: TRMPreview;
    RMPreview1: TRMPreview;
    Label2: TLabel;
    RuleBeforeTare: TEdit;
    RuleConversion: TComboBox;
    Label3: TLabel;
    Coefficient: TEdit;
    Label4: TLabel;
    ADOQueryLabel: TADOQuery;
    RM1: TRMGridReport;
    RMDB_1: TRMDBDataSet;
    ADO_1: TADOQuery;
    RM2: TRMGridReport;
    RMDB_2: TRMDBDataSet;
    cxTabSheet1: TcxTabSheet;
    DS_Label: TDataSource;
    CDS_Label: TClientDataSet;
    RMDB_Label: TRMDBDataSet;
    RMLabel: TRMGridReport;
    Panel1: TPanel;
    Panel2: TPanel;
    cxGridLabel: TcxGrid;
    TVLabel: TcxGridDBTableView;
    TVLabellabelId: TcxGridDBColumn;
    TVLabellabeltype: TcxGridDBColumn;
    TVLabellabelCaption: TcxGridDBColumn;
    TVLabellabelFile: TcxGridDBColumn;
    cxGridLabelLevel1: TcxGridLevel;
    RMPreview3: TRMPreview;
    Panel4: TPanel;
    Label10: TLabel;
    LabelCaption: TEdit;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    Tadd: TToolButton;
    Tupd: TToolButton;
    Tdel: TToolButton;
    ToolButton4: TToolButton;
    RMBarCodeObject1: TRMBarCodeObject;
    RMXLSExport1: TRMXLSExport;
    RMDataDictionary1: TRMDataDictionary;
    ADO_Down: TADOQuery;
    TVLabelColumn1: TcxGridDBColumn;
    TVLabelColumn2: TcxGridDBColumn;
    LabVolume: TEdit;
    LabPackage: TEdit;
    Label5: TLabel;
    RulePieceNo: TComboBox;
    Label6: TLabel;
    RuleLenUnit: TComboBox;
    Label8: TLabel;
    RuleLaterTare: TEdit;
    ToolButton5: TToolButton;
    RMReport1: TRMReport;
    RMCompositeReport1: TRMCompositeReport;
    RMDBDataSet1: TRMDBDataSet;
    RMUserDataset1: TRMUserDataset;
    RMAngledLabelObject1: TRMAngledLabelObject;
    RMRichObject1: TRMRichObject;
    RMCheckBoxObject1: TRMCheckBoxObject;
    RMOLEObject1: TRMOLEObject;
    RMChineseMoneyObject1: TRMChineseMoneyObject;
    RMDiagonalObject1: TRMDiagonalObject;
    RMCrossObject1: TRMCrossObject;
    RMDialogControls1: TRMDialogControls;
    RMTextExport1: TRMTextExport;
    RMCSVExport1: TRMCSVExport;
    RMBMPExport1: TRMBMPExport;
    RMEMFExport1: TRMEMFExport;
    RMTiffExport1: TRMTiffExport;
    RMHTMExport1: TRMHTMExport;
    RMllPDFExport1: TRMllPDFExport;
    RMJPEGExport1: TRMJPEGExport;
    RMDesigner1: TRMDesigner;
    RMGridReportDesigner1: TRMGridReportDesigner;
    RMReportExplorer1: TRMReportExplorer;
    RMDADOComponents1: TRMDADOComponents;
    RMDDBXComponents1: TRMDDBXComponents;
    RMFormReport1: TRMFormReport;
    RMPrintDBGrid1: TRMPrintDBGrid;
    RMDB_UP: TRMDBDataSet;
    RMUP: TRMGridReport;
    ToolButton6: TToolButton;
    GPM_Label: TcxGridPopupMenu;
    ToolButton7: TToolButton;
    Label9: TLabel;
    LabelType: TComboBox;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure cxPageControl1Change(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure TupdClick(Sender: TObject);
    procedure TdelClick(Sender: TObject);
    procedure TaddClick(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure TVLabelCellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton5Click(Sender: TObject);
    procedure LabVolumeDblClick(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure LabelTypeChange(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();
    function SaveData(): Boolean;
    procedure InitLabel();
    function SaveLabel(MLabelID: string): Boolean;
    procedure InitLabVolume();
    procedure InitLabPackage();
    procedure UpLabelImg(MlabelCaption: string);
  public
    FDataID: string;
  end;

var
  frmTradeInspSet_YJ: TfrmTradeInspSet_YJ;

implementation

uses
  U_DataLink, U_RTFun, U_LabelInput, U_TradeInspSet;

{$R *.dfm}
procedure TfrmTradeInspSet_YJ.UpLabelImg(MlabelCaption: string);
var
  fImagePath2: string;
  OpenDiaLog: TOpenDialog;
  fFileName: string;
  fFilePath: string;
  maxNo: string;
  FJStream: TMemoryStream;
  mfileSize: integer;
  mCreationTime: TdateTime;
  mWriteTime: TdateTime;
begin

  with ADOQueryLabel do
  begin
    close;
    sql.Clear;
    sql.Add('select top 1 * from RT_FileUpdate');
    sql.Add('where FileName=' + quotedstr(trim(MlabelCaption) + '.rmf'));
    Open;
  end;

  if ADOQueryLabel.IsEmpty then
    exit;

  with RMUP do
  begin
    LoadFromBlobField(tblobfield(ADOQueryLabel.fieldbyname('Files')));
    fImagePath2 := ExtractFilePath(Application.ExeName) + 'image\label0001.jpg';
    if FileExists(fImagePath2) then
      DeleteFile(fImagePath2);
    fImagePath2 := ExtractFilePath(Application.ExeName) + 'image\label.jpg';
    RMUP.PrepareReport;
    RMUP.ExportTo(RMjpegExport1, fImagePath2);
  end;

  try
    ADOQueryCmd.Connection.BeginTrans;
    fFilePath := ExtractFilePath(Application.ExeName) + 'image\label0001.jpg';
    fFileName := 'label.jpg';
    application.ProcessMessages;
    if GetLSNo(ADOQueryCmd, maxNo, 'FJ', 'TP_File', 4, 1) = False then
    begin
      adoqueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取最大号失败！', '提示', 0);
      Exit;
    end;
      //获取文件信息
    GetFileInfo(fFilePath, mfileSize, mCreationTime, mWriteTime);
    with adoqueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('delete from TP_File ');
      sql.Add('where TFType=''标签图片'' and  WBID=' + quotedstr(Trim(MlabelCaption)));
//      ShowMessage(SQL.Text)  ;
      execsql;
    end;

    try
      FJStream := TMemoryStream.Create;
      with adoqueryCmd do
      begin
        close;
        sql.Clear;
        sql.Add('select * from TP_File ');
        sql.Add('where TFID=' + quotedstr(trim(maxNo)));
        open;
        append;
        fieldbyname('TFID').Value := trim(maxNo);
        fieldbyname('WBID').Value := Trim(MlabelCaption);
        fieldbyname('TFType').Value := trim('标签图片');
        fieldbyname('Filler').Value := trim(DName);
        fieldbyname('FileName').Value := trim(fFileName);
        fieldbyname('TFDate').Value := mWriteTime;
        FJStream.LoadFromFile(fFilePath);
        tblobfield(FieldByName('Filesother')).LoadFromStream(FJStream);
        post;
      end;
    finally
      FJStream.Free;
    end;

    adoqueryCmd.Connection.CommitTrans;
  except
    adoqueryCmd.Connection.RollbackTrans;
    application.MessageBox('附件保存失败！', '提示信息', 0);
  end;
end;

function TfrmTradeInspSet_YJ.SaveLabel(MLabelID: string): Boolean;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('select * from Trade_Label');
      sql.Add('where LabelID=' + Quotedstr(MLabelID));
      Open;
      Edit;
      fieldByName('Editer').value := DName;
      FieldByName('EditTime').Value := SGetServerDateTime(ADOQueryTemp);
//      RMLabel.SaveToBlobField(TBlobField(FieldByName('LabelFile')));
      Post;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    result := true;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Result := false;
    application.MessageBox('保存标签模板出错!', '警告信息', 0);
  end;
end;

procedure TfrmTradeInspSet_YJ.InitLabel();
begin
  with ADOQueryMain do
  begin
    close;
    sql.Clear;
    sql.Add(' select * from Trade_Label');
    sql.Add(' order by labeltype,labelCaption');
    Open;
  end;
  SDofilter(ADOQueryMain, SGetFilters(Panel4, 1, 2));
  SCreateCDS(ADOQueryMain, CDS_Label);
  SInitCDSData(ADOQueryMain, CDS_Label);
end;

procedure TfrmTradeInspSet_YJ.InitLabVolume();
begin

  with ADOQueryLabel do
  begin
    close;
    sql.Clear;
    sql.Add('select top 1 * from RT_FileUpdate');
    sql.Add('where FileName=' + quotedstr(trim(LabVolume.Text) + '.rmf'));
    Open;
  end;

  if ADOQueryLabel.IsEmpty then
    exit;
  with RM1 do
  begin
    LoadFromBlobField(tblobfield(ADOQueryLabel.fieldbyname('Files')));
    Preview := RMPreview1;
    ShowReport;
  end;

end;

procedure TfrmTradeInspSet_YJ.InitLabPackage();
begin

  with ADOQueryLabel do
  begin
    close;
    sql.Clear;
    sql.Add('select top 1 * from RT_FileUpdate');
    sql.Add('where FileName=' + quotedstr(trim(LabPackage.Text) + '.rmf'));
    Open;
  end;

  if ADOQueryLabel.IsEmpty then
    exit;

  with RM2 do
  begin
    LoadFromBlobField(tblobfield(ADOQueryLabel.fieldbyname('Files')));
    Preview := RMPreview2;
    ShowReport;
  end;
end;

procedure TfrmTradeInspSet_YJ.LabVolumeDblClick(Sender: TObject);
begin
  TEdit(Sender).Text := '';
end;

procedure TfrmTradeInspSet_YJ.InitGrid();
begin

  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from Trade_Cloth_Inspect_Rule where  RuleID=''' + Trim(FDataID) + '''');
    Open;
  end;
  SCSHData(ADOQueryTemp, ScrollBox1, 2);

end;

procedure TfrmTradeInspSet_YJ.FormDestroy(Sender: TObject);
begin
  inherited;
  frmTradeInspSet_YJ := nil;
end;

procedure TfrmTradeInspSet_YJ.LabelTypeChange(Sender: TObject);
begin

  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel4, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_Label);
    SInitCDSData(ADOQueryMain, CDS_Label);
  end;
end;

procedure TfrmTradeInspSet_YJ.cxPageControl1Change(Sender: TObject);
begin
  case cxPageControl1.ActivePageIndex of
    1:
      begin
        InitLabVolume();
      end;
    2:
      begin
        InitLabPackage();
      end;
  end;
end;

procedure TfrmTradeInspSet_YJ.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  Action := caFree;
end;

procedure TfrmTradeInspSet_YJ.TaddClick(Sender: TObject);
begin
  try
    frmLabelInput := TfrmLabelInput.create(self);
    with frmLabelInput do
    begin
      FLabelId := '';
      if showModal = 1 then
      begin
        InitLabel();
      end;
    end;
  finally
    frmLabelInput.Free;
  end;
end;

procedure TfrmTradeInspSet_YJ.TBCloseClick(Sender: TObject);
begin
  ModalResult := 1;
end;

procedure TfrmTradeInspSet_YJ.FormShow(Sender: TObject);
begin
  inherited;
  readCxGrid(self.Caption, TVLabel, '生产指示单管理');
  ExportFtErpFile('模板标签.rmf', ADOQueryTemp);

  with ADO_1 do
  begin
    Close;
    SQL.Clear;
    sql.Add('exec P_BS_Label_Get_Test');
    Open;
  end;
  Initlabel();
  InitGrid();

end;

procedure TfrmTradeInspSet_YJ.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmTradeInspSet_YJ.TdelClick(Sender: TObject);
var
  fPrintFile: string;
begin
  if CDS_Label.IsEmpty then
    exit;
  if TRIM(DName) <> 'ADMIN' then
  begin
    if TRIM(CDS_Label.fieldByName('Filler').asString) <> TRIM(DName) then
    begin
      Application.MessageBox('不能操作他人的数据!', '提示', 0);
      Exit;
    end;
  end;

  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;

  try
    with ADOQueryCmd do
    begin
      close;
      sql.clear;
      sql.Add('delete Trade_Label');
      sql.Add('where labelId=' + quotedstr(CDS_Label.fieldByName('LabelID').asString));
      sql.Add('delete RT_FileUpdate');
      sql.Add('where FileName=' + quotedstr(trim(CDS_Label.fieldByName('labelCaption').asString) + '.rmf'));

      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('标签删除')));
      sql.Add(',' + quotedstr(trim('标签名称：' + trim(CDS_Label.fieldByName('labelCaption').asString))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      execSql;
    end;

    fPrintFile := ExtractFilePath(Application.ExeName) + 'report\' + trim(CDS_Label.fieldByName('labelCaption').asString) + '.rmf';

    if FileExists(fPrintFile) then
    begin
      DeleteFile(fPrintFile);
    end;

    CDS_Label.Delete;
  except
    application.MessageBox('删除失败!', '警告信息', 0);
  end;

end;

function TfrmTradeInspSet_YJ.SaveData(): Boolean;
var
  MaxId, MaxSubId, FCoCode, FCCID, MaxCFID: string;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;

    if Trim(FDataID) = '' then
    begin
      if GetLSNo(ADOQueryCmd, MaxId, 'R', 'Trade_Cloth_Inspect_Rule', 4, 1) = False then
      begin
        Result := False;
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败！', '提示', 0);
        Exit;
      end;
    end
    else
    begin
      MaxId := Trim(FDataID);
    end;

    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from Trade_Cloth_Inspect_Rule where RuleID=''' + Trim(FDataID) + '''');
      Open;
    end;
    with ADOQueryCmd do
    begin
      if Trim(FDataID) = '' then
      begin
        Append;
        FieldByName('Filler').Value := Trim(DName);
      end
      else
      begin
        Edit;
        FieldByName('Editer').Value := Trim(DName);
        FieldByName('Edittime').Value := SGetServerDateTime(ADOQueryTemp);
      end;
      FieldByName('RuleID').Value := Trim(MaxId);
      RTSetsavedata(ADOQueryCmd, 'Trade_Cloth_Inspect_Rule', ScrollBox1, 2);

      Post;
    end;

    ADOQueryCmd.Connection.CommitTrans;
    FCCID := Trim(MaxSubId);
    Result := True;
  except
    Result := false;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存异常!', '提示', 0);
  end;
end;

procedure TfrmTradeInspSet_YJ.ToolButton1Click(Sender: TObject);
begin
  if CDS_Label.IsEmpty then
    exit;
  LabVolume.Text := trim(CDS_Label.fieldbyname('labelCaption').asstring);

  UpLabelImg(trim(CDS_Label.fieldbyname('labelCaption').asstring));

end;

procedure TfrmTradeInspSet_YJ.ToolButton2Click(Sender: TObject);
begin
  if CDS_Label.IsEmpty then
    exit;
  LabPackage.Text := trim(CDS_Label.fieldbyname('labelCaption').asstring);
  UpLabelImg(trim(CDS_Label.fieldbyname('labelCaption').asstring));

end;

procedure TfrmTradeInspSet_YJ.ToolButton3Click(Sender: TObject);
begin

  if SaveData() then
  begin
    Application.MessageBox('保存成功!', '提示', 0);
  end;
end;

procedure TfrmTradeInspSet_YJ.ToolButton4Click(Sender: TObject);
var
  fFileName, fPrintFile: string;
  MLabelID, MLabelCaption: string;
begin
  if CDS_Label.IsEmpty then
    exit;
  if TRIM(DName) <> 'ADMIN' then
  begin
    if TRIM(CDS_Label.fieldByName('Filler').asString) <> TRIM(DName) then
    begin
      Application.MessageBox('不能操作他人的数据!', '提示', 0);
      Exit;
    end;
  end;

  MLabelID := TRIM(CDS_Label.fieldByName('LabelID').asString);
  MLabelCaption := TRIM(CDS_Label.fieldByName('LabelCaption').asString);
  ExportFtErpFile(MLabelCaption + '.rmf', ADOQueryTemp);
  fPrintFile := ExtractFilePath(Application.ExeName) + 'report\' + MLabelCaption + '.rmf';

  if not FileExists(fPrintFile) then
    CopyFile(PChar(ExtractFilePath(Application.ExeName) + 'Report\模板标签.rmf'), PChar(fPrintFile), False);

  with RMLabel do
  begin
    RMLabel.Clear;
    RMDB_Label.DataSet := nil;
    Dictionary.FieldAliases.Clear;
    Dictionary.FieldAliases['RMDB_Label'] := '标签数据';
    RMDB_Label.DataSet := ADO_1;
    LoadFromFile(fPrintFile);
    application.ProcessMessages;
    DesignReport();
    SaveLabel(MLabelID);
    ExportToFtErp(fPrintFile, ADOQueryCmd);
  end;
end;

procedure TfrmTradeInspSet_YJ.ToolButton5Click(Sender: TObject);
begin
  try
    with ADOQueryCmd do
    begin
      close;
      sql.clear;
      sql.Add(' update RT_FileUpdate set FileEditDate=GETDATE()   ');
      sql.Add(',LastEditer=' + quotedstr(dname));
      sql.Add(',Files=(SELECT top 1 Files from RT_FileUpdate where FileName=' + quotedstr(trim(CDS_Label.fieldbyname('labelCaption').asstring) + '.rmf') + ')     ');
      sql.Add('where FileName=''模板标签.rmf''  ');

      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('模板标签修改')));
      sql.Add(',' + quotedstr(trim('标签名称：' + trim(CDS_Label.fieldByName('labelCaption').asString))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      execSql;
    end;
    DeleteFile(PChar(ExtractFilePath(Application.ExeName) + 'Report\模板标签.rmf'));
    ExportFtErpFile('模板标签.rmf', ADOQueryTemp);
    application.MessageBox('设置成功!', '警告信息', 0);
  except
    application.MessageBox('删除失败!', '警告信息', 0);
  end;
end;

procedure TfrmTradeInspSet_YJ.ToolButton6Click(Sender: TObject);
begin
  WriteCxGrid(self.Caption, TVLabel, '生产指示单管理');
end;

procedure TfrmTradeInspSet_YJ.ToolButton7Click(Sender: TObject);
var
  MFromLabelId: string;
begin
  ToolButton5.Click;
  MFromLabelId := trim(CDS_Label.fieldbyname('LabelId').asstring);
  try
    frmLabelInput := TfrmLabelInput.create(self);
    with frmLabelInput do
    begin
      FLabelId := '';
      if showModal = 1 then
      begin
        with ADOQueryCmd do
        begin
          close;
          sql.clear;
          sql.Add(' exec P_BS_Label_Copy');
          sql.Add(' @FromLabelId=' + quotedstr(trim(MFromLabelId)));
          sql.Add(',@ToLabelId=' + quotedstr(trim(FLabelId)));

//          showmessage(sql.Text);
          execSql;
        end;
        InitLabel();
      end;
    end;
  finally
    frmLabelInput.Free;
  end;
end;

procedure TfrmTradeInspSet_YJ.TupdClick(Sender: TObject);
begin
  if CDS_Label.IsEmpty then
    exit;
  try
    frmLabelInput := TfrmLabelInput.create(self);
    with frmLabelInput do
    begin
      fLabelId := CDS_Label.fieldByName('LabelId').AsString;
      if showModal = 1 then
      begin
        InitLabel();
      end;
    end;
  finally
    frmLabelInput.Free;
  end;
end;

procedure TfrmTradeInspSet_YJ.TVLabelCellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
var
  fPrintFile: string;
begin
  if CDS_Label.IsEmpty then
    exit;
  ExportFtErpFile(TRIM(CDS_Label.fieldByName('LabelCaption').asString) + '.rmf', ADOQueryTemp);
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + CDS_Label.fieldbyname('LabelCaption').AsString + '.rmf';
  if not FileExists(fPrintFile) then
    CopyFile(PChar(ExtractFilePath(Application.ExeName) + 'Report\模板标签.rmf'), PChar(fPrintFile), False);

  with RMLabel do
  begin
    RMLabel.LoadFromFile(fPrintFile);
    Preview := RMPreview3;
    ShowReport;
  end;
end;

end.

