tangxu
2024-12-27 9cc5bf68aaab46f33f2b00f8dcef0ab52ced0c41
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using DPumpHydr.WinFrmUI.Volute;
using DPumpHydr.WinFrmUI.Volute.ViewModel;
 
namespace DPumpHydr.WinFrmUI 
{
    public partial class VoluteParasTranHelper
    {
 
        XmlDocument xmlDoc;
        public bool Save(
                string filePath, 
                DPumpHydr.WinFrmUI.Volute.ViewModel.HdrBaseInfo hdrBaseInfo,
                DPumpHydr.WinFrmUI.Volute.ViewModel.GeomBaseInfo geomBaseInfo,
                DPumpHydr.WinFrmUI.Volute.ViewModel.SectionBundleInfo sectionBundleInfo,
                DPumpHydr.WinFrmUI.Volute.ViewModel.eOutflowStyle otuflowType,
                DPumpHydr.WinFrmUI.Volute.ViewModel.OtuflowParas otuflowParas)
        {
            xmlDoc = new XmlDocument();
 
            XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
            xmlDoc.AppendChild(xmlDeclaration);
 
            XmlElement rootNode = xmlDoc.CreateElement("root");
            xmlDoc.AppendChild(rootNode);
 
            #region 版本信息
 
            //创建VersionInfo子节点
            XmlNode VersionInfoNode = xmlDoc.CreateElement("VersionInfo");
            XmlAttribute VersionInfoNodeAttribute = xmlDoc.CreateAttribute("Description");
            VersionInfoNodeAttribute.Value = "XML_Version";
            VersionInfoNode.InnerText = "V1.0";
            VersionInfoNode.Attributes.Append(VersionInfoNodeAttribute);
            rootNode.AppendChild(VersionInfoNode);
 
            #endregion
 
            #region hdrBaseInfo
 
            //创建ProductSetting子节点
            if (hdrBaseInfo != null)
            {
                var nodeHdrBaseInfo = xmlDoc.CreateElement("HdrBaseInfo");
                rootNode.AppendChild(nodeHdrBaseInfo);
 
 
                nodeHdrBaseInfo.AppendChild(AddParasNode("ShapeType", hdrBaseInfo.ShapeType.ToString(), "形状类型"));
                nodeHdrBaseInfo.AppendChild(AddParasNode("B2", hdrBaseInfo.B2.ToString(), "叶轮宽度"));
 
            }
 
 
 
            #endregion
 
 
            #region geomBaseInfo
 
            //创建ProductSetting子节点
            if (geomBaseInfo != null)
            {
                var nodeGeomBaseInfo = xmlDoc.CreateElement("GeomBaseInfo");
                rootNode.AppendChild(nodeGeomBaseInfo);
 
 
                XmlNode nodeB3 = xmlDoc.CreateElement("B3");
                nodeB3.InnerText = geomBaseInfo.B3.ToString();
                nodeGeomBaseInfo.AppendChild(nodeB3);
 
            }
            #endregion
 
 
            xmlDoc.Save(filePath);
            return true;
        }
 
        private XmlNode AddParasNode( string name,string value,string desp)
        {
            XmlNode node = xmlDoc.CreateElement(name);
            node.InnerText = value;
            if (!string.IsNullOrEmpty(desp))
            {
                XmlAttribute desAttribute = xmlDoc.CreateAttribute("Description");
                desAttribute.Value = desp;
                node.Attributes.Append(desAttribute);
            }
 
            return node;
        } 
    }
}