unit U_ExpenseList;

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,
  cxCurrencyEdit;

type
  TfrmExpenseList = 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;
    v2FactoryName: TcxGridDBColumn;
    PayMent: TcxTextEdit;
    Label4: TLabel;
    Label6: TLabel;
    oppShuiNo: TcxTextEdit;
    Tv1OppBankName: TcxGridDBColumn;
    cxTabControl1: TcxTabControl;
    Label11: TLabel;
    Use: TcxTextEdit;
    btnChk: TToolButton;
    btnReChk: TToolButton;
    PM_1: TPopupMenu;
    N1: TMenuItem;
    ToolButton4: TToolButton;
    Label2: TLabel;
    FFID: TcxTextEdit;
    ToolButton5: TToolButton;
    N2: TMenuItem;
    btnEdit: TToolButton;
    Tv1OppBankCardNo: TcxGridDBColumn;
    Tv1OurBankName: TcxGridDBColumn;
    Tv1OurBankCardNo: TcxGridDBColumn;
    Tv1Amount: TcxGridDBColumn;
    Tv1Currency: TcxGridDBColumn;
    Tv1ReimburseType: TcxGridDBColumn;
    Tv1Column20: TcxGridDBColumn;
    Tv1Status: TcxGridDBColumn;
    Tv1Column22: TcxGridDBColumn;
    Tv1PayStatus: TcxGridDBColumn;
    ToolButton9: TToolButton;
    N3: TMenuItem;
    Tv1PayTime: TcxGridDBColumn;
    Label1: TLabel;
    begdate: TcxDateEdit;
    Enddate: TcxDateEdit;
    CheckBox1: TcxCheckBox;
    Tv1TaxNumber: TcxGridDBColumn;
    Tv1PrintStatus: TcxGridDBColumn;
    TbnPay: TToolButton;
    TbnRePay: TToolButton;
    TbPrint: TToolButton;
    Tv1FFID: TcxGridDBColumn;
    Tv1Filler: TcxGridDBColumn;
    Tv1FJFlag: TcxGridDBColumn;
    Tv1PayMent: TcxGridDBColumn;
    Tv1BankSlipNumber: TcxGridDBColumn;
    Tv1Use: TcxGridDBColumn;
    btnChk2: TToolButton;
    btnReChk2: TToolButton;
    Tv1IVNo: TcxGridDBColumn;
    TbFP: TToolButton;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    TbCancelFP: 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 Tv1ReimburseTypePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure TbnPayClick(Sender: TObject);
    procedure TbnRePayClick(Sender: TObject);
    procedure TbPrintClick(Sender: TObject);
    procedure btnChk2Click(Sender: TObject);
    procedure btnReChk2Click(Sender: TObject);
    procedure TbFPClick(Sender: TObject);
    procedure TbCancelFPClick(Sender: TObject);
  private
    FPayOurBankName: TcxButtonEdit;
    FPayOurBankCardNo: TcxTextEdit;
    procedure OurBankNameButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure InitGrid();
    procedure SetStatus();
  public
    FAuthority: string;
  end;

implementation

uses
  U_DataLink, U_RTFun, U_ExpenseInput, U_ZDYHelp, U_AttachmentUpload,
  U_LabelPrint, U_InvoiceSel, U_ZDYBankSel, U_FKandFPUpload;

{$R *.dfm}
procedure TfrmExpenseList.OurBankNameButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYBankSel := TfrmZDYBankSel.Create(Application);
    with frmZDYBankSel do
    begin
      MainType := '财务银行';
      flag := 'OurBankName';
      flagname := '付款账号';
      if ShowModal = 1 then
      begin
        FPayOurBankName.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        FPayOurBankCardNo.Text := Trim(ClientDataSet1.fieldbyname('note').AsString);
      end;
    end;
  finally
    frmZDYBankSel.Free;
  end;
end;

procedure TfrmExpenseList.SetStatus();
begin

  btnChk.Enabled := false;     //审核1
  btnReChk.Enabled := false;     //撤销1
  btnChk2.Enabled := false;     //审核2
  btnReChk2.Enabled := false;     //撤销2
  TbnPay.Enabled := false;     //付款
  TbnRePay.Enabled := false;     //撤销

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

  TbFP.Enabled := False;

  if Trim(FAuthority) = '审核' then
  begin
    btnAdd.Enabled := true;
    TbFP.Enabled := true;
    cxTabControl1.Tabs[2].Visible := False;
    cxTabControl1.Tabs[3].Visible := False;
//     cxTabControl1.Tabs[0].caption := 'aa';
    case cxTabControl1.TabIndex of
      0:
        begin
          btnEdit.Enabled := true;
          btnDel.Enabled := true;
          btnChk.Enabled := true;
//          TbFP.Enabled := true;
        end;
      1:
        begin
          btnReChk.Enabled := true;
//          btnChk2.Enabled := true;     //审核2
        end;
      2:
        begin
//          TbnPay.Enabled := true;
//          btnReChk2.Enabled := true;     //撤销2
        end;
      3:
        begin
//          TbnRePay.Enabled := true;
        end;
    end;
  end;

  if Trim(FAuthority) = '审核2' then
  begin
    btnAdd.Enabled := true;
    TbFP.Enabled := true;
    cxTabControl1.Tabs[0].Visible := False;
    cxTabControl1.Tabs[3].Visible := False;
    case cxTabControl1.TabIndex of
      0:
        begin
          btnEdit.Enabled := true;
          btnDel.Enabled := true;
//          btnChk.Enabled := true;
//          TbFP.Enabled := true;
        end;
      1:
        begin
//          btnReChk.Enabled := true;
          btnChk2.Enabled := true;     //审核2
        end;
      2:
        begin
//          TbnPay.Enabled := true;
          btnReChk2.Enabled := true;     //撤销2
        end;
      3:
        begin
//          TbnRePay.Enabled := true;
        end;
    end;
  end;

  if Trim(FAuthority) = '付款' then
  begin
    cxTabControl1.Tabs[0].Visible := False;
    cxTabControl1.Tabs[1].Visible := False;
    cxTabControl1.Tabs[2].caption := '未付款';
    btnAdd.Enabled := true;
    TbFP.Enabled := true;

    case cxTabControl1.TabIndex of
      0:
        begin
          btnEdit.Enabled := true;
          btnDel.Enabled := true;
//          TbFP.Enabled := true;
//          btnChk.Enabled := true;
        end;
      1:
        begin
//          btnReChk.Enabled := true;
//          btnChk2.Enabled := true;     //审核2
        end;
      2:
        begin
          TbnPay.Enabled := true;
//          btnReChk2.Enabled := true;     //撤销2
        end;
      3:
        begin
          TbnRePay.Enabled := true;
        end;
    end;
  end;

  if Trim(FAuthority) = '申请' then
  begin
    btnAdd.Enabled := true;
    case cxTabControl1.TabIndex of
      0:
        begin
          btnEdit.Enabled := true;
          btnDel.Enabled := true;
          TbFP.Enabled := true;
        end;
      1:
        begin

        end;
      2:
        begin

        end;
    end;
  end;
end;

procedure TfrmExpenseList.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 Checkstatus=''未审核'' ');
          end;
        1:
          begin
            sql.Add(' and Checkstatus=''已审核1'' ');
          end;
        2:
          begin
            sql.add(' and Checkstatus=''已审核2'' and PayStatus<>''已付款'' ');
          end;
        3:
          begin
            sql.Add(' and PayStatus=''已付款'' ');
          end;

      end;
      if Trim(Use.Text) <> '' then
      begin
        SQL.Add(' and A.[Use] like ''%' + Trim(Use.Text) + '%'' ');
      end;
      if CheckBox1.Checked then
      begin
        sql.Add(' and A.FFTime>=''' + FormatDateTime('yyyy-MM-dd', begdate.Date) + ''' ');
        sql.Add(' and A.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 TfrmExpenseList.N1Click(Sender: TObject);
begin
  SelOKNo(cds_1, True);

end;

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

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

end;

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

procedure TfrmExpenseList.TbCancelFPClick(Sender: TObject);
var
  FFFIDS: string;
begin
  inherited;

  if CDS_1.IsEmpty then
    Exit;

  if not CDS_1.Locate('SSel', True, []) then
  begin
    Application.MessageBox('请先选择数据', '提示信息', MB_OK + MB_ICONINFORMATION);
    Exit;
  end;

  with CDS_1 do
  begin
    DisableControls;
    First;
    while not Eof do
    begin
      if FieldByName('SSel').AsBoolean then
      begin
        if Trim(FieldByName('IVID').AsString) = '' then
        begin
          Application.MessageBox(PChar('记录【' + FieldByName('FFID').AsString + '】未关联发票，无需撤销'), '提示信息', MB_OK + MB_ICONWARNING);
          EnableControls;
          Exit;
        end;
        FFFIDS := FFFIDS + Trim(FieldByName('FFID').AsString) + ',';
      end;
      Next;
    end;
    EnableControls;
  end;

  if FFFIDS <> '' then
    FFFIDS := Copy(FFFIDS, 1, Length(FFFIDS) - 1)
  else
    Exit;

  try
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      SQL.Add('UPDATE Finance_Flow SET IVNo = '''', IVID = '''' ');
      SQL.Add('WHERE FFID IN (SELECT rtvalue FROM dbo.F_Tool_SplitString(' +
              QuotedStr(FFFIDS) + ', '',''))');
      ExecSQL;
    end;

    Application.MessageBox('撤销关联发票成功', '提示信息', MB_OK + MB_ICONINFORMATION);

    InitGrid();

  except
    on E: Exception do
    begin
      Application.MessageBox(PChar('撤销关联发票失败：' + E.Message), '错误信息', MB_OK + MB_ICONERROR);
    end;
  end;
end;

procedure TfrmExpenseList.TBCloseClick(Sender: TObject);
begin

  Close;
end;

procedure TfrmExpenseList.TbFPClick(Sender: TObject);
var
  selIVNo, selIVID: string;
begin
  if not CDS_1.Locate('ssel', True, []) then
  begin
    Application.MessageBox('请先选择付款申请数据', '提示信息', MB_OK);
    Exit;
  end;

  try
    frmInvoiceSel := TfrmInvoiceSel.Create(Application);
    try
      if frmInvoiceSel.ShowModal = 1 then
      begin
        selIVNo := frmInvoiceSel.FSelectedIVNo;
        selIVID := frmInvoiceSel.FSelectedIVID;

        CDS_1.DisableControls;
        try
          CDS_1.First;
          while not CDS_1.Eof do
          begin
            if CDS_1.FieldByName('SSel').AsBoolean then
            begin
              with ADOQueryCmd do
              begin
                Close;
                SQL.Clear;
                SQL.Add('select * from Finance_Flow where FFID = ' + QuotedStr(Trim(CDS_1.FieldByName('FFID').AsString)));
                Open;
                if not IsEmpty then
                begin
                  Edit;
                  FieldByName('IVNo').AsString := selIVNo;
                  FieldByName('IVID').AsString := selIVID;
                  Post;
                end;
              end;
            end;
            CDS_1.Next;
          end;
        finally
          CDS_1.EnableControls;
        end;

        InitGrid();
      end;
    finally
      frmInvoiceSel.Free;
    end;
  except
    on E: Exception do
      Application.MessageBox(PChar('关联发票失败：' + E.Message), '错误', MB_ICONERROR);
  end;
end;

procedure TfrmExpenseList.TbnPayClick(Sender: TObject);
var
  FFFIDS: string;
  SelectedDate: TDate;
  DateForm: TForm;
  cxDateEdit: TcxDateEdit;
  cxTextEdit: TcxTextEdit;
  btnOK, btnCancel: TButton;
  lblDate, lblBankSlip: TLabel;
  BankSlipCode: string;
  lblOurBankName, lblOurBankCardNo: TLabel;
  OurBankName, OurBankCardNo: string;
begin
  if CDS_1.IsEmpty then
    exit;

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

  OurBankName := '';
  OurBankCardNo := '';
  with CDS_1 do
  begin
    First;
    while not Eof do
    begin
      if FieldByName('SSel').AsBoolean then
      begin
        if OurBankName = '' then
          OurBankName := Trim(FieldByName('OurBankName').AsString);
        if OurBankCardNo = '' then
          OurBankCardNo := Trim(FieldByName('OurBankCardNo').AsString);
      end;
      Next;
    end;
  end;

  // 创建一个窗体
  DateForm := TForm.Create(nil);
  try
    DateForm.Caption := '付款信息';
    DateForm.Width := 350;
    DateForm.Height := 260;
    DateForm.Position := poScreenCenter;
    DateForm.BorderStyle := bsDialog;
    DateForm.BorderIcons := [biSystemMenu];

    // 创建付款日期标签
    lblDate := TLabel.Create(DateForm);
    lblDate.Parent := DateForm;
    lblDate.Caption := '付款日期:';
    lblDate.Left := 20;
    lblDate.Top := 23;

    // 创建 cxDateEdit
    cxDateEdit := TcxDateEdit.Create(DateForm);
    cxDateEdit.Parent := DateForm;
    cxDateEdit.Properties.Kind := ckDate; // 或者 ckDate 如果只需要日期
    cxDateEdit.Properties.DateButtons := [btnToday]; // 添加今天按钮
    cxDateEdit.Properties.ShowTime := False; // 不显示时间部分
    cxDateEdit.Properties.SaveTime := False;
    cxDateEdit.Properties.DateOnError := deToday; // 错误时显示今天
    cxDateEdit.Date := Now; // 默认当前日期
    cxDateEdit.Left := 120;
    cxDateEdit.Top := 18;
    cxDateEdit.Width := 200;

    lblOurBankName := TLabel.Create(DateForm);
    lblOurBankName.Parent := DateForm;
    lblOurBankName.Caption := '付款账号:';
    lblOurBankName.Left := 20;
    lblOurBankName.Top := 63;

    lblOurBankName := TLabel.Create(DateForm);
    lblOurBankName.Parent := DateForm;
    lblOurBankName.Caption := '付款账号:';
    lblOurBankName.Left := 20;
    lblOurBankName.Top := 63;

    FPayOurBankName := TcxButtonEdit.Create(DateForm);  // 使用成员变量
    FPayOurBankName.Parent := DateForm;
    FPayOurBankName.Left := 120;
    FPayOurBankName.Top := 58;
    FPayOurBankName.Width := 200;
    FPayOurBankName.Text := OurBankName;
    FPayOurBankName.Properties.Buttons[0].Kind := bkEllipsis;
    FPayOurBankName.Properties.OnButtonClick := OurBankNameButtonClick;
    // ====== 新增结束 ======

    // ====== 新增：付款银行 ======
    lblOurBankCardNo := TLabel.Create(DateForm);
    lblOurBankCardNo.Parent := DateForm;
    lblOurBankCardNo.Caption := '付款银行:';
    lblOurBankCardNo.Left := 20;
    lblOurBankCardNo.Top := 103;

    FPayOurBankCardNo := TcxTextEdit.Create(DateForm);  // 使用成员变量
    FPayOurBankCardNo.Parent := DateForm;
    FPayOurBankCardNo.Left := 120;
    FPayOurBankCardNo.Top := 98;
    FPayOurBankCardNo.Width := 200;
    FPayOurBankCardNo.Text := OurBankCardNo;

    // 创建银行水单编码标签
    lblBankSlip := TLabel.Create(DateForm);
    lblBankSlip.Parent := DateForm;
    lblBankSlip.Caption := '银行水单编码:';
    lblBankSlip.Left := 20;
    lblBankSlip.Top := 143;

    // 创建 cxTextEdit 用于输入银行水单编码
    cxTextEdit := TcxTextEdit.Create(DateForm);
    cxTextEdit.Parent := DateForm;
    cxTextEdit.Left := 120;
    cxTextEdit.Top := 138;
    cxTextEdit.Width := 200;
    cxTextEdit.Text := '';

    // 创建确定按钮
    btnOK := TButton.Create(DateForm);
    btnOK.Parent := DateForm;
    btnOK.Caption := '确定';
    btnOK.ModalResult := mrOK;
    btnOK.Left := 80;
    btnOK.Top := 180;
    btnOK.Width := 80;
    btnOK.Default := True;

    // 创建取消按钮
    btnCancel := TButton.Create(DateForm);
    btnCancel.Parent := DateForm;
    btnCancel.Caption := '取消';
    btnCancel.ModalResult := mrCancel;
    btnCancel.Left := 180;
    btnCancel.Top := 180;
    btnCancel.Width := 80;
    btnCancel.Cancel := True;

    // 显示对话框
    if DateForm.ShowModal = mrOK then
    begin
      // 获取选择的日期
      SelectedDate := Trunc(cxDateEdit.Date); // 取日期部分
      BankSlipCode := Trim(cxTextEdit.Text);

      OurBankName := Trim(FPayOurBankName.Text);
      OurBankCardNo := Trim(FPayOurBankCardNo.Text);

      // 验证输入
      if BankSlipCode = '' then
      begin
        if application.MessageBox('银行水单编码为空，是否继续？', '确认', MB_YESNO + MB_ICONQUESTION) <> IDYES then
          Exit;
      end;

      // 显示选择的日期和银行水单编码（调试用）
      // ShowMessage('付款日期: ' + DateToStr(SelectedDate) + #13#10 + '银行水单编码: ' + BankSlipCode);
      // 这里可以添加审核确认
      if application.MessageBox(PChar('付款日期: ' + DateToStr(SelectedDate) + #13#10 + '银行水单编码: ' + BankSlipCode + #13#10 + '确认付款吗？'), '确认付款', MB_YESNO + MB_ICONQUESTION) = IDYES then
      begin
        // 获取选中的记录
        with CDS_1 do
        begin
          DisableControls;
          First;
          while not EOF do
          begin
            if FieldByName('SSel').AsBoolean then
            begin
              FFFIDS := FFFIDS + Trim(FieldByName('FFID').AsString) + ',';
            end;
            Next;
          end;
          EnableControls;
        end;

        // 删除末尾的逗号
        if FFFIDS <> '' then
          FFFIDS := Copy(FFFIDS, 1, Length(FFFIDS) - 1);

        // 处理选中的记录
        with CDS_1 do
        begin
          DisableControls;
          while CDS_1.Locate('SSel', True, []) do
          begin
            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(',@PayTime=' + QuotedStr(FormatDateTime('yyyy-mm-dd', SelectedDate)));
            // 添加银行水单编码参数 - 需要修改存储过程
            sql.Add(',@BankSlipNumber=' + QuotedStr(BankSlipCode));

            sql.Add(',@OurBankName=' + QuotedStr(OurBankName));
            sql.Add(',@OurBankCardNo=' + QuotedStr(OurBankCardNo));
            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;
    end;

  finally
    DateForm.Free;
  end;
end;
//var
//  FFFIDS: string;
//  SelectedDate: TDate;
//  DateForm: TForm;
//  MonthCalendar: TMonthCalendar;
//  btnOK, btnCancel: TButton;
//begin
//  if CDS_1.IsEmpty then
//    exit;
//
//  if not CDS_1.Locate('SSel', True, []) then
//  begin
//    application.MessageBox('请选择数据', '提示');
//    Exit;
//  end;
//
//  // 创建一个窗体来包含 MonthCalendar
//  DateForm := TForm.Create(nil);
//  try
//    DateForm.Caption := '选择付款日期';
//    DateForm.Width := 400;
//    DateForm.Height := 400;
//    DateForm.Position := poScreenCenter;
//    DateForm.BorderStyle := bsDialog;
//    DateForm.BorderIcons := [biSystemMenu];
//
//    // 创建 MonthCalendar
//    MonthCalendar := TMonthCalendar.Create(DateForm);
//    MonthCalendar.Parent := DateForm;
//    MonthCalendar.Left := 55;
//    MonthCalendar.Top := 15;
//    MonthCalendar.Width := 300;  // 明确设置宽度
//    MonthCalendar.Height := 300; // 明确设置高度
//    MonthCalendar.Date := Now;
//
//    // 创建确定按钮
//    btnOK := TButton.Create(DateForm);
//    btnOK.Parent := DateForm;
//    btnOK.Caption := '确定';
//    btnOK.ModalResult := mrOK;
//    btnOK.Left := 120;
//    btnOK.Top := MonthCalendar.Top + MonthCalendar.Height + 10;
//    btnOK.Default := True;
//
//    // 创建取消按钮
//    btnCancel := TButton.Create(DateForm);
//    btnCancel.Parent := DateForm;
//    btnCancel.Caption := '取消';
//    btnCancel.ModalResult := mrCancel;
//    btnCancel.Left := btnOK.Left + btnOK.Width + 20;
//    btnCancel.Top := btnOK.Top;
//    btnCancel.Cancel := True;
//
//    // 显示对话框
//    if DateForm.ShowModal = mrOK then
//    begin
//      // 获取选择的日期
//      SelectedDate := MonthCalendar.Date;
//
//      // 显示选择的日期（调试用）
//      // ShowMessage('选择的日期: ' + DateToStr(SelectedDate));
//
//      // 这里可以添加审核确认
//      if application.MessageBox(PChar('付款日期: ' + DateToStr(SelectedDate)), '确认', MB_YESNO + MB_ICONQUESTION) = IDYES then
//      begin
//        // 获取选中的记录
//        with CDS_1 do
//        begin
//          DisableControls;
//          First;
//          while not EOF do
//          begin
//            if FieldByName('SSel').AsBoolean then
//            begin
//              FFFIDS := FFFIDS + Trim(FieldByName('FFID').AsString) + ',';
//            end;
//            Next;
//          end;
//          EnableControls;
//        end;
//
//        // 删除末尾的逗号
//        if FFFIDS <> '' then
//          FFFIDS := Copy(FFFIDS, 1, Length(FFFIDS) - 1);
//
//        // 处理选中的记录
//        with CDS_1 do
//        begin
//          DisableControls;
//          while CDS_1.Locate('SSel', True, []) do
//          begin
//            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(',@PayTime=' + QuotedStr(FormatDateTime('yyyy-mm-dd', SelectedDate)));
//            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;
//    end;
//
//  finally
//    DateForm.Free;
//  end;
//end;

procedure TfrmExpenseList.TbnRePayClick(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 TfrmExpenseList.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;
      FFiltration1 := WSql;
//      ShowMessage(FFiltration1);
      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 TfrmExpenseList.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;

  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
    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)));
    application.MessageBox('审核成功', '提示');
  except
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;

end;

procedure TfrmExpenseList.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(trim(Self.Caption), Tv1, '费用管理');
  Enddate.Date := SGetServerDate(ADOQueryTemp);
  begdate.Date := Enddate.Date - 30;
  FAuthority := self.fParameters1;
  if FAuthority = '付款' then
  begin
    cxTabControl1.TabIndex := 2;
  end;
  SetStatus();

  InitGrid();
end;

procedure TfrmExpenseList.TBRafreshClick(Sender: TObject);
begin
  toolbar1.SetFocus;

  InitGrid();

end;

procedure TfrmExpenseList.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 TfrmExpenseList.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=''审核1'' ');
      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('审核1成功', '提示');
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;
end;

procedure TfrmExpenseList.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=''撤销审核1'' ');
      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('撤销审核1成功', '提示');
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;
end;

procedure TfrmExpenseList.btnAddClick(Sender: TObject);
begin

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

procedure TfrmExpenseList.btnChk2Click(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=''审核2'' ');
      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('审核2成功', '提示');
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;
end;

procedure TfrmExpenseList.btnReChk2Click(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=''撤销审核2'' ');
      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('撤销审核2成功', '提示');
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;
end;

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

procedure TfrmExpenseList.ToolButton5Click(Sender: TObject);
begin
  WriteCxGrid(trim(Self.Caption), Tv1, '费用管理');
end;

procedure TfrmExpenseList.btnEditClick(Sender: TObject);
begin
  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
    frmExpenseInput := TfrmExpenseInput.Create(Application);
    with frmExpenseInput do
    begin
      FFFID := Trim(SELF.CDS_1.fieldbyname('FFID').AsString);
      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmExpenseInput.Free;
  end;
end;

procedure TfrmExpenseList.ToolButton9Click(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;
  try
    frmFKandFPUpload := TfrmFKandFPUpload.Create(Application);
    with frmFKandFPUpload do
    begin
      if Trim(Self.CDS_1.fieldbyname('filler').AsString) = dname then
        FEditAuthority := True;
      fkeyNO := Trim(Self.CDS_1.fieldbyname('FFID').AsString);
      fkeyNO2 := Trim(Self.CDS_1.fieldbyname('IVID').AsString);
      fType := '费用登记';
      fType2 := '进项发票';
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmFKandFPUpload.Free;
  end;
end;

procedure TfrmExpenseList.Tv1ReimburseTypePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'ReimburseType';
      flagname := '报销类型';
      if ShowModal = 1 then
      begin
        Self.CDS_1.Edit;
        Self.CDS_1.FieldByName('ReimburseType').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        Self.CDS_1.Post;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

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

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

end.

