unit U_KDChkList;

interface

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


type
  TfrmKDChkList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    CDS_PRT: TClientDataSet;
    ToolButton3: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Label1: TLabel;
    ToolButton1: TToolButton;
    ToolButton4: TToolButton;
    ADOQueryPrint: TADOQuery;
    cxTabControl1: TcxTabControl;
    ToolButton2: TToolButton;
    ToolButton5: TToolButton;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ToolButton6: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column11: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v1Column24: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column25: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column26: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    v1Column23: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    v1Column22: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Note: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    lbl1: TLabel;
    lbl2: TLabel;
    lbl3: TLabel;
    lbl4: TLabel;
    lbl5: TLabel;
    KDNO: TEdit;
    Country: TEdit;
    KHName: TEdit;
    KDType: TEdit;
    FKType: TEdit;
    Label2: TLabel;
    EditNote: TMemo;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    order_Sub: TClientDataSet;
    DataSource2: TDataSource;
    v1EditNote: TcxGridDBColumn;
    v1QSDate: TcxGridDBColumn;
    Label10: TLabel;
    JYPerson: TEdit;
    Label3: TLabel;
    KDComName: TEdit;
    v1ConNo: TcxGridDBColumn;
    Label12: TLabel;
    ConNO: TEdit;
    v1FKName: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure cxPageControl1Change(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure WorkerChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure edtKDNOKeyPress(Sender: TObject; var Key: Char);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);

  private
    FInt,PFInt:Integer;
    canshu1,canshu2:string;
    FNowDate:TDateTime;
    procedure InitGrid();
    procedure InitForm();
    function  DelData():Boolean;
    procedure InitGridWsql(fsj:string);
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmKDChkList: TfrmKDChkList;

implementation
uses
  U_DataLink,U_RTFun,U_KDInPut,U_ModuleNote, U_ZDYHelp;

{$R *.dfm}

procedure TfrmKDChkList.FormDestroy(Sender: TObject);
begin
  frmKDChkList:=nil;
end;

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

procedure TfrmKDChkList.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('快递信息审核2',Tv1,'寄件管理');
end;

procedure TfrmKDChkList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.* ');
      SQL.Add(' from KuaiDi_Money A ');
      sql.Add(' inner join OA_Chk OA on A.KDID=OA.MainId and isnull(OA.OAType,'''')=''寄件'' ');
      sql.Add(' where 1=1  and OA.Chker='''+Trim(DName)+'''');
      if cxTabControl1.TabIndex<>0 then
      begin
        sql.Add(' and  A.KDDate>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
        sql.Add(' and A.KDDate<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1))+'''');
      end;
      if cxTabControl1.TabIndex=0 then
      begin
        sql.Add(' and isnull(A.Status,'''')<>''审核不通过'' and isnull(A.Status,'''')<>'''' and isnull(A.Status,'''')<>''审核通过'' ');
        sql.add(' and isnull(OA.ChkStatus,'''')<>''审核通过''');
      end else
      if cxTabControl1.TabIndex=1 then
      begin
        sql.Add(' and isnull(OA.ChkStatus,'''')=''审核通过'' ');
      end  else
      if cxTabControl1.TabIndex=2 then
      begin
        sql.Add(' and isnull(OA.ChkStatus,'''')=''审核不通过'' ');
      end;
      sql.add('Order by A.Status');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmKDChkList.InitForm();
begin
  FNowDate:=SGetServerDate(ADOQueryTemp);
  EndDate.Date:=SGetServerDateMEnd(ADOQueryTemp);
  BegDate.Date:=SGetServerDateMBeg(ADOQueryTemp);
  ReadCxGrid('快递信息审核2',Tv1,'寄件管理');
  //InitGrid();
end;

function TfrmKDChkList.DelData():Boolean;
begin
  try
    Result:=false;
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete KuaiDi_Money  where KDId='''+Trim(Order_Main.fieldbyname('KDId').AsString)+'''');
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Result:=False;
    Application.MessageBox('数据删除异常！','提示',0);
  end;
end;

procedure TfrmKDChkList.TBExportClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  TcxGridToExcel('寄件信息',cxGrid1);
end;

procedure TfrmKDChkList.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmKDChkList.FormShow(Sender: TObject);
var
  i:Integer;
begin
  InitForm();
  InitGrid();
  //SInitComBoxByTvColumns(ComboBox2,Tv1,999,True,True);
end;

procedure TfrmKDChkList.cxPageControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmKDChkList.ToolButton3Click(Sender: TObject);
begin
  try
    frmModuleNote:=TfrmModuleNote.Create(Application);
    with frmModuleNote do
    begin
      flag:='寄件信息审核';
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmModuleNote.Free;
  end;
end;

procedure TfrmKDChkList.FormCreate(Sender: TObject);
begin
  canshu1:=Trim(DParameters1);
  canshu2:=Trim(DParameters2);
end;

procedure TfrmKDChkList.InitGridWsql(fsj:string);
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.* ');
      SQL.Add(' from KuaiDi_Money A');
      sql.Add(' where isnull(HZType,'''')='''' ');
      if Trim(canshu1)<>'高权限' then
      begin
        sql.Add('and (Filler in(select UserName from  SY_User where DPID in');
        sql.Add('              (select DPID from SY_User where UserName='''+Trim(DName)+'''))');
        SQL.Add(' )');
      end;
      if cxTabControl1.TabIndex=0 then
      begin
        sql.Add('  and isnull(A.Status,'''')='''' ');
      end else
      if cxTabControl1.TabIndex=1 then
      begin
        sql.Add(' and isnull(A.Status,'''')<>'''' and isnull(A.MoneyPerson,'''')='''' ');
      end   else
      if cxTabControl1.TabIndex=2 then
      begin
        sql.Add(' and isnull(A.MoneyPerson,'''')<>'''' ');
      end;
      sql.Add(fsj);
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmKDChkList.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmKDChkList.WorkerChange(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

procedure TfrmKDChkList.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

procedure TfrmKDChkList.ToolButton4Click(Sender: TObject);
var
  fPrintFile:String;
begin
  if Order_Main.IsEmpty then Exit;
  if Order_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据！','提示',0);
    Exit;
  end;
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\检验指示单标签.rmf' ;
  Order_Main.DisableControls;
  with Order_Main do
  begin
    First;
    while not eof do
    begin
      if Order_Main.FieldByName('SSel').AsBoolean=True then
      begin
        {with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from JYOrder_Main_MD where MDID='''+Trim(Order_Main.fieldbyname('MDID').AsString)+'''');
          Open;
        end;
        if ADOQueryTemp.FieldByName('NotPrint').AsBoolean=True then
        begin
          Order_Main.EnableControls;
          Application.MessageBox('不能打印《不打印》的缸条码!','提示',0);
          Exit;
        end;  }
        if FileExists(fPrintFile) then
        begin
          with ADOQueryPrint do
          begin
            Close;
            sql.Clear;
            sql.Add('select B.OrderNo,B.MPRTCodeName,B.MPRTMF,B.MPRTKZ,C.PRTHX,C.PRTColorNo,C.PRTColor,GangNo=A.GangNo,A.PS,A.Qty,A.QtyUnit,A.MDID ');
            SQL.Add(',B.MPRTCode,B.MPRTGY,C.PRTColorEng,A.SelfGangNo');
            sql.Add('from JYOrder_Main_MD A');
            sql.Add('inner join JYOrder_Main B on A.OrdMainid=B.Mainid');
            sql.Add(' inner join JYOrder_Sub C on A.OrdSubid=C.SubId');
            sql.Add(' where A.MDID='''+Trim(Order_Main.fieldbyname('MDID').AsString)+'''');
            Open;
          end;
          RM1.LoadFromFile(fPrintFile);
          //RM1.ShowReport;
          RM1.PrintReport;
        end else
        begin
          Order_Main.DisableControls;
          Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\检验指示单标签.rmf'),'提示',0);
          Exit;
        end;
      end;

      Next;
    end;
  end;
  Order_Main.EnableControls;
end;

procedure TfrmKDChkList.edtKDNOKeyPress(Sender: TObject; var Key: Char);
var
  fsj:String;
begin
  {if Key<>#13 then Exit;
  if Length(Trim(KDNo.Text))<3 then Exit;
  fsj:=' and A.KDNo like '''+'%'+Trim(KDNo.Text)+'%'+'''';
  InitGridWsql(fsj); }
end;

procedure TfrmKDChkList.N1Click(Sender: TObject);
begin
  SelOKNo(Order_Main,True);
end;

procedure TfrmKDChkList.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Main,False);
end;

procedure TfrmKDChkList.ToolButton2Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>0 then Exit;
  if Order_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin
      while Locate('SSel',True,[])=True do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate OA_Chk Set ChkStatus=''审核通过'',ChkTIme=getdate() ');
          sql.Add(',ChkNote='''+Trim(Order_Main.fieldbyname('ChkNote').AsString)+'''');
          sql.Add(' where MainId='''+Trim(Order_Main.fieldbyname('KDID').AsString)+'''');
          sql.Add(' and isnull(OAType,'''')=''寄件'' and isnull(Chker,'''')='''+Trim(DName)+'''');
          ExecSQL;
        end;
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from OA_Chk ');
          sql.Add(' where MainId='''+Trim(Order_Main.fieldbyname('KDID').AsString)+'''');
          sql.Add(' and isnull(OAType,'''')=''寄件'' and isnull(ChkStatus,'''')<>''审核通过'' ');
          Open;
        end;
        if ADOQueryTemp.IsEmpty=False then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('UPdate KuaiDi_Money Set ChkStatus=''审核中''');  //,ChkTIme=getdate(),Chker='''+Trim(DName)+'''
            sql.Add(',Status=''审核中'',ChkNote='''+Trim(Order_Main.fieldbyname('ChkNote').AsString)+'''');
            sql.Add(' where KDID='''+Trim(Order_Main.fieldbyname('KDID').AsString)+'''');
            ExecSQL;
          end;
        end else
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('UPdate KuaiDi_Money Set ChkStatus=''审核通过'',ChkTIme=getdate(),Chker='''+Trim(DName)+'''');
            sql.Add(',Status=''审核通过'',ChkNote='''+Trim(Order_Main.fieldbyname('ChkNote').AsString)+'''');
            sql.Add(' where KDID='''+Trim(Order_Main.fieldbyname('KDID').AsString)+'''');
            ExecSQL;
          end;
        end;
        Order_Main.Delete;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Order_Main.EnableControls;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作失败!','提示',0);
  end;
  {if Order_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>0 then Exit;
  if Order_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin
      First;
      while Locate('SSel',True,[])=True do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate KuaiDi_Money Set Status=''审核通过'',ChkTime=getdate(),Chker='''+Trim(DName)+'''');
          sql.Add(',ChkNote='''+Trim(Order_Main.fieldbyname('ChkNote').AsString)+''',ChkStatus=''审核通过'' ');
          sql.Add(' where KDID='''+Trim(Order_Main.fieldbyname('KDID').AsString)+'''');
          ExecSQL;
        end;
        Order_Main.Delete;
      end;
    end;
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    
  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end; }

end;

procedure TfrmKDChkList.ToolButton5Click(Sender: TObject);
var
  FCKID,FChkStatus,FChker,FChkTime,FChkNote:String;
begin
  if Order_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex=0 then Exit;
  if cxTabControl1.TabIndex=3 then Exit;
  if Order_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin
      while Locate('SSel',True,[])=True do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate OA_Chk Set ChkStatus=Null,ChkTIme=Null ');
          sql.Add(',ChkNote=Null');
          sql.Add(' where MainId='''+Trim(Order_Main.fieldbyname('KDID').AsString)+'''');
          sql.Add(' and isnull(OAType,'''')=''寄件'' and isnull(Chker,'''')='''+Trim(DName)+'''');
          ExecSQL;
        end;
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select Top 1 * from OA_Chk');
          sql.Add(' where MainId='''+Trim(Order_Main.fieldbyname('KDID').AsString)+'''');
          sql.Add(' and isnull(ChkStatus,'''')<>'''' ');
          sql.Add(' order by ChkTime desc');
          Open;
        end;
        FCKID:=Trim(ADOQueryTemp.fieldbyname('CKID').AsString);
        FChkStatus:=Trim(ADOQueryTemp.fieldbyname('ChkStatus').AsString);
        FChker:=Trim(ADOQueryTemp.fieldbyname('Chker').AsString);
        FChkNote:=Trim(ADOQueryTemp.fieldbyname('ChkNote').AsString);
        FChkTime:=Trim(ADOQueryTemp.fieldbyname('ChkTime').AsString);
        if Trim(FCKID)='' then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add(' UPdate KuaiDi_Money Set ChkStatus=Null,ChkTIme=Null,Chker=Null,Status=''已送审'' ');
            sql.Add(',ChkNote=Null ');
            sql.Add(' where KDID='''+Trim(Order_Main.fieldbyname('KDID').AsString)+'''');
            ExecSQL;
          end;
        end else
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add(' UPdate KuaiDi_Money Set ');
            sql.Add(' Chker='''+Trim(FChker)+'''');
            sql.Add(',ChkTIme='''+Trim(FChkTIme)+'''');
            //sql.Add(',HZStatusTime='''+Trim(FChkTIme)+'''');
            sql.Add(',ChkNote='''+Trim(FChkNote)+'''');
            if Trim(FChkStatus)='审核通过' then
            begin
              sql.Add(',ChkStatus=''审核中'' ' );
              sql.Add(',Status=''审核中'' ' );
            end else
            begin
              sql.Add(',ChkStatus=''审核不通过'' ' );
              sql.Add(',Status=''审核不通过'' ' );
            end;
            sql.Add(' where KDID='''+Trim(Order_Main.fieldbyname('KDID').AsString)+'''');
            ExecSQL;
          end;
        end;

        Order_Main.Delete;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Order_Main.EnableControls;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作失败!','提示',0);
  end;

  {if Order_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex=0 then Exit;
  if cxTabControl1.TabIndex>2 then Exit;
  if Order_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin
      First;
      while Locate('SSel',True,[])=True do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate KuaiDi_Money Set Status=''已送审'',ChkTime=Null,Chker=Null,ChkStatus=Null,ChkNote=Null');
          sql.Add(' where KDID='''+Trim(Order_Main.fieldbyname('KDID').AsString)+'''');
          ExecSQL;
        end;
        Order_Main.Delete;
      end;
    end;
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    
  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end; }
end;

procedure TfrmKDChkList.ToolButton6Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>0 then Exit;
  if Order_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if Order_Main.Locate('SSel;ChkNote',VarArrayOf([True,Null]),[loPartialKey])=True then
  begin
    Application.MessageBox('审核备注不能为空!','提示',0);
    Exit;
  end;
  if Order_Main.Locate('SSel;ChkNote',VarArrayOf([True,'']),[loPartialKey])=True then
  begin
    Application.MessageBox('审核备注不能为空!','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin
      while Locate('SSel',True,[])=True do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate OA_Chk Set ChkStatus=''审核不通过'',ChkTIme=getdate()');
          sql.Add(',ChkNote='''+Trim(Order_Main.fieldbyname('ChkNote').AsString)+'''');
          sql.Add(' where MainId='''+Trim(Order_Main.fieldbyname('KDID').AsString)+'''');
          sql.Add(' and isnull(OAType,'''')=''寄件'' and isnull(Chker,'''')='''+Trim(DName)+'''');
          ExecSQL;
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate KuaiDi_Money Set ChkStatus=''审核不通过'',ChkTIme=getdate(),Chker='''+Trim(DName)+'''');
          sql.Add(',Status=''审核不通过'',ChkNote='''+Trim(Order_Main.fieldbyname('ChkNote').AsString)+'''');
          sql.Add(' where KDID='''+Trim(Order_Main.fieldbyname('KDID').AsString)+'''');
          sql.Add(' delete OA_Chk where MainId='''+Trim(Order_Main.fieldbyname('KDID').AsString)+'''');
          sql.Add(' and isnull(OAType,'''')=''寄件'' ');
          ExecSQL;
        end;
        Order_Main.Delete;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Order_Main.EnableControls;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作失败!','提示',0);
  end;
 { if Order_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>0 then Exit;
  if Order_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if Order_Main.Locate('SSel;ChkNote',VarArrayOf([True,null]),[loPartialKey])=True then
  begin
    Application.MessageBox('审核备注不能为空!','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin
      First;
      while Locate('SSel',True,[])=True do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate KuaiDi_Money Set Status=''审核不通过'',ChkTime=getdate(),Chker='''+Trim(DName)+'''');
          sql.Add(',ChkNote='''+Trim(Order_Main.fieldbyname('ChkNote').AsString)+''',ChkStatus=''审核不通过'' ');
          sql.Add(' where KDID='''+Trim(Order_Main.fieldbyname('KDID').AsString)+'''');
          ExecSQL;
        end;
        Order_Main.Delete;
      end;
    end;
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
   
  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end; }
end;

procedure TfrmKDChkList.Tv1CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from OA_Chk ');
    sql.Add(' where MainId='''+Trim(Order_Main.fieldbyname('KDId').AsString)+'''');
    sql.Add(' and OAType=''寄件'' ');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,Order_Sub);
  SInitCDSData20(ADOQueryTemp,Order_Sub);
  EditNote.Text:=trim(Order_Main.fieldbyname('EditNote').AsString);
end;

end.
