unit U_BpCklist;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, StdCtrls, ExtCtrls, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData,
  cxButtonEdit, cxDropDownEdit, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxControls, cxGridCustomView,
  cxGrid, DBClient, ADODB, cxGridCustomPopupMenu, cxGridPopupMenu, RM_Common,
  RM_Class, RM_e_Xls, RM_GridReport, RM_System, RM_Dataset, cxPC, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu, cxTextEdit, cxSplitter,
  cxContainer, dxCore, cxDateUtils, cxMaskEdit, cxCalendar;

type
  TfrmBpCklist = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBDel: TToolButton;
    TBExport: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    Label1: TLabel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1P_CodeName: TcxGridDBColumn;
    v1P_SPEC: TcxGridDBColumn;
    v1P_MF: TcxGridDBColumn;
    v1P_KZ: TcxGridDBColumn;
    v1Qty: TcxGridDBColumn;
    v1QtyUnit: TcxGridDBColumn;
    v1Note: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1CRType: TcxGridDBColumn;
    v1CRTime: TcxGridDBColumn;
    v1Filler: TcxGridDBColumn;
    v1FillTime: TcxGridDBColumn;
    CRType: TComboBox;
    Label5: TLabel;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    DataSource1: TDataSource;
    CDS_Main: TClientDataSet;
    cxGridPopupMenu1: TcxGridPopupMenu;
    v1CPTYPE: TcxGridDBColumn;
    ckName: TComboBox;
    Label6: TLabel;
    v1P_Color: TcxGridDBColumn;
    ADOPrint: TADOQuery;
    RMDB_MD: TRMDBDataSet;
    RMGridReport1: TRMGridReport;
    RMXLSExport1: TRMXLSExport;
    v1P_Code: TcxGridDBColumn;
    v1inoutNO: TcxGridDBColumn;
    v1custName: TcxGridDBColumn;
    TbPrint1: TToolButton;
    v1Column5: TcxGridDBColumn;
    v1defnote5: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    cxTabControl1: TcxTabControl;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    Tchk: TToolButton;
    Tnochk: TToolButton;
    v1Column10: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    ToolButton1: TToolButton;
    btnDelCX: TToolButton;
    btnDelData: TToolButton;
    CDS_SUB: TClientDataSet;
    DataSource2: TDataSource;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    BegDate: TcxDateEdit;
    EndDate: TcxDateEdit;
    Tv1Column6: TcxGridDBColumn;
    Label3: TLabel;
    Label4: TLabel;
    Label9: TLabel;
    Label7: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    P_SPEC: TEdit;
    P_Code: TEdit;
    custName: TEdit;
    P_CF: TEdit;
    KHCPName: TEdit;
    P_CodeName: TEdit;
    P_Color: TEdit;
    sehao: TEdit;
    KHColor: TEdit;
    KHSeHao: TEdit;
    Label2: TLabel;
    kuwei: TEdit;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Label8: TLabel;
    Label16: TLabel;
    ToOrderNo: TEdit;
    ToConNo: TEdit;
    Tv1Column9: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure P_CodeNameChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBPrintClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TbPrint1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure TchkClick(Sender: TObject);
    procedure TnochkClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure btnDelDataClick(Sender: TObject);
    procedure btnDelCXClick(Sender: TObject);
    procedure Tv1CustomDrawIndicatorCell(Sender: TcxGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
    procedure Tv1DblClick(Sender: TObject);
    procedure Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure ToolButton4Click(Sender: TObject);
  private
    procedure InitGrid();
    procedure InitSub();
    procedure SetComboBox();
    procedure SetStatus();
    { Private declarations }
  public
    fCKName: string;
    canshu1: string;
    { Public declarations }
  end;

var
  frmBpCklist: TfrmBpCklist;

implementation

uses
  U_DataLink, U_Fun10, U_ZDYHelp, U_BpCk, U_BpSmCk;
{$R *.dfm}

procedure TfrmBpCklist.SetStatus();
begin
  TBedit.Visible := false;
  Tbdel.Visible := false;
  Tchk.Visible := false;
  Tnochk.Visible := false;
  btnDelCX.Visible := false;
  btnDelData.Visible := false;
  ToolButton2.Visible := False;
  ToolButton3.Visible := False;
  case cxTabControl1.TabIndex of
    0:
      begin
        TBedit.Visible := true;
        Tbdel.Visible := true;
        ToolButton2.Visible := true;
        if trim(canshu1) = '管理' then
        begin
          Tchk.Visible := true;
          ToolButton2.Visible := True;
        end;
      end;
    1:
      begin
        if trim(canshu1) = '管理' then
        begin
          Tnochk.Visible := true;
        end;
      end;
    2:
      begin

      end;
    3:
      begin
        btnDelCX.Visible := true;
        btnDelData.Visible := true;
        ToolButton3.Visible := True;
      end;
  end;

end;

procedure TfrmBpCklist.InitSub();
begin

  if CDS_Main.IsEmpty then
    exit;
//  ADOQueryTmp.DisableControls;
  with ADOQueryTmp do
  begin
    close;
    sql.Clear;
    sql.Add('select A.*  from YP_InOut2 A');
    sql.Add('where A.CRNO=' + quotedstr(trim(self.cds_main.fieldbyname('CRNO').AsString)));
    open;
  end;
  SCreateCDS20(ADOQueryTmp, CDS_SUB);
  SInitCDSData20(ADOQueryTmp, CDS_SUB);

//  ADOQueryTmp.EnableControls;
end;

procedure TfrmBpCklist.SetComboBox();
begin
  ckName.Items.Clear;
  with adoQueryTmp do
  begin
    close;
    sql.Clear;
    sql.Add('select * from KH_ZDY where Type=''YPCK'' ');
    if trim(fCKName) <> '' then
      sql.Add('and zdyName=' + quotedstr(trim(fCKName)));
    open;
    while not eof do
    begin
      ckName.Items.Add(trim(fieldbyname('zdyName').AsString));
      next;
    end;
  end;
  if ckName.Items.Count > 0 then
    ckName.ItemIndex := 0;

  CRType.Items.Clear;
  CRType.Items.Add('');
  with adoQueryTmp do
  begin
    close;
    sql.Clear;
    sql.Add('select * from KH_ZDY where Type=''YPCKTYPE''');
    if trim(fCKName) <> '' then
      sql.Add('and note=' + quotedstr(trim(fCKName)));
    open;
    while not eof do
    begin
      CRType.Items.Add(trim(fieldbyname('zdyName').AsString));
      next;
    end;
  end;
  if CRType.Items.Count > 0 then
    CRType.ItemIndex := 0;
end;

procedure TfrmBpCklist.InitGrid();
begin
  try
    with adoqueryTmp do
    begin
      close;
      sql.Clear;
      sql.Add('select A.*  ');
      sql.Add(',ZDSC=(case when ISNULL((select count(crid) from YP_InOut2 b where b.crno=a.crno and b.valid=''Y'' group by crno ),0)=0');

      sql.Add('then 1 else 0 end)');
      SQL.Add(' from YP_InOut2 A');
      sql.Add('where CRTime>=''' + formatdateTime('yyyy-MM-dd', begdate.Date) + ''' ');
      sql.Add('and CRTime<''' + formatdateTime('yyyy-MM-dd', enddate.Date + 1) + ''' ');
      sql.Add('and CRFlag=''出库'' ');

      case cxTabControl1.TabIndex of
        0:
          begin
            sql.Add('and valid=''Y'' and A.status=''0'' ');
          end;
        1:
          begin
            sql.Add('and valid=''Y'' and A.status=''1'' ');
          end;
        2:
          begin
            sql.Add('and valid=''Y''  ');
          end;
        3:
          begin
            sql.Add('and valid=''N''  ');
          end;
      end;

      if canshu1 = '业务员' then
        sql.Add(' and A.custNo in (select distinct ZdyCode from KH_Zdy_Attachment where (DEFstr5=' + quotedstr(trim(DName)) + ' or MainType=(select UType from SY_User where username=' + quotedstr(trim(DName)) + ')))');

      sql.add('order by filltime desc');

      open;
    end;
    SCreateCDS20(adoqueryTmp, CDS_Main);
    SInitCDSData20(adoqueryTmp, CDS_Main);
  finally
  end;
end;

procedure TfrmBpCklist.FormClose(Sender: TObject; var Action: TCloseAction);
begin

  Action := cafree;
end;

procedure TfrmBpCklist.FormDestroy(Sender: TObject);
begin
  frmBpCklist := nil;
end;

procedure TfrmBpCklist.TBAddClick(Sender: TObject);
begin
  frmbpck := Tfrmbpck.create(self);
  with frmbpck do
  begin
    fkeyNo := '';
    fType := 0;
    fckName := self.fckName;

    if trim(self.canshu1) = '业务员' then
    begin
//      ywy.text := trim(Dname);
//      ywy.Enabled := false;
    end;
    if showmodal = 1 then
    begin
      TBRafresh.Click;
      self.CDS_Main.Locate('crNo', trim(fkeyNo), []);
    end;
    free;
  end;
end;

procedure TfrmBpCklist.P_CodeNameChange(Sender: TObject);
begin
  if ADOQueryTmp.Active = False then
    Exit;
  SDofilter(ADOQueryTmp, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryTmp, CDS_Main);
  SInitCDSData20(ADOQueryTmp, CDS_Main);
end;

procedure TfrmBpCklist.FormShow(Sender: TObject);
var
  fsj: string;
begin
  readCxGrid(self.Caption + '1', Tv1, '样品仓库');

  fsj := 'select UserName as Name from SY_User where Udept like  ''客服%''   ';
//  SInitComBoxBySql(ADOQueryCmd, defstr2, False, fsj);
//  SetComboBox();
//  SetStatus();
  InitGrid();
end;

procedure TfrmBpCklist.FormCreate(Sender: TObject);
begin
//  BegDate.Date := FormatDateTime('yyyy-MM-dd', (DServerDate - 7));
//  EndDate.Date := DServerDate;
//  EndDate.Text := FormatDateTime('yyyy-MM-dd', DServerDate);
//  BegDate.Text := FormatDateTime('yyyy-MM-dd', DServerDate );

  EndDate.Text := FormatDateTime('yyyy-MM-dd', SGetServerDate10(ADOQueryTmp) + 1) + ' 00:00:00';
  BegDate.Text := FormatDateTime('yyyy-MM-dd', SGetServerDate10(ADOQueryTmp) - 7) + ' 00:00:00';

  cxGrid1.Align := alclient;

end;

procedure TfrmBpCklist.TBCloseClick(Sender: TObject);
begin
  writeCxGrid(self.Caption + '1', Tv1, '样品仓库');

  close;
end;

procedure TfrmBpCklist.TBEditClick(Sender: TObject);
begin
  if cds_main.IsEmpty then
    exit;

  frmbpck := Tfrmbpck.create(self);
  with frmbpck do
  begin
    fkeyNo := self.cds_main.fieldbyname('CRNO').AsString;
    fType := 1;
    fckName := self.fckName;
    if showmodal = 1 then
    begin
      TBRafresh.Click;
      self.CDS_Main.Locate('crNo', trim(fkeyNo), []);
    end;
    free;
  end;
end;

procedure TfrmBpCklist.TBDelClick(Sender: TObject);
var
  YFID, CRID: string;
begin
  if CDS_Main.IsEmpty then
    Exit;

  with ADOQueryTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from YS_Money_CR A where  ChkStatusP=''已审核'' ');
    sql.Add('and EXISTS (select CRID from YP_InOut2 X where X.CRID=A.YFTypeID and X.CRNO=''' + Trim(Self.CDS_Main.fieldbyname('CRNO').AsString) + ''')');
    Open;
  end;
  if ADOQueryTmp.IsEmpty = false then
  begin
    Application.MessageBox('应收款已审核不能操作', '提示');
    exit;
  end;

  if Application.MessageBox('是否要整单删除？', '提示', 32 + 4) <> IDYES then
    Exit;

  try

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;

      sql.Add('update  YP_InOut2 SET valid=''N'' ');
      sql.Add(',editer=' + quotedstr(trim(DName)));
      sql.Add(',edittime=getdate(),CWFlag=0,YFID=Null');
      SQL.Add('where  CRNO=''' + Trim(CDS_Main.fieldbyname('CRNO').AsString) + ''' ');

      sql.Add('delete from YS_Money_CR  ');
      sql.Add('where EXISTS (select CRID from YP_InOut2 X where X.CRID=YS_Money_CR.YFTypeID and X.CRNO=''' + Trim(Self.CDS_Main.fieldbyname('CRNO').AsString) + ''')');
      execsql;
    end;
    TBRafresh.Click;
  except
    Application.MessageBox('数据删除失败！', '提示信息', 0);
  end;
end;

procedure TfrmBpCklist.TBRafreshClick(Sender: TObject);
begin
  initGrid();
end;

procedure TfrmBpCklist.TBPrintClick(Sender: TObject);
var
  filepath: string;
begin
  if CDS_Main.IsEmpty then
    exit;

  with AdoPrint do
  begin
    close;
    sql.Clear;
    sql.Add('exec P_Print_cpCkMd ');
    sql.Add('@inoutNo=' + quotedstr(trim(CDS_Main.fieldbyname('inoutNO').AsString)));
    sql.Add(',@flag=' + quotedstr(trim('')));
    open;
  end;

  try
    filepath := ExtractFilePath(Application.ExeName) + 'report\出库码单.rmf';
    if not FileExists(Pchar(filepath)) then
    begin
      application.MessageBox(pchar('文件[' + filepath + ']不存在！'), '提示信息', MB_IConError);
      exit;
    end;
    RMVariables['dtxz'] := FormatDateTime('yyyy-mm-dd', date());
    RMVariables['zdr'] := trim(DName);
    RMVariables['Filler'] := trim(CDS_Main.fieldbyname('Filler').AsString);
    RMGridReport1.LoadFromFile(filepath);
    RMGridReport1.ShowReport;
  finally

  end;

end;

procedure TfrmBpCklist.TBExportClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;
  TcxGridToExcel(self.Caption, cxgrid1);
end;

procedure TfrmBpCklist.TbPrint1Click(Sender: TObject);
var
  filepath: string;
begin
  if CDS_Main.IsEmpty then
    exit;

  with AdoPrint do
  begin
    close;
    sql.Clear;
    sql.Add(' select A.*,B.CYMF,B.CYKZ,A.SHAZHI defnote5,       ');
    sql.Add(' FilesOther=(select top 1 X1.FilesOther from TP_File X1,CP_YDang X2 where X1.WBID=X2.CYID and X2.CYNo=A.P_Code and X1.TFType=''样品'') ');
    sql.Add(' from YP_INout2 A ');
    sql.Add(' left join CP_YDang B on B.CYNO=A.P_Code');
    sql.Add(' where A.CRNo=' + quotedstr(trim(CDS_Main.fieldbyname('CRNO').AsString)));
    open;
  end;

  try
    filepath := ExtractFilePath(Application.ExeName) + 'report\样品发货单.rmf';
    if not FileExists(Pchar(filepath)) then
    begin
      application.MessageBox(pchar('文件[' + filepath + ']不存在！'), '提示信息', MB_IConError);
      exit;
    end;
    RMVariables['dtxz'] := FormatDateTime('yyyy-mm-dd', date());
    RMVariables['zdr'] := trim(DName);
    RMVariables['Filler'] := trim(CDS_Main.fieldbyname('Filler').AsString);
    RMGridReport1.LoadFromFile(filepath);
    RMGridReport1.ShowReport;
  finally

  end;

end;

procedure TfrmBpCklist.cxTabControl1Change(Sender: TObject);
begin
  SetStatus();
  initGrid();
end;

procedure TfrmBpCklist.TchkClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  YP_InOut2 SET status=''1'' ');
      sql.Add('where CRNO=' + quotedstr(trim(CDS_Main.fieldbyname('CRNO').AsString)));
      execsql;
    end;
    application.MessageBox('审核成功！', '提示信息');
    TBRafresh.Click;
  except
    application.MessageBox('审核失败！', '提示信息', 0);
  end;
end;

procedure TfrmBpCklist.TnochkClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  YP_InOut2 SET status=''0'' ');
      sql.Add('where CRNO=' + quotedstr(trim(CDS_Main.fieldbyname('CRNO').AsString)));
      execsql;
    end;
    application.MessageBox('撤销审核成功！', '提示信息');
    TBRafresh.Click;
  except
    application.MessageBox('撤销审核失败！', '提示信息', 0);
  end;
end;

procedure TfrmBpCklist.ToolButton1Click(Sender: TObject);
begin
  frmbpck := Tfrmbpck.create(self);
  with frmbpck do
  begin
    fkeyNo := self.cds_main.fieldbyname('CRNO').AsString;

    fType := 0;
    CopyInt := 99;
    fckName := self.fckName;
    if trim(self.canshu1) = '业务员' then
    begin
//      ywy.text := trim(Dname);
//      ywy.Enabled := false;
    end;
    if showmodal = 1 then
    begin
      TBRafresh.Click;
      self.CDS_Main.Locate('crNo', trim(fkeyNo), []);
    end;
    free;
  end;
end;

procedure TfrmBpCklist.btnDelDataClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;

  if Application.MessageBox('是否要删除数据？', '提示', 32 + 4) <> IDYES then
    Exit;

  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete  YP_InOut2  where CRID=' + quotedstr(CDS_Main.fieldbyname('CRID').AsString));
      execsql;
    end;

    ADOQueryCmd.Connection.CommitTrans;
    CDS_Main.Delete;
  except
    ADOQueryCmd.Connection.RollbackTrans;

    Application.MessageBox('数据删除失败！', '提示信息', 0);
  end;
end;

procedure TfrmBpCklist.btnDelCXClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;

  if Application.MessageBox('是否撤销删除？', '提示', 32 + 4) <> IDYES then
    Exit;

  try

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;

      sql.Add('update  YP_InOut2 SET valid=''Y'' ');
      sql.Add(',editer=' + quotedstr(trim(DName)));
      sql.Add(',edittime=getdate()');
      SQL.Add('where  CRNO=''' + Trim(CDS_Main.fieldbyname('CRNO').AsString) + ''' ');

      execsql;
    end;
    TBRafresh.Click;
  except
    Application.MessageBox('数据撤销删除失败！', '提示信息', 0);
  end;
end;

procedure TfrmBpCklist.Tv1CustomDrawIndicatorCell(Sender: TcxGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
var
  FValue: string;
  FBounds: TRect;
begin
  FBounds := AViewInfo.Bounds;
  if (AViewInfo is TcxGridIndicatorRowItemViewInfo) then
  begin
    ACanvas.FillRect(FBounds);
    ACanvas.DrawComplexFrame(FBounds, clBtnHighlight, clBtnShadow, [bBottom, bLeft, bRight], 1);
    FValue := IntToStr(TcxGridIndicatorRowItemViewInfo(AViewInfo).GridRecord.Index + 1);
    InflateRect(FBounds, -1, -1);    //Platform   specific.   May   not   work   on   Linux.
    ACanvas.Font.Color := clBlack;
    ACanvas.Brush.Style := bsClear;
    ACanvas.DrawText(FValue, FBounds, cxAlignCenter or cxAlignTop);
    ADone := True;
  end;
end;

procedure TfrmBpCklist.Tv1DblClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty = True then
  begin
    Exit;
  end;
  frmbpck := Tfrmbpck.create(self);
  with frmbpck do
  begin
    fkeyNo := self.cds_main.fieldbyname('CRNO').AsString;
    fType := 1;
    fckName := self.fckName;
    TBSave.Visible := False;
    ToolBar2.Enabled := False;
    if showmodal = 1 then
    begin
      TBRafresh.Click;
      self.CDS_Main.Locate('crNo', trim(fkeyNo), []);
    end;
    free;
  end;
end;

procedure TfrmBpCklist.Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin
//  InitSub();
end;

procedure TfrmBpCklist.ToolButton2Click(Sender: TObject);
var
  YFID, CRID: string;
begin
  if CDS_Main.IsEmpty then
    Exit;

  with ADOQueryTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from YS_Money_CR where YFTypeId=''' + Trim(Self.CDS_Main.fieldbyname('CRID').AsString) + '''');
    sql.Add(' and ChkStatusP=''已审核''');
    Open;
  end;
  if ADOQueryTmp.IsEmpty = false then
  begin
    Application.MessageBox('应收款已审核不能操作', '提示');
    exit;
  end;

  if Application.MessageBox('是否要单条删除？', '提示', 32 + 4) <> IDYES then
    Exit;

  try

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;

      sql.Add('update  YP_InOut2 SET valid=''N'' ');
      sql.Add(',editer=' + quotedstr(trim(DName)));
      sql.Add(',edittime=getdate(),CWFlag=0,YFID=Null');
      SQL.Add('where  CRid=''' + Trim(CDS_Main.fieldbyname('CRID').AsString) + ''' ');

      sql.Add('delete from YS_Money_CR  ');
      SQL.Add('where YFTypeId=''' + Trim(CDS_Main.fieldbyname('CRID').AsString) + ''' ');
      execsql;
    end;
    TBRafresh.Click;
  except
    Application.MessageBox('数据删除失败！', '提示信息', 0);
  end;
end;

procedure TfrmBpCklist.ToolButton3Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;

  if Application.MessageBox('是否撤销删除？', '提示', 32 + 4) <> IDYES then
    Exit;

  try

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;

      sql.Add('update  YP_InOut2 SET valid=''Y'' ');
      sql.Add(',editer=' + quotedstr(trim(DName)));
      sql.Add(',edittime=getdate()');
      SQL.Add('where  CRid=''' + Trim(CDS_Main.fieldbyname('CRid').AsString) + ''' ');

      execsql;
    end;
    TBRafresh.Click;
  except
    Application.MessageBox('数据撤销删除失败！', '提示信息', 0);
  end;
end;

procedure TfrmBpCklist.Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
//  if (AViewInfo.GridRecord.Values[Tv1Column5.Index] = 1) then
//  begin
//    ACanvas.font.Color := clRed;
//  end;
end;

procedure TfrmBpCklist.ToolButton4Click(Sender: TObject);
var
  fkeyNo: string;
begin
  if GetLSNo(ADOQueryCmd, fkeyNo, 'YC', 'YP_InOut2', 3, 1) = False then
  begin
      //  ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('取最大号失败!', '提示', 0);
    Exit;
  end;
end;

end.

