完整使用2
生产厂家里面包含很多规格型号,一个规格型号里面包含很多出厂序列号,点击下一步如果检测到填充的和保存的不一样 就新增一条(如检测到生产厂家相同,但是规格型号不同,就新增一组规格型号)。
界面一:新增界面
界面2 删除界面
界面一:新增界面
load
其中 因为直接使用了 节点名字作为保存,而节点名字是不能出现数字字符开头的,因此统一在各节点之前加“一”,显示的时候再给他去掉
private void DeviceEntering_Load(object sender, EventArgs e)
{
//刷新
intRefresh();
}
public static List<string> changjia = new List<string>();
public static List<string> xinghao = new List<string>();
public static List<string> xvlie = new List<string>();
public static List<string> testname = new List<string>();
public static List<string> reportname = new List<string>();
static string path = Directory.GetCurrentDirectory() + "\\Config\\测试参数.xml";
public static string pathxml = @"C:\SEET\test.xml";
public static string pathname = @"C:\SEET\testName.xml";
public static string pathreport = @"C:\SEET\testReport.xml";
public static string pathmulu = @"C:\SEET\";
public static void intRefresh ()
{
//该方法是判断该路径下有没有该文件夹,注意并不能判断某个文件是否存在
if (!Directory.Exists(pathmulu))
{
DirectoryInfo directoryInfo = new DirectoryInfo(pathmulu);
directoryInfo.Create();
}
//该方法是判断该路径下有没有该文件,注意一定要加上文件后缀名
if (!File.Exists(pathxml))
{
CreateXml();
}
if (!File.Exists(pathname))
{
XmlDocument Doc = new XmlDocument();
XmlDeclaration xnode = Doc.CreateXmlDeclaration("1.0", "UTF-8", "");
Doc.AppendChild(xnode);
XmlElement root = Doc.CreateElement("测试人员");
Doc.AppendChild(root);
XmlElement TestName = Doc.CreateElement("一测试员");
root.AppendChild(TestName);
TestName.InnerText = "张三";
Doc.Save(pathname);
}
if (!File.Exists(pathreport))
{
XmlDocument Docc = new XmlDocument();
XmlDeclaration xnode = Docc.CreateXmlDeclaration("1.0", "UTF-8", "");
Docc.AppendChild(xnode);
XmlElement root = Docc.CreateElement("报告保存");
Docc.AppendChild(root);
XmlElement TestName = Docc.CreateElement("气腹机测试报告模板-001.docx");
root.AppendChild(TestName);
TestName.InnerText = "张三";
Docc.Save(pathreport);
}
//实例化一个xml操作对象
XmlDocument xDoc = new XmlDocument();
xDoc.Load(pathxml);
XmlNode rNode = xDoc.SelectSingleNode("气腹机");//.SelectSingleNode:取到第一个和表达式匹配的节点
XmlNodeList rlist = rNode.ChildNodes; //获取节点的所有子节点
// //取根结点
// var root = xmlDoc.DocumentElement;//取到根结点
取指定的单个结点
//XmlNode oldChild = xmlDoc.SelectSingleNode("BookStore/NewBook");
取指定的结点的集合
//XmlNodeList nodes = xmlDoc.SelectNodes("BookStore/NewBook");
int i = 0, j = 0, k = 0;
changjia.Clear();
xinghao.Clear();
xvlie.Clear();
foreach (XmlNode r in rlist)
{
string name = r.Name;//获取节点的限定名称
name = name.Substring(1, name.Length - 1);
//changjia.Add(name);
changjia.Add(name);
log.SaveLog("节点:" + name.Substring(1, name.Length - 1));
i++;
XmlNodeList list2 = r.ChildNodes;
foreach (XmlNode item in list2)
{
string name2 = item.Name;
name2 = name2.Substring(1, name2.Length - 1);
if (name2.Equals("text"))
{
continue;
}
j++;
xinghao.Add(name + "*" + name2 + "*");
log.SaveLog("节点2:" + name2);
XmlNodeList list3 = item.ChildNodes;
foreach (XmlNode item2 in list3)
{
k++;
string name3 = item2.Name;
name3 = name3.Substring(1, name3.Length - 1);
if (name3.Equals("text"))
{
continue;
}
xvlie.Add(name + "*" + name2 + "*" + name3);
//uiComboBox3.Items.Add(name3);
log.SaveLog("节点3:" + name3