unit U_WorkDeptFeeList_YGXYS;

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

type
  TfrmWorkDeptFeeList_YGXYS = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBDel: 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;
    cxGrid1Level1: TcxGridLevel;
    v1Column3: TcxGridDBColumn;
    Panel1: TPanel;
    Label1: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    v1Column7: TcxGridDBColumn;
    Worker: TEdit;
    Label6: TLabel;
    v1Column17: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    ToolButton1: TToolButton;
    Label4: TLabel;
    PerSon1: TEdit;
    ToolButton2: TToolButton;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    v1Column8: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    N1: TMenuItem;
    CDS_Chker: TClientDataSet;
    CDS_Chk: TClientDataSet;
    DS_Chk: TDataSource;
    Label7: TLabel;
    Person4: TEdit;
    v1Note: TcxGridDBColumn;
    v1PerSon1: TcxGridDBColumn;
    v1HZMoney: TcxGridDBColumn;
    v1FSDate: TcxGridDBColumn;
    v1Person4: TcxGridDBColumn;
    Label9: TLabel;
    EditNote: TMemo;
    v1EditSQTime: TcxGridDBColumn;
    v1EditNote: TcxGridDBColumn;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    TEditSQ: TToolButton;
    TPrint: TToolButton;
    Panel4: TPanel;
    Label3: TLabel;
    Panel5: TPanel;
    Image1: TImage;
    RadioGroup2: TRadioGroup;
    TSure: TButton;
    ETaiTou: TEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBAddClick(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 ToolButton4Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure TEditSQClick(Sender: TObject);
    procedure TPrintClick(Sender: TObject);
    procedure Image1Click(Sender: TObject);
    procedure TSureClick(Sender: TObject);
  private
    FInt,PFInt:Integer;
    canshu1,canshu2:string;
    procedure InitGrid();
    procedure InitForm();
    function  DelData():Boolean;
    procedure InitGridWsql(fsj:string);
    function  SaveData():Boolean;
    procedure setstatus();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmWorkDeptFeeList_YGXYS: TfrmWorkDeptFeeList_YGXYS;

implementation
uses
  U_DataLink,U_RTFun,U_ModuleNote,U_WorkerDeptFeeInPut_XYS, U_ZDYHelpSel,
  U_ZDYHelp,U_WorkerDeptFeeInPut_JKSQ;

{$R *.dfm}
procedure TfrmWorkDeptFeeList_YGXYS.setstatus();
begin
  TBAdd.Visible:=False;
  TBEdit.Visible:=False;
  TBDel.Visible:=False;
  Toolbutton4.Visible:=False;
  Toolbutton5.Visible:=False;
    case cxTabControl1.TabIndex of
      0:begin
          TBAdd.Visible:=True;
          TBEdit.Visible:=True;
          TBDel.Visible:=True;
          ToolButton4.Visible:=True;
        end;
      1:begin
          ToolButton5.Visible:=True;
        end;
      2:begin

        end;
      3:begin
         
        end;
      4:begin

        end;
    end;
end;

procedure TfrmWorkDeptFeeList_YGXYS.FormDestroy(Sender: TObject);
begin
  frmWorkDeptFeeList_YGXYS:=nil;
end;

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

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

procedure TfrmWorkDeptFeeList_YGXYS.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.* ');
      SQL.Add(' from Worker_Fee_Main A ');
      sql.Add(' where A.ItemName=''借款申请单'' ');
      if cxTabControl1.TabIndex<>0 then
      begin
        sql.add(' and A.filltime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
        sql.Add(' and A.filltime<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1))+'''');
      end;
      if cxTabControl1.TabIndex=0 then
      begin
        sql.Add(' and (isnull(A.HZStatus,'''')=''待送审'' or isnull(A.HZStatus,'''')=''审核不通过'')');
      end;
      if cxTabControl1.TabIndex=1 then
      begin
        sql.Add(' and isnull(A.HZStatus,'''')<>''待送审'' and isnull(A.HZStatus,'''')<>''审核不通过'' and isnull(A.ZuoFeiFlag,'''')<>''1'' ');
      end;
      if canshu1<>'高权限' then
      begin
        sql.Add(' and A.FillCode='''+trim(DCode)+'''');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

procedure TfrmWorkDeptFeeList_YGXYS.TBEditClick(Sender: TObject);
begin
  if cxTabControl1.TabIndex<>0 then Exit;
  if Order_Main.IsEmpty then Exit;
  if Trim(DCode)<>Trim(Order_Main.fieldbyname('FillCode').AsString) then
  begin
    Application.MessageBox('不能操作他人的信息!','提示',0);
    Exit;
  end;
  try
    frmWorkerDeptFeeInPut_JKSQ:=TfrmWorkerDeptFeeInPut_JKSQ.Create(Application);
    with frmWorkerDeptFeeInPut_JKSQ do
    begin
      PState:=1;
      FMainId:=Trim(Self.Order_Main.fieldbyname('WFID').AsString);
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmWorkerDeptFeeInPut_JKSQ.Free;
  end;
end;

procedure TfrmWorkDeptFeeList_YGXYS.TBDelClick(Sender: TObject);
begin
  if cxTabControl1.TabIndex<>0 then Exit;
  if Order_Main.IsEmpty then Exit;
  if Trim(DCode)<>Trim(Order_Main.fieldbyname('FillCode').AsString) then
  begin
    Application.MessageBox('不能操作他人的信息!','提示',0);
    Exit;
  end;
  if Order_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  if DelData() then
  begin
    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);
  end;
end;

function TfrmWorkDeptFeeList_YGXYS.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_Main  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 TfrmWorkDeptFeeList_YGXYS.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmWorkDeptFeeList_YGXYS.TBAddClick(Sender: TObject);
begin
  try
    frmWorkerDeptFeeInPut_XYS:=TfrmWorkerDeptFeeInPut_XYS.Create(Application);
    with frmWorkerDeptFeeInPut_XYS do
    begin
      if ShowModal=1 then
      begin
        initGrid();
      end;
    end;
  finally
    frmWorkerDeptFeeInPut_XYS.Free;
  end;
end;

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

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

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

procedure TfrmWorkDeptFeeList_YGXYS.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 TfrmWorkDeptFeeList_YGXYS.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 TfrmWorkDeptFeeList_YGXYS.cxTabControl1Change(Sender: TObject);
begin
  setstatus();
  InitGrid();
end;

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

      end;
    end;
  finally
    frmWorkerDeptFeeInPut_JKSQ.Free;
  end;

end;

procedure TfrmWorkDeptFeeList_YGXYS.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 TfrmWorkDeptFeeList_YGXYS.ToolButton4Click(Sender: TObject);
var
  maxno,FCKID:string;
  FCount:Integer;
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;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select Chker=Cast('''' as varchar(20))');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_Chker);
  SInitCDSData20(ADOQueryTemp,CDS_Chker);
  while CDS_Chker.IsEmpty=False do
  begin
    CDS_Chker.Delete;
  end;
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:='OAChker';
      flagname:='OA审核人';
      MainType:=Trim(DName);
      if ShowModal=1 then
      begin
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSEl').AsBoolean=True then
            begin
              CDS_Chker.Append;
              CDS_Chker.FieldByName('Chker').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
              CDS_Chker.Post;
            end;
            Next;
          end;
        end;
        if CDS_Chker.IsEmpty then FCount:=9
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
  if FCount=9 then
  begin
    if CDS_Chker.IsEmpty then
    begin
      Application.MessageBox('没有选择审核人!','提示',0);
      Exit;
    end;
  end;
  
  if CDS_Chker.IsEmpty then Exit;
  CDS_Chker.DisableControls;
  with CDS_Chker do
  begin
    First;
    while not eof do
    begin
      with ADOQueryTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select * from SY_User where UserName='''+Trim(CDS_Chker.fieldbyname('Chker').AsString)+'''');
        Open;
      end;
      if ADOQueryTemp.IsEmpty then
      begin
        CDS_Chker.EnableControls;
        Application.MessageBox('审核人定义错误!','提示',0);
        Exit;
      end;
      Next;
    end;
  end;
  CDS_Chker.EnableControls;

  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin
      First;
      while Order_Main.Locate('SSel',True,[]) do
      begin
        with ADOQueryCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('Update Worker_Fee_Main Set ');
          sql.Add(' SChker='''+Trim(DName)+''',SChkTime=getdate(),HZStatus=''已送审'',HZStatusTime=getdate()');
          sql.Add(' where WFID='''+Order_Main.fieldbyname('WFID').AsString+'''');
          ExecSQL;
        end;
        with CDS_Chker do
        begin
          CDS_Chker.First;
          while not CDS_Chker.Eof do
          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 isnull(OAType,'''')=''借款申请'' ');
              sql.Add(' and isnull(Chker,'''')='''+Trim(CDS_Chker.fieldbyname('Chker').AsString)+'''');
              Open;
            end;
            FCKID:=Trim(ADOQueryTemp.fieldbyname('CKID').AsString);
            ADOQueryTemp.Close;
            if Trim(FCKID)='' then
            begin
              if GetLSNo(ADOQueryCmd,maxno,'CK','OA_Chk',4,1)=False then
              begin
                ADOQueryCmd.Connection.RollbackTrans;
                Application.MessageBox('取最大号失败!','提示',0);
                Exit;
              end;
              with ADOQueryCmd do
              begin
                Close;
                sql.Clear;
                sql.Add('select * from OA_Chk where 1=2');
                Open;
              end;
              with ADOQueryCmd do
              begin
                Append;
                FieldByName('CKID').Value:=Trim(maxno);
                FieldByName('MainID').Value:=Trim(Order_Main.fieldbyname('WFID').AsString);
                FieldByName('OAType').Value:='借款申请';
                FieldByName('Chker').Value:=Trim(CDS_Chker.fieldbyname('Chker').AsString);
                Post;
              end;
            end;
            CDS_Chker.Next;
          end;
        end;
        Order_Main.Delete;
      end;
    end;
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    Exit;
  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

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

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

procedure TfrmWorkDeptFeeList_YGXYS.ToolButton5Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>1 then
  begin
    if cxTabControl1.TabIndex<>4 then exit;
  end;
  if Order_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  Order_Main.DisableControls;
  with Order_Main do
  begin
    First;
    while not Eof do
    begin
      if Order_Main.FieldByName('SSel').AsBoolean=True then
      begin
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add(' select * from Worker_Fee_Main where WFID='''+Trim(Order_Main.fieldbyname('WFID').AsString)+'''');
          sql.Add(' and (isnull(HZStatus,'''')=''已送审'' or isnull(HZStatus,'''')=''审核不通过'') ');
          Open;
        end;
        if ADOQueryTemp.IsEmpty then
        begin
          Order_Main.EnableControls;
          Application.MessageBox('已审核，不能撤销!','提示',0);
          Exit;
        end;
      end;
      Next;
    end;
  end;

  Order_Main.EnableControls;
  if Application.MessageBox('确定要执行撤销操作吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin
      First;
      while Order_Main.Locate('SSel',True,[]) do
      begin
        with ADOQueryCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('Update Worker_Fee_Main Set ');
          sql.Add(' SChker=NUll,SChkTime=NUll,HZStatus=''待送审'',HZStatusTime=NUll');
          sql.Add(' where WFID='''+Order_Main.fieldbyname('WFID').AsString+'''');
          sql.Add(' delete OA_Chk where MainId='''+Trim(Order_Main.fieldbyname('WFID').AsString)+'''');
          sql.Add(' and isnull(OAType,'''')=''借款申请'' ');
          ExecSQL;
        end;
        Order_Main.Delete;
      end;
    end;
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

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

procedure TfrmWorkDeptFeeList_YGXYS.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);
  EditNote.Text:=trim(Order_Main.fieldbyname('EditNote').AsString);
end;

procedure TfrmWorkDeptFeeList_YGXYS.TEditSQClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  if EditNote.Text='' then
  begin
    application.MessageBox('修改原因不能为空','提示');
    exit;
  end;
  frmZDYHelpSel:=TfrmZDYHelpSel.Create(self);
  with frmZDYHelpSel do
  begin
    flag:='OAChker';
    flagname:='OA审核人';
    MainType:=Trim(DName);
    if showModal=1 then
    begin
      with ClientDataSet1 do
      begin
        first;
        while not eof do
        begin
          if fieldbyname('Ssel').AsBoolean=true then
          begin
            if CDS_Chk.Locate('Chker',Trim(fieldbyname('ZdyName').AsString),[])=False then
            begin
              application.MessageBox('没有该合同的审核人','提示');
              exit;
            end;
            with ADOQueryTemp do
            begin
              Close;
              sql.Clear;
              sql.Add('Update OA_Chk Set ChkStatus=''单据修改'',chknote='''',ChkTime=getdate()');
              sql.Add(' where Mainid='''+Trim(Order_Main.fieldbyname('WFID').AsString)+'''');
              sql.Add(' and Chker='''+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
              sql.Add(' and isnull(OAType,'''')=''借款申请'' ');
              ExecSQL;
            end;
          end;
          next;
        end;
      end;
    end;
    free;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update Worker_Fee_Main Set EditNote='''+Trim(EditNote.Text)+'''');
    sql.Add(',HZStatus=''单据修改'',EditFlag=''1'',EditSQTime=getDate()');
    sql.Add(' where WFID='''+Trim(Order_Main.fieldbyname('WFID').AsString)+'''');
    ExecSQL;
  end;
  with Order_Main do
  begin
    Edit;
    fieldbyname('HZStatus').Value:='单据修改';
    FieldByName('EditNote').Value:=Trim(EditNote.Text);
    fieldbyname('EditSQTime').Value:=SGetServerDate10(ADOQueryTemp);
    Post;
  end;
  EditNote.Text:='';
end;

procedure TfrmWorkDeptFeeList_YGXYS.TPrintClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  panel4.Visible:=true;
end;

procedure TfrmWorkDeptFeeList_YGXYS.Image1Click(Sender: TObject);
begin
  panel4.Visible:=False;
end;

procedure TfrmWorkDeptFeeList_YGXYS.TSureClick(Sender: TObject);
var FPrintFile,FYCLName,FpriceUnit,FZhaiYao: string;
begin
  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);
  if RadioGroup2.ItemIndex=0 then
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\员工借款协议.rmf';
  if RadioGroup2.ItemIndex=1 then
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\借条.rmf';
  if FileExists(fPrintFile) then
  begin
    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.
