using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
namespace IStation.WinFrmUI.Monitor
{
///
///
///
public partial class BoxSelectPointsDlg : XtraForm
{
public BoxSelectPointsDlg()
{
InitializeComponent();
this.gridView1.SetNormalView();
this.gridView1.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.Default;
}
public event Func RemovePointEvent;
public event Func, bool> ReloadDataEvent;
private BindingList _bindingList = null;
///
/// 绑定数据
///
public void Set(List checkPoints)
{
if (checkPoints != null && checkPoints.Any())
{
checkPoints.ForEach(x => x.Round());
_bindingList = new BindingList(checkPoints);
}
else
{
_bindingList = new BindingList();
}
this.curveAnalyzePointBindingSource.DataSource = _bindingList;
this.curveAnalyzePointBindingSource.ResetBindings(false);
this.gridView1.BestFitColumns();
}
//验证
public bool Valid()
{
this.gridView1.CloseEditor();
this.gridView1.UpdateCurrentRow();
if (_bindingList.Count > 0)
{
for (int i = 0; i < _bindingList.Count; i++)
{
var vm = _bindingList[i];
if (string.IsNullOrEmpty(vm.HZ.ToString()))
{
this.gridView1.FocusedRowHandle = i;
this.gridView1.SetColumnError(this.colHz, "必填项");
return false;
}
if (string.IsNullOrEmpty(vm.Q.ToString()))
{
this.gridView1.FocusedRowHandle = i;
this.gridView1.SetColumnError(this.colHz, "必填项");
return false;
}
}
}
return true;
}
#region GridView
//删除
private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
{
if (_bindingList == null || _bindingList.Count < 1)
return;
if (e.Column == this.colDelete)
{
var row = this.gridView1.GetFocusedRow() as Model.CurveAnalyzePoint;
if (row == null)
return;
if (this.RemovePointEvent != null)
{
var bol = this.RemovePointEvent(row.Time);
if (bol)
{
_bindingList.Remove(row);
}
}
}
}
#endregion
}
}