using HStation.WinFrmUI.PhartRelation;
using HStation.WinFrmUI.Xhs;
namespace HStation.WinFrmUI
{
///
/// 项目模拟属性控件
///
public partial class XhsProjectSimulationPropertyCtrl : DevExpress.XtraEditors.XtraUserControl
{
public XhsProjectSimulationPropertyCtrl()
{
InitializeComponent();
this.hydroParterPropertyCtrl1.PropertyValueChangedEvent += HydroParterPropertyCtrl1_PropertyValueChangedEvent;
this.hydroParterPropertyCtrl1.PropertyValueChangingEvent += HydroParterPropertyCtrl1_PropertyValueChangingEvent;
this.hydroParterPropertyCtrl1.MatchingDbEvent += HydroParterPropertyCtrl1_MatchingDbEvent;
this.hydroParterPropertyCtrl1.SetCurveEvent += HydroParterPropertyCtrl1_SetCurveEvent;
this.hydroParterPropertyCtrl1.SetPatternEvent += HydroParterPropertyCtrl1_SetPatternEvent;
this.hydroParterPropertyCtrl1.BlinkLinkParterEvent += HydroParterPropertyCtrl1_BlinkLinkParterEvent;
}
///
/// 强调连接组件事件
/// 第一个参数为组件Code
/// 第二个参数为连接组件Code
///
public event Action BlinkLinkParterEvent;
//水力信息方法
private Func _hydroInfoFunc = null;
private Func> _allHydroCalcuResultListFunc = null;
///
/// 初始化数据
///
public void InitialData(Func hydroInfoFunc, Func> allHydroCalcuResultListFunc)
{
_hydroInfoFunc = hydroInfoFunc;
_allHydroCalcuResultListFunc = allHydroCalcuResultListFunc;
this.hydroParterPropertyCtrl1.InitialData(hydroInfoFunc);
}
///
/// 选择组件
///
public void SelectParter(long id)
{
var hydroInfo = _hydroInfoFunc?.Invoke();
if (hydroInfo == null)
{
this.hydroParterPropertyCtrl1.SelectedObject = null;
return;
}
var allParterList = hydroInfo.GetAllParters();
var parter = allParterList.Find(x => x.ID == id);
var vm = Yw.WinFrmUI.HydroParterPropertyViewModelBuilder.CreateViewModel(parter, allParterList);
this.hydroParterPropertyCtrl1.SelectedObject = vm;
}
///
/// 选择组件
///
public void SelectParter(string code)
{
var hydroInfo = _hydroInfoFunc?.Invoke();
if (hydroInfo == null)
{
this.hydroParterPropertyCtrl1.SelectedObject = null;
return;
}
var allParterList = hydroInfo.GetAllParters();
var parter = allParterList.Find(x => x.Code == code);
var vm = Yw.WinFrmUI.HydroParterPropertyViewModelBuilder.CreateViewModel(parter, allParterList);
this.hydroParterPropertyCtrl1.SelectedObject = vm;
}
///
/// 选择组件
///
public void SelectParter(Yw.Model.HydroParterInfo parter, List allParterList)
{
var vm = Yw.WinFrmUI.HydroParterPropertyViewModelBuilder.CreateViewModel(parter, allParterList);
this.hydroParterPropertyCtrl1.SelectedObject = vm;
}
///
/// 更新计算属性
///
public void UpdateCalcuProperty(Yw.WinFrmUI.IHydroCalcuResult rhs)
{
var vm = this.hydroParterPropertyCtrl1.SelectedObject;
if (vm == null)
{
return;
}
vm.UpdateCalcuProperty(rhs);
this.hydroParterPropertyCtrl1.UpdateRows();
}
//选择曲线
private bool HydroParterPropertyCtrl1_SetCurveEvent(HydroParterPropertyViewModel propViewModel, string curveType)
{
var hydroInfo = _hydroInfoFunc?.Invoke();
if (hydroInfo == null)
{
return false;
}
switch (curveType)
{
case Yw.WinFrmUI.HydroCurve.Pump:
{
var pumpInfo = hydroInfo.Pumps?.Find(x => x.Code == propViewModel.Code);
if (pumpInfo == null)
{
break;
}
var input = AssetsMatchingParasHelper.Create(hydroInfo, pumpInfo, _allHydroCalcuResultListFunc?.Invoke());
var dlg = new SinglePumpAnalyDlg();
dlg.SetBindindData(input);
dlg.ReloadDataEvent += (output) =>
{
var bol = AssetsMatchingParasHelper.Apply(hydroInfo, output);
if (bol)
{
propViewModel.UpdateProperty(pumpInfo, hydroInfo.GetAllParters());
}
return bol;
};
dlg.ShowDialog();
return true;
}
case Yw.WinFrmUI.HydroCurve.PumpQH:
{
return false;
}
case Yw.WinFrmUI.HydroCurve.PumpQP:
{
return false;
}
case Yw.WinFrmUI.HydroCurve.PumpQE:
{
return false;
}
case Yw.WinFrmUI.HydroCurve.Valve:
{
return true;
}
case Yw.WinFrmUI.HydroCurve.ValveQL:
{
return false;
}
default: break;
}
return false;
}
//选择模式
private bool HydroParterPropertyCtrl1_SetPatternEvent(HydroParterPropertyViewModel propViewModel, string patternType)
{
switch (patternType)
{
case Yw.WinFrmUI.HydroPattern.Demand:
{
}
break;
case Yw.WinFrmUI.HydroPattern.Head:
{
}
break;
default: break;
}
return true;
}
//属性发生改变
private bool HydroParterPropertyCtrl1_PropertyValueChangedEvent(HydroParterPropertyViewModel obj)
{
return false;
}
//属性正在发生改变
private bool HydroParterPropertyCtrl1_PropertyValueChangingEvent(HydroParterPropertyViewModel arg)
{
return false;
}
//匹配Db
private bool HydroParterPropertyCtrl1_MatchingDbEvent(HydroParterPropertyViewModel propertyViewModel)
{
var bol = false;
if (propertyViewModel == null)
{
return bol;
}
var hydroInfo = _hydroInfoFunc?.Invoke();
if (hydroInfo == null)
{
return bol;
}
var catalog = Yw.WinFrmUI.HydroParterCatalogHelper.GetCatalogCode(propertyViewModel.Catalog);
switch (catalog)
{
case Yw.Hydro.ParterCatalog.Pump://水泵
{
var pumpInfo = hydroInfo.Pumps?.Find(x => x.Code == propertyViewModel.Code);
if (pumpInfo == null)
{
break;
}
var input = AssetsMatchingParasHelper.Create(hydroInfo, pumpInfo, _allHydroCalcuResultListFunc?.Invoke());
var dlg = new PumpSingleMatchingDlg();
dlg.SetBindingData(input);
dlg.ReloadDataEvent += (output) =>
{
bol = AssetsMatchingParasHelper.Apply(hydroInfo, output);
if (bol)
{
propertyViewModel.UpdateProperty(pumpInfo, hydroInfo.GetAllParters());
}
};
dlg.ShowDialog();
}
break;
case Yw.Hydro.ParterCatalog.Valve://阀门
{
var valveInfo = hydroInfo.Valves?.Find(x => x.Code == propertyViewModel.Code);
if (valveInfo == null)
{
break;
}
var input = AssetsMatchingParasHelper.Create(hydroInfo, valveInfo, _allHydroCalcuResultListFunc?.Invoke());
var dlg = new ValveSingleMatchingDlg();
dlg.SetBindingData(input);
dlg.ReloadDataEvent += (rhs) =>
{
bol = AssetsMatchingParasHelper.Apply(hydroInfo, rhs);
};
dlg.ShowDialog();
}
break;
case Yw.Hydro.ParterCatalog.Pipe://管道
{
}
break;
case Yw.Hydro.ParterCatalog.Elbow://弯头
{
var elbowInfo = hydroInfo.Elbows?.Find(x => x.Code == propertyViewModel.Code);
if (elbowInfo == null)
{
break;
}
var input = AssetsMatchingParasHelper.Create(hydroInfo, elbowInfo, _allHydroCalcuResultListFunc?.Invoke());
var dlg = new ElbowSingMatchingDlg();
dlg.SetBindingData(input);
dlg.ReloadDataEvent += (output) =>
{
bol = AssetsMatchingParasHelper.Apply(hydroInfo, output);
};
dlg.ShowDialog();
}
break;
case Yw.Hydro.ParterCatalog.Threelink://三通
{
}
break;
case Yw.Hydro.ParterCatalog.Fourlink://四通
{
}
break;
default: break;
}
return bol;
}
//强调连接组件
private void HydroParterPropertyCtrl1_BlinkLinkParterEvent(string code, string linkCode)
{
if (string.IsNullOrEmpty(code))
{
return;
}
if (string.IsNullOrEmpty(linkCode))
{
return;
}
this.BlinkLinkParterEvent?.Invoke(code, linkCode);
}
}
}