当前位置: 首页 > news >正文

c# xml 参数配置表的使用

使用简介

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
实际使用界面

在这里插入图片描述

配置表管理界面

在这里插入图片描述

进入

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;using Sunny.UI;
using System.Xml;
using System.IO;
        public ModuleGrid(){InitializeComponent();uipanelMain.AutoScroll = true;//防止内容过多 当显示不下的时候 可以有滚轮//DisplayData();//这个在这里使用不知道为什么就是报错 显示未将对象设置引用到对象实例  我直接放最开始调用//MessageBox.Show("kai ");}

在这里插入图片描述

        public static ModuleGrid modgrid;private void uiButton1_Click(object sender, EventArgs e){modgrid = new ModuleGrid();modgrid.Show();ModuleGrid.DisplayData();//这个函数的作用就是新增我们需要的框的控件}
       private static int width = 360;private static int height = 254;private static List<GridContent> list;public static string path = Directory.GetCurrentDirectory()+ "\\ParameterSet\\grid.xml";public static void DisplayData(){try{list = new List<GridContent>();XmlDocument doc = new XmlDocument();doc.Load(path);XmlNodeList nodeList = doc.SelectNodes("/person/list");//xPath相关手册,找节点person的listint index = 1;foreach (XmlNode node in nodeList){string no = node.Attributes["no"].Value;string modeName = node.SelectSingleNode("modeName").InnerText;//MessageBox.Show("modeName:" + modeName);GridContent grid = new GridContent();grid.No = no;list.Add(grid);addUIItem(index, modeName);//UI增加index++;}}catch (Exception ex){log.SaveLog(@"报告模板异常:" + ex.Message);}}
 class GridContent{private string modeName;private string no;public string ModeName{get{return modeName;}set{modeName = value;}}public string No{get{return no;}set{no = value;}}}
private static void addUIItem(int index, string modeName){//1724 -50 - 4*width =   78UIPanel paneln = new UIPanel();int curIndex = index / 4;int mod = index % 4;int pointX = (width + 65) * (mod) + 25;int pointY = curIndex * (height) + (curIndex + 1) * 25;paneln.Location = new Point(pointX, pointY);paneln.Size = new Size(width, height);paneln.FillColor = Color.White;paneln.RectColor = ColorTranslator.FromHtml("#D6D6D6");UILabel label = new UILabel();label.AutoSize = false;label.Text = modeName;label.Location = new Point(40, 20);label.Size = new Size(300, 90);label.Font = new System.Drawing.Font("微软雅黑", 16F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));label.TextAlign = ContentAlignment.MiddleCenter;UIButton btnDel = new UIButton();btnDel.Size = new Size(100, 50);btnDel.Location = new Point(50, 170);btnDel.Font = new System.Drawing.Font("微软雅黑", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));btnDel.FillColor = Color.White;btnDel.RectColor = ColorTranslator.FromHtml("#D6D6D6");btnDel.ForeColor = ColorTranslator.FromHtml("#333333");btnDel.Text = "删除";btnDel.Tag = list[index - 1].No;btnDel.Click += new System.EventHandler(btnDel_Click);UIButton btnEdit = new UIButton();btnEdit.Size = new Size(100, 50);btnEdit.Location = new Point(220, 170);btnEdit.Font = new System.Drawing.Font("微软雅黑", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));btnEdit.FillColor = Color.White;btnEdit.RectColor = ColorTranslator.FromHtml("#D6D6D6");btnEdit.ForeColor = ColorTranslator.FromHtml("#333333");btnEdit.Text = "编辑";btnEdit.Tag = list[index - 1].No;btnEdit.Click += new EventHandler(btnEdit_Click);paneln.Controls.Add(label);paneln.Controls.Add(btnDel);paneln.Controls.Add(btnEdit);Form1.modgrid.uipanelMain.Controls.Add(paneln);}

确定和返回按键

this.Close();

新增项的按键

在进入的addUIItem函数里面添加的

在这里插入图片描述

编辑

 private static void btnEdit_Click(object sender, EventArgs e){UIButton btn = (UIButton)sender;string no = btn.Tag.ToString();//  new AddModule("edit", no, uipanelMain).Show();AddModule frm = new AddModule("edit", no, Form1.modgrid.uipanelMain);    frm.Show();Form1.modgrid.Hide();//如果是关闭 那么下次是无法show的}

删除

 private static void btnDel_Click(object sender, EventArgs e){UIButton btn = (UIButton)sender;string no = btn.Tag.ToString();delUI();delGridItem(no);//this.Invalidate();//this.Refresh();}public static void delUI(){int index = 0;for (int i = list.Count() - 1; i >= 0; i--){index = (i + 1);Form1.modgrid.uipanelMain.Controls.RemoveAt(index);}}private static void delGridItem(string no){XmlDocument doc = new XmlDocument();doc.Load(path);XmlElement root = doc.DocumentElement;XmlNodeList xmlNodeList = doc.SelectNodes("/person/list[@no='" + no + "']");foreach (XmlNode xmlNode in xmlNodeList){xmlNode.ParentNode.RemoveChild(xmlNode);}doc.Save(path);DisplayData();}

新增一个
在这里插入图片描述

        private void uiPanel3_Click(object sender, EventArgs e){OpenAddModule();}private void pictureBox2_Click(object sender, EventArgs e){OpenAddModule();}private void uiLabel3_Click(object sender, EventArgs e){OpenAddModule();}public static void OpenAddModule(){AddModule frm = new AddModule("add", "", Form1.modgrid.uipanelMain);frm.Show();Form1.modgrid.Hide();//如果是关闭 那么下次是无法show的}

页面传递讲解

        public static void OpenAddModule(){AddModule frm = new AddModule("add", "", Form1.modgrid.uipanelMain);frm.Show();Form1.modgrid.Hide();//如果是关闭 那么下次是无法show的}

要打开的界面 给他一个带参数的构造函数就可以了

        string no;UIPanel uipanel;string type;public static string path = Directory.GetCurrentDirectory() + "\\ParameterSet\\grid.xml";public AddModule(string type, string no, UIPanel uipanel)//这三个参数都是自己新加的 不然是没有参数的 用于上一页面传入参数进来{InitializeComponent();this.no = no;this.type = type;this.uipanel = uipanel;if (type.Equals("add")){labelTItle.Text = "新增配置表";}else if (type.Equals("edit")){try{labelTItle.Text = "编辑配置表";//赋值XmlDocument doc = new XmlDocument();doc.Load(path);XmlNodeList xmlNodeList = doc.SelectNodes("/person/list[@no='" + no + "']");XmlNode node = xmlNodeList[0];tmodelName.Text = node.SelectSingleNode("modeName").InnerText;clientTextBox.Text = node.SelectSingleNode("client").InnerText;hardwareTextBox.Text = node.SelectSingleNode("hardware").InnerText;softwareTextBox.Text = node.SelectSingleNode("software").InnerText;tongshuTextBox.Text = node.SelectSingleNode("tongshu").InnerText;kongshuTextBox.Text = node.SelectSingleNode("kongshu").InnerText;TMCuiTextBox.Text = node.SelectSingleNode("tmc").InnerText;typeuiTextBox.Text = node.SelectSingleNode("type").InnerText;order1TextBox.Text = node.SelectSingleNode("order1").InnerText;order2TextBox.Text = node.SelectSingleNode("order2").InnerText;order3TextBox.Text = node.SelectSingleNode("order3").InnerText;order4TextBox.Text = node.SelectSingleNode("order4").InnerText;order5TextBox.Text = node.SelectSingleNode("order5").InnerText;order6TextBox.Text = node.SelectSingleNode("order6").InnerText;order7TextBox.Text = node.SelectSingleNode("order7").InnerText;order8TextBox.Text = node.SelectSingleNode("order8").InnerText;order9TextBox.Text = node.SelectSingleNode("order9").InnerText;order10TextBox.Text = node.SelectSingleNode("order10").InnerText;order11TextBox.Text = node.SelectSingleNode("order11").InnerText;order12TextBox.Text = node.SelectSingleNode("order12").InnerText;order13TextBox.Text = node.SelectSingleNode("order13").InnerText;}catch (Exception ex){log.SaveLog(ex.ToString());throw;}}}

新增页面

在这里插入图片描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using Sunny.UI;

构造函数

可以进行参数的传递

        string no;UIPanel uipanel;string type;public static string path = Directory.GetCurrentDirectory() + "\\ParameterSet\\grid.xml";public AddModule(string type, string no, UIPanel uipanel)//这三个参数都是自己新加的 不然是没有参数的 用于上一页面传入参数进来{InitializeComponent();this.no = no;this.type = type;this.uipanel = uipanel;if (type.Equals("add")){labelTItle.Text = "新增配置表";}else if (type.Equals("edit")){try{labelTItle.Text = "编辑配置表";//赋值XmlDocument doc = new XmlDocument();doc.Load(path);XmlNodeList xmlNodeList = doc.SelectNodes("/person/list[@no='" + no + "']");XmlNode node = xmlNodeList[0];tmodelName.Text = node.SelectSingleNode("modeName").InnerText;clientTextBox.Text = node.SelectSingleNode("client").InnerText;hardwareTextBox.Text = node.SelectSingleNode("hardware").InnerText;softwareTextBox.Text = node.SelectSingleNode("software").InnerText;tongshuTextBox.Text = node.SelectSingleNode("tongshu").InnerText;kongshuTextBox.Text = node.SelectSingleNode("kongshu").InnerText;TMCuiTextBox.Text = node.SelectSingleNode("tmc").InnerText;typeuiTextBox.Text = node.SelectSingleNode("type").InnerText;order1TextBox.Text = node.SelectSingleNode("order1").InnerText;order2TextBox.Text = node.SelectSingleNode("order2").InnerText;order3TextBox.Text = node.SelectSingleNode("order3").InnerText;order4TextBox.Text = node.SelectSingleNode("order4").InnerText;order5TextBox.Text = node.SelectSingleNode("order5").InnerText;order6TextBox.Text = node.SelectSingleNode("order6").InnerText;order7TextBox.Text = node.SelectSingleNode("order7").InnerText;order8TextBox.Text = node.SelectSingleNode("order8").InnerText;order9TextBox.Text = node.SelectSingleNode("order9").InnerText;order10TextBox.Text = node.SelectSingleNode("order10").InnerText;order11TextBox.Text = node.SelectSingleNode("order11").InnerText;order12TextBox.Text = node.SelectSingleNode("order12").InnerText;order13TextBox.Text = node.SelectSingleNode("order13").InnerText;}catch (Exception ex){log.SaveLog(ex.ToString());throw;}}}

load函数

进行一次自动的指令到指令名称的转换。如果该指令不等于0的话就进行一次转换

 private void AddModule_Load(object sender, EventArgs e){try{if (order1TextBox.Text != "0"){order1uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order1TextBox.Text.Substring(0, order1TextBox.Text.IndexOf('*'))));//log.SaveLog("指令转换1字符串:" + order1TextBox.Text.Substring(0, order1TextBox.Text.IndexOf('*')));//for (int i = 0; i < 5; i++)//{//    log.SaveLog("转字节{i}:" + Form1.strToToHexByte(order1TextBox.Text.Substring(0, order1TextBox.Text.IndexOf('*')))[i]);//}}if (order2TextBox.Text != "0"){order2uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order2TextBox.Text.Substring(0, order2TextBox.Text.IndexOf('*'))));}if (order3TextBox.Text != "0"){order3uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order3TextBox.Text.Substring(0, order3TextBox.Text.IndexOf('*'))));}if (order4TextBox.Text != "0"){order4uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order4TextBox.Text.Substring(0, order4TextBox.Text.IndexOf('*'))));}if (order5TextBox.Text != "0"){order5uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order5TextBox.Text.Substring(0, order5TextBox.Text.IndexOf('*'))));}if (order6TextBox.Text != "0"){order6uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order6TextBox.Text.Substring(0, order6TextBox.Text.IndexOf('*'))));}if (order7TextBox.Text != "0"){order7uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order7TextBox.Text.Substring(0, order7TextBox.Text.IndexOf('*'))));}if (order8TextBox.Text != "0"){order8uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order8TextBox.Text.Substring(0, order8TextBox.Text.IndexOf('*'))));}if (order9TextBox.Text != "0"){order9uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order9TextBox.Text.Substring(0, order9TextBox.Text.IndexOf('*'))));}if (order10TextBox.Text != "0"){order10uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order10TextBox.Text.Substring(0, order10TextBox.Text.IndexOf('*'))));}if (order11TextBox.Text != "0"){order11uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order11TextBox.Text.Substring(0, order11TextBox.Text.IndexOf('*'))));}if (order12TextBox.Text != "0"){order12uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order12TextBox.Text.Substring(0, order12TextBox.Text.IndexOf('*'))));}if (order13TextBox.Text != "0"){order13uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order13TextBox.Text.Substring(0, order13TextBox.Text.IndexOf('*'))));}}catch (Exception ex){log.SaveLog("配置表转换报错:" + ex.Message);}}

字符串转字节

        public static byte[] strToToHexByte(string hexString){hexString = hexString.Replace(" ", "");//去掉空格if ((hexString.Length % 2) != 0)hexString += " ";byte[] returnBytes = new byte[hexString.Length / 2];//字符串两个就是一个十六进制数for (int i = 0; i < returnBytes.Length; i++)returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);return returnBytes;}

根据第二个字节进行对应指令的查找

public static string judgeFun(byte[] a){string orderName = "0";if (a[2] == 1){orderName = "恢复出厂设置";}else if (a[2] == 2) {  orderName = "设置本机地址"; }else if (a[2] == 3) { orderName = "读取本机地址"; }else if (a[2] == 4) { orderName = "设置波特率"; }else if (a[2] == 5) { orderName = "复位"; }else if (a[2] == 6) { orderName = "切换通道"; }else if (a[2] == 7) { orderName = "读当前通道"; }else if (a[2] == 8) { orderName = "读版本"; }else if (a[2] == 9) { orderName = "设置CRC校验"; }else if (a[2] == 0xA) { orderName = "查询最大通道"; }else if (a[2] == 0xB) { orderName = "设置最大通道"; }else if (a[2] == 0xC) { orderName = "查正向补偿"; }else if (a[2] == 0xE) { orderName = "查反向补偿"; }else if (a[2] == 10) { orderName = "查通讯方式"; }else if (a[2] == 11) { orderName = "设置通讯方式";}else if (a[2] == 12) {orderName = "查电机最小速度";}else if (a[2] == 13) {orderName = "设置电机最小速度";}else if (a[2] == 14) {orderName = "查电机最大速度";}else if (a[2] == 15) {orderName = "设置电机最大速度";}else if (a[2] == 16) {orderName = "查丢步报错阈值";}else if (a[2] == 17) {orderName = "设置丢步报错阈值";}else if (a[2] == 80) {orderName = "常规报错";}else if (a[2] == 81) {orderName = "电机正向失步";}else if (a[2] == 82) {orderName = "电机反向失步";}else if (a[2] == 83) {orderName = "异常断电未归零";}else if (a[2] == 18) {orderName = "查磁场强度";}else if (a[2] == 19) {orderName = "磁编校准";}return orderName;}

确定按钮

 private void uiButton1_Click(object sender, EventArgs e){XmlDocument doc = new XmlDocument();if (type.Equals("add")){log.SaveLog(@"新增模板");DateTime dt = new DateTime();dt = System.DateTime.Now;//此处的大小写必须完全按照如下才能输出长日期长时间,时间为24小时制式,hh:mm:ss格式输出12小时制式时间string no = dt.ToString("yyyyMMddHHmmss");if (!File.Exists(path)){//新建一个xml文档//1、实例化一个XmlDocumentXmlDeclaration xnode = doc.CreateXmlDeclaration("1.0", "UTF-8", "");doc.AppendChild(xnode);XmlElement root = doc.CreateElement("person");doc.AppendChild(root);XmlElement newElement = doc.CreateElement("list");newElement.SetAttribute("no", no);//添加属性root.AppendChild(newElement);XmlElement modeName = doc.CreateElement("modeName");modeName.InnerText = tmodelName.Text;newElement.AppendChild(modeName);XmlElement client = doc.CreateElement("client");client.InnerText = clientTextBox.Text;newElement.AppendChild(client);XmlElement hardware = doc.CreateElement("hardware");hardware.InnerText = hardwareTextBox.Text;newElement.AppendChild(hardware);XmlElement software = doc.CreateElement("software");software.InnerText = softwareTextBox.Text;newElement.AppendChild(software);XmlElement tongshu = doc.CreateElement("tongshu");tongshu.InnerText = tongshuTextBox.Text;newElement.AppendChild(tongshu);XmlElement kongshu = doc.CreateElement("kongshu");kongshu.InnerText = kongshuTextBox.Text;newElement.AppendChild(kongshu);XmlElement TMC = doc.CreateElement("tmc");TMC.InnerText = tongshuTextBox.Text;newElement.AppendChild(TMC);XmlElement type = doc.CreateElement("type");type.InnerText = kongshuTextBox.Text;newElement.AppendChild(type);XmlElement order1 = doc.CreateElement("order1");order1.InnerText = order1TextBox.Text;newElement.AppendChild(order1);XmlElement order2 = doc.CreateElement("order2");order2.InnerText = order2TextBox.Text;newElement.AppendChild(order2);XmlElement order3 = doc.CreateElement("order3");order3.InnerText = order3TextBox.Text;newElement.AppendChild(order3);XmlElement order4 = doc.CreateElement("order4");order4.InnerText = order4TextBox.Text;newElement.AppendChild(order4);XmlElement order5 = doc.CreateElement("order5");order5.InnerText = order5TextBox.Text;newElement.AppendChild(order5);XmlElement order6= doc.CreateElement("order6");order6.InnerText = order6TextBox.Text;newElement.AppendChild(order6);XmlElement order7 = doc.CreateElement("order7");order7.InnerText = order7TextBox.Text;newElement.AppendChild(order7);XmlElement order8 = doc.CreateElement("order8");order8.InnerText = order8TextBox.Text;newElement.AppendChild(order8);XmlElement order9 = doc.CreateElement("order9");order9.InnerText = order9TextBox.Text;newElement.AppendChild(order9);XmlElement order10 = doc.CreateElement("order10");order10.InnerText = order10TextBox.Text;newElement.AppendChild(order10);XmlElement order11 = doc.CreateElement("order11");order11.InnerText = order11TextBox.Text;newElement.AppendChild(order11);XmlElement order12 = doc.CreateElement("order12");order12.InnerText = order12TextBox.Text;newElement.AppendChild(order12);XmlElement order13 = doc.CreateElement("order13");order13.InnerText = order13TextBox.Text;newElement.AppendChild(order13);root.AppendChild(newElement);doc.Save(path);//注意这个的save路径是需要加上 .xml的this.Close();Form1.modgrid.Show();}else{doc.Load(path);XmlElement root = doc.DocumentElement;XmlElement newElement = doc.CreateElement("list");newElement.SetAttribute("no", no);//添加属性root.AppendChild(newElement);XmlElement modeName = doc.CreateElement("modeName");modeName.InnerText = tmodelName.Text;newElement.AppendChild(modeName);XmlElement client = doc.CreateElement("client");client.InnerText = clientTextBox.Text;newElement.AppendChild(client);XmlElement hardware = doc.CreateElement("hardware");hardware.InnerText = hardwareTextBox.Text;newElement.AppendChild(hardware);XmlElement software = doc.CreateElement("software");software.InnerText = softwareTextBox.Text;newElement.AppendChild(software);XmlElement tongshu = doc.CreateElement("tongshu");tongshu.InnerText = tongshuTextBox.Text;newElement.AppendChild(tongshu);XmlElement kongshu = doc.CreateElement("kongshu");kongshu.InnerText = kongshuTextBox.Text;newElement.AppendChild(kongshu);XmlElement TMC = doc.CreateElement("tmc");TMC.InnerText = tongshuTextBox.Text;newElement.AppendChild(TMC);XmlElement type = doc.CreateElement("type");type.InnerText = kongshuTextBox.Text;newElement.AppendChild(type);XmlElement order1 = doc.CreateElement("order1");order1.InnerText = order1TextBox.Text;newElement.AppendChild(order1);XmlElement order2 = doc.CreateElement("order2");order2.InnerText = order2TextBox.Text;newElement.AppendChild(order2);XmlElement order3 = doc.CreateElement("order3");order3.InnerText = order3TextBox.Text;newElement.AppendChild(order3);XmlElement order4 = doc.CreateElement("order4");order4.InnerText = order4TextBox.Text;newElement.AppendChild(order4);XmlElement order5 = doc.CreateElement("order5");order5.InnerText = order5TextBox.Text;newElement.AppendChild(order5);XmlElement order6 = doc.CreateElement("order6");order6.InnerText = order6TextBox.Text;newElement.AppendChild(order6);XmlElement order7 = doc.CreateElement("order7");order7.InnerText = order7TextBox.Text;newElement.AppendChild(order7);XmlElement order8 = doc.CreateElement("order8");order8.InnerText = order8TextBox.Text;newElement.AppendChild(order8);XmlElement order9 = doc.CreateElement("order9");order9.InnerText = order9TextBox.Text;newElement.AppendChild(order9);XmlElement order10 = doc.CreateElement("order10");order10.InnerText = order10TextBox.Text;newElement.AppendChild(order10);XmlElement order11 = doc.CreateElement("order11");order11.InnerText = order11TextBox.Text;newElement.AppendChild(order11);XmlElement order12 = doc.CreateElement("order12");order12.InnerText = order12TextBox.Text;newElement.AppendChild(order12);XmlElement order13 = doc.CreateElement("order13");order13.InnerText = order13TextBox.Text;newElement.AppendChild(order13);root.AppendChild(newElement);this.Close();Form1.modgrid.Show();}}else if (type.Equals("edit")){log.SaveLog(@"编辑模板");doc.Load(path);XmlNodeList xmlNodeList = doc.SelectNodes("/person/list[@no='" + no + "']");xmlNodeList[0].SelectSingleNode("modeName").InnerText = tmodelName.Text;xmlNodeList[0].SelectSingleNode("client").InnerText = clientTextBox.Text;xmlNodeList[0].SelectSingleNode("hardware").InnerText = hardwareTextBox.Text;xmlNodeList[0].SelectSingleNode("software").InnerText = softwareTextBox.Text;xmlNodeList[0].SelectSingleNode("tongshu").InnerText = tongshuTextBox.Text;xmlNodeList[0].SelectSingleNode("kongshu").InnerText = kongshuTextBox.Text;xmlNodeList[0].SelectSingleNode("tmc").InnerText = TMCuiTextBox.Text;xmlNodeList[0].SelectSingleNode("type").InnerText = typeuiTextBox.Text;xmlNodeList[0].SelectSingleNode("order1").InnerText = order1TextBox.Text;xmlNodeList[0].SelectSingleNode("order2").InnerText = order2TextBox.Text;xmlNodeList[0].SelectSingleNode("order3").InnerText = order3TextBox.Text;xmlNodeList[0].SelectSingleNode("order4").InnerText = order4TextBox.Text;xmlNodeList[0].SelectSingleNode("order5").InnerText = order5TextBox.Text;xmlNodeList[0].SelectSingleNode("order6").InnerText = order6TextBox.Text;xmlNodeList[0].SelectSingleNode("order7").InnerText = order7TextBox.Text;xmlNodeList[0].SelectSingleNode("order8").InnerText = order8TextBox.Text;xmlNodeList[0].SelectSingleNode("order9").InnerText = order9TextBox.Text;xmlNodeList[0].SelectSingleNode("order10").InnerText = order10TextBox.Text;xmlNodeList[0].SelectSingleNode("order11").InnerText = order11TextBox.Text;xmlNodeList[0].SelectSingleNode("order12").InnerText = order12TextBox.Text;xmlNodeList[0].SelectSingleNode("order13").InnerText = order13TextBox.Text;}doc.Save(path);ModuleGrid.delUI();ModuleGrid.DisplayData();this.Close();Form1.modgrid.Show();}

返回

        private void uiButton2_Click(object sender, EventArgs e){this.Close();Form1.modgrid.Show();}

转换

 private void uiButton3_Click(object sender, EventArgs e){try{if (order1TextBox.Text!="0"){order1uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order1TextBox.Text.Substring(0, order1TextBox.Text.IndexOf('*'))));//log.SaveLog("指令转换1字符串:" + order1TextBox.Text.Substring(0, order1TextBox.Text.IndexOf('*')));//for (int i = 0; i < 5; i++)//{//    log.SaveLog("转字节{i}:" + Form1.strToToHexByte(order1TextBox.Text.Substring(0, order1TextBox.Text.IndexOf('*')))[i]);//}}if (order2TextBox.Text != "0"){order2uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order2TextBox.Text.Substring(0, order2TextBox.Text.IndexOf('*'))));}             if (order3TextBox.Text != "0"){order3uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order3TextBox.Text.Substring(0, order3TextBox.Text.IndexOf('*'))));}if (order4TextBox.Text != "0"){order4uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order4TextBox.Text.Substring(0, order4TextBox.Text.IndexOf('*'))));}if (order5TextBox.Text != "0"){order5uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order5TextBox.Text.Substring(0, order5TextBox.Text.IndexOf('*'))));}if (order6TextBox.Text != "0"){order6uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order6TextBox.Text.Substring(0, order6TextBox.Text.IndexOf('*'))));}if (order7TextBox.Text != "0"){order7uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order7TextBox.Text.Substring(0, order7TextBox.Text.IndexOf('*'))));}if (order8TextBox.Text != "0"){order8uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order8TextBox.Text.Substring(0, order8TextBox.Text.IndexOf('*'))));}if (order9TextBox.Text != "0"){order9uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order9TextBox.Text.Substring(0, order9TextBox.Text.IndexOf('*'))));}if (order10TextBox.Text != "0"){order10uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order10TextBox.Text.Substring(0, order10TextBox.Text.IndexOf('*'))));}if (order11TextBox.Text != "0"){order11uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order11TextBox.Text.Substring(0, order11TextBox.Text.IndexOf('*'))));}if (order12TextBox.Text != "0"){order12uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order12TextBox.Text.Substring(0, order12TextBox.Text.IndexOf('*'))));}if (order13TextBox.Text != "0"){order13uiLabel.Text = Form1.judgeFun(Form1.strToToHexByte(order13TextBox.Text.Substring(0, order13TextBox.Text.IndexOf('*'))));}}catch (Exception ex){log.SaveLog("配置表转换报错:" + ex.Message);}}

使用界面

在这里插入图片描述

读配置表

private void uiButton6_Click(object sender, EventArgs e){try{string str = uiComboBox1.Text.Trim();index = 0;if (str == String.Empty){MessageBox.Show("请先选择配置表");return;}else{//发送指令string no = "0";XmlDocument doc = new XmlDocument();doc.Load(AddModule.path);XmlNodeList nodeList = doc.SelectNodes("/person/list");//xPath相关手册,找节点person的list    foreach (XmlNode node1 in nodeList){string modeName = node1.SelectSingleNode("modeName").InnerText;if (modeName == uiComboBox1.Text){no = node1.Attributes["no"].Value;break;}else{continue;}}if (no == "0"){return;MessageBox.Show("未读取到配置表");}xmlNodeList = doc.SelectNodes("/person/list[@no='" + no + "']");node = xmlNodeList[0];label2.Text= "客户:"+node.SelectSingleNode("client").InnerText;label3.Text = "TMC/磁编:" + node.SelectSingleNode("tmc").InnerText;label4.Text = "型号:" + node.SelectSingleNode("type").InnerText;label5.Text = "通数:" + node.SelectSingleNode("tongshu").InnerText;uiButton4.Enabled = true;uiButton8.Enabled = true;tableFlag = true;}}catch (Exception ex){throw;}}

选择配置按钮点击

在这里插入图片描述
更新一下有哪些配置表

        private void uiComboBox1_ButtonClick(object sender, EventArgs e){ UpdateCfgTable();}
 public static string path = Directory.GetCurrentDirectory()+ "\\ParameterSet\\grid.xml";public void UpdateCfgTable(){XmlDocument doc = new XmlDocument();doc.Load(ModuleGrid.path);XmlNodeList nodeList = doc.SelectNodes("/person/list");//xPath相关手册,找节点person的listuiComboBox1.Items.Clear();foreach (XmlNode node in nodeList){string modeName = node.SelectSingleNode("modeName").InnerText;uiComboBox1.Items.Add(modeName);uiComboBox1.Text = modeName;}}

相关文章:

c# xml 参数配置表的使用

使用简介 实际使用界面 配置表管理界面 进入 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;…...

ubuntu20.04 nerf Instant-ngp

Instant-ngp linux ubuntu 20.04 GPU RTX3050Ti Instant-ngp官方文档地址 https://github.com/NVlabs/instant-ngp 参考链接Instant-ngp linux部署及使用 - 简书 Ubuntu20.04复现instant-ngp&#xff0c;自建数据集&#xff0c;导出mesh_XINYU W的博客-CSDN博客 步骤 安装基…...

隐写术--python隐写

0x00 背景 何为隐写术&#xff1f; 隐写术是一类可以隐藏自己写的一些东西的方法&#xff0c;是一门关于信息隐藏的技巧与科学。指的是采取一些不让除预期的接收者之外的任何人知晓信息的传递事件或者信息的内容的方法。 可参考 一文让你完全弄懂Stegosaurus - 知乎 本文要…...

MySQL的InnoDB存储引擎中的自适应哈希索引技术

一、自适应哈希索引的工作机制与优化策略 MySQL的InnoDB存储引擎使用了一种叫做自适应哈希索引&#xff08;Adaptive Hash Indexes&#xff09;的技术。在某些索引值被频繁访问的情况下&#xff0c;InnoDB会自动在内存中为这些值建立哈希索引&#xff0c;以加速查询操作。 何…...

交互设计主要做什么?新手入门必读

什么是交互设计&#xff1f;它涉及哪些内容&#xff1f;交互设计师是什么样的人群&#xff1f;他们到底是做什么的&#xff1f;他们身怀什么技能&#xff1f;他们工作的价值在哪里&#xff1f;交互设计行业的现状是怎样的&#xff1f;工作前景又是如何的&#xff1f; 如果你心…...

【深度学习实验】循环神经网络(三):门控制——自定义循环神经网络LSTM(长短期记忆网络)模型

目录 一、实验介绍 二、实验环境 1. 配置虚拟环境 2. 库版本介绍 三、实验内容 0. 导入必要的工具包 1. LSTM类 a.__init__&#xff08;初始化&#xff09; b. init_state&#xff08;初始化隐藏状态&#xff09; c. forward(前向传播) 2. RNNModel类 a.__init__&am…...

flutter 消息并发时处理,递归查询

收到新消息的时候执行receiveNewConversation方法 可以自己模拟一下两条数据插入&#xff0c;延时执行插入会话的操作 收到一条新的会话消息&#xff0c;先记录会话ID到列表&#xff0c;直到第一条处理完&#xff08;插入数据库后清理这个会话ID&#xff09;&#xff0c;才处理…...

第五十八章 学习常用技能 - 查看查询缓存

文章目录 第五十八章 学习常用技能 - 查看查询缓存查看查询缓存建立索引使用调谐表工具 第五十八章 学习常用技能 - 查看查询缓存 查看查询缓存 对于 SQL&#xff08;用作嵌入式 SQL 时除外&#xff09;&#xff0c;系统会生成可重用代码来访问数据&#xff0c;并将该代码放置…...

AI 辅助学 Java | 专栏 1 帮你学 Java

在利用 ChatGPT 辅助学 Java 之前,你得先知道,它到底能辅助你干什么?如何能帮你更好的学习 Java。 苍何:作为一个语言模型,你能给 Java 的初学者提供什么帮助?请罗列具体的点。 ChatGPT:当你是一个 Java 初学者时,我可以提供以下具体的帮助和指导: 基本语法和语言特…...

2023_Spark_实验十六:编写LoggerLevel方法及getLocalSparkSession方法

一、搭建Spark项目结构 在SparkProject模块的pom.xml文件中增加一下依赖&#xff0c;并等待依赖包下载完毕&#xff0c;如上图。 ​<!-- Spark及Scala的版本号 --><properties><scala.version>2.11</scala.version><spark.version>2.1.1</sp…...

彻底搞懂:防止表单重复提交,前端限制还是后端限制?

欢迎大家来到小米的技术分享专栏&#xff01;今天我将为大家带来一个热门话题&#xff1a;如何有效地防止表单重复提交。在开发中&#xff0c;我们常常会遇到这样的问题&#xff1a;用户频繁点击提交按钮&#xff0c;导致数据重复提交&#xff0c;给系统和用户体验带来不必要的…...

OCPP1.6协议

目录 导言 功能简介 本地授权列表 类型 IdToken IdTagInfo 授权状态 协议指令 1、授权 1.1 说明 1.2 Authorize.req 1.3 Authorize.conf 1.4 JSON格式 1.5 代码 2、启动通知 2.1 说明 2.2 BootNotification.req 2.3 BootNotification.conf 2.4 JSON格式 2…...

【数据存储:小端模式和大端模式】

一、引言 在计算机科学中&#xff0c;数据存储模式是指如何将数据存储在计算机内存中的方式。小端模式和大端模式是两种主要的字节序方式&#xff0c;它们决定了字节在内存中的排列顺序。这种字节顺序的选择对于跨平台编程和数据传输至关重要。在这篇博客中&#xff0c;我们将…...

【git】gitlab安装、备份

gitlab官网 官网&#xff1a;官网 中文官网&#xff1a;中文官网 作为一个英文不好的程序员&#xff0c;所以我都去中文网站去看了。下面也是带着大家去走走 安装gitlab 我不想写具体的安装方法&#xff0c;直接去逛网看下面是我的截图。步骤非常详细。 安装文档地址&…...

C51--基本认知

单片机基本认知&#xff1a; 1、什么是单片机 单片机是一种集成电路芯片。 把具有数据处理能力的中央处理器 CPU、随机存储器RAM、只读存储器ROM。 多种 I / O 口和中断系统、定时器/计数器等功能&#xff08;可能还包括显示驱动电路、脉宽调制电路、模拟多路转换器、A/D转换器…...

centos7 安装 mysql 8.0

文章目录 环境介绍一、安装前准备 1.卸载MariaDB 1.1 查看是否安装mariadb1.2 卸载1.3 检查是否卸载干净 2.检查依赖 2.1 查看是否安装libaio2.2 查看是否安装numactl 二、安装MySQL 1.下载资源包 1.1 官网下载1.2 wget下载 2.解压3.重命名4.创建存储数据文件5.设置用户组并赋…...

Vue15 计算属性VS监视属性(侦听属性)

计算属性VS监视属性&#xff08;侦听属性&#xff09; computed和watch之间的区别&#xff1a; 1.computed能完成的功能&#xff0c;watch都可以完成。 2.watch能完成的功能&#xff0c;computed不一定能完成&#xff0c;例如&#xff1a;watch可以进行异步操作。 两个重要的小…...

快速全面掌握数据库系统核心知识点

快速全面掌握数据库系统核心知识点 一、数据库系统二、三级模式-两层映射三、三级模式-视图四、数据库设计过程五、E-R模型六、关系代数七、规范化理论八、函数依赖九、规范化理论-键十、规范化理论-求候选键十一、规范化理论-范式十二、规范化理论-第一范式十三、规范化理论-第…...

学习笔记 | 音视频 | 推流项目框架及细节

推流项目: 跑起来项目,再调,创造问题,注意项目跑起来包括哪些步骤 前期准备:环境的配置 依赖库要交叉编译,编译还需注意依赖的库对应的头文件(注意是绝对路径还是相对路径) Rv1126_lib、arm_libx264、arm_libx265、arm_libsrt、arm32_ffmpeg_srt、arm_openssl Ubuntu搭…...

拓扑几何学

目录 一&#xff0c;欧拉定理 1&#xff0c;平面图论图 2&#xff0c;单连通多面体 3&#xff0c;一般多面体 一&#xff0c;欧拉定理 1&#xff0c;平面图论图 在一个联通无向图中&#xff0c;点数-边数面数 1 如&#xff1a; 7-126 1 如果把最外面的五边形外面也算…...

铭豹扩展坞 USB转网口 突然无法识别解决方法

当 USB 转网口扩展坞在一台笔记本上无法识别,但在其他电脑上正常工作时,问题通常出在笔记本自身或其与扩展坞的兼容性上。以下是系统化的定位思路和排查步骤,帮助你快速找到故障原因: 背景: 一个M-pard(铭豹)扩展坞的网卡突然无法识别了,扩展出来的三个USB接口正常。…...

ESP32读取DHT11温湿度数据

芯片&#xff1a;ESP32 环境&#xff1a;Arduino 一、安装DHT11传感器库 红框的库&#xff0c;别安装错了 二、代码 注意&#xff0c;DATA口要连接在D15上 #include "DHT.h" // 包含DHT库#define DHTPIN 15 // 定义DHT11数据引脚连接到ESP32的GPIO15 #define D…...

MySQL账号权限管理指南:安全创建账户与精细授权技巧

在MySQL数据库管理中&#xff0c;合理创建用户账号并分配精确权限是保障数据安全的核心环节。直接使用root账号进行所有操作不仅危险且难以审计操作行为。今天我们来全面解析MySQL账号创建与权限分配的专业方法。 一、为何需要创建独立账号&#xff1f; 最小权限原则&#xf…...

人机融合智能 | “人智交互”跨学科新领域

本文系统地提出基于“以人为中心AI(HCAI)”理念的人-人工智能交互(人智交互)这一跨学科新领域及框架,定义人智交互领域的理念、基本理论和关键问题、方法、开发流程和参与团队等,阐述提出人智交互新领域的意义。然后,提出人智交互研究的三种新范式取向以及它们的意义。最后,总结…...

Netty从入门到进阶(二)

二、Netty入门 1. 概述 1.1 Netty是什么 Netty is an asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers & clients. Netty是一个异步的、基于事件驱动的网络应用框架&#xff0c;用于…...

华为OD最新机试真题-数组组成的最小数字-OD统一考试(B卷)

题目描述 给定一个整型数组,请从该数组中选择3个元素 组成最小数字并输出 (如果数组长度小于3,则选择数组中所有元素来组成最小数字)。 输入描述 行用半角逗号分割的字符串记录的整型数组,0<数组长度<= 100,0<整数的取值范围<= 10000。 输出描述 由3个元素组成…...

深入理解 React 样式方案

React 的样式方案较多,在应用开发初期,开发者需要根据项目业务具体情况选择对应样式方案。React 样式方案主要有: 1. 内联样式 2. module css 3. css in js 4. tailwind css 这些方案中,均有各自的优势和缺点。 1. 方案优劣势 1. 内联样式: 简单直观,适合动态样式和…...

Linux 内存管理调试分析:ftrace、perf、crash 的系统化使用

Linux 内存管理调试分析&#xff1a;ftrace、perf、crash 的系统化使用 Linux 内核内存管理是构成整个内核性能和系统稳定性的基础&#xff0c;但这一子系统结构复杂&#xff0c;常常有设置失败、性能展示不良、OOM 杀进程等问题。要分析这些问题&#xff0c;需要一套工具化、…...

运行vue项目报错 errors and 0 warnings potentially fixable with the `--fix` option.

报错 找到package.json文件 找到这个修改成 "lint": "eslint --fix --ext .js,.vue src" 为elsint有配置结尾换行符&#xff0c;最后运行&#xff1a;npm run lint --fix...

Electron简介(附电子书学习资料)

一、什么是Electron&#xff1f; Electron 是一个由 GitHub 开发的 开源框架&#xff0c;允许开发者使用 Web技术&#xff08;HTML、CSS、JavaScript&#xff09; 构建跨平台的桌面应用程序&#xff08;Windows、macOS、Linux&#xff09;。它将 Chromium浏览器内核 和 Node.j…...