unit U_WeiXinHelp;

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, cxDropDownEdit;

type
  TfrmWeiXinHelp = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_Help: TDataSource;
    CDS_Help: TClientDataSet;
    TBOK: TToolButton;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    v2Column1: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    Panel1: TPanel;
    Label3: TLabel;
    Label1: TLabel;
    ZdyName: TEdit;
    NICKNAME: TEdit;
    TBFind: TToolButton;
    TBRafresh: TToolButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBOKClick(Sender: TObject);
    procedure Tv2CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure NICKNAMEChange(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();

  public

  end;
var
  frmWeiXinHelp: TfrmWeiXinHelp;

implementation
uses
  U_DataLink,U_Fun;

{$R *.dfm}
procedure TfrmWeiXinHelp.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      Filtered:=False;
      SQL.Clear;
      sql.Add(' select A.OPENID,A.NICKNAME,A.SUBSCRIBE_TIME ');
      sql.Add(' from Weixin_Subscribe A ');
      sql.Add(' where A.ID=(select max(X.ID) as ID from Weixin_Subscribe X where X.OPENID=A.OPENID and X.STATUS=''关注'') ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Help);
    SInitCDSData20(ADOQueryMain,CDS_Help);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmWeiXinHelp.FormDestroy(Sender: TObject);
begin
  frmWeiXinHelp:=nil;
end;

procedure TfrmWeiXinHelp.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action:=cahide;
end;

procedure TfrmWeiXinHelp.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(self.Caption,Tv2,'客户自定义');
  Close;
end;
procedure TfrmWeiXinHelp.FormShow(Sender: TObject);
begin
  ReadCxGrid(self.Caption,Tv2,'客户自定义');
  InitGrid();

end;

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

procedure TfrmWeiXinHelp.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Help);
    SInitCDSData20(ADOQueryMain,CDS_Help);
  end;
end;

procedure TfrmWeiXinHelp.TBOKClick(Sender: TObject);
begin
  IF CDS_Help.IsEmpty then exit;
  self.ModalResult:=1;
end;

procedure TfrmWeiXinHelp.Tv2CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  tbok.Click;
end;

procedure TfrmWeiXinHelp.NICKNAMEChange(Sender: TObject);
begin
  TBfind.Click;
end;

end.
