예제 #1
0
        /// <summary>
        /// 递归获取nodes
        /// </summary>
        /// <param name="_classModel"></param>
        /// <param name="_parentNode"></param>
        private void GetChildNodes(ProtocolClassificationModel _classModel, TreeNode _parentNode)
        {
            //获取所有分类
            var classList = ProtocolDB.GetAllClassification();

            //查找当前分类下的所有子类
            var childList = classList.Where(c => c.ParentID == _classModel.PCID).ToList();

            if (childList != null && childList.Count > 0)
            {
                for (int i = 0; i < childList.Count; i++)
                {
                    TreeNode node = new TreeNode();
                    node.Text = $"[模块]{childList[i].PCName}";
                    node.Tag  = new NodeSelectTag()
                    {
                        Model   = childList[i],
                        TagType = NodeSelectTag.TAGTYPE.Classisication,
                        Target  = node
                    };
                    GetChildNodes(childList[i], node);
                    _parentNode.Nodes.Add(node);
                }
            }

            //查找当前分类下的所有协议
            var proList = ProtocolDB.GetProtocol(_classModel.PCID);

            if (proList != null && proList.Count > 0)
            {
                for (int i = 0; i < proList.Count; i++)
                {
                    TreeNode node = new TreeNode();
                    node.Text = $"[协议]{ proList[i].Code}-{proList[i].CName}";
                    node.Tag  = new NodeSelectTag()
                    {
                        Model   = proList[i],
                        TagType = NodeSelectTag.TAGTYPE.Protocol,
                        Target  = node
                    };
                    _parentNode.Nodes.Add(node);
                    //添加到所有协议中
                    protocolModels.Add(proList[i]);
                }
            }
        }
예제 #2
0
        private void 添加协议ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (selectedNode == null || selectedNode.TagType != NodeSelectTag.TAGTYPE.Classisication)
            {
                MessageBox.Show("您需要在某个模块下添加协议");
                return;
            }

            ProtocolClassificationModel target = (selectedNode.Model as ProtocolClassificationModel);

            if (target == null || string.IsNullOrEmpty(target.PCID))
            {
                MessageBox.Show("您需要在某个模块下添加协议");
                return;
            }

            //查找当前模块下所有协议 并按照编码排序
            List <ProtocolModel> protocols = ProtocolDB.GetProtocol(target.PCID).OrderByDescending(c => c.Code).ToList();
            int code = 0;

            if (protocols != null && protocols.Count > 0)
            {
                //累加编号
                int _rCode = Convert.ToInt32(protocols[0].Code.ToString().Substring(protocols[0].Code.ToString().LastIndexOf("0")));
                code = ProtocolCommon.GetProtocolCode(ProtocolDB.GetMaxClassificationIndex(target.CreateTime), (_rCode + 1));
            }
            else
            {
                //新增编号
                code = ProtocolCommon.GetProtocolCode(ProtocolDB.GetMaxClassificationIndex(target.CreateTime), 1);
            }

            //DATA
            ProtocolModel protocolModel = new ProtocolModel()
            {
                CName      = "",
                Code       = code,
                Desc       = "",
                EName      = "",
                PCID       = target.PCID,
                PID        = Guid.NewGuid().ToString(),
                CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            };

            if (!ProtocolDB.AddProtocol(protocolModel))
            {
                MessageBox.Show("添加协议失败");
                return;
            }

            //UI
            TreeNode node = new TreeNode();

            node.Text = $"[协议]{ protocolModel.Code}-{protocolModel.CName}";
            node.Tag  = new NodeSelectTag()
            {
                Model   = protocolModel,
                TagType = NodeSelectTag.TAGTYPE.Protocol,
                Target  = node
            };

            selectedNode.Target.Nodes.Add(node);
            protocolModels.Add(protocolModel);

            myTree.Refresh();
            myTree.Focus();
            myTree.SelectedNode = node;

            selectedNode = node.Tag as NodeSelectTag;
            ShowProtoInfo(protocolModel);
        }