unit U_BankFlowTotalList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, DBClient, ADODB, cxGridCustomPopupMenu, cxGridPopupMenu,
  cxPC, StdCtrls, ComCtrls, ExtCtrls, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxControls, cxGridCustomView,
  cxGrid, ToolWin, cxCalendar, cxCurrencyEdit, cxTextEdit, cxLookAndFeels,
  cxLookAndFeelPainters, dxSkinsCore, dxSkinsDefaultPainters, cxNavigator,
  dxDateRanges, dxBarBuiltInMenu, U_BaseList;

type
  TfrmBankFlowTotalList = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TINIT: TToolButton;
    TGLV: TToolButton;
    TCLOSE: TToolButton;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    DataSource1: TDataSource;
    AdoQueryTmp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    V1YEMoney: TcxGridDBColumn;
    V1Column9: TcxGridDBColumn;
    TV1Column2: TcxGridDBColumn;
    Panel1: TPanel;
    Label2: TLabel;
    BKName: TEdit;
    Label1: TLabel;
    Edit1: TEdit;
    TV1Column3: TcxGridDBColumn;
    ToolButton1: TToolButton;
    Label3: TLabel;
    BegDate: TDateTimePicker;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TCLOSEClick(Sender: TObject);
    procedure TINITClick(Sender: TObject);
    procedure TGLVClick(Sender: TObject);
    procedure GSTaiTouChange(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure ToolButton1Click(Sender: TObject);
  private
    procedure initGrid();

    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmBankFlowTotalList: TfrmBankFlowTotalList;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

procedure TfrmBankFlowTotalList.InitGrid();
begin
  with AdoQueryTmp do
  begin
    close;
    sql.Clear;
    sql.Add('exec P_Bank_Balance ');
    sql.Add('@ExchangeRate=' + FloatToStr(strtofloatdef(Edit1.Text, 0)));
    sql.Add(',@BFTime=' + quotedstr(formatdateTime('yyyy-MM-dd', begdate.DateTime)));

    open;
  end;
  SCreateCDS(ADOQueryTmp, CDS_Main);
  SInitCDSData(ADOQueryTmp, CDS_Main);
  TV1.DataController.Filter.Clear;
  CDS_Main.Last;
end;

procedure TfrmBankFlowTotalList.FormCreate(Sender: TObject);
begin
  inherited;
  cxgrid1.Align := alclient;
end;

procedure TfrmBankFlowTotalList.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(self.Caption + tv1.Name, Tv1);
//  enddate.datetime := SGetServerDateTime(ADOQueryTmp);
  begdate.datetime := SGetServerDateTime(ADOQueryTmp);

  initGrid();
end;

procedure TfrmBankFlowTotalList.FormDestroy(Sender: TObject);
begin
  inherited;
  frmBankFlowTotalList := nil;
end;

procedure TfrmBankFlowTotalList.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    InitGrid();
  end;
end;

procedure TfrmBankFlowTotalList.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;

  Action := cafree;
end;

procedure TfrmBankFlowTotalList.TCLOSEClick(Sender: TObject);
begin
  close;
end;

procedure TfrmBankFlowTotalList.TINITClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmBankFlowTotalList.ToolButton1Click(Sender: TObject);
begin
  writeCxGrid(self.Caption + tv1.Name, Tv1);
end;

procedure TfrmBankFlowTotalList.TGLVClick(Sender: TObject);
begin
  SDofilter(AdoQueryTmp, SGetFilters(Panel1, 1, 0));
  SCreateCDS(AdoQueryTmp, CDS_Main);
  SInitCDSData(AdoQueryTmp, CDS_Main);
end;

procedure TfrmBankFlowTotalList.GSTaiTouChange(Sender: TObject);
begin
  SDofilter(AdoQueryTmp, SGetFilters(Panel1, 1, 0));
  SCreateCDS(AdoQueryTmp, CDS_Main);
  SInitCDSData(AdoQueryTmp, CDS_Main);
end;

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

end.

