using PBS.Model;
|
using PBS.Vmo;
|
using System.Data;
|
using System.IO;
|
using Yw;
|
using Yw.WinFrmUI;
|
using Yw.Untity;
|
using Yw.Service;
|
|
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)
|
{
|
if (SendData != null)
|
{
|
SendData?.Invoke(null, content);
|
|
}
|
else
|
{
|
if (IBoxHelper.Ping())
|
{
|
var smsg = content.Split(new string[] { IBoxHelper.paramCode }, StringSplitOptions.RemoveEmptyEntries);
|
if (smsg.Length < 2)
|
{
|
return;
|
}
|
switch (smsg[0].Trim())
|
{
|
case IBoxHelper.datadownloadCode:
|
IBoxHelper.HttpPost(content);
|
break;
|
}
|
}
|
else
|
{
|
MessageBoxHelper.ShowWarning("网络连接失败,请检查网络");
|
}
|
}
|
}
|
|
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 FacilityVmo _facilities = null;
|
private IBoxControllViewModel boxControllViewModel = null;
|
public IBoxFormControll(IBoxControllViewModel ibox)
|
{
|
this.PageTitle.Caption = "智能控制";
|
_facilities = ibox.facilities;
|
boxControllViewModel = ibox;
|
InitializeComponent();
|
//this.treeListCtrl1.FocusedChangedEvent += EquipmentTreeListCtrl1_FocusedChangedEvent;
|
InitDataSource();
|
}
|
//private string filePath = "Data\\AnalyData_{0}.json";
|
private void InitDataSource()
|
{
|
var f = _facilities;
|
this._SelectedBuild = new Build()
|
{
|
factoryName = f.Name,
|
系统最大流量 = f.MaxWaterDemand.Value,
|
Type = 二供分区Type.加压供水,
|
ID = f.ID.ToString(),
|
用户压力需求 = int.Parse(f.TerminalPressure.ToString()),
|
层数 = double.Parse(f.Floor.ToString()),
|
层高 = double.Parse(f.FloorHeight.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 = 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 SendDownloadData()
|
{
|
var model = new IBoxControllDownloadViewModel();
|
model.facilities = _facilities;
|
model.kit = boxControllViewModel.Package;
|
model.流量压降下限 = _SelectedBuild.流量压降下限.FittedCurve;
|
model.流量压降上限 = _SelectedBuild.流量压降上限.FittedCurve;
|
model.流量压降曲线 = _SelectedBuild.流量压降曲线.FittedCurve;
|
|
if (!_SelectedBuild.流量压降曲线.IsFitted)
|
_SelectedBuild.流量压降曲线.CurveFit();
|
model.coefficients = _SelectedBuild.流量压降上限.coefficients;
|
model.equations = boxControllViewModel.equations;
|
|
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("数据下发成功!");
|
}
|
|
|
}
|
}
|