unit U_GRYearPFList_YGFHDJ;

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;


type
  TfrmGRYearPFList_YGFHDJ = 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;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column7: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1YGGL: TcxGridDBColumn;
    v1FHType: TcxGridDBColumn;
    v1MBMoney: TcxGridDBColumn;
    v1PriceUnit: TcxGridDBColumn;
    v1YMBMoney: TcxGridDBColumn;
    v1FHMoney: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    cxStyle3: TcxStyle;
    TSsel: TToolButton;
    v1GRNXMoney: TcxGridDBColumn;
    v1NFYear: TcxGridDBColumn;
    v1GRYearPF: TcxGridDBColumn;
    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 v1PriceUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure TSselClick(Sender: TObject);

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

var
  frmGRYearPFList_YGFHDJ: TfrmGRYearPFList_YGFHDJ;

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

{$R *.dfm}

procedure TfrmGRYearPFList_YGFHDJ.FormDestroy(Sender: TObject);
begin
  frmGRYearPFList_YGFHDJ:=nil;
end;

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

procedure TfrmGRYearPFList_YGFHDJ.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('分红档期登记',Tv1,'分红管理');
end;

procedure TfrmGRYearPFList_YGFHDJ.InitGrid();
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select * from GRYearFH_Sub ');
    sql.Add('where filltime>='''+formatdatetime('yyyy-MM-dd',BegDate.Time)+''' ');
    sql.Add('and filltime<'''+formatdatetime('yyyy-MM-dd',enddate.Time+1)+''' ');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,Order_Main);
  SInitCDSData20(ADOQueryTemp,Order_Main);
end;

procedure TfrmGRYearPFList_YGFHDJ.InitForm();
begin
  EndDate.Date:=SGetServerDate(ADOQueryTemp);
  BegDate.Date:=SGetServerDate(ADOQueryTemp)-365;
  ReadCxGrid('分红档期登记',Tv1,'分红管理');
  InitGrid();
end;

procedure TfrmGRYearPFList_YGFHDJ.TBExportClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  TcxGridToExcel('分红档期',cxGrid1);
end;

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

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

procedure TfrmGRYearPFList_YGFHDJ.ToolButton1Click(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 TfrmGRYearPFList_YGFHDJ.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  if application.MessageBox('确定要撤销吗','提示',1)=2 then exit;
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    //sql.Add('delete from GRYearFH_Main ');
    //sql.add('where FHID='''+trim(Order_Main.fieldbyname('FHID').AsString)+'''');
    sql.add('delete from GRYearFH_Sub where FHID='''+trim(Order_Main.fieldbyname('FHID').AsString)+'''');
    execsql;
  end;
  initGrid();
end;

procedure TfrmGRYearPFList_YGFHDJ.TBAddClick(Sender: TObject);
begin
  frmYGYPInPut_YGFHDJ:=TfrmYGYPInPut_YGFHDJ.create(self);
  with frmYGYPInPut_YGFHDJ do
  begin
    FFHID:='';
    if showmodal=1 then
    begin
      initGrid();
    end;
    free;
  end;
end;

procedure TfrmGRYearPFList_YGFHDJ.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_YGFHDJ.TSselClick(Sender: TObject);
begin
  if Order_Main.isempty then exit;
  frmYGYPInPut_YGFHDJ:=TfrmYGYPInPut_YGFHDJ.create(self);
  with frmYGYPInPut_YGFHDJ do
  begin
    FFHID:=Order_Main.fieldbyname('FHID').asstring;
    if showmodal=1 then
    begin
      initGrid();
    end;
    free;
  end;
end;

end.
