using DevExpress.XtraCharts; using DevExpress.XtraEditors; using IStation.Unit; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace IStation.WinFrmUI.Monitor { public partial class DataScreeningChartCtrl : XtraUserControl { public DataScreeningChartCtrl() { InitializeComponent(); this.monitorPointTreeListCtrl1.FocusedChangedEvent += MonitorPointTreeListCtrl1_FocusedChangedEvent; this.timeValueEasyChartView1.BoxSelCompleteEvent += TimeValueEasyChartView1_BoxSelCompleteEvent; } /// /// 绑定数据 /// public void SetBindingData() { _allBindList = new List(); this.timeValueEasyChartView1.InitialDefaultSeries(_allBindList); this.monitorPointTreeListCtrl1.SetBindingData(); } private Model.MonitorPointExSignalExSignalType _model = null; private List _allBindList = null; private const string delete = "delete"; //框选返回事件 private void TimeValueEasyChartView1_BoxSelCompleteEvent(string tag, List timeValues) { if (timeValues == null || timeValues.Count < 1) return; var times = timeValues.Select(x => x.Time); switch (tag) { case delete: { Delete(times); } break; default: break; } } //监测点变换 private void MonitorPointTreeListCtrl1_FocusedChangedEvent(Model.MonitorPointExSignalExSignalType obj) { _model = obj; _allBindList = new List(); if (_model == null) { this.timeValueEasyChartView1.SetAxisYTitle("?"); this.timeValueEasyChartView1.InitialDefaultSeries(null); } else { if (int.TryParse(_model.UnitValue, out int unitValue)) { var dict = UnitHelper.GetEnUnitDict(_model.UnitType); if (dict != null) this.timeValueEasyChartView1.SetAxisYTitle(dict[unitValue]); } else { this.timeValueEasyChartView1.SetAxisYTitle(_model.UnitValue); } var packet = new BLL.MonitorDataSet().GetSignalRecordPacket(_model.MonitorPointID, _model.SignalID); if (packet != null && packet.RecordList != null) { var validList = packet.RecordList.Where(x => x.Value != IStation.Error.Default && x.Value != IStation.Error.Abnormal); if (validList != null && validList.Any()) { _allBindList = validList.Select(x => new TimeValue(x.Time, x.Value)).ToList(); } } } this.timeValueEasyChartView1.InitialDefaultSeries(_allBindList); } //删除 private void Delete(IEnumerable times) { WaitFrmHelper.ShowWaitForm("正在删除..."); if (times == null || times.Count() < 1) { XtraMessageBox.Show("无数据!"); return; } var bol = new BLL.MonitorDataSet().SetAbnormal(_model.MonitorPointID, _model.SignalID, times, IStation.Error.Default); if (!bol) { XtraMessageBox.Show("删除失败!"); return; } for (int i = 0; i < _allBindList.Count; i++) { var point = _allBindList[i]; if (times.Contains(point.Time)) { _allBindList.RemoveAt(i); i--; } } this.timeValueEasyChartView1.InitialDefaultSeries(_allBindList); WaitFrmHelper.HideWaitForm(); XtraMessageBox.Show("删除成功!"); } //框选删除 public void Delete() { this.timeValueEasyChartView1.StartBoxSel(delete); } //区间删除 public void RangeDelete() { var dlg = new SetRangeDlg(); if (dlg.ShowDialog() != DialogResult.OK) return; var times = _allBindList?.Where(x => x.Value >= dlg.MinValue && x.Value <= dlg.MaxValue).Select(x => x.Time).ToList(); if (times == null || times.Count < 1) { XtraMessageBox.Show("未检索到区间值!"); return; } Delete(times); } //清除负值 public void ClearNegativeValues() { if (XtraMessageBox.Show("确认清除所有负值吗?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) return; var times = _allBindList?.Where(x => x.Value < 0).Select(x => x.Time).ToList(); if (times == null || times.Count < 1) { XtraMessageBox.Show("未检索到负值!"); return; } Delete(times); } //清除零值 public void ClearZer0() { if (XtraMessageBox.Show("确认清除所有负值吗?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) return; var times = _allBindList?.Where(x => x.Value == 0).Select(x => x.Time).ToList(); if (times == null || times.Count < 1) { XtraMessageBox.Show("未检索到零值!"); return; } Delete(times); } /* private void barBtnCaclu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (_model == null) return; if (_allBindList == null || _allBindList.Count < 1) return; switch (_model.Identifier) { case IStation.SignalType.瞬时流量: { SuperpositionCalcu(); } break; case IStation.SignalType.有功功率: { SuperpositionCalcu(); } break; case IStation.SignalType.有功电度: { SuperpositionCalcu(); } break; default: { XtraMessageBox.Show("暂不支持计算!"); return; } } } private void SuperpositionCalcu() { if (_allBindList == null || _allBindList.Count < 1) return; double value = 0; var count = 0; for (int i = 0; i < _allBindList.Count - 1; i++) { var n = _allBindList[i]; var n1 = _allBindList[i + 1]; var second = (n1.Time - n.Time).TotalSeconds; value += n1.Value / 3600 * second; count++; } var str = new StringBuilder(); str.AppendLine($"点数量:{count}"); str.AppendLine($"叠加值:{Math.Round(value, 0)}"); XtraMessageBox.Show(str.ToString()); } private void barBtnExport_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (_model == null) return; var monitorPointExSignalList = this.monitorPointTreeListCtrl1.GetMonitorPointExSignalList(); monitorPointExSignalList = monitorPointExSignalList?.Where(x => x.SignalList.First().SignalType == IStation.Scatl.SignalType.累积流量 || x.SignalList.First().SignalType == IStation.Scatl.SignalType.有功电度).ToList(); if (monitorPointExSignalList == null || monitorPointExSignalList.Count < 1) return; var monitorPointGroups = this.monitorPointTreeListCtrl1.GetMonitorPointGroups(); WaitFrmHelper.ShowWaitForm(); var dlg = new SuperpositionCalcuDlg(); dlg.SetBindingData(_projectId, monitorPointGroups, monitorPointExSignalList); dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); }; dlg.ShowDialog(); } private void barBtnPumpDataCompare_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (_model == null) return; var monitorPointExSignalList = this.monitorPointTreeListCtrl1.GetMonitorPointExSignalList(); if (monitorPointExSignalList == null || monitorPointExSignalList.Count < 1) return; var monitorPointGroups = this.monitorPointTreeListCtrl1.GetMonitorPointGroups(); WaitFrmHelper.ShowWaitForm(); var dlg = new PumpDataCompareDlg2(); dlg.SetBindingData(_projectId, monitorPointGroups, monitorPointExSignalList); dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); }; dlg.ShowDialog(); }*/ } }