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);
|
}
|
}
|
}
|