unit U_wechatSel;

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, ComObj, cxLookAndFeels, cxLookAndFeelPainters,
  dxSkinsCore, dxSkinsDefaultPainters, cxNavigator, dxDateRanges, U_BaseHelp,
  dxBarBuiltInMenu, System.ImageList, Vcl.ImgList, dxScrollbarAnnotations;

type
  FdDy = record
    inc: integer; //客户端套接字句柄
    FDdys: string[32]; //客户端套接字
    FdDysName: string[32]; //客户端套接字
  end;

  TfrmwechatSel = class(TfrmBaseHelp)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    Label3: TLabel;
    UserName: TEdit;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_1: TDataSource;
    CDS_1: TClientDataSet;
    Label1: TLabel;
    UserID: TEdit;
    btnOK: TToolButton;
    v2Column1: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    ADOConnection1: TADOConnection;
    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 UserNameChange(Sender: TObject);
    procedure btnOKClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
  private

    { Private declarations }
    procedure InitGrid();
  public
    Fdept: string;
    FMultiple: Boolean;
  end;

var
  frmwechatSel: TfrmwechatSel;

implementation

uses
  U_DataLink, U_RTFun, U_UserSel;

{$R *.dfm}

procedure TfrmwechatSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      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;
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmwechatSel.FormCreate(Sender: TObject);
begin
  inherited;
  try
    with ADOConnection1 do
    begin
      Connected := false;
      ConnectionString := DConString;
      Connected := true;
    end;
    ADOQueryBaseCmd.Connection := ADOConnection1;
    ADOQueryBaseTemp.Connection := ADOConnection1;
  except
    application.MessageBox('网络连接失败！', '提示信息');
  end;
end;

procedure TfrmwechatSel.FormDestroy(Sender: TObject);
begin
  inherited;
  frmwechatSel := nil;
end;

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

procedure TfrmwechatSel.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(trim(self.caption), Tv1, '账户选择');
  Close;
end;

procedure TfrmwechatSel.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(trim(self.Caption), Tv1, '账户选择');

  InitGrid();
end;

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

procedure TfrmwechatSel.ToolButton2Click(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  end;
end;

procedure TfrmwechatSel.Tv1DblClick(Sender: TObject);
begin

  ModalResult := 1;
end;

procedure TfrmwechatSel.UserNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmwechatSel.btnOKClick(Sender: TObject);
begin
  ModalResult := 1;
end;

end.

