using DevExpress.Utils.Layout; namespace Yw.WinFrmUI { public partial class SetHydroWaterboxCalcuPrefixListCtrl : DevExpress.XtraEditors.XtraUserControl { public SetHydroWaterboxCalcuPrefixListCtrl() { InitializeComponent(); } /// /// 查看水箱事件 /// public event Action ViewParterEvent; private Yw.Model.HydroModelInfo _hydroInfo = null; private List _allCalcuPrefixCtrlList = null; /// /// 绑定数据 /// public void SetBindingData(Yw.Model.HydroModelInfo hydroInfo) { _hydroInfo = hydroInfo; InitialControls(); } /// /// 更新绑定数据 /// public void UpdateBindingData() { _allCalcuPrefixCtrlList?.ForEach(x => x.UpdateBindingData()); } //初始化控件 private void InitialControls() { if (_hydroInfo == null) { return; } if (_allCalcuPrefixCtrlList == null) { _allCalcuPrefixCtrlList = new List(); this.tablePanel.Rows.Add(new TablePanelRow(TablePanelEntityStyle.Relative, 55F)); if (_hydroInfo.Waterboxs != null && _hydroInfo.Waterboxs.Count > 0) { for (int i = 0; i < _hydroInfo.Waterboxs.Count; i++) { this.tablePanel.Columns.Add(new TablePanelColumn(TablePanelEntityStyle.AutoSize, 250F)); var ctrl = new SetHydroWaterboxCalcuPrefixCtrl(); ctrl.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom; ctrl.ViewEvent += (waterbox) => { if (waterbox == null) { return; } this.ViewParterEvent?.Invoke(waterbox); }; _allCalcuPrefixCtrlList.Add(ctrl); this.tablePanel.Controls.Add(ctrl); this.tablePanel.SetCell(ctrl, 0, i); } this.tablePanel.Columns.Add(new TablePanelColumn(TablePanelEntityStyle.AutoSize, 150F)); } } if (_hydroInfo.Waterboxs != null && _hydroInfo.Waterboxs.Count == _allCalcuPrefixCtrlList.Count) { for (int i = 0; i < _allCalcuPrefixCtrlList.Count; i++) { _allCalcuPrefixCtrlList[i].SetBindingData(_hydroInfo.Waterboxs[i]); } } } } }