unit U_BIHZList;

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, cxPC, RM_e_Xls, Menus, ComObj,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, cxGridBandedTableView,
  cxGridDBBandedTableView;

type
  FdDy = record
    inc: integer; //客户端套接字句柄
    FDdys: string[32]; //客户端套接字
    FdDysName: string[32]; //客户端套接字
  end;

  TfrmBIHZList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    Label2: TLabel;
    begdate10: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_FP: TDataSource;
    CDS_FP: TClientDataSet;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBBandedTableView;
    Tv1Column1: TcxGridDBBandedColumn;
    Tv1Column2: TcxGridDBBandedColumn;
    Tv1Column3: TcxGridDBBandedColumn;
    Tv1Column4: TcxGridDBBandedColumn;
    Tv1Column5: TcxGridDBBandedColumn;
    Tv1Column6: TcxGridDBBandedColumn;
    Tv1Column7: TcxGridDBBandedColumn;
    Panel10: TPanel;
    Tv1Column8: TcxGridDBBandedColumn;
    Tv1Column9: TcxGridDBBandedColumn;
    Tv1Column10: TcxGridDBBandedColumn;
    Tv1Column11: TcxGridDBBandedColumn;
    Tv1Column12: TcxGridDBBandedColumn;
    Tv1Column13: TcxGridDBBandedColumn;
    Tv1Column14: TcxGridDBBandedColumn;
    Tv1Column15: TcxGridDBBandedColumn;
    Tv1Column16: TcxGridDBBandedColumn;
    Tv1Column17: TcxGridDBBandedColumn;
    Tv1Column18: TcxGridDBBandedColumn;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBBandedTableView;
    cxGridDBBandedColumn1: TcxGridDBBandedColumn;
    cxGridDBBandedColumn2: TcxGridDBBandedColumn;
    cxGridDBBandedColumn3: TcxGridDBBandedColumn;
    cxGridDBBandedColumn4: TcxGridDBBandedColumn;
    cxGridDBBandedColumn5: TcxGridDBBandedColumn;
    cxGridDBBandedColumn6: TcxGridDBBandedColumn;
    cxGridDBBandedColumn7: TcxGridDBBandedColumn;
    cxGridDBBandedColumn8: TcxGridDBBandedColumn;
    cxGridDBBandedColumn9: TcxGridDBBandedColumn;
    cxGridDBBandedColumn10: TcxGridDBBandedColumn;
    cxGridDBBandedColumn11: TcxGridDBBandedColumn;
    cxGridDBBandedColumn12: TcxGridDBBandedColumn;
    cxGridDBBandedColumn13: TcxGridDBBandedColumn;
    cxGridDBBandedColumn14: TcxGridDBBandedColumn;
    cxGridDBBandedColumn15: TcxGridDBBandedColumn;
    cxGridDBBandedColumn16: TcxGridDBBandedColumn;
    cxGridDBBandedColumn17: TcxGridDBBandedColumn;
    cxGridDBBandedColumn18: TcxGridDBBandedColumn;
    cxGridLevel1: TcxGridLevel;
    DataSource2: TDataSource;
    ClientDataSet2: TClientDataSet;
    cxStyleRepository2: TcxStyleRepository;
    cxStyle2: TcxStyle;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure begdate10Change(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
  private
    { Private declarations }
    procedure InitGrid();
  public

    { Public declarations }
  end;

var
  frmBIHZList: TfrmBIHZList;

implementation

uses
  U_DataLink, U_Fun;

{$R *.dfm}



procedure TfrmBIHZList.InitGrid();
var
  QYear:string;
begin
  try
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      sql.Add(' exec P_BI_HZ :begdate');
      Parameters.ParamByName('begdate').Value:=Trim(formatdatetime('yyyy', begdate10.datetime));
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_FP);
    SInitCDSData20(ADOQueryMain, CDS_FP);
    QYear:=IntToStr(StrToInt(Trim(formatdatetime('yyyy', begdate10.datetime)))-1);
    Tv2.Bands[0].Caption:=QYear+'年';
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      sql.Add(' exec P_BI_HZ :begdate');
      Parameters.ParamByName('begdate').Value:=QYear;
      Open;
    end;
    SCreateCDS20(ADOQueryMain, ClientDataSet2);
    SInitCDSData20(ADOQueryMain, ClientDataSet2);
  finally

  end;
end;

procedure TfrmBIHZList.FormDestroy(Sender: TObject);
begin
  frmBIHZList := nil;
end;

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

procedure TfrmBIHZList.TBCloseClick(Sender: TObject);
begin
  //WriteCxBandedGrid('BIHZMonth', Tv1, 'BI');
  Close;
end;

procedure TfrmBIHZList.FormShow(Sender: TObject);
begin
  //ReadCxBandedGrid('BIHZMonth', Tv1, 'BI');
end;

procedure TfrmBIHZList.TBRafreshClick(Sender: TObject);
begin
  begdate10.SetFocus;
  Panel10.Visible:=True;
  Panel10.Refresh;
  InitGrid();
  Panel10.Visible:=False;
end;

procedure TfrmBIHZList.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  TcxGridToExcel(self.Caption, cxgrid1);
end;

procedure TfrmBIHZList.cxTabControl1Change(Sender: TObject);
begin
  initGrid();
end;

procedure TfrmBIHZList.Tv1DblClick(Sender: TObject);
begin
  {if CDS_FP.IsEmpty then Exit;
  if CDS_FP.fieldbyname('InvoiceNo').AsInteger=-1 then
  begin
    frmXJBXInPut := TfrmXJBXInPut.Create(self);
    with frmXJBXInPut do
    begin
      InvoiceNo.Enabled := False;
      FInvoiceNo := trim(CDS_FP.fieldbyname('InvoiceNo').asstring);
      ToolBar2.Visible:=False;
      frmXJBXInPut.TSave.Visible:=False;
      if showmodal = 1 then
      begin
        
      end;
      free;
    end;
  end; }
end;

procedure TfrmBIHZList.FormCreate(Sender: TObject);
var
  FYear:string;
  FMonth:string;
  FDate:TDate;
begin
  FDate:=SGetServerDate10(ADOQueryTemp);
  FYear:=FormatDateTime('yyyy',FDate);
  FMonth:=FormatDateTime('MM',FDate);
  if StrToInt(FMonth)<2 then
  begin
    BegDate10.Date:=StrToDate(IntToStr(strtoint(FYear)-1)+'-02-01');
  end else
  begin
    BegDate10.Date:=StrToDate(FYear+'-02-01');
  end;
  Tv1.Bands[0].Caption:=Trim(FormatDateTime('yyyy',begdate10.Date))+'年';
end;

procedure TfrmBIHZList.begdate10Change(Sender: TObject);
begin
  Tv1.Bands[0].Caption:=Trim(FormatDateTime('yyyy',begdate10.Date))+'年';
end;

procedure TfrmBIHZList.Tv1CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  ClientDataSet2.Locate('FMonth',CDS_FP.fieldbyname('FMonth').Value,[]);
  Tv2.Styles.Inactive:=cxStyle1;
  Tv2.Styles.IncSearch:=cxStyle1;
  Tv2.Styles.Selection:=cxStyle1;
end;

end.

