namespace Yw.WinFrmUI
{
public partial class SetHydroCoolingDlg : DevExpress.XtraEditors.XtraForm
{
public SetHydroCoolingDlg()
{
InitializeComponent();
this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
this.layoutControl1.SetupLayoutControl();
this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent;
}
///
/// 返回数据事件
///
public event Action> ReloadDataEvent;
private List _allVisualList = null; //所有构件列表
private HydroChangeHelper _changeHelper = null;//改变辅助类
private HydroPropStatusHelper _propStatusHelper = null;//属性状态辅助类
///
/// 绑定数据
///
public void SetBindingData
(
Yw.Model.HydroCoolingInfo visual,
HydroChangeHelper changeHelper = null,
HydroPropStatusHelper propStatusHelper = null
)
{
var allVisualList = visual == null ? null : new List() { visual };
SetBindingData(allVisualList, changeHelper, propStatusHelper);
}
///
/// 绑定数据
///
public void SetBindingData
(
List allVisualList,
HydroChangeHelper changeHelper = null,
HydroPropStatusHelper propStatusHelper = null
)
{
_allVisualList = allVisualList;
_changeHelper = changeHelper;
_propStatusHelper = propStatusHelper;
if (_allVisualList != null && _allVisualList.Count == 1)
{
var visual = _allVisualList.First();
this.txtBeginGroup.EditValue = visual.BeginGroup;
this.txtElev.EditValue = Math.Round(visual.Elev, 4);
this.txtMaterial.EditValue = visual.Material;
this.txtCaliber.EditValue = visual.Caliber;
this.txtCoefficient.EditValue = visual.Coefficient;
this.txtLowerLimit.EditValue = visual.LowerLimit;
}
}
//确定
private void GeneralOkAndCancelCtrl1_OkEvent()
{
if (_allVisualList == null || _allVisualList.Count < 1)
{
return;
}
var beginGroup = this.txtBeginGroup.Text.Trim();
double? elev = this.txtElev.EditValue == null ? null : double.Parse(this.txtElev.EditValue.ToString());
var material = this.txtMaterial.Text.Trim();
double? caliber = this.txtCaliber.EditValue == null ? null : double.Parse(this.txtCaliber.EditValue.ToString());
double? coefficient = this.txtCoefficient.EditValue == null ? null : double.Parse(this.txtCoefficient.EditValue.ToString());
double? lowerLimit = this.txtLowerLimit.EditValue == null ? null : double.Parse(this.txtLowerLimit.EditValue.ToString());
_allVisualList.ForEach(x =>
{
if (!string.IsNullOrEmpty(beginGroup))
{
if (x.BeginGroup != beginGroup)
{
_changeHelper.Append(x, eChangeType.Update);
_propStatusHelper?.UpdatePropStatus(x.Code, nameof(x.BeginGroup), Yw.Hydro.ePropStatus.Normal, $"{DateTime.Now.ToStandardString()}通过设置组件修改");
}
x.BeginGroup = beginGroup;
}
if (elev.HasValue)
{
if (x.Elev != elev.Value)
{
_changeHelper.Append(x, eChangeType.Update);
_propStatusHelper?.UpdatePropStatus(x.Code, nameof(x.Elev), Yw.Hydro.ePropStatus.Normal, $"{DateTime.Now.ToStandardString()}通过设置组件修改");
}
x.Elev = elev.Value;
}
if (!string.IsNullOrEmpty(material))
{
if (x.Material != material)
{
_changeHelper.Append(x, eChangeType.Update);
_propStatusHelper?.UpdatePropStatus(x.Code, nameof(x.Material), Yw.Hydro.ePropStatus.Normal, $"{DateTime.Now.ToStandardString()}通过设置组件修改");
}
x.Material = material;
}
if (caliber.HasValue)
{
if (x.Caliber != caliber.Value)
{
_changeHelper.Append(x, eChangeType.Update);
_propStatusHelper?.UpdatePropStatus(x.Code, nameof(x.Caliber), Yw.Hydro.ePropStatus.Normal, $"{DateTime.Now.ToStandardString()}通过设置组件修改");
}
x.Caliber = caliber.Value;
}
if (coefficient.HasValue)
{
if (x.Coefficient != coefficient.Value)
{
_changeHelper?.Append(x, eChangeType.Update);
_propStatusHelper?.UpdatePropStatus(x.Code, nameof(x.Coefficient), Yw.Hydro.ePropStatus.Normal, $"{DateTime.Now.ToStandardString()}通过设置组件修改");
}
x.Coefficient = coefficient.Value;
}
if (lowerLimit.HasValue)
{
if (x.LowerLimit != lowerLimit.Value)
{
_changeHelper.Append(x, eChangeType.Update);
_propStatusHelper?.UpdatePropStatus(x.Code, nameof(x.LowerLimit), Yw.Hydro.ePropStatus.Normal, $"{DateTime.Now.ToStandardString()}通过设置组件修改");
}
x.LowerLimit = lowerLimit.Value;
}
});
this.ReloadDataEvent?.Invoke(_allVisualList);
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}