unit U_MLManage_LRYHCE;

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_YH_SX,
  IdComponent, IdTCPConnection, IdTCPClient, IdFTP,IniFiles,ShellAPI;

type
  TfrmMLManage_LRYHCE = 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;
    PopupMenu3: TPopupMenu;
    N2: TMenuItem;
    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;
    TSave: TToolButton;
    Panel3: TPanel;
    Label8: TLabel;
    PopupMenu4: TPopupMenu;
    N4: TMenuItem;
    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;
    Button1: TButton;
    ScrollBox3: TPanel;
    LBCPAP: TLabel;
    BTLP: TButton;
    BTNP: TButton;
    Panel6: TPanel;
    Label6: TLabel;
    Panel10: TPanel;
    Label14: TLabel;
    Label15: TLabel;
    Image2: TImage;
    Image11: TImage;
    TJNote: TMemo;
    TJColNo: TEdit;
    TJCol: TBtnEditA;
    TJNo: TEdit;
    TJPTID: TEdit;
    TJCPID: TEdit;
    TJTPID: TEdit;
    Button2: TButton;
    Button3: TButton;
    Label7: TLabel;
    N3: TMenuItem;
    HXType: TBtnEditA;
    TJGYName: TBtnEditA;
    Panel7: TPanel;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    MLXXName: TEdit;
    Button7: TButton;
    TJML: TEdit;
    N6: TMenuItem;
    procedure FormShow(Sender: TObject);
    procedure MLNameChange(Sender: TObject);
    procedure MLMFChange(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 ADOClick(Sender: TObject);
    procedure N4Click(Sender: TObject);
    procedure HXTypeBtnClick(Sender: TObject);
    procedure TJColBtnClick(Sender: TObject);
    procedure TJGYNameBtnClick(Sender: TObject);
    procedure MLXXGYNameBtnClick(Sender: TObject);
    procedure N5Click(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);
    procedure N3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure N6Click(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 ShowImage1();
    procedure InitColor1();
    procedure SaveImage(maxnoWB:string);
    procedure initFY();
    procedure ColYC();
    { 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);
    procedure ShowImage();
    procedure SaveImage1(maxnoWB:string);
    { Public declarations }
  end;

var
  frmMLManage_LRYHCE: TfrmMLManage_LRYHCE;
  Mach1: array of TfrmSLT_YH_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,U_BPZdy_LRYH,U_ZHCPList_BJCX;

{$R *.dfm}

procedure TfrmMLManage_LRYHCE.ShowImage1();
var
  jpg:TJpegImage;
  myStream: TADOBlobStream;
begin
  with adoqueryPicture do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Image_Info A');
    sql.Add(' inner join Image_File B on A.IMID=B.IMID');
    sql.Add(' and A.WBID='''+Trim(MLTPID.Text)+'''');
    sql.Add(' and A.Valid=''Y'' ');
    //ShowMessage(sql.Text);
    Open;
  end;
  if adoqueryPicture.IsEmpty=False then
  begin
    FileName:=Trim(adoqueryPicture.fieldbyname('ImagePath').AsString);
    jpg:=TJpegImage.Create();
    myStream:=tadoblobstream.Create(tblobfield(adoqueryPicture.fieldbyname('ImageFile')),bmread);
    jpg.LoadFromStream(myStream);
    Image12.Picture.Assign(jpg);
    Image12.Width:=adoqueryPicture.fieldbyname('ImageWidth').Value;
    Image12.Height:=adoqueryPicture.fieldbyname('ImageHeight').Value;
    if Trim(adoqueryPicture.fieldbyname('FangXiang').AsString)='垂直' then
    begin
      Image12.Top:=1;
      Image12.Left:=Round((Panel6.Width-Image12.Width)/2);
    end else
    begin
      Image12.Left:=1;
      Image12.Top:=Round((Panel6.Height-Image12.Height)/2);
    end;
    Image12.Visible:=True;
  end;
end;

procedure TfrmMLManage_LRYHCE.ShowImage();
var
  jpg:TJpegImage;
  myStream: TADOBlobStream;
begin
  with adoqueryPicture do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Image_Info A');
    sql.Add(' inner join Image_File B on A.IMID=B.IMID');
    sql.Add(' and A.WBID='''+Trim(TJTPID.Text)+'''');
    sql.Add(' and A.Valid=''Y'' ');
    //ShowMessage(sql.Text);
    Open;
  end;
  if adoqueryPicture.IsEmpty=False then
  begin
    FileName1:=Trim(adoqueryPicture.fieldbyname('ImagePath').AsString);
    jpg:=TJpegImage.Create();
    myStream:=tadoblobstream.Create(tblobfield(adoqueryPicture.fieldbyname('ImageFile')),bmread);
    jpg.LoadFromStream(myStream);
    Image11.Picture.Assign(jpg);
    Image11.Width:=adoqueryPicture.fieldbyname('ImageWidth').Value;
    Image11.Height:=adoqueryPicture.fieldbyname('ImageHeight').Value;
    if Trim(adoqueryPicture.fieldbyname('FangXiang').AsString)='垂直' then
    begin
      Image11.Top:=1;
      Image11.Left:=Round((Panel6.Width-Image11.Width)/2);
    end else
    begin
      Image11.Left:=1;
      Image11.Top:=Round((Panel6.Height-Image11.Height)/2);
    end;
    Image11.Visible:=True;
  end;
end;

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

procedure TfrmMLManage_LRYHCE.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_LRYHCE.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_LRYHCE.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/20);
  LBCPAP.Caption:=IntToStr(my)+'/'+inttostr(mz);
end;

procedure TfrmMLManage_LRYHCE.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)+'''';
  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:='YH';
      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;
    if j<1 then exit;
    TJNo.Text:=Trim(TJML.Text)+'-'+inttostr(j+1);
    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<20*my) and (i>=20*(my-1)) then
        begin
          jpg:=TJpegImage.Create();
          myStream:=tadoblobstream.Create(tblobfield(adoqueryPicture.fieldbyname('ImageFile')),bmread);
          jpg.LoadFromStream(myStream);
          if (i-20*(my-1))<10*(p+1) then
          begin

          end
          else
          begin
            p:=p+1;
          end;
          Mach1[i]:=TfrmSLT_YH_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:=Trim(TJCPID.Text);
          if self.formid='2' then
          begin
            Mach1[I].Memo1.Visible:=true;
          end;
          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_LRYHCE.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_LRYHCE.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);
      SCSHDataNew(ADOQueryMain,Panel1,2);
      SCSHDataNew(ADOQueryMain,Panel9,2);
      SCSHDataNew(ADOQueryMain,Panel39,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);
      TJCPID.Text:='CP1910290001';
      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
      
    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_LRYHCE.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_LRYHCE.SaveImage1(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('select * from Image_Info ');
      sql.Add('where WBID='''+trim(maxnoWB)+''' and Valid=''Y''');
      Open;
    end;
    if ADOCmd.IsEmpty then
    begin
      if GetLSNo(ADOQueryTemp,MaxNo,'IM','Image_Info',4,1)=False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取图片信息最大号失败！','提示',0);
        Exit;
      end;
    end
    else
    begin
      MaxNo:=Trim(ADOCmd.fieldbyname('IMID').AsString);
    end;
    with ADOCmd do
    begin
      if IsEmpty then
      begin
        Append;
        FieldByName('IMID').Value:=Trim(MaxNo);
        FieldByName('WBID').Value:=Trim(maxnoWB);
        FieldByName('TJML').Value:=Trim(TJML.Text);
        FieldByName('ImageName').Value:=Trim(ImagName);
        FieldByName('ImagePath').Value:=Trim(MaxNo)+Trim(ImagName);
        FieldByName('ImageDate').Value:=SGetServerDate(ADOQueryTemp);
        Fieldbyname('ImageType').value:=Trim('YH');
        Fieldbyname('Valid').value:=Trim('Y');
      end
      else
        edit;
      FieldByName('CPID').Value:=Trim(TJCPID.Text);
      FieldByName('TJHX').Value:=Trim(TJNo.Text);
      FieldByName('TJCol').Value:=Trim(TJCol.Text);
      FieldByName('TJColNo').Value:=Trim(TJColNo.Text);
      FieldByName('TJHXType').Value:=Trim(HXType.Text);
      FieldByName('TJMLNo').Value:=Trim(MLXXNO.Text);
      FieldByName('TJGYName').Value:=Trim(TJGYName.Text);
      FieldByName('TJPTID').Value:=Trim(TJPTID.Text);
      FieldByName('TJCPID').Value:=Trim(TJCPID.Text);
      FieldByName('TJTPID').Value:=Trim(TJTPID.Text);
      FieldByName('TJNote').Value:=Trim(TJNote.Text);
      Post;
    end;

    with ADOCmd do
    begin
      close;
      sql.Clear;
      sql.Add('select *  from Image_File ');
      sql.Add('where IMID='''+trim(MaxNo)+''' and Valid=''Y''');
      open;
    end;
    if ADOCmd.IsEmpty then
    begin
      if GetLSNo(ADOQuery1,MaxNoFile,'IF','Image_File',4,1)=False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取图片文件最大号失败！','提示',0);
        Exit;
      end;
    end
    else
    begin
      MaxNoFile:=Trim(ADOCmd.fieldbyname('IFID').AsString);
    end;
    with ADOCmd do
    begin
      if IsEmpty then
      begin
        Append;
        FieldByName('IMID').Value:=Trim(MaxNo);
        FieldByName('IFID').Value:=Trim(MaxNoFile);
        Fieldbyname('Valid').value:=Trim('Y');
        FieldByName('ImageWidth').Value:=Image11.Width;
        FieldByName('ImageHeight').Value:=Image11.Height;
        FieldByName('FangXiang').Value:=FangXiang1;
        FieldByName('IFType').Value:='小';
      end
      else
        edit;
      FieldByName('CPID').Value:=Trim(TJCPID.Text);
      myStream := TADOBlobStream.Create(TBlobField(ADOCmd.FieldByName('ImageFile')), bmWrite);
      AJpeg.Assign(Image11.Picture.Graphic);
      AJpeg.SaveToStream(myStream);
      myStream.Free;
      Post;
    end;
    if lstPat2.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(lstPat2[0], 'TJ'+'\'+Trim(MaxNo)+Trim(ImagName));
      end;
      if IdFTP1.Connected then IdFTP1.Quit;
    end;
  except
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('图片保存失败！','提示',0);
  end;
end;

procedure TfrmMLManage_LRYHCE.FormShow(Sender: TObject);
var
  fsj:String;
begin
  InitSubGrid();
  if formid='1' then
  begin
    ColYC();
  end;
  initFY();
  if formid='3' then
  begin
    Image11.Picture:=nil;
    Image2.Picture:=nil;
  end
  else
  initimageSH();
  InitColor();
  InitColor1();
  if TJTPID.Text<>'' then
  ShowImage();
  if MLTPID.Text<>'' then
  ShowImage1();
  if formid='2' then
  begin
    ColYC();
    panel9.Enabled:=true;
    MLCF.Enabled:=False;
    MLMF.Enabled:=False;
    MLKZ.Enabled:=False;
    HXType.Enabled:=false;
    TJGYName.Color:=clWindow;
    FCYID:='';
  end;
  if formid='3' then
  begin
    FCYID:='';
    TJML.Text:='';
    TJNo.Text:='';
  end;
  TSave.Caption:='保存';
end;

function TfrmMLManage_LRYHCE.SaveData():Boolean;
var
  maxId,maxno,FXDID,FTJNo:String;
  i,j,c:Integer;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    if FCYID='' then
    begin
      if GetLSNo(ADOQueryCmd,maxno,'ML','ML_Manage',3,1)=False then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!','提示',0);
        Exit;
      end;
      if PatFile<>'' then
      begin
        if GetLSNo(ADOQueryCmd,FXDID,'YT','XD_File',4,1)=False then
        begin
          ADOQueryCmd.Connection.RollbackTrans;
          Application.MessageBox('取图片最大号失败！','提示',0);
          Exit;
        end;
      end;
    end
    else
    begin
      maxno:=Trim(FCYID);
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from ML_Manage where TJML='''+Trim(TJML.Text)+'''');
      sql.Add(' and TJGYName='''+trim(TJGYName.Text)+'''');
      Open;
    end;
    with ADOQueryCmd do
    begin
      if isempty then
      begin
        Append;
        fieldbyname('GYType').Value:=Trim(FGYName);
        FieldByName('GYTypeJC').Value:=Trim(FML);
        FieldByName('TJNo').Value:=Trim(FTJNo);
      end
      else
      begin
        Edit;
      end;
      FieldByName('MLID').Value:=Trim(maxno);
      FieldByName('MBPID').Value:=Trim(FBPID);
      FieldByName('MLType').Value:='印花面料';
      FieldByName('GSNo').Value:=Trim(GSNo.Caption);
      FieldByName('GYName').Value:=Trim(GYName.Caption);
      FieldByName('MLNo').Value:=Trim(MLNo.Text);
      RTSetsavedata(ADOQueryCmd,'ML_Manage',panel1,2);
      RTSetsavedata(ADOQueryCmd,'ML_Manage',panel9,2);
      RTSetsavedata(ADOQueryCmd,'ML_Manage',panel39,2);
      FieldByName('PTID').Value:=Trim(PTID.Text);
      FieldByName('TJPTID').Value:=Trim(TJPTID.Text);
      FieldByName('MLTPID').Value:=Trim(MLTPID.Text);
      FieldByName('TJTPID').Value:=Trim(TJTPID.Text);
      FieldByName('MLDLNo').Value:=Trim(FSKID);
      FieldByName('TJColID').Value:=Trim(FTJCoNo);
      FieldByName('CPID').Value:=Trim(FCPID);
      FieldByName('TJGYName').Value:=Trim(TJGYName.Text);
      FieldByName('HXType').Value:=Trim(HXType.Text);
      Post;
    end;
    FCYID:=Trim(maxno);
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from ML_Manage where TJML='''+Trim(TJML.Text)+'''');
      sql.Add(' and TJGYName='''+trim(TJGYName.Text)+'''');
      Open;
    end;
    if ADOQueryCmd.RecordCount>1 then
    begin
      ADOQueryCmd.Connection.RollbackTrans;
      application.MessageBox('印花工艺重复','提示');
      exit;
    end;
    with ScrollBox2 do
    begin
      for j:=0 to ControlCount-1 do
      begin
        if Controls[j] is TfrmSLT_YH_SX then
        begin
          with TfrmSLT_YH_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
                  with ADOQueryTemp do
                  begin
                    close;
                    sql.Clear;
                    sql.Add('update Image_Info set TJGYName='''+trim(TJGYName.Text)+''' ');
                    sql.Add('where IMID='''+trim(FIMID)+'''');
                    execsql;
                  end;
                end;
              end;
            end;
          end;
        end;
      end;
    end;
    if MLTPID.Text<>'' then
    begin
      if lstPat.Count=1 then
      begin
        SaveImage(Trim(MLTPID.Text));
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except;
    Result:=True;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败!','提示',0);
  end;
end;

procedure TfrmMLManage_LRYHCE.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_LRYHCE.imagePL(FFF:Integer);
begin

end;

procedure TfrmMLManage_LRYHCE.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_LRYHCE.MLNameChange(Sender: TObject);
begin
  if Trim(FCYID)<>'' then
  begin
    TSave.Caption:='保存改';
  end;
end;

procedure TfrmMLManage_LRYHCE.MLMFChange(Sender: TObject);
begin
  if Trim(FCYID)<>'' then
  begin
    TSave.Caption:='保存改';
  end;
end;

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

procedure TfrmMLManage_LRYHCE.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_LRYHCE.FormCreate(Sender: TObject);
begin
  lstPat := TStringList.Create;
  lstPat2 := TStringList.Create;
end;

procedure TfrmMLManage_LRYHCE.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_LRYHCE.ToSelPBClick(Sender: TObject);
begin
  if CDS_Sub.IsEmpty=false then
  begin
    CDS_Sub.Delete;
    //Application.MessageBox('已存在坯布信息','提示');
   // exit;
  end;

end;

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

procedure TfrmMLManage_LRYHCE.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:='';
        ShowImage1();
        Button1.Visible:=false;
      end;
    end;
  finally
    frmMLManage_LRRS_Col.Free;
  end;
end;

procedure TfrmMLManage_LRYHCE.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_LRYHCE.ADOClick(Sender: TObject);
begin
  try
    frmRTPTColor:=TfrmRTPTColor.Create(Application);
    with frmRTPTColor do
    begin
      if ShowModal=1 then
      begin
        Self.TJPTID.Text:=Trim(frmRTPTColor.FPTID);
        Self.TJColNo.Text:=Trim(frmRTPTColor.FColName);
        Self.TJCol.Text:=Trim(frmRTPTColor.FColNameKH);
      end;
    end;
  finally
    frmRTPTColor.Free;
  end;
  if Trim(TJPTID.Text)<>'' then
  begin
    InitColor1();
  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(TJTPID.Text)+''' and Valid=''Y'')');
    sql.Add('delete from Image_Info ');
    sql.Add(' where WBID='''+Trim(TJTPID.Text)+''' and Valid=''Y''');
    ExecSQL;
  end;
  TJTPID.Text:='';
  ShowImage();
end;

procedure TfrmMLManage_LRYHCE.N4Click(Sender: TObject);
var
  AJpeg:TJPEGImage;
  Bitmap,Bitmap11: TBitmap;
  ARect,ARect11: TRect;
  TPHeight, AHeightOffset: Integer;
  TPWidth, AWidthOffset: Integer;
  WZShuiPing,WZChuiZhi:Integer;
  WZFlag:String;
  FHFStr:String;
begin
  lstPat2.Clear;
  if ODPat.Execute then
  begin
    lstPat2.AddStrings(ODPat.Files);
  end else
  begin
    Exit;
  end;
  if lstPat2.Count>1 then
  begin
    lstPat2.Clear;
    Application.MessageBox('不能上传多个图片!','提示',0);
    Exit;
  end else
  if lstPat2.Count<1 then
  begin
    Exit;
  end;
  AJpeg:=TJpegImage.Create();
  AJpeg.LoadFromFile(ExtractFileName(ODPat.FileName));
  Image2.Hint:=ExtractFileName(ODPat.FileName);
  TJTPID.Text:=FormatDateTime('yyMMddhhmmss',now);
  FileName:=Trim(ExtractFileName(ODPat.FileName));
  TPWidth:=AJpeg.Width;
  TPHeight:=AJpeg.Height;
  Bitmap := TBitmap.Create;
  Bitmap11 := TBitmap.Create;
  Bitmap.Width :=Panel10.Width-2;
  Bitmap.Height :=Round(Panel10.Width/TPWidth*TPHeight);
  if Bitmap.Height>Panel10.Height then
  begin
    WZFlag:='垂直';
    Bitmap.Height:=Panel10.Height-2;
    Bitmap.Width :=Round(Panel10.Height/TPHeight*TPWidth);
  end;
  Bitmap11.Width:=Bitmap.Width*2;
  Bitmap11.Height:=Bitmap.Height*2;
  Bitmap.Canvas.FillRect(Rect(0, 0, Bitmap.Width, Bitmap.Height));
  ARect := Rect(0, 0, Bitmap.Width, Bitmap.Height);
  Bitmap.Canvas.StretchDraw(ARect, AJPeg);
  Image2.Height:=Bitmap.Height;
  Image2.Width:=Bitmap.Width;
  Image2.Picture.Assign(BitMap);
  if Trim(WZFlag)='垂直' then
  begin
    Image2.Top:=1;
    Image2.Left:=Round((Panel10.Width-Image2.Width)/2);
  end else
  begin
    Image2.Left:=1;
    Image2.Top:=Round((Panel10.Height-Image2.Height)/2);
  end;
  FangXiang1:=WZFlag;
  Image2.Visible:=True;
  Bitmap11.Canvas.FillRect(Rect(0, 0, Bitmap11.Width, Bitmap11.Height));
  ARect11 := Rect(0, 0, Bitmap11.Width, Bitmap11.Height);
  Bitmap11.Canvas.StretchDraw(ARect11, AJPeg);
  Image11.Height:=Bitmap11.Height;
  Image11.Width:=Bitmap11.Width;
  Image11.Picture.Assign(BitMap11);
  TJPTID.Text:='';
  Panel10.Color:=clBtnFace;
end;

procedure TfrmMLManage_LRYHCE.HXTypeBtnClick(Sender: TObject);
begin
  frmSCPerson:=TfrmSCPerson.Create(Application);
  with frmSCPerson do
  begin
    FlagStr:='YHHXZDYType';
    if ShowModal=1 then
    begin
      HXType.Text:=Trim(FSDPerson);
      TJCPID.Text:='CP1910290001';
    end;
    free;
  end;
end;

procedure TfrmMLManage_LRYHCE.TJColBtnClick(Sender: TObject);
begin
  frmZDYHelp_Col:=TfrmZDYHelp_Col.create(self);
  with frmZDYHelp_Col do
  begin
    flag:='TJCol';
    flagname:='印花颜色';
    fnote:=true;
    V1Note.Caption:='色号';
    V1Name.Caption:='印花颜色';
    if showmodal=1 then
    begin
      TJCol.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      TJColNo.Text:=Trim(ClientDataSet1.fieldbyname('Note').AsString);
    end;
    free;
  end;
end;

procedure TfrmMLManage_LRYHCE.TJGYNameBtnClick(Sender: TObject);
var FGYName:string;
begin
  frmBPZdy_LRYH:=TfrmBPZdy_LRYH.Create(Application);
  with frmBPZdy_LRYH do
  begin
    flag:='YHName';
    flagName:='印花';
    cxGrid3.Visible:=true;
    ViewFlag:=True;
    Panel4.Visible:=true;
    if ShowModal=1 then
    begin
      with ML_GX do
      begin
        first;
        while not eof do
        begin
          if FGYName='' then
          begin
            FGYName:=Trim(ML_GX.fieldbyname('GYName').AsString);
          end
          else
          begin
            FGYName:=FGYName+'+'+Trim(ML_GX.fieldbyname('GYName').AsString)
          end;
          next;
        end;
      end;
      TJGYName.Text:=FGYName;
    end;
    free;
  end;
end;

procedure TfrmMLManage_LRYHCE.MLXXGYNameBtnClick(Sender: TObject);
begin
  frmMLMangeRS_Sel:=TfrmMLMangeRS_Sel.Create(self);
  with frmMLMangeRS_Sel do
  begin
    MLNo.Text:=trim(MLXXNO.Text);
    if ShowModal=1 then
    begin
      MLXXGYName.Text:=Trim(CDS_Main.fieldbyname('GYLXName').AsString);
    end;
    free;
  end;
end;

procedure TfrmMLManage_LRYHCE.N5Click(Sender: TObject);
var
  AJpeg:TJPEGImage;
  Bitmap,Bitmap11: TBitmap;
  ARect,ARect11: TRect;
  TPHeight, AHeightOffset: Integer;
  TPWidth, AWidthOffset: Integer;
  WZShuiPing,WZChuiZhi:Integer;
  WZFlag:String;
  FHFStr:String;
begin
  lstPat.Clear;
  if ODPat.Execute then
  begin
    lstPat.AddStrings(ODPat.Files);
  end else
  begin
    Exit;
  end;
  if lstPat.Count>1 then
  begin
    lstPat.Clear;
    Application.MessageBox('不能上传多个图片!','提示',0);
    Exit;
  end else
  if lstPat.Count<1 then
  begin
    Exit;
  end;
  AJpeg:=TJpegImage.Create();
  AJpeg.LoadFromFile(ExtractFileName(ODPat.FileName));
  Image1.Hint:=ExtractFileName(ODPat.FileName);
  MLTPID.Text:=FormatDateTime('yyMMddhhmmss',now);
  FileName1:=Trim(ExtractFileName(ODPat.FileName));
  TPWidth:=AJpeg.Width;
  TPHeight:=AJpeg.Height;
  Bitmap := TBitmap.Create;
  Bitmap11 := TBitmap.Create;
  Bitmap.Width :=Panel42.Width-2;
  Bitmap.Height :=Round(Panel42.Width/TPWidth*TPHeight);
  if Bitmap.Height>Panel42.Height then
  begin
    WZFlag:='垂直';
    Bitmap.Height:=Panel42.Height-2;
    Bitmap.Width :=Round(Panel42.Height/TPHeight*TPWidth);
  end;
  Bitmap11.Width:=Bitmap.Width*2;
  Bitmap11.Height:=Bitmap.Height*2;
  Bitmap.Canvas.FillRect(Rect(0, 0, Bitmap.Width, Bitmap.Height));
  ARect := Rect(0, 0, Bitmap.Width, Bitmap.Height);
  Bitmap.Canvas.StretchDraw(ARect, AJPeg);
  Image1.Height:=Bitmap.Height;
  Image1.Width:=Bitmap.Width;
  Image1.Picture.Assign(BitMap);
  if Trim(WZFlag)='垂直' then
  begin
    Image1.Top:=1;
    Image1.Left:=Round((Panel42.Width-Image1.Width)/2);
  end else
  begin
    Image1.Left:=1;
    Image1.Top:=Round((Panel42.Height-Image1.Height)/2);
  end;
  FangXiang2:=WZFlag;
  Image1.Visible:=True;
  Bitmap11.Canvas.FillRect(Rect(0, 0, Bitmap11.Width, Bitmap11.Height));
  ARect11 := Rect(0, 0, Bitmap11.Width, Bitmap11.Height);
  Bitmap11.Canvas.StretchDraw(ARect11, AJPeg);
  Image12.Height:=Bitmap11.Height;
  Image12.Width:=Bitmap11.Width;
  Image12.Picture.Assign(BitMap11);
  PTID.Text:='';
  Panel42.Color:=clBtnFace;
  MLXXCol.Text:='';
  MLXXColNo.Text:='';
  Button1.Visible:=true;
end;

procedure TfrmMLManage_LRYHCE.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_LRYHCE.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_LRYHCE.MLCFBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.create(self);
  with frmZDYHelp do
  begin
    flag:='YHCF';
    flagname:='成份';
    if showmodal=1 then
    begin
      MLCF.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

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

procedure TfrmMLManage_LRYHCE.Button1Click(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.create(self);
  with frmZDYHelp do
  begin
    flag:='MLXXCol';
    flagname:='颜色';
    if showmodal=1 then
    begin
      MLXXCol.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

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

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

procedure TfrmMLManage_LRYHCE.ColYC();
begin
  Panel6.Visible:=false;
  MLXXNO.Enabled:=False;
  MLXXName.Enabled:=false;
  MLXXNO.Color:=clScrollBar;
  MLXXName.Color:=clScrollBar;
  Panel9.Enabled:=false;
  MLCF.Color:=clScrollBar;
  MLMF.Color:=clScrollBar;
  MLKZ.Color:=clScrollBar;
  Panel39.Enabled:=false;
  Button1.Visible:=false;
  MLXXCol.Color:=clScrollBar;
  MLXXColNo.Color:=clScrollBar;
  MLXXMF.Color:=clScrollBar;
  MLXXKZ.Color:=clScrollBar;
  MLXXGYName.Color:=clScrollBar;
  MLXXNote.Color:=clScrollBar;
  HXType.Color:=clScrollBar;
  TJGYName.Color:=clScrollBar;
  TJNote.Color:=clScrollBar;
end;

procedure TfrmMLManage_LRYHCE.Button2Click(Sender: TObject);
var FTJNo:string;
begin
  if HXType.Text='' then
  begin
    Application.MessageBox('花型类型不能为空','提示');
    exit;
  end;
  if TJGYName.Text='' then
  begin
    Application.MessageBox('印花工艺不能为空','提示');
    exit;
  end;
  if TJTPID.Text='' then
  begin
    Application.MessageBox('图片不能为空','提示');
    exit;
  end;
  if Trim(MLName.Text)='' then
  begin
    Application.MessageBox('品名不能为空!','提示',0);
    Exit;
  end;
  if Trim(MLXXGYName.Text)='' then
  begin
    Application.MessageBox('工艺不能为空!','提示',0);
    Exit;
  end;
  if TJML.Text='' then
  begin
    if GetLSNo(ADOQueryCmd,FTJNo,'YH','ML_Manage',4,0)=False then
    begin
      Application.MessageBox('取最大号失败!','提示',0);
      Exit;
    end;
    TJNo.Text:=Trim(FTJNo)+'-1';
    TJML.Text:=Trim(FTJNo);
    SaveData();
  end;
  if TJTPID.Text<>'' then
  begin
    if lstPat2.Count=1 then
    begin
      SaveImage1(Trim(TJTPID.Text));
      initimageSH();
      ColYC();
    end;
  end;
  Panel7.Visible:=True;
end;

procedure TfrmMLManage_LRYHCE.Button3Click(Sender: TObject);
begin
  SClearData(Panel6,2);
  Panel6.Visible:=False;
  Panel7.Visible:=True;
end;

procedure TfrmMLManage_LRYHCE.N3Click(Sender: TObject);
begin
  try
    frmRTPTColor:=TfrmRTPTColor.Create(Application);
    with frmRTPTColor do
    begin
      if ShowModal=1 then
      begin
        Self.PTID.Text:=Trim(frmRTPTColor.FPTID);
        Self.MLXXCol.Text:=Trim(frmRTPTColor.FColNameKH);
        Self.MLXXColNo.Text:=Trim(frmRTPTColor.FColName);
      end;
    end;
  finally
    frmRTPTColor.Free;
  end;
  if Trim(PTID.Text)<>'' then
  begin
    InitColor();
  end;
end;

procedure TfrmMLManage_LRYHCE.Button4Click(Sender: TObject);
begin
  if Trim(MLMF.Text)='' then
  begin
    Application.MessageBox('门幅不能为空!','提示',0);
    Exit;
  end;
  if Trim(MLKZ.Text)='' then
  begin
    Application.MessageBox('克重不能为空!','提示',0);
    Exit;
  end;
  if MLXXNO.Text='' then
  begin
    Application.MessageBox('面料信息不能为空','提示');
    exit;
  end;
  SClearData(Panel6,2);
  Panel6.Visible:=true;
  Image11.Picture:=nil;
  Image2.Picture:=nil;
  Panel7.Visible:=false;
end;

procedure TfrmMLManage_LRYHCE.Button5Click(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.create(self);
  with frmZDYHelp do
  begin
    flag:='YHKZ';
    flagname:='克重';
    if showmodal=1 then
    begin
      MLKZ.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

procedure TfrmMLManage_LRYHCE.Button6Click(Sender: TObject);
begin
  frmMLMangeRS_Sel:=TfrmMLMangeRS_Sel.Create(self);
  with frmMLMangeRS_Sel do
  begin
    if ShowModal=1 then
    begin
      Self.MLXXNO.Text:=Trim(CDS_Main.fieldbyname('MLNo').AsString);
      Self.MLCF.Text:=Trim(CDS_Main.fieldbyname('MLCF').AsString);
      Self.MLMF.Text:=Trim(CDS_Main.fieldbyname('MLMF').AsString);
      Self.MLKZ.Text:=Trim(CDS_Main.fieldbyname('MLKZ').AsString);
      Self.MBPID.Text:=Trim(CDS_Main.fieldbyname('MLID').AsString);
      Self.MLXXName.Text:=CDS_Main.fieldbyname('MLName').AsString;
      self.MLXXGYName.Text:=Trim(CDS_Main.fieldbyname('GYLXName').AsString);
      Self.MLXXMF.Text:=CDS_Main.fieldbyname('MLMF').AsString;
      Self.MLXXKZ.Text:=CDS_Main.fieldbyname('MLKZ').AsString;
      Self.MLName.Text:=CDS_Main.fieldbyname('MLName').AsString+'印花';
      Self.MLNo.Text:='Y'+copy(Trim(CDS_Main.fieldbyname('MLNo').AsString),2,Length(Trim(CDS_Main.fieldbyname('MLNo').AsString)));
      Self.FSKID:=CDS_Main.fieldbyname('SKID').AsString;
    end;
    free;
  end;
  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:='';
        ShowImage1();
        Button1.Visible:=false;
      end;
    end;
  finally
    frmMLManage_LRRS_Col.Free;
  end;
end;

procedure TfrmMLManage_LRYHCE.Button7Click(Sender: TObject);
begin
  if application.MessageBox('确定要删除所有图片吗','提示',1)=2 then Exit;
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add('delete from Image_File where ');
    sql.Add('IMID in (select IMID from Image_Info where TJML='''+Trim(TJML.Text)+''' and Valid=''Y'')');
    sql.Add('delete from Image_Info ');
    sql.Add(' where TJML='''+Trim(TJML.Text)+''' and Valid=''Y''');
    ExecSQL;
  end;
  Application.MessageBox('删除成功','提示');
  initimageSH();
end;

procedure TfrmMLManage_LRYHCE.N6Click(Sender: TObject);
var
  FZIID,FLeiBie,FZIIDYS,fsj:String;
begin
  frmZHCPList_BJCX:=TfrmZHCPList_BJCX.create(self);
  with frmZHCPList_BJCX do
  begin
    if ShowModal=1 then
    begin
      TJNote.Text:='编号：'+Trim(Order_Main.fieldbyname('ZIID').AsString)+#13#13
                   +'门幅：'+Trim(Order_Main.fieldbyname('ZIMF').AsString)+#13#13
                   +'克重：'+Trim(Order_Main.fieldbyname('ZIKZ').AsString)+#13#13
                   +'成份：'+Trim(Order_Main.fieldbyname('ZICF').AsString)+#13#13
                   +'品名：'+Trim(Order_Main.fieldbyname('ZIName').AsString)+#13#13
                   +'工艺：'+Trim(Order_Main.fieldbyname('ZIGY').AsString)+#13#13;
      with adoqueryPicture do
      begin
        Close;
        sql.Clear;
        sql.Add('select * from Image_Info A');
        sql.Add(' inner join Image_File B on A.IMID=B.IMID');
        sql.Add(' and A.WBID='''+Trim(Order_Main.fieldbyname('ZIID').AsString)+'''');
        sql.Add(' and isnull(A.IMNo,'''')=''图片'' and A.Valid=''Y'' ');
        Open;
      end;
      if adoqueryPicture.IsEmpty=False then
      begin
        FileName1:=Trim(adoqueryPicture.fieldbyname('ImagePath').AsString);
        jpg:=TJpegImage.Create();
        myStream:=tadoblobstream.Create(tblobfield(adoqueryPicture.fieldbyname('ImageFile')),bmread);
        jpg.LoadFromStream(myStream);
        Image11.Picture.Assign(jpg);
        Image11.Width:=adoqueryPicture.fieldbyname('ImageWidth').Value;
        Image11.Height:=adoqueryPicture.fieldbyname('ImageHeight').Value;
        if Trim(adoqueryPicture.fieldbyname('FangXiang').AsString)='垂直' then
        begin
          Image11.Top:=1;
          Image11.Left:=Round((Panel6.Width-Image11.Width)/2);
        end else
        begin
          Image11.Left:=1;
          Image11.Top:=Round((Panel6.Height-Image11.Height)/2);
        end;
        Image11.Visible:=True;
      end;
    end;
    free;
  end;
end;

end.
