unit U_WorkDeptFeeListBXSH;

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,jpeg, IdBaseComponent, IdComponent,
  IdTCPConnection, IdTCPClient, IdFTP,ShellAPI,IniFiles, BtnEdit;

type
  TfrmWorkDeptFeeListBXSH = 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;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column5: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Panel1: TPanel;
    Label1: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    v1WFDate: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    Worker: TEdit;
    Label6: TLabel;
    v1Column17: TcxGridDBColumn;
    ToolButton1: TToolButton;
    Label3: TLabel;
    XJLLFLAG: TEdit;
    Label4: TLabel;
    WFType: TEdit;
    ToolButton2: TToolButton;
    TSH: TToolButton;
    TCX: TToolButton;
    v1Column8: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    N1: TMenuItem;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    cxSplitter1: TcxSplitter;
    CDS_Chker: TClientDataSet;
    CDS_Chk: TClientDataSet;
    DS_Chk: TDataSource;
    v1ItemNameBX: TcxGridDBColumn;
    Label5: TLabel;
    ItemNameBX: TEdit;
    Label7: TLabel;
    PZType: TEdit;
    Label8: TLabel;
    INVNo: TEdit;
    TPrint: TToolButton;
    IdFTP1: TIdFTP;
    ODPat: TOpenDialog;
    SaveDialog1: TSaveDialog;
    v1WFNO: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    ToolButton4: TToolButton;
    Panel3: TPanel;
    Image1: TImage;
    cxStyle2: TcxStyle;
    v1WFType: TcxGridDBColumn;
    v1XJLLFLAG: 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 TSHClick(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure TCXClick(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure v1Column8PropertiesEditValueChanged(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure TPrintClick(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure Image1Click(Sender: TObject);
    procedure ReadINIFile();
  private
    FInt,PFInt:Integer;
    canshu1,canshu2:string;
    procedure InitGrid();
    procedure InitForm();
    function  DelData():Boolean;
    procedure InitGridWsql(fsj:string);
    function  SaveData():Boolean;
    procedure InitImage();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmWorkDeptFeeListBXSH: TfrmWorkDeptFeeListBXSH;

implementation
uses
  U_DataLink,U_RTFun,U_ModuleNote,U_WorkerDeptFeeInPut_BXDJ, U_ZDYHelpSel,
  U_ZDYHelp,U_FileUp_PZ;

{$R *.dfm}

procedure TfrmWorkDeptFeeListBXSH.ReadINIFile();
var
  programIni:Tinifile;  //配置文件名
  FileName:string;
begin
  FileName:=ExtractFilePath(Paramstr(0))+'SYSTEMSET.INI';
  programIni:=Tinifile.create(FileName);
  server:=programIni.ReadString('SERVER','服务器地址','127.0.0.1');
  programIni.Free;
end;

procedure TfrmWorkDeptFeeListBXSH.InitImage();
var
  jpg:TJpegImage;
  myStream:TADOBlobStream;
begin
  if Order_Main.IsEmpty then Exit;
  if Trim(Order_Main.fieldbyname('WFNO').AsString)='' then Exit;
  //if cxPageControl1.ActivePageIndex=6 then
  begin
    Image1.Picture.Assign(nil);
    try
      with ADOQueryTemp do
      begin
        close;
        sql.Clear;
        sql.Add(' select * from TP_File A where A.WBID='''+Trim(Order_Main.fieldbyname('WFNO').AsString)+'''');
        sql.Add(' and TFType=''凭证'' ');
        open;
        if RecordCount>0 then
        begin
          if trim(ADOQueryTemp.fieldbyname('FilesOther').AsString)<>'' then
          begin
            myStream:=tadoblobstream.Create(tblobfield(ADOQueryTemp.fieldbyname('FilesOther')),bmread);
            if myStream=nil then exit;
            jpg:=TJPEGImage.Create;
            jpg.LoadFromStream(myStream);
            Image1.Picture.Assign(jpg);
          end;
        end;
      end;
    finally
      jpg.Free;
      myStream.Free;
    end;
  end;
end;

procedure TfrmWorkDeptFeeListBXSH.FormDestroy(Sender: TObject);
begin
  frmWorkDeptFeeListBXSH:=nil;
end;

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

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

procedure TfrmWorkDeptFeeListBXSH.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select distinct A.*,B.Mainid,B.CKID,B.Chker,isnull(C.FKStatus,'''') FKStatus,C.XJLLFLAG');
      SQL.Add(' from Worker_Fee_LKMain A ');
      sql.add(' inner join Worker_Fee_LKSub C on C.WFID=A.WFID');
      sql.add(' inner join OA_Chk B on B.Mainid=C.WFID and B.OAType=''费用报销''');
      sql.Add(' where B.Chker='''+trim(DName)+''' 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(B.Chkstatus,'''')='''' or isnull(B.Chkstatus,'''')=''单据修改'')');
        sql.add(' and isnull(C.MStatus,'''')<>''审核不通过''');
      end;
      if cxTabControl1.TabIndex=1 then
      begin
        sql.Add(' and isnull(B.Chkstatus,'''')=''审核通过'' ');
      end;
      if cxTabControl1.TabIndex=2 then
      begin
        sql.Add(' and isnull(C.MStatus,'''')=''审核通过'' ');
      end;
      if cxTabControl1.TabIndex=3 then
      begin
        sql.Add(' and isnull(C.MStatus,'''')=''审核不通过'' ');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from OA_Chk where 1=2');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_Chk);
    SInitCDSData20(ADOQueryTemp,CDS_Chk);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmWorkDeptFeeListBXSH.InitForm();
begin
  endDate.Date:=SGetServerDate(ADOQueryTemp);
  BegDate.Date:=EndDate.Date-7;
  cxTabControl1.TabIndex:=0;
  TSH.Visible:=False;
  if cxtabControl1.TabIndex=0 then
  begin
    TSH.Visible:=true;
  end;
  if cxtabControl1.TabIndex=1 then
  begin
  end;
  InitGrid();
  InitImage();
end;

function TfrmWorkDeptFeeListBXSH.DelData():Boolean;
begin
  try
    Result:=false;
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin
      First;
      while Locate('SSel',True,[]) do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('delete Worker_Fee_LKMain  where WFId='''+Trim(Order_Main.fieldbyname('WFId').AsString)+'''');
          sql.Add('delete Worker_Fee_LKSub  where WFId='''+Trim(Order_Main.fieldbyname('WFId').AsString)+'''');
          ExecSQL;
        end;
        Delete;
      end;
    end;
    Order_Main.EnableControls;

    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Result:=False;
    Application.MessageBox('数据删除异常！','提示',0);
  end;
end;

procedure TfrmWorkDeptFeeListBXSH.TBRafreshClick(Sender: TObject);
begin
  ToolBar1.SetFocus;
  InitGrid();
end;

procedure TfrmWorkDeptFeeListBXSH.FormShow(Sender: TObject);
begin
  ReadCxGrid('费用报销列表1',Tv1,'费用管理');
  InitForm();
end;

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

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

procedure TfrmWorkDeptFeeListBXSH.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 TfrmWorkDeptFeeListBXSH.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 TfrmWorkDeptFeeListBXSH.cxTabControl1Change(Sender: TObject);
begin
  TSH.Visible:=False;
  if cxtabControl1.TabIndex=0 then
  begin
    TSH.Visible:=true;
  end;
  if cxtabControl1.TabIndex=1 then
  begin

  end;
  if cxtabControl1.TabIndex=3 then
  begin
    TSH.Visible:=true;
  end;
  InitGrid();
end;

procedure TfrmWorkDeptFeeListBXSH.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 TfrmWorkDeptFeeListBXSH.ToolButton1Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  try
    frmWorkerDeptFeeInPut_BXDJ:=TfrmWorkerDeptFeeInPut_BXDJ.Create(Application);
    with frmWorkerDeptFeeInPut_BXDJ do
    begin
      PState:=1;
      FMainId:=Trim(Self.Order_Main.fieldbyname('WFID').AsString);
      TBSave.Visible:=False;
      ToolBar2.Visible:=False;
      if ShowModal=1 then
      begin
        initGrid();
      end;
    end;
  finally
    frmWorkerDeptFeeInPut_BXDJ.Free;
  end;
end;

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

procedure TfrmWorkDeptFeeListBXSH.TSHClick(Sender: TObject);
var
  maxno,FCKID:string;
  FCount:Integer;
  FWFID:string;
begin
  if Order_Main.IsEmpty then exit;
  if cxtabControl1.TabIndex<>0 then exit;
  toolbar1.SetFocus;
  if order_Main.Locate('Ssel',true,[])=False then
  begin
    application.MessageBox('没有选择数据','提示');
    exit;
  end;
  FWFID:=Trim(Order_Main.fieldbyname('WFID').AsString);
  try
    with Order_Main do
    begin
      first;
      while not eof do
      begin
        if FieldByName('Ssel').AsBoolean=true then
        begin
          if trim(Canshu1)='高权限' then
          begin
            with ADOQueryCmd do
            begin
              Close;
              SQL.Clear;
              sql.Add('Update OA_Chk Set ');
              sql.Add('ChkTime=getdate(),Chkstatus=''审核通过'' ');
              sql.Add('where Mainid='''+trim(Order_Main.fieldbyname('WFID').AsString)+''' ');
              sql.add('and OAType=''费用报销''');
              ExecSQL;
            end;
          end
          else
          begin
            with ADOQueryCmd do
            begin
              Close;
              SQL.Clear;
              sql.Add('Update OA_Chk Set ');
              sql.Add(' ChkTime=getdate(),Chkstatus=''审核通过'' ');
              sql.Add(' where CKID='''+trim(Order_Main.fieldbyname('CKID').AsString)+''' ');
              ExecSQL;
            end;
          end;
          if cxtabControl1.TabIndex=3 then
          begin
            with ADOQueryMain do
            begin
              close;
              sql.Clear;
              sql.add('update Worker_Fee_LKSub set ');
              sql.add('MStatus=''已送审'' ');
              sql.Add(' where WFID='''+trim(Order_Main.fieldbyname('WFID').AsString)+'''');
              execsql;
            end;
          end;
          with ADOQueryCmd do
          begin
            close;
            sql.clear;
            sql.add('select A.* from OA_Chk A ');
            sql.add('where A.Mainid='''+trim(Order_Main.fieldbyname('WFID').AsString)+''' ');
            sql.add('and isnull(A.Chkstatus,'''')<>''审核通过'' ');
            sql.add('and isnull(A.OAType,'''')=''费用报销''');
            open;
          end;
          if ADOQueryCmd.IsEmpty then
          begin
            with ADOQueryMain do
            begin
              close;
              sql.Clear;
              sql.add('update Worker_Fee_LKSub set ');
              sql.add('MStatus=''审核通过'' ');
              sql.Add(' where WFID='''+trim(Order_Main.fieldbyname('WFID').AsString)+'''');
              execsql;
            end;
          end;
        end;
        next;
      end;
    end;
    application.MessageBox('审核成功','提示');
    initGrid();
  except;
    application.MessageBox('审核失败','提示');
    exit;
  end;
end;

procedure TfrmWorkDeptFeeListBXSH.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Main,True);  
end;

procedure TfrmWorkDeptFeeListBXSH.N1Click(Sender: TObject);
begin
  SelOKNo(Order_Main,False);  
end;

procedure TfrmWorkDeptFeeListBXSH.TCXClick(Sender: TObject);
var FWFID:string;
begin
  if Order_Main.IsEmpty then Exit;
  toolbar1.SetFocus;
  FWFID:=Trim(Order_Main.fieldbyname('WFID').asstring);
  if order_main.Locate('Ssel',True,[])=false then
  begin
    application.MessageBox('没有选择数据','提示');
    exit;
  end;
  if Application.MessageBox('确定要执行撤销操作吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableConstraints;
    with Order_Main do
    begin
      First;
      while not eof do
      begin
        if FieldByName('Ssel').AsBoolean=true then
        begin
          if trim(Order_Main.FieldByName('FKStatus').AsString)='已付款' then
          begin
            Order_Main.EnableConstraints;
            application.MessageBox('已核销不能审核','提示');
            exit;
          end;
          with ADOQueryCmd do
          begin
            Close;
            SQL.Clear;
            sql.Add('Update Worker_Fee_LKSub Set MStatus=''审核不通过'',XJLLFLAG=''''');
            sql.Add(' where WFID='''+trim(Order_Main.fieldbyname('WFID').AsString)+'''');
            ExecSQL;
          end;
          with ADOQueryCmd do
          begin
            Close;
            SQL.Clear;
            sql.Add('update OA_Chk set ChkStatus=''审核不通过''');
            sql.Add(' where CKID='''+trim(Order_Main.fieldbyname('CKID').AsString)+'''');
            sql.Add(' and isnull(OAType,'''')=''费用报销'' ');
            ExecSQL;
          end;
        end;
        next;
      end;
    end;
    initGrid();
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

procedure TfrmWorkDeptFeeListBXSH.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 where MainId='''+Trim(Order_Main.fieldbyname('WFID').AsString)+'''');
    sql.Add(' and OAType=''费用报销'' ');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_Chk);
  SInitCDSData20(ADOQueryTemp,CDS_Chk);
  InitImage();
end;

procedure TfrmWorkDeptFeeListBXSH.v1Column8PropertiesEditValueChanged(
  Sender: TObject);
var FMoney,FWFID: string;
begin
  FMoney:='0';
  FWFID:=Trim(Order_Main.fieldbyname('WSID').AsString);
  with Order_Main do
  begin
    first;
    DisableControls;
    while not eof do
    begin
      if FieldByName('Ssel').AsBoolean=True then
      begin
        FMoney:=floattoStr(strtofloat(FMoney)+FieldByName('Money').AsFloat);
      end;

      next;
    end;
    EnableControls;
  end;
  order_main.Locate('WSID',FWFID,[]);
end;

procedure TfrmWorkDeptFeeListBXSH.Tv1DblClick(Sender: TObject);
begin
  ToolButton1.Click;
end;

procedure TfrmWorkDeptFeeListBXSH.TPrintClick(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_LKMain 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_LKSub 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(FYCLName);
    RMVariables['priceUnit']:=trim(FpriceUnit);
    RMVariables['ZhaiYao']:=trim(FZhaiYao);
    RM1.LoadFromFile(fPrintFile);
    RM1.PreviewButtons:=[pbZoom, pbFind, pbPageSetup,pbExit];
    RM1.ShowReport;
  end else
  begin
    Application.MessageBox('没有找到报表','提示',0);
    exit;
  end;
end;

procedure TfrmWorkDeptFeeListBXSH.ToolButton4Click(Sender: TObject);
begin
  try
    frmFileUpPZ:=TfrmFileUpPZ.Create(Application);
    with frmFileUpPZ do
    begin
      Code.Text:=Trim(Self.Order_Main.fieldbyname('WFNO').AsString);
      CYID:=Trim(Self.Order_Main.fieldbyname('WFNO').AsString);
      if ShowModal=1 then
      begin
        Self.InitGrid();
        Self.Order_Main.Locate('WFNO',CYID,[]);
      end;
    end;
  finally
    frmFileUpPZ.Free;
  end;
end;

procedure TfrmWorkDeptFeeListBXSH.Image1Click(Sender: TObject);
var
  fHandle:THandle;
  FInt:Integer;
  FFName,FPath:String;
begin
  if Order_Main.IsEmpty then exit;
  with ADOQueryTemp do
  begin
    close;
    sql.Clear;
    sql.Add('select * from XD_File where CYNO='''+Trim(Order_Main.fieldbyname('WFNO').AsString)+'''');
    Open;
    if IsEmpty then
    begin
      Application.MessageBox('凭证图片未上传！','提示',0);
      Exit;
    end;
  end;
  try
    ReadINIFile();
    server:=ReadINIFileStr('SYSTEMSET.INI','SERVER','服务器地址','127.0.0.1');
    if Length(server)<6 then
    begin
      server:='127.0.0.1';
    end;
    IdFTP1.Host :=server;//PicSvr;
    IdFTP1.Username := 'three';
    IdFTP1.Password := '641010';
    IdFTP1.Connect();
  except
    IdFTP1.Quit;
    Application.MessageBox('无法连接到文件服务器，请检查！', '提示', MB_ICONWARNING);
    Exit;
  end;
  FPath:='D:\Right1209\';
  if not DirectoryExists(ExtractFileDir(FPath)) then
    CreateDir(ExtractFileDir(FPath));
  FFName:=Trim(ADOQueryTemp.fieldbyname('FileName').AsString);
  FFName:=FPath+FFName;
  if FileExists(FFName) then
  begin
    FInt:=1;
  end;
  if FInt<>1 then
    IdFTP1.Get('PZ\'+Trim(ADOQueryTemp.fieldbyname('FileName').AsString),
                   FPath+Trim(ADOQueryTemp.fieldbyname('FileName').AsString));
  if IdFTP1.Connected then IdFTP1.Quit;
  ShellExecute(Handle, 'open',PChar(FPath+Trim(ADOQueryTemp.fieldbyname('FileName').AsString)),'', '', SW_SHOWNORMAL);

end;

end.
