public bool NewMethodSnapShotMethod(string path, string methodName) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(path); XmlNode root = xmlDoc.ChildNodes[1]; foreach (XmlNode node in root.ChildNodes) { if (methodName == node.Name) { MessageBox.Show("已存在此配置", "新建配置", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return(false); } } try { XmlNode user = xmlDoc.CreateNode(XmlNodeType.Element, methodName, null); root.AppendChild(user); AppConfig.CreateNode(xmlDoc, user, "SaveTime", DateTime.Now.ToString("g")); XmlNode uv = xmlDoc.CreateNode(XmlNodeType.Element, "UV", null); AppConfig.CreateNode(xmlDoc, uv, "UVVPS", AppConfig.frmUV.GetUVVPS_ComboBox()); AppConfig.CreateNode(xmlDoc, uv, "UVAUUnit", AppConfig.frmUV.GetUVAUUnit_ComboBox()); AppConfig.CreateNode(xmlDoc, uv, "UVTimeUnit", AppConfig.frmUV.GetUVTimeUnit_ComboBox()); AppConfig.CreateNode(xmlDoc, uv, "UVMaxTime", AppConfig.frmUV.GetUVMaxTime_TextBox()); AppConfig.CreateNode(xmlDoc, uv, "UVWaveLength1", AppConfig.frmUV.GetUVWaveLength1_TextBox()); AppConfig.CreateNode(xmlDoc, uv, "UVWaveLength2", AppConfig.frmUV.GetUVWaveLength2_TextBox()); AppConfig.CreateNode(xmlDoc, uv, "UVWaveLength3", AppConfig.frmUV.GetUVWaveLength3_TextBox()); AppConfig.CreateNode(xmlDoc, uv, "UVCurv0Color", AppConfig.frmUV.GetUVWaveLength1Color_Set()); AppConfig.CreateNode(xmlDoc, uv, "UVCurv1Color", AppConfig.frmUV.GetUVWaveLength2Color_Set()); AppConfig.CreateNode(xmlDoc, uv, "UVCurv2Color", AppConfig.frmUV.GetUVWaveLength3Color_Set()); user.AppendChild(uv); XmlNode pump = xmlDoc.CreateNode(XmlNodeType.Element, "Pump", null); user.AppendChild(pump); XmlNode constant = xmlDoc.CreateNode(XmlNodeType.Element, "Constant", null); AppConfig.CreateNode(xmlDoc, constant, "ConstantFlow", AppConfig.frmPump.SetConstantFlow_TextBox("")); AppConfig.CreateNode(xmlDoc, constant, "ConstantTime", AppConfig.frmPump.SetConstantTime_TextBox("")); AppConfig.CreateNode(xmlDoc, constant, "ConstantPumpA", AppConfig.frmPump.SetConstantPumpA_TextBox("")); AppConfig.CreateNode(xmlDoc, constant, "ConstantPumpB", AppConfig.frmPump.SetConstantPumpB_TextBox("")); AppConfig.CreateNode(xmlDoc, constant, "ConstantPumpC", AppConfig.frmPump.SetConstantPumpC_TextBox("")); AppConfig.CreateNode(xmlDoc, constant, "ConstantPumpD", AppConfig.frmPump.SetConstantPumpD_TextBox("")); pump.AppendChild(constant); XmlNode grad = xmlDoc.CreateNode(XmlNodeType.Element, "Gradient", null); AppConfig.CreateNode(xmlDoc, grad, "PumpACurvEn", AppConfig.frmPump.SetPumpA_ColorChecked(false)); AppConfig.CreateNode(xmlDoc, grad, "PumpBCurvEn", AppConfig.frmPump.SetPumpB_ColorChecked(false)); AppConfig.CreateNode(xmlDoc, grad, "PumpCCurvEn", AppConfig.frmPump.SetPumpC_ColorChecked(false)); AppConfig.CreateNode(xmlDoc, grad, "PumpDCurvEn", AppConfig.frmPump.SetPumpD_ColorChecked(false)); AppConfig.CreateNode(xmlDoc, grad, "PumpACurvColor", AppConfig.frmPump.GetPumpA_Color()); AppConfig.CreateNode(xmlDoc, grad, "PumpBCurvColor", AppConfig.frmPump.GetPumpB_Color()); AppConfig.CreateNode(xmlDoc, grad, "PumpCCurvColor", AppConfig.frmPump.GetPumpC_Color()); AppConfig.CreateNode(xmlDoc, grad, "PumpDCurvColor", AppConfig.frmPump.GetPumpD_Color()); AppConfig.CreateNode(xmlDoc, grad, "GradTime", ""); AppConfig.CreateNode(xmlDoc, grad, "GradFlow", ""); AppConfig.CreateNode(xmlDoc, grad, "GradPumpA", ""); AppConfig.CreateNode(xmlDoc, grad, "GradPumpB", ""); AppConfig.CreateNode(xmlDoc, grad, "GradPumpC", ""); AppConfig.CreateNode(xmlDoc, grad, "GradPumpD", ""); pump.AppendChild(grad); XmlNode collector = xmlDoc.CreateNode(XmlNodeType.Element, "Collector", null); AppConfig.CreateNode(xmlDoc, collector, "ButtleVolume", AppConfig.frmCollector.SetButtleVolume_TextBox("")); AppConfig.CreateNode(xmlDoc, collector, "PipeLength", AppConfig.frmCollector.SetPipeLength_TextBox("")); AppConfig.CreateNode(xmlDoc, collector, "PipeDiameter", AppConfig.frmCollector.SetPipeDiameter_TextBox("")); AppConfig.CreateNode(xmlDoc, collector, "CollectorProgram_MinPeakWidth", AppConfig.frmCollector.SetCollectorProgram_MinPeakWidth_TextBox("")); AppConfig.CreateNode(xmlDoc, collector, "StartButtleNo", AppConfig.frmCollector.SetStartButtleNo_TextBox("")); AppConfig.CreateNode(xmlDoc, collector, "StopButtleNo", AppConfig.frmCollector.SetStopButtleNo_TextBox("")); AppConfig.CreateNode(xmlDoc, collector, "StartFilter", ""); AppConfig.CreateNode(xmlDoc, collector, "StartTime", ""); AppConfig.CreateNode(xmlDoc, collector, "StartThreshold", ""); AppConfig.CreateNode(xmlDoc, collector, "StartSlope", ""); AppConfig.CreateNode(xmlDoc, collector, "StopFilter", ""); AppConfig.CreateNode(xmlDoc, collector, "StopTime", ""); AppConfig.CreateNode(xmlDoc, collector, "StopThreshold", ""); AppConfig.CreateNode(xmlDoc, collector, "StopSlope", ""); AppConfig.CreateNode(xmlDoc, collector, "MaxVolume", ""); AppConfig.CreateNode(xmlDoc, collector, "MaxTime", ""); AppConfig.CreateNode(xmlDoc, collector, "CollectorProgram_Channel", ""); user.AppendChild(collector); xmlDoc.Save(path); } catch (Exception e) { ////显示错误信息 //Console.WriteLine(e.Message); MessageBox.Show(e.Message, "新建配置", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return(false); } return(true); }
public void CreateMethodSnapShotXmlFile(string path) { if (File.Exists(path)) { return; } XmlDocument xmlDoc = new XmlDocument(); XmlNode node = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", ""); xmlDoc.AppendChild(node); XmlNode root = xmlDoc.CreateElement("Method"); xmlDoc.AppendChild(root); XmlNode config = xmlDoc.CreateNode(XmlNodeType.Element, "MethodConfig", null); AppConfig.CreateNode(xmlDoc, config, "LastMethodName", "默认"); root.AppendChild(config); XmlNode user = xmlDoc.CreateNode(XmlNodeType.Element, "默认", null); root.AppendChild(user); AppConfig.CreateNode(xmlDoc, user, "SaveTime", DateTime.Now.ToString("g")); XmlNode uv = xmlDoc.CreateNode(XmlNodeType.Element, "UV", null); AppConfig.CreateNode(xmlDoc, uv, "UVVPS", AppConfig.frmUV.GetUVVPS_ComboBox()); AppConfig.CreateNode(xmlDoc, uv, "UVAUUnit", AppConfig.frmUV.GetUVAUUnit_ComboBox()); AppConfig.CreateNode(xmlDoc, uv, "UVTimeUnit", AppConfig.frmUV.GetUVTimeUnit_ComboBox()); AppConfig.CreateNode(xmlDoc, uv, "UVMaxTime", AppConfig.frmUV.GetUVMaxTime_TextBox()); AppConfig.CreateNode(xmlDoc, uv, "UVWaveLength1", AppConfig.frmUV.GetUVWaveLength1_TextBox()); AppConfig.CreateNode(xmlDoc, uv, "UVWaveLength2", AppConfig.frmUV.GetUVWaveLength2_TextBox()); AppConfig.CreateNode(xmlDoc, uv, "UVWaveLength3", AppConfig.frmUV.GetUVWaveLength3_TextBox()); AppConfig.CreateNode(xmlDoc, uv, "UVCurv0Color", AppConfig.frmUV.GetUVWaveLength1Color_Set()); AppConfig.CreateNode(xmlDoc, uv, "UVCurv1Color", AppConfig.frmUV.GetUVWaveLength2Color_Set()); AppConfig.CreateNode(xmlDoc, uv, "UVCurv2Color", AppConfig.frmUV.GetUVWaveLength3Color_Set()); user.AppendChild(uv); XmlNode pump = xmlDoc.CreateNode(XmlNodeType.Element, "Pump", null); user.AppendChild(pump); XmlNode constant = xmlDoc.CreateNode(XmlNodeType.Element, "Constant", null); AppConfig.CreateNode(xmlDoc, constant, "ConstantFlow", AppConfig.frmPump.SetConstantFlow_TextBox("")); AppConfig.CreateNode(xmlDoc, constant, "ConstantTime", AppConfig.frmPump.SetConstantTime_TextBox("")); AppConfig.CreateNode(xmlDoc, constant, "ConstantPumpA", AppConfig.frmPump.SetConstantPumpA_TextBox("")); AppConfig.CreateNode(xmlDoc, constant, "ConstantPumpB", AppConfig.frmPump.SetConstantPumpB_TextBox("")); AppConfig.CreateNode(xmlDoc, constant, "ConstantPumpC", AppConfig.frmPump.SetConstantPumpC_TextBox("")); AppConfig.CreateNode(xmlDoc, constant, "ConstantPumpD", AppConfig.frmPump.SetConstantPumpD_TextBox("")); pump.AppendChild(constant); XmlNode grad = xmlDoc.CreateNode(XmlNodeType.Element, "Gradient", null); AppConfig.CreateNode(xmlDoc, grad, "PumpACurvEn", AppConfig.frmPump.SetPumpA_ColorChecked(false)); AppConfig.CreateNode(xmlDoc, grad, "PumpBCurvEn", AppConfig.frmPump.SetPumpB_ColorChecked(false)); AppConfig.CreateNode(xmlDoc, grad, "PumpCCurvEn", AppConfig.frmPump.SetPumpC_ColorChecked(false)); AppConfig.CreateNode(xmlDoc, grad, "PumpDCurvEn", AppConfig.frmPump.SetPumpD_ColorChecked(false)); AppConfig.CreateNode(xmlDoc, grad, "PumpACurvColor", AppConfig.frmPump.GetPumpA_Color()); AppConfig.CreateNode(xmlDoc, grad, "PumpBCurvColor", AppConfig.frmPump.GetPumpB_Color()); AppConfig.CreateNode(xmlDoc, grad, "PumpCCurvColor", AppConfig.frmPump.GetPumpC_Color()); AppConfig.CreateNode(xmlDoc, grad, "PumpDCurvColor", AppConfig.frmPump.GetPumpD_Color()); AppConfig.CreateNode(xmlDoc, grad, "GradTime", ""); AppConfig.CreateNode(xmlDoc, grad, "GradFlow", ""); AppConfig.CreateNode(xmlDoc, grad, "GradPumpA", ""); AppConfig.CreateNode(xmlDoc, grad, "GradPumpB", ""); AppConfig.CreateNode(xmlDoc, grad, "GradPumpC", ""); AppConfig.CreateNode(xmlDoc, grad, "GradPumpD", ""); pump.AppendChild(grad); XmlNode collector = xmlDoc.CreateNode(XmlNodeType.Element, "Collector", null); AppConfig.CreateNode(xmlDoc, collector, "ButtleVolume", AppConfig.frmCollector.SetButtleVolume_TextBox("")); AppConfig.CreateNode(xmlDoc, collector, "PipeLength", AppConfig.frmCollector.SetPipeLength_TextBox("")); AppConfig.CreateNode(xmlDoc, collector, "PipeDiameter", AppConfig.frmCollector.SetPipeDiameter_TextBox("")); AppConfig.CreateNode(xmlDoc, collector, "CollectorProgram_MinPeakWidth", AppConfig.frmCollector.SetCollectorProgram_MinPeakWidth_TextBox("")); AppConfig.CreateNode(xmlDoc, collector, "StartButtleNo", AppConfig.frmCollector.SetStartButtleNo_TextBox("")); AppConfig.CreateNode(xmlDoc, collector, "StopButtleNo", AppConfig.frmCollector.SetStopButtleNo_TextBox("")); AppConfig.CreateNode(xmlDoc, collector, "StartFilter", ""); AppConfig.CreateNode(xmlDoc, collector, "StartTime", ""); AppConfig.CreateNode(xmlDoc, collector, "StartThreshold", ""); AppConfig.CreateNode(xmlDoc, collector, "StartSlope", ""); AppConfig.CreateNode(xmlDoc, collector, "StopFilter", ""); AppConfig.CreateNode(xmlDoc, collector, "StopTime", ""); AppConfig.CreateNode(xmlDoc, collector, "StopThreshold", ""); AppConfig.CreateNode(xmlDoc, collector, "StopSlope", ""); AppConfig.CreateNode(xmlDoc, collector, "MaxVolume", ""); AppConfig.CreateNode(xmlDoc, collector, "MaxTime", ""); AppConfig.CreateNode(xmlDoc, collector, "CollectorProgram_Channel", ""); user.AppendChild(collector); try { xmlDoc.Save(path); } catch (Exception e) { ////显示错误信息 //Console.WriteLine(e.Message); } }