unit U_MLManage_LRXH;

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

type
  TfrmMLManage_LRXH = class(TForm)
    CDS_Sub: TClientDataSet;
    ADOQueryMain: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ADOQueryTemp: TADOQuery;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Panel1: TPanel;
    Order_GX: TClientDataSet;
    DataSource1: TDataSource;
    Panel4: TPanel;
    OrdBP_SH: TClientDataSet;
    GSNo: TLabel;
    MLNo: TLabel;
    Ord_HX: TClientDataSet;
    GYName: TLabel;
    Panel9: TPanel;
    Label2: TLabel;
    MLName: TEdit;
    MLMF: TEdit;
    MLKZ: TEdit;
    GYLX: TLabel;
    GYLXName: TLabel;
    Label1: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label8: TLabel;
    Button2: TButton;
    MLCF: TEdit;
    Button1: TButton;
    ScrollBox2: TScrollBox;
    adoqueryPicture: TADOQuery;
    RMDB_Main: TRMDBDataSet;
    RM1: TRMGridReport;
    ADOQueryPrint: TADOQuery;
    CDS_Print: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    Button5: TButton;
    SaveDialog1: TSaveDialog;
    ODPat: TOpenDialog;
    IdFTP1: TIdFTP;
    Panel7: TPanel;
    Panel39: TPanel;
    ToolBar3: TToolBar;
    ToolButton2: TToolButton;
    ToolButton1: TToolButton;
    ToolButton3: TToolButton;
    Panel5: TPanel;
    Label5: TLabel;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    V1Ssel: TcxGridDBColumn;
    V1BPCode: TcxGridDBColumn;
    V1BPName: TcxGridDBColumn;
    V1BPMF: TcxGridDBColumn;
    V1BPKZ: TcxGridDBColumn;
    V1BPJS: TcxGridDBColumn;
    v1BPMiDu: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    ScrollBox1: TScrollBox;
    Panel42: TPanel;
    Label79: TLabel;
    Label80: TLabel;
    Panel43: TPanel;
    Label81: TLabel;
    Label82: TLabel;
    Panel44: TPanel;
    Label83: TLabel;
    Label84: TLabel;
    Panel45: TPanel;
    Label85: TLabel;
    Label86: TLabel;
    Panel46: TPanel;
    Label87: TLabel;
    Label88: TLabel;
    Panel47: TPanel;
    Label89: TLabel;
    Label90: TLabel;
    Panel48: TPanel;
    Label91: TLabel;
    Label92: TLabel;
    Panel49: TPanel;
    Label93: TLabel;
    Label94: TLabel;
    Panel50: TPanel;
    Label95: TLabel;
    Label96: TLabel;
    Panel51: TPanel;
    Label97: TLabel;
    Label98: TLabel;
    Panel52: TPanel;
    Label99: TLabel;
    Label100: TLabel;
    Panel53: TPanel;
    Label101: TLabel;
    Label102: TLabel;
    Panel54: TPanel;
    Label103: TLabel;
    Label104: TLabel;
    Panel55: TPanel;
    Label105: TLabel;
    Label106: TLabel;
    Panel56: TPanel;
    Label107: TLabel;
    Label108: TLabel;
    Panel61: TPanel;
    Label117: TLabel;
    Label118: TLabel;
    Panel60: TPanel;
    Label115: TLabel;
    Label116: TLabel;
    Panel59: TPanel;
    Label113: TLabel;
    Label114: TLabel;
    Panel58: TPanel;
    Label111: TLabel;
    Label112: TLabel;
    Panel57: TPanel;
    Label109: TLabel;
    Label110: TLabel;
    Panel62: TPanel;
    Label119: TLabel;
    Label120: TLabel;
    Panel63: TPanel;
    Label121: TLabel;
    Label122: TLabel;
    Panel64: TPanel;
    Label123: TLabel;
    Label124: TLabel;
    Panel65: TPanel;
    Label125: TLabel;
    Label126: TLabel;
    Panel66: TPanel;
    Label127: TLabel;
    Label128: TLabel;
    Panel71: TPanel;
    Label137: TLabel;
    Label138: TLabel;
    Panel70: TPanel;
    Label135: TLabel;
    Label136: TLabel;
    Panel69: TPanel;
    Label133: TLabel;
    Label134: TLabel;
    Panel68: TPanel;
    Label131: TLabel;
    Label132: TLabel;
    Panel67: TPanel;
    Label129: TLabel;
    Label130: TLabel;
    Panel11: TPanel;
    Label7: TLabel;
    Label12: TLabel;
    Panel12: TPanel;
    Label13: TLabel;
    Label14: TLabel;
    Panel13: TPanel;
    Label15: TLabel;
    Label16: TLabel;
    Panel14: TPanel;
    Label17: TLabel;
    Label18: TLabel;
    Panel15: TPanel;
    Label19: TLabel;
    Label20: TLabel;
    Panel16: TPanel;
    Label21: TLabel;
    Label22: TLabel;
    Panel17: TPanel;
    Label23: TLabel;
    Label24: TLabel;
    Panel18: TPanel;
    Label25: TLabel;
    Label26: TLabel;
    Panel19: TPanel;
    Label27: TLabel;
    Label28: TLabel;
    Panel20: TPanel;
    Label29: TLabel;
    Label30: TLabel;
    Panel21: TPanel;
    Label31: TLabel;
    Label32: TLabel;
    Panel22: TPanel;
    Label33: TLabel;
    Label34: TLabel;
    Panel23: TPanel;
    Label35: TLabel;
    Label36: TLabel;
    Panel24: TPanel;
    Label37: TLabel;
    Label38: TLabel;
    Panel25: TPanel;
    Label39: TLabel;
    Label40: TLabel;
    Panel3: TPanel;
    Label11: TLabel;
    BPCode: TLabel;
    BPName: TLabel;
    BPJS: TLabel;
    BPMF: TLabel;
    BPKZ: TLabel;
    BPMiDu: TLabel;
    BPCF: TLabel;
    RSGYLXName: TLabel;
    Panel6: TPanel;
    ToolBar2: TToolBar;
    TAdd: TToolButton;
    ToolButton5: TToolButton;
    Panel8: TPanel;
    Label6: TLabel;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    V2XHNo: TcxGridDBColumn;
    VGYCode: TcxGridDBColumn;
    V2GYName: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    ScrollBox3: TScrollBox;
    Label45: TLabel;
    Panel10: TPanel;
    Label41: TLabel;
    Label42: TLabel;
    Button3: TButton;
    cxGrid3: TcxGrid;
    TV3: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    PopupMenu2: TPopupMenu;
    MenuItem1: TMenuItem;
    Ord_ZB: TClientDataSet;
    procedure FormShow(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure TAddClick(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure MLNameChange(Sender: TObject);
    procedure MLMFChange(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure N1Click(Sender: TObject);
    procedure Panel42MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure MenuItem1Click(Sender: TObject);
  private
    lstPat: TStringList;
    Fint,my,mz:Integer;
    procedure InitSubGrid();
    function  SaveData():Boolean;
    procedure BHCZhu();
    procedure SavePrint(var CP,TP:string);
    procedure CreThumb(AJPeg:TJPEGImage;Image1:TImage;Width, Height: Integer);
    { Private declarations }
  public
    FCYID,FCYCode,FCPID,FCPNO,FBPID,FGYName,FML,FGYLX,FGSNo,FHXBPID,FGSName,FSKID,FBPIDSH:String;
    FGYLXName,PatFile,FTJCoNo:string;
    viewFlag:Boolean;
    procedure initimageSH();
    procedure initimage();
    procedure imagePL(FFF:Integer);
    { Public declarations }
  end;

var
  frmMLManage_LRXH: TfrmMLManage_LRXH;
  Mach1: array of TfrmSlt;
  Mach: array of TfrmSLT_PBSK;
implementation
uses
  U_DataLink,U_Fun,U_BPZdy_LR,U_BPZdy_SH,U_MLMange_ADDCX, U_BPZdy_HXK,U_BPZdy_LRPB,U_BPZdy_LRGX,
  U_BPZdy_PanelCX, U_BPZdy_YT,U_BPZdy_Panel,U_BPZdy_LRTJ,U_FileUp_TPSH,U_MLMangeRS_Sel,U_BPZdy_Panel_M;

{$R *.dfm}
procedure TfrmMLManage_LRXH.initimageSH();
var
  i,j,p,x:integer;
  jpg:TJpegImage;
  myStream: TADOBlobStream;
  FZGao:string;
begin
  j:=length(Mach1);
  if j>0 then
  begin
    for i:=0 to j-1 do
    begin
      Mach1[i].free;
    end;
    //Finalize(Mach1);
  end;
  SetLength(Mach1, 0);
  IF FCYID='' then exit;
  try
    with adoqueryPicture do
    begin
      close;
      sql.Clear;
      sql.Add(' select A.TFID,A.WBID,A.FilesOther,B.FileName,C.*,D.* from XD_File B ');
      SQL.Add(' inner join TP_File A on B.XFID=A.TFID ');
      sql.Add(' left join SH_Base D on A.WBID=D.WBID ');
      sql.Add(' left join ML_Manage C on C.MLID =B.SKID');
      sql.Add(' where B.SKID='+quotedstr(trim(FCYID)));
      sql.Add(' order by cast(D.ColorNo as int)');
      //ShowMessage(sql.Text);
      open;
    end;
    j:=adoqueryPicture.RecordCount;
    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
        jpg:=TJpegImage.Create();
        myStream:=tadoblobstream.Create(tblobfield(adoqueryPicture.fieldbyname('FilesOther')),bmread);
        jpg.LoadFromStream(myStream);
        if i<3*(p+1) then
        begin

        end
        else
        begin
          p:=p+1;
        end;
        Mach1[i] := TfrmSLT.Create(Self);
        Mach1[i].Name:=trim(adoqueryPicture.fieldbyname('TFID').AsString);
        Mach1[i].Parent := ScrollBox2;
        Mach1[I].Left:=0+(x-3*p)*175;
        Mach1[I].Top:=p*143;
        if adoqueryPicture.fieldbyname('SHID').AsString='' then
        begin
          Mach1[I].ColorNo.Text:=inttostr(i+1);
          Mach1[i].WBID.Text:=trim(adoqueryPicture.fieldbyname('WBID').AsString);
        end
        else
        begin
          SCSHDataNew(adoqueryPicture,Mach1[I].Panel1,2);
        end;
        Mach1[I].SH.Caption:=Trim(adoqueryPicture.fieldbyname('ColorNo').AsString);
        Mach1[I].ZW.Caption:=Trim(adoqueryPicture.fieldbyname('ColorName').AsString);
        Mach1[I].YW.Caption:=Trim(adoqueryPicture.fieldbyname('ColorNameEng').AsString);
        if triM(adoqueryPicture.fieldbyname('TFID').AsString)<>'' then
        begin
          Mach1[i].Init(adoqueryPicture.fieldbyname('TFID').AsString,adoqueryPicture.fieldbyname('FileName').AsString,jpg);
        end;
        i:=i+1;
        x:=x+1;
        Next;
      end;
    end;
    adoqueryPicture.EnableControls;
  finally
    jpg.free;
    //application.ProcessMessages;
  end;
end;

procedure TfrmMLManage_LRXH.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_LRXH.InitSubGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select A.*,B.* from ML_Manage A ');
      sql.Add('inner join BP_ColZDY_M B on B.ColID=A.TJColID ');
      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.Caption:=Trim(ADOQueryMain.FieldByName('MLNo').asstring);
      GYLX.Caption:=Trim(ADOQueryMain.FieldByName('GYLX').asstring);
      GYLXName.Caption:=Trim(ADOQueryMain.FieldByName('GYLXName').asstring);
      //MLDLNo.Caption:=Trim(ADOQueryMain.FieldByName('MLDLNo').asstring);
      SCSHDataNew(ADOQueryMain,Panel9,2);
      FBPID:=Trim(ADOQueryMain.FieldByName('MBPID').Value);
      FSKID:=Trim(ADOQueryMain.FieldByName('MLDLNo').AsString);
      FTJCoNo:=Trim(ADOQueryMain.FieldByName('TJColID').AsString);
      Label41.Caption:=Trim(ADOQueryMain.FieldByName('ColNo').AsString);
      Label42.Caption:=Trim(ADOQueryMain.FieldByName('ColNameKH').AsString);
      Panel10.Color:=StrToInt('$'+Trim(ADOQueryMain.FieldByName('ColDaiMa').AsString));
    end;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select A.*,isnull(B.BPCode,C.MLNo) BPCode,isnull(B.BPName,C.MLName) BPName');
      sql.Add(' ,isnull(B.BPMF,C.MLMF) BPMF,isnull(B.BPKZ,C.MLKZ) BPKZ,C.GYLXName');
      sql.Add(',B.BPJS,B.BPWS,B.BPMiDu,B.BPUnit,B.BPCF,B.CPMiDu');
      sql.Add(',isnull(B.SKID,(select D.SKID from BP_ZDY D where D.BPID=C.MBPID)) SKID');
      SQL.Add(' from ML_Manage_PB A left join BP_ZDY B on B.BPID=A.BPID ');
      sql.Add(' left join ML_Manage C on C.MLID=A.BPID');
      sql.Add(' where A.MLID='''+Trim(FCYID)+'''');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Sub);
    SInitCDSData20(ADOQueryMain,CDS_Sub);
    BPCode.caption:=Trim(CDS_Sub.fieldbyname('BPCode').AsString);
    BPName.caption:=Trim(CDS_Sub.fieldbyname('BPName').AsString);
    BPMF.Caption:=Trim(CDS_Sub.fieldbyname('BPMF').AsString);
    BPKZ.Caption:=Trim(CDS_Sub.fieldbyname('BPKZ').AsString);
    BPCF.Caption:=Trim(CDS_Sub.fieldbyname('BPCF').AsString);
    BPJS.Caption:=Trim(CDS_Sub.fieldbyname('BPJS').AsString);
    BPMiDu.Caption:=Trim(CDS_Sub.fieldbyname('BPMiDu').AsString);
    RSGYLXName.Caption:=Trim(CDS_Sub.fieldbyname('GYLXName').AsString);
    FBPIDSH:=Trim(CDS_Sub.fieldbyname('SKID').AsString);
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select A.*,B.* from ML_Manage_GX A ');
      SQL.Add('inner join GY_ZDY B on B.GYID=A.GYID ');
      sql.Add('where A.MLID='''+Trim(FCYID)+'''');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_GX);
    SInitCDSData20(ADOQueryMain,Order_GX);
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.*,B.* ');
      sql.Add('from RT_PTColor A ');
      sql.Add('inner join BP_ColZDY B on B.PTID=A.PTID ');
      sql.Add('where isnull(B.SKID,'''')='''+trim(FBPIDSH)+''' and isnull(B.SKID,'''')<>''''');
      sql.Add(' order by cast(B.ColNo as int)');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,OrdBP_SH);
    SInitCDSData20(ADOQueryMain,OrdBP_SH);
    if FCYID='' then
    begin
      with ADOQueryMain do
      begin
        Close;
        SQL.Clear;
        sql.Add('select * from GY_ZDY ');
        sql.Add('where ZGYName='''+Trim(FGYName)+''' and GYflag=''TJName''');
        Open;
      end;
      MLNo.Caption:=ADOQueryMain.fieldbyname('ZGYCode').AsString;
      FML:=ADOQueryMain.fieldbyname('ZGYCode').AsString;
    end else
    begin
      with ADOQueryMain do
      begin
        Close;
        SQL.Clear;
        sql.Add('select * from GY_ZDY ');
        sql.Add('where ZGYName='''+Trim(FGYName)+''' and GYflag=''TJName''');
        //ShowMessage(sql.Text);
        Open;
      end;
      FML:=ADOQueryMain.fieldbyname('ZGYCode').AsString;
    end;
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmMLManage_LRXH.FormShow(Sender: TObject);
var
  fsj:String;
begin
  ReadCxGrid('烫金面料管理1',Tv1,'样品管理');
  ReadCxGrid('烫金面料管理2',Tv2,'样品管理');
  InitSubGrid();
  initimageSH();
  initimage();
  Button1.Caption:='保存';
  if viewFlag=True then
  begin
    ToolButton2.Visible:=False;
    ToolButton3.Visible:=False;
    TAdd.Visible:=False;
    ToolButton5.Visible:=False;
    Button1.Visible:=False;
  end;
end;

function TfrmMLManage_LRXH.SaveData():Boolean;
var
  maxId,maxno,FXDID:String;
  i,j: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 MLID='''+Trim(FCYID)+'''');
      Open;
    end;
    with ADOQueryCmd do
    begin
      if isempty then
      begin
        Append;
        fieldbyname('GYType').Value:=Trim(FGYName);
        FieldByName('GYTypeJC').Value:=Trim(FML);
      end
      else
      begin
        Edit;
      end;
      //ShowMessage(FBPID);
      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.Caption);
      FieldByName('GYLX').Value:=Trim(GYLX.Caption);
      FieldByName('GYLXName').Value:=Trim(GYLXName.Caption);
      //SSetsaveSqlNew(ADOQueryCmd,'ML_Manage',panel9,2);
      RTSetsavedata(ADOQueryCmd,'ML_Manage',panel9,2);
      FieldByName('MLJWMD').Value:=Trim(BPMiDu.Caption);
      FieldByName('MLDLNo').Value:=Trim(FSKID);
      FieldByName('TJColID').Value:=Trim(FTJCoNo);
      Post;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from ML_Manage where GSNo='''+Trim(GSNo.Caption)+'''');
      Open;
    end;
    if ADOQueryCmd.RecordCount>1 then
    begin
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('工艺编号重复!','提示',0);
      Exit;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from ML_Manage where MLNo='''+Trim(MLNo.Caption)+'''');
      sql.add(' and GYLX='''+trim(GYLX.Caption)+'''');
      Open;
    end;
    if ADOQueryCmd.RecordCount>1 then
    begin
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('产品编号+工艺路线重复!','提示',0);
      Exit;
    end;
    FCYID:=Trim(maxno);
    CDS_Sub.DisableControls;
    with CDS_Sub do
    begin
      First;
      while not Eof do
      begin
        if Trim(CDS_Sub.fieldbyname('MPID').AsString)='' then
        begin
          if GetLSNo(ADOQueryCmd,maxId,'MP','ML_Manage_PB',4,1)=False then
          begin
            Result:=False;
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('区最大号失败！','提示',0);
            Exit;
          end;
        end else
        begin
          maxId:=Trim(CDS_Sub.fieldbyname('MPID').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from ML_Manage_PB where MPID='''+Trim(maxId)+'''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if isempty then
          begin
            Append;
          end else
          begin
            Edit;
          end;
          FieldByName('MPID').Value:=Trim(maxId);
          FieldByName('MLID').Value:=Trim(FCYID);
          FieldByName('BPID').Value:=Trim(CDS_Sub.fieldbyname('BPID').AsString);
          Post;
        end;
        Next;
      end;
    end;
    CDS_Sub.EnableControls;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete ML_Manage_GX where MLID='''+Trim(FCYID)+'''');
      ExecSQL;
    end;
    Order_GX.DisableControls;
    with Order_GX do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_GX.fieldbyname('GXID').AsString)='' then
        begin
          if GetLSNo(ADOQueryCmd,maxId,'GX','ML_Manage_GX',4,1)=False then
          begin
            Result:=False;
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('区最大号失败！','提示',0);
            Exit;
          end;
        end else
        begin
          maxId:=Trim(Order_GX.fieldbyname('GXID').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from ML_Manage_GX where GXID='''+Trim(maxId)+'''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if isempty then
          begin
            Append;
          end else
          begin
            Edit;
          end;
          FieldByName('GXID').Value:=Trim(maxId);
          FieldByName('MLID').Value:=Trim(FCYID);
          fieldbyname('XHNo').Value:=Order_GX.fieldbyname('XHNo').Value;
          FieldByName('GYID').Value:=Trim(Order_GX.fieldbyname('GYID').AsString);
          Post;
        end;
        Next;
      end;
    end;
    Order_GX.EnableControls;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update BP_ZDY Set BPCF='''+Trim(MLCF.Text)+'''');
      sql.Add(' where isnull(BPCode,'''')='''+Trim(BPCode.Caption)+'''');
      sql.Add(' and isnull(BPType,'''')=''坯布'' ');
      ExecSQL;
    end;
    with ScrollBox2 do
    begin
      for i:=0 to ScrollBox2.ControlCount-1 do
      begin
        if Controls[i] is TfrmSLT then
        begin
          with TfrmSLT(Controls[i]).Panel1 do
          begin
            for j:=0 to ControlCount-1 do
            begin
              if Controls[j] is TButton then
              begin
                TButton(Controls[j]).Click;
              end;
            end;
          end;
        end;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except;
    Result:=True;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败!','提示',0);
  end;
end;

procedure TfrmMLManage_LRXH.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.Caption:=Trim(FCP);
  if FLX<>'' then
  begin
    if FGYLX='' then
    GYLX.Caption:=Trim(FLX)
    else
    GYLX.Caption:=FGYLX+'+'+Trim(FLX);
  end
  else
  begin
    GYLX.Caption:=FGYLX;
  end;
  if FLXName<>'' then
  begin
    if FGYLXName='' then
    GYLXName.Caption:=Trim(FLXName)
    else
    GYLXName.Caption:=FGYLXName+'+'+Trim(FLXName);
  end
  else
  begin
    GYLXName.Caption:=FGYLXName;
  end;
end;

procedure TfrmMLManage_LRXH.imagePL(FFF:Integer);
begin

end;

procedure TfrmMLManage_LRXH.initimage();
var
  i,j,z,x,q:Integer;
begin
  with Self.ScrollBox1 do
  begin
    for i:=0 to Self.ScrollBox1.ControlCount-1 do
    begin
      if Controls[i] is TPanel then
      begin
        TPanel(Controls[i]).Visible:=false;
      end;
    end;
  end;
  OrdBP_SH.DisableControls;
  with OrdBP_SH do
  begin
    First;
    i:=0;
    q:=1;
    while not Eof do
    begin
      //if (q>(my-1)*50) and (q<=my*50) then
      begin
        with ScrollBox1 do
        begin
          TPanel(Controls[i]).Visible:=True;
          TPanel(Controls[i]).Hint:=Trim(OrdBP_SH.Fieldbyname('PTID').AsString);
          TPanel(Controls[i]).Color:=StrToInt('$'+Trim(OrdBP_SH.Fieldbyname('ColDaiMa').AsString));
          with TPanel(Controls[i]) do
          begin
            TLabel(Controls[0]).Caption:=Trim(OrdBP_SH.Fieldbyname('ColNo').AsString);
            TLabel(Controls[1]).Caption:=Trim(OrdBP_SH.Fieldbyname('ColNameKH').AsString);
            TLabel(Controls[0]).Visible:=true;
            TLabel(Controls[1]).Visible:=true;
            TLabel(Controls[0]).Color:=clWhite;
            TLabel(Controls[1]).Color:=clWhite;
          end;
        end;
        i:=i+1;
      end;
      q:=q+1;
      Next;
    end;
  end;
  OrdBP_SH.EnableControls;
end;

procedure TfrmMLManage_LRXH.ToolButton2Click(Sender: TObject);
begin
  if CDS_Sub.IsEmpty=false then
  begin
    CDS_Sub.Delete;
    //Application.MessageBox('已存在坯布信息','提示');
   // exit;
  end;
  frmBPZDY_LRPB:=TfrmBPZDY_LRPB.create(self);
  with frmBPZDY_LRPB do
  begin
    flag:='PBName';
    flagName:='坯布';
    ViewFlag:=true;
    Panel4.Align:=alClient;
    ToolBar3.Visible:=false;
    Button1.Visible:=False;
    if ShowModal=1 then
    begin
      with CDS_Sub do
      begin
        append;
        FieldByName('BPCode').Value:=Trim(ClientDataSet1.fieldbyname('BPCode').AsString);
        FieldByName('BPID').Value:=Trim(ClientDataSet1.fieldbyname('BPID').AsString);
        FieldByName('BPName').Value:=Trim(ClientDataSet1.fieldbyname('BPName').AsString);
        FieldByName('BPMF').Value:=Trim(ClientDataSet1.fieldbyname('BPMF').AsString);
        FieldByName('BPKZ').Value:=Trim(ClientDataSet1.fieldbyname('BPKZ').AsString);
        FieldByName('BPCF').Value:=Trim(ClientDataSet1.fieldbyname('BPCF').AsString);
        FieldByName('BPJS').Value:=Trim(ClientDataSet1.fieldbyname('BPJS').AsString);
        FieldByName('BPWS').Value:=Trim(ClientDataSet1.fieldbyname('BPWS').AsString);
        FieldByName('BPMiDu').Value:=Trim(ClientDataSet1.fieldbyname('BPMiDu').AsString);
        FieldByName('CPMiDu').Value:=Trim(ClientDataSet1.fieldbyname('CPMiDu').AsString);
        FieldByName('SKID').Value:=trim(ClientDataSet1.fieldbyname('SKID').AsString);
        post;
      end;
      self.BPCode.caption:=Trim(ClientDataSet1.fieldbyname('BPCode').AsString);
      Self.BPName.caption:=Trim(ClientDataSet1.fieldbyname('BPName').AsString);
      Self.MLName.Text:=Trim(ClientDataSet1.fieldbyname('BPName').AsString);
      Self.MLCF.Text:=Trim(ClientDataSet1.fieldbyname('BPCF').AsString);
      Self.BPMF.Caption:=Trim(ClientDataSet1.fieldbyname('BPMF').AsString);
      Self.BPKZ.Caption:=Trim(ClientDataSet1.fieldbyname('BPKZ').AsString);
      Self.BPCF.Caption:=Trim(ClientDataSet1.fieldbyname('BPCF').AsString);
      Self.BPJS.Caption:=Trim(ClientDataSet1.fieldbyname('BPJS').AsString);
      Self.BPMiDu.Caption:=Trim(ClientDataSet1.fieldbyname('BPMiDu').AsString);
      //Self.CPMiDu.Caption:=Trim(ClientDataSet1.fieldbyname('CPMiDu').AsString);
      Self.FBPID:=Trim(ClientDataSet1.fieldbyname('BPID').AsString);
      if ClientDataSet1.fieldbyname('SKID').AsString='' then
        self.FBPIDSH:=Trim(ClientDataSet1.fieldbyname('BPCode').AsString)
      else
        self.FBPIDSH:=Trim(ClientDataSet1.fieldbyname('SKID').AsString);
      BHCZhu();
      with ADOQueryMain do
      begin
        Close;
        sql.Clear;
        sql.Add('select A.*,B.* from RT_PTColor A ');
        sql.Add('inner join BP_ColZDY B on B.PTID=A.PTID ');
        sql.Add('where isnull(B.SKID,'''')='''+trim(self.FBPIDSH)+''' and isnull(B.SKID,'''')<>''''');
        sql.Add(' order by cast(B.ColNo as int)');
        Open;
      end;
      SCreateCDS20(ADOQueryMain,OrdBP_SH);
      SInitCDSData20(ADOQueryMain,OrdBP_SH);
      //initimageSH();
      initimage();
    end;
    free;
  end;
end;

procedure TfrmMLManage_LRXH.ToolButton3Click(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then exit;
  if CDS_Sub.fieldbyname('MPID').AsString<>'' then
  begin
    if Application.MessageBox('确定要删除数据吗','提示',1)=2 then exit;
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('delete from ML_Manage_PB where MPID='''+trim(CDS_Sub.fieldbyname('MPID').AsString)+'''');
      ExecSQL;
    end;
  end;
  CDS_Sub.Delete;
  BHCZhu();
end;

procedure TfrmMLManage_LRXH.ToolButton5Click(Sender: TObject);
var FGYName:string;
begin
  if Order_GX.IsEmpty then exit;
  if Order_GX.fieldbyname('GXID').AsString<>'' then
  begin
    if Application.MessageBox('确定要删除数据吗','提示',1)=2 then exit;
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('delete from ML_Manage_GX where GXID='''+trim(Order_GX.fieldbyname('GXID').AsString)+'''');
      ExecSQL;
    end;
  end;
  Order_GX.Delete;
  BHCZhu();
end;

procedure TfrmMLManage_LRXH.TAddClick(Sender: TObject);
var FGYLX,FGSNo:string;
begin
  frmBPZDY_LRTJ:=TfrmBPZDY_LRTJ.create(self);
  with frmBPZDY_LRTJ do
  begin
    flag:='TJName';
    flagName:='烫金';
    ViewFlag:=true;
    FGYName:=Self.FGYName;
    Label12.Visible:=true;
    DASH.Visible:=true;
    cxGrid3.Align:=alClient;
    Panel2.Visible:=false;
    Panel4.Visible:=false;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.* from GY_ZDY A where 1=2');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,ML_GX);
    Order_GX.DisableControls;
    with Order_GX do
    begin
      First;
      while not Eof do
      begin
        with ML_GX do
        begin
          Append;
          FieldByName('XHNo').Value:=Order_GX.fieldbyname('XHNo').Value;
          FieldByName('ZGYCode').Value:=Trim(Order_GX.fieldbyname('ZGYCode').AsString);
          FieldByName('ZGYName').Value:=Trim(Order_GX.fieldbyname('ZGYName').AsString);
          FieldByName('GYCode').Value:=Trim(Order_GX.fieldbyname('GYCode').AsString);
          FieldByName('GYName').Value:=Trim(Order_GX.fieldbyname('GYName').AsString);
          FieldByName('GYID').Value:=Trim(Order_GX.fieldbyname('GYID').AsString);
          Post;
        end;
        Next;
      end;
    end;
    Order_GX.EnableControls;
    if ShowModal=1 then
    begin
      with ADOQueryMain do
      begin
        Close;
        SQL.Clear;
        sql.Add(' select A.*,B.* from ML_Manage_GX A ');
        SQL.Add('inner join GY_ZDY B on B.GYID=A.GYID ');
        sql.Add('where 1=2 ');
        Open;
      end;
      SCreateCDS20(ADOQueryMain,Order_GX);
      SInitCDSData20(ADOQueryMain,Order_GX);
      ML_GX.DisableControls;
      with ML_GX do
      begin
        first;
        while not eof do
        begin
          with Order_GX do
          begin
            append;
            FieldByName('XHNo').Value:=ML_GX.fieldbyname('XHNo').Value;
            FieldByName('ZGYCode').Value:=Trim(ML_GX.fieldbyname('ZGYCode').AsString);
            FieldByName('ZGYName').Value:=Trim(ML_GX.fieldbyname('ZGYName').AsString);
            FieldByName('GYCode').Value:=Trim(ML_GX.fieldbyname('GYCode').AsString);
            FieldByName('GYName').Value:=Trim(ML_GX.fieldbyname('GYName').AsString);
            FieldByName('GYID').Value:=Trim(ML_GX.fieldbyname('GYID').AsString);
            post;
          end;
          Next;
        end;
      end;
      ML_GX.EnableControls;
      BHCZhu();
    end;
    free;
  end;
end;

procedure TfrmMLManage_LRXH.ToolButton4Click(Sender: TObject);
begin
  if CDS_Sub.IsEmpty=false then
  begin
    Application.MessageBox('已存在面料信息','提示');
    exit;
  end;
  frmMLMange_ADDCX:=TfrmMLMange_ADDCX.Create(self);
  with frmMLMange_ADDCX do
  begin
    if ShowModal=1 then
    begin
      with CDS_Sub do
      begin
        Append;
        FieldByName('BPCode').Value:=CDS_Main.fieldbyname('MLNo').AsString;
        FieldByName('BPID').Value:=Trim(CDS_Main.fieldbyname('MLID').AsString);
        FieldByName('BPName').Value:=CDS_Main.fieldbyname('MLName').AsString;
        FieldByName('BPMF').Value:=CDS_Main.fieldbyname('MLMF').AsString;
        FieldByName('BPKZ').Value:=CDS_Main.fieldbyname('MLKZ').AsString;
        post;
      end;
      GYLX.Caption:=CDS_Main.fieldbyname('GYLX').AsString;
      FGYLX:=CDS_Main.fieldbyname('GYLX').AsString;
      GSNo.Caption:=CDS_Main.fieldbyname('GSNo').AsString;
      FGSNo:=CDS_Main.fieldbyname('GSNo').AsString;
      FGYLXName:=CDS_Main.fieldbyname('GYLXName').AsString;
      FGSName:=CDS_Main.fieldbyname('GYName').AsString;
      BHCZhu();
    end;
    free;
  end;
end;

procedure TfrmMLManage_LRXH.Button1Click(Sender: TObject);
var FBH:string;
begin
  if CDS_Sub.IsEmpty then
  begin
    application.MessageBox('请选择坯布信息','提示');
    exit;
  end;
  if Trim(MLName.Text)='' then
  begin
    Application.MessageBox('品名不能为空!','提示',0);
    Exit;
  end;
  if Trim(MLKZ.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_LRXH.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_LRXH.Button2Click(Sender: TObject);
begin
  WriteCxGrid('烫金面料管理1',Tv1,'样品管理');
  WriteCxGrid('烫金面料管理2',Tv2,'样品管理');
  close;
end;

procedure TfrmMLManage_LRXH.MLNameChange(Sender: TObject);
begin
  if Trim(FCYID)<>'' then
  begin
    Button1.Caption:='保存改'
  end;
end;

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

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

procedure TfrmMLManage_LRXH.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_LRXH.Panel42MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  OrdBP_SH.Locate('PTID',TPanel(Sender).Hint,[]);
end;

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

procedure TfrmMLManage_LRXH.ToolButton1Click(Sender: TObject);
begin
  frmMLMangeRS_Sel:=TfrmMLMangeRS_Sel.Create(self);
  with frmMLMangeRS_Sel do
  begin
    if ShowModal=1 then
    begin
      with CDS_Sub do
      begin
        append;
        FieldByName('BPCode').Value:=Trim(CDS_Main.fieldbyname('MLNo').AsString);
        FieldByName('BPID').Value:=Trim(CDS_Main.fieldbyname('MLID').AsString);
        FieldByName('BPName').Value:=Trim(CDS_Main.fieldbyname('MLName').AsString);
        FieldByName('BPMF').Value:=Trim(CDS_Main.fieldbyname('MLMF').AsString);
        FieldByName('BPKZ').Value:=Trim(CDS_Main.fieldbyname('MLKZ').AsString);
        FieldByName('BPCF').Value:=Trim(CDS_Main.fieldbyname('MLCF').AsString);
        FieldByName('BPJS').Value:=Trim(CDS_Main.fieldbyname('MLJWMD').AsString);
        fieldbyname('GYLXName').Value:=Trim(CDS_Main.fieldbyname('GYLXName').AsString);
        fieldbyname('SKID').Value:=Trim(CDS_Main.fieldbyname('SKID').AsString);
        post;
      end;
      self.RSGYLXName.Caption:=Trim(CDS_Main.fieldbyname('GYLXName').AsString);
      self.BPCode.caption:=Trim(CDS_Main.fieldbyname('MLNo').AsString);
      Self.BPName.caption:=Trim(CDS_Main.fieldbyname('MLName').AsString);
      Self.MLName.Text:=Trim(CDS_Main.fieldbyname('MLName').AsString);
      Self.MLCF.Text:=Trim(CDS_Main.fieldbyname('MLCF').AsString);
      Self.BPMF.Caption:=Trim(CDS_Main.fieldbyname('MLMF').AsString);
      Self.BPKZ.Caption:=Trim(CDS_Main.fieldbyname('MLKZ').AsString);
      Self.BPCF.Caption:=Trim(CDS_Main.fieldbyname('MLCF').AsString);
      Self.BPJS.Caption:=Trim(CDS_Main.fieldbyname('MLJWMD').AsString);
      Self.FBPID:=Trim(CDS_Main.fieldbyname('MLID').AsString);
      self.FBPIDSH:=Trim(CDS_Main.fieldbyname('SKID').AsString);
      BHCZhu();
      with ADOQueryMain do
      begin
        Close;
        sql.Clear;
        sql.Add('select A.*,B.* from RT_PTColor A ');
        sql.Add('inner join BP_ColZDY B on B.PTID=A.PTID ');
        sql.Add('where isnull(B.SKID,'''')='''+trim(self.FBPIDSH)+''' and isnull(B.SKID,'''')<>''''');
        sql.Add(' order by cast(B.ColNo as int)');
        Open;
      end;
      SCreateCDS20(ADOQueryMain,OrdBP_SH);
      SInitCDSData20(ADOQueryMain,OrdBP_SH);
      initimage();
    end;
    free;
  end;
end;

procedure TfrmMLManage_LRXH.Button5Click(Sender: TObject);
begin
  try
    frmBPZDY_Panel_M:=TfrmBPZDY_Panel_M.Create(Application);
    with frmBPZDY_Panel_M do
    begin
      if ShowModal=1 then
      begin
        with Ord_ZB do
        begin
          Edit;
          FieldByName('ColDaiMa').Value:=Trim(Ord_SH.FieldByName('ColDaiMa').AsString);
          FieldByName('PTID').Value:=Trim(Ord_SH.FieldByName('PTID').AsString);
          FieldByName('ColNameEng').Value:=Trim(Ord_SH.FieldByName('ColNameEng').AsString);
          FieldByName('ColName').Value:=Trim(Ord_SH.FieldByName('ColName').AsString);
          FieldByName('ColNameKH').Value:=Trim(Ord_SH.FieldByName('ColNameKH').AsString);
          FieldByName('ColNo').Value:=Trim(Ord_SH.FieldByName('ColNo').AsString);
        end;
        FTJCoNo:=Trim(Ord_SH.FieldByName('ColID').AsString);
        self.Label41.Caption:=Trim(Ord_SH.FieldByName('ColNo').AsString);
        self.Label42.Caption:=Trim(Ord_SH.FieldByName('ColNameKH').AsString);
        Panel10.Color:=StrToInt('$'+Trim(Ord_SH.FieldByName('ColDaiMa').AsString));
      end;
    end;
  finally
    frmBPZDY_Panel_M.Free;
  end;
end;

procedure TfrmMLManage_LRXH.MenuItem1Click(Sender: TObject);
var
  i:Integer;
begin
  //ShowMessage(FPT);
  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;

end.
