//功能说明:将当前用户加入在线列表 //如果该用户的数据当前仍然在在线列表中,则暂时先不让该用户登陆,提示用户存在 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["ip"] = user.ip; myRow["iswhere"] = user.iswhere; myRow["lasttime"] = user.lasttime; myRow["curtime"] = DateTime.Now; myRow["sessionid"] = user.sessionid; _alluser.Rows.Add(myRow); } catch(Exception e) { throw(new Exception(e + "--------------------" + e.ToString())) ; } } _alluser.AcceptChanges(); return true; }