public static void WriteXml(GameInfo info,GameObject PanelRunRecord)
{
DateTime now = DateTime.Now;
string dataPath = Application.dataPath;
string url = dataPath + "/XML/DetailList.xml";
if (!File.Exists(@url))
{
File.Create(@url);
XmlDocument xmlDoc = new XmlDocument();
XmlDeclaration Declaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
XmlNode rootNode = xmlDoc.createElement_x("detaillist");
}
XmlDocument doc = new XmlDocument();
doc.Load(url);
XmlElement rootElem = doc.DocumentElement;
XElement temp = XElement.Load(url);
XmlNodeList personNodes = rootElem.ChildNodes;
if (personNodes.Count > 0)
{
bool isExitYear = false;
bool isExitMonth = false;
bool isExitDay = false;
foreach (XmlNode node in personNodes)
{
string year = ((XmlElement)node).getElementsByTagName_r("year")[0].InnerText.ToString().Trim();
string month = ((XmlElement)node).getElementsByTagName_r("month")[0].InnerText.ToString().Trim();
if (now.Year == int.Parse(year))
{
isExitYear = true;
}
if (now.Year == int.Parse(year) && now.Month == int.Parse(month))
{
isExitMonth = true;
}
if (((XmlElement)node).getElementsByTagName_r("mlist")!=null)
{
XmlNodeList mlist = ((XmlElement)node).getElementsByTagName_r("mlist")[0].ChildNodes;
if (mlist.Count>0)
{
foreach (XmlNode k in ((XmlElement)node).getElementsByTagName_r("mlist"))
{
int date = int.Parse(k.Attributes.GetNamedItem("date").Value);
if (now.Year==int.Parse(year)&&now.Month==int.Parse(month)&&now.Day==date)
{
isExitDay = true;
}
}
}
}
}
//从月写入
if (isExitYear&&!isExitMonth&&!isExitDay)
{
writerItem_year(doc, personNodes ,now,url, info);
}
//从天写入
if (isExitYear&&isExitMonth&&!isExitDay)
{
writerItem_month(doc, personNodes, now, url, info);
}
//从天写入
if (isExitYear && isExitMonth && isExitDay)
{
writerItem_day(doc, personNodes, now, url, info);
}
if (!isExitYear && !isExitMonth && !isExitDay)
{
writerItem_0(doc, now, url, info);
}
}
else
{
writerItem_0(doc, now, url,info);
}
//刷新记录
//GameInfo.gdatalist.Clear();
string XML = Application.dataPath + "/XML/";
InitializeVRPlatform.InitializeGameRunInfo(XML);
PanelRunRecord.GetComponent().RecordInitialize();
}
#region[直接写入]
///
/// Debug.Log("直接写入");
///
///
///
///
static void writerItem_0(XmlDocument doc, DateTime now, string url,GameInfo info)
{
ISFSObject o = new SFSObject();
XmlNode root = doc.SelectSingleNode("detaillist");
XmlNode rootNode = doc.createElement_x("detail");
root.AppendChild(rootNode);
XmlElement id = doc.createElement_x("id");
id.InnerText = now.TimeOfDay.ToString();
XmlElement Year = doc.createElement_x("year");
Year.InnerText = now.Year.ToString();
XmlElement month = doc.createElement_x("month");
month.InnerText = now.Month.ToString();
rootNode.AppendChild(id);
rootNode.AppendChild(Year);
rootNode.AppendChild(month);
XmlNode mlist = doc.createElement_x("mlist");
XmlAttribute date = doc.CreateAttribute("date");
date.Value = now.Day.ToString();
mlist.Attributes.Append(date);
rootNode.AppendChild(mlist);
XmlNode dlist = doc.createElement_x("dlist");
XmlAttribute gname = doc.CreateAttribute("gname");
gname.Value =info.GetGname() ;
dlist.Attributes.Append(gname);
XmlAttribute startdate = doc.CreateAttribute("startdate");
startdate.Value = GameInfo.startdate;
dlist.Attributes.Append(startdate);
XmlAttribute enddate = doc.CreateAttribute("enddate");
enddate.Value = GameInfo.enddate;
dlist.Attributes.Append(enddate);
XmlAttribute needtime = doc.CreateAttribute("needtime");
needtime.Value = "VR";
dlist.Attributes.Append(needtime);
mlist.AppendChild(dlist);
doc.Save(url);
}
#endregion
#region[从年写入] 月
static void writerItem_year(XmlDocument doc,XmlNodeList personNodes, DateTime now,string url, GameInfo info)
{
bool flag = false;
foreach (XmlNode node in personNodes)
{
string year = ((XmlElement)node).getElementsByTagName_r("year")[0].InnerText.ToString().Trim();
string month = ((XmlElement)node).getElementsByTagName_r("month")[0].InnerText.ToString().Trim();
if (now.Year == int.Parse(year) && now.Month!=int.Parse(month))
{
flag = true;
}
}
if (flag)
{
writerItem_0(doc,now,url,info);
}
doc.Save(url);
}
#endregion
#region[从月写入] 天
static void writerItem_month(XmlDocument doc, XmlNodeList personNodes, DateTime now, string url, GameInfo info)
{
foreach (XmlNode node in personNodes)
{
string year = ((XmlElement)node).getElementsByTagName_r("year")[0].InnerText.ToString().Trim();
string month = ((XmlElement)node).getElementsByTagName_r("month")[0].InnerText.ToString().Trim();
if (now.Year == int.Parse(year) && now.Month == int.Parse(month))
{
XmlElement mlist = doc.createElement_x("mlist");
XmlAttribute date = doc.CreateAttribute("date");
date.Value = now.Day.ToString();
mlist.Attributes.Append(date);
node.AppendChild(mlist);
XmlNode dlist = doc.createElement_x("dlist");
XmlAttribute gname = doc.CreateAttribute("gname");
gname.Value = info.GetGname();
dlist.Attributes.Append(gname);
XmlAttribute startdate = doc.CreateAttribute("startdate");
startdate.Value = GameInfo.startdate;
dlist.Attributes.Append(startdate);
XmlAttribute enddate = doc.CreateAttribute("enddate");
enddate.Value = GameInfo.enddate;
dlist.Attributes.Append(enddate);
XmlAttribute needtime = doc.CreateAttribute("needtime");
needtime.Value = "VR";
dlist.Attributes.Append(needtime);
mlist.AppendChild(dlist);
doc.Save(url);
}
}
}
#endregion
#region[从时间段写入]时间段
static void writerItem_day(XmlDocument doc, XmlNodeList personNodes, DateTime now, string url, GameInfo info)
{
//查找
foreach (XmlNode node in personNodes)
{
string year = ((XmlElement)node).getElementsByTagName_r("year")[0].InnerText.ToString().Trim();
string month = ((XmlElement)node).getElementsByTagName_r("month")[0].InnerText.ToString().Trim();
if (((XmlElement)node).getElementsByTagName_r("mlist") != null)
{
XmlNodeList mlist = ((XmlElement)node).getElementsByTagName_r("mlist")[0].ChildNodes;
if (mlist.Count > 0)
{
foreach (XmlNode k in ((XmlElement)node).getElementsByTagName_r("mlist"))
{
int date = int.Parse(k.Attributes.GetNamedItem("date").Value);
if (now.Year == int.Parse(year) && now.Month == int.Parse(month) && now.Day == date)
{
XmlNode dlist = doc.createElement_x("dlist");
XmlAttribute gname = doc.CreateAttribute("gname");
gname.Value = info.GetGname();
dlist.Attributes.Append(gname);
XmlAttribute startdate = doc.CreateAttribute("startdate");
startdate.Value = GameInfo.startdate;
dlist.Attributes.Append(startdate);
XmlAttribute enddate = doc.CreateAttribute("enddate");
enddate.Value = GameInfo.enddate;
dlist.Attributes.Append(enddate);
XmlAttribute needtime = doc.CreateAttribute("needtime");
needtime.Value = "VR";
dlist.Attributes.Append(needtime);
k.AppendChild(dlist);
doc.Save(url);
}
}
}
}
}
}
#endregion