unit U_ZZYSSKYFFKList;

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
  TfrmZZYSSKYFFKList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    Label3: TLabel;
    FactoryNameKH: TEdit;
    Label2: TLabel;
    Label6: TLabel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    ADOQueryMain: TADOQuery;
    CDS_HZ: TClientDataSet;
    Panel2: TPanel;
    Panel3: TPanel;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2Column6: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    v2Column8: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    Label1: TLabel;
    FactoryNameGYS: TEdit;
    Label4: TLabel;
    YSHZ: TEdit;
    Label5: TLabel;
    YFHZ: TEdit;
    Label7: TLabel;
    ChaE: TEdit;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ClientDataSet1: TClientDataSet;
    ADOQueryMain10: TADOQuery;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FactoryNameKHChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Tv2CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure FactoryNameGYSChange(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
  private
    { Private declarations }
    procedure InitGrid();
  public
    fDParameters1:string;
    { Public declarations }
    RKFlag,FCYID:String;

  end;

var
  frmZZYSSKYFFKList: TfrmZZYSSKYFFKList;

implementation
uses
  U_DataLink,U_RTFun,U_Fun,U_ZDYHelp,U_ZZYSMXlist,U_YFMXlist;

{$R *.dfm}



procedure TfrmZZYSSKYFFKList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin

      Close;
      SQL.Clear;
      Filtered:=False;
      sql.Add(' exec P_YSSK_List10 :begdate,:Enddate,:Flag') ;
      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(fDParameters1);
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
  end;
  try
    ADOQueryMain10.DisableControls;
    with ADOQueryMain10 do
    begin

      Close;
      SQL.Clear;
      Filtered:=False;
      sql.Add(' exec P_YFFK_List10 :begdate,:Enddate,:Flag') ;
      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(fDParameters1);
      Open;
    end;
    SCreateCDS20(ADOQueryMain10,ClientDataSet1);
    SInitCDSData20(ADOQueryMain10,ClientDataSet1);
  finally
    ADOQueryMain10.EnableControls;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select YSHZ=isnull(Sum(Money*QtyFlag),0) from YF_Money_CR where CRType in(''应收款登记'',''收款登记'')');
    Open;
  end;
  YSHZ.Text:=Trim(ADOQueryTemp.fieldbyname('YSHZ').AsString);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select YFHZ=isnull(Sum(Money*QtyFlag),0) from YF_Money_CR where CRType in(''应付款登记'',''付款登记'')');
    Open;
  end;
  YFHZ.Text:=Trim(ADOQueryTemp.fieldbyname('YFHZ').AsString);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select ChaE=Cast(('+YSHZ.Text+'-'+YFHZ.Text+') as decimal(18,2))');
    open;
  end;
  ChaE.Text:=Trim(ADOQueryTemp.fieldbyname('ChaE').AsString);
  //ToolButton2.Click;
end;


procedure TfrmZZYSSKYFFKList.FormDestroy(Sender: TObject);
begin
  frmZZYSSKYFFKList:=nil;
end;

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

procedure TfrmZZYSSKYFFKList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('应收收款统计1',Tv2,'财务管理');
  WriteCxGrid('应付付款统计1',Tv1,'财务管理');
  Close;
end;
procedure TfrmZZYSSKYFFKList.FormShow(Sender: TObject);
begin
  ReadCxGrid('应收收款统计1',Tv2,'财务管理');
  ReadCxGrid('应付付款统计1',Tv1,'财务管理');
  Enddate.DateTime:=SGetServerDate(ADOQueryTemp);
  begdate.DateTime:=SGetServerDateMBeg(ADOQueryTemp);
  InitGrid();
end;

procedure TfrmZZYSSKYFFKList.TBRafreshClick(Sender: TObject);
begin
  InitGrid();

end;

procedure TfrmZZYSSKYFFKList.FactoryNameKHChange(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,CDS_HZ);
  SInitCDSData20(ADOQueryMain,CDS_HZ);
end;

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

procedure TfrmZZYSSKYFFKList.Tv2CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  {try
    frmZZYSMXlist:=TfrmZZYSMXlist.Create(Application);
    with frmZZYSMXlist do
    begin
      FMX:='99';
      frmZZYSMXlist.begdate.DateTime:=Self.begdate.DateTime;
      frmZZYSMXlist.Enddate.DateTime:=Self.Enddate.DateTime;
      frmZZYSMXlist.factoryName.Text:=Self.CDS_HZ.fieldbyname('factoryName').AsString;
    
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmZZYSMXlist.Free;
  end;  }
end;

procedure TfrmZZYSSKYFFKList.FactoryNameGYSChange(Sender: TObject);
begin
  if ADOQueryMain10.Active=False then Exit;
  SDofilter(ADOQueryMain10,SGetFilters(Panel1,3,4));
  SCreateCDS20(ADOQueryMain10,ClientDataSet1);
  SInitCDSData20(ADOQueryMain10,ClientDataSet1);
end;

procedure TfrmZZYSSKYFFKList.Tv1CellDblClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
 { try
    frmYFMXlist:=TfrmYFMXlist.Create(Application);
    with frmYFMXlist do
    begin
      FMX:='99';
      frmYFMXlist.begdate.DateTime:=Self.begdate.DateTime;
      frmYFMXlist.Enddate.DateTime:=Self.Enddate.DateTime;
      frmYFMXlist.factoryName.Text:=Self.CDS_HZ.fieldbyname('factoryName').AsString;
    
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmYFMXlist.Free;
  end;}
end;

end.
