lixiaojun
2024-11-04 865ca7b89bde6b1793641c8421fc466695d48f6a
WinFrmUI/Yw.WinFrmUI.Hydro.Core/06-parter/04-junction/HydroJunctionListCtrl.cs
@@ -1,20 +1,26 @@
using Yw.Model;
using DevExpress.XtraEditors;
using Yw.Model;
namespace Yw.WinFrmUI
{
    public partial class HydroJunctionListCtrl : DevExpress.XtraEditors.XtraUserControl, IViewHydroParterList
    public partial class HydroJunctionListCtrl : DevExpress.XtraEditors.XtraUserControl, IHydroParterList
    {
        public HydroJunctionListCtrl()
        {
            InitializeComponent();
            this.gridView1.SetNormalView(30);
            this.gridView1.RegistCustomDrawRowIndicator(40);
            this.layoutControl1.SetupLayoutControl();
        }
        /// <summary>
        /// 水力点击事件
        /// </summary>
        public event Action<HydroParterInfo> HydroClickEvent;
        /// <summary>
        /// 水力改变事件
        /// </summary>
        public event Action<List<HydroParterInfo>> HydroChangedEvent;
        /// <summary>
        /// 显示查询面板
@@ -35,46 +41,124 @@
        {
            get
            {
                return _allBindingList != null && _allBindingList.Count > 0;
                return _allList != null && _allList.Count > 0;
            }
        }
        //所有列表
        private List<HydroJunctionViewModel> _allList = null;
        //所有绑定列表
        private List<HydroJunctionViewModel> _allBindingList = null;
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(HydroModelInfo hydroInfo, List<HydroCalcuResult> allCalcuResultList)
        public void SetBindingData(Yw.Model.HydroModelInfo hydroInfo)
        {
            _allBindingList = new List<HydroJunctionViewModel>();
            _allList = new List<HydroJunctionViewModel>();
            if (hydroInfo != null && hydroInfo.Junctions != null && hydroInfo.Junctions.Count > 0)
            {
                foreach (var junction in hydroInfo.Junctions)
                {
                    var calcuResult = allCalcuResultList?.Find(x => x.Code == junction.Code);
                    var vm = new HydroJunctionViewModel(junction, hydroInfo);
                    vm.UpdateCalcuProperty(calcuResult);
                    _allBindingList.Add(vm);
                    _allList.Add(vm);
                }
            }
            Search();
        }
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(HydroModelInfo hydroInfo, List<HydroCalcuResult> allCalcuResultList)
        {
            _allList = new List<HydroJunctionViewModel>();
            if (hydroInfo != null && hydroInfo.Junctions != null && hydroInfo.Junctions.Count > 0)
            {
                foreach (var junction in hydroInfo.Junctions)
                {
                    var vm = new HydroJunctionViewModel(junction, hydroInfo);
                    var calcuResult = allCalcuResultList?.Find(x => x.Code == junction.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.hydroJunctionViewModelBindingSource.DataSource = _allBindingList;
            this.hydroJunctionViewModelBindingSource.ResetBindings(false);
            if (allCalcuResultList == null || allCalcuResultList.Count < 1)
            {
                SetNormalView();
            }
            else
            {
                SetCalcuView();
            }
        }
        //重置
        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)
            {
                XtraMessageBox.Show("无可设置连接节点数据");
                return;
            }
            var dlg = new SetHydroJunctionDlg();
            dlg.SetBindingData(_allBindingList.Select(x => x.Vmo).ToList());
            dlg.ReloadDataEvent += (list) =>
            {
                _allBindingList.ForEach(x =>
                {
                    x.Elev = x.Vmo.Elev;
                    x.MinorLoss = x.Vmo.MinorLoss;
                    x.Demand = x.Vmo.Demand;
                });
                this.hydroJunctionViewModelBindingSource.ResetBindings(false);
                var allParterList = _allBindingList.Select(x => x.Vmo as HydroParterInfo).ToList();
                this.HydroChangedEvent?.Invoke(allParterList);
            };
            dlg.ShowDialog();
        }
        /// <summary>
        /// 设置简单显示模式
        /// </summary>
        public void SetSimpleView()
        {
            this.groupForHead.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
            this.colDbLocked.Visible = true;
            this.colName.Visible = true;
            this.colCode.Visible = true;
@@ -86,8 +170,9 @@
            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>
@@ -95,6 +180,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;
@@ -106,8 +192,9 @@
            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>
@@ -115,6 +202,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;
@@ -126,37 +214,73 @@
            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;
        }
        //行点击事件
        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        /// <summary>
        /// 设置批量设置模式
        /// </summary>
        public void SetBulkSetView()
        {
            this.groupForHead.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
            this.colDbLocked.Visible = true;
            this.colName.Visible = true;
            this.colCode.Visible = true;
            this.colModelType.Visible = true;
            this.colElev.Visible = true;
            this.colMinorLoss.Visible = true;
            this.colDemand.Visible = true;
            this.colCalcuPress.Visible = true;
            this.colCalcuHead.Visible = true;
            this.colCalcuDemand.Visible = true;
            this.colHasDb.Visible = true;
            this.colFlags.Visible = true;
            this.colDescription.Visible = true;
            this.colSet.Visible = true;
        }
        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 HydroJunctionViewModel;
            if (row == null)
            {
                return;
            }
            if (e.Clicks > 1)
            if (e.Column == this.colSet)
            {
                var dlg = new HydroJunctionBulkSetDlg();
                var dlg = new SetHydroJunctionDlg();
                dlg.SetBindingData(row.Vmo);
                dlg.ReloadDataEvent += (list) =>
                {
                    row.Elev = Math.Round(row.Vmo.Elev, 4);
                    row.MinorLoss = row.Vmo.MinorLoss;
                    row.Demand = row.Vmo.Demand;
                    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);
            }
        }
    }
}