📄 nodes.cs
字号:
namespace PowerEasy.Contents
{
using PowerEasy.AccessManage;
using PowerEasy.Common;
using PowerEasy.CommonModel;
using PowerEasy.Components;
using PowerEasy.Enumerations;
using PowerEasy.IDal.Contents;
using PowerEasy.Model.Contents;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Text;
using System.Web;
public sealed class Nodes
{
private static readonly INodes dal = DataAccess.CreateNodes();
private static int orderId;
private Nodes()
{
}
public static int Add(NodeInfo nodeInfo)
{
int maxRootId = GetMaxRootId();
nodeInfo.NodeId = GetMaxNodeId() + 1;
nodeInfo.ArrChildId = nodeInfo.NodeId.ToString();
nodeInfo.Child = 0;
nodeInfo.ParentDir = "/" + nodeInfo.ParentDir;
if (ExistsNodeName(nodeInfo.ParentId, nodeInfo.NodeName))
{
return 2;
}
if (ExistsNodeIdentifier(nodeInfo.ParentId, nodeInfo.NodeIdentifier))
{
return 3;
}
if (ExistsNodeDir(nodeInfo.ParentId, nodeInfo.NodeDir))
{
return 4;
}
if (nodeInfo.ParentId > 0)
{
NodeInfo cacheNodeById = GetCacheNodeById(nodeInfo.ParentId);
if (cacheNodeById.IsNull)
{
return 6;
}
nodeInfo.ParentPath = cacheNodeById.ParentPath + "," + cacheNodeById.NodeId.ToString();
nodeInfo.RootId = cacheNodeById.RootId;
nodeInfo.Depth = cacheNodeById.Depth + 1;
nodeInfo.ParentDir = cacheNodeById.ParentDir + cacheNodeById.NodeDir + "/";
if ((cacheNodeById.NodeType == NodeType.Single) || (cacheNodeById.NodeType == NodeType.Link))
{
return 5;
}
UpdateChild(nodeInfo.ParentId);
foreach (KeyValuePair<int, string> pair in GetParentPathArrChildId(nodeInfo.ParentPath))
{
int key = pair.Key;
string arrChildId = pair.Value + "," + nodeInfo.NodeId.ToString();
UpdateArrChildId(key, arrChildId);
}
if (cacheNodeById.Child > 0)
{
nodeInfo.OrderId = GetPrevOrderId(cacheNodeById.ArrChildId);
nodeInfo.PrevId = GetPrevId(nodeInfo.ParentId);
}
else
{
nodeInfo.OrderId = cacheNodeById.OrderId;
nodeInfo.PrevId = 0;
}
}
else
{
nodeInfo.ParentDir = "/";
if (maxRootId > 0)
{
nodeInfo.PrevId = dal.GetRootPrevId(maxRootId);
}
else
{
nodeInfo.PrevId = 0;
}
nodeInfo.RootId = maxRootId + 1;
nodeInfo.ParentPath = "0";
nodeInfo.OrderId = 0;
nodeInfo.Depth = 0;
}
UpdateNextId(nodeInfo.PrevId, nodeInfo.NodeId);
bool flag = dal.Add(nodeInfo);
UpdateOrderId(nodeInfo.RootId, nodeInfo.OrderId, 1);
if (nodeInfo.ParentId > 0)
{
UpdateOrderId(nodeInfo.NodeId, nodeInfo.OrderId + 1);
}
RemoveCacheAllNodeInfo();
if (!flag)
{
return 0;
}
return 1;
}
public static int Add(NodeInfo nodeInfo, IList<NodesModelTemplateRelationShipInfo> infoList)
{
nodeInfo.NodeName = DataSecurity.HtmlEncode(nodeInfo.NodeName);
nodeInfo.NodeIdentifier = DataSecurity.HtmlEncode(nodeInfo.NodeIdentifier);
int num = Add(nodeInfo);
if (num == 1)
{
foreach (NodesModelTemplateRelationShipInfo info in infoList)
{
info.NodeId = nodeInfo.NodeId;
if (!ModelManager.ExistsNodesModelTemplateRelationShip(info))
{
ModelManager.AddNodesModelTemplateRelationShip(info);
}
}
}
return num;
}
public static bool BatchUpdate(NodeInfo nodeInfo, string nodesId, Dictionary<string, bool> checkItem)
{
foreach (NodeInfo info in GetNodesList(nodesId))
{
NodeSettingInfo settings = info.Settings;
if (checkItem["EnableComment"])
{
settings.EnableComment = nodeInfo.Settings.EnableComment;
settings.CommentNeedCheck = nodeInfo.Settings.CommentNeedCheck;
settings.EnableTouristsComment = nodeInfo.Settings.EnableTouristsComment;
}
if (checkItem["EnableProtect"])
{
settings.EnableProtect = nodeInfo.Settings.EnableProtect;
}
if (checkItem["EnableAddWhenHasChild"])
{
settings.EnableAddWhenHasChild = nodeInfo.Settings.EnableAddWhenHasChild;
}
if (checkItem["PresentExp"])
{
settings.PresentExp = nodeInfo.Settings.PresentExp;
}
if (checkItem["DefaultItemPoint"])
{
settings.DefaultItemPoint = nodeInfo.Settings.DefaultItemPoint;
}
if (checkItem["ShowChargeType"])
{
settings.DefaultItemChargeType = nodeInfo.Settings.DefaultItemChargeType;
settings.DefaultItemPitchTime = nodeInfo.Settings.DefaultItemPitchTime;
settings.DefaultItemReadTimes = nodeInfo.Settings.DefaultItemReadTimes;
}
if (checkItem["DefaultItemDividePercent"])
{
settings.DefaultItemDividePercent = nodeInfo.Settings.DefaultItemDividePercent;
}
dal.UpdateSettings(settings, info.NodeId);
}
BatchUpdateField(nodeInfo, nodesId, checkItem);
RemoveCacheAllNodeInfo();
return true;
}
public static bool BatchUpdateField(NodeInfo nodeInfo, string nodesId, Dictionary<string, bool> checkItem)
{
if (!DataValidator.IsValidId(nodesId))
{
return false;
}
if (!checkItem.ContainsValue(true))
{
return false;
}
return dal.BatchUpdateField(nodeInfo, nodesId, checkItem);
}
public static bool CheckNodePermission(int nodeId)
{
if (nodeId > 0)
{
NodeInfo cacheNodeById = GetCacheNodeById(nodeId);
if (!cacheNodeById.Settings.EnableAddWhenHasChild && (cacheNodeById.Child > 0))
{
return false;
}
}
return true;
}
public static bool CheckRoleNodePurview(int nodeId, OperateCode operateCode)
{
bool flag = true;
if (PEContext.Current.Admin.IsSuperAdmin)
{
return flag;
}
if (nodeId > 0)
{
NodeInfo cacheNodeById = GetCacheNodeById(nodeId);
flag = RolePermissions.AccessCheckNodePermission(operateCode, cacheNodeById.NodeId);
if (!flag && (cacheNodeById.ParentId > 0))
{
string roleNodeId = RolePermissions.GetRoleNodeId(PEContext.Current.Admin.Roles, operateCode);
string str2 = cacheNodeById.ParentPath + "," + cacheNodeById.NodeId.ToString();
flag = RolePermissions.CheckNodePurview(roleNodeId, str2);
}
return flag;
}
return RolePermissions.AccessCheckNodePermission(operateCode, -1);
}
public static int Delete(int nodeId)
{
if (nodeId == 0)
{
return 3;
}
NodeInfo cacheNodeById = GetCacheNodeById(nodeId);
if (cacheNodeById.IsNull)
{
return 2;
}
DeleteNodeRelationByNodeId(nodeId);
DeleteInArrChild(cacheNodeById.ArrChildId);
if (cacheNodeById.ParentId > 0)
{
NodeInfo nodeInfo = GetCacheNodeById(cacheNodeById.ParentId);
nodeInfo.Child--;
nodeInfo.ArrChildId = nodeInfo.ArrChildId.Replace("," + cacheNodeById.ArrChildId, "");
Update(nodeInfo);
ModifyNodeStructure(nodeInfo);
}
ContentManage.DeleteByNodeId(cacheNodeById.ArrChildId, -4);
DeleteNodeFolder(cacheNodeById);
RemoveCacheAllNodeInfo();
return 1;
}
public static bool DeleteInArrChild(string arrChildId)
{
if (!DataValidator.IsValidId(arrChildId))
{
return false;
}
RemoveCacheAllNodeInfo();
return dal.DeleteInArrChild(arrChildId);
}
private static void DeleteNodeFolder(NodeInfo nodeInfo)
{
if (!string.IsNullOrEmpty(nodeInfo.ParentDir) && !string.IsNullOrEmpty(nodeInfo.NodeDir))
{
string path = "~/" + SiteConfig.SiteOption.CreateHtmlPath + nodeInfo.ParentDir + nodeInfo.NodeDir;
if (HttpContext.Current != null)
{
FileSystemObject.Delete(HttpContext.Current.Server.MapPath(path), FsoMethod.Folder);
}
}
}
private static void DeleteNodeRelationByNodeId(int nodeId)
{
RolePermissions.DeleteNodePermissionFromRoles(-1, nodeId);
UserPermissions.DeleteNodePermissionsByNodeId(nodeId, OperateCode.None);
ModelManager.DeleteNodeModel(nodeId);
ModelManager.DeleteNodeTemplateId(nodeId);
ModelManager.DeleteNodesModelTemplateRelationShip(nodeId);
}
public static bool ExistsNodeDir(int parentId, string nodeDir)
{
if (string.IsNullOrEmpty(nodeDir))
{
return false;
}
return dal.ExistNodeDir(parentId, nodeDir);
}
public static bool ExistsNodeIdentifier(int parentId, string nodeIdentifier)
{
return dal.ExistsNodeIdentifier(parentId, nodeIdentifier);
}
public static bool ExistsNodeName(int parentId, string nodeName)
{
string str = DataSecurity.FilterBadChar(nodeName);
return dal.ExistsNodeName(parentId, str);
}
public static bool ExistsTargetNodeIdInArrChildId(int targetNodeId, string arrChildId)
{
if (!DataValidator.IsValidId(arrChildId))
{
return false;
}
return dal.ExistsTargetNodeIdInArrChildId(targetNodeId, arrChildId);
}
public static IList<NodeInfo> GetAnonymousNodeId(int groupId, OperateCode operateCode)
{
return dal.GetAnonymousNodeId(groupId, operateCode);
}
public static NodeInfo GetCacheNodeById(int nodeId)
{
if ((nodeId != -2) && (nodeId <= 0))
{
return new NodeInfo(true);
}
string key = "CK_Content_NodeInfo_NodeId_" + nodeId.ToString();
NodeInfo nodeById = SiteCache.Get(key) as NodeInfo;
if (nodeById == null)
{
nodeById = dal.GetNodeById(nodeId);
if (!nodeById.IsNull)
{
SiteCache.Insert(key, nodeById, 0x4380);
}
}
return nodeById;
}
public static int GetCountModelByNodeId(int nodeId)
{
return dal.GetCountModelByNodeId(nodeId);
}
public static int GetCountNodesBySameNodeDir(int parentId, int nodeId, string nodeDir)
{
return dal.GetCountNodesBySameNodeDir(parentId, nodeId, nodeDir);
}
public static bool GetDefaultTemplate(int nodeId, int templateId)
{
return dal.GetDefaultTemplate(nodeId, templateId);
}
public static int GetMaxNodeId()
{
return dal.GetMaxNodeId();
}
public static int GetMaxPurviewTypeInParentPath(int nodeId)
{
NodeInfo cacheNodeById = GetCacheNodeById(nodeId);
if (!DataValidator.IsValidId(cacheNodeById.ParentPath))
{
return 0;
}
return dal.GetMaxPurviewTypeInParentPath(cacheNodeById.ParentPath);
}
private static int GetMaxRootId()
{
return dal.GetMaxRootId();
}
public static int GetNextIdByDepth(int depth, string parentPath)
{
if (DataValidator.IsValidId(parentPath))
{
return dal.GetNextIdByDepth(depth, parentPath);
}
return 0;
}
public static NodeInfo GetNodeById(int nodeId)
{
if ((nodeId != -2) && (nodeId <= 0))
{
return new NodeInfo(true);
}
return dal.GetNodeById(nodeId);
}
public static string GetNodeDir(int child, NodeType nodeType, string nodeDir)
{
StringBuilder builder = new StringBuilder();
if (child > 0)
{
builder.Append("(");
builder.Append(child);
builder.Append(")");
}
if (NodeType.Link == nodeType)
{
builder.Append(" <font color=blue>(外)</font>");
}
else if (!string.IsNullOrEmpty(nodeDir))
{
builder.Append(" [");
builder.Append(nodeDir);
builder.Append("]");
}
return builder.ToString();
}
public static IList<NodeInfo> GetNodeList()
{
IList<NodeInfo> nodesList = GetNodesList();
NodeInfo item = new NodeInfo();
item.NodeName = "<span style='color:red'>所有栏目</span>";
item.NodeId = -1;
item.Depth = 0;
item.ParentPath = "0";
item.NextId = 0;
item.Child = 0;
item.NodeType = NodeType.Container;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -