unit U_PBTopMX;

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, cxDBLookupComboBox, cxContainer, cxDropDownEdit, cxPC, Menus,
  TeEngine, Series, TeeProcs, Chart, DbChart, GanttCh;

type
  TfrmPBTopMX = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    cxGridPopupMenu2: TcxGridPopupMenu;
    Panel2: TPanel;
    Panel3: TPanel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v2Column12: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    SH1: TPanel;
    ClientDataSet1: TClientDataSet;
    DataSource1: TDataSource;
    v1Column1: TcxGridDBColumn;
    DataSource3: TDataSource;
    ClientDataSet3: TClientDataSet;
    Panel1: TPanel;
    Label1: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    C_Code: TEdit;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Panel10: TPanel;
    ToolButton1: TToolButton;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
  private

    { Private declarations }
    procedure InitGrid();
  public
    FBegdate,FEnddate:TDate;
    FSPName:String;
   
  end;

var
  frmPBTopMX: TfrmPBTopMX;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}


procedure TfrmPBTopMX.InitGrid();
begin
  Panel10.Visible:=True;
  Panel10.Refresh;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('exec P_BI_CPAll_SHMX :begdate,:enddate,:SPName');
      Parameters.ParamByName('begdate').Value:=Trim(FormatDateTime('yyyy-MM-dd',FBegdate));
      Parameters.ParamByName('enddate').Value:=Trim(FormatDateTime('yyyy-MM-dd',FEnddate));;
      Parameters.ParamByName('SPName').Value:=FSPName;
      Open;
    end;
    SCreateCDS20(ADOQueryMain, ClientDataSet1);
    SInitCDSData20(ADOQueryMain, ClientDataSet1);
  finally
    ADOQueryMain.EnableControls;
  end;
  Panel10.Visible:=False;
end;

procedure TfrmPBTopMX.FormDestroy(Sender: TObject);
begin
  frmPBTopMX := nil;
end;

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

procedure TfrmPBTopMX.TBCloseClick(Sender: TObject);
begin
  //WriteCxGrid('收货', Tv1, '前十大产品排行榜');
  Close;
end;

procedure TfrmPBTopMX.FormShow(Sender: TObject);
begin
  //ReadCxGrid('收货', Tv1, '前十大产品排行榜');
  SH1.Caption:='坯布采购排行榜'+'  ( '+FSPName+' )  ';
  InitGrid();
end;

procedure TfrmPBTopMX.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
    BegDate.Date:=StrToDate(IntToStr(strtoint(FYear)-1)+'-02-01');
    EndDate.Date:=StrToDate(FYear+'-01-31');
  end else
  begin
    BegDate.Date:=StrToDate(FYear+'-02-01');
    EndDate.Date:=StrToDate(IntToStr(strtoint(FYear)+1)+'-01-31');
  end;  }
end;

procedure TfrmPBTopMX.ToolButton1Click(Sender: TObject);
begin
  TcxGridToExcel(Self.Caption,cxGrid1);
end;

end.

