ningshuxia
2025-03-20 04f704ff17446bf70381c337b6539bfd4fe03cab
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
using Hydro;
 
namespace PBS.WinFrmUI.Hydro
{
    /// <summary>
    /// 管网模型辅助类
    /// </summary>
    public static class NetWorkModelHelper
    {
 
        /// <summary>
        /// 从模型导入
        /// </summary>
        public static void ImportFromModel(long FacilitiesID, MapViewNetWork netWork)
        {
            if (netWork != null)
            {
                ClearData(FacilitiesID);
                var m = new BLL.Facilities().GetByID(FacilitiesID);
                //var watersupply = new BLL.Part().GetAll().FirstOrDefault(c => c.ID == long.Parse(m.WaterSupply));
 
                if (netWork.meters != null && netWork.meters.Any())
                {
                    var meterModels = new List<Model.Meter>();
                    var meterBLL = new BLL.Meter();
                    var dlTemplateBLL = new BLL.EquivalentTemplate();
                    foreach (var meter in netWork.meters)
                    {
                        var dlTemplate = "";
                        if (!string.IsNullOrEmpty(meter.DlTemplateID))
                        {
                            var dls = dlTemplateBLL.GetAll();
                            if (dls.Any(c => c.Name.Equals(meter.DlTemplateID)))
                                dlTemplate = dls.FirstOrDefault(c => c.Name.Equals(meter.DlTemplateID)).ID.ToString();
                        }
                        meterModels.Add(new Model.Meter()
                        {
                            BelongID = m.ID,
                            DlTemplateID = dlTemplate,
                            Floor = string.IsNullOrEmpty(meter.Floor) ? "0" : meter.Floor,
                            Elevation = (decimal)meter.Elev,
                            id = meter.ID,
                            Name = meter.GetTypeString().ToString(),
                            PositionX = meter.X.ToString(),
                            PositionY = meter.Y.ToString(),
                            SystemType = m.ModelType
                        });
                    }
                    if (meterModels.Count > 0)
                        meterBLL.Inserts(meterModels);
                }
                if (netWork.nozzles != null && netWork.nozzles.Any())
                {
                    var nozzleBLL = new BLL.Nozzle();
                    var ratioBLL = new BLL.RatioConfig();
                    foreach (var nozzle in netWork.nozzles)
                    {
                        var ratio = "";
                        var config = ratioBLL.GetAll().FirstOrDefault(c => c.Value == nozzle.FlowCoefficient.ToString());
                        if (config != null)
                        {
                            ratio = config.ID.ToString();
                        }
                        nozzleBLL.Insert(new Model.Nozzle()
                        {
                            BelongID = m.ID,
                            Kratio = ratio,
                            Floor = string.IsNullOrEmpty(nozzle.Floor) ? "0" : nozzle.Floor,
                            id = nozzle.ID,
                            Name = nozzle.GetTypeString().ToString(),
                            PositionX = nozzle.X.ToString(),
                            PositionY = nozzle.Y.ToString(),
                            SystemType = m.ModelType,
                            Room = nozzle.Room
                        });
                    }
                }
                if (netWork.junctions != null && netWork.junctions.Any())
                {
                    var otherBLL = new BLL.Other();
                    var otherModels = new List<Model.Other>();
                    foreach (var junction in netWork.junctions)
                    {
                        otherModels.Add(new Model.Other()
                        {
                            id = junction.ID,
                            Name = junction.GetTypeString().ToString(),
                            BelongID = m.ID,
                            Elevation = (decimal)junction.Elev,
                            Floor = string.IsNullOrEmpty(junction.Floor) ? "0" : junction.Floor,
                            PositionX = junction.X.ToString(),
                            PositionY = junction.Y.ToString(),
                            SystemType = m.ModelType
 
                        });
                    }
                    if (otherModels.Count > 0)
                        otherBLL.Inserts(otherModels);
                }
                if (netWork.pipes != null && netWork.pipes.Any())
                {
                    var pipeBLL = new BLL.Pipe();
                    var pipeModels = new List<Model.Pipe>();
                    foreach (var pipe in netWork.pipes)
                    {
                        pipeModels.Add(new Model.Pipe()
                        {
                            BelongID = m.ID,
                            Name = pipe.GetTypeString().ToString(),
                            EndNode = pipe.Node2,
                            Floor = string.IsNullOrEmpty(pipe.Floor) ? "0" : pipe.Floor,
                            HeisenCoefficient = (decimal)pipe.Roughness,
                            PipediaMeter = (decimal)pipe.Diameter,
                            Length = (decimal)pipe.Length,
                            PipeType = 1,
                            id = pipe.ID,
                            PositionX = pipe.X.ToString(),
                            PositionY = pipe.Y.ToString(),
                            StartNode = pipe.Node1,
                            Status = (pipe.Status == Hydro.Core.ObjectEnum.StatusType.DEFAULT || pipe.Status == Hydro.Core.ObjectEnum.StatusType.OPEN) ? true : false,
                            SystemType = m.ModelType
                        });
                    }
                    if (pipeModels.Count>0)
                        pipeBLL.Inserts(pipeModels);
                }
                if (netWork.reservoirs != null && netWork.reservoirs.Any())
                {
                    var pumpAdapterBLL = new BLL.PumpAdapter();
                    foreach (var reservoir in netWork.reservoirs)
                    {
                        var name = reservoir.GetTypeString().ToString();
                        if (name == "水库")
                        {
                            new BLL.WaterTank().Insert(new Model.WaterTank()
                            {
                                BelongID = m.ID,
                                Floor = string.IsNullOrEmpty(reservoir.Floor) ? "0" : reservoir.Floor,
                                id = reservoir.ID,
                                Name = name,
                                PositionX = reservoir.X.ToString(),
                                PositionY = reservoir.Y.ToString(),
                                Level = reservoir.Level,
                                //MaxLevel = (decimal)reservoir.MaxLevel,
                                //MinLevel = (decimal)reservoir.MinLevel,
                                //Volume = (decimal)reservoir.MinVol,
                                SystemType = m.ModelType
                            });
                        }
                        else
                        {
                            pumpAdapterBLL.Insert(new Model.PumpAdapter()
                            {
                                BelongID = m.ID,
                                Elevation = (decimal)reservoir.Elev,
                                Floor = string.IsNullOrEmpty(reservoir.Floor) ? "0" : reservoir.Floor,
                                id = reservoir.ID,
                                Name = reservoir.Name,
                                Pressure = (decimal)reservoir.Head,
                                PositionX = reservoir.X.ToString(),
                                PositionY = reservoir.Y.ToString(),
                                SystemType = m.ModelType
                            });
                        }
                    }
                }
                if (netWork.valves != null && netWork.valves.Any())
                {
                    var valveBLL = new BLL.Valve();
                    foreach (var valve in netWork.valves)
                    {
                        valveBLL.Insert(new Model.Valve()
                        {
                            BelongID = m.ID,
                            Diameter = (decimal)valve.Diameter,
                            EndNode = valve.Node2,
                            StartNode = valve.Node1,
                            Floor = string.IsNullOrEmpty(valve.Floor) ? "0" : valve.Floor,
                            id = valve.ID,
                            Name = valve.Name,
                            PositionX = valve.X.ToString(),
                            PositionY = valve.Y.ToString(),
                            Status = (valve.Status == Hydro.Core.ObjectEnum.StatusType.DEFAULT || valve.Status == Hydro.Core.ObjectEnum.StatusType.OPEN) ? true : false,
                            SystemType = m.ModelType
 
                        });
                    }
                }
                if (netWork.pumps != null && netWork.pumps.Any())
                {
                    var pumpBLL = new BLL.WaterPump();
                    foreach (var pump in netWork.pumps)
                    {
                        pumpBLL.Insert(new Model.WaterPump()
                        {
                            BelongID = m.ID,
                            EndNode = pump.Node2,
                            StartNode = pump.Node1,
                            Floor = string.IsNullOrEmpty(pump.Floor) ? "0" : pump.Floor,
                            id = pump.ID,
                            Name = pump.Name,
                            PositionX = pump.X.ToString(),
                            PositionY = pump.Y.ToString(),
                            RatedFlow = (decimal)pump.额定流量,
                            RatedHead = (decimal)pump.额定扬程,
                            RatedPower = (decimal)pump.额定功率,
                            RatedSpeed = (decimal)pump.额定转速,
                            Status = (pump.Status == Hydro.Core.ObjectEnum.StatusType.DEFAULT || pump.Status == Hydro.Core.ObjectEnum.StatusType.OPEN) ? true : false,
                            SystemType = m.ModelType
                        });
                    }
                }
                if (netWork.tanks != null && netWork.tanks.Any())
                {
                    var tankBLL = new BLL.WaterTank();
                    foreach (var tank in netWork.tanks)
                    {
                        tankBLL.Insert(new Model.WaterTank()
                        {
                            BelongID = m.ID,
                            Floor = string.IsNullOrEmpty(tank.Floor) ? "0" : tank.Floor,
                            id = tank.ID,
                            Name = tank.Name,
                            PositionX = tank.X.ToString(),
                            PositionY = tank.Y.ToString(),
                            Level = tank.Level,
                            MaxLevel = (decimal)tank.MaxLevel,
                            MinLevel = (decimal)tank.MinLevel,
                            Volume = (decimal)tank.MinVol,
                            SystemType = m.ModelType
                        });
                    }
                }
 
            }
        }
 
        /// <summary>
        /// 从Revit导入
        /// </summary>
        public static void ImportFromRevit(long FacilitiesID, string JsonText)
        {
            ClearData(FacilitiesID);
 
        }
 
        /// <summary>
        /// 先清空数据
        /// </summary>
        public static void ClearData(long FacilitiesID)
        {
            new BLL.HydrantBox().DeletByBelongID(FacilitiesID);
            new BLL.Meter().DeletByBelongID(FacilitiesID);
            new BLL.Nozzle().DeletByBelongID(FacilitiesID);
            new BLL.Other().DeletByBelongID(FacilitiesID);
            new BLL.Pipe().DeletByBelongID(FacilitiesID);
            new BLL.PumpAdapter().DeletByBelongID(FacilitiesID);
            new BLL.Valve().DeletByBelongID(FacilitiesID);
            new BLL.WaterPump().DeletByBelongID(FacilitiesID);
            new BLL.WaterTank().DeletByBelongID(FacilitiesID);
        }
    }
}