Exemplo n.º 1
0
        /// <summary>
        /// 加载导航
        /// </summary>
        private void LoadMenu()
        {
            myTree.Nodes.Clear();
            protocolModels.Clear();
            myTree.Refresh();

            //获取所有分类
            var classList = ProtocolDB.GetAllClassification();

            //首级菜单
            var fList = classList.Where(c => c.ParentID == "").ToList();

            if (fList != null && fList.Count > 0)
            {
                for (int i = 0; i < fList.Count; i++)
                {
                    TreeNode node = new TreeNode();
                    node.Text = $"[模块]{fList[i].PCName}";
                    node.Tag  = new NodeSelectTag()
                    {
                        Model   = fList[i],
                        TagType = NodeSelectTag.TAGTYPE.Classisication,
                        Target  = node
                    };
                    GetChildNodes(fList[i], node);
                    myTree.Nodes.Add(node);
                }
            }
            myTree.Refresh();
        }
Exemplo n.º 2
0
        private void  除全部内容ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var result = MessageBox.Show("是否彻底删除全部数据?数据删除后无法恢复", "警告", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                if (ProtocolDB.DeleteAll())
                {
                    MessageBox.Show("全部删除成功");
                }
                else
                {
                    MessageBox.Show("数据清理异常,或有残余数据未清理,请联系管理员检查");
                }
                myTree.Nodes.Clear();
                myTree.Refresh();

                selectedNode = null;
            }

            txtProtoCnName.Clear();
            txtProtoCode.Clear();
            txtProtoDesc.Clear();
            txtProtoEnName.Clear();
            dvGrid.Rows.Clear();
        }
Exemplo n.º 3
0
        private void btnSaveSetting_Click(object sender, EventArgs e)
        {
            ProtocolDB.settingModel.UseNamespace     = cbUseNamespace.Checked;
            ProtocolDB.settingModel.NamespaceContent = txtNamespace.Text;
            ProtocolDB.UpdateSetting();

            MessageBox.Show("保存成功");
        }
Exemplo n.º 4
0
        private void 添加模块ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string parentID = "";

            if (selectedNode != null)
            {
                if (selectedNode.TagType == NodeSelectTag.TAGTYPE.Classisication)
                {
                    parentID = (selectedNode.Model as ProtocolClassificationModel).PCID;
                }
            }

            if (ProtocolDB.GetClassificationCount() > 9)
            {
                MessageBox.Show("至多只能有9个模块");
                return;
            }

            EditClassificationModel editClassification = new EditClassificationModel(parentID);

            if (editClassification.ShowDialog() == DialogResult.OK)
            {
                var result = editClassification.ResultModel;

                TreeNode node = new TreeNode();
                node.Text = $"[模块]{result.PCName}";
                node.Tag  = new NodeSelectTag()
                {
                    Model   = result,
                    TagType = NodeSelectTag.TAGTYPE.Classisication,
                    Target  = node
                };

                if (string.IsNullOrEmpty(parentID))
                {
                    myTree.Nodes.Add(node);
                }
                else
                {
                    if (selectedNode.Target != null)
                    {
                        selectedNode.Target.Nodes.Add(node);
                    }
                }

                myTree.SelectedNode = node;
                selectedNode        = node.Tag as NodeSelectTag;
                myTree.Refresh();
            }
        }
Exemplo n.º 5
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]);
                }
            }
        }
Exemplo n.º 6
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtModelName.Text))
            {
                MessageBox.Show("请输入模块名称");
                txtModelName.Focus();
                return;
            }

            if (edit)
            {
                //编辑
                ResultModel.PCName   = txtModelName.Text;
                ResultModel.ParentID = parentID;

                if (!ProtocolDB.UpdateClassification(ResultModel))
                {
                    MessageBox.Show($"{txtModelName.Text} 已存在");
                    txtModelName.Focus();
                    txtModelName.SelectAll();
                    return;
                }
            }
            else
            {
                //添加
                ResultModel.PCID       = Guid.NewGuid().ToString();
                ResultModel.PCName     = txtModelName.Text;
                ResultModel.ParentID   = parentID;
                ResultModel.CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                if (!ProtocolDB.AddClassification(ResultModel))
                {
                    MessageBox.Show($"{txtModelName.Text} 已存在");
                    txtModelName.Focus();
                    txtModelName.SelectAll();
                    return;
                }
            }

            DialogResult = DialogResult.OK;
        }
Exemplo n.º 7
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();
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 显示数据
        /// </summary>
        /// <param name="_proModel"></param>
        private void ShowProtoInfo(ProtocolModel _proModel)
        {
            if (_proModel == null)
            {
                return;
            }
            groupProtoInfo.Enabled = true;

            //协议基本信息
            this.txtProtoCode.Text   = _proModel.Code.ToString();
            this.txtProtoEnName.Text = _proModel.EName;
            this.txtProtoCnName.Text = _proModel.CName;
            this.txtProtoDesc.Text   = _proModel.Desc;

            var attrsList = ProtocolDB.GetAttributes(_proModel.PID);

            dvGrid.Rows.Clear();
            if (attrsList != null && attrsList.Count > 0)
            {
                for (int i = 0; i < attrsList.Count; i++)
                {
                    DataGridViewRow dataGridViewRow = dvGrid.Rows[0].Clone() as DataGridViewRow;

                    dataGridViewRow.Cells[0].Value  = attrsList[i].AType;
                    dataGridViewRow.Cells[1].Value  = attrsList[i].EName;
                    dataGridViewRow.Cells[2].Value  = attrsList[i].CName;
                    dataGridViewRow.Cells[3].Value  = attrsList[i].IsLoop;
                    dataGridViewRow.Cells[4].Value  = attrsList[i].A2LoopEName;
                    dataGridViewRow.Cells[5].Value  = attrsList[i].A2BoolEName;
                    dataGridViewRow.Cells[6].Value  = attrsList[i].A2Bool;
                    dataGridViewRow.Cells[7].Value  = attrsList[i].A2StrEName;
                    dataGridViewRow.Cells[8].Value  = attrsList[i].A2Str;
                    dataGridViewRow.Cells[9].Value  = attrsList[i].PAID;
                    dataGridViewRow.Cells[10].Value = attrsList[i].PID;

                    dvGrid.Rows.Add(dataGridViewRow);
                }
            }
        }
Exemplo n.º 9
0
        private void  除当前协议ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (selectedNode == null || selectedNode.TagType != NodeSelectTag.TAGTYPE.Protocol)
            {
                MessageBox.Show("请正确选择协议");
                return;
            }

            ProtocolModel protocolModel = selectedNode.Model as ProtocolModel;

            if (protocolModel == null || string.IsNullOrEmpty(protocolModel.PID))
            {
                MessageBox.Show("请正确选择协议");
                return;
            }

            if (MessageBox.Show($"您确定要删除[{protocolModel.CName}]模块吗?谨慎操作", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                //DATA
                if (ProtocolDB.DeleteProtocol(protocolModel.PID))
                {
                    //UI
                    selectedNode.Target.Parent.Nodes.Remove(selectedNode.Target);
                    protocolModels.Remove(protocolModel);
                    myTree.Refresh();
                    selectedNode = null;

                    MessageBox.Show("删除成功");
                }
                else
                {
                    MessageBox.Show("协议删除失败,请联系管理员检查数据");
                    return;
                }
            }
        }
Exemplo n.º 10
0
        private async void ExportAsync(ProtocolModel _model)
        {
            //获取协议的所有属性
            List <ProtocolAttributeModel> attributes = ProtocolDB.GetAttributes(_model.PID);

            StringBuilder sbr = await Task.Run(() =>
            {
                //代码结果集
                StringBuilder sb = new StringBuilder();

                sb.Append("//===================================================\r\n");
                sb.Append($"//创建时间:{ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}\r\n");
                sb.Append("//备    注:\r\n");
                sb.Append("//===================================================\r\n");
                sb.Append("using System.Collections;\r\n");
                sb.Append("using System.Collections.Generic;\r\n");
                sb.Append("using System;\r\n");
                sb.Append("\r\n");
                sb.Append("/// <summary>\r\n");
                sb.Append($"/// {_model.CName}\r\n");
                sb.Append("/// </summary>\r\n");


                if (ProtocolDB.settingModel.UseNamespace)
                {
                    sb.AppendFormat($"namespace {ProtocolDB.settingModel.NamespaceContent}\r\n");
                    sb.AppendFormat("{{\r\n");//namespace Start
                }

                sb.Append($"public struct {_model.EName}Protocol\r\n");
                sb.AppendFormat("{{\r\n");//class Start
                sb.Append($"    public ushort Code {{ get {{ return {_model.Code}; }} }}\r\n");
                sb.Append("\r\n");

                #region 字段

                for (int i = 0; i < attributes.Count; i++)
                {
                    var att = attributes[i];

                    if (!string.IsNullOrEmpty(att.A2LoopEName))
                    {
                        //如果是从属某项循环的 不理会
                        continue;
                    }

                    //不从属循环的
                    if (att.IsLoop)
                    {
                        //如果当前是循环项
                        var loopAtts = attributes.Where(c => c.A2LoopEName == att.EName).OrderBy(c => c.Index).ToList();
                        for (int l = 0; l < loopAtts.Count; l++)
                        {
                            sb.Append($"    public List<{loopAtts[l].AType}> {loopAtts[l].EName}List; //{loopAtts[l].CName}\r\n");
                        }
                    }
                    else
                    {
                        //正常
                        sb.Append($"    public {att.AType} {att.EName}; //{att.CName}\r\n");
                    }
                }

                sb.Append("\r\n");

                #endregion

                #region ToArray

                sb.AppendFormat("    public byte[] ToArray()\r\n");
                sb.AppendFormat("    {{\r\n");//ToArray Start

                sb.AppendFormat("        using (JZ_MemoryStream ms = new JZ_MemoryStream())\r\n");
                sb.AppendFormat("        {{\r\n");//JZ_MemoryStream Start
                sb.AppendFormat("                ms.WriteUShort(Code);\r\n");

                for (int i = 0; i < attributes.Count; i++)
                {
                    var att = attributes[i];
                    if (!string.IsNullOrEmpty(att.A2LoopEName) || !string.IsNullOrEmpty(att.A2BoolEName) || !string.IsNullOrEmpty(att.A2StrEName))
                    {
                        //附属于其它属性的值 不处理 后面一起处理
                        continue;
                    }

                    if (att.IsLoop)
                    {
                        //本身是循环项
                        //查找依附于当前循环项的子项
                        var loopAtts = attributes.Where(c => c.A2LoopEName == att.EName).OrderBy(c => c.Index).ToList();
                        //输出子项数量
                        sb.AppendFormat($"            ms.WriteInt({loopAtts.Count});\r\n");
                        if (loopAtts != null && loopAtts.Count > 0)
                        {
                            for (int l = 0; l < loopAtts.Count; l++)
                            {
                                sb.Append($"for(int i=0;i<{loopAtts[l].EName}List.Count;i++)");
                                sb.AppendFormat("        {{\r\n");
                                sb.Append($"    ms.Write{ChangeTypeName(loopAtts[l].AType).Replace("()", "")} {loopAtts[l].EName}List[i]; //{loopAtts[l].CName}\r\n");
                                sb.AppendFormat("        }}\r\n");
                            }
                        }
                    }
                    else if (att.AType.ToLower() == "bool")
                    {
                        //正常
                        sb.AppendFormat($"            ms.Write{ChangeTypeName(att.AType).Replace("()", "")}({att.EName});\r\n");

                        //查看是否有关联项
                        var boolAtts = attributes.Where(c => c.A2BoolEName == att.EName).OrderBy(c => c.Index).ToList();
                        if (boolAtts != null && boolAtts.Count > 0)
                        {
                            //有bool关联
                            for (int b = 0; b < boolAtts.Count; b++)
                            {
                                string torf = att.A2Bool ? "" : "!";
                                sb.Append($"if({torf}{att.EName})");
                                sb.AppendFormat("        {{\r\n");
                                sb.Append($"    ms.Write{ChangeTypeName(boolAtts[b].AType).Replace("()", "")}({boolAtts[b].EName}); //{boolAtts[b].CName}\r\n");
                                sb.AppendFormat("        }}\r\n");
                            }
                        }
                    }
                    else if (att.AType.ToLower() == "string")
                    {
                        //本身是string项
                        //正常输出string内容
                        sb.AppendFormat($"            ms.Write{ChangeTypeName(att.AType).Replace("()", "")}({att.EName});\r\n");
                        //查找string附属
                        var stringAtts = attributes.Where(c => c.A2StrEName == att.EName).OrderBy(c => c.Index).ToList();
                        if (stringAtts != null && stringAtts.Count > 0)
                        {
                            for (int s = 0; s < stringAtts.Count; s++)
                            {
                                sb.Append($"if({att.EName}=={stringAtts[s].A2Str})");
                                sb.AppendFormat("        {{\r\n");
                                sb.Append($"    ms.Write{ChangeTypeName(stringAtts[s].AType).Replace("()", "")}({stringAtts[s].EName}); //{stringAtts[s].CName}\r\n");
                                sb.AppendFormat("        }}\r\n");
                            }
                        }
                    }
                    else
                    {
                        //其它项 正常处理
                        sb.AppendFormat("            ms.Write{0}({1});\r\n", ChangeTypeName(att.AType).Replace("()", ""), att.EName);
                    }
                }

                sb.AppendFormat("        }}\r\n"); //JZ_MemoryStream End
                sb.AppendFormat(" return ms.ToArray();\r\n");
                sb.AppendFormat("        }}\r\n"); //ToArray End

                #endregion

                #region ToProtocol


                sb.AppendFormat($"    public {_model.EName}Protocol ToProtocol(byte[] _buffer)\r\n");
                sb.AppendFormat("    {{\r\n");//ToProtocol Start
                sb.AppendFormat($"        {_model.EName}Protocol pro = new {_model.EName}Protocol();\r\n");
                sb.AppendFormat("        using (JZ_MemoryStream ms = new JZ_MemoryStream(_buffer))\r\n");
                sb.AppendFormat("        {{\r\n");//JZ_MemoryStream Start

                for (int i = 0; i < attributes.Count; i++)
                {
                    var att = attributes[i];
                    if (!string.IsNullOrEmpty(att.A2LoopEName) || !string.IsNullOrEmpty(att.A2BoolEName) || !string.IsNullOrEmpty(att.A2StrEName))
                    {
                        //附属于其它属性的值 不处理 后面一起处理
                        continue;
                    }

                    if (att.IsLoop)
                    {
                        //本身是循环项
                        //查找依附于当前循环项的子项
                        var loopAtts = attributes.Where(c => c.A2LoopEName == att.EName).OrderBy(c => c.Index).ToList();
                        //输出子项数量
                        sb.AppendFormat($"           int count= ms.ReadInt();\r\n");
                        if (loopAtts != null && loopAtts.Count > 0)
                        {
                            //字段初始化
                            for (int l = 0; l < loopAtts.Count; l++)
                            {
                                sb.Append($"    pro.{loopAtts[l].EName}List=new List<{loopAtts[l].AType}>();//{loopAtts[l].CName}\r\n");
                            }
                            //字段赋值
                            for (int l = 0; l < loopAtts.Count; l++)
                            {
                                sb.Append($"for(int i=0;i<count;i++)");
                                sb.AppendFormat("        {{\r\n");
                                sb.Append($"    pro.{loopAtts[l].EName}List.Add(ms.Read{ChangeTypeName(loopAtts[l].AType).Replace("()", "")}()); //{loopAtts[l].CName}\r\n");
                                sb.AppendFormat("        }}\r\n");
                            }
                        }
                    }
                    else if (att.AType.ToLower() == "bool")
                    {
                        //正常
                        sb.AppendFormat($"           pro.{att.EName}= ms.Read{ChangeTypeName(att.AType).Replace("()", "")}();\r\n");

                        //查看是否有关联项
                        var boolAtts = attributes.Where(c => c.A2BoolEName == att.EName).OrderBy(c => c.Index).ToList();
                        if (boolAtts != null && boolAtts.Count > 0)
                        {
                            //有bool关联
                            for (int b = 0; b < boolAtts.Count; b++)
                            {
                                string torf = att.A2Bool ? "" : "!";
                                sb.Append($"if({torf}{att.EName})");
                                sb.AppendFormat("        {{\r\n");
                                sb.Append($"   pro.{boolAtts[b].EName}= ms.Read{ChangeTypeName(boolAtts[b].AType).Replace("()", "")}(); //{boolAtts[b].CName}\r\n");
                                sb.AppendFormat("        }}\r\n");
                            }
                        }
                    }
                    else if (att.AType.ToLower() == "string")
                    {
                        //本身是string项
                        //正常输出string内容
                        sb.AppendFormat($"           pro.{att.EName}= ms.Read{ChangeTypeName(att.AType).Replace("()", "")}();\r\n");
                        //查找string附属
                        var stringAtts = attributes.Where(c => c.A2StrEName == att.EName).OrderBy(c => c.Index).ToList();
                        if (stringAtts != null && stringAtts.Count > 0)
                        {
                            for (int s = 0; s < stringAtts.Count; s++)
                            {
                                sb.Append($"if({att.EName}=={stringAtts[s].A2Str})");
                                sb.AppendFormat("        {{\r\n");
                                sb.Append($"   pro.{stringAtts[s].EName}= ms.Read{ChangeTypeName(stringAtts[s].AType).Replace("()", "")}(); //{stringAtts[s].CName}\r\n");
                                sb.AppendFormat("        }}\r\n");
                            }
                        }
                    }
                    else
                    {
                        //其它项 正常处理
                        sb.AppendFormat("           pro.{1}= ms.Read{0}();\r\n", ChangeTypeName(att.AType).Replace("()", ""), att.EName);
                    }
                }

                sb.AppendFormat("        return pro;\r\n");
                sb.AppendFormat("        }}\r\n"); //JZ_MemoryStream End
                sb.AppendFormat("        }}\r\n"); //ToProtocol End

                #endregion

                sb.AppendFormat("        }}\r\n");//class End


                if (ProtocolDB.settingModel.UseNamespace)
                {
                    sb.AppendFormat("}}\r\n");//namespace End
                }

                return(sb);
            });

            using (FileStream fs = new FileStream(string.Format("{0}/{1}Protocol.cs", saveFolder, _model.EName), FileMode.Create))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    sw.Write(sbr.ToString());
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 保存当前协议
        /// </summary>
        private void SaveProto()
        {
            if (selectedNode == null)
            {
                return;
            }
            if (selectedNode.TagType != NodeSelectTag.TAGTYPE.Protocol)
            {
                MessageBox.Show("当前状态下不能进行保存,请正确选择需要保存的协议");
                return;
            }

            if (txtProtoCode.Text.Trim() == "-1" || string.IsNullOrEmpty(this.txtProtoCode.Text.Trim()))
            {
                MessageBox.Show("请输入协议编码 只能是数字");
                txtProtoCode.Focus();
                return;
            }

            int protoCode = 0;

            if (!int.TryParse(this.txtProtoCode.Text, out protoCode))
            {
                MessageBox.Show("协议编码 只能是数字");
                txtProtoCode.Focus();
                return;
            }

            if (string.IsNullOrEmpty(this.txtProtoEnName.Text.Trim()))
            {
                MessageBox.Show("请输入协议英文名称");
                txtProtoEnName.Focus();
                return;
            }

            if (string.IsNullOrEmpty(this.txtProtoCnName.Text.Trim()))
            {
                MessageBox.Show("请输入协议中文名称");
                txtProtoCnName.Focus();
                return;
            }

            ProtocolModel currModel = selectedNode.Model as ProtocolModel;

            currModel.Code  = protoCode;
            currModel.EName = txtProtoEnName.Text.Trim();
            currModel.CName = txtProtoCnName.Text.Trim();
            currModel.Desc  = txtProtoDesc.Text.Trim();

            for (int i = 0; i < dvGrid.Rows.Count - 1; i++)
            {
                ProtocolAttributeModel attModel = new ProtocolAttributeModel();

                attModel.AType       = dvGrid.Rows[i].Cells[0].Value == null ? "" : dvGrid.Rows[i].Cells[0].Value.ToString();
                attModel.EName       = dvGrid.Rows[i].Cells[1].Value == null ? "" : dvGrid.Rows[i].Cells[1].Value.ToString();
                attModel.CName       = dvGrid.Rows[i].Cells[2].Value == null ? "" : dvGrid.Rows[i].Cells[2].Value.ToString();
                attModel.IsLoop      = dvGrid.Rows[i].Cells[3].Value == null ? false : Convert.ToBoolean(dvGrid.Rows[i].Cells[3].Value);
                attModel.A2LoopEName = dvGrid.Rows[i].Cells[4].Value == null ? "" : dvGrid.Rows[i].Cells[4].Value.ToString();
                attModel.A2BoolEName = dvGrid.Rows[i].Cells[5].Value == null ? "" : dvGrid.Rows[i].Cells[5].Value.ToString();
                attModel.A2Bool      = dvGrid.Rows[i].Cells[6].Value == null ? false : Convert.ToBoolean(dvGrid.Rows[i].Cells[6].Value);
                attModel.A2StrEName  = dvGrid.Rows[i].Cells[7].Value == null ? "" : dvGrid.Rows[i].Cells[7].Value.ToString();
                attModel.A2Str       = dvGrid.Rows[i].Cells[8].Value == null ? "" : dvGrid.Rows[i].Cells[8].Value.ToString();
                attModel.PAID        = dvGrid.Rows[i].Cells[9].Value == null?Guid.NewGuid().ToString() : dvGrid.Rows[i].Cells[9].Value.ToString();

                attModel.PID = dvGrid.Rows[i].Cells[10].Value == null ? currModel.PID : dvGrid.Rows[i].Cells[10].Value.ToString();

                if (!ProtocolDB.UpdateAttributes(attModel))
                {
                    MessageBox.Show($"{attModel.CName} 更新失败");
                }
            }

            if (ProtocolDB.UpdateProtocol(currModel))
            {
                ShowInfo(InfoType.Succeed, "保存成功");
            }
            else
            {
                ShowInfo(InfoType.Error, "协议更改失败");
            }

            selectedNode.Model       = currModel;
            selectedNode.Target.Text = $"[协议]{ currModel.Code}-{currModel.CName}";
            myTree.Refresh();
        }
Exemplo n.º 12
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);
        }