unit U_PayList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
  cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin, StdCtrls,
  cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
  cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP, ShellAPI, IniFiles, cxCheckBox, cxCalendar, cxButtonEdit,
  cxTextEdit, cxPC, cxDropDownEdit, cxLookAndFeels, cxLookAndFeelPainters,
  cxNavigator, dxBarBuiltInMenu, dxDateRanges, U_BaseList, Vcl.Menus,
  Vcl.Clipbrd, cxContainer, dxCore, cxDateUtils, dxSkinsCore,
  dxSkinsDefaultPainters, dxScrollbarAnnotations, cxProgressBar, dxSkinWXI;

type
  TfrmPayList = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    btnDel: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ADOQueryMain: TADOQuery;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    Label3: TLabel;
    OppCoName: TcxTextEdit;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    Tv1FFTime: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    GPM_1: TcxGridPopupMenu;
    DS_1: TDataSource;
    CDS_1: TClientDataSet;
    btnAdd: TToolButton;
    Tv1OppCoName: TcxGridDBColumn;
    F_Name: TcxTextEdit;
    Label4: TLabel;
    Label6: TLabel;
    P_Code: TcxTextEdit;
    Tv1BuyConNo: TcxGridDBColumn;
    cxTabControl1: TcxTabControl;
    Label10: TLabel;
    ConNo: TcxTextEdit;
    Label11: TLabel;
    BuyConNo: TcxTextEdit;
    Tv1OurCoName: TcxGridDBColumn;
    btnChk: TToolButton;
    btnReChk: TToolButton;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    ToolButton4: TToolButton;
    Label2: TLabel;
    OppParentCoName: TcxTextEdit;
    ToolButton5: TToolButton;
    N2: TMenuItem;
    btnEdit: TToolButton;
    Tv1OurBankName: TcxGridDBColumn;
    Tv1OppBankName: TcxGridDBColumn;
    Tv1PayMent: TcxGridDBColumn;
    Tv1Amount: TcxGridDBColumn;
    Tv1Currency: TcxGridDBColumn;
    Tv1ConNo: TcxGridDBColumn;
    Tv1OrderNo: TcxGridDBColumn;
    Tv1Column22: TcxGridDBColumn;
    Tv1FFAbstract: TcxGridDBColumn;
    ToolButton9: TToolButton;
    N3: TMenuItem;
    Tv1Note: TcxGridDBColumn;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    Tv1FJFlag: TcxGridDBColumn;
    Label1: TLabel;
    begdate: TcxDateEdit;
    Enddate: TcxDateEdit;
    CheckBox1: TcxCheckBox;
    Tv1Filler: TcxGridDBColumn;
    Tv1Filltime: TcxGridDBColumn;
    Tv1Chker: TcxGridDBColumn;
    Tv1Chktime: TcxGridDBColumn;
    Tv1CheckStatus: TcxGridDBColumn;
    Tv1PrintStatus: TcxGridDBColumn;
    Tv1PayStatus: TcxGridDBColumn;
    Tv1PayTime: TcxGridDBColumn;
    TbPrint: TToolButton;
    TbFinPay: TToolButton;
    TbReFinPay: TToolButton;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure btnDelClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure cxGridDBColumn5PropertiesEditValueChanged(Sender: TObject);
    procedure btnAddClick(Sender: TObject);
    procedure OppCoNameKeyPress(Sender: TObject; var Key: Char);
    procedure cxTabControl1Change(Sender: TObject);
    procedure btnChkClick(Sender: TObject);
    procedure btnReChkClick(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure btnEditClick(Sender: TObject);
    procedure ToolButton9Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure TbFinPayClick(Sender: TObject);
    procedure TbReFinPayClick(Sender: TObject);
    procedure TbPrintClick(Sender: TObject);
  private
    procedure InitGrid();
    procedure SetStatus();
  public
    FAuthority: string;
  end;

implementation

uses
  U_DataLink, U_RTFun, U_PayInput, U_ZDYHelp, U_AttachmentUpload, U_PayImport,U_LabelPrint;

{$R *.dfm}
procedure TfrmPayList.SetStatus();
begin

  btnChk.Enabled := false;     //审核
  btnReChk.Enabled := false;     //撤销

  btnAdd.Enabled := false;   //新增
  btnEdit.Enabled := false;     //修改
  btnDel.Enabled := false;           //删除

  TbFinPay.Enabled := False;
  TbReFinPay.Enabled := False;
//  ShowMessage(FAuthority);
  if Trim(FAuthority) = '管理' then
  begin
    btnAdd.Enabled := true;
    case cxTabControl1.TabIndex of
      0:
        begin
          btnEdit.Enabled := true;
          btnDel.Enabled := true;
          btnChk.Enabled := true;
        end;
      1:
        begin
          btnReChk.Enabled := true;
          TbFinPay.Enabled := true;
        end;
      2:
        begin
          TbReFinPay.Enabled := true;
        end;
    end;
  end;
  if Trim(FAuthority) = '申请' then
  begin
    btnAdd.Enabled := true;
    case cxTabControl1.TabIndex of
      0:
        begin
          btnEdit.Enabled := true;

        end;
      1:
        begin

        end;
      2:
        begin

        end;
    end;
  end;
end;

procedure TfrmPayList.InitGrid();
var
  WSql: string;
begin
  WSql := SGetFilters(Panel1, 1, 2);
  if Trim(WSql) <> '' then
    WSql := ' and ' + WSql
  else
    CheckBox1.Checked := True;

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      Filtered := False;
      sql.Add(' select A.*  ');
      sql.Add(',FJFlag=CAST((CASE WHEN (SELECT COUNT(X.FileName) FROM FJ_File X where X.TFType=''财务流水'' and X.WBID=A.FFID)>0 THEN 1 ELSE 0 END) AS BIT)');
      sql.Add(' from Finance_Flow A ');

      sql.Add(' where A.FFType=''付款登记''  ');
      case cxTabControl1.TabIndex of
        0:
          begin
            sql.Add(' and isnull(Checkstatus,''0'')=''未审核'' ');
          end;
        1:
          begin
            sql.Add(' and isnull(Checkstatus,''0'')=''已审核'' ');
          end;
        2:
          begin
            sql.Add(' and isnull(Checkstatus,''0'')=''已对账'' ');
          end;
      end;
      if CheckBox1.Checked then
      begin
        sql.Add(' and A.FFTime>=''' + FormatDateTime('yyyy-MM-dd', begdate.Date) + ''' ');
        sql.Add(' and FFTime<''' + FormatDateTime('yyyy-MM-dd', Enddate.Date + 1) + ''' ');
      end;
      sql.Add(WSql);
      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  finally
    ADOQueryMain.EnableControls;
    TV1.DataController.Filter.Clear;
  end;
end;

procedure TfrmPayList.N1Click(Sender: TObject);
begin
  SelOKNo(cds_1, True);

end;

procedure TfrmPayList.N2Click(Sender: TObject);
begin
  Clipboard.SetTextBuf(PChar(Trim(CDS_1.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));
end;

procedure TfrmPayList.N3Click(Sender: TObject);
begin
  SelOKNo(cds_1, false);

end;

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

procedure TfrmPayList.TBCloseClick(Sender: TObject);
begin

  Close;
end;

procedure TfrmPayList.TbFinPayClick(Sender: TObject);
var
  FFFIDS: string;
begin
  if CDS_1.IsEmpty then
    exit;

  if not CDS_1.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;

  with CDS_1 do
  begin
    DisableControls;
    while CDS_1.Locate('SSel', True, []) do
    begin
      FFFIDS := FFFIDS + Trim(CDS_1.fieldbyname('FFID').AsString) + ',';
      CDS_1.Delete;
    end;
    EnableControls;
  end;

  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Fin_Flow_SetStatus ');
      sql.Add(' @FFIDS=' + QuotedStr(FFFIDS));
      sql.Add(',@Operation=''对账'' ');
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));
      open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    ADOQueryCmd.Connection.CommitTrans;
    application.MessageBox('对账成功', '提示');
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;

end;

procedure TfrmPayList.btnDelClick(Sender: TObject);
var
  FFFIDS: string;
begin
  if CDS_1.IsEmpty then
    exit;

  if not CDS_1.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;

  if Application.MessageBox('确定要删除所选数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;

  with CDS_1 do
  begin
    DisableControls;
    while CDS_1.Locate('SSel', True, []) do
    begin
      FFFIDS := FFFIDS + Trim(CDS_1.fieldbyname('FFID').AsString) + ',';
      CDS_1.Delete;
    end;
    EnableControls;
  end;

  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Fin_Flow_Del ');
      sql.Add(' @FFIDS=' + QuotedStr(FFFIDS));
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));
      open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    ADOQueryCmd.Connection.CommitTrans;
    application.MessageBox('删除成功', '提示');
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;

end;

procedure TfrmPayList.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(trim(Self.Caption), Tv1, '财务管理');
  Enddate.Date := SGetServerDate(ADOQueryTemp);
  begdate.Date := Enddate.Date - 30;
  FAuthority := self.fParameters1;
  SetStatus();
  InitGrid();
end;

procedure TfrmPayList.TBRafreshClick(Sender: TObject);
begin

  begdate.SetFocus;
  InitGrid();

end;

procedure TfrmPayList.TbReFinPayClick(Sender: TObject);
var
  FFFIDS: string;
begin
  if CDS_1.IsEmpty then
    exit;

  if not CDS_1.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;

  with CDS_1 do
  begin
    DisableControls;
    while CDS_1.Locate('SSel', True, []) do
    begin
      FFFIDS := FFFIDS + Trim(CDS_1.fieldbyname('FFID').AsString) + ',';
      CDS_1.Delete;
    end;
    EnableControls;
  end;

  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Fin_Flow_SetStatus ');
      sql.Add(' @FFIDS=' + QuotedStr(FFFIDS));
      sql.Add(',@Operation=''撤销对账'' ');
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));
      open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    ADOQueryCmd.Connection.CommitTrans;
    application.MessageBox('撤销对账成功', '提示');
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;

end;

procedure TfrmPayList.cxGridDBColumn5PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
  FPS, FQty, FPrice, FQTFee, FMoney, FZKMoney: Double;
begin
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  mvalue := TcxTextEdit(Sender).EditingText;
  if Trim(mvalue) = '' then
  begin
    mvalue := '0';
  end;

  with CDS_1 do
  begin
    Edit;
    FieldByName(FFieldName).Value := Trim(mvalue);
    Post;
    FPS := CDS_1.fieldbyname('PS').AsFloat;
    FQty := CDS_1.fieldbyname('Qty').AsFloat;
    FQTFee := CDS_1.fieldbyname('QTFee').AsFloat;
    FPrice := CDS_1.fieldbyname('Price').AsFloat;
    FMoney := CDS_1.fieldbyname('Money').AsFloat;

    FZKMoney := CDS_1.fieldbyname('ZKMoney').AsFloat;
  end;

  if Trim(FFieldName) <> 'Money' then
  begin
    FMoney := FQty * FPrice + FQTFee - FZKMoney;
  end;
  with CDS_1 do
  begin
    Edit;
    FieldByName('Money').Value := FMoney;
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('update Finance_Flow set ' + FFieldName + '=' + Trim(mvalue));
    if Trim(FFieldName) <> 'Money' then
      sql.Add(' ,Money=' + FloatToStr(FMoney));
    sql.Add('where FFID=' + quotedstr(Trim(CDS_1.fieldbyname('FFID').AsString)));
    ExecSQL;
  end;

  Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmPayList.btnChkClick(Sender: TObject);
var
  FFFIDS: string;
begin
  if CDS_1.IsEmpty then
    exit;

  if not CDS_1.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;

  with CDS_1 do
  begin
    DisableControls;
    while CDS_1.Locate('SSel', True, []) do
    begin
      FFFIDS := FFFIDS + Trim(CDS_1.fieldbyname('FFID').AsString) + ',';
      CDS_1.Delete;
    end;
    EnableControls;
  end;

  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Fin_Flow_SetStatus ');
      sql.Add(' @FFIDS=' + QuotedStr(FFFIDS));
      sql.Add(',@Operation=''审核'' ');
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));
      open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));

//    with ADOQueryCmd do
//    begin
//      Close;
//      sql.Clear;
//      sql.Add(' exec P_Fin_In_Bank_Flow ');
//      sql.Add(' @FFIDS=' + QuotedStr(FFFIDS));
//      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
//      Sql.Add(',@DName=' + quotedstr(Trim(DName)));
//      open;
//    end;
//    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
//      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    ADOQueryCmd.Connection.CommitTrans;
    application.MessageBox('审核成功', '提示');
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;

end;

procedure TfrmPayList.btnReChkClick(Sender: TObject);
var
  FFFIDS: string;
begin
  if CDS_1.IsEmpty then
    exit;

  if not CDS_1.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;

  with CDS_1 do
  begin
    DisableControls;
    while CDS_1.Locate('SSel', True, []) do
    begin
      FFFIDS := FFFIDS + Trim(CDS_1.fieldbyname('FFID').AsString) + ',';
      CDS_1.Delete;
    end;
    EnableControls;
  end;

  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Fin_Flow_SetStatus ');
      sql.Add(' @FFIDS=' + QuotedStr(FFFIDS));
      sql.Add(',@Operation=''撤销审核'' ');
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));
      open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));

//    with ADOQueryCmd do
//    begin
//      Close;
//      sql.Clear;
//      sql.Add(' exec P_Fin_In_Bank_Flow ');
//      sql.Add(' @FFIDS=' + QuotedStr(FFFIDS));
//      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
//      Sql.Add(',@DName=' + quotedstr(Trim(DName)));
//      open;
//    end;
//    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
//      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    ADOQueryCmd.Connection.CommitTrans;

    application.MessageBox('撤销审核成功', '提示');
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;
end;

procedure TfrmPayList.btnAddClick(Sender: TObject);
begin

  try
    frmPayInput := TfrmPayInput.Create(Application);
    with frmPayInput do
    begin
      FFFID := '';
      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmPayInput.Free;
  end;
end;

procedure TfrmPayList.ToolButton1Click(Sender: TObject);
begin
  try
    frmPayImport := TfrmPayImport.Create(Application);
    with frmPayImport do
    begin

      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmPayImport.Free;
  end;
end;

procedure TfrmPayList.ToolButton2Click(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;
  try
    frmAttachmentUpload := TfrmAttachmentUpload.Create(Application);
    with frmAttachmentUpload do
    begin
      fkeyNO := Trim(Self.CDS_1.fieldbyname('FFID').AsString);
      fType := '财务流水';
      FEditAuthority := True;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmAttachmentUpload.Free;
  end;
end;

procedure TfrmPayList.TbPrintClick(Sender: TObject);
var
  WSql,Wsql1: string;
begin
  if CDS_1.IsEmpty then
    Exit;
  if not CDS_1.Locate('SSel', True, []) then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  WSql := '';
  WSql1 := '';
  CDS_1.DisableControls;
  with CDS_1 do
  begin
    First;
    while not Eof do
    begin
      if CDS_1.fieldbyname('SSel').AsBoolean then
      begin
        if WSql <> '' then
        begin
          WSql := WSql + ',' + Trim(CDS_1.fieldbyname('FFID').AsString);
        end
        else
        begin
          WSql := Trim(CDS_1.fieldbyname('FFID').AsString);
        end;

        if WSql1 <> '' then
        begin
          WSql1 := WSql1 + ',' + QuotedStr(Trim(CDS_1.fieldbyname('FFID').AsString));
        end
        else
        begin
          WSql1 := QuotedStr(Trim(CDS_1.fieldbyname('FFID').AsString));
        end;
      end;
      Next;
    end;
  end;
  CDS_1.Locate('SSel', True, []);
  CDS_1.EnableControls;
  try
    frmLabelPrint := TfrmLabelPrint.Create(Application);
    with frmLabelPrint do
    begin
      FLMType := 'ExpenseList';
      FFiltration1 := WSql1;
      if ShowModal = 1 then
      begin
      WSQl := ''''+WSql + '''';
//        ShowMessage('1111');
        with Self.ADOQueryCmd do
        begin
          Close;
          sql.Clear;

          sql.Add(' UPDATE F SET PrintStatus = ''已打印'' FROM Finance_Flow F ');
          SQL.Add(' WHERE EXISTS ( SELECT 1 FROM [dbo].[F_Tool_SplitString]('+WSQl+', '','') X WHERE X.RTValue = F.FFID )');
//          showMessage(sql.Text);
          execsql;
        end;
      end;
    end;
  finally
    frmLabelPrint.Free;
  end;
end;

procedure TfrmPayList.ToolButton4Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  TcxGridToExcel(self.Caption, cxgrid1);
end;

procedure TfrmPayList.ToolButton5Click(Sender: TObject);
begin
  WriteCxGrid(trim(Self.Caption), Tv1, '财务管理');
end;

procedure TfrmPayList.btnEditClick(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;
  if Trim(CDS_1.fieldbyname('Filler').AsString) <> Trim(DName) then
  begin
    Application.MessageBox('不能操作他人的数据!', '提示', 0);
    Exit;
  end;

  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Fin_Flow_Judge ');
      sql.Add(' @FFIDS=' + QuotedStr(Trim(SELF.CDS_1.fieldbyname('FFID').AsString)));
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));
      open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
  except
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    Exit;
  end;

  try
    frmPayInput := TfrmPayInput.Create(Application);
    with frmPayInput do
    begin
      FFFID := Trim(SELF.CDS_1.fieldbyname('FFID').AsString);
      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmPayInput.Free;
  end;
end;

procedure TfrmPayList.ToolButton9Click(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;
  try
    frmAttachmentUpload := TfrmAttachmentUpload.Create(Application);
    with frmAttachmentUpload do
    begin
      if Trim(Self.CDS_1.fieldbyname('filler').AsString) = dname then
        FEditAuthority := True;
      fkeyNO := Trim(Self.CDS_1.fieldbyname('FFID').AsString);
      fType := 'SD';
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmAttachmentUpload.Free;
  end;

end;

procedure TfrmPayList.OppCoNameKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    InitGrid();
  end;
end;

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

end.

