unit U_YF_Money_LL_list;

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;

type
  TfrmYF_Money_LL_list = class(TForm)
    ToolBar1: TToolBar;
    TINIT: TToolButton;
    TGLV: TToolButton;
    Texcel: TToolButton;
    TCLOSE: TToolButton;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    factoryName: TEdit;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    V1InMoney: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    DataSource1: TDataSource;
    AdoQueryTmp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    V1OutMoney: TcxGridDBColumn;
    V1YEMoney: TcxGridDBColumn;
    Label3: TLabel;
    V1Column2: TcxGridDBColumn;
    V1Column1: TcxGridDBColumn;
    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 TexcelClick(Sender: TObject);
    procedure CRTypeChange(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
  private
    procedure initGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmYF_Money_LL_list: TfrmYF_Money_LL_list;

implementation

uses U_DataLink, U_Fun,U_YF_Money_Sub, U_ZDYHelp;

{$R *.dfm}

procedure TfrmYF_Money_LL_list.InitGrid();
begin
  with AdoQueryTmp do
  begin
    close;
    sql.Clear;
    sql.Add(' exec P_ZHLL_List ');
    sql.Add(' @begdate='''+formatdateTime('yyyy-MM-dd',begdate.DateTime)+''' ');
    sql.Add(',@enddate='''+formatdateTime('yyyy-MM-dd',enddate.DateTime+1)+''' ');
    open;
  end;
  SCreateCDS20(ADOQueryTmp,CDS_Main);
  SInitCDSData20(ADOQueryTmp,CDS_Main);
end;

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

procedure TfrmYF_Money_LL_list.FormShow(Sender: TObject);
begin
  ReadCxGrid(self.Caption+tv1.Name,Tv1);
  enddate.datetime:=SGetServerDateTime(ADOQueryTmp);
  begdate.datetime:=strtodate(formatdateTime('yyyy-MM',enddate.DateTime)+'-01');
  initGrid();
end;

procedure TfrmYF_Money_LL_list.FormDestroy(Sender: TObject);
begin
  frmYF_Money_LL_list:=nil;
end;

procedure TfrmYF_Money_LL_list.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  writeCxGrid(self.Caption+tv1.Name,Tv1);
  action:=cafree;
end;

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

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

procedure TfrmYF_Money_LL_list.TGLVClick(Sender: TObject);
begin
  SDofilter(AdoQueryTmp,SGetFilters(Panel1,1,0));
  SCreateCDS20(AdoQueryTmp,CDS_Main);
  SInitCDSData20(AdoQueryTmp,CDS_Main);
end;

procedure TfrmYF_Money_LL_list.TexcelClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  TcxGridToExcel(self.Caption,cxGrid1);
end;

procedure TfrmYF_Money_LL_list.CRTypeChange(Sender: TObject);
begin
  SDofilter(AdoQueryTmp,SGetFilters(Panel1,1,0));
  SCreateCDS20(AdoQueryTmp,CDS_Main);
  SInitCDSData20(AdoQueryTmp,CDS_Main);
end;

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

end.
