lixiaojun
2024-11-09 c9585ab171fb973d16792d7a290994bf8279da63
WinFrmUI/Yw.WinFrmUI.Hydro.Core/06-visual/15-translation/HydroTranslationListCtrl.cs
copy from WinFrmUI/Yw.WinFrmUI.Hydro.Core/06-parter/14-pipe/HydroPipeListCtrl.cs copy to WinFrmUI/Yw.WinFrmUI.Hydro.Core/06-visual/15-translation/HydroTranslationListCtrl.cs
Îļþ´Ó WinFrmUI/Yw.WinFrmUI.Hydro.Core/06-parter/14-pipe/HydroPipeListCtrl.cs ¸´ÖÆ
@@ -1,11 +1,10 @@
using DevExpress.XtraEditors;
using Yw.Model;
using Yw.Model;
namespace Yw.WinFrmUI
{
    public partial class HydroPipeListCtrl : DevExpress.XtraEditors.XtraUserControl, IHydroParterList
    public partial class HydroTranslationListCtrl : DevExpress.XtraEditors.XtraUserControl, IHydroVisualList
    {
        public HydroPipeListCtrl()
        public HydroTranslationListCtrl()
        {
            InitializeComponent();
            this.gridView1.SetNormalView(30);
@@ -17,11 +16,19 @@
        /// <summary>
        /// æ°´åŠ›ç‚¹å‡»äº‹ä»¶
        /// </summary>
        public event Action<Yw.Model.HydroParterInfo> HydroClickEvent;
        public event Action<Yw.Model.HydroVisualInfo> HydroClickInfoEvent;
        /// <summary>
        /// æ°´åŠ›ç‚¹å‡»è§†å›¾äº‹ä»¶
        /// </summary>
        public event Action<HydroVisualViewModel> HydroClickViewEvent;
        /// <summary>
        /// æ°´åŠ›æ”¹å˜äº‹ä»¶
        /// </summary>
        public event Action<List<HydroParterInfo>> HydroChangedEvent;
        public event Action<List<Yw.Model.HydroVisualInfo>> HydroChangedInfoEvent;
        /// <summary>
        /// æ°´åŠ›æ”¹å˜è§†å›¾äº‹ä»¶
        /// </summary>
        public event Action<List<HydroVisualViewModel>> HydroChangedViewEvent;
        /// <summary>
        /// æ˜¾ç¤ºæŸ¥è¯¢é¢æ¿
@@ -36,7 +43,7 @@
        }
        /// <summary>
        /// æ˜¯å¦æ‹¥æœ‰æ°´åˆ©åˆ—表
        /// æ˜¯å¦æ‹¥æœ‰æ°´åŠ›åˆ—è¡¨
        /// </summary>
        public bool HasHydroList
        {
@@ -44,21 +51,21 @@
        }
        //所有列表
        private List<HydroPipeViewModel> _allList = null;
        private List<HydroTranslationViewModel> _allList = null;
        //所有绑定列表
        private List<HydroPipeViewModel> _allBindingList = null;
        private List<HydroTranslationViewModel> _allBindingList = null;
        /// <summary>
        /// ç»‘定数据
        /// </summary>
        public void SetBindingData(HydroModelInfo hydroInfo)
        public void SetBindingData(Yw.Model.HydroModelInfo hydroInfo)
        {
            _allList = new List<HydroPipeViewModel>();
            if (hydroInfo != null && hydroInfo.Pipes != null && hydroInfo.Pipes.Count > 0)
            _allList = new List<HydroTranslationViewModel>();
            if (hydroInfo != null && hydroInfo.Translations != null && hydroInfo.Translations.Count > 0)
            {
                foreach (var pipe in hydroInfo.Pipes)
                foreach (var visual in hydroInfo.Translations)
                {
                    var vm = new HydroPipeViewModel(pipe, hydroInfo);
                    var vm = new HydroTranslationViewModel(visual, hydroInfo);
                    _allList.Add(vm);
                }
            }
@@ -70,13 +77,13 @@
        /// </summary>
        public void SetBindingData(Yw.Model.HydroModelInfo hydroInfo, List<HydroCalcuResult> allCalcuResultList)
        {
            _allList = new List<HydroPipeViewModel>();
            if (hydroInfo != null && hydroInfo.Pipes != null && hydroInfo.Pipes.Count > 0)
            _allList = new List<HydroTranslationViewModel>();
            if (hydroInfo != null && hydroInfo.Translations != null && hydroInfo.Translations.Count > 0)
            {
                foreach (var pipe in hydroInfo.Pipes)
                foreach (var visual in hydroInfo.Translations)
                {
                    var vm = new HydroPipeViewModel(pipe, hydroInfo);
                    var calcuResult = allCalcuResultList?.Find(x => x.Code == pipe.Code);
                    var vm = new HydroTranslationViewModel(visual, hydroInfo);
                    var calcuResult = allCalcuResultList?.Find(x => x.Code == visual.Code);
                    if (calcuResult != null)
                    {
                        vm.UpdateCalcuProperty(calcuResult);
@@ -85,6 +92,30 @@
                }
            }
            Search();
        }
        /// <summary>
        /// ç»‘定数据
        /// </summary>
        public void SetBindingData(List<HydroVisualViewModel> allVisualViewModelList)
        {
            _allList = new List<HydroTranslationViewModel>();
            allVisualViewModelList?.ForEach(x =>
            {
                if (x.Catalog == HydroParterCatalogHelper.GetName(Yw.Hydro.ParterCatalog.Translation))
                {
                    _allList.Add(x as HydroTranslationViewModel);
                }
            });
            Search();
        }
        /// <summary>
        /// æ›´æ–°ç»‘定
        /// </summary>
        public void UpdateBindingData()
        {
            this.hydroTranslationViewModelBindingSource.ResetBindings(false);
        }
        /// <summary>
@@ -97,45 +128,45 @@
                return;
            }
            _allList.ForEach(x => x.UpdateProperty());
            this.hydroPipeViewModelBindingSource.ResetBindings(false);
            this.hydroTranslationViewModelBindingSource.ResetBindings(false);
        }
        /// <summary>
        /// æ›´æ–°å±žæ€§
        /// </summary>
        public void UpdateProperty(Yw.Model.HydroParterInfo parter)
        public void UpdateProperty(Yw.Model.HydroVisualInfo visual)
        {
            if (_allList == null || _allList.Count < 1)
            {
                return;
            }
            if (parter == null)
            if (visual == null)
            {
                return;
            }
            var vm = _allList.Find(x => x.Code == parter.Code);
            var vm = _allList.Find(x => x.Code == visual.Code);
            if (vm == null)
            {
                return;
            }
            vm.UpdateProperty();
            this.hydroPipeViewModelBindingSource.ResetBindings(false);
            this.hydroTranslationViewModelBindingSource.ResetBindings(false);
        }
        /// <summary>
        /// æ›´æ–°å±žæ€§
        /// </summary>
        public void UpdateProperty(List<Yw.Model.HydroParterInfo> parterList)
        public void UpdateProperty(List<Yw.Model.HydroVisualInfo> visualList)
        {
            if (_allList == null || _allList.Count < 1)
            {
                return;
            }
            if (parterList == null || parterList.Count < 1)
            if (visualList == null || visualList.Count < 1)
            {
                return;
            }
            parterList.ForEach(x =>
            visualList.ForEach(x =>
            {
                var vm = _allList.Find(t => x.Code == x.Code);
                if (vm != null)
@@ -143,7 +174,7 @@
                    vm.UpdateProperty();
                }
            });
            this.hydroPipeViewModelBindingSource.ResetBindings(false);
            this.hydroTranslationViewModelBindingSource.ResetBindings(false);
        }
        /// <summary>
@@ -155,15 +186,15 @@
            {
                if (_allList != null && _allList.Count > 0)
                {
                    foreach (var parter in _allList)
                    foreach (var visual in _allList)
                    {
                        var calcuResult = allCalcuResultList.Find(x => x.Code == parter.Code);
                        var calcuResult = allCalcuResultList.Find(x => x.Code == visual.Code);
                        if (calcuResult != null)
                        {
                            parter.UpdateCalcuProperty(calcuResult);
                            visual.UpdateCalcuProperty(calcuResult);
                        }
                    }
                    this.hydroPipeViewModelBindingSource.ResetBindings(false);
                    this.hydroTranslationViewModelBindingSource.ResetBindings(false);
                }
            }
        }
@@ -191,8 +222,8 @@
            {
                _allBindingList = _allBindingList.Where(x => !string.IsNullOrEmpty(x.ModelType) && x.ModelType.Contains(modelType)).ToList();
            }
            this.hydroPipeViewModelBindingSource.DataSource = _allBindingList;
            this.hydroPipeViewModelBindingSource.ResetBindings(false);
            this.hydroTranslationViewModelBindingSource.DataSource = _allBindingList;
            this.hydroTranslationViewModelBindingSource.ResetBindings(false);
        }
        //重置
@@ -210,23 +241,69 @@
            Search();
            if (_allBindingList == null || _allBindingList.Count < 1)
            {
                XtraMessageBox.Show("无可设置管道数据");
                TipFormHelper.ShowWarn("无数据!");
                return;
            }
            var dlg = new SetHydroPipeDlg();
            var dlg = new SetHydroTranslationDlg();
            dlg.SetBindingData(_allBindingList.Select(x => x.Vmo).ToList());
            dlg.ReloadDataEvent += (list) =>
            {
                _allBindingList.ForEach(x =>
                {
                    x.UpdateProperty();
                });
                this.hydroPipeViewModelBindingSource.ResetBindings(false);
                var allParterList = _allBindingList.Select(x => x.Vmo as HydroParterInfo).ToList();
                this.HydroChangedEvent?.Invoke(allParterList);
                _allBindingList.ForEach(x => x.UpdateProperty());
                this.hydroTranslationViewModelBindingSource.ResetBindings(false);
                var allVisualViewModelList = _allBindingList.Select(x => x as HydroVisualViewModel).ToList();
                this.HydroChangedViewEvent?.Invoke(allVisualViewModelList);
                var allVisualInfoList = allVisualViewModelList.Select(x => x.Vmo).ToList();
                this.HydroChangedInfoEvent?.Invoke(allVisualInfoList);
            };
            dlg.ShowDialog();
        }
        //查询
        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 HydroTranslationViewModel;
            if (row == null)
            {
                return;
            }
            if (e.Column == this.colSet)
            {
                var dlg = new SetHydroTranslationDlg();
                dlg.SetBindingData(row.Vmo);
                dlg.ReloadDataEvent += (list) =>
                {
                    row.UpdateProperty();
                    this.gridView1.RefreshRow(e.RowHandle);
                    this.HydroChangedViewEvent?.Invoke(new List<HydroVisualViewModel>() { row });
                    this.HydroChangedInfoEvent?.Invoke(new List<HydroVisualInfo>() { row.Vmo });
                };
                dlg.ShowDialog();
            }
            else
            {
                this.HydroClickViewEvent?.Invoke(row);
                this.HydroClickInfoEvent?.Invoke(row.Vmo);
            }
        }
        /// <summary>
        /// è®¾ç½®ç®€å•显示模式
@@ -328,33 +405,6 @@
            this.colSet.Visible = true;
        }
        private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            var row = this.gridView1.GetRow(e.RowHandle) as HydroPipeViewModel;
            if (row == null)
            {
                return;
            }
            if (e.Column == this.colSet)
            {
                var dlg = new SetHydroPipeDlg();
                dlg.SetBindingData(row.Vmo);
                dlg.ReloadDataEvent += (list) =>
                {
                    row.UpdateProperty();
                    this.gridView1.RefreshRow(e.RowHandle);
                    this.HydroChangedEvent?.Invoke(new List<Model.HydroParterInfo>() { row.Vmo });
                };
                dlg.ShowDialog();
            }
            else
            {
                this.HydroClickEvent?.Invoke(row.Vmo);
            }
        }
        //初始化管段状态
        private void InitialLinkStatus()
        {
@@ -366,5 +416,6 @@
            this.imgCmbLinkStatus.Properties.EndUpdate();
        }
    }
}