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
//功能说明:
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);
//功能说明:判断某用户是否在线,本部分暂时不用
//返回值: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;
}
}
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);
//功能说明:将当前用户加入在线列表
//如果该用户的数据当前仍然在在线列表中,则暂时先不让该用户登陆,提示用户存在
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