unit U_frmsmewm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, ADODB, RM_System, RM_Common, RM_Class, RM_GridReport,
  RM_Dataset;

type
  Tfrmsmewm = class(TForm)
    Label1: TLabel;
    APID: TEdit;
    ADOQueryPrint: TADOQuery;
    ADOTmp: TADOQuery;
    ADOCmd: TADOQuery;
    RM2: TRMGridReport;
    Button2: TButton;
    RMDB_Main: TRMDBDataSet;
    ComboBox1: TComboBox;
    Button1: TButton;
    procedure APIDKeyPress(Sender: TObject; var Key: Char);
    procedure Button2Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Button1Click(Sender: TObject);
//    procedure FormKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmsmewm: Tfrmsmewm;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, U_iniParam, U_ClothHCList, MMSystem;

{$R *.dfm}

procedure Tfrmsmewm.APIDKeyPress(Sender: TObject; var Key: Char);
begin

  if Key = #13 then
  begin
    Button2.Click;
  end;
  with ADOTmp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select A.* from WFB_MJJY A');
    SQL.Add(' where A.MJID=''' + Trim(APID.Text) + '''');
    Open;
  end;
end;

procedure Tfrmsmewm.Button2Click(Sender: TObject);
var
  fPrintFile: string;
  FMJID: string;
begin
  with ADOQueryPrint do
  begin
    Close;
    SQL.Clear;
    sql.Add('select A.MJID,A.mjstr3,QtyUnit=A.MJTypeOther,B.orderNo,B.conNo,B.customerNoName,B.OrdDate,B.NO,B.LBName ');
    sql.Add(',EngColor=(select max(Note) from KH_Zdy X where X.ZDYName=C.PRTColor and X.Type=''OrdColor'' ) ');
    sql.Add(',B.MPRTCF,C.*,A.* ');
    sql.Add(' from WFB_MJJY A');
    sql.Add(' inner join JYOrder_Main B On A.Mainid=B.Mainid');
    sql.Add(' inner join JYOrder_Sub C on A.SubId=C.SubId');
    SQL.Add(' where A.MJID=''' + APID.Text + '''');
    Open;
  end;

  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(ADOQueryPrint.fieldbyname('Slbname').AsString);
  ExportFtErpFile(Trim(ADOQueryPrint.fieldbyname('Slbname').AsString), ADOCmd);


//   if Trim(ADOQueryPrint.fieldbyname('Slbname').AsString) <> '' then
//  begin
//    fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(ADOQueryPrint.fieldbyname('Slbname').AsString);
//    ExportFtErpFile(Trim(ADOQueryPrint.fieldbyname('Slbname').AsString), ADOCmd);
//  end
//  else
//  begin
//    fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\通用标签.rmf';
//    ExportFtErpFile('通用标签.rmf', ADOCmd);
//  end;

  if not FileExists(fPrintFile) then
  begin
    Application.MessageBox(PChar('没有找到' + fPrintFile), '提示', 0);
    Exit;
  end;

  if FileExists(fPrintFile) then
  begin
    RM2.LoadFromFile(fPrintFile);
    RM2.DefaultCopies := strtointdef(trim(ComboBox1.Text), 1);    
//    RM2.DefaultCopies := 1;
//    RM2.ShowReport;
    RM2.printReport;
  end;

  APID.Text := '';  
end;

procedure Tfrmsmewm.FormShow(Sender: TObject);
begin
  APID.SetFocus;
end;

procedure Tfrmsmewm.Button1Click(Sender: TObject);
begin
  APID.Text := '';
end;

end.

