unit U_CKProductBCPInList;

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, cxCheckBox, RM_Common, RM_Class, RM_e_Xls, RM_Dataset,
  RM_System, RM_GridReport, Menus, cxLookAndFeels, cxLookAndFeelPainters,
  cxNavigator;

type
  TfrmCKProductBCPInList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label3: TLabel;
    Label4: TLabel;
    PRTCodeName: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    Label5: TLabel;
    orderNo: TEdit;
    Label6: TLabel;
    MJID: TEdit;
    Label8: TLabel;
    PRTKZ: TEdit;
    Label9: TLabel;
    PRTMF: TEdit;
    Label7: TLabel;
    CPType: TComboBox;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column1: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    Label10: TLabel;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    TBRKCX: TToolButton;
    v1Column4: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    v1Column11: TcxGridDBColumn;
    PRTColor: TComboBox;
    v1Column12: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    ComboBox1: TComboBox;
    BaoNo: 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;
    ADOQueryPrint: TADOQuery;
    RKOrdID: TEdit;
    Label15: TLabel;
    v1Column17: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    MJstr4: TEdit;
    Label16: TLabel;
    CheckBox1: TCheckBox;
    RMDBHZ: TRMDBDataSet;
    CDS_HZ: TClientDataSet;
    CDS_PRT: TClientDataSet;
    RMDBMain10: TRMDBDataSet;
    CDS_PRT10: 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 orderNoKeyPress(Sender: TObject; var Key: Char);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure TBRKCXClick(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure PRTColorChange(Sender: TObject);
    procedure BaoNoChange(Sender: TObject);
    procedure Image2Click(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 CheckBox1Click(Sender: TObject);
  private
    FLeft, FTop: Integer;
    procedure InitGrid();
    procedure JSbaoNum();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmCKProductBCPInList: TfrmCKProductBCPInList;

implementation

uses
  U_DataLink, U_Fun;

{$R *.dfm}
procedure TfrmCKProductBCPInList.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 TfrmCKProductBCPInList.FormDestroy(Sender: TObject);
begin
  frmCKProductBCPInList := nil;
end;

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

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

procedure TfrmCKProductBCPInList.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.PRTHX,D.MJQty3,D.MJQty4');
      sql.Add(',isnull(customerNoName,B.OrderNo) KHName');
      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(',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 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 A.CRType=''检验入库'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
  TBFind.Click;
end;

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

end;

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

procedure TfrmCKProductBCPInList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('半成品仓库入库', Tv1, '半成品仓库');
  Close;
end;

procedure TfrmCKProductBCPInList.FormShow(Sender: TObject);
begin
  ReadCxGrid('半成品仓库入库', Tv1, '半成品仓库');
  if Trim(DParameters2) = '管理' then
  begin
    v1Column4.Visible := True;
    TBRKCX.Visible := True;

  end
  else
  begin
    v1Column4.Visible := False;
    TBRKCX.Visible := False;

  end;
  InitGrid();
end;

procedure TfrmCKProductBCPInList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    exit;
  TcxGridToExcel('入库列表', cxGrid2);
end;

procedure TfrmCKProductBCPInList.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 TfrmCKProductBCPInList.PRTCodeNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmCKProductBCPInList.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) = '单色包装-长度') 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) = '裸装') then
  begin

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.add(' SELECT A.mainID,MJID,gangNO=MJstr4,mjxh,colNo=B.sorddefstr1,prthx=isnull(B.prthx,''''), ');
      sql.add(' MJlen,MJQty4,MJmaoZ');
      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('WHERE EXISTS(select SubId from TBSubID X where X.SubId=A.MJID and X.DName=''' + trim(DCode) + ''') ');
      sql.add('ORDER BY MainID,cast(ISNULL(baoNO,0) as Int),MJstr4,colNo,prthx,mjxh ');
      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);

    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_PRT10);
    SInitCDSData20(ADOQueryTemp, CDS_PRT10);
  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);

    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_PRT10);
    SInitCDSData20(ADOQueryTemp, CDS_PRT10);

  end;

  if trim(ComboBox1.Text) = '混色包装-15色（卷号）' 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=''15'' ');
      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);

    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_PRT10);
    SInitCDSData20(ADOQueryTemp, CDS_PRT10);

  end;

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

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

procedure TfrmCKProductBCPInList.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.PRTHX,D.MJQty3,D.MJQty4');
        sql.Add(',isnull(customerNoName,B.OrderNo) KHName');
        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(',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 :OrderNo');
        SQL.Add(' and CRType=''检验入库'' ');
        Parameters.ParamByName('orderNo').Value := '%' + Trim(orderNo.Text) + '%';

        Open;
        //ShowMessage(SQL.Text);
      end;
      SCreateCDS20(ADOQueryMain, CDS_Main);
      SInitCDSData20(ADOQueryMain, CDS_Main);
      if CDS_Main.IsEmpty = False then
      begin
        InitOrderColor(Trim(CDS_Main.fieldbyname('MainId').AsString), PRTColor, ADOQueryTemp);
        //InitBCGangNo(Trim(CDS_Main.fieldbyname('SubId').AsString),AOrdDefStr1,ADOQueryTemp);
      end;
    finally
      ADOQueryMain.EnableControls;
    end;
    JSbaoNum();
  end;
end;

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

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

procedure TfrmCKProductBCPInList.TBRKCXClick(Sender: TObject);
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;
  BegDate.SetFocus;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_Main do
    begin
      while Locate('SSel', True, []) do
      begin
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from CK_BanCP_CR where CRID=' + Trim(CDS_Main.fieldbyname('CRID').AsString));
          Open;
        end;
        if ADOQueryTemp.RecordCount > 1 then
        begin
          ADOQueryCmd.Connection.RollbackTrans;
          Application.MessageBox('已出库不能撤销入库!', '提示', 0);
          Exit;
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('delete CK_BanCP_CR where BCID=''' + Trim(CDS_Main.fieldbyname('BCID').AsString) + '''');
          sql.Add('delete CK_BanCP_KC where CRID=' + Trim(CDS_Main.fieldbyname('CRID').AsString));
          sql.Add('Update WFB_MJJY Set MJStr2=''未入库'' where MJID=''' + Trim(CDS_Main.fieldbyname('MJID').AsString) + '''');
          ExecSQL;
        end;
        CDS_Main.Delete;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;

  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('撤销失败!', '提示', 0);
  end;
end;

procedure TfrmCKProductBCPInList.Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  if CDS_Main.IsEmpty = False then
  begin
    InitOrderColor(Trim(CDS_Main.fieldbyname('MainId').AsString), PRTColor, ADOQueryTemp);
   // InitBCGangNo(Trim(CDS_Main.fieldbyname('SubId').AsString),AOrdDefStr1,ADOQueryTemp);
  end;
end;

procedure TfrmCKProductBCPInList.PRTColorChange(Sender: TObject);
begin
  TBFind.Click;
  if CDS_Main.IsEmpty = False then
  begin
    //InitOrderColor(Trim(CDS_Main.fieldbyname('MainId').AsString),PRTColor,ADOQueryTemp);
    //InitBCGangNo(Trim(CDS_Main.fieldbyname('SubId').AsString),AOrdDefStr1,ADOQueryTemp);
  end;
end;

procedure TfrmCKProductBCPInList.BaoNoChange(Sender: TObject);
begin
  TBFind.Click;
end;

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

procedure TfrmCKProductBCPInList.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 TfrmCKProductBCPInList.Tv1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FLeft := X;
  FTop := Y;
end;

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

end.

