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, RM_E_llPDF, cxCalendar, Math,
  Clipbrd, cxPC;

type
  TfrmCKProductBCPOutList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    Tv1: TcxGridDBTableView;
    cxGrid2Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    cxgrdMPRTCodeName: TcxGridDBColumn;
    cxgrdPRTColor: TcxGridDBColumn;
    cxgrdKGQty: TcxGridDBColumn;
    cxgrdQty: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    cxgrdQtyUnit: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    cxgrdMPRTMF: TcxGridDBColumn;
    cxgrdMPRTKZ: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    RMXLSExport1: TRMXLSExport;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    cxgrdMPRTSpec: TcxGridDBColumn;
    TBCKCX: TToolButton;
    v1Column11: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    MovePanel2: TMovePanel;
    DS_JuanPRT: TDataSource;
    cxGridPopupMenu2: TcxGridPopupMenu;
    cxgrdNETKGQty: TcxGridDBColumn;
    cxgrdKuangHao: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    cxgrdAPID: TcxGridDBColumn;
    v1Column22: TcxGridDBColumn;
    begtime: TDateTimePicker;
    endTime: TDateTimePicker;
    ADOQueryPrint: TADOQuery;
    RMDB_Main: TRMDBDataSet;
    v1rkplace: TcxGridDBColumn;
    RMDBHZ: TRMDBDataSet;
    CDS_HZ: TClientDataSet;
    RM3: TRMGridReport;
    v1Column24: TcxGridDBColumn;
    RMDBPRT: TRMDBDataSet;
    CDS_PRT: TClientDataSet;
    lblKHName: TLabel;
    KHName: TEdit;
    cxgrdCustomerNoName: TcxGridDBColumn;
    Panel6: TPanel;
    Label31: TLabel;
    LBCPAP: TLabel;
    BTLP: TButton;
    BTNP: TButton;
    TCBNOR: TComboBox;
    IsJYTime: TCheckBox;
    v1Column13: TcxGridDBColumn;
    ToolButton2: TToolButton;
    ToolButton1: TToolButton;
    ComboBox1: TComboBox;
    cxTabControl1: TcxTabControl;
    lblAPID: TLabel;
    APID: TEdit;
    lblMPRTCodeName: TLabel;
    lblorderNo: TLabel;
    lblMJID: TLabel;
    lblMPRTKZ: TLabel;
    lblMPRTMF: TLabel;
    lblCPType: TLabel;
    lblPRTColor: TLabel;
    lblMPRTSpec: TLabel;
    lblRKplace: TLabel;
    lblConNo: TLabel;
    lblKuangHao: TLabel;
    Label14: TLabel;
    MPRTCodeName: TEdit;
    orderNo: TEdit;
    MJID: TEdit;
    MPRTKZ: TEdit;
    MPRTMF: TEdit;
    CPType: TComboBox;
    RKplace: TEdit;
    PRTColor: TEdit;
    MPRTSpec: TEdit;
    ConNo: TEdit;
    KuangHao: TEdit;
    CustomerNoName: TEdit;
    cxgrdJQty: TcxGridDBColumn;
    N3: TMenuItem;
    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 N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure TBCKCXClick(Sender: TObject);
    procedure orderNoKeyPress(Sender: TObject; var Key: Char);
    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 BTNPClick(Sender: TObject);
    procedure BTLPClick(Sender: TObject);
    procedure TCBNORChange(Sender: TObject);
    procedure CPTypeChange(Sender: TObject);
    procedure CRTypeChange(Sender: TObject);
    procedure edtSMNOKeyPress(Sender: TObject; var Key: Char);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure N3Click(Sender: TObject);
  private
    FLeft, FTop: Integer;
    CurrentPage, RecordsNumber: Integer;
    procedure InitGrid();
    procedure SetStatus();
    { Private declarations }
  public
    canshu1: string;
    { Public declarations }
  end;

//var
//  frmCKProductBCPOutList: TfrmCKProductBCPOutList;

implementation

uses
  U_DataLink, U_Fun, U_SysLogHelp;

{$R *.dfm}
procedure TfrmCKProductBCPOutList.SetStatus();
var
  i: Integer;
begin
  lblorderNo.Visible := True;
  orderNo.Visible := True;

  lblMPRTCodeName.Visible := True;
  MPRTCodeName.Visible := True;

  lblMPRTSpec.Visible := True;
  MPRTSpec.Visible := True;

  lblMPRTMF.Visible := True;
  MPRTMF.Visible := True;

  lblMPRTKZ.Visible := True;
  MPRTKZ.Visible := True;

  lblPRTColor.Visible := True;
  PRTColor.Visible := True;

  lblCPType.Visible := True;
  CPType.Visible := True;

  lblConNo.Visible := True;
  ConNo.Visible := True;

  lblKHName.Visible := True;
  KHName.Visible := True;

  lblRKplace.Visible := True;
  RKplace.Visible := True;

  lblKuangHao.Visible := True;
  KuangHao.Visible := True;

  lblMJID.Visible := True;
  MJID.Visible := True;

  lblAPID.Visible := True;
  APID.Visible := True;
  case cxTabControl1.TabIndex of
    0:
      begin
        Panel6.Visible := False;
        for i := 0 to tv1.ColumnCount - 1 do
        begin
          tv1.Columns[i].Visible := false;
        end;
        cxgrdJQty.Visible := True;
        cxgrdCustomerNoName.Visible := True;
        cxgrdKGQty.Visible := True;
        cxgrdNETKGQty.Visible := True;
        cxgrdQty.Visible := True;
        cxgrdQtyUnit.Visible := True;

        lblorderNo.Visible := False;
        orderNo.Text := '';
        orderNo.Visible := False;

        lblMPRTCodeName.Visible := False;
        MPRTCodeName.Text := '';
        MPRTCodeName.Visible := False;

        lblMPRTSpec.Visible := False;
        MPRTSpec.Text := '';
        MPRTSpec.Visible := False;

        lblMPRTMF.Visible := False;
        MPRTMF.Text := '';
        MPRTMF.Visible := False;

        lblMPRTKZ.Visible := False;
        MPRTKZ.Text := '';
        MPRTKZ.Visible := False;

        lblPRTColor.Visible := False;
        PRTColor.Text := '';
        PRTColor.Visible := False;

        lblCPType.Visible := False;
        CPType.Text := '';
        CPType.Visible := False;

        lblConNo.Visible := False;
        ConNo.Text := '';
        ConNo.Visible := False;

        lblKHName.Visible := False;
        KHName.Text := '';
        KHName.Visible := False;

        lblRKplace.Visible := False;
        RKplace.Text := '';
        RKplace.Visible := False;

        lblKuangHao.Visible := False;
        KuangHao.Text := '';
        KuangHao.Visible := False;

        lblMJID.Visible := False;
        MJID.Text := '';
        MJID.Visible := False;

        lblAPID.Visible := False;
        APID.Text := '';
        APID.Visible := False;
      end;
    1:
      begin
        Panel6.Visible := False;
        for i := 0 to tv1.ColumnCount - 1 do
        begin
          tv1.Columns[i].Visible := false;
        end;
        cxgrdJQty.Visible := True;
        cxgrdCustomerNoName.Visible := True;
        cxgrdKGQty.Visible := True;
        cxgrdNETKGQty.Visible := True;
        cxgrdQty.Visible := True;
        cxgrdQtyUnit.Visible := True;
        cxgrdMPRTCodeName.Visible := True;
        cxgrdMPRTSpec.Visible := True;
        cxgrdMPRTMF.Visible := True;
        cxgrdMPRTKZ.Visible := True;
        cxgrdPRTColor.Visible := True;

        lblorderNo.Visible := False;
        orderNo.Text := '';
        orderNo.Visible := False;

        lblCPType.Visible := False;
        CPType.Text := '';
        CPType.Visible := False;

        lblConNo.Visible := False;
        ConNo.Text := '';
        ConNo.Visible := False;

        lblKHName.Visible := False;
        KHName.Text := '';
        KHName.Visible := False;

        lblRKplace.Visible := False;
        RKplace.Text := '';
        RKplace.Visible := False;

        lblKuangHao.Visible := False;
        KuangHao.Text := '';
        KuangHao.Visible := False;

        lblMJID.Visible := False;
        MJID.Text := '';
        MJID.Visible := False;

        lblAPID.Visible := False;
        APID.Text := '';
        APID.Visible := False;
      end;
    2:
      begin
        for i := 0 to tv1.ColumnCount - 1 do
        begin
          tv1.Columns[i].Visible := True;
        end;
        cxgrdJQty.Visible := false;
        Panel6.Visible := True;

      end;
  end;
end;

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

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

procedure TfrmCKProductBCPOutList.InitGrid();
var
  fwhere, Pwhere: string;
begin
  MovePanel2.Left := (self.Width - MovePanel2.Width) div 2;
  MovePanel2.Visible := True;
  MovePanel2.Refresh;
  Pwhere := SGetFilters(Panel1, 1, 2);

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      case cxTabControl1.TabIndex of
        0:
          begin
            if trim(Pwhere) <> '' then
              fwhere := fwhere + ' where ' + trim(Pwhere);
            sql.Add('select * from (   ');
            sql.Add('select SUM(A.KGQty) KGQty,SUM(A.Qty) Qty,SUM(A.NetKGQty) NETKGQty,count(A.MJID) JQty,A.QtyUnit ');
            sql.Add(',B.CustomerNoName');
            sql.Add('from  CK_BanCP_CR A  inner join JYOrder_Main B on A.MainId=B.MainId  ');
            sql.Add('inner join JYOrder_Sub C on A.SubId=C.SubId   where A.CRFlag=''出库''  ');
            sql.Add(' and A.CRTime>' + quotedstr(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)));
            sql.Add(' and A.CRTime<=' + quotedstr(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1)));
            sql.Add(' group by  B.CustomerNoName,A.QtyUnit');
            sql.Add(' ) AA ' + fwhere);
          end;
        1:
          begin
            if trim(Pwhere) <> '' then
              fwhere := fwhere + ' where ' + trim(Pwhere);
            sql.Add('select * from (   ');
            sql.Add('select SUM(A.KGQty) KGQty,SUM(A.Qty) Qty,SUM(A.NetKGQty) NetKGQty,count(A.MJID) JQty,A.QtyUnit,A.ganghao ');
            sql.Add(' ,B.CustomerNoName,B.ConNo,B.OrderNo,B.MPRTCode,B.MPRTCodeName,B.MPRTMF,B.MPRTKZ ,B.MPRTSpec,C.PRTColor  ');
            sql.Add('from  CK_BanCP_CR A  inner join JYOrder_Main B on A.MainId=B.MainId  ');
            sql.Add('inner join JYOrder_Sub C on A.SubId=C.SubId   where A.CRFlag=''出库''  ');
            sql.Add(' and A.CRTime>' + quotedstr(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)));
            sql.Add(' and A.CRTime<=' + quotedstr(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1)));
            sql.Add(' group by  B.CustomerNoName,A.QtyUnit,A.ganghao,B.ConNo,B.OrderNo,B.MPRTCode,B.MPRTCodeName,B.MPRTMF,B.MPRTKZ ,B.MPRTSpec,C.PRTColor   ');
            sql.Add(' ) AA ' + fwhere);
          end;

        2:
          begin
            if IsJYTime.Checked then
            begin
              fwhere := ' where CRTime>' + quotedstr(FormatDateTime('yyyy-MM-dd', BegDate.DateTime));
              fwhere := fwhere + ' and CRTime<=' + quotedstr(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1));
              if trim(Pwhere) <> '' then
                fwhere := fwhere + ' and ' + trim(Pwhere);
            end
            else
            begin
              if trim(Pwhere) <> '' then
                fwhere := fwhere + ' where ' + trim(Pwhere);
            end;

            sql.Add('exec P_Page_FinishClothCK ');
            sql.Add('@pageIndex=' + inttostr(CurrentPage));
            sql.Add(',@pageSize=' + inttostr(RecordsNumber));
            sql.Add(',@criteria= ' + quotedstr(fwhere));
          end;
      end;
//      ShowMessage(SQL.TEXT);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);

    if cxTabControl1.TabIndex = 2 then
      LBCPAP.Caption := inttostr(CurrentPage) + '/' + inttostr(ceil(CDS_Main.FieldByName('TotalCount').AsInteger / RecordsNumber));
    MovePanel2.Visible := false;
  finally
    ADOQueryMain.EnableControls;
    MovePanel2.Visible := false;
  end;

end;

procedure TfrmCKProductBCPOutList.TBRafreshClick(Sender: TObject);
begin
  CurrentPage := 1;
  SetStatus();
  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(trim(self.Caption), Tv1, '成品仓库');
  Close;
end;

procedure TfrmCKProductBCPOutList.FormShow(Sender: TObject);
begin
  ReadCxGrid(trim(self.Caption), Tv1, '成品仓库');
  CurrentPage := 1;
  RecordsNumber := 500;
  if Trim(canshu1) = '管理' then
  begin
    TBCKCX.Visible := True;
  end
  else
  begin
    TBCKCX.Visible := false;
  end;
end;

procedure TfrmCKProductBCPOutList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    exit;
  SelExportData(Tv1, ADOQueryMain, '');
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, strsql: string;
begin
  if CDS_Main.IsEmpty then
    Exit;
  if cxTabControl1.TabIndex <> 2 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
      while CDS_Main.Locate('SSel', True, []) = True do
      begin
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('Update CK_BanCP_CR Set CRFlag=''待出库'',CRType='''',CRTime=NULL,CRNote='''',CKOrdNo='''' ');
            sql.Add(' where MJID=''' + Trim(CDS_Main.fieldbyname('MJID').AsString) + '''');
            sql.Add(' and CRFlag=''出库''');

            sql.Add(' UPdate CK_BanCP_KC Set KCValid=''Y'' ');
            SQL.Add(' where MJID=''' + Trim(CDS_Main.fieldbyname('MJID').AsString) + '''');

            sql.Add(' Update WFB_MJJY Set MJStr2=''已入库'' where MJID=''' + Trim(CDS_Main.fieldbyname('MJID').AsString) + ''' ');

            ExecSQL;
          end;

          strsql := '卷ID：' + trim(CDS_Main.FieldByName('MJID').AsString) + ' 出库单号：' + trim(CDS_Main.FieldByName('CKOrdNo').AsString);

          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
            sql.Add(' ' + quotedstr(trim(DName)));
            sql.Add(',getdate() ');
            sql.Add(',' + quotedstr(trim(self.Caption)));
            sql.Add(',' + quotedstr(trim('出库撤销')));
            sql.Add(',' + quotedstr(trim(strsql)));
            sql.Add(',' + quotedstr(trim('成功')));
            sql.Add(')');
            ExecSQL;
          end;

          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('exec P_Update_FHSQ @CKOrdNo=' + quotedstr(trim(CDS_Main.FieldByName('CKOrdNo').AsString)));
            ExecSQL;
          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;

procedure TfrmCKProductBCPOutList.orderNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    CurrentPage := 1;
    InitGrid();
  end;
end;

procedure TfrmCKProductBCPOutList.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
var
  Tabint: integer;
begin
  Tabint := cxTabControl1.TabIndex;
  case Tabint of
    0:
      begin
        CustomerNoName.Text := CDS_Main.FieldByName('CustomerNoName').AsString;
        cxTabControl1.TabIndex := 1;
      end;
    1:
      begin
        MPRTCodeName.Text := CDS_Main.FieldByName('MPRTCodeName').AsString;
        MPRTSpec.Text := CDS_Main.FieldByName('MPRTSpec').AsString;
        MPRTMF.Text := CDS_Main.FieldByName('MPRTMF').AsString;
        MPRTKZ.Text := CDS_Main.FieldByName('MPRTKZ').AsString;
        PRTColor.Text := CDS_Main.FieldByName('PRTColor').AsString;
        cxTabControl1.TabIndex := 2;
      end;
  end;
end;

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

procedure TfrmCKProductBCPOutList.BTNPClick(Sender: TObject);
begin
  if CurrentPage < CDS_Main.FieldByName('TotalCount').AsInteger / RecordsNumber then
    CurrentPage := CurrentPage + 1;
  InitGrid();
end;

procedure TfrmCKProductBCPOutList.BTLPClick(Sender: TObject);
begin
  if CurrentPage > 1 then
    CurrentPage := CurrentPage - 1;
  InitGrid();
end;

procedure TfrmCKProductBCPOutList.TCBNORChange(Sender: TObject);
begin
  RecordsNumber := StrToInt(TCBNOR.Text);
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmCKProductBCPOutList.CPTypeChange(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmCKProductBCPOutList.CRTypeChange(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmCKProductBCPOutList.edtSMNOKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin

  end;
end;

procedure TfrmCKProductBCPOutList.ToolButton2Click(Sender: TObject);
begin
  frmSysLogHelp := TfrmSysLogHelp.create(self);
  with frmSysLogHelp do
  begin
    fModel := self.caption;
  //  facction:='生产指示单删除';
    showmodal;
    free;
  end;
end;

procedure TfrmCKProductBCPOutList.ToolButton1Click(Sender: TObject);
var
  fPrintFile, fPrintFile10, FMainID, FKHName, FFPNo: string;
begin
  if CDS_Main.IsEmpty then
    Exit;
  if cxTabControl1.TabIndex <> 2 then
    Exit;
  ExportFtErpFile(trim(ComboBox1.Text) + '.rmf', ADOQueryTemp);

  if trim(ComboBox1.Text) = '三水码单1' then
  begin
    with ADOQueryTemp do
    begin

      Close;
      sql.Clear;
      sql.add('exec P_Print_CKMDWSQ1 ');
      sql.add('@CKOrdNo=' + quotedstr(Trim(Trim(CDS_Main.fieldbyname('CKOrdNo').AsString))));
      Open;
    end;
    SCreateCDS20(ADOQueryTemp, CDS_PRT);
    SInitCDSData20(ADOQueryTemp, CDS_PRT);
  end;
  if trim(ComboBox1.Text) = '三水码单2' then
  begin
    with ADOQueryTemp do
    begin

      Close;
      sql.Clear;
      sql.add('exec P_Print_CKMDWSQ2 ');
      sql.add('@CKOrdNo=' + quotedstr(Trim(Trim(CDS_Main.fieldbyname('CKOrdNo').AsString))));
      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_Print_CKMDWSQ3 ');
      sql.add('@CKOrdNo=' + quotedstr(Trim(Trim(CDS_Main.fieldbyname('CKOrdNo').AsString))));
      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_Print_CKMDWSQ4 ');
      sql.add('@CKOrdNo=' + quotedstr(Trim(Trim(CDS_Main.fieldbyname('CKOrdNo').AsString))));
      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_Print_CKMDWSQ5 ');
      sql.add('@CKOrdNo=' + quotedstr(Trim(Trim(CDS_Main.fieldbyname('CKOrdNo').AsString))));
      Open;
    end;
    SCreateCDS20(ADOQueryTemp, CDS_PRT);
    SInitCDSData20(ADOQueryTemp, CDS_PRT);
  end;
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(ComboBox1.Text) + '.rmf';
  if FileExists(fPrintFile) then
  begin
    RM3.LoadFromFile(fPrintFile);
    RMVariables['Filler'] := trim(DName);
    RM3.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找到' + fPrintFile), '提示', 0);
  end;
end;

procedure TfrmCKProductBCPOutList.cxTabControl1Change(Sender: TObject);
begin
  case cxTabControl1.TabIndex of
    0:
      begin
        CustomerNoName.Text := '';
      end;
    1:
      begin
        orderNo.Text := '';

        MPRTCodeName.Text := '';

        MPRTSpec.Text := '';

        MPRTMF.Text := '';

        MPRTKZ.Text := '';

        PRTColor.Text := '';
      end;
    2:
      begin

      end;
  end;
  SetStatus();
  InitGrid();
end;

procedure TfrmCKProductBCPOutList.N3Click(Sender: TObject);
begin
  Clipboard.SetTextBuf(PChar(Trim(CDS_Main.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));
end;

end.

