'XML添加
Public Sub Add(ID As String, RFSerialnumber As String, Mood As Integer)
If reatch(RFSerialnumber) = 1 Then
Return
End If
Dim xmlDoc As New XmlDocument()
path = System.IO.Path.GetFullPath("../../Mood.xml")
xmlDoc.Load(path)
Dim root As XmlNode = xmlDoc.SelectSingleNode("RECard") '查找
Dim xe1 As XmlElement = xmlDoc.CreateElement("RFID") '创建一个
xe1.SetAttribute("Type", "IC卡") '设置该节点genre属性
'xe1.SetAttribute("ID", ) '设置该节点ISBN属性
Dim xesub1 As XmlElement = xmlDoc.CreateElement("ID")
xesub1.InnerText = ID '设置文本节点
xe1.AppendChild(xesub1) '添加到
Dim xesub2 As XmlElement = xmlDoc.CreateElement("RFSerialnumber")
xesub2.InnerText = RFSerialnumber
xe1.AppendChild(xesub2)
Dim xesub3 As XmlElement = xmlDoc.CreateElement("Mood")
xesub3.InnerText = Mood
xe1.AppendChild(xesub3)
root.AppendChild(xe1) '添加到
xmlDoc.Save(path)
End Sub
Public Function Read(RFSerialnumber As String) As Int32
path = System.IO.Path.GetFullPath("../../Mood.xml")
Dim xmlDoc As New XmlDocument()
xmlDoc.Load(path)
Dim xn As XmlNode
xn = xmlDoc.SelectSingleNode("RECard")
Dim xnl As XmlNodeList
xnl = xn.ChildNodes
Dim xnc As XmlNode
xnc = xn.SelectSingleNode("RFID")
Dim moodid As Integer
moodid = 0
For index = 0 To xnl.Count - 1
If xnl(index).Item("RFSerialnumber").InnerText = RFSerialnumber Then
moodid = Convert.ToInt32(xnl(index).Item("Mood").InnerText)
End If
Next
Return moodid
End Function
'''
''' 查询
'''
'''
'''
Public Function reatch(RFSerialnumber As String) As Int32
Dim xmlDoc As New XmlDocument()
path = System.IO.Path.GetFullPath("../../Mood.xml")
xmlDoc.Load(path)
Dim xn As XmlNode
xn = xmlDoc.SelectSingleNode("RECard")
Dim xnl As XmlNodeList
xnl = xn.ChildNodes
Dim xnc As XmlNode
xnc = xn.SelectSingleNode("RFID")
Dim num As Integer
num = 0
For index = 0 To xnl.Count - 1
If xnl(index).Item("RFSerialnumber").InnerText = RFSerialnumber Then
num = 1
End If
Next
Return num
End Function
Private Sub AddPressure_visualizationxml(Pressure_visualization As Pressure_visualization)
Dim path As String
Dim xmlDoc As New XmlDocument()
path = System.IO.Path.GetFullPath("../../../Pressure_visualization.xml")
xmlDoc.Load(path)
Dim root As XmlNode = xmlDoc.SelectSingleNode("Pressure_visualizationConfig") '查找
Dim xe1 As XmlElement = xmlDoc.CreateElement("Pressure_visualization") '创建一个
xe1.SetAttribute("Type", "IC卡") '设置该节点genre属性
'xe1.SetAttribute("ID", ) '设置该节点ISBN属性
Dim xesub1 As XmlElement = xmlDoc.CreateElement("t_Device_address")
Dim xesub2 As XmlElement = xmlDoc.CreateElement("t_Equipment_number")
Dim xesub3 As XmlElement = xmlDoc.CreateElement("t_Equipment_state")
Dim xesub4 As XmlElement = xmlDoc.CreateElement("t_Packing_pressure")
Dim xesub5 As XmlElement = xmlDoc.CreateElement("t_Pressure_holding_time")
Dim xesub6 As XmlElement = xmlDoc.CreateElement("t_Upper_limit_pressure")
Dim xesub7 As XmlElement = xmlDoc.CreateElement("t_Lower_limit_pressure")
Dim xesub8 As XmlElement = xmlDoc.CreateElement("t_Upper_limit_holding_time")
Dim xesub9 As XmlElement = xmlDoc.CreateElement("t_Holding_time_lower_limit")
xesub1.InnerText = Pressure_visualization.t_Device_address
xesub2.InnerText = Pressure_visualization.t_Equipment_number
xesub3.InnerText = Pressure_visualization.t_Equipment_state
xesub4.InnerText = Pressure_visualization.t_Packing_pressure
xesub5.InnerText = Pressure_visualization.t_Pressure_holding_time
xesub6.InnerText = Pressure_visualization.t_Upper_limit_pressure
xesub7.InnerText = Pressure_visualization.t_Lower_limit_pressure
xesub8.InnerText = Pressure_visualization.t_Upper_limit_holding_time
xesub9.InnerText = Pressure_visualization.t_Holding_time_lower_limit
xe1.AppendChild(xesub1)
xe1.AppendChild(xesub2)
xe1.AppendChild(xesub3)
xe1.AppendChild(xesub4)
xe1.AppendChild(xesub5)
xe1.AppendChild(xesub6)
xe1.AppendChild(xesub7)
xe1.AppendChild(xesub8)
xe1.AppendChild(xesub9)
root.AppendChild(xe1) '添加到
xmlDoc.Save(path)
End Sub
''更新更新
Private Sub Pressure_visualizationUPdata(Pressure_visualization As Pressure_visualization)
Dim path As String
Dim xmlDoc As New XmlDocument()
path = System.IO.Path.GetFullPath("../../../Pressure_visualization.xml")
xmlDoc.Load(path)
Dim root As XmlNode = xmlDoc.SelectSingleNode("Pressure_visualizationConfig") '查找
Dim t_Device_address As XmlNode = root.ChildNodes(0).SelectSingleNode("t_Device_address") '查找t_Device_address
Dim t_Equipment_number As XmlNode = root.ChildNodes(0).SelectSingleNode("t_Equipment_number") '查找t_Equipment_number
Dim t_Equipment_state As XmlNode = root.ChildNodes(0).SelectSingleNode("t_Equipment_state") '查找t_Equipment_state
Dim t_Packing_pressure As XmlNode = root.ChildNodes(0).SelectSingleNode("t_Packing_pressure") '查找t_Packing_pressure
Dim t_Pressure_holding_time As XmlNode = root.ChildNodes(0).SelectSingleNode("t_Pressure_holding_time") '查找t_Pressure_holding_time
Dim t_Upper_limit_pressure As XmlNode = root.ChildNodes(0).SelectSingleNode("t_Upper_limit_pressure") '查找t_Upper_limit_pressure
Dim t_Lower_limit_pressure As XmlNode = root.ChildNodes(0).SelectSingleNode("t_Lower_limit_pressure") '查找t_Lower_limit_pressure
Dim t_Upper_limit_holding_time As XmlNode = root.ChildNodes(0).SelectSingleNode("t_Upper_limit_holding_time") '查找t_Upper_limit_holding_time
Dim t_Holding_time_lower_limit As XmlNode = root.ChildNodes(0).SelectSingleNode("t_Holding_time_lower_limit") '查找t_Holding_time_lower_limit
t_Device_address.InnerText = Pressure_visualization.t_Device_address
t_Equipment_number.InnerText = Pressure_visualization.t_Equipment_number
t_Equipment_state.InnerText = Pressure_visualization.t_Equipment_state
t_Packing_pressure.InnerText = Pressure_visualization.t_Packing_pressure
t_Pressure_holding_time.InnerText = Pressure_visualization.t_Pressure_holding_time
t_Upper_limit_pressure.InnerText = Pressure_visualization.t_Upper_limit_pressure
t_Lower_limit_pressure.InnerText = Pressure_visualization.t_Lower_limit_pressure
t_Upper_limit_holding_time.InnerText = Pressure_visualization.t_Upper_limit_holding_time
t_Holding_time_lower_limit.InnerText = Pressure_visualization.t_Holding_time_lower_limit
xmlDoc.Save(path)
End Sub
Private Function Pressure_visualizationRead(Pressure_visualization As Pressure_visualization) As Pressure_visualization
Dim path As String
Dim xmlDoc As New XmlDocument()
path = System.IO.Path.GetFullPath("../../../Pressure_visualization.xml")
xmlDoc.Load(path)
Dim root As XmlNode = xmlDoc.SelectSingleNode("Pressure_visualizationConfig") '查找
Dim t_Device_address As XmlNode = root.ChildNodes(0).SelectSingleNode("t_Device_address") '查找t_Device_address
Dim t_Equipment_number As XmlNode = root.ChildNodes(0).SelectSingleNode("t_Equipment_number") '查找t_Equipment_number
Dim t_Equipment_state As XmlNode = root.ChildNodes(0).SelectSingleNode("t_Equipment_state") '查找t_Equipment_state
Dim t_Packing_pressure As XmlNode = root.ChildNodes(0).SelectSingleNode("t_Packing_pressure") '查找t_Packing_pressure
Dim t_Pressure_holding_time As XmlNode = root.ChildNodes(0).SelectSingleNode("t_Pressure_holding_time") '查找t_Pressure_holding_time
Dim t_Upper_limit_pressure As XmlNode = root.ChildNodes(0).SelectSingleNode("t_Upper_limit_pressure") '查找t_Upper_limit_pressure
Dim t_Lower_limit_pressure As XmlNode = root.ChildNodes(0).SelectSingleNode("t_Lower_limit_pressure") '查找t_Lower_limit_pressure
Dim t_Upper_limit_holding_time As XmlNode = root.ChildNodes(0).SelectSingleNode("t_Upper_limit_holding_time") '查找t_Upper_limit_holding_time
Dim t_Holding_time_lower_limit As XmlNode = root.ChildNodes(0).SelectSingleNode("t_Holding_time_lower_limit") '查找t_Holding_time_lower_limit
Pressure_visualization.t_Device_address = t_Device_address.InnerText
Pressure_visualization.t_Equipment_number = t_Equipment_number.InnerText
Pressure_visualization.t_Equipment_state = t_Equipment_state.InnerText
Pressure_visualization.t_Packing_pressure = t_Packing_pressure.InnerText
Pressure_visualization.t_Pressure_holding_time = t_Pressure_holding_time.InnerText
Pressure_visualization.t_Upper_limit_pressure = t_Upper_limit_pressure.InnerText
Pressure_visualization.t_Lower_limit_pressure = t_Lower_limit_pressure.InnerText
Pressure_visualization.t_Upper_limit_holding_time = t_Upper_limit_holding_time.InnerText
Pressure_visualization.t_Holding_time_lower_limit = t_Holding_time_lower_limit.InnerText
Return Pressure_visualization
End Function
--C#C#C#C#C#C#C#C#C#C#C#C#C#C#C#C#C#C#--C#C#C#C#C#C#---C#C#C#C#C#C#-----------------------------------------
///
/// 创建xml文件
///
public void CreateXmlFile()
{
XDocument xdoc = new XDocument();
//创建根节点
XElement root = new XElement("TimeConfig");
xdoc.Add(root); //添加根节点到XDoucment对象
xdoc.Save(XmlPath); //使用XML的保存会自动在xml文件开始添加:
}
FileInfo fi = new FileInfo(XmlPath);
if (fi.Length <57 )
{
CreateXmlFile();
}
public int reatch(int ID) {
XmlDocument xmlDoc = new XmlDocument();
string path;
path = System.IO.Path.GetFullPath("../../../LightTime.xml");
xmlDoc.Load(path);
XmlNode xn;
xn = xmlDoc.SelectSingleNode("TimeConfig");
XmlNodeList xnl = xn.ChildNodes;
XmlNode xnc;
xnc = xn.SelectSingleNode("TimeCon");
int num;
num = 0;
for (int i = 0; i < xn.ChildNodes.Count - 1; i++)
{
if (xnl[i].ChildNodes[0].InnerText ==""+ID)
{
num = 1;
}
}
return num;
}
///
/// 把ID对应的时间添加到xml文件中
///
///
///
public void addxml(int ID,DateTime time) {
string path;
XmlDocument xmlDoc = new XmlDocument();
path = System.IO.Path.GetFullPath("../../../LightTime.xml");
xmlDoc.Load(path);
XmlNode root;
root = xmlDoc.SelectSingleNode("TimeConfig"); /*'查找
XmlElement xe1;
xe1 = xmlDoc.CreateElement("TimeCon"); /*'创建一个
xe1.SetAttribute("Type", "DateTime");/*'设置该节点genre属性 */
XmlElement xesub1;
xesub1 = xmlDoc.CreateElement("ID");
xesub1.InnerText = ID.ToString(); /*'设置文本节点 */
xe1.AppendChild(xesub1); /*'添加到
XmlElement xesub2;
xesub2 = xmlDoc.CreateElement("LastTime");
xesub2.InnerText = time.ToString();
xe1.AppendChild(xesub2);
root.AppendChild(xe1); /*'添加到
xmlDoc.Save(path);
}
read
public string GetReadID( ) {
string path;
path = System.IO.Path.GetFullPath("../../../LightTime.xml");
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load(path);
XmlNode xn;
xn = xmlDoc.SelectSingleNode("TimeConfig");
XmlNodeList xnl= xn.ChildNodes;
XmlNode xnc = xn.SelectSingleNode("TimeCon");
string ids="";
for (int i = 0; i < xn.ChildNodes.Count-1; i++)
{
if (Convert.ToDateTime(xn.ChildNodes[i].ChildNodes[1].InnerText) <= DateTime.Now)
{
ids+= xn.ChildNodes[i].ChildNodes[0].InnerText+"-";
}
}
return ids;
}
xml 文件
手机扫一扫
移动阅读更方便
你可能感兴趣的文章