unit U_YWYTop;

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
  TfrmYWYTop = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    cxGridPopupMenu2: TcxGridPopupMenu;
    Panel2: TPanel;
    Panel3: TPanel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v2Column12: TcxGridDBColumn;
    v2Column15: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    SH1: TPanel;
    ClientDataSet1: TClientDataSet;
    DataSource1: TDataSource;
    DataSource2: TDataSource;
    ClientDataSet2: TClientDataSet;
    Panel10: TPanel;
    Panel1: TPanel;
    Label1: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    C_Code: TEdit;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    v1Column2: TcxGridDBColumn;
    HZ: TPanel;
    v1Column1: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    Panel4: TPanel;
    Panel5: TPanel;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Panel6: TPanel;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridDBColumn16: TcxGridDBColumn;
    cxGridDBColumn17: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    Panel7: TPanel;
    cxGrid4: TcxGrid;
    Tv4: TcxGridDBTableView;
    cxGridDBColumn18: TcxGridDBColumn;
    cxGridDBColumn19: TcxGridDBColumn;
    cxGridDBColumn20: TcxGridDBColumn;
    cxGridDBColumn21: TcxGridDBColumn;
    cxGridDBColumn22: TcxGridDBColumn;
    cxGridDBColumn23: TcxGridDBColumn;
    cxGridDBColumn24: TcxGridDBColumn;
    cxGridDBColumn25: TcxGridDBColumn;
    cxGridLevel4: TcxGridLevel;
    cxGridPopupMenu3: TcxGridPopupMenu;
    ClientDataSet3: TClientDataSet;
    DataSource3: TDataSource;
    cxGridPopupMenu4: TcxGridPopupMenu;
    ClientDataSet4: TClientDataSet;
    DataSource4: TDataSource;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v3Column1: TcxGridDBColumn;
    v3Column2: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v4Column1: TcxGridDBColumn;
    v4Column2: TcxGridDBColumn;
    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 Tv1DblClick(Sender: TObject);
    procedure Tv2DblClick(Sender: TObject);
    procedure Tv3DblClick(Sender: TObject);
    procedure Tv4DblClick(Sender: TObject);
  private

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

var
  frmYWYTop: TfrmYWYTop;

implementation

uses
  U_DataLink, U_RTFun,U_YWYTopMX,U_YWYTopKH;

{$R *.dfm}


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

    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('exec P_Get_YWYLiDanTop :begdate,:enddate,:BZType,:Type');
      Parameters.ParamByName('begdate').Value:=Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date));
      Parameters.ParamByName('enddate').Value:=Trim(FormatDateTime('yyyy-MM-dd',enddate.Date+1));
      Parameters.ParamByName('BZType').Value:='￥';
      Parameters.ParamByName('Type').Value:='业务员';
      Open;
    end;
    SCreateCDS20(ADOQueryMain, ClientDataSet2);
    SInitCDSData20(ADOQueryMain, ClientDataSet2);

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

    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('exec P_Get_YWYLiDanTop :begdate,:enddate,:BZType,:Type');
      Parameters.ParamByName('begdate').Value:=Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date));
      Parameters.ParamByName('enddate').Value:=Trim(FormatDateTime('yyyy-MM-dd',enddate.Date+1));
      Parameters.ParamByName('BZType').Value:='￥';
      Parameters.ParamByName('Type').Value:='理单';
      Open;
    end;
    SCreateCDS20(ADOQueryMain, ClientDataSet4);
    SInitCDSData20(ADOQueryMain, ClientDataSet4);
  finally
    ADOQueryMain.EnableControls;
  end;
  Panel10.Visible:=False;
end;

procedure TfrmYWYTop.FormDestroy(Sender: TObject);
begin
  frmYWYTop := nil;
end;

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

procedure TfrmYWYTop.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('YWYTopMJ12', Tv1, '排行榜');
  WriteCxGrid('YWYTopRMB12', Tv2, '排行榜');
  WriteCxGrid('YWYTopRMB11', Tv3, '排行榜');
  WriteCxGrid('YWYTopRMB11', Tv4, '排行榜');
  Close;
end;

procedure TfrmYWYTop.FormShow(Sender: TObject);
begin
  ReadCxGrid('YWYTopMJ12', Tv1, '排行榜');
  ReadCxGrid('YWYTopRMB12', Tv2, '排行榜');
  ReadCxGrid('YWYTopRMB11', Tv3, '排行榜');
  ReadCxGrid('YWYTopRMB11', Tv4, '排行榜');
end;

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

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

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

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

procedure TfrmYWYTop.Tv1DblClick(Sender: TObject);
begin
  if ClientDataSet1.IsEmpty then Exit;
  try
    frmYWYTopKH:=TfrmYWYTopKH.Create(Application);
    with frmYWYTopKH do
    begin
      FBegdate:=Self.BegDate.Date;
      FEnddate:=Self.EndDate.Date;
      FMXName:=Trim(Self.ClientDataSet1.fieldbyname('YWY').AsString);
      FType:='业务员';
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmYWYTopKH.Free;
  end;
  {try
    frmYWYTopMX:=TfrmYWYTopMX.Create(Application);
    with frmYWYTopMX do
    begin
      FBegdate:=Self.BegDate.Date;
      FEnddate:=Self.EndDate.Date;
      FMXName:=Trim(Self.ClientDataSet1.fieldbyname('YWY').AsString);
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmYWYTopMX.Free;
  end; }
end;

procedure TfrmYWYTop.Tv2DblClick(Sender: TObject);
begin
  if ClientDataSet2.IsEmpty then Exit;
  try
    frmYWYTopKH:=TfrmYWYTopKH.Create(Application);
    with frmYWYTopKH do
    begin
      FBegdate:=Self.BegDate.Date;
      FEnddate:=Self.EndDate.Date;
      FMXName:=Trim(Self.ClientDataSet2.fieldbyname('YWY').AsString);
      FType:='业务员';
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmYWYTopKH.Free;
  end;
end;

procedure TfrmYWYTop.Tv3DblClick(Sender: TObject);
begin
  if ClientDataSet3.IsEmpty then Exit;
  try
    frmYWYTopKH:=TfrmYWYTopKH.Create(Application);
    with frmYWYTopKH do
    begin
      FBegdate:=Self.BegDate.Date;
      FEnddate:=Self.EndDate.Date;
      FMXName:=Trim(Self.ClientDataSet3.fieldbyname('YWY').AsString);
      FType:='理单';
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmYWYTopKH.Free;
  end;
end;

procedure TfrmYWYTop.Tv4DblClick(Sender: TObject);
begin
  if ClientDataSet4.IsEmpty then Exit;
  try
    frmYWYTopKH:=TfrmYWYTopKH.Create(Application);
    with frmYWYTopKH do
    begin
      FBegdate:=Self.BegDate.Date;
      FEnddate:=Self.EndDate.Date;
      FMXName:=Trim(Self.ClientDataSet4.fieldbyname('YWY').AsString);
      FType:='理单';
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmYWYTopKH.Free;
  end;
end;

end.

