unit U_WorkDeptFeeChkList_JKSQSH;

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
  TfrmWorkDeptFeeChkList_JKSQSH = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    CDS_PRT: TClientDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    cxTabControl1: TcxTabControl;
    Panel1: TPanel;
    Label1: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Worker: TEdit;
    Label6: TLabel;
    ToolButton1: TToolButton;
    Label3: TLabel;
    PerSon1: TEdit;
    ToolButton2: TToolButton;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    CDS_Chker: TClientDataSet;
    Label9: TLabel;
    Person4: TEdit;
    cxSplitter1: TcxSplitter;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    order_Sub: TClientDataSet;
    DataSource2: TDataSource;
    ToolButton8: TToolButton;
    Order_Print: TClientDataSet;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column8: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1FSDate: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1PerSon1: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    v1HZMoney: TcxGridDBColumn;
    v1HZStatus: TcxGridDBColumn;
    v1Person4: TcxGridDBColumn;
    v1Note: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v2Column1: TcxGridDBColumn;
    v1ChkNote: TcxGridDBColumn;
    Label4: TLabel;
    EditNote: TMemo;
    v1EditSQTime: TcxGridDBColumn;
    v1EditNote: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    v1PriceUnit: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure cxPageControl1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure WorkerChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton8Click(Sender: TObject);
  private
    FInt,PFInt:Integer;
    canshu1,canshu2:string;
    procedure InitGrid();
    procedure InitForm();
    function  DelData():Boolean;
    procedure InitGridWsql(fsj:string);
    function  SaveData():Boolean;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmWorkDeptFeeChkList_JKSQSH: TfrmWorkDeptFeeChkList_JKSQSH;

implementation
uses
  U_DataLink,U_RTFun,U_ModuleNote,U_WorkerDeptFeeInPut, U_ZDYHelpSel;

{$R *.dfm}

procedure TfrmWorkDeptFeeChkList_JKSQSH.FormDestroy(Sender: TObject);
begin
  frmWorkDeptFeeChkList_JKSQSH:=nil;
end;

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

procedure TfrmWorkDeptFeeChkList_JKSQSH.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('费用报销列表审核2',Tv1,'费用管理');
end;

procedure TfrmWorkDeptFeeChkList_JKSQSH.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.*,OA.Chker DChker ');
      SQL.Add(' from Worker_Fee_Main A ');
      sql.Add(' inner join OA_Chk OA on A.WFID=OA.MainId and isnull(OA.OAType,'''')=''借款申请'' ');
      sql.Add(' where A.Valid=''Y'' and OA.Chker='''+Trim(DName)+'''');
      sql.add(' and A.ItemName=''借款申请单''');
      if cxTabControl1.TabIndex<>0 then
      begin
        sql.Add(' and  A.WFDate>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
        sql.Add(' and A.WFDate<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1))+'''');
      end;
      if cxTabControl1.TabIndex=0 then
      begin
        sql.Add(' and ((isnull(OA.ChkStatus,'''')='''' and (isnull(A.HZStatus,'''')=''已送审'' or isnull(A.HZStatus,'''')=''审核中''))');
        sql.add(' or 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.HZStatus');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from OA_Chk ');
      sql.Add(' where MainId='''+Trim(Order_Main.fieldbyname('WFID').AsString)+'''');
      sql.add(' and isnull(OAType,'''')=''借款申请''');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,Order_Sub);
    SInitCDSData20(ADOQueryTemp,Order_Sub);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmWorkDeptFeeChkList_JKSQSH.InitForm();
begin
  endDate.Date:=SGetServerDate(ADOQueryTemp);
  BegDate.Date:=EndDate.Date-7;
  cxTabControl1.TabIndex:=0;
  InitGrid();
end;

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

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

procedure TfrmWorkDeptFeeChkList_JKSQSH.FormShow(Sender: TObject);
begin
  ReadCxGrid('费用报销列表审核2',Tv1,'费用管理');
  InitForm();
  InitGrid();
end;

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

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

procedure TfrmWorkDeptFeeChkList_JKSQSH.InitGridWsql(fsj:string);
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('select A.*,FS.*,HJMoney=FS.YunFee+FS.MaTouFee+FS.YangBanFee+FS.OtherFee ');
      SQL.Add(' from JYOrderKP_Fee A inner join JYOrderKP_Fee_Sub FS on A.FMID=FS.FMID');
      sql.Add(' where 1=1');
      if Trim(canshu1)<>'高权限' then
      begin
        sql.Add(' and A.Filler='''+Trim(DName)+'''');
      end;
      sql.Add(fsj);
      sql.Add(' order by A.FPNo');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;
function TfrmWorkDeptFeeChkList_JKSQSH.SaveData():Boolean;
var
  maxno,maxSubNo:String;
begin
  try
    Result:=False;
    ADOQueryCmd.Connection.BeginTrans;
    //保存主表
    if Trim(Order_Main.fieldbyname('MRID').AsString)='' then
    begin
      if GetLSNo(ADOQueryCmd,maxno,'MR','Module_Prompt_Result',4,1)=False then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('取工作子流水号失败!','提示',0);
        Exit;
      end;
    end else
    begin
      maxno:=Trim(Order_Main.fieldbyname('MRID').AsString);
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from Module_Prompt_Result where MRId='''+Trim(Order_Main.fieldbyname('MRID').AsString)+'''');
      Open;
    end;
    with ADOQueryCmd do
    begin
      if Trim(Order_Main.fieldbyname('MRID').AsString)='' then
      begin
        Append;
      end
      else begin
        Edit;
      end;
      FieldByName('MPId').Value:=Trim(Order_Main.fieldbyname('MPId').AsString);
      FieldByName('MRId').Value:=Trim(maxno);
      FieldByName('MRStatus').Value:='已处理';
      FieldByName('MRDate').Value:=SGetServerDateTime(ADOQueryTemp);
      if Trim(Order_Main.fieldbyname('MRId').AsString)='' then
      begin
        FieldByName('Filler').Value:=Trim(DName);
      end else
      begin
        FieldByName('Editer').Value:=Trim(DName);
        FieldByName('EditTime').Value:=SGetServerDateTime(ADOQueryTemp);
      end;
      Post;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;
procedure TfrmWorkDeptFeeChkList_JKSQSH.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmWorkDeptFeeChkList_JKSQSH.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 TfrmWorkDeptFeeChkList_JKSQSH.ToolButton1Click(Sender: TObject);
begin
  try
    frmWorkerDeptFeeInPut:=TfrmWorkerDeptFeeInPut.Create(Application);
    with frmWorkerDeptFeeInPut do
    begin
      PState:=1;
      FMainId:=Trim(Self.Order_Main.fieldbyname('WFID').AsString);
      TBSave.Visible:=False;
      ToolBar2.Visible:=False;
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmWorkerDeptFeeInPut.Free;
  end;

end;

procedure TfrmWorkDeptFeeChkList_JKSQSH.ToolButton2Click(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 TfrmWorkDeptFeeChkList_JKSQSH.N1Click(Sender: TObject);
begin
  SelOKNo(Order_Main,True);
end;

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

procedure TfrmWorkDeptFeeChkList_JKSQSH.ToolButton4Click(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
        if trim(DParameters1)<>'高权限' then
        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('WFID').AsString)+'''');
            sql.Add(' and isnull(OAType,'''')=''借款申请'' and isnull(Chker,'''')='''+Trim(DName)+'''');
            ExecSQL;
          end;
        end
        else
        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('WFID').AsString)+'''');
            ExecSQL;
          end;
        end;
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from OA_Chk ');
          sql.Add(' where MainId='''+Trim(Order_Main.fieldbyname('WFID').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 Worker_Fee_Main Set ChkStatus=''审核中'',ChkTIme=getdate(),Chker='''+Trim(DName)+'''');
            sql.Add(',HZStatus=''审核中'',HZStatusTime=getdate(),ChkNote='''+Trim(Order_Main.fieldbyname('ChkNote').AsString)+'''');
            sql.Add(' where WFID='''+Trim(Order_Main.fieldbyname('WFID').AsString)+'''');
            ExecSQL;
          end;
        end else
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('UPdate Worker_Fee_Main Set ChkStatus=''审核通过'',ChkTIme=getdate(),Chker='''+Trim(DName)+'''');
            sql.Add(',HZStatus=''审核通过'',HZStatusTime=getdate(),ChkNote='''+Trim(Order_Main.fieldbyname('ChkNote').AsString)+'''');
            sql.Add(' where WFID='''+Trim(Order_Main.fieldbyname('WFID').AsString)+'''');
            ExecSQL;
          end;
        end;
        Order_Main.Delete;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Order_Main.EnableControls;
    initGrid();
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作失败!','提示',0);
  end;
end;

procedure TfrmWorkDeptFeeChkList_JKSQSH.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 Order_Main.Locate('SSel;CWChkStatus',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
      first;
      while not eof do
      begin
        if fieldbyname('Ssel').AsBoolean=true then
        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('WFID').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('WFID').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);
          with ADOQueryCmd do
          begin
          Close;
          sql.Clear;
          sql.Add(' UPdate Worker_Fee_Main Set  ');
          sql.Add(' Chker='''+Trim(FChker)+'''');
          sql.Add(',ChkTIme='''+Trim(FChkTIme)+'''');
          sql.Add(',HZStatusTime='''+Trim(FChkTIme)+'''');
          sql.Add(',ChkNote='''+Trim(FChkNote)+'''');
          sql.Add(',ChkStatus=''审核中'' ' );
          sql.Add(',HZStatus=''审核中'' ' );
          sql.Add(' where WFID='''+Trim(Order_Main.fieldbyname('WFID').AsString)+'''');
          ExecSQL;
          end;
        end;
        next;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Order_Main.EnableControls;
    initGrid();
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作失败!','提示',0);
  end;
end;

procedure TfrmWorkDeptFeeChkList_JKSQSH.ToolButton6Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if Order_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if Order_Main.Locate('SSel;CWChkStatus',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('WFID').AsString)+'''');
          sql.Add(' and isnull(OAType,'''')=''借款申请'' and isnull(Chker,'''')='''+Trim(DName)+'''');
          ExecSQL;
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate Worker_Fee_Main Set ChkStatus=''审核不通过'',ChkTIme=getdate(),Chker='''+Trim(DName)+'''');
          sql.Add(',HZStatus=''审核不通过'',HZStatusTime=getdate(),ChkNote='''+Trim(Order_Main.fieldbyname('ChkNote').AsString)+'''');
          sql.Add(' where WFID='''+Trim(Order_Main.fieldbyname('WFID').AsString)+'''');
          ExecSQL;
        end;
        Order_Main.Delete;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Order_Main.EnableControls;
    initGrid();
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作失败!','提示',0);
  end;
end;

procedure TfrmWorkDeptFeeChkList_JKSQSH.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('WFID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,Order_Sub);
  SInitCDSData20(ADOQueryTemp,Order_Sub);
  EditNote.Text:=trim(Order_Main.fieldbyname('EditNote').AsString);
end;

procedure TfrmWorkDeptFeeChkList_JKSQSH.ToolButton8Click(Sender: TObject);
var FPrintFile,FYCLName,FpriceUnit,FZhaiYao: string;
begin
  if Order_Main.IsEmpty then exit;
  FYCLName:='';
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add(' select A.* ');
    SQL.Add(' from Worker_Fee_Main A ');
    sql.add(' where WFID='''+trim(Order_Main.fieldbyname('WFID').asstring)+''' ');
    open;
  end;
  SCreateCDS20(ADOQueryCmd,CDS_PRT);
  SInitCDSData20(ADOQueryCmd,CDS_PRT);
  With ADOQueryTemp do
  begin
    close;
    sql.Clear;
    sql.Add(' select A.* ');
    SQL.Add(' from Worker_Fee_Sub A ');
    sql.add(' where WFID='''+trim(Order_Main.fieldbyname('WFID').asstring)+''' ');
    open;
  end;
  with ADOQueryTemp do
  begin
    first;
    while not eof do
    begin
      if trim(FYCLName)='' then
      FYCLName:=trim(fieldbyname('YCLName').AsString)
      else
      FYCLName:=FYCLName+','+trim(fieldbyname('YCLName').AsString);
      next;
    end;
    FpriceUnit:=trim(fieldbyname('priceUnit').AsString);
    FZhaiYao:=trim(fieldbyname('ZhaiYao').AsString);
  end;

  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\费用报销单.rmf';
  if FileExists(fPrintFile) then
  begin
    RMVariables['YCLName']:=trim(CDS_PRT.fieldbyname('JKYongTu').AsString);
    RMVariables['priceUnit']:=trim(CDS_PRT.fieldbyname('priceUnit').AsString);
    RMVariables['ZhaiYao']:=trim(CDS_PRT.fieldbyname('Person1').AsString);
    RM1.LoadFromFile(fPrintFile);
    if Order_Main.FieldByName('HZStatus').AsString<>'审核通过' then
    begin
      RM1.PreviewButtons:=[pbZoom, pbFind, pbPageSetup,pbExit];
      RM1.ShowReport;
    end
    else
    RM1.ShowReport;
  end else
  begin
    Application.MessageBox('没有找到报表','提示',0);
    exit;
  end;
end;

end.
