public void DeserializeXml() { XmlSerializerProvider.Deserialize(new XmlSerializer(Drivers.GetType()), ref Drivers); XmlSerializerProvider.Deserialize(new XmlSerializer(Routes.GetType()), ref Routes); XmlSerializerProvider.Deserialize(new XmlSerializer(Transports.GetType()), ref Transports); XmlSerializerProvider.Deserialize(new XmlSerializer(Shifts.GetType()), ref Shifts); XmlSerializerProvider.Deserialize(new XmlSerializer(DriverShifts.GetType()), ref DriverShifts); XmlSerializerProvider.Deserialize(new XmlSerializer(TechPassports.GetType()), ref TechPassports); }
public void SerializeXml() { XmlSerializerProvider.Serialize(new XmlSerializer(Drivers.GetType()), Drivers); XmlSerializerProvider.Serialize(new XmlSerializer(Routes.GetType()), Routes); XmlSerializerProvider.Serialize(new XmlSerializer(Transports.GetType()), Transports); XmlSerializerProvider.Serialize(new XmlSerializer(Shifts.GetType()), Shifts); XmlSerializerProvider.Serialize(new XmlSerializer(DriverShifts.GetType()), DriverShifts); XmlSerializerProvider.Serialize(new XmlSerializer(TechPassports.GetType()), TechPassports); }
// 读取系统配置文件 private bool ReadSystemConfig() { try { XmlSerializerProvider xml = new XmlSerializerProvider(); SystemConfig fc = xml.Deserialize <SystemConfig>(AppDomain.CurrentDomain.BaseDirectory + "\\SystemConfig.xml"); if (string.IsNullOrWhiteSpace(fc.BackupPath) || string.IsNullOrWhiteSpace(fc.CenterIP) || string.IsNullOrWhiteSpace(fc.Port) || string.IsNullOrWhiteSpace(fc.SoundName) || fc.Xrange < 1 || fc.PreiodUnit < 0 || fc.Preiod < 1 || fc.CenterPort < 1 || fc.BaudRate < 1 || fc.BackupPreiod < 1) { LogLib.Log.GetLogger(this).Warn("系统配置文件有空值"); return(false); } systemConfig = fc; comboBoxEdit_Port.Text = systemConfig.Port; textEdit_BaudRate.Text = systemConfig.BaudRate.ToString(); textEdit_Preod.Text = systemConfig.Preiod.ToString(); comboBoxEdit_second.SelectedIndex = systemConfig.PreiodUnit; textEdit_RealTime.Text = systemConfig.Xrange.ToString(); textEdit_Temperature.Text = systemConfig.Temperature.ToString(); textEdit_Volume.Text = systemConfig.Volume.ToString(); textEdit_Molecular.Text = systemConfig.Molecular.ToString(); textEdit_Path.Text = systemConfig.BackupPath; checkEdit_Back.Checked = systemConfig.Isbackup; textEdit_BackupPreiod.Text = systemConfig.BackupPreiod.ToString(); textEdit_CenterIP.Text = systemConfig.CenterIP; textEdit_centerPort.Text = systemConfig.CenterPort.ToString(); checkEdit_autosample.Checked = systemConfig.Isauto; } catch (Exception ex) { LogLib.Log.GetLogger(this).Warn(ex); return(false); } return(true); }
/// <summary> /// 获取界面系统配置参数 /// </summary> /// <returns></returns> private void SaveSystemConfig() { try { systemConfig.Port = comboBoxEdit_Port.Text; systemConfig.BaudRate = int.Parse(textEdit_BaudRate.Text); systemConfig.Preiod = int.Parse(textEdit_Preod.Text); systemConfig.PreiodUnit = comboBoxEdit_second.SelectedIndex; systemConfig.Xrange = int.Parse(textEdit_RealTime.Text); systemConfig.Temperature = float.Parse(textEdit_Temperature.Text); systemConfig.Volume = float.Parse(textEdit_Volume.Text); systemConfig.Molecular = int.Parse(textEdit_Molecular.Text); systemConfig.BackupPath = textEdit_Path.Text; systemConfig.Isbackup = checkEdit_Back.Checked; systemConfig.BackupPreiod = int.Parse(textEdit_BackupPreiod.Text); systemConfig.CenterIP = textEdit_CenterIP.Text; systemConfig.CenterPort = int.Parse(textEdit_centerPort.Text); systemConfig.Isauto = checkEdit_autosample.Checked; if (PLAASerialPort.serialport.IsOpen) { PLAASerialPort.GetInstance().Close(); PLAASerialPort.GetInstance().Open(systemConfig.Port, systemConfig.BaudRate); Gloabl.IsOpen = true; } else { PLAASerialPort.GetInstance().Open(systemConfig.Port, systemConfig.BaudRate); Gloabl.IsOpen = true; } XmlSerializerProvider xml = new XmlSerializerProvider(); xml.Serialize <SystemConfig>(AppDomain.CurrentDomain.BaseDirectory + "\\SystemConfig.xml", systemConfig); XtraMessageBox.Show("保存成功"); } catch (Exception ex) { XtraMessageBox.Show("保存失败"); LogLib.Log.GetLogger(this).Warn(ex); } }