unit U_GDQSList;

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, cxCalendar, cxButtonEdit, cxSplitter,
  RM_Common, RM_Class, RM_e_Xls, RM_Dataset, RM_System, RM_GridReport,
  cxTextEdit, cxDropDownEdit, cxCheckBox,ShellAPI;

type
  TfrmGDQSList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Label1: TLabel;
    Label2: TLabel;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    UserName: TEdit;
    Order_Main: TClientDataSet;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1Column4: TcxGridDBColumn;
    ToolButton1: TToolButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure UserNameChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
  private
    FInt,PFInt:Integer;
    procedure InitGrid();
    procedure InitForm();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmGDQSList: TfrmGDQSList;

implementation
uses
  U_DataLink,U_ZDYHelp,U_RTFun;

{$R *.dfm}

procedure TfrmGDQSList.FormDestroy(Sender: TObject);
begin
  frmGDQSList:=nil;
end;

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

procedure TfrmGDQSList.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('跟单签到',Tv1,'跟单管理');
end;

procedure TfrmGDQSList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      SQL.Add('select A.*,Qd_time=rq+'' ''+sj  from sy_user_signin A');
      SQL.Add(' where A.rq>='''+Trim(FormatDateTime('yyyyMMdd',BegDate.DateTime))+''' ');
      SQL.Add(' and A.rq<='''+Trim(FormatDateTime('yyyyMMdd',Enddate.DateTime+1))+''' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmGDQSList.InitForm();
begin
  ReadCxGrid('跟单签到',Tv1,'跟单管理');
  BegDate.DateTime:=SGetServerDate10(ADOQueryTemp)-7;
  EndDate.DateTime:=SGetServerDate10(ADOQueryTemp);
  InitGrid();
end;

procedure TfrmGDQSList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

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

procedure TfrmGDQSList.UserNameChange(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

procedure TfrmGDQSList.FormShow(Sender: TObject);
begin
  InitForm();
end;

procedure TfrmGDQSList.Tv1DblClick(Sender: TObject);
var
  link:string;
begin
  with Order_Main do
  begin
//    link:='https://www.rightsoft001.top/mrqd.php';
//    link:=link+'?user_id='+trim(fieldbyname('UserID').AsString);
//    link:=link+'&ksrq='+Trim(FormatDateTime('yyyy-MM-dd',fieldbyname('Qd_time').AsDateTime));
//    link:=link+'&jsrq='+Trim(FormatDateTime('yyyy-MM-dd',fieldbyname('Qd_time').AsDateTime));
    link:='https://uri.amap.com/marker?position='
    +trim(fieldbyname('longitude').AsString)+','+trim(fieldbyname('latitude').AsString);
  end;
  ShellExecute(Handle,'open',PChar(link),'', '', SW_SHOWNORMAL);
end;

procedure TfrmGDQSList.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  TcxGridToExcel(Self.Caption,cxGrid1);
end;

end.
