| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 | using OTSDataType;using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Xml;using NLog;namespace OTSModelSharp{       //used for export and import the parameter    public class CSampleParamMgr    {             //-------------------全局定义---------        protected static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();            // measurement parameters file mark        public int MRS_PARAM_FILE_MARK = 'M' + 'E' + 'A' + 'S' + 'U' + 'R' + 'E' + 'P' + 'A' + 'R' + 'A' + 'M';        // measurement parameters file version string        public string MRS_PARAM_FILE_VERSION = "1.1.1";        // measurement parameters file        public string MESUREMENT_PARAM_FILE_EXT = (".mrp");        public string MESUREMENT_PARAM_FILE_FILTER = ("Measurement Parmeters Files (*.mrp)|*.mrp||");        //------------------定义----------------        // file pathname        string m_strPathName;        // measurement parameters         CSampleParam m_poMsrParams;                      //----------------public------------------        public CSampleParamMgr()        {            // initialization            Init();        }        public void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)        {            xInt xMrsParamFileMark = new xInt();            xString xMrsOaramFileVersion = new xString();            Slo slo = new Slo();            slo.Register("MrsParamFileMark", xMrsParamFileMark);            slo.Register("MrsParamFileVersion", xMrsOaramFileVersion);            slo.Register("MsrParams", m_poMsrParams);            if (isStoring)            {                xMrsParamFileMark.AssignValue(MRS_PARAM_FILE_MARK);                xMrsOaramFileVersion.AssignValue(MRS_PARAM_FILE_VERSION);                slo.Serialize(true, classDoc, rootNode);            }            else            {                slo.Serialize(false, classDoc, rootNode);                         }        }        //load/Save        public bool Load(string a_strPathName, bool a_bClear)        {                       if (a_bClear)            {                Init();            }            //获取属性配置文件            XmlDocument doc = new XmlDocument();            //载入xml文件            doc.Load(a_strPathName);            XmlNode rootNode = doc.SelectSingleNode("XMLData");            Serialize(false, doc, rootNode);            // file pathname            m_strPathName = a_strPathName;            // ok, return TRUE            return true;        }        public bool Load(bool a_bClear)        {            if (a_bClear)            {                Init();            }            SaveFileDialog folder = new SaveFileDialog();            folder.InitialDirectory = Application.StartupPath + "\\Config\\ProData";                       if (folder.ShowDialog() != DialogResult.OK)            {                return false;            }            //a_strPathName = folder.InitialDirectory;            XmlDocument doc = new XmlDocument();            doc.Load(folder.InitialDirectory);             doc.RemoveAll();            XmlDeclaration xmldecl = doc.CreateXmlDeclaration("1.0", "UTF-8", null);              doc.AppendChild(xmldecl);            XmlElement rootNode = doc.CreateElement("XMLData");                doc.AppendChild(rootNode);                  Serialize(false, doc, rootNode);            try            {                doc.Save(folder.InitialDirectory);            }            catch            {                return false;            }            //doc.LoadXml(folder.InitialDirectory);            //XmlDocument xmlDoc = new XmlDocument();            //xmlDoc.LoadXml(folder.InitialDirectory);            //XmlNode Root = xmlDoc.SelectSingleNode("XMLData");            //Serialize(false, xmlDoc, Root);            // file pathname            m_strPathName = folder.InitialDirectory;            return true;        }        public bool Save(string a_strPathName)        {            //保存测量项目文件 .prj            XmlDocument doc = new XmlDocument();            //添加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);            m_strPathName = a_strPathName;            try            {                doc.Save(a_strPathName);            }            catch            {                return false;            }            m_strPathName = a_strPathName;            return true;        }        public bool Save()        {            SaveFileDialog folder = new SaveFileDialog();            folder.InitialDirectory = Application.StartupPath + "\\Config\\ProData";            if (folder.ShowDialog() != DialogResult.OK)            {                return false;            }            XmlDocument doc = new XmlDocument();            doc.Load(folder.InitialDirectory);            doc.RemoveAll();            XmlDeclaration xmldecl = doc.CreateXmlDeclaration("1.0", "UTF-8", null);            doc.AppendChild(xmldecl);            XmlElement rootNode = doc.CreateElement("XMLData");            doc.AppendChild(rootNode);            Serialize(true, doc, rootNode);            // file pathname            m_strPathName = folder.InitialDirectory;            try            {                doc.Save(folder.InitialDirectory);            }            catch            {                return false;            }            return true;        }        // file pathname        public string GetPathName()        {            return m_strPathName;        }        public void SetPathName(string a_strPathName)        {            m_strPathName = a_strPathName;        }        // measurement parameters file        public CSampleParam GetMsrParams()        {            return m_poMsrParams;        }        public bool SetMsrParamFile(CSampleParam a_poMsrParams)        {            m_poMsrParams = a_poMsrParams;            return true;        }        //--------------protected----------------        // initialization        protected void Init()        {            m_poMsrParams = new CSampleParam();        }        // duplication        public void Duplicate( CSampleParamMgr a_oSource)        {            // initialization            Init();            // copy data over        }    }}
 |