unit U_MLManage_LRTJDY;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, ADODB, DBClient, cxGridLevel,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses,
  cxControls, cxGridCustomView, cxGrid, ComCtrls, ToolWin,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxContainer, cxTextEdit,
  cxMaskEdit, cxDropDownEdit, cxCalendar, StdCtrls, ExtCtrls, BtnEdit,
  cxButtonEdit,jpeg,U_SLT,Math, Menus, RM_Common, RM_Class, RM_GridReport,
  RM_System, RM_Dataset,U_SLT_PBSK,U_BPZdy_LRSHK, IdBaseComponent,U_SLT_TJ_SX,
  IdComponent, IdTCPConnection, IdTCPClient, IdFTP,IniFiles,ShellAPI;

type
  TfrmMLManage_LRTJDY = class(TForm)
    CDS_Sub: TClientDataSet;
    ADOQueryMain: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ADOQueryTemp: TADOQuery;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Panel1: TPanel;
    Order_GX: TClientDataSet;
    DataSource1: TDataSource;
    OrdBP_SH: TClientDataSet;
    GSNo: TLabel;
    Ord_HX: TClientDataSet;
    GYName: TLabel;
    Panel9: TPanel;
    Label2: TLabel;
    MLKZ: TEdit;
    Label1: TLabel;
    Label3: TLabel;
    adoqueryPicture: TADOQuery;
    RMDB_Main: TRMDBDataSet;
    RM1: TRMGridReport;
    ADOQueryPrint: TADOQuery;
    CDS_Print: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    SaveDialog1: TSaveDialog;
    ODPat: TOpenDialog;
    IdFTP1: TIdFTP;
    PopupMenu2: TPopupMenu;
    MenuItem1: TMenuItem;
    Ord_ZB: TClientDataSet;
    Panel2: TPanel;
    Ord_Col: TClientDataSet;
    DataSource2: TDataSource;
    ADOQueryCol: TADOQuery;
    TJName: TLabel;
    TJGYMX: TLabel;
    Panel14: TPanel;
    Panel39: TPanel;
    Label11: TLabel;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    V1Ssel: TcxGridDBColumn;
    V1BPCode: TcxGridDBColumn;
    V1BPName: TcxGridDBColumn;
    V1BPMF: TcxGridDBColumn;
    V1BPKZ: TcxGridDBColumn;
    V1BPJS: TcxGridDBColumn;
    v1BPMiDu: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    ToolBar4: TToolBar;
    Panel12: TPanel;
    Panel42: TPanel;
    Label79: TLabel;
    Label80: TLabel;
    MLXXNO: TEdit;
    MLXXMF: TEdit;
    MLXXKZ: TEdit;
    MLXXColNo: TEdit;
    Label5: TLabel;
    MLXXCol: TEdit;
    MLXXGYName: TBtnEditA;
    MLName: TEdit;
    MLNo: TEdit;
    ToolBar3: TToolBar;
    Panel3: TPanel;
    Label8: TLabel;
    Panel4: TPanel;
    ScrollBox2: TScrollBox;
    MLXXNote: TMemo;
    Panel5: TPanel;
    Label4: TLabel;
    Label12: TLabel;
    MBPID: TEdit;
    PTID: TEdit;
    Image1: TImage;
    MLTPID: TEdit;
    Image12: TImage;
    ADOQuery1: TADOQuery;
    ADOCmd: TADOQuery;
    Panel16: TPanel;
    MLCF: TBtnEditA;
    MLMF: TBtnEditA;
    ScrollBox3: TPanel;
    LBCPAP: TLabel;
    BTLP: TButton;
    BTNP: TButton;
    TJML: TEdit;
    HXType: TBtnEditA;
    TJGYName: TBtnEditA;
    MLXXName: TEdit;
    Button1: TButton;
    RM2: TRMGridReport;
    Button2: TButton;
    Button3: TButton;
    GYLX: TEdit;
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure N1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure MenuItem1Click(Sender: TObject);
    procedure ToSelPBClick(Sender: TObject);
    procedure ToolButton10Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure TSaveClick(Sender: TObject);
    procedure Image12DblClick(Sender: TObject);
    procedure Image11DblClick(Sender: TObject);
    procedure MLCFBtnClick(Sender: TObject);
    procedure MLMFBtnClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure BTLPClick(Sender: TObject);
    procedure BTNPClick(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    lstPat,lstPat2: TStringList;
    Fint,my,mz:Integer;
    FangXiang1,FangXiang2:String;
    procedure InitSubGrid();
    function  SaveData():Boolean;
    procedure InitColor();
    procedure BHCZhu();
    procedure ReadINIFile10();
    procedure SavePrint(var CP,TP:string);
    procedure CreThumb(AJPeg:TJPEGImage;Image1:TImage;Width, Height: Integer);
    procedure SaveImage(maxnoWB:string);
    procedure initFY();
    { Private declarations }
  public
    FCYID,FCYCode,FCPID,FCPNO,FBPID,FGYName,FML,FGYLX,FGSNo,FHXBPID,FGSName,FSKID,FBPIDSH,formid:String;
    FGYLXName,PatFile,FTJCoNo,FPTID,FileName,FileName1:string;
    //viewFlag:Boolean;
    procedure initimageSH();
    procedure imagePL(FFF:Integer);
    { Public declarations }
  end;

var
  frmMLManage_LRTJDY: TfrmMLManage_LRTJDY;
  Mach1: array of TfrmSLT_TJ_SX;
  Mach: array of TfrmSLT_PBSK;
implementation
uses
  U_DataLink,U_Fun,U_BPZdy_SH,U_MLMange_ADDCX, U_BPZdy_HXK,U_BPZdy_LRPB,U_BPZdy_LRGX,U_BPZdy_RSSel,
  U_BPZdy_PanelCX, U_BPZdy_YT,U_BPZdy_Panel,U_BPZdy_LRTJ,U_FileUp_TPSH,U_MLMangeRS_Sel,U_BPZdy_Panel_M,U_BPZdy_LRTJ1,
  U_BPZdy_TJHXK_M3_Sel,U_MLManage_LRRS,U_ZDYHelp,U_MLManage_LRRS_Col,U_RTPTColor,U_ZDYHelp_Col,U_HXKTJ_Type,
  U_SCPerson,U_BPZdy_ColTJ;

{$R *.dfm}

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

procedure TfrmMLManage_LRTJDY.InitColor();
var
  fsj:string;
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from RT_PTColor where PTID='''+Trim(Self.PTID.Text)+'''');
    //ShowMessage(sql.Text);
    Open;
  end;
  fsj:=Trim(ADOQueryTemp.fieldbyname('ColDaiMa').AsString);
  if ADOQueryTemp.IsEmpty=False then
  Panel42.Color:=StrToInt('$'+Trim(fsj));
end;

procedure TfrmMLManage_LRTJDY.initFY();
begin
  with adoqueryPicture do
  begin
    close;
    sql.Clear;
    sql.Add('select Count(IMID) GS from Image_Info ');
    sql.Add('where TJML='''+trim(TJML.Text)+'''');
    Open;
  end;
  my:=1;
  mz:=Ceil(adoqueryPicture.fieldbyname('GS').AsInteger/30);
  LBCPAP.Caption:=IntToStr(my)+'/'+inttostr(mz);
end;

procedure TfrmMLManage_LRTJDY.initimageSH();
var
  i,j,p,x:integer;
  jpg:TJpegImage;
  myStream: TADOBlobStream;
  Fstr:string;
begin
  Fstr:=' and TJML='''+trim(TJML.Text)+''' and TJGYName='''+trim(TJGYName.Text)+''' ';
  //ShowMessage(TJML.Text);
  j:=length(Mach1);
  if j>0 then
  begin
    for i:=0 to j-1 do
    begin
      Mach1[i].free;
    end;
  end;
  SetLength(Mach1, 0);
  try
    with adoqueryPicture do
    begin
      close;
      sql.Clear;
      sql.Add(' exec P_View_Image :WBID,:ImageType,:IFType,:Ye,:YeQty,:WPS  ');
      Parameters.ParamByName('WBID').Value:='CP1910290001';
      Parameters.ParamByName('ImageType').Value:='TJ';
      Parameters.ParamByName('IFType').Value:='小';
      Parameters.ParamByName('Ye').Value:=my;
      Parameters.ParamByName('YeQty').Value:=100;
      Parameters.ParamByName('WPS').Value:=Trim(Fstr);
      open;
    end;
    j:=adoqueryPicture.RecordCount;
    //ShowMessage(IntToStr(j));
    if j<1 then exit;
    adoqueryPicture.DisableControls;
    adoqueryPicture.First;
    SetLength(Mach1, j);
    with adoqueryPicture do
    begin
      First;
      i:=0;
      x:=0;    //列
      p:=0;    //行
      while not eof do
      begin
        if (i<30*my) and (i>=30*(my-1)) then
        begin
          jpg:=TJpegImage.Create();
          myStream:=tadoblobstream.Create(tblobfield(adoqueryPicture.fieldbyname('ImageFile')),bmread);
          jpg.LoadFromStream(myStream);
          if (i-30*(my-1))<10*(p+1) then
          begin

          end
          else
          begin
            p:=p+1;
          end;
          Mach1[i]:=TfrmSLT_TJ_SX.Create(Self);
          Mach1[i].Name:=trim(adoqueryPicture.fieldbyname('IMID').AsString);
          Mach1[i].FImagePath:=trim(adoqueryPicture.fieldbyname('ImagePath').AsString);
          Mach1[i].Parent:=ScrollBox2;
          Mach1[I].Left:=0+(x-10*p)*135;
          Mach1[I].Top:=p*190;
          Mach1[I].FIMID:=trim(adoqueryPicture.fieldbyname('IMID').AsString);
          Mach1[I].FTJHX:=trim(adoqueryPicture.fieldbyname('TJHX').AsString);
          Mach1[I].YW.Caption:=trim(adoqueryPicture.fieldbyname('TJHX').AsString);
          Mach1[I].TJMLNo.Caption:=trim(adoqueryPicture.fieldbyname('TJMLNo').AsString);
          Mach1[I].ZW.Caption:=trim(adoqueryPicture.fieldbyname('TJCol').AsString);
          Mach1[I].SH.Caption:=trim(adoqueryPicture.fieldbyname('TJColNo').AsString);
          Mach1[I].FIMNO:=trim(adoqueryPicture.fieldbyname('IMNO').AsString);
          Mach1[I].FWBID:='CP1910290001';
          Mach1[I].Formid:=self.formid;
          Mach1[I].Memo1.Visible:=true;
          if triM(adoqueryPicture.fieldbyname('IMID').AsString)<>'' then
          begin
            Mach1[i].Init('',adoqueryPicture.fieldbyname('ImagePath').AsString,jpg);
          end;
          Mach1[i].cxImage1.Visible:=True;
          Mach1[i].cxImage1.Properties.Stretch:=True;
          x:=x+1;
        end;
        i:=i+1;
        Next;
      end;
    end;
    adoqueryPicture.EnableControls;
  finally
    jpg.free;
  end;
end;

procedure TfrmMLManage_LRTJDY.SavePrint(var CP,TP:string);
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(CP)+'''');
    sql.Add(' and TFID='''+trim(TP)+'''');
    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(CP);
    FieldByName('TFID').Value:=Trim(TP);
    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(CP);
    FieldByName('TFID').Value:=Trim(TP);
    post;
  end;
  //打印
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\单面料标签染色.rmf';
  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.*,C.DYID from BP_DY C ');
    sql.Add('inner join ML_Manage A on A.MLID=C.MLID ');
    sql.Add('inner join XD_File D on D.XFID=C.TFID ');
    sql.Add('inner join SH_Base B on B.WBID=D.CYID ');
    sql.Add(' Where C.DYID='''+Trim(maxno)+'''');
    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 TfrmMLManage_LRTJDY.InitSubGrid();
var FTPID,FTJNo:String;
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select A.* from ML_Manage A ');
      sql.Add('where MLID='''+trim(FCYID)+'''');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Ord_ZB);
    SInitCDSData20(ADOQueryMain,Ord_ZB);
    if ADOQueryMain.IsEmpty=false then
    begin
      GSNo.Caption:=Trim(ADOQueryMain.FieldByName('GSNo').asstring);
      GYName.Caption:=Trim(ADOQueryMain.FieldByName('GYName').asstring);
      MLNo.Text:=Trim(ADOQueryMain.FieldByName('MLNo').asstring);
      //GYLXName.Caption:=Trim(ADOQueryMain.FieldByName('GYLXName').asstring);
      SCSHDataNew(ADOQueryMain,Panel1,2);
      SCSHDataNew(ADOQueryMain,Panel9,2);
      SCSHDataNew(ADOQueryMain,Panel39,2);
      //SCSHDataNew(ADOQueryMain,Panel6,2);
      FBPID:=Trim(ADOQueryMain.FieldByName('MBPID').Value);
      FSKID:=Trim(ADOQueryMain.FieldByName('MLDLNo').AsString);
      FTJCoNo:=Trim(ADOQueryMain.FieldByName('TJColID').AsString);
      FCPID:=Trim(ADOQueryMain.FieldByName('CPID').asstring);
      TJGYName.Text:=Trim(ADOQueryMain.FieldByName('TJGYName').asstring);
      HXType.Text:=Trim(ADOQueryMain.FieldByName('HXType').asstring);
      if Trim(DParameters1)<>'高权限' then
      begin
        MLXXNO.Enabled:=False;
        MLXXName.Enabled:=false;
        MLXXNO.Color:=clSkyBlue;
        MLXXName.Color:=clSkyBlue;
      end
      else
      begin
        MLXXNO.Enabled:=true;
        MLXXName.Enabled:=true;
      end;
    end
    else
    begin
      if GetLSNo(ADOQueryCmd,FTJNo,'TG','ML_Manage',4,0)=False then
      begin
        Application.MessageBox('取最大号失败!','提示',0);
        Exit;
      end;
      TJML.Text:=Trim(FTJNo);
    end;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;;
      sql.Add('select cast('''' as varchar(50)) RSGYMX,cast('''' as varchar(50)) RSSH,cast('''' as varchar(50)) TJGYMX,cast('''' as varchar(50)) TJSeHao');
      sql.Add(' from RT_PTColor A ');
      sql.Add('where 1=2');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Ord_Col);
    SInitCDSData20(ADOQueryMain,Ord_Col);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmMLManage_LRTJDY.SaveImage(maxnoWB:string);
var
  ImagePath,ImagName,MaxNo,MaxNoFile:String;
  AJpeg:TJPEGImage;
  myStream:TADOBlobStream;
begin
  try
    ImagePath:=Trim(maxnoWB);
    ImagName:=Trim(maxnoWB);
    AJpeg:=TJpegImage.Create();
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('UPdate Image_File Set Valid=''N'' ');
      sql.Add(' where IMID=(select IMID from Image_Info');
      Sql.Add(' where WBID='''+Trim(maxnoWB)+''' and Valid=''Y'')');
      ExecSQL;
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('UPdate Image_Info Set Editer='''+Trim(DName)+''',EditerCode='''+Trim(DCode)+''',EditTime=getdate()');
      sql.Add(',Valid=''N''  where WBID='''+Trim(maxnoWB)+''' and Valid=''Y''  ');
      ExecSQL;
    end;
    if GetLSNo(ADOCmd,MaxNo,'IM','Image_Info',4,1)=False then
    begin
      ADOCmd.Connection.RollbackTrans;
      Application.MessageBox('取图片信息最大号失败！','提示',0);
      Exit;
    end;
    with ADOCmd do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from Image_Info where 1=2');
      Open;
    end;
    with ADOCmd do
    begin
      Append;
      FieldByName('IMID').Value:=Trim(MaxNo);
      FieldByName('WBID').Value:=Trim(maxnoWB);
      FieldByName('ImageName').Value:=Trim(ImagName);
      FieldByName('ImagePath').Value:=Trim(MaxNo)+Trim(ImagName);
      FieldByName('ImageDate').Value:=SGetServerDate(ADOQueryTemp);
      Fieldbyname('ImageType').value:=Trim('YP');
      Fieldbyname('Valid').value:=Trim('Y');
      Post;
    end;
    if GetLSNo(ADOCmd,MaxNoFile,'IF','Image_File',4,1)=False then
    begin
      ADOCmd.Connection.RollbackTrans;
      Application.MessageBox('取图片文件最大号失败！','提示',0);
      Exit;
    end;
    with ADOCmd do
    begin
      close;
      sql.Clear;
      sql.Add(' select *  from Image_File where 1=2');
      open;
    end;
    with ADOCmd do
    begin
      Append;
      FieldByName('IMID').Value:=Trim(MaxNo);
      FieldByName('IFID').Value:=Trim(MaxNoFile);
      Fieldbyname('Valid').value:=Trim('Y');
      FieldByName('ImageWidth').Value:=Image12.Width;
      FieldByName('ImageHeight').Value:=Image12.Height;
      FieldByName('FangXiang').Value:=FangXiang1;
      FieldByName('IFType').Value:='小';
      myStream := TADOBlobStream.Create(TBlobField(ADOCmd.FieldByName('ImageFile')), bmWrite);
      AJpeg.Assign(Image12.Picture.Graphic);
      AJpeg.SaveToStream(myStream);
      myStream.Free;
      Post;
    end;
    if lstPat.Count=1 then
    begin
      try
        ReadINIFile10();
        server:=ReadINIFileStr('SYSTEMSET.INI','SERVER','服务器地址','127.0.0.1');
        IdFTP1.Host :=server;//PicSvr;
        IdFTP1.Username := 'three';
        IdFTP1.Password := '641010';
        IdFTP1.Connect();
      except
        IdFTP1.Quit;
        Application.MessageBox('无法连接到文件服务器，请检查！', '提示', MB_ICONWARNING);
        Exit;
      end;
      if IdFTP1.Connected then
      begin
        IdFTP1.Put(lstPat[0], 'YP'+'\'+Trim(MaxNo)+Trim(ImagName));
      end;
      if IdFTP1.Connected then IdFTP1.Quit;
    end;
  except
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('图片保存失败！','提示',0);
  end;
end;


procedure TfrmMLManage_LRTJDY.FormShow(Sender: TObject);
var
  fsj:String;
begin
  InitSubGrid();
  initFY();
  initimageSH();
  InitColor();
end;

function TfrmMLManage_LRTJDY.SaveData():Boolean;
begin
 
end;

procedure TfrmMLManage_LRTJDY.BHCZhu();
var FBH,FCP,FLX,FLL:string;
    FBHName,FLXName,FLLName:string;
begin
  CDS_Sub.DisableControls;
  with CDS_Sub do
  begin
    First;
    while not eof do
    begin
      FBH:=FBH+trim(CDS_Sub.fieldbyname('BPCode').AsString);
      FBHName:=FBHName+trim(CDS_Sub.fieldbyname('BPName').AsString);
      Next;
    end;
  end;
  CDS_Sub.EnableControls;
  FCP:=FML+FBH;
  Order_GX.DisableControls;
  with Order_GX do
  begin
    First;
    while not eof do
    begin
      FLL:=FLL+trim(Order_GX.fieldbyname('GYCode').AsString);
      FLLName:=FLLName+trim(Order_GX.fieldbyname('GYName').AsString);
      if FLX='' then
      FLX:=trim(Order_GX.fieldbyname('GYCode').AsString)
      else
      FLX:=FLX+'+'+trim(Order_GX.fieldbyname('GYCode').AsString);
      if FLXName='' then
      FLXName:=trim(Order_GX.fieldbyname('GYName').AsString)
      else
      FLXName:=FLXName+'+'+trim(Order_GX.fieldbyname('GYName').AsString);
      Next;
    end;
  end;
  Order_GX.EnableControls;
  GSNo.Caption:=FBH+Trim(FLL);
  GYName.Caption:=FBHName+Trim(FLLName);
  MLNo.Text:=Trim(FCP);
end;

procedure TfrmMLManage_LRTJDY.imagePL(FFF:Integer);
begin

end;

procedure TfrmMLManage_LRTJDY.CreThumb(AJPeg:TJPEGImage;Image1:TImage;Width, Height: Integer);
var
  Bitmap: TBitmap;
  Ratio: Double;
  ARect: TRect;
  AHeight, AHeightOffset: Integer;
  AWidth, AWidthOffset: Integer;
begin
  Bitmap := TBitmap.Create;
  try
    Ratio := AJPeg.Width /AJPeg.Height;
    if Ratio > 1.333 then
    begin
      AHeight := Round(Width / Ratio);
      AHeightOffset := (Height - AHeight) div 2;
      AWidth := Width;
      AWidthOffset := 0;
    end
    else
    begin
      AWidth := Round(Height * Ratio);
      AWidthOffset := (Width - AWidth) div 2;
      AHeight := Height;
      AHeightOffset := 0;
    end;
    Bitmap.Width := Width;
    Bitmap.Height := Height;
    Bitmap.Canvas.Brush.Color := clBtnFace;
    Bitmap.Canvas.FillRect(Rect(0, 0, Width, Height));
    ARect := Rect(AWidthOffset, AHeightOffset, AWidth + AWidthOffset, AHeight + AHeightOffset);
    Bitmap.Canvas.StretchDraw(ARect, AJPeg);
    Image1.Picture.Assign(BitMap);
  finally
    Bitmap.Free;
  end;
end;

procedure TfrmMLManage_LRTJDY.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Finalize(Mach1);
  Finalize(Mach);
end;

procedure TfrmMLManage_LRTJDY.N1Click(Sender: TObject);
var
  i:Integer;
begin
  //ShowMessage(FPT);
  FrmBPZdy_YT:=TFrmBPZdy_YT.create(Self);
  with FrmBPZdy_YT do
  begin
    Panel1.Color:=StrToInt('$'+OrdBP_SH.fieldbyname('ColDaiMa').Value);
    Label1.Caption:=Trim(OrdBP_SH.fieldbyname('PTID').AsString);
    Label2.Caption:=Trim(OrdBP_SH.fieldbyname('ColNameEng').AsString);
    Label3.Caption:=Trim(OrdBP_SH.fieldbyname('ColName').AsString);
    Label4.Caption:=Trim(OrdBP_SH.fieldbyname('ColNameKH').AsString);
    Label5.Visible:=true;
    Label5.Caption:=Trim(OrdBP_SH.fieldbyname('ColNo').AsString);
    if showmodal=1 then
    begin

    end;
    free;
  end;
end;


procedure TfrmMLManage_LRTJDY.FormCreate(Sender: TObject);
begin
  lstPat := TStringList.Create;
  lstPat2 := TStringList.Create;
end;

procedure TfrmMLManage_LRTJDY.MenuItem1Click(Sender: TObject);
var
  i:Integer;
begin
  FrmBPZdy_YT:=TFrmBPZdy_YT.create(Self);
  with FrmBPZdy_YT do
  begin
    Panel1.Color:=StrToInt('$'+Ord_ZB.fieldbyname('ColDaiMa').Value);
    Label1.Caption:=Trim(Ord_ZB.fieldbyname('PTID').AsString);
    Label2.Caption:=Trim(Ord_ZB.fieldbyname('ColNameEng').AsString);
    Label3.Caption:=Trim(Ord_ZB.fieldbyname('ColName').AsString);
    Label4.Caption:=Trim(Ord_ZB.fieldbyname('ColNameKH').AsString);
    Label5.Visible:=true;
    Label5.Caption:=Trim(Ord_ZB.fieldbyname('ColNo').AsString);
    if showmodal=1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmMLManage_LRTJDY.ToSelPBClick(Sender: TObject);
begin
  if CDS_Sub.IsEmpty=false then
  begin
    CDS_Sub.Delete;
    //Application.MessageBox('已存在坯布信息','提示');
   // exit;
  end;

end;

procedure TfrmMLManage_LRTJDY.ToolButton10Click(Sender: TObject);
begin
  if CDS_Sub.IsEmpty=false then
  begin
    CDS_Sub.Delete;
  end;
end;

procedure TfrmMLManage_LRTJDY.N2Click(Sender: TObject);
begin
  try
    frmMLManage_LRRS_Col:=TfrmMLManage_LRRS_Col.Create(Application);
    with frmMLManage_LRRS_Col do
    begin
      FCYID:=Trim(Self.MBPID.Text);
      FGYName:='染色';
      viewFlag:=True;
      if ShowModal=1 then
      begin
        MLXXCol.Text:=Trim(OrdBP_SH.fieldbyname('ColNameKH').AsString);
        MLXXColNo.Text:=Trim(OrdBP_SH.fieldbyname('ColNo').AsString);
        self.PTID.Text:=Trim(OrdBP_SH.fieldbyname('PTID').AsString);
        if Trim(PTID.Text)<>'' then
        begin
          InitColor();
        end;
        with ADOQuery1 do
        begin
          Close;
          SQL.Clear;
          sql.Add('delete from Image_File where ');
          sql.Add('IMID in (select IMID from Image_Info where WBID='''+Trim(MLTPID.Text)+''' and Valid=''Y'')');
          sql.Add('delete from Image_Info ');
          sql.Add(' where WBID='''+Trim(MLTPID.Text)+''' and Valid=''Y''');
          ExecSQL;
        end;
        MLTPID.Text:='';
      end;
    end;
  finally
    frmMLManage_LRRS_Col.Free;
  end;
end;

procedure TfrmMLManage_LRTJDY.TSaveClick(Sender: TObject);
var FBH:string;
begin
  if Trim(MLName.Text)='' then
  begin
    Application.MessageBox('品名不能为空!','提示',0);
    Exit;
  end;
  {if Trim(MLXXCol.Text)='' then
  begin
    Application.MessageBox('颜色不能为空!','提示',0);
    Exit;
  end;
  if Trim(MLXXColNo.Text)='' then
  begin
    Application.MessageBox('色号不能为空!','提示',0);
    Exit;
  end;}
  if Trim(MLXXGYName.Text)='' then
  begin
    Application.MessageBox('工艺不能为空!','提示',0);
    Exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！','提示',0);
    Finalize(Mach1);
    Finalize(Mach);
    ModalResult:=1;
  end;
end;

procedure TfrmMLManage_LRTJDY.Image12DblClick(Sender: TObject);
var
  IdFTP1: TIdFTP;
  FPath,FFName:string;
  FInt:integer;
  maxno:string;
  j,i:Integer;
  fPrintFile,fFileName:string;
begin
  if Application.MessageBox('原图下载需要等待时间，确定要查看原图吗？','提示',32+4)<>IDYES then Exit;
  try
    ReadINIFile10();
    server:=ReadINIFileStr('SYSTEMSET.INI','SERVER','服务器地址','127.0.0.1');
    IdFTP1:=TIdFTP.Create(self);
    IdFTP1.Host :=server;
    IdFTP1.Username := 'three';
    IdFTP1.Password := '641010';
    IdFTP1.Connect();
  except
    IdFTP1.Quit;
    IdFTP1.Free;
    Application.MessageBox('无法连接到文件服务器，请检查！', '提示', MB_ICONWARNING);
    Exit;
  end;
  Panel16.Visible:=true;
  Panel16.Refresh;
  fPrintFile:= ExtractFilePath(Application.ExeName)+'Photo\';
  if not DirectoryExists(ExtractFileDir(FPrintFile)) then
    CreateDir(ExtractFileDir(fPrintFile));
  FFName:=Trim(FileName);
  FFName:=fPrintFile+FFName+'.jpg';
  if not FileExists(FFName) then
  begin
    IdFTP1.Get('YP\'+FileName,FFName);
  end;
  if IdFTP1.Connected then
  begin
    IdFTP1.Quit;
    IdFTP1.Free;
  end;
  Panel16.Visible:=false;
  ShellExecute(Handle, 'open',PChar(FFName),'', '', SW_SHOWNORMAL);
end;

procedure TfrmMLManage_LRTJDY.Image11DblClick(Sender: TObject);
var
  IdFTP1: TIdFTP;
  FPath,FFName:string;
  FInt:integer;
  maxno:string;
  j,i:Integer;
  fPrintFile,fFileName:string;
begin
  if Application.MessageBox('原图下载需要等待时间，确定要查看原图吗？','提示',32+4)<>IDYES then Exit;
  try
    ReadINIFile10();
    server:=ReadINIFileStr('SYSTEMSET.INI','SERVER','服务器地址','127.0.0.1');
    IdFTP1:=TIdFTP.Create(self);
    IdFTP1.Host :=server;
    IdFTP1.Username := 'three';
    IdFTP1.Password := '641010';
    IdFTP1.Connect();
  except
    IdFTP1.Quit;
    IdFTP1.Free;
    Application.MessageBox('无法连接到文件服务器，请检查！', '提示', MB_ICONWARNING);
    Exit;
  end;
  Panel16.Visible:=true;
  Panel16.Refresh;
  fPrintFile:= ExtractFilePath(Application.ExeName)+'Photo\';
  if not DirectoryExists(ExtractFileDir(FPrintFile)) then
    CreateDir(ExtractFileDir(fPrintFile));
  FFName:=Trim(FileName1);
  FFName:=fPrintFile+FFName+'.jpg';
  if not FileExists(FFName) then
  begin
    IdFTP1.Get('TJ\'+FileName1,FFName);
  end;
  if IdFTP1.Connected then
  begin
    IdFTP1.Quit;
    IdFTP1.Free;
  end;
  Panel16.Visible:=false;
  ShellExecute(Handle, 'open',PChar(FFName),'', '', SW_SHOWNORMAL);
end;

procedure TfrmMLManage_LRTJDY.MLCFBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.create(self);
  with frmZDYHelp do
  begin
    flag:='MLCF';
    flagname:='成份';
    if showmodal=1 then
    begin
      MLCF.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

procedure TfrmMLManage_LRTJDY.MLMFBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.create(self);
  with frmZDYHelp do
  begin
    flag:='MLMF';
    flagname:='门幅';
    if showmodal=1 then
    begin
      MLMF.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

procedure TfrmMLManage_LRTJDY.Button1Click(Sender: TObject);
var
   fPrintFile,Txt,fImagePath,maxno:string;
   i,j,c,p:Integer;
   Moudle: THandle;
   Makebar:TMakebar;
   Mixtext:TMixtext;
begin
  p:=0;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    SQL.Add('select A.*,B.*,FDYID=Cast('''' as varchar(100)),FQRBARCODE=Cast('''' as varchar(100))');
    SQL.Add(' from Image_Info A ');
    sql.Add('inner join ML_Manage B on B.TJML=A.TJML');
    sql.Add(' where 1=2');
    //ShowMessage(sql.Text);
    Open;
  end;
  SCreateCDS20(ADOQueryCmd,CDS_Print);
  with ScrollBox2 do
  begin
    for j:=0 to ControlCount-1 do
    begin
      if Controls[j] is TfrmSLT_TJ_SX then
      begin
        with TfrmSLT_TJ_SX(Controls[j]) do
        begin
          for c:=0 to ControlCount-1 do
          begin
            if Controls[c] is TMemo then
            begin
              if TMemo(Controls[c]).Text<>'' then
              begin
                p:=p+1;
                if self.formid='1' then
                begin
                  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\烫金面料颜色标签.rmf';
                  if FileExists(fPrintFile)=False then
                  begin
                    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\烫金面料颜色标签.rmf'),'提示',0);
                    exit;
                  end;
                end;
                if self.formid='2' then
                begin
                  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\烫金小色标.rmf';
                  if FileExists(fPrintFile)=False then
                  begin
                    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\烫金小色标.rmf'),'提示',0);
                    exit;
                  end;
                end;
                if self.formid='3' then
                begin
                  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\烫金客户标签.rmf';
                  if FileExists(fPrintFile)=False then
                  begin
                    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\烫金客户标签.rmf'),'提示',0);
                    exit;
                  end;
                end;
                try
                  ADOQueryCmd.Connection.BeginTrans;
                  if GetLSNo(ADOQueryCmd,maxno,'TGML','BP_DY',4,1,)=False then
                  begin
                    ADOQueryCmd.Connection.RollbackTrans;
                    Application.MessageBox('取样品打印最大号失败!','提示',0);
                    Exit;
                  end;
                  with ADOQueryCmd do
                  begin
                    Close;
                    sql.Clear;
                    SQL.Add('select * from BP_DY where DYId='''+Trim(maxno)+'''');
                    Open;
                  end;
                  with ADOQueryCmd do
                  begin
                    Append;
                    FieldByName('MLID').Value:=Trim(FCYID);
                    FieldByName('TFID').Value:=Trim(FIMID);
                    FieldByName('DYId').Value:=Trim(maxno);
                    FieldByName('Filler').Value:=Trim(DName);
                    FieldByName('FillerCode').Value:=Trim(DCode);
                    FieldByName('Valid').Value:='Y';
                    Post;
                  end;
                  ADOQueryCmd.Connection.CommitTrans;
                except
                  ADOQueryCmd.Connection.RollbackTrans;
                  Application.MessageBox('保存打印流水号异常！','提示',0);
                  Exit;
                end;
                with ADOQueryCmd do
                begin
                  Close;
                  sql.Clear;
                  SQL.Add('select A.*,B.*,FDYID=Cast('''' as varchar(100)),FQRBARCODE=Cast('''' as varchar(100)) ');
                  sql.Add('from Image_Info A ');
                  sql.Add('inner join ML_Manage B on B.TJML=A.TJML');
                  sql.Add(' where A.IMID='''+Trim(FIMID)+'''');
                  sql.Add(' and B.MLID='''+trim(FCYID)+'''');
                  //ShowMessage(sql.Text);
                  Open;
                end;
                if (self.formid='1') or (self.formid='3') then
                begin
                  SCreateCDS20(ADOQueryCmd,CDS_Print);
                  SInitCDSData20(ADOQueryCmd,CDS_Print);
                end
                else
                SInitCDSData20(ADOQueryCmd,CDS_Print);
                //ShowMessage(IntToStr(CDS_Print.RecordCount));
                try
                  Moudle:=LoadLibrary('MakeQRBarcode.dll');
                  @Makebar:=GetProcAddress(Moudle,'Make');
                  @Mixtext:=GetProcAddress(Moudle,'MixText');
                  Txt:=Trim(maxno);
                  fImagePath:=ExtractFilePath(Application.ExeName)+'image\temp'+inttostr(p)+'.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 self.formid='2' then
                begin
                  CDS_Print.Locate('IMID',FIMID,[]);
                  with CDS_Print do
                  begin
                    edit;
                    FieldByName('FDYID').AsString:=Trim(maxno);
                    FieldByName('FQRBARCODE').Value:=Trim(fImagePath);
                  end;
                end;
                if (Self.formid='1') or (self.formid='3') then
                begin
                  RMVariables['QRBARCODE']:=fImagePath;
                  RMVariables['DYID']:=maxno;
                  RM1.LoadFromFile(fPrintFile);
                 // RM1.ShowReport;
                  RM1.PrintReport;
                end;
              end;
            end;
          end;
        end;
      end;
    end;
  end;
  if self.formid='2' then
  begin
    RM2.LoadFromFile(fPrintFile);
    //RM2.ShowReport;
    RM2.PrintReport;
  end;
  ShowMessage('共打印'+inttostr(p)+'张标签');
end;

procedure TfrmMLManage_LRTJDY.BTLPClick(Sender: TObject);
begin
  if my<=1 then exit;
  my:=my-1;
  LBCPAP.Caption:=IntToStr(my)+'/'+inttostr(mz);
  initimageSH();
end;

procedure TfrmMLManage_LRTJDY.BTNPClick(Sender: TObject);
begin
  if my>=mz then exit;
  my:=my+1;
  LBCPAP.Caption:=IntToStr(my)+'/'+inttostr(mz);
  initimageSH();
end;

procedure TfrmMLManage_LRTJDY.Button2Click(Sender: TObject);
var j,c:integer;
begin
  with ScrollBox2 do
  begin
    for j:=0 to ControlCount-1 do
    begin
      if Controls[j] is TfrmSLT_TJ_SX then
      begin
        with TfrmSLT_TJ_SX(Controls[j]) do
        begin
          for c:=0 to ControlCount-1 do
          begin
            if Controls[c] is TMemo then
            begin
              TMemo(Controls[c]).Text:='√';
              TMemo(Controls[c]).Color:=clRed;
            end;
          end;
        end;
      end;
    end;
  end;
end;

procedure TfrmMLManage_LRTJDY.Button3Click(Sender: TObject);
var j,c:integer;
begin
  with ScrollBox2 do
  begin
    for j:=0 to ControlCount-1 do
    begin
      if Controls[j] is TfrmSLT_TJ_SX then
      begin
        with TfrmSLT_TJ_SX(Controls[j]) do
        begin
          for c:=0 to ControlCount-1 do
          begin
            if Controls[c] is TMemo then
            begin
              TMemo(Controls[c]).Text:='';
              TMemo(Controls[c]).Color:=clWindow;
            end;
          end;
        end;
      end;
    end;
  end;
end;

end.
