unit U_YSSKList;

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,strutils, cxLookAndFeels, cxLookAndFeelPainters,
  cxNavigator;

type
  TfrmYSSKList = 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;
    Label3: TLabel;
    FactoryName: TEdit;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    Label2: TLabel;
    Label6: TLabel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    v2Column5: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    v2Column8: TcxGridDBColumn;
    v2Column9: TcxGridDBColumn;
    v2GSTT: TcxGridDBColumn;
    Label1: TLabel;
    ComTaiTou: TEdit;
    ToolButton3: TToolButton;
    v2Column10: TcxGridDBColumn;
    v2Column11: TcxGridDBColumn;
    v2Column12: TcxGridDBColumn;
    DEFStr6: TEdit;
    Label4: TLabel;
    Label5: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Label7: TLabel;
    v2Column14: TcxGridDBColumn;
    v2Column13: 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);
    procedure ToolButton3Click(Sender: TObject);
    procedure Tv2CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
  private
    { Private declarations }
    procedure InitGrid();
  public
    { Public declarations }
    RKFlag,FCYID:String;

  end;

var
  frmYSSKList: TfrmYSSKList;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp, U_YSMXlist;

{$R *.dfm}



procedure TfrmYSSKList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      SQL.Clear;
      if Trim(DParameters10)='' then
        sql.Add(' exec P_YSSK_List :begdate,:Enddate,:Flag')
      else
        SQL.Add(' exec '+Trim(DParameters10)+' :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));
      Parameters.ParamByName('Flag').Value:=Trim(DParameters1);
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
    ToolButton2.Click;
  end;
end;


procedure TfrmYSSKList.FormDestroy(Sender: TObject);
begin
  frmYSSKList:=nil;
end;

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

procedure TfrmYSSKList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('应收收款统计',Tv2,'财务管理');
  Close;
end;
procedure TfrmYSSKList.FormShow(Sender: TObject);
begin
  ReadCxGrid('应收收款统计',Tv2,'财务管理');
  Enddate.DateTime:=SGetServerDate(ADOQueryTemp);
  begdate.DateTime:=Enddate.DateTime-7;

  if Trim(DParameters9)='支付台头' then
  begin
    v2GSTT.Hidden:=False;
    v2GSTT.Visible:=True;
    Label1.Visible:=True;
    ComTaiTou.Visible:=True;
  end else
  begin
    v2GSTT.Hidden:=True;
    v2GSTT.Visible:=False;
    Label1.Visible:=False;
    ComTaiTou.Visible:=False;
  end;

  InitGrid();
end;

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

procedure TfrmYSSKList.ToolButton2Click(Sender: TObject);
var
  fsj,fsj1:string;
begin
  if ADOQueryMain.Active=False then Exit;
  fsj:=SGetFilters(Panel1,1,2);
  fsj1:='';
  IF trim(Edit1.Text)<>'' then
  begin
    fsj1:=fsj1+' and BQMoney>='''+floattostr(strtofloatdef(trim(Edit1.Text),0))+''' ';
  end;
  IF trim(Edit2.Text)<>'' then
  begin
    fsj1:=fsj1+' and BQMoney<='''+floattostr(strtofloatdef(trim(Edit2.Text),0))+''' ';
  end;

  IF fsj1<>'' then
  begin
    IF trim(fsj)='' then
    begin
      fsj:=Trim(RightBStr(fsj1,Length(fsj1)-4));
    end
    else
      fsj:=fsj+fsj1;
  end;

  SDofilter(ADOQueryMain,fsj);
  SCreateCDS20(ADOQueryMain,CDS_HZ);
  SInitCDSData20(ADOQueryMain,CDS_HZ);
end;

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

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

procedure TfrmYSSKList.ToolButton3Click(Sender: TObject);
begin
  IF CDS_HZ.IsEmpty then exit;
  frmYSMXlist:=TfrmYSMXlist.create(self);
  with frmYSMXlist do
  begin
    begdate.Date:=self.begdate.Date;
    enddate.Date:=self.Enddate.Date;
    factoryName.Tag:=1;
    factoryName.Text:=self.CDS_HZ.fieldbyname('FactoryName').AsString;
    if showmodal=1 then
    begin
    end;
    free;
  end;
end;

procedure TfrmYSSKList.Tv2CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  ToolButton3.Click;
end;

end.
