📄 nodes.cs
字号:
item.NodeDir = "";
nodesList.Insert(0, item);
return nodesList;
}
public static IList<NodeInfo> GetNodeListExecptLinkType()
{
IList<NodeInfo> nodesList = GetNodesList(NodeType.Container);
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;
item.NodeDir = "";
nodesList.Insert(0, item);
return nodesList;
}
public static DataTable GetNodeNameByModelId(int modelId, NodeType nodeType)
{
return dal.GetNodeNameByModelId(modelId, nodeType);
}
public static IList<NodeInfo> GetNodeNameForContainerItems()
{
return NodeTreeItems(GetNodesList(NodeType.Container));
}
public static IList<NodeInfo> GetNodeNameForItems()
{
return NodeTreeItems(GetNodesList());
}
public static IList<NodeInfo> GetNodeNameForItemsExceptOutLinks()
{
IList<NodeInfo> nodesList = GetNodesList();
IList<NodeInfo> nodeList = new List<NodeInfo>();
foreach (NodeInfo info in nodesList)
{
if (info.NodeType != NodeType.Link)
{
nodeList.Add(info);
}
}
return NodeTreeItems(nodeList);
}
public static IList<NodeInfo> GetNodesList()
{
return dal.GetNodesList(NodeType.None);
}
public static IList<NodeInfo> GetNodesList(NodeType nodeType)
{
return dal.GetNodesList(nodeType);
}
public static IList<NodeInfo> GetNodesList(string nodesId)
{
if (!DataValidator.IsValidId(nodesId))
{
return new List<NodeInfo>();
}
return dal.GetNodesList(nodesId);
}
public static IList<NodeInfo> GetNodesListByParentId(int parentId)
{
return dal.GetNodesListByParentId(parentId);
}
public static IList<NodeInfo> GetNodesListByRootId(int rootId)
{
return dal.GetNodesListByRootId(rootId);
}
public static IList<NodeInfo> GetNodesListInArrChildId(string arrChildId)
{
if (!DataValidator.IsValidId(arrChildId))
{
return null;
}
RemoveCacheAllNodeInfo();
return dal.GetNodesListInArrChildId(arrChildId);
}
public static IList<NodeInfo> GetNodesListInParentPath(string parentPath)
{
if (DataValidator.IsValidId(parentPath))
{
return dal.GetNodesListInParentPath(parentPath);
}
return null;
}
public static int GetNodeWorkFlowId(int nodeId)
{
return dal.GetNodeWorkFlowId(nodeId);
}
public static NodeInfo GetParentNodeByNodeId(int parentId, int nodeId)
{
return dal.GetParentNodeByNodeId(parentId, nodeId);
}
private static NodeInfo GetParentNodeInfo(NodeInfo nodeInfo)
{
if (nodeInfo.ParentId != 0)
{
while (nodeInfo.ParentId != 0)
{
nodeInfo = GetCacheNodeById(nodeInfo.ParentId);
}
return nodeInfo;
}
return nodeInfo;
}
public static Dictionary<int, string> GetParentPathArrChildId(string parentPath)
{
if (DataValidator.IsValidId(parentPath))
{
return dal.GetParentPathArrChildId(parentPath);
}
return null;
}
private static int GetPrevId(int parentId)
{
return dal.GetPrevId(parentId);
}
public static int GetPrevOrderId(string arrChildId)
{
if (DataValidator.IsValidId(arrChildId))
{
return dal.GetPrevOrderId(arrChildId);
}
return 0;
}
public static IList<NodeInfo> GetShopNodeList()
{
return NodeTreeItems(dal.GetShopNodeList());
}
public static int GetTotalOfNodes()
{
return dal.GetTotalOfNodes();
}
public static string GetTreeLine(int depth, string parentPath, int nextId, int child)
{
StringBuilder builder = new StringBuilder("");
string str = DataSecurity.FilterBadChar(parentPath);
string str2 = "";
str2 = HttpContext.Current.Request.ApplicationPath.Equals("/") ? string.Empty : HttpContext.Current.Request.ApplicationPath;
str2 = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + str2;
if (depth > 0)
{
for (int i = 1; i <= depth; i++)
{
if (i == depth)
{
if (nextId > 0)
{
builder.Append("<img src='" + str2 + "/Admin/images/Node/tree_line1.gif' width='17' height='16' valign='abvmiddle'>");
}
else
{
builder.Append("<img src='" + str2 + "/Admin/images/Node/tree_line2.gif' width='17' height='16' valign='abvmiddle'>");
}
}
else if (GetNextIdByDepth(i, str) > 0)
{
builder.Append("<img src='" + str2 + "/Admin/images/Node/tree_line3.gif' width='17' height='16' valign='abvmiddle'>");
}
else
{
builder.Append("<img src='" + str2 + "/Admin/images/Node/tree_line4.gif' width='17' height='16' valign='abvmiddle'>");
}
}
}
if (child > 0)
{
builder.Append("<img src='" + str2 + "/Admin/images/Node/tree_folder4.gif' width='15' height='15' valign='abvmiddle'>");
}
else
{
builder.Append("<img src='" + str2 + "/Admin/images/Node/tree_folder3.gif' width='15' height='15' valign='abvmiddle'>");
}
if (depth == 0)
{
builder.Append("<b>");
}
return builder.ToString();
}
public static void ModifyNodeStructure(NodeInfo nodeInfo)
{
nodeInfo = GetParentNodeInfo(nodeInfo);
if (nodeInfo.ParentId == 0)
{
orderId = 0;
UpateNodeStructure(nodeInfo.NodeId, nodeInfo.Depth + 1, nodeInfo.ParentPath, "/" + nodeInfo.NodeDir + "/");
}
RemoveCacheAllNodeInfo();
}
public static int NodesMove(int nodeId, int moveToNodeId)
{
int num = 0;
if (nodeId == moveToNodeId)
{
return 2;
}
NodeInfo cacheNodeById = GetCacheNodeById(moveToNodeId);
NodeInfo nodeInfo = GetCacheNodeById(nodeId);
num = NodesMoveValidCheck(nodeInfo, cacheNodeById);
if (num <= 0)
{
nodeInfo.ParentId = moveToNodeId;
if ((moveToNodeId == 0) || cacheNodeById.IsNull)
{
nodeInfo.RootId = GetMaxRootId() + 1;
nodeInfo.ParentPath = "0";
nodeInfo.Depth = 0;
nodeInfo.ParentDir = "/";
nodeInfo.PrevId = GetMaxNodeId();
nodeInfo.NextId = 0;
}
else
{
nodeInfo.ParentPath = cacheNodeById.ParentPath + "," + moveToNodeId.ToString();
nodeInfo.RootId = cacheNodeById.RootId;
nodeInfo.Depth = cacheNodeById.Depth + 1;
nodeInfo.ParentDir = cacheNodeById.ParentDir + cacheNodeById.NodeDir + "/";
nodeInfo.PrevId = GetPrevId(moveToNodeId);
nodeInfo.NextId = 0;
}
Update(nodeInfo);
ModifyNodeStructure(cacheNodeById);
RemoveCacheAllNodeInfo();
}
return num;
}
private static int NodesMoveValidCheck(NodeInfo nodeInfo, NodeInfo moveToNodeInfo)
{
if (nodeInfo.IsNull)
{
return 1;
}
if (nodeInfo.ParentId == moveToNodeInfo.NodeId)
{
return 3;
}
if (moveToNodeInfo.NodeType != NodeType.Container)
{
return 4;
}
if (StringHelper.FoundInArr(nodeInfo.ArrChildId, moveToNodeInfo.NodeId.ToString(), ","))
{
return 5;
}
if (ExistsNodeName(moveToNodeInfo.NodeId, nodeInfo.NodeName))
{
return 6;
}
if (ExistsNodeDir(moveToNodeInfo.NodeId, nodeInfo.NodeDir))
{
return 7;
}
return 0;
}
public static int NodesUnite(int nodeId, int targetNodeId)
{
if (nodeId <= 0)
{
return 1;
}
if (targetNodeId <= 0)
{
return 2;
}
if (nodeId == targetNodeId)
{
return 3;
}
NodeInfo nodeById = GetNodeById(targetNodeId);
if (nodeById.IsNull)
{
return 4;
}
if (nodeById.Child > 0)
{
return 5;
}
if (nodeById.NodeType != NodeType.Container)
{
return 6;
}
NodeInfo cacheNodeById = GetCacheNodeById(nodeId);
if (cacheNodeById.IsNull)
{
return 7;
}
if (StringHelper.FoundInArr(cacheNodeById.ArrChildId, targetNodeId.ToString(), ""))
{
return 8;
}
ContentManage.UpdateNodeId(targetNodeId, cacheNodeById.ArrChildId);
Delete(cacheNodeById.NodeId);
RemoveCacheAllNodeInfo();
return 0;
}
private static IList<NodeInfo> NodeTreeItems(IList<NodeInfo> nodeList)
{
int index = 0;
char ch = '\x00a0';
bool[] flagArray = new bool[50];
foreach (NodeInfo info in nodeList)
{
index = info.Depth;
if (info.NextId > 0)
{
flagArray[index] = true;
}
else
{
flagArray[index] = false;
}
StringBuilder builder = new StringBuilder();
if (index > 0)
{
for (int i = 1; i <= index; i++)
{
builder.Append(ch);
builder.Append(ch);
if (i == index)
{
if (info.NextId > 0)
{
builder.Append("├");
builder.Append(ch);
}
else
{
builder.Append("└");
builder.Append(ch);
}
}
else if (flagArray[i])
{
builder.Append("│");
}
else
{
builder.Append(ch);
}
}
}
builder.Append(DataSecurity.HtmlDecode(info.NodeName));
if (info.NodeType == NodeType.Link)
{
builder.Append("(外)");
}
info.NodeName = builder.ToString();
}
return nodeList;
}
public static void OrderNode(IList<NodeInfo> nodeList)
{
List<NodeInfo> list = (List<NodeInfo>) nodeList;
list.Sort();
int count = list.Count;
for (int i = 0; i < count; i++)
{
NodeInfo nodeInfo = list[i];
if (i == 0)
{
nodeInfo.PrevId = 0;
}
else
{
nodeInfo.PrevId = list[i - 1].NodeId;
}
if (i == (count - 1))
{
nodeInfo.NextId = 0;
}
else
{
nodeInfo.NextId = list[i + 1].NodeId;
}
if (nodeInfo.OrderType == 1)
{
UpdateRootId(nodeInfo.ArrChildId, nodeInfo.RootId);
}
Update(nodeInfo);
}
RemoveCacheAllNodeInfo();
}
public static void PatchNodes()
{
foreach (NodeInfo info in GetNodesListByParentId(0))
{
ModifyNodeStructure(info);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -