unit U_CustStatement;

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

type
  TfrmCustStatement = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    Label3: TLabel;
    OppCoName: TEdit;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    Label2: TLabel;
    Label6: TLabel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    GPM_2: 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;
    Tv2Column1: TcxGridDBColumn;
    Tv2Column2: TcxGridDBColumn;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    ToolButton7: 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);
    procedure ToolButton7Click(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_SingleCustStatement, U_LabelPrint;


{$R *.dfm}

procedure TfrmCustStatement.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add(' exec  P_Fin_CustStatement  ');
      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(' ,@Currency=''RMB'' ');
      //      case cxTabControl1.TabIndex of
//        0:
//          begin
//            sql.Add(' ,@Currency=''USD'' ');
//          end;
//        1:
//          begin
//            sql.Add(' ,@Currency=''CNY'' ');
//          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 TfrmCustStatement.N1Click(Sender: TObject);
begin

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

end;

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

procedure TfrmCustStatement.TBCloseClick(Sender: TObject);
begin

  Close;
end;

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

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

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

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

procedure TfrmCustStatement.ToolButton3Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    exit;
  frmSingleCustStatement := TfrmSingleCustStatement.Create(self);
  with frmSingleCustStatement 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;
    FCurrency := 'RMB';

//    case cxTabControl1.TabIndex of
//      0:
//        begin
//          FCurrency := 'USD';
//        end;
//      1:
//        begin
//          FCurrency := 'CNY';
//        end;
//      2:
//        begin
//          FCurrency := 'EUR';
//        end;
//    end;
    show;
  end;
end;

procedure TfrmCustStatement.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=''RMB'' ';
      end;
    2:
      begin
        WSql := WSql + ' ,@Currency=''EUR'' ';
      end;
  end;

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

end;

procedure TfrmCustStatement.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=''RMB'' ';
      end;
    2:
      begin
        WSql := WSql + ' ,@Currency=''EUR'' ';
      end;
  end;

  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;

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

procedure TfrmCustStatement.ToolButton7Click(Sender: TObject);
begin
  CDS_HZ.DisableControls;
  with CDS_HZ do
  begin

    with ADOQueryCmd do
    begin
      close;
      sql.Clear;

//      sql.Add('exec P_Do_WXInsert_CW ');
//      sql.Add('@CKORDNO=' + quotedstr(trim(CDS_HZ.fieldbyname('fhsubid').AsString)));

      sql.Add(' exec  P_Do_WXInsert_CW  ');
      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(CDS_HZ.fieldbyname('oppcono').AsString)));
      sql.Add(',@oppconame=' + quotedstr(trim(CDS_HZ.fieldbyname('oppconame').AsString)));
      execsql;
    end;
    GetHTTP('http://www.rightsoft.top/hengyan/api/message/send/AcountStatement');
    Application.MessageBox('推送成功', '提示', 0);
  end;
  CDS_HZ.EnableControls;
//  InitGrid();

end;

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

end.

