高分 求 ASPNET 论坛会员在线源码

Xpengfee 2006-11-16 08:54:09
小弟最近在负责开发一个论坛,大部分程序已成型。现在就卡在 查看论坛会员在线情况 这一功能上,试过几种方法总是感觉不对,诚心恳求大虾们给份源码吧。。。。。。。。。
xpengfee@163.com
...全文
246 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
tianzhenjing 2006-11-28
  • 打赏
  • 举报
回复
//功能说明:更新用户在线时间
//返回值:最新的在线用户列表
public bool checkuseronline(string name, string iswhere, string sessionid, string ip,string cBrowser)
{
#if debug
(new sohoproject.sohodebug()).writetodoc("开始进入检查用户方法....");
(new sohoproject.sohodebug()).writetodoc("");
#endif

//需要先判断用户是否已经在用户列表中了
user newuser = new user();
newuser.name = name;
newuser.iswhere = iswhere;
newuser.lasttime = newuser.curtime = DateTime.Now;
newuser.sessionid = sessionid;
newuser.ip = ip;
newuser.cBrowser = cBrowser;

onlineuser alluser = new onlineuser();
alluser.AddUserToOnline(newuser);


#if debug
(new sohoproject.sohodebug()).writetodoc("离开检查用户方法....");
#endif

return true;
}
}



//定义在线用户类
public class onlineuser_old
{
private static ArrayList _alluser ; //定义用户

public ArrayList alluser
{
get{return _alluser;}
set{_alluser=value;}
}

public onlineuser_old() //构造函数
{
if(_alluser==null)
{
_alluser=new ArrayList();
}
}

//功能说明:将当前用户加入在线列表
//如果该用户的数据当前仍然在在线列表中,则暂时先不让该用户登陆,提示用户存在
public bool addusertoonline(user user)
{
//需要先判断用户是否已经在用户列表中了
if (_alluser == null)
{
_alluser.Add(user);
return (true);
}
else
{
for (int i = 0; i < _alluser.Count; i++)
{
//循环判断用户是否已经存在
BBS.BusinessLogicLayer.user tempuser = (BBS.BusinessLogicLayer.user)_alluser[i];

if (tempuser.sessionid.Equals(user.sessionid))
{
//更新用户在线时间
tempuser.name = user.name;
tempuser.curtime = DateTime.Now;
tempuser.iswhere = user.iswhere;
tempuser.sessionid = user.sessionid;
tempuser.ip = user.ip;
tempuser.cBrowser = user.cBrowser;
alluser[i] = tempuser;
return (true);
//return(true); //用户已经存在,则直接退出 }
}
_alluser.Add(user);

}
return (true);
}
}

//功能说明:判断某用户是否在线,本部分暂时不用
//返回值:true代表在线,false不在
public bool IsSessionOnline(string paraSessionID)
{
//需要先判断用户是否已经在用户列表中了
if (_alluser == null)
{
return (false);
}
else
{
for (int i = 0; i < _alluser.Count; i++)
{
//循环判断用户是否已经存在
BBS.BusinessLogicLayer.user tempuser = (BBS.BusinessLogicLayer.user)_alluser[i];
if (tempuser.sessionid.ToLower().Equals(paraSessionID.ToLower().ToLower()))
{
return (true);
}
}
return (false);
}
}


//功能说明:判断某用户是否在线,本部分暂时不用
//返回值:true代表在线,false不在
public bool IsUserOnline(string name)
{
//需要先判断用户是否已经在用户列表中了
if(_alluser==null)
{
return (false);
}
else
{
for ( int i = 0 ; i < _alluser.Count ; i ++)
{
//循环判断用户是否已经存在
BBS.BusinessLogicLayer.user tempuser= (BBS.BusinessLogicLayer.user)_alluser[i];
if(tempuser.name.ToLower().Equals(name.ToLower()))
{
return(true) ;
}
}
return (false);
}
}

//功能说明:更新用户在线时间
//返回值:最新的在线用户列表
public bool checkuseronline(string name,string iswhere,string sessionid,string ip,string cBrowser)
{
//需要先判断用户是否已经在用户列表中了
if(_alluser!=null)
{
user newuser=new user();
newuser.name= name;
newuser.iswhere= iswhere;
newuser.lasttime=newuser.curtime=DateTime.Now;
newuser.sessionid=sessionid;
newuser.ip=ip;
newuser.cBrowser = cBrowser;

//onlineuser alluser= new onlineuser();
addusertoonline(newuser);
}
return(false);
}
}

/*
下面开始建立守护线程类:
(注:此处,开始写的时候本来想做成单件模式的,不过由于以前没有做过这个东西,所以反而发生
了很多问题,最后决定放弃而使用现有的格式)
*/
public class checkonline
{
const int delay_times = 10000; //定义执行的时间间隔为5秒
const int delay_seconds = 60; //将用户掉线时间设置为30秒

private Thread thread; //定义内部线程

private static bool _flag = false; //定义唯一标志

public checkonline()
{
if (!_flag)
{
_flag = true;
this.thread = new Thread(new ThreadStart(threadproc));
thread.Name = "online user";
thread.Start();
}
}


internal void threadproc()
{
while (true)
{
// sohoproject.onlineuser temp=new sohoproject.onlineuser(); //定义一个用户对象
// for (int i=0 ;i< temp.alluser.count;i++)
// {
// user tmpuser=(user)temp.alluser[i];
// //我是将该用户的最新时间加上30秒,然后和当前时间比较,小与当前时间,
// //则表示该用户已经吊线,则删除他的记录
// if(tmpuser.curtime.addseconds(delay_seconds).compareto(datetime.now)<0)
// {
// temp.alluser.removeat(i);
// }
// }
BBS.BusinessLogicLayer.onlineuser temp = new BBS.BusinessLogicLayer.onlineuser();//定义一个用户对象
//开始检查是否有用户过期了
string strexpr;
//tmpuser.curtime.addseconds(delay_seconds).compareto(datetime.now)<0
strexpr = "curtime < '" + DateTime.Now.AddSeconds(0 - delay_seconds) + "'";
#if debug
(new sohoproject.sohodebug()).writetodoc(strexpr);
#endif

DataRow[] curuser;
// use the select method to find all rows matching the filter.
curuser = temp.alluser.Select(strexpr);

if (curuser.Length > 0)
{
//删除这些记录
for (int i = 0; i < curuser.Length; i++)
{
curuser[i].Delete();
}
temp.alluser.AcceptChanges();
}
//thread.sleep(delay_times);
}
}
}


}
tianzhenjing 2006-11-28
  • 打赏
  • 举报
回复
public bool UpdateNameOnline(user user)
{
#if debug
(new sohoproject.sohodebug()).writetodoc("开始进入<将当前用户加入在线列表>....");
(new sohoproject.sohodebug()).writetodoc("\r\n");
#endif


//开始搜索是否已经存在该用户,如果存在则是改变数据,否则添加新的用户
string strexpr;
strexpr = "name='" + user.name + "'";
DataRow[] curuser;
// use the select method to find all rows matching the filter.
#if debug
(new sohoproject.sohodebug()).writetodoc("搜索字符串:" + strexpr);
(new sohoproject.sohodebug()).writetodoc("\r\n");
#endif


curuser = _alluser.Select(strexpr);

#if debug
(new sohoproject.sohodebug()).writetodoc(strexpr);
(new sohoproject.sohodebug()).writetodoc(curuser.length.tostring());
#endif


if (curuser.Length > 0)
{
for (int i = 0; i < curuser.Length; i++)
{
curuser[i]["name"] = user.name;
curuser[i]["RoleCode"] = user.RoleCode;
curuser[i]["NickName"] = user.NickName;
curuser[i]["Code"] = user.Code;
curuser[i]["curtime"] = DateTime.Now;
curuser[i]["lasttime"] = DateTime.Now;
curuser[i]["iswhere"] = user.iswhere;
curuser[i]["ip"] = user.ip;
curuser[i]["curtime"] = DateTime.Now;
curuser[i]["cBrowser"] = user.cBrowser;
}
}
_alluser.AcceptChanges();
return true;
}

//功能说明:
public bool UpdateUserWhere(user user)
{
#if debug
(new sohoproject.sohodebug()).writetodoc("开始进入<将当前用户加入在线列表>....");
(new sohoproject.sohodebug()).writetodoc("\r\n");
#endif


//开始搜索是否已经存在该用户,如果存在则是改变数据,否则添加新的用户
string strexpr;
strexpr = "name='" + user.name + "'";
DataRow[] curuser;
// use the select method to find all rows matching the filter.
#if debug
(new sohoproject.sohodebug()).writetodoc("搜索字符串:" + strexpr);
(new sohoproject.sohodebug()).writetodoc("\r\n");
#endif

string a= "";
for (int i = 0; i < _alluser.Rows.Count; i++)
{
a = _alluser.Rows[i]["name"].ToString();
}

curuser = _alluser.Select(strexpr);

#if debug
(new sohoproject.sohodebug()).writetodoc(strexpr);
(new sohoproject.sohodebug()).writetodoc(curuser.length.tostring());
#endif


if (curuser.Length > 0)
{
for (int i = 0; i < curuser.Length; i++)
{
curuser[i]["curtime"] = DateTime.Now;
curuser[i]["iswhere"] = user.iswhere;
}
}
_alluser.AcceptChanges();
return true;
}

//功能说明:将当前用户加入在线列表
//如果该用户的数据当前仍然在在线列表中,则暂时先不让该用户登陆,提示用户存在
public bool AddUserToOnline(user user)
{
#if debug
(new sohoproject.sohodebug()).writetodoc("开始进入<将当前用户加入在线列表>....");
(new sohoproject.sohodebug()).writetodoc("\r\n");
#endif


//开始搜索是否已经存在该用户,如果存在则是改变数据,否则添加新的用户
string strexpr;
strexpr = "sessionid='" + user.sessionid + "'";
DataRow[] curuser;
// use the select method to find all rows matching the filter.
#if debug
(new sohoproject.sohodebug()).writetodoc("搜索字符串:" + strexpr);
(new sohoproject.sohodebug()).writetodoc("\r\n");
#endif


curuser = _alluser.Select(strexpr);

#if debug
(new sohoproject.sohodebug()).writetodoc(strexpr);
(new sohoproject.sohodebug()).writetodoc(curuser.length.tostring());
#endif


if (curuser.Length > 0)
{
for (int i = 0; i < curuser.Length; i++)
{
curuser[i]["curtime"] =DateTime.Now;
curuser[i]["iswhere"] = user.iswhere;
}
}
else
{
//直接加入新的数据
DataRow myrow;
try
{
myrow = _alluser.NewRow();
// then add the new row to the collection.
myrow["name"] = user.name;
myrow["RoleCode"] = user.RoleCode;
myrow["NickName"] = user.NickName;
myrow["Code"] = user.Code;
myrow["ip"] = user.ip;
myrow["iswhere"] = user.iswhere;
myrow["lasttime"] = user.lasttime;
myrow["curtime"] = DateTime.Now;
myrow["sessionid"] = user.sessionid;
myrow["cBrowser"] = user.cBrowser;
_alluser.Rows.Add(myrow);
}
catch (Exception e)
{
throw (new Exception(e + "--------------------" + e.ToString()));
}
}
_alluser.AcceptChanges();
return true;
}

//功能说明:判断某用户是否在线,本部分暂时不用
//返回值:true代表在线,false不在
public bool IsSessionOnline(string paraSessionID)
{
//需要先判断用户是否已经在用户列表中了
//开始搜索是否已经存在该用户,如果存在则是改变数据,否则添加新的用户
string strexpr;
strexpr = "sessionid ='" + paraSessionID + "'";
DataRow[] curuser;
// use the select method to find all rows matching the filter.
curuser = _alluser.Select(strexpr);

if (curuser.Length > 0)
{
return true;
}
else
{
return false;
}
}

//功能说明:判断某用户是否在线,本部分暂时不用
//返回值:true代表在线,false不在
public bool IsUserOnline(string name)
{
//需要先判断用户是否已经在用户列表中了
//开始搜索是否已经存在该用户,如果存在则是改变数据,否则添加新的用户
//string strexpr;
// //strexpr = "name ='" + name + "'";
// DataRow[] curuser;
// use the select method to find all rows matching the filter.
//curuser = _alluser.Select(strexpr);
string a = "";
for (int i = 0; i < _alluser.Rows.Count; i++)
{
if (_alluser.Rows[i]["name"].ToString() == name)
{
a = _alluser.Rows[i]["name"].ToString();
break;
}
}

if (a !="")
{
return true;
}
else
{
return false;
}
}
tianzhenjing 2006-11-28
  • 打赏
  • 举报
回复
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Threading;
using System.Diagnostics;
using System.Data.SqlClient;

namespace BBS.BusinessLogicLayer
{
//定义了一个结构
public struct user
{
public string name;
public string NickName;
public string RoleCode;
public string Code;
public DateTime lasttime;
public DateTime curtime;
public string sessionid;
public string ip;
public string iswhere;
public string cBrowser;
}
/// <summary>
/// onLineuser 的摘要说明
/// </summary>
public class onlineuser
{
private static DataTable _alluser;

//只读属性
public DataTable alluser
{
get { return _alluser; }
}

public onlineuser()
{
if (_alluser == null)
{
//define user list
// declare variables for datacolumn and datarow objects.
_alluser = new DataTable("onlineuser");

DataColumn mydatacolumn;

// create new datacolumn, set datatype, columnname and add to datatable.
mydatacolumn = new DataColumn();
mydatacolumn.DataType = System.Type.GetType("System.String");
mydatacolumn.ColumnName = "name";
mydatacolumn.AutoIncrement = false;
mydatacolumn.Caption = "name";
mydatacolumn.ReadOnly = false;
mydatacolumn.Unique = false;
_alluser.Columns.Add(mydatacolumn);

// create NickName column.
mydatacolumn = new DataColumn();
mydatacolumn.DataType = System.Type.GetType("System.String");
mydatacolumn.ColumnName = "NickName";
mydatacolumn.AutoIncrement = false;
mydatacolumn.Caption = "NickName";
mydatacolumn.ReadOnly = false;
mydatacolumn.Unique = false;
_alluser.Columns.Add(mydatacolumn);


// create NickName column.
mydatacolumn = new DataColumn();
mydatacolumn.DataType = System.Type.GetType("System.String");
mydatacolumn.ColumnName = "RoleCode";
mydatacolumn.AutoIncrement = false;
mydatacolumn.Caption = "RoleCode";
mydatacolumn.ReadOnly = false;
mydatacolumn.Unique = false;
_alluser.Columns.Add(mydatacolumn);

// create sessionid column.
mydatacolumn = new DataColumn();
mydatacolumn.DataType = System.Type.GetType("System.String");
mydatacolumn.ColumnName = "sessionid";
mydatacolumn.AutoIncrement = false;
mydatacolumn.Caption = "sessionid";
mydatacolumn.ReadOnly = false;
mydatacolumn.Unique = true;
_alluser.Columns.Add(mydatacolumn);


// create Code column.
mydatacolumn = new DataColumn();
mydatacolumn.DataType = System.Type.GetType("System.String");
mydatacolumn.ColumnName = "Code";
mydatacolumn.AutoIncrement = false;
mydatacolumn.Caption = "Code";
mydatacolumn.ReadOnly = false;
mydatacolumn.Unique = false;
_alluser.Columns.Add(mydatacolumn);

// create ip column.
mydatacolumn = new DataColumn();
mydatacolumn.DataType = System.Type.GetType("System.String");
mydatacolumn.ColumnName = "ip";
mydatacolumn.AutoIncrement = false;
mydatacolumn.Caption = "ip";
mydatacolumn.ReadOnly = false;
mydatacolumn.Unique = false;
_alluser.Columns.Add(mydatacolumn);

// create iswhere column.
mydatacolumn = new DataColumn();
mydatacolumn.DataType = System.Type.GetType("System.String");
mydatacolumn.ColumnName = "iswhere";
mydatacolumn.AutoIncrement = false;
mydatacolumn.Caption = "iswhere";
mydatacolumn.ReadOnly = false;
mydatacolumn.Unique = false;
_alluser.Columns.Add(mydatacolumn);

// create iswhere column.
mydatacolumn = new DataColumn();
mydatacolumn.DataType = System.Type.GetType("System.DateTime");
mydatacolumn.ColumnName = "lasttime";
mydatacolumn.AutoIncrement = false;
mydatacolumn.Caption = "lasttime";
mydatacolumn.ReadOnly = false;
mydatacolumn.Unique = false;
_alluser.Columns.Add(mydatacolumn);

// create iswhere column.
mydatacolumn = new DataColumn();
mydatacolumn.DataType = System.Type.GetType("System.DateTime");
mydatacolumn.ColumnName = "curtime";
mydatacolumn.AutoIncrement = false;
mydatacolumn.Caption = "curtime";
mydatacolumn.ReadOnly = false;
mydatacolumn.Unique = false;
_alluser.Columns.Add(mydatacolumn);

// create cBrowser column.
mydatacolumn = new DataColumn();
mydatacolumn.DataType = System.Type.GetType("System.String");
mydatacolumn.ColumnName = "cBrowser";
mydatacolumn.AutoIncrement = false;
mydatacolumn.Caption = "cBrowser";
mydatacolumn.ReadOnly = false;
mydatacolumn.Unique = false;
_alluser.Columns.Add(mydatacolumn);
}
}

//功能说明:将当前用户加入在线列表
//如果该用户的数据当前仍然在在线列表中,则暂时先不让该用户登陆,提示用户存在
public bool UpdateSessionOnline(user user)
{
#if debug
(new sohoproject.sohodebug()).writetodoc("开始进入<将当前用户加入在线列表>....");
(new sohoproject.sohodebug()).writetodoc("\r\n");
#endif


//开始搜索是否已经存在该用户,如果存在则是改变数据,否则添加新的用户
string strexpr;
strexpr = "sessionid='" + user.sessionid + "'";
DataRow[] curuser;
// use the select method to find all rows matching the filter.
#if debug
(new sohoproject.sohodebug()).writetodoc("搜索字符串:" + strexpr);
(new sohoproject.sohodebug()).writetodoc("\r\n");
#endif


curuser = _alluser.Select(strexpr);

#if debug
(new sohoproject.sohodebug()).writetodoc(strexpr);
(new sohoproject.sohodebug()).writetodoc(curuser.length.tostring());
#endif


if (curuser.Length > 0)
{
for (int i = 0; i < curuser.Length; i++)
{
curuser[i]["name"] = user.name;
curuser[i]["RoleCode"] = user.RoleCode;
curuser[i]["NickName"] = user.NickName;
curuser[i]["Code"] = user.Code;
curuser[i]["curtime"] = DateTime.Now;
curuser[i]["lasttime"] = DateTime.Now;
curuser[i]["iswhere"] = user.iswhere;
curuser[i]["ip"] = user.ip;
curuser[i]["curtime"] = DateTime.Now;
curuser[i]["cBrowser"] = user.cBrowser;
}
}
_alluser.AcceptChanges();
return true;
}
Xpengfee 2006-11-21
  • 打赏
  • 举报
回复
首先感谢 zhuxiaojun2002(车房志之扯坏的领带)
提供这么好的网址,但是大家能否给段代码先,谢谢了
(附:投票功能已解决,有需要的说一声)
NoMembers 2006-11-16
  • 打赏
  • 举报
回复
不虚此行啊,谢谢楼上提更怎么好的网址
zhuxiaojun2002 2006-11-16
  • 打赏
  • 举报
回复
http://www.codeclub.cn/files/folders/bssource/entry141.aspx

比较有名的,有会员在线情况,你研究一下了。
Xpengfee 2006-11-16
  • 打赏
  • 举报
回复
自己先顶一下,大虾们帮忙帮到底,在给个论坛投票功能的示例让小弟瞻仰一下吧
gy348 2006-11-16
  • 打赏
  • 举报
回复
zhuxiaojun2002(车房志之扯坏的领带)
http://www.codeclub.cn/files/folders/bssource/entry141.aspx

比较有名的,有会员在线情况,你研究一下了。

不错的地址哦
cho__cho 2006-11-16
  • 打赏
  • 举报
回复

网上有很多成熟的解决方案了

aaajedll 2006-11-16
  • 打赏
  • 举报
回复
up

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧