unit U_SingleFtyStatement;

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, cxDropDownEdit, RM_e_Xls, cxGridBandedTableView,
  cxGridDBBandedTableView, BtnEdit, cxLookAndFeels, cxLookAndFeelPainters,
  cxNavigator, dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges,
  dxBarBuiltInMenu, dxSkinWXI, dxScrollbarAnnotations;

type
  TfrmSingleFtyStatement = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    Label1: TLabel;
    MPRTCodeName: TEdit;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    Label3: TLabel;
    OrderNo: TEdit;
    cxGrid2: TcxGrid;
    cxGridLevel1: TcxGridLevel;
    Label2: TLabel;
    Label6: TLabel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    Label4: TLabel;
    OrdDefNote3: TComboBox;
    Label5: TLabel;
    ToolButton3: TToolButton;
    RMGridReport1: TRMGridReport;
    RMDBDataSet1: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    ADOQueryPrint: TADOQuery;
    TV1: TcxGridDBBandedTableView;
    V1Column2: TcxGridDBBandedColumn;
    V1Column4: TcxGridDBBandedColumn;
    V1Column5: TcxGridDBBandedColumn;
    V1Column6: TcxGridDBBandedColumn;
    V1Column7: TcxGridDBBandedColumn;
    V1Column8: TcxGridDBBandedColumn;
    V1Column9: TcxGridDBBandedColumn;
    V1Column12: TcxGridDBBandedColumn;
    V1Column15: TcxGridDBBandedColumn;
    V1Column3: TcxGridDBBandedColumn;
    V1Column10: TcxGridDBBandedColumn;
    V1Column14: TcxGridDBBandedColumn;
    V1Column16: TcxGridDBBandedColumn;
    V1Column17: TcxGridDBBandedColumn;
    V1Column20: TcxGridDBBandedColumn;
    V1Column21: TcxGridDBBandedColumn;
    V1Column22: TcxGridDBBandedColumn;
    V1Column23: TcxGridDBBandedColumn;
    V1Column25: TcxGridDBBandedColumn;
    V1Column26: TcxGridDBBandedColumn;
    V1Column33: TcxGridDBBandedColumn;
    V1Column34: TcxGridDBBandedColumn;
    OppCoName: TEdit;
    ToolButton2: TToolButton;
    TV1Column1: TcxGridDBBandedColumn;
    TV1Column2: TcxGridDBBandedColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyleRepository2: TcxStyleRepository;
    cxStyle2: TcxStyle;
    cxStyleRepository3: TcxStyleRepository;
    cxStyle3: TcxStyle;
    cxGrid1: TcxGrid;
    TV11: TcxGridDBTableView;
    v2CRTime: TcxGridDBColumn;
    Tv1Column23: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v2FactoryName: TcxGridDBColumn;
    v2OrderNo: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column19: TcxGridDBColumn;
    Tv1Column24: TcxGridDBColumn;
    Tv1Column20: TcxGridDBColumn;
    Tv1Column21: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Tv1Column11: TcxGridDBColumn;
    Tv1Column12: TcxGridDBColumn;
    Tv1Column14: TcxGridDBColumn;
    Tv1Column15: TcxGridDBColumn;
    Tv1Column28: TcxGridDBColumn;
    Tv1Column17: TcxGridDBColumn;
    Tv1Column25: TcxGridDBColumn;
    Tv1Column26: TcxGridDBColumn;
    Tv1Column27: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure P_OrderNo_YSK(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
  private
    { Private declarations }

    procedure InitGrid();
  public
    { Public declarations }
    FOppCoNo, FCurrency: string;
  end;

var
  frmSingleFtyStatement: TfrmSingleFtyStatement;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp;

{$R *.dfm}

procedure TfrmSingleFtyStatement.InitGrid();
begin

  with ADOQueryMain do
  begin
    Close;
    SQL.Clear;
    Filtered := False;
    sql.Add(' exec  P_Fin_FtyStatementSingle  ');
    sql.Add('  @Begdate=' + QuotedStr(Trim(FormatDateTime('yyyy-MM-dd', begdate.DateTime))));
    sql.Add(' ,@Enddate=' + QuotedStr(Trim(FormatDateTime('yyyy-MM-dd', Enddate.DateTime + 1))));
    sql.Add(' ,@OppCoNo=' + QuotedStr(Trim(FOppCoNo)));
    sql.Add(' ,@Currency=' + QuotedStr(Trim(FCurrency)));
    ShowMessage(sql.text);
    Open;
  end;
  SCreateCDS(ADOQueryMain, CDS_HZ);
  SInitCDSData(ADOQueryMain, CDS_HZ);
end;

procedure TfrmSingleFtyStatement.FormDestroy(Sender: TObject);
begin
  frmSingleFtyStatement := nil;
end;

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

procedure TfrmSingleFtyStatement.TBCloseClick(Sender: TObject);
begin

  Close;
end;

procedure TfrmSingleFtyStatement.FormShow(Sender: TObject);
begin
//  readCxBandedGrid(trim(self.Caption), Tv1, '财务管理');
  readCxGrid(trim(self.Caption), Tv11, '应付款对账单');
  InitGrid();
end;

procedure TfrmSingleFtyStatement.TBRafreshClick(Sender: TObject);
begin
  begdate.SetFocus;
  InitGrid();
end;

procedure TfrmSingleFtyStatement.P_OrderNo_YSK(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmSingleFtyStatement.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  TcxGridToExcel(self.Caption + '-' + trim(OppCoName.Text), cxgrid2);
end;

procedure TfrmSingleFtyStatement.ToolButton2Click(Sender: TObject);
begin
//  WriteCxBandedGrid(trim(self.Caption), Tv1, '财务管理');
  WriteCxGrid(trim(Self.Caption), Tv11, '应付款对账单');
end;

procedure TfrmSingleFtyStatement.FormCreate(Sender: TObject);
begin
  cxGrid2.Align := AlClient;
  Enddate.DateTime := SGetServerDate(ADOQueryTemp);
  begdate.DateTime := Enddate.DateTime;
end;

procedure TfrmSingleFtyStatement.ToolButton3Click(Sender: TObject);
var
  filepath: string;
  mBegdate, mEnddate: string;
begin
  mBegdate := FormatDateTime('yyyy-MM-dd', begdate.Date);
  mEnddate := FormatDateTime('yyyy-MM-dd', enddate.Date);
  if CDS_HZ.IsEmpty then
    exit;

  filepath := ExtractFilePath(Application.ExeName) + 'report\应付款明细对账单.rmf';
  if not FileExists(Pchar(filepath)) then
  begin
    application.MessageBox(pchar('文件[' + filepath + ']不存在！'), '提示信息', MB_IConError);
    exit;
  end;
  RMGridReport1.LoadFromFile(filepath);
  RMGridReport1.ShowReport;

end;

end.

