| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 | 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 Boolean is_Photograph;        public Boolean Is_Photograph        {            get { return this.is_Photograph; }            set { this.is_Photograph = value; }        }        //是否PT沉积        private Boolean pt_Depostion;        public Boolean PT_Depostion        {            get { return this.pt_Depostion; }            set { this.pt_Depostion = value; }        }        //PT使用的ELY文件        private String pt_ELYFile;        public String PT_ELYFile        {            get { return this.pt_ELYFile; }            set { this.pt_ELYFile = value; }        }        //FIB使用的ELY文件        private String fib_ELYFile;        public String FIB_ELYFile        {            get { return this.fib_ELYFile; }            set { this.fib_ELYFile = value; }        }        //拉直操作需要的放大位数        private double stretch_Magnification;        public double Stretch_Magnification        {            get { return this.stretch_Magnification; }            set { this.stretch_Magnification = value; }        }        //定位切割位置的放大倍数        private double location_Magnification;        public double Location_Magnification        {            get { return this.location_Magnification; }            set { this.location_Magnification = value; }        }        //定位切割位置的工作电压        private double location_Voltage;        public double Location_Voltage        {            get { return this.location_Voltage; }            set { this.location_Voltage = value; }        }        //拍照的放大倍数        private double photograph_Magnification;        public double Photograph_Magnification        {            get { return this.photograph_Magnification; }            set { this.photograph_Magnification = value; }        }        //拍照的工作电压        private double photograph_Voltage;        public double Photograph_Voltage        {            get { return this.photograph_Voltage; }            set { this.photograph_Voltage = value; }        }        //校正角度选择        private double correction_Angle;        public double Correction_Angle        {            get { return this.correction_Angle; }            set { this.correction_Angle = value; }        }        //样品类型        private String sample_Type;        public String Sample_Type        {            get { return this.sample_Type; }            set { this.sample_Type = value; }        }        //厂商        private String firm;        public String Firm        {            get { return this.firm; }            set { this.firm = value; }        }        //对焦参数        //能谱参数        #endregion        public ConfigFile()        {                    }        /// <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(this.is_Photograph);            ptDepostion.AssignValue(this.pt_Depostion);            sFile.Register("Is_Photograph", isPhotograph);            sFile.Register("PT_Depostion", ptDepostion);            xString ptELYFile = new xString();            xString fibELYFile = new xString();            ptELYFile.AssignValue(this.pt_ELYFile);            fibELYFile.AssignValue(this.fib_ELYFile);            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(this.stretch_Magnification);            locationMagnification.AssignValue(this.location_Magnification);            locationVoltage.AssignValue(this.location_Voltage);            photographMagnification.AssignValue(this.photograph_Magnification);            photographVoltage.AssignValue(this.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(this.correction_Angle);            sFile.Register("Correction_Angle", correctionAngle);            xString sampleType = new xString();            xString _firm = new xString();            sampleType.AssignValue(this.sample_Type);            _firm.AssignValue(this.firm);            sFile.Register("Sample_Type", sampleType);            sFile.Register("Firm", _firm);            if (isStoring)            {                sFile.Serialize(true, xml, rootNode);            }            else            {                sFile.Serialize(false, xml, rootNode);                this.is_Photograph = isPhotograph.value();                this.pt_Depostion = ptDepostion.value();                this.pt_ELYFile = ptELYFile.value();                this.fib_ELYFile = fibELYFile.value();                this.stretch_Magnification = stretchMagnification.value();                this.location_Magnification = locationMagnification.value();                this.location_Voltage = locationVoltage.value();                this.photograph_Magnification = photographMagnification.value();                this.photograph_Voltage = photographVoltage.value();                this.correction_Angle = correctionAngle.value();                this.sample_Type = sampleType.value();                this.firm = _firm.value();            }        }    }}
 |