unit U_FtyStatement;

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, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator,
  dxBarBuiltInMenu, cxPC, dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges,
  U_BaseList, Vcl.Menus, Vcl.Clipbrd, DateUtils, dxScrollbarAnnotations;

type
  TfrmFtyStatement = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    Label3: TLabel;
    OppCoName: 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;
    Label1: TLabel;
    ComTaiTou: TEdit;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    ADOQueryPrint: TADOQuery;
    cxTabControl1: TcxTabControl;
    ToolButton1: TToolButton;
    PM_1: TPopupMenu;
    N1: TMenuItem;
    Tv2Column1: TcxGridDBColumn;
    Tv2Column2: TcxGridDBColumn;
    Tv2Column5: TcxGridDBColumn;
    Tv2Column6: TcxGridDBColumn;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure OppCoNameChange(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();
  public
    fmanage, FZKType: string;
    { Public declarations }
    RKFlag, FCYID: string;
  end;

implementation

uses
  U_DataLink, U_RtFun, U_ZDYHelp, U_SingleFtyStatement, U_LabelPrint;


{$R *.dfm}

procedure TfrmFtyStatement.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add(' exec P_Fin_FtyStatement  ');
      sql.Add('  @begdate=' + QuotedStr(Trim(FormatDateTime('yyyy-MM-dd', begdate.DateTime))));
      sql.Add(' ,@Enddate=' + QuotedStr(Trim(FormatDateTime('yyyy-MM-dd', Enddate.DateTime + 1))));
      case cxTabControl1.TabIndex of
        0:
          begin
            sql.Add(' ,@Currency=''USD'' ');
          end;
        1:
          begin
            sql.Add(' ,@Currency=''RMB'' ');
          end;
        2:
          begin
            sql.Add(' ,@Currency=''EUR'' ');
          end;
      end;

      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_HZ);
    SInitCDSData(ADOQueryMain, CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
    TV2.DataController.Filter.Clear;
  end;
  ToolButton2.Click;
end;

procedure TfrmFtyStatement.N1Click(Sender: TObject);
begin

  Clipboard.SetTextBuf(PChar(Trim(CDS_HZ.fieldbyname(TV2.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));

end;

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

procedure TfrmFtyStatement.TBCloseClick(Sender: TObject);
begin

  Close;
end;

procedure TfrmFtyStatement.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(trim(self.Caption), Tv2, '财务管理');
  Enddate.DateTime := SGetServerDate(ADOQueryTemp);
  begdate.DateTime := StartOfTheMonth(Enddate.DateTime);
  InitGrid();
end;

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

procedure TfrmFtyStatement.ToolButton1Click(Sender: TObject);
begin
  WriteCxGrid(trim(self.Caption), Tv2, '财务管理');
end;

procedure TfrmFtyStatement.ToolButton2Click(Sender: TObject);
var
  fsj: string;
begin
  if ADOQueryMain.Active = False then
    Exit;

  SDofilter(ADOQueryMain, Trim(SGetFilters(Panel1, 1, 2)));
  SCreateCDS(ADOQueryMain, CDS_HZ);
  SInitCDSData(ADOQueryMain, CDS_HZ);
end;

procedure TfrmFtyStatement.OppCoNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmFtyStatement.ToolButton3Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    exit;
  frmSingleFtyStatement := TfrmSingleFtyStatement.Create(self);
  with frmSingleFtyStatement do
  begin
    begdate.DateTime := self.begdate.DateTime;
    enddate.DateTime := self.Enddate.DateTime;
    OppCoName.Text := self.CDS_HZ.fieldbyname('OppCoName').AsString;
    FOppCoNo := self.CDS_HZ.fieldbyname('OppCoNo').AsString;
    FZKType := Self.FZKType;
    case cxTabControl1.TabIndex of
      0:
        begin
          FCurrency := 'USD';
        end;
      1:
        begin
          FCurrency := 'CNY';
        end;
      2:
        begin
          FCurrency := 'EUR';
        end;
    end;
    show;
  end;
end;

procedure TfrmFtyStatement.ToolButton4Click(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)));
  case cxTabControl1.TabIndex of
    0:
      begin
        WSql := WSql + ' ,@Currency=''USD'' ';
      end;
    1:
      begin
        WSql := WSql + ' ,@Currency=''CNY'' ';
      end;
    2:
      begin
        WSql := WSql + ' ,@Currency=''EUR'' ';
      end;
  end;

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

end;

procedure TfrmFtyStatement.ToolButton5Click(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(self.CDS_HZ.fieldbyname('OppCoNo').AsString));
  case cxTabControl1.TabIndex of
    0:
      begin
        WSql := WSql + ' ,@Currency=''USD'' ';
      end;
    1:
      begin
        WSql := WSql + ' ,@Currency=''CNY'' ';
      end;
    2:
      begin
        WSql := WSql + ' ,@Currency=''EUR'' ';
      end;
  end;

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

end;

procedure TfrmFtyStatement.ToolButton6Click(Sender: TObject);
begin
  with ADOQueryCmd do
  begin
    Close;
    Sql.Clear;
    Sql.Add('exec P_Fin_Up_All ');
    Open;
  end;

end;

procedure TfrmFtyStatement.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

end.

