unit U_YFFKListTaiTou;

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

type
  TfrmYFFKListTaiTou = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    Label3: TLabel;
    FactoryNameGYS: TEdit;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    Label2: TLabel;
    Label6: TLabel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    v2Column5: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    ADOQueryMain: TADOQuery;
    CDS_HZ: TClientDataSet;
    v2Column7: TcxGridDBColumn;
    v2Column8: TcxGridDBColumn;
    v2Column9: TcxGridDBColumn;
    CheckBox1: TCheckBox;
    v2Column10: TcxGridDBColumn;
    v2Column11: TcxGridDBColumn;
    ToolButton3: TToolButton;
    v2Column12: TcxGridDBColumn;
    Label1: TLabel;
    ComTaiTou: TEdit;
    v2Column13: TcxGridDBColumn;
    v2Column14: TcxGridDBColumn;
    v2Column15: TcxGridDBColumn;
    v2Column16: TcxGridDBColumn;
    v2Column17: TcxGridDBColumn;
    v2Column18: 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 FactoryNameGYSChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Tv2CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton3Click(Sender: TObject);
    procedure v2Column6HeaderClick(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();
  public
    fDParameters1:string;
    { Public declarations }
    RKFlag,FCYID:String;

  end;

var
  frmYFFKListTaiTou: TfrmYFFKListTaiTou;

implementation
uses
  U_DataLink,U_RTFun,U_Fun,U_ZDYHelp,U_YFMXlistTaiTou;

{$R *.dfm}



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

      Close;
      SQL.Clear;
      Filtered:=False;
      sql.Add(' exec P_YFFK_List_TaiTou :begdate,:Enddate ') ;
      if CheckBox1.Checked=True then
      begin
        Parameters.ParamByName('begdate').Value:=Trim(FormatDateTime('yyyy-MM-dd',begdate.DateTime));
        Parameters.ParamByName('Enddate').Value:=Trim(FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1));
      end else
      begin
        Parameters.ParamByName('begdate').Value:='2000-01-01';
        Parameters.ParamByName('Enddate').Value:='2500-01-01';
      end;

      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
  end;
  //ToolButton2.Click;
end;


procedure TfrmYFFKListTaiTou.FormDestroy(Sender: TObject);
begin
  frmYFFKListTaiTou:=nil;
end;

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

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

procedure TfrmYFFKListTaiTou.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
  CDS_HZ.IndexFieldNames:='FactoryName';
  
  with CDS_HZ do
  begin
    with IndexDefs do
    begin
      Clear;
      with AddIndexDef do
      begin
        Name := 'Fld1Indx';
        Fields := 'FactoryName';
        Options := [ixDescending];  //降序
      end;
    end;
  end;
end;

procedure TfrmYFFKListTaiTou.ToolButton2Click(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 TfrmYFFKListTaiTou.FactoryNameGYSChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

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

procedure TfrmYFFKListTaiTou.Tv2CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  try
    frmYFMXlistTaiTou:=TfrmYFMXlistTaiTou.Create(Application);
    with frmYFMXlistTaiTou do
    begin
      FMX:='99';
      frmYFMXlistTaiTou.begdate.DateTime:=Self.begdate.DateTime;
      frmYFMXlistTaiTou.Enddate.DateTime:=Self.Enddate.DateTime;
      frmYFMXlistTaiTou.factoryName.Text:=Self.CDS_HZ.fieldbyname('factoryName').AsString;
      frmYFMXlistTaiTou.ComTaiTou.Text:=Self.CDS_HZ.fieldbyname('ComTaiTou').AsString;
      if Self.CheckBox1.Checked then
      begin
        frmYFMXlistTaiTou.CheckBox1.Checked:=True;
      end else
      begin
        frmYFMXlistTaiTou.CheckBox1.Checked:=False;
      end;
      frmYFMXlistTaiTou.Align:=alClient;
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmYFMXlistTaiTou.Free;
  end;
end;

procedure TfrmYFFKListTaiTou.ToolButton3Click(Sender: TObject);
var
  filepath:string;
  mBegdate,mEnddate:string;
  FName,FNameSX,FNameJX:String;
  i:Integer;
begin
  for i:=0 to Tv2.ColumnCount-1 do
  begin
    FName:=Tv2.Columns[i].DataBinding.FilterFieldName;
    FNameSX:=Trim(FName)+'-1';
    FNameJX:=Trim(FName)+'-2';
    CDS_HZ.AddIndex(FNameSX, FName, []);             { 正序 }
    CDS_HZ.AddIndex(FNameJX, FName, [ixDescending]); { 倒序 }
    if Tv2.Columns[i].SortOrder=soDescending then
    begin
      CDS_HZ.IndexName:=FNameJX;
    end else
    if Tv2.Columns[i].SortOrder=soAscending then
    begin
      CDS_HZ.IndexName:=FNameSX;
    end;
  end;
  mbegdate:=FormatDateTime('yyyy-MM-dd',begdate.Date);
  menddate:=FormatDateTime('yyyy-MM-dd',enddate.Date);
  if CDS_HZ.IsEmpty then exit;
  try
    filepath:=ExtractFilePath(Application.ExeName) + 'report\应付款统计报表.rmf';
    if not FileExists(Pchar(filepath))  then
    begin
      application.MessageBox(pchar('文件['+filepath+']不存在！'),'提示信息',MB_IConError);
      exit;
    end;
    RmVariables['begDate'] :=FormatDateTime('yymmdd',begDate.Date)+'-'+FormatDateTime('yymmdd',enddate.Date);
    RM1.LoadFromFile(filepath);
    RM1.ShowReport;
  finally

  end;

end;

procedure TfrmYFFKListTaiTou.v2Column6HeaderClick(Sender: TObject);
var
  FName,FNameSX,FNameJX:String;
begin
  FName:=TcxGridDBColumn(Sender).DataBinding.FilterFieldName;
  FNameSX:=Trim(FName)+'-1';
  FNameJX:=Trim(FName)+'-2';
  CDS_HZ.AddIndex(FNameSX, FName, []);             { 正序 }
  CDS_HZ.AddIndex(FNameJX, FName, [ixDescending]); { 倒序 }
  if TcxGridDBColumn(Sender).SortOrder=soDescending then
  begin
    CDS_HZ.IndexName:=FNameSX;
  end else
  if TcxGridDBColumn(Sender).SortOrder=soAscending then
  begin
    CDS_HZ.IndexName:=FNameJX;
  end;

end;

end.
