Exemplo n.º 1
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string _error;

            // 检查用户输入数据值.
            if (check_text(out _error))
            {
                // 初始化保存当前在线用户的信息的datatable.
                DataTableForCurrentOnlineUser onLineTable = new DataTableForCurrentOnlineUser();

                // 用户身份实例.
                UserEntity _user = new UserEntity();
                _user.Ticket = DateTime.Now.ToString("yyyyMMddHHmmss");
                _user.UserName = tbUserName.Text.Trim();
                _user.TrueName = tbTrueName.Text.Trim();
                _user.ClientIP = this.Request.UserHostAddress;
                _user.RoleID = "MingXuGroup";

                // 使用session变量保存ticket.
                this.Session["Ticket"] = _user.Ticket;

                // 登入.
                onLineTable.Login(_user, true);
                Response.Redirect("CurrentOnlineUserList.aspx");
            }
            else
            {
                this.lbMessage.Visible = true;
                this.lbMessage.Text = _error;
            }
        }
 private UserEntity SingleUser(string strUserKey, bool byTicket)
 {
     strUserKey = strUserKey.Trim();
     string _strExpr;
     UserEntity user = new UserEntity();
     _strExpr = byTicket ? "Ticket='" + strUserKey + "'" : "UserName='******'";
     DataRow[] _curuser;
     _curuser = _activeusers.Select(_strExpr);
     if (_curuser.Length > 0)
     {
         user.Ticket = (string)_curuser[0]["Ticket"];
         user.UserName = (string)_curuser[0]["UserName"];
         user.TrueName = (string)_curuser[0]["TrueName"];
         user.RoleID = (string)_curuser[0]["RoleID"];
         user.ActiveTime = (DateTime)_curuser[0]["ActiveTime"];
         user.RefreshTime = (DateTime)_curuser[0]["RefreshTime"];
         user.ClientIP = (string)_curuser[0]["ClientIP"];
     }
     else
     {
         user.UserName = "";
     }
     return user;
 }
 /// <summary>
 /// 登录方法.
 /// </summary>
 public void Login(UserEntity user, bool singleLogin)
 {
     // 清除离线用户记录.
     DelTimeOut();
     if (singleLogin)
     {
         // 让已登录用户登出.
         this.Logout(user.UserName, false);
     }
     DataRow _myrow;
     try
     {
         _myrow = _activeusers.NewRow();
         _myrow["Ticket"] = user.Ticket.Trim();
         _myrow["UserName"] = user.UserName.Trim();
         _myrow["TrueName"] = "" + user.TrueName.Trim();
         _myrow["RoleID"] = "" + user.RoleID.Trim();
         _myrow["ActiveTime"] = DateTime.Now;
         _myrow["RefreshTime"] = DateTime.Now;
         _myrow["ClientIP"] = user.ClientIP.Trim();
         _activeusers.Rows.Add(_myrow);
     }
     catch
     {
         throw;
     }
     _activeusers.AcceptChanges();
 }