using DevExpress.Utils.Extensions;
|
using DevExpress.XtraEditors;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Linq;
|
|
namespace IStation.WinFrmUI.Monitor
|
{
|
/// <summary>
|
/// 设置校验点
|
/// </summary>
|
public partial class SetCheckPointsDlg : XtraForm
|
{
|
public SetCheckPointsDlg()
|
{
|
InitializeComponent();
|
}
|
|
public event Func<List<Model.CurveAnalyzePoint>, bool> ReloadDataEvent;
|
private BindingList<Model.CurveAnalyzePoint> _bindingList = null;
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void Set(List<Model.CurveAnalyzePoint> checkPoints)
|
{
|
if (checkPoints != null && checkPoints.Any())
|
{
|
_bindingList = new BindingList<Model.CurveAnalyzePoint>(checkPoints);
|
}
|
else
|
{
|
_bindingList = new BindingList<Model.CurveAnalyzePoint>();
|
}
|
|
|
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;
|
_bindingList.Remove(row);
|
}
|
}
|
|
//新增属性时必须先输入属性名
|
private void gridView1_ShowingEditor(object sender, CancelEventArgs e)
|
{
|
if (_bindingList == null)
|
{
|
e.Cancel = true;
|
return;
|
}
|
if (this.gridView1.FocusedColumn != this.colHz)
|
{
|
var row = this.gridView1.GetFocusedRow() as Model.CurveAnalyzePoint;
|
if (row == null)
|
{
|
e.Cancel = true;
|
return;
|
}
|
}
|
}
|
|
//验证名称的唯一性
|
private void gridView1_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
|
{
|
if (_bindingList == null || _bindingList.Count < 1)
|
return;
|
if (this.gridView1.FocusedColumn == this.colHz)
|
{
|
if (double.TryParse(e.Value.ToString(), out double value))
|
{
|
if (value <= 0)
|
{
|
e.ErrorText = "小于或等于0";
|
e.Valid = false;
|
}
|
else if (value > 50)
|
{
|
e.ErrorText = "大于50";
|
e.Valid = false;
|
}
|
var row = this.gridView1.GetFocusedRow() as Model.CurveAnalyzePoint;
|
var list = _bindingList.ToList();
|
list.Remove(row);
|
if (list.Find(x => x.HZ == Convert.ToDouble(e.Value)) != null)
|
{
|
e.ErrorText = "重复";
|
e.Valid = false;
|
}
|
}
|
}
|
}
|
|
#endregion
|
|
private void btnOk_Click(object sender, EventArgs e)
|
{
|
if (!Valid())
|
return;
|
|
var list = _bindingList?.ToList();
|
if (this.ReloadDataEvent != null)
|
{
|
var bol = this.ReloadDataEvent(list);
|
if (!bol)
|
{
|
XtraMessageBox.Show("设置失败!");
|
return;
|
}
|
XtraMessageBox.Show("设置成功!");
|
}
|
this.DialogResult = System.Windows.Forms.DialogResult.OK;
|
this.Close();
|
|
}
|
|
}
|
}
|