| | |
| | | using System.IO; |
| | | using Yw; |
| | | using Yw.WinFrmUI; |
| | | using Yw.Untity; |
| | | using Yw.Service; |
| | | |
| | | namespace IBox.WinFrmUI |
| | | { |
| | |
| | | public event EventHandler<string> SendData; |
| | | private void SendText(string content) |
| | | { |
| | | //BluetoothHelper.GetInstance().SendData(content); |
| | | SendData?.Invoke(null, 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) |
| | |
| | | } |
| | | private FacilityVmo _facilities = null; |
| | | private IBoxControllViewModel boxControllViewModel = 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(IBoxControllViewModel ibox) |
| | | { |
| | | this.PageTitle.Caption = "智能控制"; |
| | |
| | | private void InitDataSource() |
| | | { |
| | | var f = _facilities; |
| | | //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 Build() |
| | | { |
| | | factoryName = f.Name, |
| | |
| | | 层数 = double.Parse(f.Floor.ToString()), |
| | | 层高 = double.Parse(f.FloorHeight.ToString()), |
| | | }; |
| | | ShowChart(); |
| | | //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 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 FileHelper().ReadFile(path); |
| | | var result = JsonHelper.Json2Object<List<Result>>(content); |
| | | AddPoints(result); |
| | | ShowPressPoints(); |
| | | } |
| | | private List<Result> _res; |
| | | //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; |
| | | //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); |
| | | // // 计算多项式在点 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; |
| | | // //_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.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; |
| | | // //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; |
| | | // var dataPoints = this.chart1.Series[0].Points; |
| | | |
| | | // 计算多项式在点 x 处的取值 |
| | | // 计算拟合曲线上的点 |
| | | var waterpress = _SelectedBuild.流量压降下限.FittedCurve.Select((d) => { return new PointF(d.X, (float)_facilities.MaxHeight + _SelectedBuild.用户压力需求); }).ToList(); |
| | | // // 计算多项式在点 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); |
| | | } |
| | | } |
| | | // 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 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() |