123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml;
- using System.IO;
- using FileManager;
- namespace MeasureData
- {
- public class ConfigFile : ISlo
- {
- #region 内容
- public MeasureParam m_Config;
- #endregion
- public ConfigFile(MeasureParam mp)
- {
- this.m_Config = mp;
- }
- /// <summary>
- /// 创建XML文件
- /// </summary>
- /// <param name="filename">创建XML文件的全路径</param>
- /// <returns>0:失败;1:成功;2:文件已存在</returns>
- public int CreateXml(String filename)
- {
- if (!File.Exists(filename))
- {
- if (XmlManager.CreateXmlFile(filename))
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- else
- {
- XmlManager.CreateXmlFile(filename);
- return 2;
- }
- }
- //保存
- public bool Save(String filename)
- {
- CreateXml(filename);
- XmlDocument doc = new XmlDocument();
- if (File.Exists(filename))
- {
- doc.Load(filename);//载入xml文件
- }
- else
- {
- return false; //当前路径不存在
- }
- XmlNode root = doc.SelectSingleNode("XMLData");
- Serialize(true, doc, root);
- doc.Save(filename);
- return true;
- }
- //读取
- public bool Read(String filename)
- {
- XmlDocument doc = new XmlDocument();
- if (File.Exists(filename))
- {
- doc.Load(filename);//载入xml文件
- }
- else
- {
- return false; //当前路径不存在
- }
- XmlNode root = doc.SelectSingleNode("XMLData");
- Serialize(false, doc, root);
- //doc.Save(filename);
- return true;
- }
- //XML文件保存
- //样品孔存储xml文档
- public override void Serialize(bool isStoring, XmlDocument xml, XmlNode rootNode)
- {
- Slo sFile = new Slo();
- xBool isPhotograph = new xBool();
- xBool ptDepostion = new xBool();
- isPhotograph.AssignValue(m_Config.Is_Photograph);
- ptDepostion.AssignValue(m_Config.PT);
- sFile.Register("Is_Photograph", isPhotograph);
- sFile.Register("PT_Depostion", ptDepostion);
- xString ptELYFile = new xString();
- xString fibELYFile = new xString();
- ptELYFile.AssignValue(m_Config.PTTemp);
- fibELYFile.AssignValue(m_Config.FIBTemp);
- sFile.Register("PT_ELYFile", ptELYFile);
- sFile.Register("FIB_ELYFile", fibELYFile);
- xDouble stretchMagnification = new xDouble();
- xDouble locationMagnification = new xDouble();
- xDouble locationVoltage = new xDouble();
- xDouble photographMagnification = new xDouble();
- xDouble photographVoltage = new xDouble();
- stretchMagnification.AssignValue(m_Config.Stretch_Magnification);
- locationMagnification.AssignValue(m_Config.Location_Magnification);
- locationVoltage.AssignValue(m_Config.Location_Voltage);
- photographMagnification.AssignValue(m_Config.Photograph_Magnification);
- photographVoltage.AssignValue(m_Config.Photograph_Voltage);
- sFile.Register("Strectch_Magnification", stretchMagnification);
- sFile.Register("Locatio_Magnification", locationMagnification);
- sFile.Register("Location_Voltage", locationVoltage);
- sFile.Register("Photograph_Magnification", photographMagnification);
- sFile.Register("Photograph_Voltage", photographVoltage);
- xDouble correctionAngle = new xDouble();
- correctionAngle.AssignValue(m_Config.Correction_Angle);
- sFile.Register("Correction_Angle", correctionAngle);
- xString sampleType = new xString();
- xString _firm = new xString();
- sampleType.AssignValue(m_Config.SampleName);
- _firm.AssignValue(m_Config.Firm);
- sFile.Register("Sample_Type", sampleType);
- sFile.Register("Firm", _firm);
- if (isStoring)
- {
- sFile.Serialize(true, xml, rootNode);
- }
- else
- {
- sFile.Serialize(false, xml, rootNode);
- m_Config.Is_Photograph = isPhotograph.value();
- m_Config.PT = ptDepostion.value();
- m_Config.PTTemp = ptELYFile.value();
- m_Config.FIBTemp = fibELYFile.value();
- m_Config.Stretch_Magnification = stretchMagnification.value();
- m_Config.Location_Magnification = locationMagnification.value();
- m_Config.Location_Voltage = locationVoltage.value();
- m_Config.Photograph_Magnification = photographMagnification.value();
- m_Config.Photograph_Voltage = photographVoltage.value();
- m_Config.Correction_Angle = correctionAngle.value();
- m_Config.SampleName = sampleType.value();
- m_Config.Firm = _firm.value();
- }
- }
- }
- }
|