unit U_SingleCustStatement;

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,   dxDateRanges,
  dxBarBuiltInMenu, dxSkinsCore, dxSkinWXI, dxScrollbarAnnotations;

type
  TfrmSingleCustStatement = 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;
    Tv1BQYSAmount: TcxGridDBBandedColumn;
    Tv1BQSKAmount: TcxGridDBBandedColumn;
    Tv1BQJYAmount: TcxGridDBBandedColumn;
    V1Column14: TcxGridDBBandedColumn;
    Tv1IVNo: TcxGridDBBandedColumn;
    V1Column25: TcxGridDBBandedColumn;
    V1Column34: TcxGridDBBandedColumn;
    OppCoName: TEdit;
    ToolButton2: TToolButton;
    TV1ReconciliationDate: TcxGridDBBandedColumn;
    TV1BGDNum: TcxGridDBBandedColumn;
    TV1oppShuiNo: TcxGridDBBandedColumn;
    TV1oppconame: TcxGridDBBandedColumn;
    TV1Currency: TcxGridDBBandedColumn;
    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
  frmSingleCustStatement: TfrmSingleCustStatement;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_LabelPrint;

{$R *.dfm}

procedure TfrmSingleCustStatement.InitGrid();
begin

  with ADOQueryMain do
  begin
    Close;
    SQL.Clear;
    Filtered := False;
    sql.Add(' exec  P_Fin_CustStatementSingle_New1  ');
    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)));
    Open;
  end;
  SCreateCDS(ADOQueryMain, CDS_HZ);
  SInitCDSData(ADOQueryMain, CDS_HZ);
end;

procedure TfrmSingleCustStatement.FormDestroy(Sender: TObject);
begin
  frmSingleCustStatement := nil;
end;

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

procedure TfrmSingleCustStatement.TBCloseClick(Sender: TObject);
begin

  Close;
end;

procedure TfrmSingleCustStatement.FormShow(Sender: TObject);
begin
  readCxBandedGrid(trim(self.Caption), Tv1, '应收款对账单');
  InitGrid();
end;

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

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

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

procedure TfrmSingleCustStatement.ToolButton2Click(Sender: TObject);
begin
  WriteCxBandedGrid(trim(self.Caption), Tv1, '应收款对账单');
end;

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

procedure TfrmSingleCustStatement.ToolButton3Click(Sender: TObject);
var
  WSql: string;
begin
  if CDS_HZ.IsEmpty then
    exit;

  WSql := '  @Begdate=' + QuotedStr(Trim(FormatDateTime('yyyy-MM-dd', begdate.DateTime)));
  WSql := WSql + ' ,@Enddate=' + QuotedStr(Trim(FormatDateTime('yyyy-MM-dd', Enddate.DateTime + 1)));
  WSql := WSql + ' ,@OppCoNo=' + QuotedStr(Trim(FOppCoNo));
  WSql := WSql + ' ,@Currency=' + QuotedStr(Trim(FCurrency));

  try
    frmLabelPrint := TfrmLabelPrint.Create(Application);
    with frmLabelPrint do
    begin
      IsSql1 := True;
      FLMType := 'SingleCustStatement';
      FFiltration1 := WSql;
      if ShowModal = 1 then
      begin
//        Self.InitGrid();
      end;
    end;
  finally
    frmLabelPrint.Free;
  end;

end;

end.

