unit U_GRYearPFList_YGXZFF;

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


type
  TfrmGRYearPFList_YGXZFF = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    CDS_PRT: TClientDataSet;
    Panel1: TPanel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Label1: TLabel;
    ToolButton1: TToolButton;
    ADOQueryPrint: TADOQuery;
    TBAdd: TToolButton;
    TBDel: TToolButton;
    Source1: TDataSource;
    Order_Sub: TClientDataSet;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    cxStyle3: TcxStyle;
    TSsel: TToolButton;
    TUpdate: TToolButton;
    TCHk: TToolButton;
    TCXChk: TToolButton;
    cxTabControl1: TcxTabControl;
    Label3: TLabel;
    YGName: TEdit;
    Label5: TLabel;
    Label6: TLabel;
    TTJ: TToolButton;
    TCXTJ: TToolButton;
    FKType: TComboBox;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    N1: TMenuItem;
    cxTabControl2: TcxTabControl;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Ssel: TcxGridDBColumn;
    v1FFDate: TcxGridDBColumn;
    v1XHNo: TcxGridDBColumn;
    v1YGName: TcxGridDBColumn;
    v1GZMoney: TcxGridDBColumn;
    v1KQJMoney: TcxGridDBColumn;
    v1KSBMoney: TcxGridDBColumn;
    v1KOtherMoney: TcxGridDBColumn;
    v1DXGZMoney: TcxGridDBColumn;
    v1GLFLMoney: TcxGridDBColumn;
    v1KGSMoney: TcxGridDBColumn;
    v1KFKMeny: TcxGridDBColumn;
    v1CJBGZMoney: TcxGridDBColumn;
    v1KCDMoney: TcxGridDBColumn;
    v1JKMoney: TcxGridDBColumn;
    v1FFMoney: TcxGridDBColumn;
    v1JLMoney: TcxGridDBColumn;
    v1FKSYSTEM: TcxGridDBColumn;
    v1FKType: TcxGridDBColumn;
    v1XZNote: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure TSselClick(Sender: TObject);
    procedure TUpdateClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure TCHkClick(Sender: TObject);
    procedure TCXChkClick(Sender: TObject);
    procedure YGNameChange(Sender: TObject);
    procedure TTJClick(Sender: TObject);
    procedure cxTabControl2Change(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure TCXTJClick(Sender: TObject);

  private
    FInt,PFInt:Integer;
    canshu1,canshu2:string;
    FNowDate:TDateTime;
    procedure InitGrid();
    procedure InitForm();
    procedure setstatus();
    { Private declarations }
  public
    Ftype:string;
    { Public declarations }
  end;

var
  frmGRYearPFList_YGXZFF: TfrmGRYearPFList_YGXZFF;

implementation
uses
  U_DataLink,U_RTFun,U_KDInPut,U_ModuleNote, U_ZDYHelp,U_GRYearPFList_Sub,
  U_ZDYHelpSel,U_YGYPInPut_YGXZDJ;

{$R *.dfm}
procedure TfrmGRYearPFList_YGXZFF.setstatus();
begin
  TBAdd.Visible:=False;
  TUpdate.Visible:=False;
  TBDel.Visible:=False;
  TChk.Visible:=False;
  TCXChk.Visible:=False;
  case cxTabControl1.TabIndex of
      0:begin
        TChk.Visible:=True;
      end;
      1:begin
        TCXChk.Visible:=True;
      end;
      2:begin
      end;
  end;
end;

procedure TfrmGRYearPFList_YGXZFF.FormDestroy(Sender: TObject);
begin
  frmGRYearPFList_YGXZFF:=nil;
end;

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

procedure TfrmGRYearPFList_YGXZFF.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('员工工资登记32',Tv1,'分红管理');
end;

procedure TfrmGRYearPFList_YGXZFF.InitGrid();
begin
  with ADOQueryTemp do
  begin
    close;
    sql.Clear;
    sql.Add('select A.*,B.* from OA_YG_XZFF_Main A ');
    sql.add('inner join OA_YG_XZFF B on B.XZMain=A.XZMain ');
    sql.add('where A.filltime>='''+trim(formatdatetime('yyyy-MM-dd',begdate.DateTime))+''' ');
    sql.add('and A.filltime<'''+trim(formatdatetime('yyyy-MM-dd',Enddate.dateTime+1))+''' ');
    if cxTabControl1.TabIndex=0 then
    begin
      sql.add('and isnull(B.ChkStatus,'''')=''待审核'' ');
    end;
    if cxTabControl1.TabIndex=1 then
    begin
      sql.add('and isnull(B.ChkStatus,'''')=''已审核'' ');
    end;
    if cxtabControl2.TabIndex=0 then
    begin
      sql.add('and B.FKSYSTEM=''云翔'' ');
    end;
    if cxtabControl2.TabIndex=1 then
    begin
      sql.add('and B.FKSYSTEM=''宇昊'' ');
    end;
    if cxtabControl2.TabIndex=2 then
    begin
      sql.add('and B.FKSYSTEM=''若凡'' ');
    end;
    if cxtabControl2.TabIndex=3 then
    begin
      sql.add('and B.FKSYSTEM=''昕绅'' ');
    end;
    sql.add('Order By A.SSYear,A.SSMonth,B.XHNo');
    open;
  end;
  SCreateCDS20(ADOQueryTemp,Order_Main);
  SInitCDSData20(ADOQueryTemp,Order_Main);
end;

procedure TfrmGRYearPFList_YGXZFF.InitForm();
begin
  EndDate.Date:=SGetServerDate(ADOQueryTemp);
  BegDate.Date:=SGetServerDate(ADOQueryTemp)-30;
  ReadCxGrid('员工工资登记32',Tv1,'分红管理');
  setstatus();
  InitGrid();
end;

procedure TfrmGRYearPFList_YGXZFF.TBExportClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  TcxGridToExcel('员工工资',cxGrid1);
end;

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

procedure TfrmGRYearPFList_YGXZFF.FormShow(Sender: TObject);
var
  i:Integer;
begin
  InitForm();
end;

procedure TfrmGRYearPFList_YGXZFF.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryTemp.Active=False then Exit;
  SDofilter(ADOQueryTemp,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryTemp,Order_Main);
  SInitCDSData20(ADOQueryTemp,Order_Main);
end;

procedure TfrmGRYearPFList_YGXZFF.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  if Order_Main.Locate('Ssel',true,[])=False then
  begin
    application.MessageBox('没有选择数据','提示');
    exit;
  end;
  if application.MessageBox('确定要删除吗','提示',1)=2 then exit;
  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('delete from OA_YG_XZFF ');
          sql.add('where XZID='''+trim(Order_Main.fieldbyname('XZID').AsString)+'''');
          execsql;
        end;
      end;
      next;
    end;
  end;
  initGrid();
end;

procedure TfrmGRYearPFList_YGXZFF.TBAddClick(Sender: TObject);
begin
  frmYGYPInPut_YGXZDJ:=TfrmYGYPInPut_YGXZDJ.create(self);
  with frmYGYPInPut_YGXZDJ do
  begin
    FXZMain:='';
    if showmodal=1 then
    begin
      initGrid();
    end;
    free;
  end;
end;

procedure TfrmGRYearPFList_YGXZFF.TSselClick(Sender: TObject);
begin
  if Order_Main.isempty then exit;
  frmYGYPInPut_YGXZDJ:=TfrmYGYPInPut_YGXZDJ.create(self);
  with frmYGYPInPut_YGXZDJ do
  begin
    ToolBar1.Enabled:=False;
    Panel3.Enabled:=False;
    toolbar2.Enabled:=False;
    FXZMain:=trim(Order_Main.fieldbyname('XZMain').AsString);
    if showmodal=1 then
    begin
      initGrid();
    end;
    free;
  end;
end;

procedure TfrmGRYearPFList_YGXZFF.TUpdateClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  frmYGYPInPut_YGXZDJ:=TfrmYGYPInPut_YGXZDJ.create(self);
  with frmYGYPInPut_YGXZDJ do
  begin
    FXZMain:=trim(Order_Main.fieldbyname('XZMain').AsString);
    if showmodal=1 then
    begin
      initGrid();
    end;
    free;
  end;
end;

procedure TfrmGRYearPFList_YGXZFF.cxTabControl1Change(Sender: TObject);
begin
  setstatus();
  initGrid();
end;

procedure TfrmGRYearPFList_YGXZFF.TCHkClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  if Order_Main.Locate('Ssel',true,[])=False then
  begin
    application.MessageBox('没有选择数据','提示');
    exit;
  end;
  try
    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_YG_XZFF set Chkstatus=''已审核'' ');
            sql.add('where XZID='''+trim(Order_Main.fieldbyname('XZID').AsString)+'''');
            execsql;
          end;
        end;
        next;
      end;
    end;
    initGrid();
    application.MessageBox('付款成功','提示');
  except;
    application.MessageBox('付款失败','提示');
  end;
end;

procedure TfrmGRYearPFList_YGXZFF.TCXChkClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  if Order_Main.Locate('Ssel',true,[])=False then
  begin
    application.MessageBox('没有选择数据','提示');
    exit;
  end;
  try
    with Order_Main do
    begin
      first;
      while not eof do
      begin
        if fieldbyname('Ssel').AsBoolean=True then
        begin
          if order_Main.fieldbyname('FKStatus').asstring='已付款' then
          begin
            application.MessageBox('有已付款不能撤销','提示');
            exit;
          end;
          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add('update OA_YG_XZFF set Chkstatus=''待审核'' ');
            sql.add('where XZID='''+trim(Order_Main.fieldbyname('XZID').AsString)+'''');
            execsql;
          end;
        end;
        next;
      end;
    end;
    initGrid();
    application.MessageBox('付款成功','提示');
  except;
    application.MessageBox('付款失败','提示');
  end;
end;

procedure TfrmGRYearPFList_YGXZFF.YGNameChange(Sender: TObject);
begin
  ToolButton1.Click;
end;

procedure TfrmGRYearPFList_YGXZFF.TTJClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  if Order_Main.Locate('Ssel',true,[])=False then
  begin
    application.MessageBox('没有选择数据','提示');
    exit;
  end;
  try
    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_YG_XZFF set Chkstatus=''未审核'' ');
            sql.add('where XZID='''+trim(Order_Main.fieldbyname('XZID').AsString)+'''');
            execsql;
          end;
        end;
        next;
      end;
    end;
    initGrid();
    application.MessageBox('提交成功','提示');
  except;
    application.MessageBox('提交失败','提示');
  end;
end;

procedure TfrmGRYearPFList_YGXZFF.cxTabControl2Change(Sender: TObject);
begin
  InitGrid();
end;

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

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

procedure TfrmGRYearPFList_YGXZFF.Tv1CellDblClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  TSsel.Click;
end;

procedure TfrmGRYearPFList_YGXZFF.TCXTJClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  if Order_Main.Locate('Ssel',true,[])=False then
  begin
    application.MessageBox('没有选择数据','提示');
    exit;
  end;
  try
    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_YG_XZFF set Chkstatus=''待提交'' ');
            sql.add('where XZID='''+trim(Order_Main.fieldbyname('XZID').AsString)+'''');
            execsql;
          end;
        end;
        next;
      end;
    end;
    initGrid();
    application.MessageBox('审核成功','提示');
  except;
    application.MessageBox('审核失败','提示');
  end;
end;

end.
