using System;
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Xml;
|
|
namespace IStation.Common
|
{
|
public class TotalWaterOutHelper
|
{
|
//读取
|
public static double Read(DateTime day)
|
{
|
string filePath = System.IO.Path.Combine(IStation.DataFolderHelper.GetRootPath(),
|
"TotalWaterOut", day.Year.ToString(), day.Month.ToString()+".xml");
|
if (!File.Exists(filePath))
|
{
|
return -1;
|
}
|
|
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
|
xmlDoc.Load(filePath);
|
System.Xml.XmlElement rootNode = xmlDoc.DocumentElement;//根节点
|
if (rootNode == null)
|
return -1;
|
|
XmlNode nodeInfo = rootNode.SelectSingleNode(string.Format("Day{0}", day.Day));
|
if (nodeInfo == null)
|
{
|
return -1;
|
}
|
|
return Convert.ToDouble(nodeInfo.InnerText);
|
}
|
|
//保存
|
public static bool Save(DateTime day ,double sum)
|
{
|
var root_folder = System.IO.Path.Combine(IStation.DataFolderHelper.GetRootPath(), "TotalWaterOut");
|
if (!System.IO.Directory.Exists(root_folder))
|
{
|
System.IO.Directory.CreateDirectory(root_folder);
|
}
|
var year_folder = System.IO.Path.Combine(root_folder, day.Year.ToString());
|
if (!System.IO.Directory.Exists(year_folder))
|
{
|
System.IO.Directory.CreateDirectory(year_folder);
|
}
|
|
|
string filePath = System.IO.Path.Combine(year_folder, day.Month.ToString() + ".xml");
|
if (!File.Exists(filePath))
|
{
|
XmlDocument xmlDoc1 = new XmlDocument();
|
|
xmlDoc1.AppendChild(xmlDoc1.CreateXmlDeclaration("1.0", "UTF-8", null));
|
|
XmlNode rootNode1 = xmlDoc1.CreateElement("root");
|
xmlDoc1.AppendChild(rootNode1);
|
|
xmlDoc1.Save(filePath);
|
}
|
|
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
|
xmlDoc.Load(filePath);
|
|
System.Xml.XmlElement rootNode = xmlDoc.DocumentElement;//根节点
|
if (rootNode == null)
|
return false;
|
|
XmlNode nodeInfo = rootNode.SelectSingleNode(string.Format("Day{0}", day.Day));
|
|
if (nodeInfo == null)
|
{
|
XmlNode VersionInfoNode = xmlDoc.CreateElement(string.Format("Day{0}", day.Day));
|
|
VersionInfoNode.InnerText = sum.ToString();
|
rootNode.AppendChild(VersionInfoNode);
|
}
|
else
|
{
|
nodeInfo.InnerText = sum.ToString();
|
}
|
|
xmlDoc.Save(filePath);
|
|
return true;
|
}
|
|
}
|
}
|