예제 #1
0
 public EditClassificationModel(string _parentID = "")
 {
     InitializeComponent();
     parentID     = _parentID;
     ResultModel  = new ProtocolClassificationModel();
     btnSave.Text = "添加";
 }
예제 #2
0
 public EditClassificationModel(ProtocolClassificationModel _editModel)
 {
     InitializeComponent();
     edit              = true;
     ResultModel       = _editModel;
     txtModelName.Text = _editModel.PCName;
     btnSave.Text      = "编辑";
 }
예제 #3
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]);
                }
            }
        }
예제 #4
0
        private static List <ProtocolClassificationModel> DT2ProtocolClassificationModel(DataTable _dt)
        {
            List <ProtocolClassificationModel> list = new List <ProtocolClassificationModel>();

            if (_dt != null && _dt.Rows.Count > 0)
            {
                for (int i = 0; i < _dt.Rows.Count; i++)
                {
                    ProtocolClassificationModel model = new ProtocolClassificationModel();
                    model.ParentID   = _dt.Rows[i]["ParentID"].ToString();
                    model.PCID       = _dt.Rows[i]["PCID"].ToString();
                    model.PCName     = _dt.Rows[i]["PCName"].ToString();
                    model.CreateTime = _dt.Rows[i]["CreateTime"].ToString();
                    list.Add(model);
                }
            }
            return(list);
        }
예제 #5
0
        /// <summary>
        /// 编辑分类
        /// </summary>
        /// <param name="_model"></param>
        /// <returns></returns>
        public static bool UpdateClassification(ProtocolClassificationModel _model)
        {
            string sql = $@"UPDATE [ProtocolClassification]
	SET [PCName] = '{_model.PCName}'
		,[ParentID] = '{_model.ParentID}'
	WHERE [PCID] = '{_model.PCID}'"    ;

            int succeedNum = helper.ExecuteNonQuery(sql);

            if (succeedNum > 0)
            {
                var model = classificationModels.Single(c => c.PCID == _model.PCID);
                model.PCName   = _model.PCName;
                model.ParentID = _model.ParentID;
                return(true);
            }
            return(false);
        }
예제 #6
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 (MessageBox.Show($"您确定要删除[{target.PCName}]模块吗?谨慎操作", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                //DATA
                ProtocolDB.DeleteClassification(target.PCID);

                //UI
                myTree.Nodes.Remove(selectedNode.Target);
                myTree.Refresh();
            }
        }
예제 #7
0
        /// <summary>
        /// 添加分类
        /// </summary>
        /// <param name="_model"></param>
        /// <returns></returns>
        public static bool AddClassification(ProtocolClassificationModel _model)
        {
            string sql = $@"INSERT INTO [ProtocolClassification]
		([PCID]
		,[PCName]
		,[ParentID]
        ,[CreateTime])
	VALUES
		('{_model.PCID}'
		,'{_model.PCName}'
		,'{_model.ParentID}','{_model.CreateTime}')"        ;

            int succeedNum = helper.ExecuteNonQuery(sql);

            if (succeedNum > 0)
            {
                classificationModels.Add(_model);
                return(true);
            }
            return(false);
        }
예제 #8
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);
        }