unit U_CWZK_CX;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
  cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin,
  StdCtrls, cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
  cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP,ShellAPI,IniFiles, cxCheckBox, cxCalendar,
  cxButtonEdit, cxTextEdit;

type
  TfrmCWZK_CX = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    Label2: TLabel;
    Label6: TLabel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    v2YSMoney: TcxGridDBColumn;
    v2YFMoney: TcxGridDBColumn;
    v2DQLIRun: TcxGridDBColumn;
    v2FKMoney: TcxGridDBColumn;
    Label1: TLabel;
    ComTaiTou: TEdit;
    Label4: TLabel;
    FHAddress: TEdit;
    Label5: TLabel;
    FHdq: TEdit;
    v2SKMoney: TcxGridDBColumn;
    v2WSKMoney: TcxGridDBColumn;
    v2WFKMoney: TcxGridDBColumn;
    v2SXMoney: TcxGridDBColumn;
    v2TSMoney: TcxGridDBColumn;
    v2FYZCMoney: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure FactoryNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();
  public
    fDParameters1:string;
    { Public declarations }
    RKFlag,FCYID:String;

  end;

var
  frmCWZK_CX: TfrmCWZK_CX;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp,U_YSSKList_KP;

{$R *.dfm}



procedure TfrmCWZK_CX.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      SQL.Clear;
      sql.Add(' exec P_CWZK_CX :begdate,:Enddate');
      Parameters.ParamByName('begdate').Value:=Trim(FormatDateTime('yyyy-MM-dd',begdate.DateTime));
      Parameters.ParamByName('Enddate').Value:=Trim(FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1));
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
  end;
  ToolButton2.Click;
end;


procedure TfrmCWZK_CX.FormDestroy(Sender: TObject);
begin
  frmCWZK_CX:=nil;
end;

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

procedure TfrmCWZK_CX.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('应收收款统计45',Tv2,'财务管理');
  Close;
end;
procedure TfrmCWZK_CX.FormShow(Sender: TObject);
var fsj:string;
begin
  ReadCxGrid('应收收款统计45',Tv2,'财务管理');
  Enddate.DateTime:=SGetServerDate(ADOQueryTemp);
  begdate.DateTime:=StrToDate(FormatDateTime('YYYY',Enddate.DateTime)+'-01'+'-01');
  fsj:='select distinct (A.FactoryName) name from YF_Money_CR A where A.CRType=''应收款登记'' ';

end;

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

procedure TfrmCWZK_CX.ToolButton2Click(Sender: TObject);
var
  fsj:string;
begin
  if ADOQueryMain.Active=False then Exit;

  SDofilter(ADOQueryMain,Trim(SGetFilters(Panel1,1,2)));
  SCreateCDS20(ADOQueryMain,CDS_HZ);
  SInitCDSData20(ADOQueryMain,CDS_HZ);
end;

procedure TfrmCWZK_CX.FactoryNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmCWZK_CX.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  SelExportData(Tv2,ADOQueryMain,'应收收款统计列表');
end;

end.
