cformvisit.~pas

来自「Delphi深度探索,Delphi深度探索(第二版)」· ~PAS 代码 · 共 94 行

~PAS
94
字号
unit CFormVisit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, CFormBase, CFrameMenu, IWControl, IWCompLabel, IWExtCtrls, jpeg,
  IWBaseControl, IWCompDynamicChart, IWGrids, IWDBGrids, IWDBStdCtrls,
  IWHTMLControls, IWCompText;

type
  TformVisit = class(TformBase)
    iwdgVisit: TIWDBGrid;
    IWDBNavigator1: TIWDBNavigator;
    IWLabel1: TIWLabel;
    iwtUsers: TIWText;
    iwlExcel: TIWLink;
    procedure IWAppFormCreate(Sender: TObject);
    procedure iwlExcelClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  formVisit: TformVisit;

implementation

uses DatamoduleUnit, IWApplication, ServerController;

{$R *.dfm}

procedure TformVisit.IWAppFormCreate(Sender: TObject);
var
  SessionList:TList;
  UserSession:TUserSession;
  I:Integer;
  S:string;
begin
  inherited;
  with dmHr do
  begin
    badoOperator.Active:=False;
    badoOperator.Active:=True;
  end;
  SessionList:=GSessions.LockList;
  try
    s:='';
    for I:=0 to SessionList.Count-1 do
    begin
      UserSession:=TUserSession(TIWApplication(SessionList.Items[I]).Data);
      //获得用户名称
      with dmHR do
      begin
        badoQuery.Active:=False;
        badoQuery.CommandText:='Select OperName from TblOperator where OperId='+IntToStr(UserSession.Id);
        badoQuery.Active:=True;
        if badoQuery.RecordCount>0 then
          s:=s+(badoQuery.FieldByName('Opername').AsString)+'.';
      end;
    end;
    iwtUsers.lines.text:='<marquee bgcolor="#00FFFF">'+s+'</marquee>';    
  finally
    GSessions.UnlockList;
  end;
end;

procedure TformVisit.iwlExcelClick(Sender: TObject);
//返回Excel文件
var
  strExcel:string;
  Stream:TStringStream;
  I:Integer;
begin
  inherited;
  strExcel:='';
  strExcel:=strExcel+'<tr><td>用户名</td><td>访问次数</td></tr>'+#13#10;
  with dmHR do
  begin
    badoQuery.Active:=False;
    badoQuery.CommandText:='Select * from TblOperator';
    badoQuery.Active:=True;
    for I:=0 to badoQuery.RecordCount-1 do
      strExcel:=strExcel+Format('<tr><td>%s</td><td>%d</td></tr>'+#13#10, [badoQuery.FieldByName('OperName').asString, badoQuery.FieldByName('VisitTimes').AsInteger]);
  end;
  strExcel:=Format('<table border="1">%s</table>', [strExcel]);
  Stream:=TStringStream.Create(strExcel);  
  WebApplication.SendStream(Stream, 'application/vnd.ms-excel', '', false);
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?