Exemplo n.º 1
0
        private void InternalCehckOneNode(RelationSimple item)
        {
            if (item.parentId == 0)
            {
                return;
            }

            int id = item.storeType == 2 ? item.memoryStoreId : -item.termId;

            Node node;

            if (!this.elements.TryGetValue(id, out node))
            {
                Console.WriteLine("node not found {0}", id);
                return;
            }

            //Node node = this.elements[id];

            Node parent = this.elements[item.parentId];

            switch (item.relationType)
            {
            case -1:
            case -2:
                node.AddChildren(parent);
                break;

            case 1:
                parent.AddChildren(node);
                break;



            default:
                break;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 将简单关系对象转换为节点
        /// </summary>
        /// <param name="relation"></param>
        private void ToNodeV2(RelationSimple relation)
        {
            Node node = new Node();

            node.type = relation.termId > 0 ? 1 : 2;

            if (node.type == 1)
            {
                node.id = -relation.termId;
            }
            else
            {
                node.id = relation.memoryStoreId;
            }

            node.areaCode  = relation.areaCode;
            node.areaName  = relation.areaSegment;
            node.code      = relation.code;
            node.direction = relation.relationType;



            //Node parent;
            //if (elements.TryGetValue(relation.parentId, out parent))
            //{
            //    parent.AddChildren(node);
            //}
            //else
            //{
            //    if (relation.parentId != 0)
            //        throw new ArgumentNullException("无法找到父节点");
            //}

            Node storeNode;

            if (elements.TryGetValue(node.id, out storeNode))
            {
                if (storeNode.name != null && storeNode.name.Length > 0)
                {
                    return;
                }
                node = storeNode;
            }
            else
            {
                elements.Add(node.id, node);
                node.nodeIndex = currIndex++;
            }

            node.index = relation.index;


            if (node.id < 0)
            {
                node.longName = relation.name;
                //node.name = string.Format(string.Format("{0}{1}{2}", relation.areaSegment, relation.nameSegment, relation.tradeSegment));
                node.areaName = relation.areaSegment;
                node.sgName   = relation.nameSegment;
                node.sgTrade  = relation.tradeSegment;
                node.sgBranch = relation.branchSegment;



                if (node.longName != null && node.areaName != null && node.longName.IndexOf(node.areaName) == -1)
                {
                    //说明是大公司或者其他机构

                    if (relation.typeSegment != null && relation.typeSegment.Length < 4)
                    {
                        node.name = string.Format("{0}{1}{2}", relation.nameSegment, relation.tradeSegment, relation.typeSegment);
                    }
                    else
                    {
                        node.name = string.Format("{0}{1}", relation.nameSegment, relation.tradeSegment);
                    }
                }
                else
                {
                    string checkName = string.Format("{0}{1}", relation.nameSegment, relation.tradeSegment);
                    if (!enableAreaName && nameMap.ContainsKey(checkName))
                    {
                        if (relation.typeSegment != null && relation.typeSegment.Length < 4)
                        {
                            node.name = string.Format("{0}{1}{2}{3}", relation.areaSegment, relation.nameSegment, relation.tradeSegment, relation.typeSegment);
                        }
                        else
                        {
                            node.name = string.Format("{0}{1}{2}", relation.areaSegment, relation.nameSegment, relation.tradeSegment);
                        }
                        nameMap[checkName].Add(node);
                    }
                    else
                    {
                        if (!enableAreaName)
                        {
                            if (relation.typeSegment != null && relation.typeSegment.Length < 4)
                            {
                                node.name = string.Format("{0}{1}{2}", relation.nameSegment, relation.tradeSegment, relation.typeSegment);
                            }
                            else
                            {
                                node.name = string.Format("{0}{1}", relation.nameSegment, relation.tradeSegment);
                            }

                            nameMap.Add(checkName, new List <Node>()
                            {
                                node
                            });
                        }
                        else
                        {
                            if (relation.typeSegment != null && relation.typeSegment.Length < 4)
                            {
                                node.name = string.Format("{0}{1}{2}{3}", relation.areaSegment, relation.nameSegment, relation.tradeSegment, relation.typeSegment);
                            }
                            else
                            {
                                node.name = string.Format("{0}{1}{2}", relation.areaSegment, relation.nameSegment, relation.tradeSegment);
                            }
                        }
                    }
                }

                node.code = relation.code;
                if (node.code == null)
                {
                    this.elements.Remove(node.id);
                    this.currIndex--;
                }
            }
            else
            {
                node.name     = relation.name;
                node.longName = node.name;
            }

            if (node.index > maxIndex)
            {
                maxIndex = node.index;
            }

            node.relationType = relation.relationType;
            node.weight       = relation.weight;
            node.areaCode     = relation.areaCode;

            //node.type = relation.storeType;
        }