| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
-
- using OTSDataType;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml;
- namespace OTSCommon
- {
- public class CHistoryPrj : ISlo
- {
- private string strfilepath = @".\Config\ProData\HistoryPrj.xml";
- List<string> m_listPrjPath;
- public CHistoryPrj()
- {
- m_listPrjPath = new List<string>();
- }
- public void AddPrjPath(string strPath)
- {
- if (!m_listPrjPath.Contains(strPath))
- {
- m_listPrjPath.Add(strPath);
- }
- else
- {
- int i=m_listPrjPath.IndexOf(strPath);
- m_listPrjPath.RemoveAt(i);
- m_listPrjPath.Add(strPath);
- }
- if (m_listPrjPath.Count > 10)
- {
- m_listPrjPath.RemoveAt(0);
- }
- }
- public List<string> GetPrjPathList()
- {
- List< string> strTemp= new List<string>(m_listPrjPath);
- strTemp.Reverse();
- return strTemp;
- }
- public string GetLatestPrjFolder()
- {
- string strLatestFolder = string.Empty;
- if (m_listPrjPath.Count > 0)
- {
- strLatestFolder = m_listPrjPath[m_listPrjPath.Count - 1];
- int nLastIndex = strLatestFolder.LastIndexOf('\\');
- if (nLastIndex != -1)
- {
- strLatestFolder = strLatestFolder.Substring(0, nLastIndex);
- return strLatestFolder;
- }
- }
- return string.Empty;
- }
- public string GetLatestPrjUpFolder()
- {
- string strLatestPrj = GetLatestPrjFolder();
- string strLatestFolder;
- int nLastIndex = strLatestPrj.LastIndexOf('\\');
- if (nLastIndex != -1)
- {
- strLatestFolder = strLatestPrj.Substring(0, nLastIndex);
- return strLatestFolder;
- }
- return string.Empty;
- }
- public override void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
- {
- if (isStoring)
- {
- foreach (string strPath in m_listPrjPath)
- {
-
-
- rootNode.AppendChild(classDoc.CreateElement("PathName")).InnerText = strPath;
- }
-
-
- }
- else
- {
- m_listPrjPath.Clear();
-
- for (int i = 0; i < rootNode.ChildNodes.Count; i++)
- {
- m_listPrjPath.Add(rootNode.ChildNodes[i].InnerText);
- }
-
- }
- }
- public void loadHistoryPath()
- {
-
- if (File.Exists(strfilepath))
- {
- XmlDocument doc = new XmlDocument();
- //载入xml文件
- doc.Load(strfilepath);
- XmlNode root = doc.SelectSingleNode("XMLData");
- // tried to load it
- Serialize(false, doc, root);
- }
- }
- public void saveHistoryPath()
- {
- XmlDocument doc = new XmlDocument();
- doc.Load(strfilepath);
- doc.RemoveAll();
- //添加xml文件头申明
- XmlDeclaration xmldecl = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
- doc.AppendChild(xmldecl);
- XmlElement rootNode = doc.CreateElement("XMLData");
- doc.AppendChild(rootNode);
- Serialize(true, doc, rootNode);
- try
- {
- doc.Save(strfilepath);
- }
- catch (Exception ex) { }
- }
- }
- }
|