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 内容
//文件名
private string m_fileName;
public string FileName
{
get { return this.m_fileName; }
set { this.m_fileName = value; }
}
//文件路径
private string m_filepath;
public string FilePath
{
get { return this.m_filepath; }
set { this.m_filepath = value; }
}
public MeasureParam m_Config;
#endregion
public ConfigFile(MeasureParam mp)
{
this.m_Config = mp;
}
///
/// 创建XML文件
///
/// 创建XML文件的全路径
/// 0:失败;1:成功;2:文件已存在
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();
sFile.Register("Param", this.m_Config);
//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();
}
}
}
}