2023-04-13 11:51:03 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
|
|
|
|
|
namespace MECF.Framework.Common.Account.Extends
|
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 角色加载器,从Account.xml文件加载角色。
|
|
|
|
|
/// </summary>
|
2023-04-13 11:51:03 +08:00
|
|
|
|
public class RoleLoader : XmlLoader
|
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
#region Variables
|
2023-04-13 11:51:03 +08:00
|
|
|
|
|
2023-08-28 11:30:57 +08:00
|
|
|
|
private List<Role> _roleList;
|
|
|
|
|
private List<AccountEx> _accountList;
|
2023-04-13 11:51:03 +08:00
|
|
|
|
|
2023-08-28 11:30:57 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
|
|
|
|
public RoleLoader(string fileName)
|
|
|
|
|
: base(fileName)
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-28 11:30:57 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 返回角色列表。
|
|
|
|
|
/// </summary>
|
|
|
|
|
public List<Role> RoleList
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
get => _roleList;
|
|
|
|
|
set => _roleList = value;
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-28 11:30:57 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 返回账号列表。
|
|
|
|
|
/// </summary>
|
|
|
|
|
public List<AccountEx> AccountList
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
get => _accountList;
|
|
|
|
|
set => _accountList = value;
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
2023-08-28 11:30:57 +08:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Methods
|
2023-04-13 11:51:03 +08:00
|
|
|
|
|
2023-08-28 11:30:57 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取所有非超级用户角色列表。
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2023-04-13 11:51:03 +08:00
|
|
|
|
public List<Role> GetRoles()
|
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
return _roleList.Where((Role e) => !e.IsSuper).ToList();
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-28 11:30:57 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取所有非超级用户账号列表。
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2023-04-13 11:51:03 +08:00
|
|
|
|
public List<AccountEx> GetAccounts()
|
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
return _accountList.Where((AccountEx e) => !e.IsSuper).ToList();
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-28 11:30:57 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 解析Account.xml文件。
|
|
|
|
|
/// </summary>
|
2023-04-13 11:51:03 +08:00
|
|
|
|
protected override void AnalyzeXml()
|
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
if (XmlDoc == null)
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-08-28 11:30:57 +08:00
|
|
|
|
var roleItems = from r in XmlDoc.Descendants("roleItem")
|
2023-04-13 11:51:03 +08:00
|
|
|
|
select (r);
|
2023-08-28 11:30:57 +08:00
|
|
|
|
var list = new List<Role>();
|
|
|
|
|
foreach (var roleNode in roleItems)
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
var strRoleId = roleNode.Attribute("id").Value;
|
|
|
|
|
var strRoleName = roleNode.Attribute("name").Value;
|
|
|
|
|
var strIsAutoLogout = roleNode.Attribute("autologout").Value;
|
|
|
|
|
var strAutoLogoutTime = roleNode.Attribute("logouttime").Value;
|
|
|
|
|
int.TryParse(strAutoLogoutTime, out var logoutTime);
|
2023-09-04 16:28:14 +08:00
|
|
|
|
var isAutoLogout = ((strIsAutoLogout == "1"));
|
|
|
|
|
var strReserved = roleNode.Attribute("buildin")?.Value ?? "false";
|
|
|
|
|
if (!bool.TryParse(strReserved, out var isBuildIn))
|
|
|
|
|
isBuildIn = false;
|
|
|
|
|
|
|
|
|
|
var strDescription = roleNode.Attribute("description")?.Value ?? "";
|
|
|
|
|
var permContent= roleNode.Value;
|
|
|
|
|
var role = new Role(strRoleId, strRoleName, isAutoLogout, logoutTime, permContent, isBuildIn, strDescription);
|
2023-08-28 11:30:57 +08:00
|
|
|
|
list.Add(role);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
2023-08-28 11:30:57 +08:00
|
|
|
|
|
2023-09-04 16:28:14 +08:00
|
|
|
|
var roleAdmin = new Role("-1", "Administrators", true, 20, null, true, null)
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
|
|
|
|
IsSuper = true
|
|
|
|
|
};
|
2023-08-28 11:30:57 +08:00
|
|
|
|
|
|
|
|
|
list.Add(roleAdmin);
|
|
|
|
|
_roleList = list;
|
|
|
|
|
var users = from r in XmlDoc.Descendants("userItem")
|
2023-04-13 11:51:03 +08:00
|
|
|
|
select (r);
|
2023-08-28 11:30:57 +08:00
|
|
|
|
var lstUsers = new List<AccountEx>();
|
|
|
|
|
|
|
|
|
|
foreach (var userNode in users)
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
var lstRolesBelongTo = new List<string>();
|
|
|
|
|
var strUserId = userNode.Attribute("id").Value;
|
|
|
|
|
var strLoginName = userNode.Attribute("loginname").Value;
|
|
|
|
|
var strPassword = Decrypt(userNode.Attribute("password").Value);
|
|
|
|
|
var strFirstName = userNode.Attribute("firstname").Value;
|
|
|
|
|
var strLastName = userNode.Attribute("lastname").Value;
|
|
|
|
|
var strEmail = userNode.Attribute("email").Value;
|
|
|
|
|
var strDescription = "";
|
|
|
|
|
if (userNode.Attribute("description") != null)
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
strDescription = userNode.Attribute("description").Value;
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
2023-08-28 11:30:57 +08:00
|
|
|
|
var userRoles = from ro in userNode.Descendants("role")
|
2023-04-13 11:51:03 +08:00
|
|
|
|
select (ro);
|
2023-08-28 11:30:57 +08:00
|
|
|
|
foreach (var userRoleNode in userRoles)
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
var strRoleId = userRoleNode.Attribute("id").Value;
|
|
|
|
|
lstRolesBelongTo.Add(strRoleId);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
2023-08-28 11:30:57 +08:00
|
|
|
|
|
|
|
|
|
var item3 = new AccountEx(strUserId, strLoginName, strPassword, strFirstName, strLastName, strEmail, lstRolesBelongTo, strDescription);
|
|
|
|
|
lstUsers.Add(item3);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
2023-08-28 11:30:57 +08:00
|
|
|
|
var item4 = new AccountEx("-1", "admin", "admin", "", "", "", new List<string> { "-1" })
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
|
|
|
|
IsSuper = true
|
|
|
|
|
};
|
2023-08-28 11:30:57 +08:00
|
|
|
|
lstUsers.Add(item4);
|
|
|
|
|
_accountList = lstUsers;
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-28 11:30:57 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新指定的角色。
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="newRole"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool UpdateRole(Role newRole)
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
var oldRole = _roleList.Find((Role item) => item.RoleId == newRole.RoleId);
|
|
|
|
|
if (oldRole == null)
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
_roleList.Add(newRole);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
_roleList[_roleList.IndexOf(oldRole)] = newRole;
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
2023-08-28 11:30:57 +08:00
|
|
|
|
var doc = XmlDoc;
|
|
|
|
|
var list = (from m_xRole in doc.Descendants("roleItem")
|
|
|
|
|
where m_xRole.Attribute("id").Value == newRole.RoleId
|
2023-04-13 11:51:03 +08:00
|
|
|
|
select m_xRole).ToList();
|
|
|
|
|
if (list.Count > 0)
|
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
list[0].Attribute("name").Value = newRole.RoleName;
|
|
|
|
|
list[0].Attribute("autologout").Value = (newRole.IsAutoLogout ? "1" : "0");
|
|
|
|
|
list[0].Attribute("logouttime").Value = newRole.LogoutTime.ToString();
|
2023-09-04 16:28:14 +08:00
|
|
|
|
if(list[0].Attribute("buildin")!= null)
|
|
|
|
|
list[0].Attribute("buildin").Value = newRole.IsBuildIn.ToString();
|
|
|
|
|
|
2023-04-13 11:51:03 +08:00
|
|
|
|
if (list[0].Attribute("description") != null)
|
2023-08-28 11:30:57 +08:00
|
|
|
|
list[0].Attribute("description").Value = newRole.Description;
|
2023-09-04 16:28:14 +08:00
|
|
|
|
|
2023-09-04 11:51:05 +08:00
|
|
|
|
list[0].Value = newRole.PermissionContent;
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
var content = new XElement("roleItem", new XAttribute("id", newRole.RoleId), new XAttribute("name", newRole.RoleName), new XAttribute("autologout", newRole.IsAutoLogout ? "1" : "0"), new XAttribute("logouttime", newRole.LogoutTime), new XAttribute("description", newRole.Description))
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
2023-09-04 11:51:05 +08:00
|
|
|
|
Value = newRole.PermissionContent
|
2023-04-13 11:51:03 +08:00
|
|
|
|
};
|
2023-08-28 11:30:57 +08:00
|
|
|
|
doc.Root.Element("roles").Add(content);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
2023-08-28 11:30:57 +08:00
|
|
|
|
doc.Save(FileName);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-28 11:30:57 +08:00
|
|
|
|
public bool DeleteRole(string roleId)
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
|
|
|
|
Load();
|
2023-08-28 11:30:57 +08:00
|
|
|
|
var roleToDelete = _roleList.Find((Role item) => item.RoleId == roleId);
|
|
|
|
|
if (roleToDelete != null)
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
_roleList.Remove(roleToDelete);
|
|
|
|
|
var xmlDoc = XmlDoc;
|
|
|
|
|
var list = (from m_xRole in xmlDoc.Descendants("roleItem")
|
|
|
|
|
where m_xRole.Attribute("id").Value == roleId
|
2023-04-13 11:51:03 +08:00
|
|
|
|
select m_xRole).ToList();
|
|
|
|
|
if (list.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
list[0].Remove();
|
2023-08-28 11:30:57 +08:00
|
|
|
|
foreach (var item in _accountList)
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
if (item.RoleIDs.Contains(roleToDelete.RoleId))
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
item.RoleIDs.Remove(roleToDelete.RoleId);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-28 11:30:57 +08:00
|
|
|
|
list = (from m_xRole in xmlDoc.Descendants("role")
|
|
|
|
|
where m_xRole.Attribute("id").Value == roleToDelete.RoleId
|
2023-04-13 11:51:03 +08:00
|
|
|
|
select m_xRole).ToList();
|
|
|
|
|
if (list.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
list.Remove();
|
|
|
|
|
}
|
2023-08-28 11:30:57 +08:00
|
|
|
|
xmlDoc.Save(FileName);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-28 11:30:57 +08:00
|
|
|
|
private List<string> GetRolePermission(string roleId)
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
var result = new List<string>();
|
|
|
|
|
foreach (var item in _roleList)
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
if (item.RoleId == roleId)
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
2023-09-04 11:51:05 +08:00
|
|
|
|
result = item.PermissionContent.Split(';').ToList();
|
2023-04-13 11:51:03 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int GetMenuPermission(List<string> rolePermissions, string menuid)
|
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
foreach (var rolePermission in rolePermissions)
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
|
|
|
|
if (rolePermission.IndexOf(menuid) >= 0)
|
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
var array = rolePermission.Split(',');
|
2023-04-13 11:51:03 +08:00
|
|
|
|
if (array.Length > 1 && array[0].Trim() == menuid)
|
|
|
|
|
{
|
|
|
|
|
return int.Parse(array[1].Trim());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-05 10:57:11 +08:00
|
|
|
|
return 1; //MP_NONE
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-04 11:51:05 +08:00
|
|
|
|
public List<AppMenu> GetMenusByRole(string roleId, List<AppMenu> menuList)
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
var list = new List<AppMenu>();
|
2023-09-04 11:51:05 +08:00
|
|
|
|
var rolePermission = GetRolePermission(roleId);
|
|
|
|
|
foreach (var menu in menuList)
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
var list2 = new List<AppMenu>();
|
2023-09-04 11:51:05 +08:00
|
|
|
|
foreach (var menuItem in menu.MenuItems)
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
2023-09-04 11:51:05 +08:00
|
|
|
|
var appMenu = new AppMenu(menuItem.MenuID, menuItem.ViewModel, menuItem.ResKey, null,
|
|
|
|
|
menuItem.Description)
|
|
|
|
|
{
|
|
|
|
|
System = menuItem.System,
|
|
|
|
|
AlarmModule = menuItem.AlarmModule,
|
|
|
|
|
Permission = GetMenuPermission(rolePermission, menuItem.MenuID)
|
|
|
|
|
};
|
2023-04-13 11:51:03 +08:00
|
|
|
|
if (appMenu.Permission > 1)
|
|
|
|
|
{
|
|
|
|
|
list2.Add(appMenu);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-04 11:51:05 +08:00
|
|
|
|
|
2023-04-13 11:51:03 +08:00
|
|
|
|
if (list2.Count > 0)
|
|
|
|
|
{
|
2023-09-04 11:51:05 +08:00
|
|
|
|
var appMenu2 = new AppMenu(menu.MenuID, menu.ViewModel, menu.ResKey, list2, menu.Description);
|
|
|
|
|
appMenu2.System = menu.System;
|
|
|
|
|
appMenu2.AlarmModule = menu.AlarmModule;
|
2023-04-13 11:51:03 +08:00
|
|
|
|
list.Add(appMenu2);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-04 11:51:05 +08:00
|
|
|
|
|
2023-04-13 11:51:03 +08:00
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int GetMenuPermission(string roleid, string menuName)
|
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
var rolePermission = GetRolePermission(roleid);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
return GetMenuPermission(rolePermission, menuName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool UpdateAccount(AccountEx p_newAccount)
|
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
var accountEx = _accountList.Find((AccountEx item) => item.UserId == p_newAccount.UserId);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
if (accountEx == null)
|
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
_accountList.Add(p_newAccount);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
_accountList[_accountList.IndexOf(accountEx)] = p_newAccount;
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
2023-08-28 11:30:57 +08:00
|
|
|
|
var xdoc = XmlDoc;
|
|
|
|
|
var list = (from xAccount in xdoc.Descendants("userItem")
|
|
|
|
|
where xAccount.Attribute("id").Value == p_newAccount.UserId
|
2023-04-13 11:51:03 +08:00
|
|
|
|
select xAccount).ToList();
|
|
|
|
|
if (list.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
list[0].SetAttributeValue("loginname", p_newAccount.LoginName);
|
|
|
|
|
list[0].SetAttributeValue("password", Encrypt(p_newAccount.Password));
|
|
|
|
|
list[0].SetAttributeValue("firstname", p_newAccount.FirstName);
|
|
|
|
|
list[0].SetAttributeValue("lastname", p_newAccount.LastName);
|
|
|
|
|
list[0].SetAttributeValue("email", p_newAccount.Email);
|
|
|
|
|
list[0].SetAttributeValue("description", p_newAccount.Description);
|
|
|
|
|
|
|
|
|
|
list[0].Element("rolegroup").RemoveAll();
|
2023-08-28 11:30:57 +08:00
|
|
|
|
foreach (var roleID in p_newAccount.RoleIDs)
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
|
|
|
|
list[0].Element("rolegroup").Add(new XElement("role", new XAttribute("id", roleID)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
var xElement = new XElement("userItem", new XAttribute("id", p_newAccount.UserId), new XAttribute("loginname", p_newAccount.LoginName), new XAttribute("password", Encrypt(p_newAccount.Password)), new XAttribute("firstname", p_newAccount.FirstName), new XAttribute("lastname", p_newAccount.LastName), new XAttribute("email", p_newAccount.Email), new XAttribute("description", p_newAccount.Description), new XElement("rolegroup"));
|
|
|
|
|
foreach (var roleID2 in p_newAccount.RoleIDs)
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
|
|
|
|
xElement.Element("rolegroup").Add(new XElement("role", new XAttribute("id", roleID2)));
|
|
|
|
|
}
|
|
|
|
|
xdoc.Root.Element("users").Add(xElement);
|
|
|
|
|
}
|
2023-08-28 11:30:57 +08:00
|
|
|
|
xdoc.Save(FileName);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool DeleteAccount(string p_strUserID)
|
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
var accountEx = _accountList.Find((AccountEx item) => item.UserId == p_strUserID);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
if (accountEx != null)
|
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
_accountList.Remove(accountEx);
|
|
|
|
|
var xdoc = XmlDoc;
|
|
|
|
|
var list = (from xAccount in xdoc.Descendants("userItem")
|
2023-04-13 11:51:03 +08:00
|
|
|
|
where xAccount.Attribute("id").Value == p_strUserID
|
|
|
|
|
select xAccount).ToList();
|
|
|
|
|
if (list.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
list[0].Remove();
|
2023-08-28 11:30:57 +08:00
|
|
|
|
xdoc.Save(FileName);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Encrypt(string encrytStr)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(encrytStr))
|
|
|
|
|
{
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
var bytes = Encoding.UTF8.GetBytes(encrytStr);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
return Convert.ToBase64String(bytes);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return encrytStr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Decrypt(string decryptStr)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(decryptStr))
|
|
|
|
|
{
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-08-28 11:30:57 +08:00
|
|
|
|
var bytes = Convert.FromBase64String(decryptStr);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
return Encoding.UTF8.GetString(bytes);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return decryptStr;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-28 11:30:57 +08:00
|
|
|
|
|
|
|
|
|
#endregion
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|