lixiaojun
2024-11-04 865ca7b89bde6b1793641c8421fc466695d48f6a
WinFrmUI/Yw.WinFrmUI.Hydro.Core/06-parter/02-tank/HydroTankListCtrl.cs
@@ -1,18 +1,25 @@
namespace Yw.WinFrmUI
using DevExpress.XtraEditors;
namespace Yw.WinFrmUI
{
    public partial class HydroTankListCtrl : DevExpress.XtraEditors.XtraUserControl, IViewHydroParterList
    public partial class HydroTankListCtrl : DevExpress.XtraEditors.XtraUserControl, IHydroParterList
    {
        public HydroTankListCtrl()
        {
            InitializeComponent();
            this.gridView1.SetNormalView(30);
            this.gridView1.RegistCustomDrawRowIndicator(40);
            this.layoutControl1.SetupLayoutControl();
        }
        /// <summary>
        /// 水力点击事件
        /// </summary>
        public event Action<Yw.Model.HydroParterInfo> HydroClickEvent;
        /// <summary>
        /// 水力改变事件
        /// </summary>
        public event Action<List<Yw.Model.HydroParterInfo>> HydroChangedEvent;
        /// <summary>
        /// 显示查询面板
@@ -31,37 +38,113 @@
        /// </summary>
        public bool HasHydroList
        {
            get { return _allBindingList != null && _allBindingList.Count > 0; }
            get { return _allList != null && _allList.Count > 0; }
        }
        //所有列表
        private List<HydroTankViewModel> _allList = null;
        //所有绑定列表
        private List<HydroTankViewModel> _allBindingList = null;
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(Yw.Model.HydroModelInfo hydroInfo, List<HydroCalcuResult> allCalcuResultList)
        public void SetBindingData(Yw.Model.HydroModelInfo hydroInfo)
        {
            _allBindingList = new List<HydroTankViewModel>();
            _allList = new List<HydroTankViewModel>();
            if (hydroInfo != null && hydroInfo.Tanks != null && hydroInfo.Tanks.Count > 0)
            {
                foreach (var tank in hydroInfo.Tanks)
                {
                    var calcuResult = allCalcuResultList?.Find(x => x.Code == tank.Code) as HydroCalcuNodeResult;
                    var vm = new HydroTankViewModel(tank, hydroInfo);
                    _allBindingList.Add(vm);
                    _allList.Add(vm);
                }
            }
            Search();
        }
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(Yw.Model.HydroModelInfo hydroInfo, List<HydroCalcuResult> allCalcuResultList)
        {
            _allList = new List<HydroTankViewModel>();
            if (hydroInfo != null && hydroInfo.Tanks != null && hydroInfo.Tanks.Count > 0)
            {
                foreach (var tank in hydroInfo.Tanks)
                {
                    var vm = new HydroTankViewModel(tank, hydroInfo);
                    var calcuResult = allCalcuResultList?.Find(x => x.Code == tank.Code);
                    if (calcuResult != null)
                    {
                        vm.UpdateCalcuProperty(calcuResult);
                    }
                    _allList.Add(vm);
                }
            }
            Search();
        }
        //查询
        private void Search()
        {
            if (_allList == null || _allList.Count < 1)
            {
                return;
            }
            var name = this.txtName.Text.Trim();
            var code = this.txtCode.Text.Trim();
            var modelType = this.txtModelType.Text.Trim();
            _allBindingList = _allList;
            if (!string.IsNullOrEmpty(name))
            {
                _allBindingList = _allBindingList.Where(x => !string.IsNullOrEmpty(x.Name) && x.Name.Contains(name)).ToList();
            }
            if (!string.IsNullOrEmpty(code))
            {
                _allBindingList = _allBindingList.Where(x => !string.IsNullOrEmpty(x.Code) && x.Code.Contains(code)).ToList();
            }
            if (!string.IsNullOrEmpty(modelType))
            {
                _allBindingList = _allBindingList.Where(x => !string.IsNullOrEmpty(x.ModelType) && x.ModelType.Contains(modelType)).ToList();
            }
            this.hydroTankViewModelBindingSource.DataSource = _allBindingList;
            this.hydroTankViewModelBindingSource.ResetBindings(false);
            if (allCalcuResultList == null || allCalcuResultList.Count < 1)
        }
        //重置
        private void Reset()
        {
            this.txtName.EditValue = null;
            this.txtCode.EditValue = null;
            this.txtModelType.EditValue = null;
            Search();
        }
        //设置
        private void Set()
        {
            Search();
            if (_allBindingList == null || _allBindingList.Count < 1)
            {
                SetNormalView();
                XtraMessageBox.Show("无可设置水箱数据");
                return;
            }
            else
            var dlg = new SetHydroTankDlg();
            dlg.SetBindingData(_allBindingList.Select(x => x.Vmo).ToList());
            dlg.ReloadDataEvent += (list) =>
            {
                SetCalcuView();
            }
                _allBindingList.ForEach(x =>
                {
                    x.Update();
                });
                this.hydroTankViewModelBindingSource.DataSource = _allBindingList;
                this.hydroTankViewModelBindingSource.ResetBindings(false);
                var allParterList = _allBindingList.Select(x => x.Vmo as Yw.Model.HydroParterInfo).ToList();
                this.HydroChangedEvent?.Invoke(allParterList);
            };
            dlg.ShowDialog();
        }
        /// <summary>
@@ -69,6 +152,7 @@
        /// </summary>
        public void SetSimpleView()
        {
            this.groupForHead.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
            this.colDbLocked.Visible = true;
            this.colName.Visible = true;
            this.colCode.Visible = true;
@@ -79,14 +163,15 @@
            this.colMaxLevel.Visible = false;
            this.colDN.Visible = false;
            this.colMinVol.Visible = false;
            this.colVolCurve.Visible = false;
            this.colCurve.Visible = false;
            this.colOverFlow.Visible = false;
            this.colCalcuPress.Visible = false;
            this.colCalcuHead.Visible = false;
            this.colCalcuDemand.Visible = false;
            this.colHasDb.Visible = true;
            this.colFlagsString.Visible = true;
            this.colFlags.Visible = true;
            this.colDescription.Visible = true;
            this.colSet.Visible = false;
        }
        /// <summary>
@@ -94,6 +179,7 @@
        /// </summary>
        public void SetNormalView()
        {
            this.groupForHead.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
            this.colDbLocked.Visible = true;
            this.colName.Visible = true;
            this.colCode.Visible = true;
@@ -104,14 +190,15 @@
            this.colMaxLevel.Visible = true;
            this.colDN.Visible = true;
            this.colMinVol.Visible = true;
            this.colVolCurve.Visible = true;
            this.colCurve.Visible = true;
            this.colOverFlow.Visible = true;
            this.colCalcuPress.Visible = false;
            this.colCalcuHead.Visible = false;
            this.colCalcuDemand.Visible = false;
            this.colHasDb.Visible = true;
            this.colFlagsString.Visible = true;
            this.colFlags.Visible = true;
            this.colDescription.Visible = true;
            this.colSet.Visible = true;
        }
        /// <summary>
@@ -119,6 +206,7 @@
        /// </summary>
        public void SetCalcuView()
        {
            this.groupForHead.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
            this.colDbLocked.Visible = true;
            this.colName.Visible = true;
            this.colCode.Visible = true;
@@ -129,19 +217,65 @@
            this.colMaxLevel.Visible = true;
            this.colDN.Visible = true;
            this.colMinVol.Visible = true;
            this.colVolCurve.Visible = true;
            this.colCurve.Visible = true;
            this.colOverFlow.Visible = true;
            this.colCalcuPress.Visible = true;
            this.colCalcuHead.Visible = true;
            this.colCalcuDemand.Visible = true;
            this.colHasDb.Visible = true;
            this.colFlagsString.Visible = true;
            this.colFlags.Visible = true;
            this.colDescription.Visible = true;
            this.colSet.Visible = true;
        }
        /// <summary>
        /// 设置设置界面模式
        /// </summary>
        public void SetBulkSetView()
        {
            this.groupForHead.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
            this.colDbLocked.Visible = true;
            this.colName.Visible = true;
            this.colCode.Visible = true;
            this.colModelType.Visible = true;
            this.colPoolElev.Visible = true;
            this.colInitLevel.Visible = true;
            this.colMinLevel.Visible = true;
            this.colMaxLevel.Visible = true;
            this.colDN.Visible = true;
            this.colMinVol.Visible = true;
            this.colCurve.Visible = true;
            this.colOverFlow.Visible = true;
            this.colCalcuPress.Visible = false;
            this.colCalcuHead.Visible = false;
            this.colCalcuDemand.Visible = false;
            this.colHasDb.Visible = true;
            this.colFlags.Visible = true;
            this.colDescription.Visible = true;
            this.colSet.Visible = true;
        }
        //行点击事件
        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        //查询
        private void btnSearch_Click(object sender, EventArgs e)
        {
            Search();
        }
        //重置
        private void btnReset_Click(object sender, EventArgs e)
        {
            Reset();
        }
        //设置
        private void btnSet_Click(object sender, EventArgs e)
        {
            Set();
        }
        //单元格点击
        private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            var row = this.gridView1.GetRow(e.RowHandle) as HydroTankViewModel;
            if (row == null)
@@ -149,27 +283,22 @@
                return;
            }
            if (e.Clicks > 1)
            if (e.Column == this.colSet)
            {
                var dlg = new HydroTankBulkSetDlg();
                var dlg = new SetHydroTankDlg();
                dlg.SetBindingData(row.Vmo);
                dlg.ReloadDataEvent += (list) =>
                {
                    row.PoolElev = Math.Round(row.Vmo.PoolElev, 4);
                    row.InitLevel = Math.Round(row.Vmo.InitLevel, 4);
                    row.MinLevel = Math.Round(row.Vmo.MinLevel, 4);
                    row.MaxLevel = Math.Round(row.Vmo.MaxLevel, 4);
                    row.DN = Math.Round(row.Vmo.DN, 4);
                    row.MinVol = Math.Round(row.Vmo.MinVol, 4);
                    row.OverFlow = row.Vmo.OverFlow;
                    row.Update();
                    this.gridView1.RefreshRow(e.RowHandle);
                    this.HydroChangedEvent?.Invoke(new List<Model.HydroParterInfo>() { row.Vmo });
                };
                if (dlg.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                dlg.ShowDialog();
            }
            this.HydroClickEvent?.Invoke(row.Vmo);
            else
            {
                this.HydroClickEvent?.Invoke(row.Vmo);
            }
        }
    }
}