using PBS.Model;
|
using System.Data;
|
using System.IO;
|
using Yw;
|
using Yw.WinFrmUI;
|
|
namespace IBox.WinFrmUI
|
{
|
public partial class IBoxFormControll : DocumentPage
|
{
|
|
private string startCode = "[&start&]";
|
private string endCode = "[&end&]";
|
private string paramCode = "[¶m&]";
|
private string datadownloadCode = "datadownload";
|
|
private void EboxFormControll_Load(object sender, EventArgs e)
|
{
|
//BluetoothHelper.GetInstance().SMR -= null;
|
//BluetoothHelper.GetInstance().SMR += new BluetoothHelper.ShowMessReturn(GetReceive);
|
//BluetoothHelper.GetInstance().ListenerData();
|
}
|
|
public void GetReceive(string msg)
|
{
|
if (!this.IsHandleCreated || this.IsDisposed || string.IsNullOrEmpty(msg)) return;
|
if (msg.StartsWith("error:") && msg.Contains("目标主机坏了"))
|
{
|
MessageBoxHelper.ShowWarning(" c蓝牙设备连接失败,请重试!"); return;
|
}
|
if (!string.IsNullOrEmpty(msg) && msg.Contains(startCode))
|
{
|
var order = msg.Replace(endCode, "").Replace(startCode, "").Trim();
|
SetOrder(order);
|
}
|
else MessageBoxHelper.ShowWarning(" c蓝牙设备连接失败");
|
}
|
public event EventHandler<string> SendData;
|
private void SendText(string content)
|
{
|
//BluetoothHelper.GetInstance().SendData(content);
|
SendData?.Invoke(null, content);
|
}
|
|
private void SetOrder(string order)
|
{
|
var smsg = order.Split(new string[] { paramCode }, StringSplitOptions.RemoveEmptyEntries);
|
if (smsg.Length < 2)
|
{
|
return;
|
}
|
|
switch (smsg[0].Trim())
|
{
|
case "datadownload":
|
//WaitFrmHelper.HideWaitForm();
|
break;
|
}
|
}
|
private Model.Facilities _facilities = null;
|
private BLL.EquipmentEChartMapping _bll = new BLL.EquipmentEChartMapping();
|
private BLL.EChart _bllEChart = new BLL.EChart();
|
private BLL.Equipment _bllEquipment = new BLL.Equipment();
|
private Model.Kit _kit = null;
|
private BLL.EquipmentTypeEChartMapping _equipmentTypeEChartMappingBLL = new BLL.EquipmentTypeEChartMapping();
|
public IBoxFormControll(Facility facilities)
|
{
|
this.PageTitle.Caption = "智能控制";
|
_facilities = facilities;
|
InitializeComponent();
|
this.treeListCtrl1.FocusedChangedEvent += EquipmentTreeListCtrl1_FocusedChangedEvent;
|
InitDataSource();
|
}
|
private string filePath = "Data\\AnalyData_{0}.json";
|
private void InitDataSource()
|
{
|
var f = new BLL.Facilities().GetByID(this._facilities.ID);
|
if (f != null)
|
{
|
var kid = long.Parse(f.CompletePlant);
|
var kit = new BLL.Kit().GetByID(kid);
|
_kit = kit;
|
this.treeListCtrl1.SetBindingData(kid);
|
}
|
this._SelectedBuild = new Basic.Build()
|
{
|
factoryName = f.Name,
|
系统最大流量 = f.WaterHeight,
|
Type = 二供分区Type.加压供水,
|
ID = f.ID.ToString(),
|
用户压力需求 = int.Parse(f.WaterPressure.ToString()),
|
层数 = double.Parse(f.Floor.ToString()),
|
层高 = double.Parse(f.FloorHeight.ToString()),
|
每层户数 = double.Parse(f.FloorHouseHolds.ToString())
|
};
|
ShowChart();
|
}
|
|
private void ShowChart()
|
{
|
var file = string.Format(filePath, _facilities.ID.ToString());
|
var path = Path.Combine(Directory.GetCurrentDirectory(), file);
|
if (!File.Exists(path))
|
{
|
MessageBoxHelper.ShowInfo("请先进行系统曲线操作!");
|
return;
|
}
|
else
|
{
|
SetResult(path);
|
}
|
}
|
|
private void SetResult(string path)
|
{
|
var content = new Eventech.Common.FileHelper().ReadFile(path);
|
var result = JsonHelper.Json2Object<List<Result>>(content);
|
AddPoints(result);
|
ShowPressPoints();
|
}
|
private List<Result> _res;
|
private Build _SelectedBuild;
|
public void AddPoints(List<Result> res)
|
{
|
_res = res;
|
List<PointF> nums = res.Select(o => new PointF((float)o.Demand, (float)o.ObjFunctionValue)).ToList();
|
var chartDatas = nums.Select(p => new PointF(p.X, p.Y + _SelectedBuild.用户压力需求 + (float)_facilities.MaxHeight)).ToList();
|
if (chartDatas == null || chartDatas.Count == 0) return;
|
|
// 计算多项式在点 x 处的取值
|
// 计算拟合曲线上的点
|
var curve = new CurveFitHelper(chartDatas, 2);
|
//List<PointF> fitPoints = curve.GetFitCurve(100);
|
List<List<PointF>> confidencePoints = curve.GetConfidenceCurve(100);
|
|
//_SelectedPump.流量压降平均.Data = fitPoints;
|
//_SelectedBuild.流量压降曲线.Data = chartDatas;
|
_SelectedBuild.Datasets.Clear();
|
_SelectedBuild.流量压降曲线.Data = chartDatas;
|
_SelectedBuild.流量压降下限.Data = confidencePoints[0];
|
_SelectedBuild.流量压降上限.Data = confidencePoints[1];
|
}
|
public void ShowPressPoints()
|
{
|
this.chart1.ChartAreas.Clear();
|
this.chart1.ChartAreas.Add(new ChartArea());
|
chart1.Series.Clear();
|
chart1.Series.Add("数据");
|
chart1.Series.Add("平均");
|
chart1.Series["平均"].ChartType = SeriesChartType.Line;
|
chart1.Series["平均"].BorderWidth = 2;
|
chart1.Series.Add("上限");
|
chart1.Series["上限"].ChartType = SeriesChartType.Line;
|
chart1.Series["上限"].BorderWidth = 2;
|
chart1.Series.Add("下限");
|
chart1.Series["下限"].ChartType = SeriesChartType.Line;
|
chart1.Series["下限"].BorderWidth = 2;
|
chart1.Series.Add("泵出口静压线");
|
chart1.Series["泵出口静压线"].ChartType = SeriesChartType.Line;
|
chart1.Series["泵出口静压线"].BorderWidth = 2;
|
chart1.Series["泵出口静压线"].Color = Color.Green;
|
|
chart1.Series.Add("最高楼层标高");
|
chart1.Series["最高楼层标高"].ChartType = SeriesChartType.Line;
|
chart1.Series["最高楼层标高"].BorderWidth = 2;
|
chart1.Series["最高楼层标高"].Color = Color.Yellow;
|
if (chart1.ChartAreas.Count > 0)
|
{
|
chart1.ChartAreas[0].AxisY.Enabled = AxisEnabled.True;
|
//chart1.ChartAreas[0].AxisY2.Enabled = AxisEnabled.True;
|
chart1.ChartAreas[0].AxisX.Enabled = AxisEnabled.True;
|
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "0";
|
chart1.ChartAreas[0].AxisY.LabelStyle.Format = "0";
|
chart1.ChartAreas[0].AxisX.Title = "系统流量(m³/h)";
|
chart1.ChartAreas[0].AxisY.Title = "泵后压力(m)";
|
chart1.ChartAreas[0].AxisY2.Enabled = AxisEnabled.False;
|
}
|
//chart1.ChartAreas[0].AxisX.Minimum = double.NaN;
|
|
//chart1.ChartAreas[0].AxisY.Minimum = double.NaN;
|
var nums = _SelectedBuild.流量压降曲线.Data;
|
if (nums.Count == 0) return;
|
_SelectedBuild.流量压降曲线.CurveFit();
|
var fitPoints = _SelectedBuild.流量压降曲线.FittedCurve;
|
_SelectedBuild.流量压降下限.CurveFit();
|
_SelectedBuild.流量压降上限.CurveFit();
|
List<List<PointF>> confidencePoints = new List<List<PointF>>() { _SelectedBuild.流量压降下限.FittedCurve, _SelectedBuild.流量压降上限.FittedCurve };
|
var chartDatas = nums.ToList();
|
double yMin = double.MaxValue;
|
double yMax = double.MinValue;
|
float xMin = float.MaxValue;
|
float xMax = float.MinValue;
|
if (nums == null || nums.Count == 0) return;
|
this.chart1.Series[0].ChartType = SeriesChartType.Point;
|
//double x = double.Parse(textBox_current_TotalDemand.Text);
|
float x_Avg = 0;
|
float x_Sum = 0;
|
nums.ForEach(y =>
|
{
|
this.chart1.Series["数据"].Points.AddXY(y.X, y.Y);
|
x_Sum += (y.X);
|
if (yMin > y.Y) yMin = y.Y;
|
if (yMax < y.Y) yMax = y.Y;
|
if (xMin > y.X) xMin = y.X;
|
if (xMax < y.X) xMax = y.X;
|
});
|
x_Avg = x_Sum / nums.Count;
|
|
var dataPoints = this.chart1.Series[0].Points;
|
|
// 计算多项式在点 x 处的取值
|
// 计算拟合曲线上的点
|
var waterpress = _SelectedBuild.流量压降下限.FittedCurve.Select((d) => { return new PointF(d.X, (float)_facilities.MaxHeight + _SelectedBuild.用户压力需求); }).ToList();
|
|
var maxheight = _SelectedBuild.流量压降下限.FittedCurve.Select((d) => { return new PointF(d.X, (float)_facilities.MaxHeight); }).ToList();
|
AddSeries(chart1.Series["平均"], fitPoints);
|
AddSeries(chart1.Series["下限"], confidencePoints[0]);
|
AddSeries(chart1.Series["上限"], confidencePoints[1]);
|
AddSeries(chart1.Series["泵出口静压线"], waterpress);
|
AddSeries(chart1.Series["最高楼层标高"], maxheight);
|
if (yMin > 0 && yMin < 10)
|
{
|
this.chart1.ChartAreas[0].AxisY.Minimum = 0;
|
this.chart1.ChartAreas[0].AxisY.Maximum = Math.Ceiling((yMax * 1.2) / 10) * 10;
|
this.chart1.ChartAreas[0].AxisY.Interval = (chart1.ChartAreas[0].AxisY.Maximum - chart1.ChartAreas[0].AxisY.Minimum) / 4;
|
}
|
else
|
{
|
this.chart1.ChartAreas[0].AxisY.Minimum = Math.Floor((yMin * 0.8) / 10) * 10;
|
this.chart1.ChartAreas[0].AxisY.Maximum = Math.Ceiling((yMax * 1.2) / 10) * 10;
|
chart1.ChartAreas[0].AxisX.IsLabelAutoFit = true;
|
//this.chart1.ChartAreas[0].AxisX.Minimum = double.NaN;
|
//this.chart1.ChartAreas[0].AxisX.Maximum = double.NaN;
|
this.chart1.ChartAreas[0].AxisY.Interval = (chart1.ChartAreas[0].AxisY.Maximum - chart1.ChartAreas[0].AxisY.Minimum) / 4;
|
}
|
if (xMin > 0 && xMin < 10)
|
{
|
this.chart1.ChartAreas[0].AxisX.Minimum = 0;
|
this.chart1.ChartAreas[0].AxisX.Maximum = Math.Ceiling(xMax);
|
}
|
else
|
{
|
this.chart1.ChartAreas[0].AxisX.Minimum = Math.Floor((xMin * 0.8) / 10) * 10;
|
this.chart1.ChartAreas[0].AxisX.Maximum = Math.Ceiling(xMax * 1.2);
|
}
|
}
|
|
private void AddSeries(System.Windows.Forms.DataVisualization.Charting.Series serie, List<PointF> points)
|
{
|
if (points == null) return;
|
serie.Points.Clear();
|
foreach (var point in points)
|
{
|
serie.Points.AddXY(point.X, point.Y);
|
}
|
}
|
private void EquipmentTreeListCtrl1_FocusedChangedEvent(string objType, object obj)
|
{
|
this.curveExpressChart1.InitialChartData();
|
if (obj != null && objType == ISupply.ObjectType.Kit)
|
{
|
_kit = obj as Model.Kit;
|
var equipmentList = _bllEquipment.GetByKitIDAndCatalog(_kit.ID, ISupply.Equipment.Pump);
|
if (equipmentList != null && equipmentList.Any())
|
{
|
var mappings = new List<Model.EquipmentEChartMapping>();
|
foreach (var equipment in equipmentList)
|
{
|
var mapping = _bll.GetWorkingByEquipmentID(equipment.ID);
|
if (mapping != null)
|
{
|
mappings.Add(mapping);
|
}
|
}
|
if (mappings.Any())
|
{
|
var curveInfoList = new List<Model.PumpCurveInfo>();
|
foreach (var mapping in mappings)
|
{
|
var chart = _bllEChart.GetPumpCurveInfoByID(mapping.EChartID);
|
if (chart != null && chart.CurveInfoModel != null)
|
{
|
curveInfoList.Add(chart.CurveInfoModel);
|
}
|
}
|
|
if (curveInfoList != null && curveInfoList.Any())
|
{
|
var theConnectCurve = new Curve.ParallelConnectionHelper();
|
for (int i = 0; i < curveInfoList.Count; i++)
|
{
|
var chart = curveInfoList[i];
|
var QH = chart.CurveQH;
|
var QP = chart.CurveQP;
|
var QE = Curve.PumpCalculateHelper.CalculateE(QH, QP);
|
theConnectCurve.AddCurve(QH, QP);
|
}
|
var bol = theConnectCurve.CalculateParallel(out List<ISupply.Curve.CurvePoint> ConnectCurveQH,
|
out List<ISupply.Curve.CurvePoint> ConnectCurveQE,
|
out List<ISupply.Curve.CurvePoint> ConnectCurveQP);
|
if (bol)
|
{
|
var curveExpressQH = ISupply.Curve.FitHelper.BuildCurveExpress(ConnectCurveQH);
|
var curveExpressQE = ISupply.Curve.FitHelper.BuildCurveExpress(ConnectCurveQE);
|
var curveExpressQP = ISupply.Curve.FitHelper.BuildCurveExpress(ConnectCurveQP);
|
this.curveExpressChart1.SetBindingData(curveExpressQH,
|
curveExpressQE,
|
curveExpressQP);
|
}
|
}
|
}
|
}
|
}
|
else if (obj != null && objType == ISupply.ObjectType.Equipment)
|
{
|
var equ = obj as Model.Equipment;
|
var _equipmentChartMappingEx = _equipmentTypeEChartMappingBLL.GetExByEquipmentTypeID(equ.TypeID);
|
|
SetBindingData(_equipmentChartMappingEx);
|
}
|
}
|
|
private void SendDownloadData()
|
{
|
var model = new IBoxControllViewModel();
|
model.facilities = _facilities;
|
model.kit = _kit;
|
model.流量压降下限 = _SelectedBuild.流量压降下限.FittedCurve;
|
model.流量压降上限 = _SelectedBuild.流量压降上限.FittedCurve;
|
model.流量压降曲线 = _SelectedBuild.流量压降曲线.FittedCurve;
|
|
if (!_SelectedBuild.流量压降曲线.IsFitted)
|
_SelectedBuild.流量压降曲线.CurveFit();
|
model.coefficients = _SelectedBuild.流量压降上限.coefficients;
|
//model.IsControll = checkEdit1.Checked;
|
var equipmentList = _bllEquipment.GetByKitIDAndCatalog(_kit.ID, ISupply.Equipment.Pump);
|
if (equipmentList != null && equipmentList.Any())
|
{
|
foreach (var item in equipmentList)
|
{
|
var _equipmentChartMappingEx = _equipmentTypeEChartMappingBLL.GetExByEquipmentTypeID(item.TypeID);
|
_equipmentChartMappingEx.EquipmentId = item.ID;
|
_equipmentChartMappingEx.EquipmentOtherName = item.Name;
|
_equipmentChartMappingEx.RatedParas = item.RatedParas;
|
model.equations.Add(_equipmentChartMappingEx);
|
}
|
}
|
//FileHelper.Write("d:\\EboxData.txt", JsonHelper.Object2Json(model));
|
Thread.Sleep(500);
|
SendText(startCode + datadownloadCode + paramCode + JsonHelper.Object2Json(model) + endCode);
|
}
|
|
private void simpleButton1_Click(object sender, EventArgs e)
|
{
|
//WaitFrmHelper.ShowWaitForm();
|
SendDownloadData();
|
MessageBoxHelper.ShowInfo("数据下发成功!");
|
//MessageBoxHelper.ShowInfo("数据下发成功!");
|
}
|
|
|
|
private void SetBindingData(Model.EquipmentTypeEChartMappingEx model)
|
{
|
this.curveExpressChart1.InitialChartData();
|
var curveInfo = model?.CurveInfo;
|
var coordParas = model?.CoordParas;
|
if (curveInfo != null)
|
{
|
var coordinateParas = ISupply.Curve.CurveCoordinate.ToModel(coordParas);
|
this.curveExpressChart1.SetBindingData(curveInfo.CurveQH,
|
curveInfo.CurveQE,
|
curveInfo.CurveQP,
|
coordinateParas);
|
}
|
}
|
}
|
}
|