unit U_CKProductBCPOutList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, cxGridCustomTableView,
  cxGridTableView, cxGridBandedTableView, cxGridDBBandedTableView,
  cxGridLevel, cxClasses, cxControls, cxGridCustomView, cxGridDBTableView,
  cxGrid, StdCtrls, ComCtrls, ExtCtrls, ToolWin, cxGridCustomPopupMenu,
  cxGridPopupMenu, ADODB, DBClient, cxDropDownEdit, RM_Common, RM_Class,
  RM_e_Xls, RM_Dataset, RM_System, RM_GridReport, cxCheckBox, Menus,
  MovePanel, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;

type
  TfrmCKProductBCPOutList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label3: TLabel;
    Label4: TLabel;
    PRTCodeName: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    Tv1: TcxGridDBTableView;
    cxGrid2Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    Label5: TLabel;
    orderNo: TEdit;
    Label6: TLabel;
    MJID: TEdit;
    v1Column7: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    Label8: TLabel;
    PRTKZ: TEdit;
    Label9: TLabel;
    PRTMF: TEdit;
    Label7: TLabel;
    CPType: TComboBox;
    v1Column3: TcxGridDBColumn;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    v1Column4: TcxGridDBColumn;
    Label10: TLabel;
    CkOrdNo: TEdit;
    v1Column5: TcxGridDBColumn;
    TBCKCX: TToolButton;
    v1Column11: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    MovePanel2: TMovePanel;
    v1Column12: TcxGridDBColumn;
    cxGridPopupMenu2: TcxGridPopupMenu;
    cxGridPopupMenu3: TcxGridPopupMenu;
    ComboBox1: TComboBox;
    RM1: TRMGridReport;
    v1Column13: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    cxGridPopupMenu4: TcxGridPopupMenu;
    PRTColor: TEdit;
    v1BAOID: TcxGridDBColumn;
    Panel4: TPanel;
    Label11: TLabel;
    Panel10: TPanel;
    Image2: TImage;
    RichEdit1: TRichEdit;
    v1Column10: TcxGridDBColumn;
    Label12: TLabel;
    PRTHX: TEdit;
    Label13: TLabel;
    SOrddefstr1: TEdit;
    Label14: TLabel;
    DataSource1: TDataSource;
    ADOQueryPrint: TADOQuery;
    v1Column17: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    MJstr4: TEdit;
    Label15: TLabel;
    CheckBox1: TCheckBox;
    RMDBHZ: TRMDBDataSet;
    CDS_HZ: TClientDataSet;
    CDS_PRT: TClientDataSet;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure PRTCodeNameChange(Sender: TObject);
    procedure TBPrintClick(Sender: TObject);
    procedure orderNoChange(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure TBCKCXClick(Sender: TObject);
    procedure orderNoKeyPress(Sender: TObject; var Key: Char);
    procedure AOrdDefStr1Change(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure Tv1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Image2Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
  private
      FLeft,FTop:Integer;
    procedure InitGrid();
    function  YSData(Order_Main10:TClientDataSet):Boolean;

    Procedure JSbaoNum();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmCKProductBCPOutList: TfrmCKProductBCPOutList;

implementation
uses
  U_DataLink,U_Fun;

{$R *.dfm}
Procedure TfrmCKProductBCPOutList.JSbaoNum();
var
  i:integer;
  baoID:string;
  strlist:Tstringlist;
begin
  i:=0;
  baoID:='';
  IF CDS_Main.IsEmpty then
  begin
    Label12.Caption:='包数：0';
    exit;
  end;
  strlist:=Tstringlist.Create;
  try
    with CDS_Main do
    begin
      DisableControls;
      first;
      while not eof do
      begin
        
        IF  (trim(fieldbyname('BaoNO').AsString)<>'') then
        begin
          IF strlist.IndexOf(trim(fieldbyname('subID').AsString)+trim(fieldbyname('BaoNO').AsString))<0 then
          begin
            strlist.Add(trim(fieldbyname('subID').AsString)+trim(fieldbyname('BaoNO').AsString));
          end;
        end;
     {   IF (trim(fieldbyname('BaoID').AsString)<>trim(baoID)) and (trim(fieldbyname('BaoID').AsString)<>'') then
        begin
          i:=i+1;
          baoID:=trim(fieldbyname('BaoID').AsString);
        end;  }
        Next;
      end;
      EnableControls;
    end;
    Label12.Caption:='包数：'+inttostr(strlist.Count);
  finally
    strlist.Free;
  end;
end;



procedure TfrmCKProductBCPOutList.FormDestroy(Sender: TObject);
begin
  frmCKProductBCPOutList:=nil;
end;


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

procedure TfrmCKProductBCPOutList.FormCreate(Sender: TObject);
begin
  BegDate.DateTime:=SGetServerDateTime(ADOQueryTemp);
  EndDate.DateTime:=SGetServerDateTime(ADOQueryTemp)
end;

procedure TfrmCKProductBCPOutList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      SQL.Add('select A.*,B.OrderNo,C.PRTCodeName,C.PRTSpec,C.PRTColor,C.SOrddefstr1,C.PRTMF,C.PRTKZ,D.MJXH,C.PRTPrice,C.PRTHX ');
      sql.Add(',C.SOrddefstr4,D.MJQty3,D.MJQty4');
      sql.Add(',PONO=(select Top 1 KHConNo from JYOrderCon_Main JCM where JCM.ConNo=B.OrderNo)');
      sql.Add(',MPRTECodeName=(select Top 1 MPRTCodeName from JYOrderCon_Main JCM where JCM.ConNo=B.OrderNo)');
      sql.Add(',isnull(customerNoName,B.OrderNo) KHName');
      sql.Add(',cast(D.mjstr4 as varchar(20)) as mjstr4,D.MJstr5 ');
      sql.add('from CK_BanCP_CR A ');
      Sql.add(' inner join JYOrder_Main B on A.MainId=B.MainId');
      Sql.add(' inner join JYOrder_Sub C on A.SubId=C.SubId');
      Sql.add(' inner join WFB_MJJY D on A.MJId=D.MJId');
      sql.add('where A.CRTime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime))+'''');
      sql.add('  and A.CRTime<'''+Trim(FormatDateTime('yyyy-MM-dd',enddate.DateTime+1))+'''');
      SQL.Add(' and CRType=''正常出库'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
    TBFind.Click;
end;

procedure TfrmCKProductBCPOutList.TBRafreshClick(Sender: TObject);
begin
  BegDate.SetFocus;
  InitGrid();
end;

procedure TfrmCKProductBCPOutList.ConNoMChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  end;
end;

procedure TfrmCKProductBCPOutList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('仓库出库列表',Tv1,'成品仓库');

  Close;
end;

procedure TfrmCKProductBCPOutList.FormShow(Sender: TObject);
begin
  ReadCxGrid('仓库出库列表',Tv1,'成品仓库');


  InitGrid();
  if Trim(DParameters2)='管理' then
  begin
    v1Column11.Visible:=True;
    TBCKCX.Visible:=True;
  end;
end;

procedure TfrmCKProductBCPOutList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then exit;
  SelExportData(Tv1,ADOQueryMain,'');
end;

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

procedure TfrmCKProductBCPOutList.PRTCodeNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmCKProductBCPOutList.TBPrintClick(Sender: TObject);
var
  fPrintFile,fPrintFile10,FMainID:String;
begin
  if CDS_Main.IsEmpty then Exit;
  if trim(ComboBox1.Text)='' then exit;
  if CDS_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据','提示',0);
    Exit;
  end;
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\'+trim(ComboBox1.Text)+'.rmf' ;

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('delete TBSubID where DName='''+Trim(DCode)+'''');
    ExecSQL;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('SELECT * FROM TBSubID where 1=2 ');
    open;
  end;
  FMainID:='';
  CDS_Main.DisableControls;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_Main do
    begin
    First;
    while not Eof do
    begin
      If Fieldbyname('Ssel').AsBoolean then
      begin
        IF FMainID='' then
        begin
          FMainID:=Trim(CDS_Main.fieldbyname('mainID').AsString);
        end
        else
        begin
          IF Trim(CDS_Main.fieldbyname('mainID').AsString)<>FMainID then
          begin
            application.MessageBox('选择的不是同一个指示单，不能一起打印！','提示信息',0);
            ADOQueryCmd.Connection.RollbackTrans;
            EnableControls;
            exit;
          end;
        end;
          ADOQueryCmd.append;
          ADOQueryCmd.fieldbyname('SubId').Value:=Trim(CDS_Main.fieldbyname('MJID').AsString);
          ADOQueryCmd.fieldbyname('Dname').Value:=Trim(DCode);
          ADOQueryCmd.post;
      end;
      Next;
    end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
  end;
  CDS_Main.EnableControls;

      IF (trim(ComboBox1.Text)='销售码单') or (trim(combobox1.Text)='销售码单-安康') then
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('exec P_Print_CKMD ');
      sql.add('@mainID='+quotedstr(Trim('')));
      sql.add(',@DName='+quotedstr(Trim(DCode)));
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_HZ);
    SInitCDSData20(ADOQueryTemp,CDS_HZ);

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('exec P_Do_PrintMd_HZ ');
      sql.add('@mainID='+quotedstr(Trim('')));
      sql.add(',@DName='+quotedstr(Trim(DCode)));
      sql.add(',@flag=''2'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_PRT);
    SInitCDSData20(ADOQueryTemp,CDS_PRT);
  end;

  IF trim(ComboBox1.Text)='销售码单-QLO' then
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add(' SELECT A.mainID,A.subID,A.MJStr4,A.MJLen,A.MJTypeOther,A.baoID,A.baoNo,A.MJQty2,A.MJQty3,A.MJQty4,A.MJMaoZ,A.MJXH,A.MJID, ');
      sql.add('B.SOrddefstr1,B.PRTCodeName,B.prtSpec,B.PRTColor,B.SOrddefstr4,B.PRTHX,B.Sorddefstr6,B.PRTKuanNO,  ');
      sql.add('C.Filler as zl,C.OrdPerson1,C.OrderNo,');
      sql.add('CRTime=(select MAX(CRTime) from CK_BanCP_CR X where X.MJID=A.MJID),');
      sql.add('CKOrdNo=(select MAX(CKOrdNo) from CK_BanCP_CR X where X.MJID=A.MJID )  ');
//      sql.add(',a=count(distinct A.MJStr4)');
      sql.add('FROM WFB_MJJY A');
      sql.add('inner join JYOrder_Sub B on B.MainId=A.MainId and B.SubId=A.subID  ');
      sql.add('inner join JYOrder_Main C on C.MainId=A.MainId   ');
      sql.add('WHERE EXISTS(select SubId from TBSubID X where X.SubId=A.MJID and X.DName='''+DCode+''') ');
      sql.add('ORDER BY A.MainID,A.subID,A.MJStr4,A.MJXH ');
//      showmessage(sql.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_HZ);
    SInitCDSData20(ADOQueryTemp,CDS_HZ);

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('exec P_Do_PrintMd_HZ ');
      sql.add('@mainID='+quotedstr(Trim('')));
      sql.add(',@DName='+quotedstr(Trim(DCode)));
      sql.add(',@flag=''2'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_PRT);
    SInitCDSData20(ADOQueryTemp,CDS_PRT);
  end;

  IF (trim(ComboBox1.Text)='单色包装') OR (trim(ComboBox1.Text)='单色包装-长度') then
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('exec P_Do_PrintMd20 ');
      sql.add('@mainID='+quotedstr(Trim('')));
      sql.add(',@DName='+quotedstr(Trim(DCode)));
      sql.add(',@flag=''0'' ');
      sql.add(',@CNum=''10'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_HZ);
    SInitCDSData20(ADOQueryTemp,CDS_HZ);

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('exec P_Do_PrintMd_HZ ');
      sql.add('@mainID='+quotedstr(Trim('')));
      sql.add(',@DName='+quotedstr(Trim(DCode)));
      sql.add(',@flag=''0'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_PRT);
    SInitCDSData20(ADOQueryTemp,CDS_PRT);
  end;

  IF trim(ComboBox1.Text)='混色包装-10色' then
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('exec P_Do_PrintMd30 ');
      sql.add('@mainID='+quotedstr(Trim('')));
      sql.add(',@DName='+quotedstr(Trim(DCode)));
      sql.add(',@flag=''0'' ');
      sql.add(',@CNum=''10'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_HZ);
    SInitCDSData20(ADOQueryTemp,CDS_HZ);

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('exec P_Do_PrintMd_HZ ');
      sql.add('@mainID='+quotedstr(Trim('')));
      sql.add(',@DName='+quotedstr(Trim(DCode)));
      sql.add(',@flag=''1'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_PRT);
    SInitCDSData20(ADOQueryTemp,CDS_PRT);
  end;
  IF trim(ComboBox1.Text)='混色包装-重量' then
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('exec P_Do_PrintMd30 ');
      sql.add('@mainID='+quotedstr(Trim('')));
      sql.add(',@DName='+quotedstr(Trim(DCode)));
      sql.add(',@flag=''0'' ');
      sql.add(',@CNum=''10'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_HZ);
    SInitCDSData20(ADOQueryTemp,CDS_HZ);

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('exec P_Do_PrintMd_HZ ');
      sql.add('@mainID='+quotedstr(Trim('')));
      sql.add(',@DName='+quotedstr(Trim(DCode)));
      sql.add(',@flag=''1'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_PRT);
    SInitCDSData20(ADOQueryTemp,CDS_PRT);
  end;



  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+fPrintFile),'提示',0);
  end;
end;

{procedure TfrmCKProductBCPOutList.GetLotData();
var
  i,j,z,h,q:Integer;
  FGangNo,FHZ:String;
begin
  if CDS_Main.IsEmpty then Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select GangNo=AP.AOrdDefStr1,A.BaoNo,MJ.MJXH,MJ.MJMaoZ,MJ.MJLen,A.SubId,A.MainId,MJ.MJQty4,');
    sql.Add('DD.OrderNo,JS.PRTColor,PRTEColor=JS.SOrddefstr4,PRTColorNo=JS.SOrddefstr1,JS.PRTHX');
    sql.Add(' from CK_BanCP_CR A');
    sql.Add(' inner join WFB_MJJY MJ on A.MJID=MJ.MJID');
    sql.Add(' inner join JYOrder_Main DD on A.MainId=DD.MainId');
    sql.Add(' inner join JYOrder_Sub JS on A.SubId=JS.SubId');
    sql.Add(' inner join JYOrder_Sub_AnPai AP on A.APID=AP.APID');
    sql.Add(' where A.MainId='''+Trim(CDS_Main.fieldbyname('MainId').AsString)+'''');
    //sql.Add(' and A.SubId='''+Trim(CDS_Main.fieldbyname('SubId').AsString)+'''');
    if Trim(CDS_Main.FieldByName('CKOrdNo').AsString)<>'' then
    begin
      sql.Add(' and A.CKOrdNo='''+Trim(CDS_Main.FieldByName('CKOrdNo').AsString)+'''');
    end;
    if Trim(CPType.Text)<>'' then
    begin
      sql.Add(' and A.CPType='''+Trim(CPType.Text)+'''');
    end;
    sql.Add(' and A.CRType=''正常出库'' ');
    sql.Add(' order by  A.SubId,Cast(AP.AOrdDefStr1 as int),MJ.MJXH');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_Juan);
  SInitCDSData20(ADOQueryTemp,CDS_Juan);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select MainId=Cast('''' as varchar(20)),SubId=Cast('''' as varchar(20)),');
    sql.Add(' PRTEColor=Cast('''' as varchar(20)),PRTHX=Cast('''' as varchar(20)),PRTColorNo=Cast('''' as varchar(20)),');
    sql.Add(' GangNo=Cast('''' as varchar(20)),BaoNo=Cast('''' as varchar(20)),XH=Cast(0 as int),');
    sql.Add(' LenQty0=Cast(1.00 as decimal(18,2)),LenQty1=Cast(1.00 as decimal(18,2)),');
    sql.Add(' LenQty2=Cast(1.00 as decimal(18,2)),LenQty3=Cast(1.00 as decimal(18,2)),');
    sql.Add(' LenQty4=Cast(1.00 as decimal(18,2)),LenQty5=Cast(1.00 as decimal(18,2)),');
    sql.Add(' LenQty6=Cast(1.00 as decimal(18,2)),LenQty7=Cast(1.00 as decimal(18,2)),');
    sql.Add(' LenQty8=Cast(1.00 as decimal(18,2)),LenQty9=Cast(1.00 as decimal(18,2)),');
    sql.Add(' MZ0=Cast(1.00 as decimal(18,2)),MZ1=Cast(1.00 as decimal(18,2)),');
    sql.Add(' MZ2=Cast(1.00 as decimal(18,2)),MZ3=Cast(1.00 as decimal(18,2)),');
    sql.Add(' MZ4=Cast(1.00 as decimal(18,2)),MZ5=Cast(1.00 as decimal(18,2)),');
    sql.Add(' MZ6=Cast(1.00 as decimal(18,2)),MZ7=Cast(1.00 as decimal(18,2)),');
    sql.Add(' MZ8=Cast(1.00 as decimal(18,2)),MZ9=Cast(1.00 as decimal(18,2)),');
    sql.Add(' JZ0=Cast(1.00 as decimal(18,2)),JZ1=Cast(1.00 as decimal(18,2)),');
    sql.Add(' JZ2=Cast(1.00 as decimal(18,2)),JZ3=Cast(1.00 as decimal(18,2)),');
    sql.Add(' JZ4=Cast(1.00 as decimal(18,2)),JZ5=Cast(1.00 as decimal(18,2)),');
    sql.Add(' JZ6=Cast(1.00 as decimal(18,2)),JZ7=Cast(1.00 as decimal(18,2)),');
    sql.Add(' JZ8=Cast(1.00 as decimal(18,2)),JZ9=Cast(1.00 as decimal(18,2)),');
    sql.Add(' MJPS0=Cast(1 as int),MJPS1=Cast(1 as int),');
    sql.Add(' MJPS2=Cast(1 as int),MJPS3=Cast(1 as int),');
    sql.Add(' MJPS4=Cast(1 as int),MJPS5=Cast(1 as int),');
    sql.Add(' MJPS6=Cast(1 as int),MJPS7=Cast(1 as int),');
    sql.Add(' MJPS8=Cast(1 as int),MJPS9=Cast(1 as int),');
    sql.Add(' XH=Cast(0 as int)');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_JuanPRT);
  SInitCDSData20(ADOQueryTemp,CDS_JuanPRT);
  if CDS_JuanPRT.IsEmpty=False then
  begin
    CDS_JuanPRT.Delete;
  end;
  i:=0;j:=0;z:=0;FGangNo:='';h:=0;
  CDS_Juan.DisableControls;
  with CDS_Juan do
  begin
    First;
    while not Eof do
    begin
      //FHZ:=Trim(CDS_Juan.fieldbyname('SubId').AsString)+Trim(CDS_Juan.fieldbyname('BaoNO').AsString)
           //+Trim(CDS_Juan.fieldbyname('GangNo').AsString);
      with CDS_JuanPRT do
      begin
        if CDS_JuanPRT.IsEmpty then
        begin
          CDS_JuanPRT.Append;
          CDS_JuanPRT.FieldByName('GangNo').Value:=CDS_Juan.fieldbyname('GangNo').Value;
         // CDS_JuanPRT.FieldByName('BaoNO').Value:=CDS_Juan.fieldbyname('BaoNO').Value;
          CDS_JuanPRT.FieldByName('PRTEColor').Value:=CDS_Juan.fieldbyname('PRTEColor').Value;
          CDS_JuanPRT.FieldByName('PRTColorNo').Value:=CDS_Juan.fieldbyname('PRTColorNo').Value;
          CDS_JuanPRT.FieldByName('PRTHX').Value:=CDS_Juan.fieldbyname('PRTHX').Value;
          CDS_JuanPRT.FieldByName('MJPS0').Value:=1;
          CDS_JuanPRT.FieldByName('XH').Value:=0;
          CDS_JuanPRT.FieldByName('LenQty0').Value:=CDS_Juan.fieldbyname('MJLen').Value;
          CDS_JuanPRT.FieldByName('MZ0').Value:=CDS_Juan.fieldbyname('MJMaoZ').Value;
          CDS_JuanPRT.FieldByName('JZ0').Value:=CDS_Juan.fieldbyname('MJQty4').Value;
          CDS_JuanPRT.FieldByName('SubId').Value:=CDS_Juan.fieldbyname('SubId').Value;
          CDS_JuanPRT.FieldByName('MainId').Value:=CDS_Juan.fieldbyname('MainId').Value;
          CDS_JuanPRT.Post;
          FHZ:=Trim(CDS_Juan.fieldbyname('SubId').AsString)
           +Trim(CDS_Juan.fieldbyname('GangNo').AsString);
          //FGangNo:=Trim(CDS_Juan.fieldbyname('GangNo').AsString);
          Z:=0;//gang 后缀
          j:=0;//行号
          for i:=1 to 9 do
          begin
            CDS_JuanPRT.Edit;
            CDS_JuanPRT.FieldByName('MJPS'+Trim(IntToStr(i))).Value:=0;
            CDS_JuanPRT.Post;
          end;
        end else
        begin
          if (Trim(CDS_Juan.fieldbyname('SubId').AsString)
             +Trim(CDS_Juan.fieldbyname('GangNo').AsString))<>FHZ then
          begin
            CDS_JuanPRT.Append;
            CDS_JuanPRT.FieldByName('GangNo').Value:=CDS_Juan.fieldbyname('GangNo').Value;
            //CDS_JuanPRT.FieldByName('BaoNO').Value:=CDS_Juan.fieldbyname('BaoNO').Value;
            CDS_JuanPRT.FieldByName('PRTEColor').Value:=CDS_Juan.fieldbyname('PRTEColor').Value;
            CDS_JuanPRT.FieldByName('PRTColorNo').Value:=CDS_Juan.fieldbyname('PRTColorNo').Value;
            CDS_JuanPRT.FieldByName('PRTHX').Value:=CDS_Juan.fieldbyname('PRTHX').Value;
            CDS_JuanPRT.FieldByName('MJPS0').Value:=1;
            CDS_JuanPRT.FieldByName('XH').Value:=J+1;
            CDS_JuanPRT.FieldByName('LenQty0').Value:=CDS_Juan.fieldbyname('MJLen').Value;
            CDS_JuanPRT.FieldByName('MZ0').Value:=CDS_Juan.fieldbyname('MJMaoZ').Value;
            CDS_JuanPRT.FieldByName('JZ0').Value:=CDS_Juan.fieldbyname('MJQty4').Value;
            CDS_JuanPRT.FieldByName('SubId').Value:=CDS_Juan.fieldbyname('SubId').Value;
            CDS_JuanPRT.FieldByName('MainId').Value:=CDS_Juan.fieldbyname('MainId').Value;
            CDS_JuanPRT.Post;
            FHZ:=Trim(CDS_Juan.fieldbyname('SubId').AsString)
               +Trim(CDS_Juan.fieldbyname('GangNo').AsString);
            Z:=0;//gang 后缀
            j:=j+1;//行号
            for i:=1 to 9 do
            begin
              CDS_JuanPRT.Edit;
              CDS_JuanPRT.FieldByName('MJPS'+Trim(IntToStr(i))).Value:=0;
              CDS_JuanPRT.Post;
            end;
          end else
          begin
            if Z<10 then
            begin
              CDS_JuanPRT.Locate('XH',j,[]);
              with CDS_JuanPRT do
              begin
                Edit;
                FieldByName('GangNo').Value:=CDS_Juan.fieldbyname('GangNo').Value;
                //FieldByName('BaoNO').Value:=CDS_Juan.fieldbyname('BaoNO').Value;
                CDS_JuanPRT.FieldByName('PRTEColor').Value:=CDS_Juan.fieldbyname('PRTEColor').Value;
                CDS_JuanPRT.FieldByName('PRTColorNo').Value:=CDS_Juan.fieldbyname('PRTColorNo').Value;
                CDS_JuanPRT.FieldByName('PRTHX').Value:=CDS_Juan.fieldbyname('PRTHX').Value;
                FieldByName('MJPS'+Trim(IntToStr(Z))).Value:=1;
                FieldByName('LenQty'+Trim(IntToStr(Z))).Value:=CDS_Juan.fieldbyname('MJLen').Value;
                CDS_JuanPRT.FieldByName('MZ'+Trim(IntToStr(Z))).Value:=CDS_Juan.fieldbyname('MJMaoZ').Value;
                CDS_JuanPRT.FieldByName('JZ'+Trim(IntToStr(Z))).Value:=CDS_Juan.fieldbyname('MJQty4').Value;
                FieldByName('SubId').Value:=CDS_Juan.fieldbyname('SubId').Value;
                FieldByName('MainId').Value:=CDS_Juan.fieldbyname('MainId').Value;
                Post;
              end;
            end else
            begin
              CDS_JuanPRT.Append;
              CDS_JuanPRT.FieldByName('GangNo').Value:=CDS_Juan.fieldbyname('GangNo').Value;
              CDS_JuanPRT.FieldByName('BaoNO').Value:=CDS_Juan.fieldbyname('BaoNO').Value;
              CDS_JuanPRT.FieldByName('PRTEColor').Value:=CDS_Juan.fieldbyname('PRTEColor').Value;
              CDS_JuanPRT.FieldByName('PRTColorNo').Value:=CDS_Juan.fieldbyname('PRTColorNo').Value;
              CDS_JuanPRT.FieldByName('PRTHX').Value:=CDS_Juan.fieldbyname('PRTHX').Value;
              CDS_JuanPRT.FieldByName('MJPS0').Value:=1;
              CDS_JuanPRT.FieldByName('XH').Value:=J+1;
              CDS_JuanPRT.FieldByName('LenQty0').Value:=CDS_Juan.fieldbyname('MJLen').Value;
              CDS_JuanPRT.FieldByName('MZ0').Value:=CDS_Juan.fieldbyname('MJMaoZ').Value;
              CDS_JuanPRT.FieldByName('JZ0').Value:=CDS_Juan.fieldbyname('MJQty4').Value;
              CDS_JuanPRT.FieldByName('SubId').Value:=CDS_Juan.fieldbyname('SubId').Value;
              CDS_JuanPRT.FieldByName('MainId').Value:=CDS_Juan.fieldbyname('MainId').Value;
              CDS_JuanPRT.Post;
              Z:=0;//gang 后缀
              j:=j+1;//行号
              for i:=1 to 9 do
              begin
                CDS_JuanPRT.Edit;
                CDS_JuanPRT.FieldByName('MJPS'+Trim(IntToStr(i))).Value:=0;
                CDS_JuanPRT.Post;
              end;
            end;
          end;
        end
      end;
      Z:=Z+1;
      Next;
    end;
  end;
  CDS_Juan.EnableControls;
end;}

{procedure TfrmCKProductBCPOutList.GetBaoData();
var
  i,j,z,h:Integer;
  FGangNo:String;
begin
  if CDS_Main.IsEmpty then Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select GangNo=AP.AOrdDefStr1,A.BaoNo,MJ.MJXH,MJ.MJMaoZ,MJ.MJLen');
    sql.Add(' from CK_BanCP_CR A');
    sql.Add(' inner join WFB_MJJY MJ on A.MJID=MJ.MJID');
    sql.Add(' inner join JYOrder_Main DD on A.MainId=DD.MainId');
    sql.Add(' inner join JYOrder_Sub_AnPai AP on A.APID=AP.APID');
    sql.Add(' where A.MainId='''+Trim(CDS_Main.fieldbyname('MainId').AsString)+'''');
    sql.Add(' and A.SubId='''+Trim(CDS_Main.fieldbyname('SubId').AsString)+'''');
    if Trim(CDS_Main.FieldByName('CKOrdNo').AsString)<>'' then
    begin
      sql.Add(' and A.CKOrdNo='''+Trim(CDS_Main.FieldByName('CKOrdNo').AsString)+'''');
    end;
    if Trim(CPType.Text)<>'' then
    begin
      sql.Add(' and A.CPType='''+Trim(CPType.Text)+'''');
    end;
    sql.Add(' and A.CRType=''正常出库'' ');
    sql.Add(' order by  Cast(AP.AOrdDefStr1 as int),Cast(A.BaoNo as int),MJ.MJXH');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_BaoNo);
  SInitCDSData20(ADOQueryTemp,CDS_BaoNo);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select GangNo0=Cast('''' as varchar(20)),GangNo1=Cast('''' as varchar(20)),GangNo2=Cast('''' as varchar(20)),');
    sql.Add(' GangNo3=Cast('''' as varchar(20)),GangNo4=Cast('''' as varchar(20)),XH=Cast('''' as varchar(20))');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_BaoPRT);
  SInitCDSData20(ADOQueryTemp,CDS_BaoPRT);
  if CDS_BaoPRT.IsEmpty=False then
  begin
    CDS_BaoPRT.Delete;
  end;
  i:=0;j:=0;z:=0;FGangNo:='';h:=0;
  CDS_BaoNo.DisableControls;
  with CDS_BaoNo do
  begin
    First;
    while not Eof do
    begin
      with CDS_BaoPRT do
      begin
        if CDS_BaoPRT.IsEmpty then
        begin
          if J=0 then
          begin
            CDS_BaoPRT.Append;
            CDS_BaoPRT.FieldByName('GangNo0').Value:=CDS_BaoNo.fieldbyname('GangNo').Value;
            CDS_BaoPRT.FieldByName('XH').Value:='0';
            CDS_BaoPRT.Post;
            FGangNo:=Trim(CDS_BaoNo.fieldbyname('GangNo').AsString);
            J:=0;//XH   行号
            Z:=0;//gang 后缀
            h:=0;//每行的记录数。
          end;
        end else
        begin
          if i>9 then
          begin
            Z:=Z+1;
            if Z>4 then
            begin
              Z:=0;
              J:=J+1;
              CDS_BaoPRT.Append;
              CDS_BaoPRT.FieldByName('GangNo0').Value:=CDS_BaoNo.fieldbyname('GangNo').Value;
              CDS_BaoPRT.FieldByName('XH').Value:=Trim(IntToStr(J));
              CDS_BaoPRT.Post;
              FGangNo:=Trim(CDS_BaoNo.fieldbyname('GangNo').AsString);
            end else
            begin
              CDS_BaoPRT.Locate('XH',Trim(IntToStr(J)),[]);
              CDS_BaoPRT.Edit;
              CDS_BaoPRT.FieldByName('GangNo'+Trim(IntToStr(Z))).Value:=CDS_BaoNo.fieldbyname('GangNo').Value;
              CDS_BaoPRT.Post;
              FGangNo:=Trim(CDS_BaoNo.fieldbyname('GangNo').AsString);
            end;
            i:=0;
          end else
          begin
            if FGangNo<>Trim(CDS_BaoNo.fieldbyname('GangNo').AsString) then
            begin
              Z:=Z+1;
              if Z>4 then
              begin
                Z:=0;
                J:=J+1;
                CDS_BaoPRT.Append;
                CDS_BaoPRT.FieldByName('GangNo0').Value:=CDS_BaoNo.fieldbyname('GangNo').Value;
                CDS_BaoPRT.FieldByName('XH').Value:=Trim(IntToStr(J));
                CDS_BaoPRT.Post;
                FGangNo:=Trim(CDS_BaoNo.fieldbyname('GangNo').AsString);
              end else
              begin
                CDS_BaoPRT.Locate('XH',Trim(IntToStr(J)),[]);
                CDS_BaoPRT.Edit;
                CDS_BaoPRT.FieldByName('GangNo'+Trim(IntToStr(Z))).Value:=CDS_BaoNo.fieldbyname('GangNo').Value;
                CDS_BaoPRT.Post;
                FGangNo:=Trim(CDS_BaoNo.fieldbyname('GangNo').AsString);
              end;
              i:=0;
            end;
          end;
        end;
      end;
      i:=i+1;
      Next;
    end;
  end;
  CDS_BaoNo.EnableControls;

end;}

{procedure TfrmCKProductBCPOutList.GetBaleData();
var
  i,j,z,h,q:Integer;
  FGangNo,FHZ:String;
begin
  if CDS_Main.IsEmpty then Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select GangNo=AP.AOrdDefStr1,A.BaoNo,MJ.MJXH,MJ.MJMaoZ,MJ.MJLen,A.SubId,A.MainId,');
    sql.Add('DD.OrderNo,JS.PRTColor,PRTEColor=JS.SOrddefstr4,JS.PRTHX');
    sql.Add(' from CK_BanCP_CR A');
    sql.Add(' inner join WFB_MJJY MJ on A.MJID=MJ.MJID');
    sql.Add(' inner join JYOrder_Main DD on A.MainId=DD.MainId');
    sql.Add(' inner join JYOrder_Sub JS on A.SubId=JS.SubId');
    sql.Add(' inner join JYOrder_Sub_AnPai AP on A.APID=AP.APID');
    sql.Add(' where A.MainId='''+Trim(CDS_Main.fieldbyname('MainId').AsString)+'''');
    //sql.Add(' and A.SubId='''+Trim(CDS_Main.fieldbyname('SubId').AsString)+'''');
    if Trim(CDS_Main.FieldByName('CKOrdNo').AsString)<>'' then
    begin
      sql.Add(' and A.CKOrdNo='''+Trim(CDS_Main.FieldByName('CKOrdNo').AsString)+'''');
    end;
    if Trim(CPType.Text)<>'' then
    begin
      sql.Add(' and A.CPType='''+Trim(CPType.Text)+'''');
    end;
    sql.Add(' and A.CRType=''正常出库'' ');
    sql.Add(' order by  Cast(AP.AOrdDefStr1 as int),Cast(A.BaoNo as int),MJ.MJXH');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_Juan);
  SInitCDSData20(ADOQueryTemp,CDS_Juan);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select MainId=Cast('''' as varchar(20)),SubId=Cast('''' as varchar(20)),');
    sql.Add(' PRTEColor=Cast('''' as varchar(20)),PRTHX=Cast('''' as varchar(20)),');
    sql.Add(' GangNo=Cast('''' as varchar(20)),BaoNo=Cast('''' as varchar(20)),MJPS=Cast(0 as int),XH=Cast(0 as int),');
    sql.Add(' LenQty0=Cast(1.00 as decimal(18,2)),LenQty1=Cast(1.00 as decimal(18,2)),');
    sql.Add(' LenQty2=Cast(1.00 as decimal(18,2)),LenQty3=Cast(1.00 as decimal(18,2)),');
    sql.Add(' LenQty4=Cast(1.00 as decimal(18,2)),LenQty5=Cast(1.00 as decimal(18,2)),');
    sql.Add(' LenQty6=Cast(1.00 as decimal(18,2)),LenQty7=Cast(1.00 as decimal(18,2)),');
    sql.Add(' LenQty8=Cast(1.00 as decimal(18,2)),LenQty9=Cast(1.00 as decimal(18,2)),');
    sql.Add(' LenQty10=Cast(1.00 as decimal(18,2)),LenQty11=Cast(1.00 as decimal(18,2)),');
    sql.Add(' MJPS0=Cast(0 as int),MJPS1=Cast(0 as int),');
    sql.Add(' MJPS2=Cast(0 as int),MJPS3=Cast(0 as int),');
    sql.Add(' MJPS4=Cast(0 as int),MJPS5=Cast(0 as int),');
    sql.Add(' MJPS6=Cast(0 as int),MJPS7=Cast(0 as int),');
    sql.Add(' MJPS8=Cast(0 as int),MJPS9=Cast(0 as int),');
    sql.Add(' MJPS10=Cast(0 as int),MJPS11=Cast(1 as int),XH=Cast(0 as int)');
    //sql.Add(' KgQty0=Cast(1.00 as decimal(18,2)),KgQty1=Cast(1.00 as decimal(18,2)),');
    //sql.Add(' LenQty2=Cast(1.00 as decimal(18,2)),LenQty3=Cast(1.00 as decimal(18,2)),');
    //sql.Add(' LenQty4=Cast(1.00 as decimal(18,2)),LenQty5=Cast(1.00 as decimal(18,2)),');
    //sql.Add(' LenQty5=Cast(1.00 as decimal(18,2)),LenQty7=Cast(1.00 as decimal(18,2)),');
    //sql.Add(' LenQty6=Cast(1.00 as decimal(18,2)),LenQty9=Cast(1.00 as decimal(18,2)),');
    //sql.Add(' LenQty10=Cast(1.00 as decimal(18,2)),LenQty11=Cast(1.00 as decimal(18,2)),');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_JuanPRT);
  SInitCDSData20(ADOQueryTemp,CDS_JuanPRT);
  if CDS_JuanPRT.IsEmpty=False then
  begin
    CDS_JuanPRT.Delete;
  end;
  i:=0;j:=0;z:=0;FGangNo:='';h:=0;
  CDS_Juan.DisableControls;
  with CDS_Juan do
  begin
    First;
    while not Eof do
    begin
      //FHZ:=Trim(CDS_Juan.fieldbyname('SubId').AsString)+Trim(CDS_Juan.fieldbyname('BaoNO').AsString)
           //+Trim(CDS_Juan.fieldbyname('GangNo').AsString);
      with CDS_JuanPRT do
      begin
        if CDS_JuanPRT.IsEmpty then
        begin
          CDS_JuanPRT.Append;
          CDS_JuanPRT.FieldByName('GangNo').Value:=CDS_Juan.fieldbyname('GangNo').Value;
          CDS_JuanPRT.FieldByName('BaoNO').Value:=CDS_Juan.fieldbyname('BaoNO').Value;
          CDS_JuanPRT.FieldByName('PRTEColor').Value:=CDS_Juan.fieldbyname('PRTEColor').Value;
          CDS_JuanPRT.FieldByName('PRTHX').Value:=CDS_Juan.fieldbyname('PRTHX').Value;
          CDS_JuanPRT.FieldByName('MJPS0').Value:=1;
          CDS_JuanPRT.FieldByName('XH').Value:=0;
          CDS_JuanPRT.FieldByName('LenQty0').Value:=CDS_Juan.fieldbyname('MJLen').Value;
          CDS_JuanPRT.FieldByName('SubId').Value:=CDS_Juan.fieldbyname('SubId').Value;
          CDS_JuanPRT.FieldByName('MainId').Value:=CDS_Juan.fieldbyname('MainId').Value;
          CDS_JuanPRT.Post;
          FHZ:=Trim(CDS_Juan.fieldbyname('SubId').AsString)+Trim(CDS_Juan.fieldbyname('BaoNO').AsString)
           +Trim(CDS_Juan.fieldbyname('GangNo').AsString);
          //FGangNo:=Trim(CDS_Juan.fieldbyname('GangNo').AsString);
          Z:=0;//gang 后缀
          j:=0;//行号
        end else
        begin
          if (Trim(CDS_Juan.fieldbyname('SubId').AsString)+Trim(CDS_Juan.fieldbyname('BaoNO').AsString)
             +Trim(CDS_Juan.fieldbyname('GangNo').AsString))<>FHZ then
          begin
            CDS_JuanPRT.Append;
            CDS_JuanPRT.FieldByName('GangNo').Value:=CDS_Juan.fieldbyname('GangNo').Value;
            CDS_JuanPRT.FieldByName('BaoNO').Value:=CDS_Juan.fieldbyname('BaoNO').Value;
            CDS_JuanPRT.FieldByName('PRTEColor').Value:=CDS_Juan.fieldbyname('PRTEColor').Value;
            CDS_JuanPRT.FieldByName('PRTHX').Value:=CDS_Juan.fieldbyname('PRTHX').Value;
            CDS_JuanPRT.FieldByName('MJPS0').Value:=1;
            CDS_JuanPRT.FieldByName('XH').Value:=J+1;
            CDS_JuanPRT.FieldByName('LenQty0').Value:=CDS_Juan.fieldbyname('MJLen').Value;
            CDS_JuanPRT.FieldByName('SubId').Value:=CDS_Juan.fieldbyname('SubId').Value;
            CDS_JuanPRT.FieldByName('MainId').Value:=CDS_Juan.fieldbyname('MainId').Value;
            CDS_JuanPRT.Post;
            FHZ:=Trim(CDS_Juan.fieldbyname('SubId').AsString)+Trim(CDS_Juan.fieldbyname('BaoNO').AsString)
               +Trim(CDS_Juan.fieldbyname('GangNo').AsString);
            Z:=0;//gang 后缀
            j:=j+1;//行号
          end else
          begin
            if Z<12 then
            begin
              CDS_JuanPRT.Locate('XH',j,[]);
              with CDS_JuanPRT do
              begin
                Edit;
                FieldByName('GangNo').Value:=CDS_Juan.fieldbyname('GangNo').Value;
                FieldByName('BaoNO').Value:=CDS_Juan.fieldbyname('BaoNO').Value;
                CDS_JuanPRT.FieldByName('PRTEColor').Value:=CDS_Juan.fieldbyname('PRTEColor').Value;
                CDS_JuanPRT.FieldByName('PRTHX').Value:=CDS_Juan.fieldbyname('PRTHX').Value;
                FieldByName('MJPS'+Trim(IntToStr(Z))).Value:=1;
                FieldByName('LenQty'+Trim(IntToStr(Z))).Value:=CDS_Juan.fieldbyname('MJLen').Value;
                FieldByName('SubId').Value:=CDS_Juan.fieldbyname('SubId').Value;
                FieldByName('MainId').Value:=CDS_Juan.fieldbyname('MainId').Value;
                Post;
              end;
            end else
            begin
              CDS_JuanPRT.Append;
              CDS_JuanPRT.FieldByName('GangNo').Value:=CDS_Juan.fieldbyname('GangNo').Value;
              CDS_JuanPRT.FieldByName('BaoNO').Value:=CDS_Juan.fieldbyname('BaoNO').Value;
              CDS_JuanPRT.FieldByName('PRTEColor').Value:=CDS_Juan.fieldbyname('PRTEColor').Value;
              CDS_JuanPRT.FieldByName('PRTHX').Value:=CDS_Juan.fieldbyname('PRTHX').Value;
              CDS_JuanPRT.FieldByName('MJPS0').Value:=1;
              CDS_JuanPRT.FieldByName('XH').Value:=J+1;
              CDS_JuanPRT.FieldByName('LenQty0').Value:=CDS_Juan.fieldbyname('MJLen').Value;
              CDS_JuanPRT.FieldByName('SubId').Value:=CDS_Juan.fieldbyname('SubId').Value;
              CDS_JuanPRT.FieldByName('MainId').Value:=CDS_Juan.fieldbyname('MainId').Value;
              CDS_JuanPRT.Post;
              Z:=0;//gang 后缀
              j:=j+1;//行号
            end;
          end;
        end
      end;
      Z:=Z+1;
      Next;
    end;
  end;
  CDS_Juan.EnableControls;
end; }
{procedure TfrmCKProductBCPOutList.GetJuanData();
var
  i,j,z,h,q:Integer;
  FGangNo:String;
begin
  if CDS_Main.IsEmpty then Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select GangNo=AP.AOrdDefStr1,A.BaoNo,MJ.MJXH,MJ.MJMaoZ,MJ.MJLen,A.SubId,A.MainId');
    sql.Add(' from CK_BanCP_CR A');
    sql.Add(' inner join WFB_MJJY MJ on A.MJID=MJ.MJID');
    sql.Add(' inner join JYOrder_Main DD on A.MainId=DD.MainId');
    sql.Add(' inner join JYOrder_Sub JS on A.SubId=JS.SubId');
    sql.Add(' inner join JYOrder_Sub_AnPai AP on A.APID=AP.APID');
    sql.Add(' where A.MainId='''+Trim(CDS_Main.fieldbyname('MainId').AsString)+'''');
    sql.Add(' and A.SubId='''+Trim(CDS_Main.fieldbyname('SubId').AsString)+'''');
    if Trim(CDS_Main.FieldByName('CKOrdNo').AsString)<>'' then
    begin
      sql.Add(' and A.CKOrdNo='''+Trim(CDS_Main.FieldByName('CKOrdNo').AsString)+'''');
    end;
    if Trim(CPType.Text)<>'' then
    begin
      sql.Add(' and A.CPType='''+Trim(CPType.Text)+'''');
    end;
    sql.Add(' and A.CRType=''正常出库'' ');
    sql.Add(' order by  Cast(AP.AOrdDefStr1 as int),Cast(A.BaoNo as int),MJ.MJXH');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_Juan);
  SInitCDSData20(ADOQueryTemp,CDS_Juan);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select BaoNo0=Cast('''' as varchar(20)),MJXH0=Cast(0 as int),MJPS0=Cast(1 as int),');
    sql.Add('MJPS1=Cast(1 as int),MJPS2=Cast(1 as int),MJPS3=Cast(1 as int),MJPS4=Cast(1 as int),');
    sql.Add(' KGQty0=Cast(1.00 as decimal(18,2)),LenQty0=Cast(1.00 as decimal(18,2)),');
    sql.Add(' BaoNo1=Cast('''' as varchar(20)),MJXH1=Cast(0 as int),');
    sql.Add(' KGQty1=Cast(1.00 as decimal(18,2)),LenQty1=Cast(1.00 as decimal(18,2)),');
    sql.Add(' BaoNo2=Cast('''' as varchar(20)),MJXH2=Cast(0 as int),');
    sql.Add(' KGQty2=Cast(1.00 as decimal(18,2)),LenQty2=Cast(1.00 as decimal(18,2)),');
    sql.Add(' BaoNo3=Cast('''' as varchar(20)),MJXH3=Cast(0 as int),');
    sql.Add(' KGQty3=Cast(1.00 as decimal(18,2)),LenQty3=Cast(1.00 as decimal(18,2)),');
    sql.Add(' BaoNo4=Cast('''' as varchar(20)),MJXH4=Cast(0 as int),');
    sql.Add(' KGQty4=Cast(1.00 as decimal(18,2)),LenQty4=Cast(1.00 as decimal(18,2)),');
    sql.Add(' BaoNo5=Cast('''' as varchar(20)),MJXH5=Cast(0 as int),');
    sql.Add(' KGQty5=Cast(1.00 as decimal(18,2)),LenQty5=Cast(1.00 as decimal(18,2)),');
    sql.Add(' GangNo0=Cast('''' as varchar(20)),XH=Cast('''' as varchar(20)),');
    sql.Add(' GangNo1=Cast('''' as varchar(20)),GangNo2=Cast('''' as varchar(20)),');
    sql.Add(' GangNo3=Cast('''' as varchar(20)),GangNo4=Cast('''' as varchar(20))');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_JuanPRT);
  SInitCDSData20(ADOQueryTemp,CDS_JuanPRT);
  if CDS_JuanPRT.IsEmpty=False then
  begin
    CDS_JuanPRT.Delete;
  end;
  i:=0;j:=0;z:=0;FGangNo:='';h:=0;
  CDS_Juan.DisableControls;
  with CDS_Juan do
  begin
    First;
    while not Eof do
    begin
      with CDS_JuanPRT do
      begin
        if CDS_JuanPRT.IsEmpty then
        begin
          begin
            CDS_JuanPRT.Append;
            CDS_JuanPRT.FieldByName('GangNo0').Value:=CDS_Juan.fieldbyname('GangNo').Value;
            CDS_JuanPRT.FieldByName('BaoNO0').Value:=CDS_Juan.fieldbyname('BaoNO').Value;
            CDS_JuanPRT.FieldByName('MJXH0').Value:=CDS_Juan.fieldbyname('MJXH').Value;
            CDS_JuanPRT.FieldByName('MJPS0').Value:=1;
            CDS_JuanPRT.FieldByName('KGQty0').Value:=CDS_Juan.fieldbyname('MJMaoZ').Value;
            CDS_JuanPRT.FieldByName('LenQty0').Value:=CDS_Juan.fieldbyname('MJLen').Value;
            CDS_JuanPRT.FieldByName('XH').Value:='0';
            CDS_JuanPRT.Post;
            FGangNo:=Trim(CDS_Juan.fieldbyname('GangNo').AsString);
            for h:=1 to 9 do
            begin
              CDS_JuanPRT.Append;
              CDS_JuanPRT.FieldByName('XH').Value:=Trim(IntToStr(h));
              CDS_JuanPRT.Post;
            end;
            J:=0;//XH   行号
            Z:=0;//gang 后缀
            //h:=9;//
            q:=0; //页数
          end;
        end else
        begin
          if i>9 then
          begin
            Z:=Z+1;

            if Z>4 then
            begin
              Z:=0;
              q:=q+1;
              J:=q*10;
              CDS_JuanPRT.Append;
              CDS_JuanPRT.FieldByName('GangNo0').Value:=CDS_Juan.fieldbyname('GangNo').Value;
              CDS_JuanPRT.FieldByName('BaoNO0').Value:=CDS_Juan.fieldbyname('BaoNO').Value;
              CDS_JuanPRT.FieldByName('MJXH0').Value:=CDS_Juan.fieldbyname('MJXH').Value;
              CDS_JuanPRT.FieldByName('KGQty0').Value:=CDS_Juan.fieldbyname('MJMaoZ').Value;
              CDS_JuanPRT.FieldByName('LenQty0').Value:=CDS_Juan.fieldbyname('MJLen').Value;
              CDS_JuanPRT.FieldByName('MJPS0').Value:=1;
              CDS_JuanPRT.FieldByName('XH').Value:=Trim(IntToStr(J));
              CDS_JuanPRT.Post;
              for h:=J+1 to J+9 do
              begin
                CDS_JuanPRT.Append;
                CDS_JuanPRT.FieldByName('XH').Value:=Trim(IntToStr(h));
                CDS_JuanPRT.Post;
              end;
              FGangNo:=Trim(CDS_Juan.fieldbyname('GangNo').AsString);
            end else
            begin
              J:=q*10;
              CDS_JuanPRT.Locate('XH',Trim(IntToStr(10*q)),[]);
              CDS_JuanPRT.Edit;
              CDS_JuanPRT.FieldByName('GangNo'+Trim(IntToStr(Z))).Value:=CDS_Juan.fieldbyname('GangNo').Value;
              CDS_JuanPRT.FieldByName('BaoNO'+Trim(IntToStr(Z))).Value:=CDS_Juan.fieldbyname('BaoNO').Value;
              CDS_JuanPRT.FieldByName('MJXH'+Trim(IntToStr(Z))).Value:=CDS_Juan.fieldbyname('MJXH').Value;
              CDS_JuanPRT.FieldByName('MJPS'+Trim(IntToStr(Z))).Value:=1;
              CDS_JuanPRT.FieldByName('KGQty'+Trim(IntToStr(Z))).Value:=CDS_Juan.fieldbyname('MJMaoZ').Value;
              CDS_JuanPRT.FieldByName('LenQty'+Trim(IntToStr(Z))).Value:=CDS_Juan.fieldbyname('MJLen').Value;
              CDS_JuanPRT.Post;
              FGangNo:=Trim(CDS_Juan.fieldbyname('GangNo').AsString);
            end;
            i:=0;
          end else
          begin
            if FGangNo<>Trim(CDS_Juan.fieldbyname('GangNo').AsString) then
            begin
              Z:=Z+1;

              if Z>4 then
              begin
                Z:=0;
                q:=q+1;
                J:=q*10;
                CDS_JuanPRT.Append;
                CDS_JuanPRT.FieldByName('GangNo0').Value:=CDS_Juan.fieldbyname('GangNo').Value;
                CDS_JuanPRT.FieldByName('BaoNO0').Value:=CDS_Juan.fieldbyname('BaoNO').Value;
                CDS_JuanPRT.FieldByName('MJXH0').Value:=CDS_Juan.fieldbyname('MJXH').Value;
                CDS_JuanPRT.FieldByName('KGQty0').Value:=CDS_Juan.fieldbyname('MJMaoZ').Value;
                CDS_JuanPRT.FieldByName('LenQty0').Value:=CDS_Juan.fieldbyname('MJLen').Value;
                CDS_JuanPRT.FieldByName('MJPS0').Value:=1;
                CDS_JuanPRT.FieldByName('XH').Value:=Trim(IntToStr(J));
                CDS_JuanPRT.Post;
                FGangNo:=Trim(CDS_Juan.fieldbyname('GangNo').AsString);
                for h:=J+1 to J+9 do
                begin
                  CDS_JuanPRT.Append;
                  CDS_JuanPRT.FieldByName('XH').Value:=Trim(IntToStr(h));
                  CDS_JuanPRT.Post;
                end;
              end else
              begin
                J:=q*10;
                CDS_JuanPRT.Locate('XH',Trim(IntToStr(10*q)),[]);
                CDS_JuanPRT.Edit;
                CDS_JuanPRT.FieldByName('GangNo'+Trim(IntToStr(Z))).Value:=CDS_Juan.fieldbyname('GangNo').Value;
                CDS_JuanPRT.FieldByName('BaoNO'+Trim(IntToStr(Z))).Value:=CDS_Juan.fieldbyname('BaoNO').Value;
                CDS_JuanPRT.FieldByName('MJXH'+Trim(IntToStr(Z))).Value:=CDS_Juan.fieldbyname('MJXH').Value;
                CDS_JuanPRT.FieldByName('KGQty'+Trim(IntToStr(Z))).Value:=CDS_Juan.fieldbyname('MJMaoZ').Value;
                CDS_JuanPRT.FieldByName('LenQty'+Trim(IntToStr(Z))).Value:=CDS_Juan.fieldbyname('MJLen').Value;
                CDS_JuanPRT.FieldByName('MJPS'+Trim(IntToStr(Z))).Value:=1;
                CDS_JuanPRT.Post;
                FGangNo:=Trim(CDS_Juan.fieldbyname('GangNo').AsString);
              end;
              i:=0;
            end else
            begin
              j:=j+1;
              CDS_JuanPRT.Locate('XH',Trim(IntToStr(J)),[]);
              CDS_JuanPRT.Edit;
              CDS_JuanPRT.FieldByName('GangNo'+Trim(IntToStr(Z))).Value:=CDS_Juan.fieldbyname('GangNo').Value;
              CDS_JuanPRT.FieldByName('BaoNO'+Trim(IntToStr(Z))).Value:=CDS_Juan.fieldbyname('BaoNO').Value;
              CDS_JuanPRT.FieldByName('MJXH'+Trim(IntToStr(Z))).Value:=CDS_Juan.fieldbyname('MJXH').Value;
              CDS_JuanPRT.FieldByName('KGQty'+Trim(IntToStr(Z))).Value:=CDS_Juan.fieldbyname('MJMaoZ').Value;
              CDS_JuanPRT.FieldByName('LenQty'+Trim(IntToStr(Z))).Value:=CDS_Juan.fieldbyname('MJLen').Value;
              CDS_JuanPRT.FieldByName('MJPS'+Trim(IntToStr(Z))).Value:=1;
              CDS_JuanPRT.Post;
              FGangNo:=Trim(CDS_Juan.fieldbyname('GangNo').AsString);
            end;
          end;
        end;
      end;
      i:=i+1;
      Next;
    end;
  end;
  CDS_Juan.EnableControls;
end;   }

procedure TfrmCKProductBCPOutList.orderNoChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmCKProductBCPOutList.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main,True);
end;

procedure TfrmCKProductBCPOutList.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main,False);
end;

procedure TfrmCKProductBCPOutList.TBCKCXClick(Sender: TObject);
var
  FFMainId,FPrice:String;
begin
  if CDS_Main.IsEmpty then Exit;
  if CDS_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要撤销数据吗？','提示',32+4)<>IDYES then Exit;
  MovePanel2.Visible:=True;
  MovePanel2.Refresh;
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Main.DisableControls;
    with CDS_Main do
    begin
      //First;
      while CDS_Main.Locate('SSel',True,[])=True do
      begin
        //if CDS_Main.FieldByName('SSel').AsBoolean=True then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('delete CK_BanCP_CR where BCID='''+Trim(CDS_Main.fieldbyname('BCID').AsString)+'''');
            sql.Add('UPdate CK_BanCP_KC Set KCKgQty=(select KgQty from CK_BanCP_CR A where  A.CRID=CK_BanCP_KC.CRID and A.CRType=''检验入库'') ');
            sql.Add(',KCQty=(select Qty from CK_BanCP_CR A where  A.CRID=CK_BanCP_KC.CRID and A.CRType=''检验入库'') ');
            SQL.Add(' where CRID='+CDS_Main.fieldbyname('CRID').AsString);
            sql.Add('Update WFB_MJJY Set MJStr2=''已入库'' where MJID='''+Trim(CDS_Main.fieldbyname('MJID').AsString)+'''');
            ExecSQL;
          end;
          {if YSData(CDS_Main)=False then
          begin
            CDS_Main.EnableControls;
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('撤销失败!','提示',0);
            Exit;
          end; }
          CDS_Main.Delete;
        end;
      end;
    end;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    MovePanel2.Visible:=False;
    Exit;
  except
    MovePanel2.Visible:=False;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('撤销异常！','提示',0);
  end;

end;
function TfrmCKProductBCPOutList.YSData(Order_Main10:TClientDataSet):Boolean;
var
  CRID,YFID,Price,PriceUnit,OrderUnit:String;
begin
  Result:=False;
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select Top 1 * from JYOrder_Sub Where Mainid='''+Trim(Order_Main10.fieldbyname('MainId').AsString)+'''');
    //sql.Add(' and PRTPrice>0');
    Open;
  end;
  {Price:=ADOQueryTemp.fieldbyname('PRTPrice').AsString;
  if Trim(Price)='' then
  begin
    Price:='0';
  end; }
  PriceUnit:=Trim(ADOQueryTemp.fieldbyname('PriceUnit').AsString);
  OrderUnit:=Trim(ADOQueryTemp.fieldbyname('OrderUnit').AsString);
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from YF_Money_KC where FactoryName='''+Trim(Order_Main10.fieldbyname('KHName').AsString)+'''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty=False then
  begin
    CRID:=ADOQueryTemp.fieldbyname('CRID').AsString;
  end else
  begin
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update YF_Money_CRID set CRID=CRID+1');
      sql.Add('select * from YF_Money_CRID ');
      Open;
    end;
    CRID:=ADOQueryCmd.fieldbyname('CRID').AsString;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from YF_Money_KC where 1<>1');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('CRID').Value:=StrToInt(CRID);
      FieldByName('FactoryName').Value:=Trim(Order_Main10.fieldbyname('KHName').AsString);
      FieldByName('ZdyStr1').Value:='应收收';
      Post;
    end;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from YF_Money_CR where FactoryName='''+Trim(Order_Main10.fieldbyname('KHName').AsString)+'''');
    sql.Add(' and YFTypeId='''+Trim(Order_Main10.fieldbyname('Mainid').AsString)+'''');
    //sql.Add(' and Price='''+Trim(Order_Main10.fieldbyname('PRTPrice').AsString)+'''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty then
  begin
    if GetLSNo(ADOQueryCmd,YFID,'CS','YF_Money_CR',3,1)=False then
    begin
      Application.MessageBox('取坯布应付最大号失败!','提示',0);
      Exit;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from YF_Money_CR where 1<>1');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('YFID').Value:=Trim(YFID);
      FieldByName('YFTypeId').Value:=Trim(Order_Main10.fieldbyname('MainId').AsString);
      FieldByName('CRID').Value:=StrToInt(CRID);
      FieldByName('Filler').Value:=Trim(DName);
      FieldByName('CRType').Value:='应收款登记';
      FieldByName('CRFlag').Value:='应收收';
      FieldByName('QtyFlag').Value:=1;
      FieldByName('FactoryName').Value:=Trim(Order_Main10.fieldbyname('KHName').AsString);
      FieldByName('CRTime').Value:=SGetServerDateTime(ADOQueryTemp);
      FieldByName('YFType').Value:='自动生成';
      FieldByName('Price').Value:=Price;
      //FieldByName('HuiLv').Value:=1;
      FieldByName('BZType').Value:=Trim(PriceUnit);
      FieldByName('QtyUnit').Value:=Trim(OrderUnit);
      FieldByName('YFName').Value:='销售金额';
      FieldByName('MainId').Value:=Trim(Order_Main10.fieldbyname('Mainid').AsString);
      Post;
    end;
  end else
  begin
    YFID:=Trim(ADOQueryTemp.fieldbyname('YFID').AsString);
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    if Trim(OrderUnit)<>'Kg' then
    begin
      sql.Add('update YF_Money_CR Set Qty=(select isnull(Sum(A.Qty),0) from CK_BanCP_CR A  ');
    end else
    begin
      sql.Add('update YF_Money_CR Set Qty=(select isnull(Sum(A.KgQty),0) from CK_BanCP_CR A  ');
    end;
    sql.Add(' inner join JYOrder_Sub B on A.SubId=B.SubId where');
    SQL.Add(' A.MainId=YF_Money_CR.YFTypeId and A.CRType=''正常出库'' and CPType=''正品''  ');
    SQL.Add(' )'); //and B.PRTPrice=YF_Money_CR.Price
    sql.Add(',PS=(select isnull(count(*),0) from CK_BanCP_CR A  ');
    sql.Add(' inner join JYOrder_Sub B on A.SubId=B.SubId where');
    SQL.Add(' A.MainId=YF_Money_CR.YFTypeId and A.CRType=''正常出库'' and CPType=''正品''  ');
    SQL.Add('  )');  //and B.PRTPrice=YF_Money_CR.Price
    sql.Add(' where YFTypeId='''+Trim(Order_Main10.fieldbyname('Mainid').AsString)+'''');
    //sql.Add(' and Price='+Order_Main10.fieldbyname('PRTPrice').AsString);
    ExecSQL;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update YF_Money_CR Set Money=Price*Qty,BBMoney=Price*Qty*HuiLv');
    sql.Add(' where YFID='''+Trim(YFID)+'''');
    ExecSQL;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update YF_Money_KC Set KCMoney=(select isnull(Sum(Money*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID)');
    sql.Add(',KCBBMoney=(select isnull(Sum(BBMoney*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID)');
    sql.Add(' where CRID='+CRID);
    ExecSQL;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from YF_Money_CR where YFId='''+Trim(YFID)+'''');
    Open;
  end;
  if ADOQueryTemp.FieldByName('Qty').Value=0 then
  begin
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete from YF_Money_CR where YFID='''+Trim(YFID)+'''');
      ExecSQL;
    end;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from YF_Money_CR where CRId='+CRID);
    Open;
  end;
  if ADOQueryTemp.IsEmpty then
  begin
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete from YF_Money_KC where CRId='+CRID);
      ExecSQL;
    end;
  end;


  Result:=True;
end;

procedure TfrmCKProductBCPOutList.orderNoKeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key=#13 then
  begin
    if Length(Trim(orderNo.Text))<4 then Exit;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        sql.Clear;
        SQL.Add('select A.*,B.OrderNo,C.PRTCodeName,C.PRTSpec,C.PRTColor,C.SOrddefstr1,C.PRTMF,C.PRTKZ,D.MJXH,C.PRTPrice,C.PRTHX ');
        sql.Add(',C.SOrddefstr4,D.MJQty3,D.MJQty4');
        sql.Add(',PONO=(select Top 1 KHConNo from JYOrderCon_Main JCM where JCM.ConNo=B.OrderNo)');
        sql.Add(',MPRTECodeName=(select Top 1 MPRTCodeName from JYOrderCon_Main JCM where JCM.ConNo=B.OrderNo)');
        sql.Add(',isnull(customerNoName,B.OrderNo) KHName');
        sql.Add(',D.mjstr4,D.MJstr5 ');
        sql.add('from CK_BanCP_CR A ');
        Sql.add(' inner join JYOrder_Main B on A.MainId=B.MainId');
        Sql.add(' inner join JYOrder_Sub C on A.SubId=C.SubId');
        Sql.add(' inner join WFB_MJJY D on A.MJId=D.MJId');
        sql.add('where B.OrderNo like '''+'%'+Trim(orderNo.Text)+'%'+'''');
        SQL.Add(' and CRType=''正常出库'' ');
       // Parameters.ParamByName('orderNo').Value:='%'+Trim(orderNo.Text)+'%';

        Open;
        //ShowMessage(SQL.Text);
      end;
      SCreateCDS20(ADOQueryMain,CDS_Main);
      SInitCDSData20(ADOQueryMain,CDS_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
    JSbaoNum();
  end;

end;

procedure TfrmCKProductBCPOutList.AOrdDefStr1Change(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmCKProductBCPOutList.Tv1CellDblClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  Panel4.Left:=FLeft;
  Panel4.Top:=FTop+110;
  Panel4.Visible:=True;
  Panel4.Refresh;
  Panel10.Caption:=Trim(TV1.Controller.FocusedColumn.Caption);
  RichEdit1.Text:=CDS_Main.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString;
end;

procedure TfrmCKProductBCPOutList.Tv1MouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FLeft:=X;
  FTop:=Y;
end;

procedure TfrmCKProductBCPOutList.Image2Click(Sender: TObject);
begin
  Panel4.Visible:=False;
end;

procedure TfrmCKProductBCPOutList.CheckBox1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main,CheckBox1.Checked);
end;

end.
