unit U_WorkDeptFeeList_YGXYSCX;

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
  TfrmWorkDeptFeeList_YGXYSCX = 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;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    v1CWChkStatus: 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;
    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;
    Label2: TLabel;
    v1FSDate: TcxGridDBColumn;
    v1Person4: TcxGridDBColumn;
    TFK: TToolButton;
    TCXFK: TToolButton;
    v1ChkNote: TcxGridDBColumn;
    cxTabControl1: TcxTabControl;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure WorkerChange(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure TFKClick(Sender: TObject);
    procedure TCXFKClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
  private
    FInt,PFInt:Integer;
    canshu1,canshu2:string;
    procedure InitGrid();
    procedure InitForm();
    procedure setstatus();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmWorkDeptFeeList_YGXYSCX: TfrmWorkDeptFeeList_YGXYSCX;

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

{$R *.dfm}
procedure TfrmWorkDeptFeeList_YGXYSCX.setstatus();
begin
  TFK.Visible:=False;
  TCXFK.Visible:=False;
  v1ChkNote.Options.Editing:=False;
  if canshu1<>'高权限' then
  begin
    if cxTabCOntrol1.TabIndex=0 then
    begin
      TFK.Visible:=true;
      v1ChkNote.Options.Editing:=True;
    end;
    if cxTabCOntrol1.TabIndex=1 then
    begin
      TCXFK.Visible:=True;;
    end;
  end
  else
  begin
    cxTabCOntrol1.Visible:=False;
  end;
end;

procedure TfrmWorkDeptFeeList_YGXYSCX.FormDestroy(Sender: TObject);
begin
  frmWorkDeptFeeList_YGXYSCX:=nil;
end;

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

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

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

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

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

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

procedure TfrmWorkDeptFeeList_YGXYSCX.FormCreate(Sender: TObject);
begin
  canshu1:=Trim(DParameters1);
end;

procedure TfrmWorkDeptFeeList_YGXYSCX.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_YGXYSCX.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_YGXYSCX.Tv1DblClick(Sender: TObject);
begin
  ToolButton1.Click;
end;

procedure TfrmWorkDeptFeeList_YGXYSCX.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_YGXYSCX.TFKClick(Sender: TObject);
var maxno: string;
begin
  ToolBar1.SetFocus;
  if Order_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>0 then Exit;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryMain do
  begin
    close;
    sql.Clear;
    sql.add('update Worker_Fee_Main set CWChkStatus=''已付款'',CWChker='''+trim(DName)+''',CWChktime=getDate() ');
    sql.add(',ChkNote='''+trim(Order_Main.fieldbyname('ChkNote').AsString)+''' ');
    sql.add('where WFID='''+trim(Order_Main.fieldbyname('WFID').AsString)+'''');
    execsql;
  end;
  TBRafresh.Click;
end;

procedure TfrmWorkDeptFeeList_YGXYSCX.TCXFKClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if Application.MessageBox('确定要撤销吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.add('update Worker_Fee_Main set CWChkStatus='''',CWChker='''',CWChktime=NULL ');
    //sql.add(',ChkNote='''' ');
    sql.add('where WFID='''+Order_Main.fieldbyname('WFID').AsString+'''');
    execsql;
  end;
  initGrid();
end;

procedure TfrmWorkDeptFeeList_YGXYSCX.cxTabControl1Change(Sender: TObject);
begin
  setstatus();
  InitGrid();
end;

end.
