unit U_GRYearPFList_YGXZFFCX;

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_YGXZFFCX = 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;
    Source1: TDataSource;
    Order_Sub: TClientDataSet;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    cxStyle3: TcxStyle;
    TCXFK: TToolButton;
    Label3: TLabel;
    YGName: TEdit;
    cxTabControl1: TcxTabControl;
    Label5: TLabel;
    FKType: TEdit;
    ToolButton2: TToolButton;
    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 TBAddClick(Sender: TObject);
    procedure v1PriceUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure YGNameChange(Sender: TObject);
    procedure TCXFKClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure cxTabControl2Change(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);

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

var
  frmGRYearPFList_YGXZFFCX: TfrmGRYearPFList_YGXZFFCX;

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

{$R *.dfm}
procedure TfrmGRYearPFList_YGXZFFCX.setstatus();
begin
  TBAdd.Visible:=False;
  TCXFK.Visible:=False;
  Toolbutton2.Visible:=False;
  if trim(DParameters1)<>'查询' then
  begin
    case cxTabControl1.TabIndex of
      0:begin
        TBAdd.Visible:=True;
        Toolbutton2.Visible:=True;
      end;
      1:begin
        TCXFK.Visible:=true;
      end;
      2:begin
        TCXFK.Visible:=true;
      end;
    end;
  end;
end;

procedure TfrmGRYearPFList_YGXZFFCX.FormDestroy(Sender: TObject);
begin
  frmGRYearPFList_YGXZFFCX:=nil;
end;

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

procedure TfrmGRYearPFList_YGXZFFCX.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('工资付款登记22',Tv1,'分红管理');
end;

procedure TfrmGRYearPFList_YGXZFFCX.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))+''' ');
    sql.add('and B.ChkStatus=''已审核'' ');
    if cxTabControl1.TabIndex=0 then
    begin
      sql.add('and isnull(B.FKStatus,'''')='''' ');
    end;
    if cxTabControl1.TabIndex=1 then
    begin
      sql.add('and isnull(B.FKStatus,'''')=''已付款'' ');
    end;
    if cxTabControl1.TabIndex=2 then
    begin
      sql.add('and isnull(B.FKStatus,'''')=''作废'' ');
    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_YGXZFFCX.InitForm();
begin
  EndDate.Date:=SGetServerDate(ADOQueryTemp);
  BegDate.Date:=SGetServerDate(ADOQueryTemp)-30;
  ReadCxGrid('工资付款登记22',Tv1,'分红管理');
  setstatus();
  InitGrid();
end;

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

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

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

procedure TfrmGRYearPFList_YGXZFFCX.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_YGXZFFCX.TBAddClick(Sender: TObject);
begin
  toolbar1.SetFocus;
  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 FKStatus=''已付款'',FKDate=getdate(),FKNote='''+trim(Order_Main.fieldbyname('FKNote').AsString)+''' ');
            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_YGXZFFCX.v1PriceUnitPropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag:='PriceUnit';
    flagname:='币种';
    if showModal=1 then
    begin
      with Order_Main do
      begin
        edit;
        fieldbyname('PriceUnit').asstring:=trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
    free;
  end;
end;

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

procedure TfrmGRYearPFList_YGXZFFCX.TCXFKClick(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 FKstatus='''',FKDate=NULL,FKNote='''' ');
            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_YGXZFFCX.cxTabControl1Change(Sender: TObject);
begin
  setstatus();
  initGrid();
end;

procedure TfrmGRYearPFList_YGXZFFCX.cxTabControl2Change(Sender: TObject);
begin
  initGrid();
end;

procedure TfrmGRYearPFList_YGXZFFCX.ToolButton2Click(Sender: TObject);
begin
  toolbar1.SetFocus;
  if Order_Main.IsEmpty then exit;
  if cxTabControl1.TabIndex<>0 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 FKStatus=''作废'',FKNote='''+trim(Order_Main.fieldbyname('FKNote').AsString)+''' ');
            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_YGXZFFCX.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Main,True);
end;

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

end.
