unit U_GYSTopList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridCustomTableView, cxGridTableView,
  cxGridBandedTableView, cxGridDBBandedTableView, cxGridLevel, cxClasses,
  cxControls, cxGridCustomView, cxGridDBTableView, cxGrid, StdCtrls, ComCtrls,
  ExtCtrls, ToolWin, cxGridCustomPopupMenu, cxGridPopupMenu, ADODB, DBClient,
  cxDropDownEdit, MovePanel, Menus, cxCheckBox, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, RM_e_Xls, cxPC, cxLookAndFeels, cxLookAndFeelPainters,
  dxBarBuiltInMenu, cxNavigator;

type
  TfrmGYSTopList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    Label1: TLabel;
    KHName: TEdit;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    cxPageControl1: TcxPageControl;
    cxTabSheet1: TcxTabSheet;
    cxTabSheet2: TcxTabSheet;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column1: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1Column9: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    v1Column11: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    MovePanel2: TMovePanel;
    cxGridPopupMenu2: TcxGridPopupMenu;
    Label3: TLabel;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure KHNameChange(Sender: TObject);
    procedure cxPageControl1Change(Sender: TObject);
  private
    FLeft, FTop: Integer;
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
    FMainid, FSubId, FConNo, FColor, FCodeName: string;
  end;

var
  frmGYSTopList: TfrmGYSTopList;

implementation

uses
  U_DataLink, U_Fun;

{$R *.dfm}

procedure TfrmGYSTopList.FormDestroy(Sender: TObject);
begin
  frmGYSTopList := nil;
end;

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

procedure TfrmGYSTopList.InitGrid();
begin
  MovePanel2.Visible := True;
  MovePanel2.Refresh;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      SQL.Add('exec P_View_GYSTop :FYear,:CXState');
      Parameters.ParamByName('FYear').Value := Trim(FormatDateTime('yyyy', BegDate.Date));
      if cxPageControl1.ActivePageIndex = 0 then
      begin
        Parameters.ParamByName('CXState').Value := '月';
      end
      else
      begin
        Parameters.ParamByName('CXState').Value := '季度';
      end;
//      ShowMessage(Parameters.ParamByName('FYear').Value );
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
  MovePanel2.Visible := False;

end;

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

procedure TfrmGYSTopList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('Tv1', Tv1, '供应商排行');
  WriteCxGrid('Tv2', Tv2, '供应商排行');
  Close;
end;

procedure TfrmGYSTopList.FormShow(Sender: TObject);
begin
  BegDate.Date := SGetServerDate(ADOQueryTemp);
  ReadCxGrid('Tv1', Tv1, '供应商排行');
  ReadCxGrid('Tv2', Tv2, '供应商排行');
end;

procedure TfrmGYSTopList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  end;
end;

procedure TfrmGYSTopList.KHNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmGYSTopList.cxPageControl1Change(Sender: TObject);
begin
  InitGrid();
end;

end.

