using DevExpress.XtraCharts;
using DevExpress.XtraEditors;
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.WinFormUI.MonitorDataSet
{
public partial class FilterDataMgrPage : DocumentPage
{
public FilterDataMgrPage()
{
InitializeComponent();
_boxSelHelper = new ChartBoxSelHelper(this.chartControl1);
_boxSelHelper.BoxSelCompletedEvent += _boxSelHelper_BoxSelCompletedEvent;
this.monitorPointTreeListCtrl1.SelectEvent += MonitorPointTreeListCtrl1_SelectEvent;
this.PageTitle.Caption = "数据筛查";
}
#region 当前视图类
public class CurrentViewModel
{
public CurrentViewModel() { }
public CurrentViewModel(Model.SignalRecord rhs)
{
this.DataTime = rhs.Time;
this.DataValue = rhs.Value;
}
public DateTime DataTime { get; set; }
public double DataValue { get; set; }
}
#endregion
///
/// 初始化数据
///
public void InitialDataSource(long projectId,long sceneId, Model.LogicTree logic)
{
_projectId = projectId;
_sceneId = sceneId;
this.monitorPointTreeListCtrl1.SetBindingData(_projectId, logic.LogicType, logic.LogicId);
}
private SwiftPlotDiagram _diagram
{
get { return this.chartControl1.Diagram as SwiftPlotDiagram; }
}
private Series _series
{
get
{
return this.chartControl1.Series[0];
}
}
private long _projectId;
private long _sceneId;
private Model.Signal _model = null;
private List _allBindList = null;
private ChartBoxSelHelper _boxSelHelper = null;//框选辅助类
private void MonitorPointTreeListCtrl1_SelectEvent(string objectType, object model, MouseEventArgs arg3)
{
/*var lays = this.chartControl1.ShowOverlay();
var monitorPointExSignalList = model as Model.MonitorPointExSignalList;
_model = monitorPointExSignalList?.SignalList.First();
if (_model == null)
{
this.labCaption.Text = "未知";
_diagram.AxisY.Title.Text = "值";
_allBindList = null;
}
else
{
this.labCaption.Text = _model.Name;
_diagram.AxisY.Title.Text = UnitValueHelper.Get(_projectId,_model);
var packet = new BLL.MonitorDataSet().GetSignalRecordPacket(_projectId,_sceneId, _model.MonitorPointId, _model.Id);
if (packet == null|| packet.RecordList==null)
{
_allBindList = new List();
lays.Close();
return;
}
else
{
_allBindList = packet.RecordList.Where(x => x.Value != IStation.Default.Abnormal&&x.Value!= IStation.Default.Error)?.Select(x => new CurrentViewModel(x)).ToList();
}
}
if (_allBindList == null)
_allBindList = new List();
this.currentViewModelBindingSource.DataSource = _allBindList;
this.currentViewModelBindingSource.ResetBindings(false);
lays.Close();*/
var lays = this.chartControl1.ShowOverlay();
var monitorPointExSignalList = model as Model.MonitorPointExSignalList;
_model = monitorPointExSignalList?.SignalList.First();
if (_model == null)
{
this.labCaption.Text = "未知";
_diagram.AxisY.Title.Text = "值";
_allBindList = null;
}
else
{
this.labCaption.Text = _model.Name;
_diagram.AxisY.Title.Text = "高度/m";
var packet = new BLL.MonitorDataSet().GetSignalRecordPacket(_projectId, _sceneId, _model.MonitorPointId, _model.Id);
if (packet == null || packet.RecordList == null)
{
_allBindList = new List();
lays.Close();
return;
}
else
{
_allBindList = packet.RecordList.Where(x => x.Value != IStation.Default.Abnormal && x.Value != IStation.Default.Error)?.Select(x => new CurrentViewModel(x)).ToList();
}
}
if (_allBindList == null)
_allBindList = new List();
this.currentViewModelBindingSource.DataSource = _allBindList;
this.currentViewModelBindingSource.ResetBindings(false);
lays.Close();
}
//框选完成
private void _boxSelHelper_BoxSelCompletedEvent(MouseEventArgs e)
{
_boxSelSeriesPointList = _boxSelHelper?.CalcuDataTimeSelSeriesPoints(new List() { _series });
if (_boxSelSeriesPointList == null || _boxSelSeriesPointList.Count < 1)
{
_boxSelHelper?.CloseBoxSel();
}
else
{
this.popBoxSel.ShowPopup(MousePosition);
}
}
private List _boxSelSeriesPointList = null;
//删除
private void barBtnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
if (_boxSelSeriesPointList == null || _boxSelSeriesPointList.Count < 1)
return;
var lays = this.chartControl1.ShowOverlay();
var dataTimeList = _boxSelSeriesPointList.Select(x => x.DateTimeArgument).ToList();
var bol = new BLL.MonitorDataSet().SetAbnormal(_projectId,_sceneId, _model.MonitorPointId, _model.Id, dataTimeList,IStation.Default.Abnormal);
if (!bol)
{
lays.Close();
XtraMessageBox.Show("删除失败!");
return;
}
_allBindList.RemoveAll(x => dataTimeList.Contains(x.DataTime));
this.currentViewModelBindingSource.ResetBindings(false);
lays.Close();
}
//关闭
private void popBoxSel_CloseUp(object sender, EventArgs e)
{
_boxSelHelper?.CloseBoxSel();
}
//框选删除
private void barBtnBoxSel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
_boxSelHelper?.StartBoxSel();
}
//区间删除
private void barBtnRangeDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
XtraMessageBox.Show("未恢复");
/*var dlg = new SetRangeDlg();
if (dlg.ShowDialog() == DialogResult.OK)
{
var dataTimeList = _allBindList?.Where(x => x.DataValue>=dlg.MinValue&&x.DataValue<=dlg.MaxValue).Select(x => x.DataTime).ToList();
if (dataTimeList == null || dataTimeList.Count < 1)
{
XtraMessageBox.Show("未检索到区间值!");
return;
}
var lays = this.chartControl1.ShowOverlay();
var bol = new BLL.MonitorDataSet().SetAbnormal(_projectId,_sceneId, _model.MonitorPointId, _model.Id, dataTimeList,IStation.Default.Abnormal);
if (!bol)
{
lays.Close();
XtraMessageBox.Show("删除失败!");
return;
}
_allBindList.RemoveAll(x => dataTimeList.Contains(x.DataTime));
this.currentViewModelBindingSource.ResetBindings(false);
lays.Close();
} */
}
//清除负值
private void barBtnClearNegative_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
if (XtraMessageBox.Show("确认清除所有负值吗?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
return;
}
var dataTimeList = _allBindList?.Where(x => x.DataValue < 0).Select(x=>x.DataTime).ToList();
if (dataTimeList == null || dataTimeList.Count < 1)
{
XtraMessageBox.Show("未检索到负值!");
return;
}
var lays = this.chartControl1.ShowOverlay();
var bol = new BLL.MonitorDataSet().SetAbnormal(_projectId,_sceneId, _model.MonitorPointId, _model.Id, dataTimeList,IStation.Default.Abnormal);
if (!bol)
{
lays.Close();
XtraMessageBox.Show("删除失败!");
return;
}
_allBindList.RemoveAll(x => dataTimeList.Contains(x.DataTime));
this.currentViewModelBindingSource.ResetBindings(false);
lays.Close();
}
//清除零值
private void barBtnClearZero_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
if (XtraMessageBox.Show("确认清除所有零值吗?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
return;
}
var dataTimeList = _allBindList?.Where(x => x.DataValue == 0).Select(x => x.DataTime).ToList();
if (dataTimeList == null || dataTimeList.Count < 1)
{
XtraMessageBox.Show("未检索到零值!");
return;
}
var lays = this.chartControl1.ShowOverlay();
var bol = new BLL.MonitorDataSet().SetAbnormal(_projectId, _sceneId, _model.MonitorPointId, _model.Id, dataTimeList, IStation.Default.Abnormal);
if (!bol)
{
lays.Close();
XtraMessageBox.Show("删除失败!");
return;
}
_allBindList.RemoveAll(x => dataTimeList.Contains(x.DataTime));
this.currentViewModelBindingSource.ResetBindings(false);
lays.Close();
}
//图标的右键菜单
private void chartControl1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
this.popMain.ShowPopup(MousePosition);
}
}
}
}