unit U_CarTKHZTop;

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, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator,dxCore,ActiveX;

type
  TfrmCarTKHZTop = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    cxGridPopupMenu2: TcxGridPopupMenu;
    ClientDataSet1: TClientDataSet;
    DataSource1: TDataSource;
    Panel1: TPanel;
    Label1: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    C_Code: TEdit;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    ToolButton1: TToolButton;
    ComboBox1: TComboBox;
    ClientDataSet3: TClientDataSet;
    DataSource3: TDataSource;
    Panel5: TPanel;
    Panel7: TPanel;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    Tv3Column2: TcxGridDBColumn;
    Tv3Column3: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    Tv3Column1: TcxGridDBColumn;
    Tv3Column4: TcxGridDBColumn;
    Tv3Column5: TcxGridDBColumn;
    v3Column1: TcxGridDBColumn;
    Tv3Column6: TcxGridDBColumn;
    Tv3Column7: TcxGridDBColumn;
    v3Column2: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    Panel3: TPanel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1XH: TcxGridDBColumn;
    v1FXH: TcxGridDBColumn;
    v2Column12: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    v2Column15: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    SH1: TPanel;
    Button1: TButton;
    Button2: TButton;
    Panel10: TPanel;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure C_CodeNameChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure Tv3DblClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private

    { Private declarations }
    procedure InitGrid();
  public
   
  end;

var
  frmCarTKHZTop: TfrmCarTKHZTop;

implementation

uses
  U_DataLink, U_RTFun,U_PBCarCPTopMX;

{$R *.dfm}


procedure TfrmCarTKHZTop.InitGrid();
begin
  Panel10.Visible:=True;
  Panel10.Refresh;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('exec P_BI_TKJView :begdate,:enddate');
      Parameters.ParamByName('begdate').Value:=Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date));
      Parameters.ParamByName('enddate').Value:=Trim(FormatDateTime('yyyy-MM-dd',enddate.Date+1));
      Open;
    end;
    SCreateCDS20(ADOQueryMain, ClientDataSet1);
    SInitCDSData20(ADOQueryMain, ClientDataSet1);

    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('exec P_BI_TKJView_Zu :begdate,:enddate');
      Parameters.ParamByName('begdate').Value:=Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date));
      Parameters.ParamByName('enddate').Value:=Trim(FormatDateTime('yyyy-MM-dd',enddate.Date+1));
      Open;
    end;
    SCreateCDS20(ADOQueryMain, ClientDataSet3);
    SInitCDSData20(ADOQueryMain, ClientDataSet3);


  finally
    ADOQueryMain.EnableControls;
  end;
  Panel10.Visible:=False;
end;

procedure TfrmCarTKHZTop.FormDestroy(Sender: TObject);
begin
  frmCarTKHZTop := nil;
end;

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

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

procedure TfrmCarTKHZTop.FormShow(Sender: TObject);
begin
  //ReadCxGrid('收货', Tv1, '前十大产品排行榜');
  v1FXH.Visible:=False;
  v1FXH.SortOrder:=soNone;
  v1XH.Visible:=True;
  v1XH.SortOrder:=soAscending;
end;

procedure TfrmCarTKHZTop.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
  v1FXH.Visible:=False;
  v1FXH.SortOrder:=soNone;
  v1XH.Visible:=True;
  v1XH.SortOrder:=soAscending;
  ClientDataSet1.Locate('XH',1,[]);
  SH1.Caption:='开机天数排行榜';
end;

procedure TfrmCarTKHZTop.ToolButton2Click(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, ClientDataSet1);
    SInitCDSData20(ADOQueryMain, ClientDataSet1);
  end;
end;

procedure TfrmCarTKHZTop.C_CodeNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmCarTKHZTop.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;
  EndDate.Date:=SGetServerDate(ADOQueryTemp);
end;

procedure TfrmCarTKHZTop.ToolButton1Click(Sender: TObject);
begin
  if ComboBox1.Text='' then Exit;
  if ComboBox1.ItemIndex=0 then
  begin
    TcxGridToExcel(ComboBox1.Text,cxGrid1);
  end else
  if ComboBox1.ItemIndex=1 then
  begin
    TcxGridToExcel(ComboBox1.Text,cxGrid3);
  end;
end;

procedure TfrmCarTKHZTop.Tv1DblClick(Sender: TObject);
begin
  if ClientDataSet1.IsEmpty then Exit;
  try
    frmPBCarCPTopMX:=TfrmPBCarCPTopMX.Create(Application);
    with frmPBCarCPTopMX do
    begin
      FBegdate:=Self.BegDate.Date;
      FEnddate:=Self.EndDate.Date;
      FCarNo:=Trim(Self.ClientDataSet1.fieldbyname('CarNo').AsString);
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmPBCarCPTopMX.Free;
  end;
end;

procedure TfrmCarTKHZTop.Tv3DblClick(Sender: TObject);
begin
  if ClientDataSet3.IsEmpty then Exit;
  try
    frmPBCarCPTopMX:=TfrmPBCarCPTopMX.Create(Application);
    with frmPBCarCPTopMX do
    begin
      FBegdate:=Self.BegDate.Date;
      FEnddate:=Self.EndDate.Date;
      FCarNo:=Trim(Self.ClientDataSet3.fieldbyname('CarNo').AsString);
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmPBCarCPTopMX.Free;
  end;
end;

procedure TfrmCarTKHZTop.Button1Click(Sender: TObject);
begin
  v1FXH.Visible:=False;
  v1FXH.SortOrder:=soNone;
  v1XH.Visible:=True;
  v1XH.SortOrder:=soAscending;
  ClientDataSet1.Locate('XH',1,[]);
  SH1.Caption:='开机天数排行榜';
end;

procedure TfrmCarTKHZTop.Button2Click(Sender: TObject);
begin
  v1FXH.Visible:=True;
  v1XH.Visible:=false;
  v1XH.SortOrder:=soNone;
  v1FXH.SortOrder:=soAscending;
  ClientDataSet1.Locate('FXH',1,[]);
  SH1.Caption:='停机天数排行榜';
end;

end.

