using System;
using System.Collections.Generic;
///
/// 用户数据库结构
/// 支持版本管理和用户集合
///
[System.Serializable]
public class UserDatabase
{
public string Version = "1.0";
public List Users = new List();
///
/// 查找活跃用户
/// 用户名区分大小写
///
/// 用户名
/// 用户信息,如果不存在或不活跃则返回null
public UserInfo FindUser(string username)
{
// 修改为区分大小写的比较
return Users.Find(u => u.Username == username && u.IsActive);
}
///
/// 获取所有活跃用户
///
/// 活跃用户列表
public List GetActiveUsers()
{
return Users.FindAll(u => u.IsActive);
}
///
/// 获取管理员用户列表
///
/// 管理员用户列表
public List GetAdminUsers()
{
return Users.FindAll(u => u.IsActive && u.Role == UserRole.Admin);
}
}
///
/// 扩展的用户信息类
/// 包含完整的用户数据和时间戳
///
[System.Serializable]
public class UserInfo
{
public string Username;
public string Password;
public UserRole Role;
public DateTime CreatedTime;
public DateTime LastLoginTime;
public DateTime PasswordChangedTime;
public bool IsActive = true;
///
/// 获取用户显示名称
///
/// 包含角色信息的显示名称
public string GetDisplayName()
{
string displayName = Username;
if (Role == UserRole.Admin)
{
displayName += " [管理员]";
}
return displayName;
}
///
/// 检查密码是否需要更新(例如:超过指定天数)
///
/// 最大天数
/// 是否需要更新
public bool IsPasswordExpired(int maxDays = 90)
{
if (PasswordChangedTime == default(DateTime))
{
// 如果从未修改过密码,使用创建时间
return (DateTime.Now - CreatedTime).Days > maxDays;
}
return (DateTime.Now - PasswordChangedTime).Days > maxDays;
}
}
///
/// 用户操作日志事件
/// 记录用户的各种操作行为
///
[System.Serializable]
public class UserLogEvent
{
public int Id;
public string Username;
public string Operation; // 操作类型:登录、登出、修改密码、创建用户等
public string OperationDetails; // 操作详情
public DateTime Timestamp;
public string IPAddress; // IP地址(如果需要)
public bool IsSuccessful; // 操作是否成功
public UserLogEvent()
{
Timestamp = DateTime.Now;
IsSuccessful = true;
}
public UserLogEvent(string username, string operation, string details = null, bool successful = true)
{
Username = username;
Operation = operation;
OperationDetails = details;
IsSuccessful = successful;
Timestamp = DateTime.Now;
}
}
///
/// 系统使用日志事件(保持向后兼容)
///
[System.Serializable]
public class UseLogEvent
{
public int Id;
public string OperationContentText;
public DateTime Time;
public string Account;
public UseLogEvent()
{
Time = DateTime.Now;
}
public UseLogEvent(string account, string operation)
{
Account = account;
OperationContentText = operation;
Time = DateTime.Now;
}
}