unit U_MLManage_LR;

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;

type
  TfrmMLManage_LR = class(TForm)
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    TBClose: TToolButton;
    CDS_Sub: TClientDataSet;
    ADOQueryMain: TADOQuery;
    DataSource2: TDataSource;
    ADOQueryCmd: TADOQuery;
    ADOQueryTemp: TADOQuery;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Panel1: TPanel;
    cxGridPopupMenu2: TcxGridPopupMenu;
    Order_GX: TClientDataSet;
    DataSource1: TDataSource;
    Panel2: TPanel;
    ToolBar2: TToolBar;
    TAdd: TToolButton;
    ToolButton5: TToolButton;
    Panel3: TPanel;
    ToolBar3: TToolBar;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    V1Ssel: TcxGridDBColumn;
    V1BPCode: TcxGridDBColumn;
    V1BPName: TcxGridDBColumn;
    V1BPMF: TcxGridDBColumn;
    V1BPKZ: TcxGridDBColumn;
    V1BPJS: TcxGridDBColumn;
    v1BPMiDu: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridDBColumn2: TcxGridDBColumn;
    TVBPName: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Panel4: TPanel;
    ML_Col: TClientDataSet;
    DataSource3: TDataSource;
    cxGridPopupMenu3: TcxGridPopupMenu;
    V2XHNo: TcxGridDBColumn;
    Label1: TLabel;
    Label3: TLabel;
    GSNo: TEdit;
    MLNo: TEdit;
    V2BPPrice: TcxGridDBColumn;
    V2BPGYSName: TcxGridDBColumn;
    GYLX: TEdit;
    cxGrid3: TcxGrid;
    TV3: TcxGridDBTableView;
    V2BPSeHao: TcxGridDBColumn;
    V2BPCol: TcxGridDBColumn;
    V2CBPColEng: TcxGridDBColumn;
    V2BPNote: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    cxGrid4: TcxGrid;
    TV4: TcxGridDBTableView;
    v2ZDYCode: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v2Column12: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v2defstr3: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    Ord_HX: TClientDataSet;
    DataSource4: TDataSource;
    cxGridPopupMenu4: TcxGridPopupMenu;
    Label4: TLabel;
    GYName: TEdit;
    GYLXName: TEdit;
    MLName: TEdit;
    Label2: TLabel;
    MLMF: TEdit;
    MLKZ: TEdit;
    MLDLNo: TBtnEditA;
    DLHXK: TBtnEditA;
    Panel5: TPanel;
    Label5: TLabel;
    Panel6: TPanel;
    Label6: TLabel;
    Panel7: TPanel;
    Label7: TLabel;
    Panel8: TPanel;
    Label8: TLabel;
    ToolButton4: TToolButton;
    procedure FormShow(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure TAddClick(Sender: TObject);
    procedure MLDLNoBtnClick(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure DLHXKBtnClick(Sender: TObject);
  private
    Fint:Integer;
    procedure InitSubGrid();
    function  SaveData():Boolean;
    procedure BHCZhu();
    { Private declarations }
  public
    FCYID,FCYCode,FCPID,FCPNO,FBPID,FGYName,FML,FGYLX,FGSNo,FHXBPID,FGSName:String;
    FGYLXName:string;
    { Public declarations }
  end;

var
  frmMLManage_LR: TfrmMLManage_LR;

implementation
uses
  U_DataLink,U_Fun,U_BPZdy_LR,U_BPZdy_SH,U_MLMange_ADDCX, U_BPZdy_HXK,U_BPZdy_LRPB,U_BPZdy_LRGX;

{$R *.dfm}

procedure TfrmMLManage_LR.InitSubGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from ML_Manage where MLID='''+trim(FCYID)+'''');
      Open;
    end;
    if ADOQueryMain.IsEmpty=false then
    begin
      SCSHDataNew(ADOQueryMain,Panel1,2);
      SCSHDataNew(ADOQueryMain,Panel3,2);
      FBPID:=Trim(ADOQueryMain.FieldByName('MBPID').Value);
    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');
      sql.Add(',B.BPJS,B.BPWS,B.BPMiDu,B.BPUnit');
      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);
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select A.*,B.*,C.* from ML_Manage_GX A ');
      SQL.Add('inner join BP_ZDY B on B.BPID=A.BPID ');
      SQL.Add('inner join BP_ZDY_Sub C on C.BPSubID=A.BPSubID ');
      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 * from BP_ZDY_Sub ');
      sql.Add('where BPCode='''+Trim(MLDLNo.Text)+''' and BPflag=''SHK''');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,ML_Col);
    SInitCDSData20(ADOQueryMain,ML_Col);
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      sql.Add('select A.* ');
      sql.Add(',IFTP=(case when isnull((select Top 1 B.CYID from XD_File B where B.CYID=A.BPSubID),'''')='''' then '''' else ''是'' end)');
      sql.Add(' from BP_ZDY_Sub A ');
      sql.Add(' where A.BPCode='''+trim(DLHXK.Text)+'''');
      open;
    end;
    SCreateCDS20(ADOQueryMain,Ord_HX);
    SInitCDSData20(ADOQueryMain,Ord_HX);
    if FCYID='' then
    begin
      with ADOQueryMain do
      begin
        Close;
        SQL.Clear;
        sql.Add('select * from BP_ZDY ');
        sql.Add('where BPName='''+Trim(FGYName)+''' and BPflag=''GXName''');
        Open;
      end;
      MLNo.Text:=ADOQueryMain.fieldbyname('BPCode').AsString;
      FML:=ADOQueryMain.fieldbyname('BPCode').AsString;
    end;
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmMLManage_LR.FormShow(Sender: TObject);
var
  fsj:String;
begin
  ReadCxGrid('面料管理1',Tv1,'样品管理');
  ReadCxGrid('面料管理2',Tv2,'样品管理');
  InitSubGrid();
end;

procedure TfrmMLManage_LR.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('面料管理1',Tv1,'样品管理');
  WriteCxGrid('面料管理2',Tv2,'样品管理');
  Close;
end;

function TfrmMLManage_LR.SaveData():Boolean;
var
  maxId,maxno:String;
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;
    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;
      FieldByName('MLID').Value:=Trim(maxno);
      FieldByName('MBPID').Value:=Trim(FBPID);
      FieldByName('MLType').Value:='单面料';
      SSetsaveSqlNew(ADOQueryCmd,'ML_Manage',panel1,2);
      SSetsaveSqlNew(ADOQueryCmd,'ML_Manage',panel3,2);
      Post;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from ML_Manage where GSNo='''+Trim(GSNo.Text)+'''');
      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.Text)+'''');
      sql.add(' and GYLX='''+trim(GYLX.Text)+'''');
      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;
    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('BPID').Value:=Trim(Order_GX.fieldbyname('BPID').AsString);
          FieldByName('BPSubID').Value:=Trim(Order_GX.fieldbyname('BPSubID').AsString);
          Post;
        end;
        Next;
      end;
    end;
    Order_GX.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except;
    Result:=True;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败!','提示',0);
  end;
end;

procedure TfrmMLManage_LR.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('BPGYSName').AsString);
      FLLName:=FLLName+trim(Order_GX.fieldbyname('BPPrice').AsString);
      if FLX='' then
      FLX:=trim(Order_GX.fieldbyname('BPGYSName').AsString)
      else
      FLX:=FLX+'→'+trim(Order_GX.fieldbyname('BPGYSName').AsString);
      if FLXName='' then
      FLXName:=trim(Order_GX.fieldbyname('BPPrice').AsString)
      else
      FLXName:=FLXName+'→'+trim(Order_GX.fieldbyname('BPPrice').AsString);
      Next;
    end;
  end;
  Order_GX.EnableControls;
  GSNo.Text:=FGSNo+Trim(FLL);
  GYName.Text:=FGSName+Trim(FLLName);
  MLNo.Text:=Trim(FCP);
  if FLX<>'' then
  begin
    if FGYLX='' then
    GYLX.Text:=Trim(FLX)
    else
    GYLX.Text:=FGYLX+'→'+Trim(FLX);
  end
  else
  begin
    GYLX.Text:=FGYLX;
  end;
  if FLXName<>'' then
  begin
    if FGYLXName='' then
    GYLXName.Text:=Trim(FLXName)
    else
    GYLXName.Text:=FGYLXName+'→'+Trim(FLXName);
  end
  else
  begin
    GYLXName.Text:=FGYLXName;
  end;
end;

procedure TfrmMLManage_LR.ToolButton1Click(Sender: TObject);
var FBH:string;
begin
  {if Trim(MLNo.Text)='' then
  begin
    Application.MessageBox('编号不能为空!','提示',0);
    Exit;
  end; }
  if Trim(MLName.Text)='' then
  begin
    Application.MessageBox('品名不能为空!','提示',0);
    Exit;
  end;
  //BHCZhu();
  if SaveData() then
  begin
    Application.MessageBox('保存成功！','提示',0);
    ModalResult:=1;
  end;
end;

procedure TfrmMLManage_LR.ToolButton2Click(Sender: TObject);
begin
  if CDS_Sub.IsEmpty=false then
  begin
    Application.MessageBox('已存在坯布信息','提示');
    exit;
  end;
  frmBPZDY_LRPB:=TfrmBPZDY_LRPB.create(self);
  with frmBPZDY_LRPB do
  begin
    flag:='PBName';
    flagName:='坯布';
    ViewFlag:=true;
    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('BPJS').Value:=Trim(ClientDataSet1.fieldbyname('BPJS').AsString);
        FieldByName('BPWS').Value:=Trim(ClientDataSet1.fieldbyname('BPWS').AsString);
        FieldByName('BPMiDu').Value:=Trim(ClientDataSet1.fieldbyname('BPMiDu').AsString);
        post;
      end;
      FGSNo:=FGSNo+trim(CDS_Sub.fieldbyname('BPCode').AsString);
      FGSName:=FGSName+trim(CDS_Sub.fieldbyname('BPName').AsString);
      BHCZhu();
    end;
    free;
  end;
end;

procedure TfrmMLManage_LR.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_LR.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(CDS_Sub.fieldbyname('GXID').AsString)+'''');
      ExecSQL;
    end;
  end;
  Order_GX.Delete;
  BHCZhu();
end;

procedure TfrmMLManage_LR.TAddClick(Sender: TObject);
var FGYLX,FGSNo:string;
begin
  frmBPZDY_LRGX:=TfrmBPZDY_LRGX.create(self);
  with frmBPZDY_LRGX do
  begin
    flag:='GXName';
    flagName:='工序';
    ViewFlag:=true;
    Panel2.Visible:=false;
    frmBPZDY_LR.FGYName:=Self.FGYName;
    if FGYName='染色' then
    begin
      Label12.Visible:=true;
      DASH.Visible:=true;
    end;
    cxGrid3.Align:=alClient;
    if ShowModal=1 then
    begin
      with ML_GX do
      begin
        first;
        while not eof do
        begin
          with Order_GX do
          begin
            append;
            FieldByName('XHNo').Value:=ML_GX.fieldbyname('BPMiDu').Value;
            FieldByName('BPCode').Value:=Trim(ML_GX.fieldbyname('BPCode').AsString);
            FieldByName('BPName').Value:=Trim(ML_GX.fieldbyname('BPName').AsString);
            FieldByName('BPGYSName').Value:=Trim(ML_GX.fieldbyname('BPMF').AsString);
            FieldByName('BPPrice').Value:=Trim(ML_GX.fieldbyname('BPKZ').AsString);
            FieldByName('BPID').Value:=Trim(ML_GX.fieldbyname('BPID').AsString);
            FieldByName('BPSubID').Value:=Trim(ML_GX.fieldbyname('BPSubID').AsString);
            post;
          end;
          Next;
        end;
      end;
      //ShowMessage(FGYLX);
      MLDLNo.Text:=DASH.Text;
      FBPID:=Trim(DASH.TxtCode);
      BHCZhu();
      with ADOQueryMain do
      begin
        Close;
        SQL.Clear;
        sql.Add('select * from BP_ZDY_Sub ');
        sql.Add('where BPCode='''+Trim(MLDLNo.Text)+''' and BPflag=''SHK''');
        Open;
      end;
      SCreateCDS20(ADOQueryMain,ML_Col);
      SInitCDSData20(ADOQueryMain,ML_Col);
      with ADOQueryCmd do
      begin
        Close;
        SQL.Clear;
        sql.Add('select A.* ');
        sql.Add(',IFTP=(case when isnull((select Top 1 B.CYID from XD_File B where B.CYID=A.BPSubID),'''')='''' then '''' else ''是'' end)');
        sql.Add(' from BP_ZDY_Sub A ');
        sql.Add(' where A.BPCode='''+trim(DLHXK.Text)+'''');
        open;
      end;
      SCreateCDS20(ADOQueryCmd,Ord_HX);
      SInitCDSData20(ADOQueryCmd,Ord_HX);
    end;
    free;
  end;
end;

procedure TfrmMLManage_LR.MLDLNoBtnClick(Sender: TObject);
begin
  try
    frmBPZDY_SH:=TfrmBPZDY_SH.Create(self);
    with frmBPZDY_SH do
    begin
      flag:='SHK';
      flagName:='色号库';
      ViewFlag:=true;
      if ShowModal=1 then
      begin
        self.MLDLNo.Text:=Trim(frmBPZDY_SH.ClientDataSet1.fieldbyname('BPCode').AsString);
        self.FBPID:=Trim(frmBPZDY_SH.ClientDataSet1.fieldbyname('BPID').AsString);
        with ADOQueryMain do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from BP_ZDY_Sub ');
          sql.Add('where BPCode='''+Trim(Self.MLDLNo.Text)+''' and BPflag=''SHK''');
          Open;
        end;
      end;
    end;
  finally
    frmBPZDY_SH.Free;
  end;
end;

procedure TfrmMLManage_LR.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.Text:=CDS_Main.fieldbyname('GYLX').AsString;
      FGYLX:=CDS_Main.fieldbyname('GYLX').AsString;
      GSNo.Text:=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_LR.DLHXKBtnClick(Sender: TObject);
begin
  frmBPZDY_HXK:=TfrmBPZDY_HXK.Create(self);
  with frmBPZDY_HXK do
  begin
    flag:='HXK';
    flagName:='花型库';
    ViewFlag:=true;
    if ShowModal=1 then
    begin
      Self.DLHXK.Text:=Trim(ClientDataSet1.fieldbyname('BPCode').AsString);
      FHXBPID:=Trim(ClientDataSet1.fieldbyname('BPID').AsString);
      with ADOQueryCmd do
      begin
        Close;
        SQL.Clear;
        sql.Add('select A.* ');
        sql.Add(',IFTP=(case when isnull((select Top 1 B.CYID from XD_File B where B.CYID=A.BPSubID),'''')='''' then '''' else ''是'' end)');
        sql.Add(' from BP_ZDY_Sub A ');
        sql.Add(' where A.BPCode='''+trim(DLHXK.Text)+'''');
        open;
      end;
      SCreateCDS20(ADOQueryCmd,Ord_HX);
      SInitCDSData20(ADOQueryCmd,Ord_HX);
    end;
    free;
  end;
end;

end.
