unit U_MLMangeRS;

interface

uses
  Windows, Messages, 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, cxTextEdit,
  cxButtonEdit, Menus, cxLookAndFeelPainters, cxButtons, cxImage, jpeg;

type
  TfrmMLMangeRS = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    DataSource1: TDataSource;
    ADOQueryTree: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    DataSource2: TDataSource;
    ADOQueryMain: TADOQuery;
    CDS_Main: TClientDataSet;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    ODPat: TOpenDialog;
    IdFTP1: TIdFTP;
    SaveDialog1: TSaveDialog;
    DataSource3: TDataSource;
    cxGridPopupMenu2: TcxGridPopupMenu;
    Order_GX: TClientDataSet;
    DataSource4: TDataSource;
    cxGridPopupMenu3: TcxGridPopupMenu;
    ML_Col: TClientDataSet;
    DataSource5: TDataSource;
    cxGridPopupMenu4: TcxGridPopupMenu;
    CDS_Sub: TClientDataSet;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxGridPopupMenu5: TcxGridPopupMenu;
    DataSource6: TDataSource;
    Ord_HX: TClientDataSet;
    ADOQuery1: TADOQuery;
    TCK: TToolButton;
    ToolButton11: TToolButton;
    Panel5: TPanel;
    Label2: TLabel;
    MLNo: TEdit;
    Label1: TLabel;
    Label4: TLabel;
    MLName: TEdit;
    GYLXName: TEdit;
    tv1: TcxGridDBTableView;
    v1MLNo: TcxGridDBColumn;
    v1MLName: TcxGridDBColumn;
    v1MLMF: TcxGridDBColumn;
    v1MLKZ: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1GYLXName: TcxGridDBColumn;
    v1SKID: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label3: TLabel;
    TColAdd: TToolButton;
    Panel2: TPanel;
    Label5: TLabel;
    Label6: TLabel;
    DMLMF: TEdit;
    DMLKZ: TEdit;
    Button1: TButton;
    ADOQueryPrint: TADOQuery;
    CDS_Print: TClientDataSet;
    Label7: TLabel;
    DYID: TEdit;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    ML_GX: TClientDataSet;
    Panel3: TPanel;
    Label8: TLabel;
    Image1: TImage;
    cxButton1: TcxButton;
    cxButton2: TcxButton;
    cxButton4: TcxButton;
    N4: TMenuItem;
    cxGrid1: TcxGrid;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure cxDBTreeList1DblClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure MLNoChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure tv1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure TV4CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure tv1DblClick(Sender: TObject);
    procedure TCKClick(Sender: TObject);
    procedure ToolButton11Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TColAddClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure DYIDKeyPress(Sender: TObject; var Key: Char);
    procedure N2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure cxButton1Click(Sender: TObject);
    procedure cxButton2Click(Sender: TObject);
    procedure Image1Click(Sender: TObject);
    procedure cxButton4Click(Sender: TObject);
    procedure N4Click(Sender: TObject);
  private
    { Private declarations }
    PState:Integer;
    FCPID,FTopID:String;
    procedure InitTree();
    procedure InitGrid();
    procedure ReadINIFile();
    procedure ButtonColorCSH();
  public
    canshu1:string;
    { Public declarations }
  end;

var
  frmMLMangeRS: TfrmMLMangeRS;

implementation
uses
  U_DataLink,U_Fun,U_CPAdd,U_FileUp,U_MLManage_LR,U_BPZdy_LR,U_BPZdy_SH,U_MLManage_LRRS,
  U_MLManage_FHLR,U_MLManage_ZHLR,U_BPZdy_HXK,U_MLMange_CX,U_BPZdy_LRPB,U_BPZdy_LRGX,
  U_CPManage_TP,U_BPZdy_LRSHK, U_BPZdy_PanelCX,U_BPZdy_Panel;

{$R *.dfm}

procedure TfrmMLMangeRS.InitTree();
begin
  
end;

procedure TfrmMLMangeRS.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * ');
      sql.Add(',SKID=(select B.SKID from BP_ZDY B where B.BPID=A.MBPID)');
      sql.Add(',BPCode=(select B.BPCode from BP_ZDY B where B.BPID=A.MBPID)');
      sql.Add(' from ML_Manage A ');
      sql.Add(' where isnull(MLType,'''')=''染色面料'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmMLMangeRS.FormDestroy(Sender: TObject);
begin
  frmMLMangeRS:=nil;
end;

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

procedure TfrmMLMangeRS.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('染色面料',Tv1,'样品管理');
  Close;
end;
procedure TfrmMLMangeRS.FormShow(Sender: TObject);
begin
  if canshu1='高权限' then
  begin
    toolbutton11.Visible:=True;
    N1.Visible:=true;
    N2.Visible:=true;
    TColAdd.Visible:=false;
    Panel2.Visible:=false;
  end
  else
  begin
    if canshu1='查询' then
    begin
      toolbutton11.Visible:=false;
      N1.Visible:=false;
      N2.Visible:=false;
      TColAdd.Visible:=false;
      Panel2.Visible:=false;
    end
    else
    begin
      toolbutton11.Visible:=false;
      N1.Visible:=false;
      N2.Visible:=false;
      TColAdd.Visible:=true;
      Panel2.Visible:=true;
    end;
  end;
  InitGrid();
  ReadCxGrid('染色面料',Tv1,'样品管理');
end;

procedure TfrmMLMangeRS.cxDBTreeList1DblClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmMLMangeRS.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmMLMangeRS.ToolButton2Click(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmMLMangeRS.MLNoChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel5,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmMLMangeRS.ToolButton1Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  TcxGridToExcel('客户拿样',cxGrid1);
end;

procedure TfrmMLMangeRS.ReadINIFile();
var
  programIni:Tinifile;  //配置文件名
  FileName:string;
begin
  FileName:=ExtractFilePath(Paramstr(0))+'SYSTEMSET.INI';
  programIni:=Tinifile.create(FileName);
  server:=programIni.ReadString('SERVER','服务器地址','127.0.0.1');
  programIni.Free;
end;

procedure TfrmMLMangeRS.tv1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  DMLMF.Text:=Trim(CDS_Main.fieldbyname('MLMF').AsString);
  DMLKZ.Text:=Trim(CDS_Main.fieldbyname('MLKZ').AsString);
end;

procedure TfrmMLMangeRS.TV4CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  //if CDS_Main.FieldByName('MLType').AsString='复合' then
  begin
    with ADOQuery1 do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from BP_ZDY_Sub ');
      sql.Add('where BPCode='''+Trim(CDS_Sub.Fieldbyname('MLDLNo').AsString)+''' and BPflag=''SHK''');
      Open;
    end;
    SCreateCDS20(ADOQuery1,ML_Col);
    SInitCDSData20(ADOQuery1,ML_Col);
    with ADOQuery1 do
    begin
      Close;
      SQL.Clear;
      sql.Add('select A.*,B.* from BP_ZDY_Sub A ');
      Sql.Add('inner join KH_Zdy_Attachment B on A.HXATID=B.ATID and B.Type=''CPHX''');
      sql.Add(' where A.BPCode='''+trim(CDS_Sub.Fieldbyname('DLHXK').AsString)+'''');
      open;
    end;
    SCreateCDS20(ADOQuery1,Ord_HX);
    SInitCDSData20(ADOQuery1,Ord_HX);
  end;
end;

procedure TfrmMLMangeRS.tv1DblClick(Sender: TObject);
begin
  TCK.Click;
end;

procedure TfrmMLMangeRS.TCKClick(Sender: TObject);
begin
  try
    frmMLManage_LRRS:=TfrmMLManage_LRRS.Create(Application);
    with frmMLManage_LRRS do
    begin
      FCYID:=Trim(Self.CDS_Main.fieldbyname('MLID').AsString);
      FGYName:='染色';
      viewFlag:=True;
      if ShowModal=1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmMLManage_LRRS.Free;
  end;
end;

procedure TfrmMLMangeRS.ToolButton11Click(Sender: TObject);
begin
  try
    frmMLManage_LRRS:=TfrmMLManage_LRRS.Create(Application);
    with frmMLManage_LRRS do
    begin
      FCYID:='';
      FGYName:='染色';
      if ShowModal=1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmMLManage_LRRS.Free;
  end;
end;

procedure TfrmMLMangeRS.ButtonColorCSH();
begin

end;

procedure TfrmMLMangeRS.FormCreate(Sender: TObject);
begin
  canshu1:=Trim(DParameters1);
end;

procedure TfrmMLMangeRS.TColAddClick(Sender: TObject);
var i,j,x:Integer;
begin
  j:=0;
  frmBPZDY_Panel:=TfrmBPZDY_Panel.create(self);
  with frmBPZDY_Panel do
  begin
    if self.CDS_Main.fieldbyname('SKID').asstring='' then
    begin
      FColorFlag:=Trim(self.CDS_Main.fieldbyname('BPCode').asstring);
    end
    else
    FColorFlag:=Trim(self.CDS_Main.fieldbyname('SKID').asstring);
    if ShowModal=1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmMLMangeRS.Button1Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then exit;
  if Application.MessageBox('确定要修改门幅克重吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('update ML_Manage set MLMF='''+trim(DMLMF.Text)+''' ');
    sql.Add(',MLKZ='''+trim(DMLKZ.Text)+''' ');
    sql.Add('where MLID='''+Trim(CDS_Main.fieldbyname('MLID').AsString)+'''');
    ExecSQL;
  end;
  with CDS_Main do
  begin
    edit;
    FieldByName('MLMF').Value:=trim(DMLMF.Text);
    FieldByName('MLKZ').Value:=trim(DMLKZ.Text);
  end;
end;

procedure TfrmMLMangeRS.DYIDKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Close;
        sql.Clear;
        sql.Add('select A.*,B.*,C.DYID,D.ColNo colorNo,D.ColNameKH colorName,B.ColNameEng colorNameEng ');
        sql.Add(',BP.SKID,BP.BPCode');
        sql.Add('from BP_DY C ');
        sql.Add('inner join ML_Manage A on A.MLID=C.MLID ');
        sql.add('left join BP_ZDY BP on A.MBPID=BP.BPID ');
        sql.Add('left join BP_ColZDY D on D.PTID=C.TFID and BP.SKID=D.SKID ');
        sql.Add('left join RT_PTColor B on B.PTID=D.PTID ');
        sql.Add(' Where C.DYID='''+Trim(DYID.Text)+'''');
        //ShowMessage(sql.Text);
        Open;
      end;
      SCreateCDS20(ADOQueryMain,CDS_Main);
      SInitCDSData20(ADOQueryMain,CDS_Main);
      DYID.Text:='';
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

procedure TfrmMLMangeRS.N2Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    SQL.Add('select * from BP_DY ');
    sql.Add('where MLID='''+trim(CDS_Main.fieldbyname('MLID').AsString)+'''');
    Open;
  end;
  if ADOQueryCmd.IsEmpty=false then
  begin
    if Application.MessageBox('数据已打印确定要删除吗?','提示',32+4)<>IDYES then Exit;
  end
  else
  begin
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  end;
  with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('delete ML_Manage where MLID='''+Trim(CDS_Main.fieldbyname('MLID').AsString)+'''');
    sql.Add('delete ML_Manage_PB where MLID='''+Trim(CDS_Main.fieldbyname('MLID').AsString)+'''');
    sql.Add('delete ML_Manage_GX where MLID='''+Trim(CDS_Main.fieldbyname('MLID').AsString)+'''');
    ExecSQL;
  end;
  CDS_Main.Delete;
end;

procedure TfrmMLMangeRS.N1Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  if CDS_Main.FieldByName('GYType').AsString='染色' then
  begin
    try
      frmMLManage_LRRS:=TfrmMLManage_LRRS.Create(Application);
      with frmMLManage_LRRS do
      begin
        FCYID:=Trim(Self.CDS_Main.fieldbyname('MLID').AsString);
        FGYName:='染色';
        if ShowModal=1 then
        begin
          Self.InitGrid();
        end;
      end;
    finally
      frmMLManage_LRRS.Free;
    end;
  end;
end;

procedure TfrmMLMangeRS.N3Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  if CDS_Main.FieldByName('GYType').AsString='染色' then
  begin
    try
      frmMLManage_LRRS:=TfrmMLManage_LRRS.Create(Application);
      with frmMLManage_LRRS do
      begin
        FCYID:=Trim(Self.CDS_Main.fieldbyname('MLID').AsString);
        FGYName:='染色';
        FZ:='1';
        if ShowModal=1 then
        begin
          Self.InitGrid();
        end;
      end;
    finally
      frmMLManage_LRRS.Free;
    end;
  end;
end;

procedure TfrmMLMangeRS.cxButton1Click(Sender: TObject);
var i,j,x:Integer;
begin
  i:=0;
  j:=0;
  frmBPZDY_PanelCX:=TfrmBPZDY_PanelCX.create(self);
  with frmBPZDY_PanelCX do
  begin
    FColorFlag:=Trim(self.CDS_Main.fieldbyname('SKID').asstring);
    FBPID:=Trim(self.CDS_Main.fieldbyname('MBPID').asstring);
    FMLID:=Trim(Self.CDS_Main.fieldbyname('MLID').AsString);
    if ShowModal=1 then
    begin

    end;
    free;
  end;
  panel3.Visible:=False;
end;

procedure TfrmMLMangeRS.cxButton2Click(Sender: TObject);
var maxno,MaxSub:string;
   fPrintFile,Txt,fImagePath:string;
   Porderno:string;
   i,j:Integer;
   Moudle: THandle;
   Makebar:TMakebar;
   Mixtext:TMixtext;
begin
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    SQL.Add('select * from BP_DY ');
    sql.Add('where MLID='''+trim(CDS_Main.fieldbyname('MLID').AsString)+'''');
    sql.Add(' and DYType=''面料''');
    //ShowMessage(sql.Text);
    Open;
  end;
  if ADOQueryCmd.IsEmpty then
  begin
    if GetLSNo(ADOQueryTemp,maxno,'DY','BP_DY',3,1)=False then
    begin
      Application.MessageBox('取最大号失败!','提示',0);
      Exit;
    end;
  end
  else
  begin
    maxno:=Trim(ADOQueryCmd.fieldbyname('DYID').AsString);
  end;
  with ADOQueryCmd do
  begin
    if IsEmpty then
    begin
      Append;
      FieldByName('filler').Value:=Trim(DName);
      FieldByName('DYID').Value:=Trim(maxno);
    end
    else
    begin
      edit;
      FieldByName('laster').Value:=Trim(DName);
      FieldByName('lasttime').Value:=SGetServerDate(ADOQueryTemp);
    end;
    FieldByName('MLID').Value:=Trim(CDS_Main.fieldbyname('MLID').AsString);
    FieldByName('TFID').Value:=Trim(CDS_Main.fieldbyname('SKID').AsString);
    FieldByName('DYType').Value:='面料';
    FieldByName('BQType').Value:='染色面料标签';
    post;
  end;
  //////////记录
  if GetLSNo(ADOQueryTemp,MaxSub,'JL','BP_DY_JL',3,1)=False then
  begin
    Application.MessageBox('取最大号失败!','提示',0);
    Exit;
  end;
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    SQL.Add('select * from BP_DY_JL ');
    sql.Add('where 1=2');
    Open;
  end;
  with ADOQueryCmd do
  begin
    Append;
    FieldByName('filler').Value:=Trim(DName);
    FieldByName('JLID').Value:=Trim(MaxSub);
    FieldByName('DYID').Value:=Trim(maxno);
    FieldByName('MLID').Value:=Trim(CDS_Main.fieldbyname('MLID').AsString);
    FieldByName('TFID').Value:=Trim(CDS_Main.fieldbyname('SKID').AsString);
    FieldByName('BQType').Value:='染色面料标签';
    post;
  end;
  //打印
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\染色面料标签.rmf';
  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.*,C.DYID,D.ColNo colorNo,D.ColNameKH colorName,B.ColNameEng colorNameEng ');
    sql.Add('from BP_DY C ');
    sql.Add('inner join ML_Manage A on A.MLID=C.MLID ');
    sql.add('left join BP_ZDY BP on A.MBPID=BP.BPID ');
    sql.Add('left join BP_ColZDY D on D.PTID=C.TFID and BP.SKID=D.SKID ');
    sql.Add('left join RT_PTColor B on B.PTID=D.PTID ');
    sql.Add(' Where C.DYID='''+Trim(maxno)+'''');
    //ShowMessage(sql.Text);
    Open;
  end;
  SCreateCDS20(ADOQueryPrint,CDS_Print);
  SInitCDSData20(ADOQueryPrint,CDS_Print);
  try
    Moudle:=LoadLibrary('MakeQRBarcode.dll');
    @Makebar:=GetProcAddress(Moudle,'Make');
    @Mixtext:=GetProcAddress(Moudle,'MixText');
    Txt:=Trim(CDS_Print.fieldbyname('DYID').AsString);
    fImagePath:=ExtractFilePath(Application.ExeName)+'image\temp.bmp';
    if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName)+'image')) then
      CreateDirectory(pchar(ExtractFilePath(Application.ExeName)+'image'),nil);
    if FileExists(fImagePath) then DeleteFile(fImagePath);
    Makebar(pchar(Txt),Length(Txt),3,3,0,PChar(fImagePath),3);
  except
    application.MessageBox('条形码生成失败！','提示信息',MB_ICONERROR);
    exit;
  end;
  if FileExists(fPrintFile) then
  begin
    RMVariables['QRBARCODE']:=fImagePath;
    RM1.LoadFromFile(fPrintFile);
    //RM1.ShowReport;
    RM1.PrintReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\染色面料标签.rmf'),'提示',0);
    exit;
  end;
  panel3.Visible:=false;
end;

procedure TfrmMLMangeRS.Image1Click(Sender: TObject);
begin
  Panel3.Visible:=false;
end;

procedure TfrmMLMangeRS.cxButton4Click(Sender: TObject);
var maxno,MaxSub:string;
   fPrintFile,Txt,fImagePath:string;
   Porderno:string;
   i,j:Integer;
   Moudle: THandle;
   Makebar:TMakebar;
   Mixtext:TMixtext;
begin
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    SQL.Add('select * from BP_DY ');
    sql.Add('where MLID='''+trim(CDS_Main.fieldbyname('MLID').AsString)+'''');
    sql.Add(' and DYType=''面料''');
    //ShowMessage(sql.Text);
    Open;
  end;
  if ADOQueryCmd.IsEmpty then
  begin
    if GetLSNo(ADOQueryTemp,maxno,'DY','BP_DY',3,1)=False then
    begin
      Application.MessageBox('取最大号失败!','提示',0);
      Exit;
    end;
  end
  else
  begin
    maxno:=Trim(ADOQueryCmd.fieldbyname('DYID').AsString);
  end;
  with ADOQueryCmd do
  begin
    if IsEmpty then
    begin
      Append;
      FieldByName('filler').Value:=Trim(DName);
      FieldByName('DYID').Value:=Trim(maxno);
    end
    else
    begin
      edit;
      FieldByName('laster').Value:=Trim(DName);
      FieldByName('lasttime').Value:=SGetServerDate(ADOQueryTemp);
    end;
    FieldByName('MLID').Value:=Trim(CDS_Main.fieldbyname('MLID').AsString);
    FieldByName('TFID').Value:=Trim(CDS_Main.fieldbyname('SKID').AsString);
    FieldByName('DYType').Value:='面料';
    FieldByName('BQType').Value:='染色客户标签';
    post;
  end;
  //////////记录
  if GetLSNo(ADOQueryTemp,MaxSub,'JL','BP_DY_JL',3,1)=False then
  begin
    Application.MessageBox('取最大号失败!','提示',0);
    Exit;
  end;
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    SQL.Add('select * from BP_DY_JL ');
    sql.Add('where 1=2');
    Open;
  end;
  with ADOQueryCmd do
  begin
    Append;
    FieldByName('filler').Value:=Trim(DName);
    FieldByName('JLID').Value:=Trim(MaxSub);
    FieldByName('DYID').Value:=Trim(maxno);
    FieldByName('MLID').Value:=Trim(CDS_Main.fieldbyname('MLID').AsString);
    FieldByName('TFID').Value:=Trim(CDS_Main.fieldbyname('SKID').AsString);
    FieldByName('BQType').Value:='染色客户标签';
    post;
  end;
  //打印
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\染色客户标签.rmf';
  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.*,C.DYID,D.ColNo colorNo,D.ColNameKH colorName,B.ColNameEng colorNameEng ');
    sql.Add('from BP_DY C ');
    sql.Add('inner join ML_Manage A on A.MLID=C.MLID ');
    sql.add('left join BP_ZDY BP on A.MBPID=BP.BPID ');
    sql.Add('left join BP_ColZDY D on D.PTID=C.TFID and BP.SKID=D.SKID ');
    sql.Add('left join RT_PTColor B on B.PTID=D.PTID ');
    sql.Add(' Where C.DYID='''+Trim(maxno)+'''');
    //ShowMessage(sql.Text);
    Open;
  end;
  SCreateCDS20(ADOQueryPrint,CDS_Print);
  SInitCDSData20(ADOQueryPrint,CDS_Print);
  try
    Moudle:=LoadLibrary('MakeQRBarcode.dll');
    @Makebar:=GetProcAddress(Moudle,'Make');
    @Mixtext:=GetProcAddress(Moudle,'MixText');
    Txt:=Trim(CDS_Print.fieldbyname('DYID').AsString);
    fImagePath:=ExtractFilePath(Application.ExeName)+'image\temp.bmp';
    if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName)+'image')) then
      CreateDirectory(pchar(ExtractFilePath(Application.ExeName)+'image'),nil);
    if FileExists(fImagePath) then DeleteFile(fImagePath);
    Makebar(pchar(Txt),Length(Txt),3,3,0,PChar(fImagePath),3);
  except
    application.MessageBox('条形码生成失败！','提示信息',MB_ICONERROR);
    exit;
  end;
  if FileExists(fPrintFile) then
  begin
    RMVariables['QRBARCODE']:=fImagePath;
    RM1.LoadFromFile(fPrintFile);
    //RM1.ShowReport;
    RM1.PrintReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\染色客户标签.rmf'),'提示',0);
    exit;
  end;
end;

procedure TfrmMLMangeRS.N4Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then exit;
  Panel3.Visible:=true;
end;

end.
