unit U_GDXSETJList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, DBClient, cxCheckBox, cxCalendar, cxSplitter, RM_Dataset, RM_System,
  RM_Common, RM_Class, RM_GridReport, RM_e_Xls, Menus, MovePanel, cxTextEdit,
  cxContainer, cxCurrencyEdit, BtnEdit, RM_e_main, RM_e_htm, RM_e_Graphic,
  RM_e_Jpeg, RM_e_txt, RM_e_csv, RM_E_llPDF, Math, Clipbrd, cxPC, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu, DateUtils,
  dxSkinsCore, dxSkinsDefaultPainters, dxSkinscxPCPainter;

type
  TfrmGDXSETJList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DS_2: TDataSource;
    TBExport: TToolButton;
    CDS_2: TClientDataSet;
    RM2: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    ADOQueryPrint: TADOQuery;
    RMXLSExport1: TRMXLSExport;
    Panel1: TPanel;
    Label3: TLabel;
    Label11: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_1: TClientDataSet;
    DS_1: TDataSource;
    cxGridPopupMenu2: TcxGridPopupMenu;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column19: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label1: TLabel;
    huilv: TEdit;
    gdy: TComboBox;
    Tv1Column2: TcxGridDBColumn;
    Label2: TLabel;
    leader: TComboBox;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure gdyKeyPress(Sender: TObject; var Key: Char);
    procedure cxPageControl1Change(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure gdyChange(Sender: TObject);
  private
    DQdate: TDateTime;
    FLeft, FTop: Integer;
    CurrentPage, RecordsNumber: Integer;
    procedure InitGrid();
    procedure SetStatus();
    { Private declarations }
  public
    FFInt: Integer;
    canshu1: string;
    { Public declarations }
  end;

var
  frmGDXSETJList: TfrmGDXSETJList;

implementation

uses
  U_DataLink, U_Fun;

{$R *.dfm}
procedure TfrmGDXSETJList.SetStatus();
var
  i: Integer;
begin

end;

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

procedure TfrmGDXSETJList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('跟单销售额统计表', Tv1, '进度管理');

  Close;
end;

procedure TfrmGDXSETJList.InitGrid();
var
  fwhere, Pwhere: string;
  freal: double;
begin
  if TryStrToFloat(huilv.Text, freal) = False then
  begin
    application.MessageBox('汇率格式不正确！', '提示信息');
    Exit;
  end;
  if huilv.Text = '0' then
  begin
    application.MessageBox('汇率格式不正确！', '提示信息');
    Exit;
  end;
  Pwhere := SGetFilters(Panel1, 1, 2);

  try
    ADOQueryMain.DisableControls;

    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('exec P_View_GDXSTJLIST ');
      sql.Add('@BegDate=' + quotedstr(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)));
      sql.Add(',@EndDate=' + quotedstr(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1)));
      sql.Add(',@huilv= ' + (huilv.Text));
//      ShowMessage(SQL.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_2);
    SInitCDSData20(ADOQueryMain, CDS_2);

  finally
    ADOQueryMain.EnableControls;
  end;

end;

procedure TfrmGDXSETJList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  SelExportData(Tv1, ADOQueryMain, Self.Caption);
end;

procedure TfrmGDXSETJList.TBRafreshClick(Sender: TObject);
begin

  InitGrid();
end;

procedure TfrmGDXSETJList.FormCreate(Sender: TObject);
var
  fsj: string;
begin
  ReadCxGrid('跟单销售额统计表', Tv1, '进度管理');

//  fsj := 'select distinct(Filler) name from WFB_MJJY   ';
//  SInitComBoxBySql(ADOQueryCmd, JYER, False, fsj);

  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime := StartOfTheYear(Now);
end;

procedure TfrmGDXSETJList.FormDestroy(Sender: TObject);
begin
  frmGDXSETJList := nil;
end;

procedure TfrmGDXSETJList.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  AssignmentControls(Panel1, CDS_1, '0');

end;

procedure TfrmGDXSETJList.gdyKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    InitGrid();
  end;
end;

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

procedure TfrmGDXSETJList.FormShow(Sender: TObject);
var
  fsj, fsj2: string;
begin
  fsj := 'select distinct gdy as name  from jyorder_main order by gdy    ';
  SInitComBoxBySql(ADOQueryCmd, gdy, False, fsj);

  fsj2 := 'select distinct ywy as name  from V_YWYNAME order by ywy    ';
  SInitComBoxBySql(ADOQueryCmd, leader, False, fsj2);
  SetStatus();
  InitGrid();
end;

procedure TfrmGDXSETJList.gdyChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, CDS_2);
    SInitCDSData20(ADOQueryMain, CDS_2);
  end;
end;

end.

