/// <summary> /// 添加券别信息到配置文件中。 /// </summary> /// <param name="path"></param> /// <param name="cashType"></param> private void AddXML(string path, string cashType, string cashVersion) { //获取券别包装信息 CashInfo cashInfo = new CashInfo(); if (!GetCashInfo(Util.cashInfoPath, cashType, cashInfo)) { Util.pause = true; MessageBox.Show("没找到‘" + cashType + "’券别包装信息,请核对券别包装,手动添加信息。"); Util.newCash = cashType; Form2 fm2 = new Form2(); fm2.ShowDialog(); return; } //加载文件,选出节点 XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(path); XmlNode xn = xmlDoc.SelectSingleNode("cashlist"); //创建节点 XmlElement xelKey = xmlDoc.CreateElement("cash"); //创建子节点 XmlElement xelType = xmlDoc.CreateElement("type"); xelType.InnerText = cashType; XmlElement xelLabel = xmlDoc.CreateElement("label"); xelLabel.InnerText = cashType; XmlElement xelVersion = xmlDoc.CreateElement("version"); xelVersion.InnerText = cashVersion; XmlElement xelBox = xmlDoc.CreateElement("box"); xelBox.InnerText = cashInfo.Box; XmlElement xelBundle = xmlDoc.CreateElement("bundle"); xelBundle.InnerText = cashInfo.Bundle; XmlElement xelBag = xmlDoc.CreateElement("bag"); xelBag.InnerText = cashInfo.Bag; xelKey.AppendChild(xelType); xelKey.AppendChild(xelLabel); xelKey.AppendChild(xelVersion); xelKey.AppendChild(xelBox); xelKey.AppendChild(xelBundle); xelKey.AppendChild(xelBag); //添加入文件 xn.AppendChild(xelKey); xmlDoc.Save(path); }
/// <summary> /// 查找泛用券别信息,导入箱捆包数据 /// </summary> /// <param name="path"></param> /// <param name="cashType"></param> /// <param name="cashInfo"></param> private bool GetCashInfo(string path, string cashType, CashInfo cashInfo) { if (-1 != cashType.IndexOf("币")) { if (-1 != cashType.IndexOf("10元")) { cashType = "硬10元"; } if (-1 != cashType.IndexOf("5元")) { cashType = "硬5元"; } if (-1 != cashType.IndexOf("1元")) { cashType = "硬1元"; } } if (-1 != cashType.IndexOf("钞")) { if (-1 != cashType.IndexOf("100元")) { cashType = "纸100元"; } if (-1 != cashType.IndexOf("50元")) { cashType = "纸50元"; } if (-1 != cashType.IndexOf("20元")) { cashType = "纸20元"; } if (-1 != cashType.IndexOf("10元")) { cashType = "纸10元"; } if (-1 != cashType.IndexOf("5元")) { cashType = "纸5元"; } if (-1 != cashType.IndexOf("2元")) { cashType = "纸2元"; } if (-1 != cashType.IndexOf("1元")) { cashType = "纸1元"; } } XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreComments = true;//忽略文档里面的注释 XmlReader reader = XmlReader.Create(path, settings); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(reader); XmlNode xn = xmlDoc.SelectSingleNode("cashlist"); XmlNodeList xnl = xn.ChildNodes; foreach (XmlNode xn1 in xnl) { XmlElement xe = (XmlElement)xn1;// 将节点转换为元素,便于得到节点的属性值 XmlNodeList xnl0 = xe.ChildNodes; if (-1 != cashType.IndexOf(xnl0.Item(0).InnerText)) { cashInfo.Type = xnl0.Item(0).InnerText; cashInfo.Box = xnl0.Item(1).InnerText; cashInfo.Bundle = xnl0.Item(2).InnerText; cashInfo.Bag = xnl0.Item(3).InnerText; reader.Close(); return(true); } } reader.Close(); return(false); }