duheng
2024-12-24 ef716332fef142a02843b5a99e8e3e92ab165738
WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/04-scheme/02-change/01-pump/CreateXhsSchemePumpChangePage.cs
@@ -1,12 +1,17 @@
namespace HStation.WinFrmUI
using DevExpress.Utils.Svg;
using Mapster;
using Yw;
namespace HStation.WinFrmUI
{
    public partial class CreateXhsSchemePumpChangePage : DevExpress.XtraEditors.XtraUserControl, Yw.WinFrmUI.IWizardPage<CreateXhsSchemeViewModel>
    {
        public CreateXhsSchemePumpChangePage()
        {
            InitializeComponent();
            InitialStatus();
            this.layoutView1.OptionsFilter.AllowFilterEditor = false;
            InitialLinkStatus();
            this.layoutView1.SetDefuaulView();
            this.layoutView1.SetFindPanel();
        }
        /// <summary>
@@ -18,8 +23,19 @@
        private bool _isInitialize = false;//是否初始化
        private HStation.Vmo.XhsProjectVmo _project = null;//项目
        private HStation.Vmo.XhsProjectSiteVmo _project_site = null;//项目站
        private Yw.Model.HydroModelInfo _hydro_info = null;//水力信息
        private HStation.Vmo.XhsProjectSiteVmo _project_site = null;//项目站
        private List<CreateXhsSchemePumpChangeViewMdoel> _vm_list = null;
        //初始化状态
        private void InitialLinkStatus()
        {
            this.repImgCmbStatus.BeginUpdate();
            this.repImgCmbStatus.Items.Clear();
            this.repImgCmbStatus.Items.Add("开启", "开启", -1);
            this.repImgCmbStatus.Items.Add("关闭", "关闭", -1);
            this.repImgCmbStatus.EndUpdate();
        }
        /// <summary>
        /// 初始化
@@ -34,21 +50,21 @@
            _isInitialize = true;
            _project = t.Project;
            _project_site = t.ProjectSite;
            _hydro_info = t.HydroInfo;
            if (t.HydroInfo.Pumps != null && t.HydroInfo.Pumps.Any())
            {
                var svg = SvgImage.FromStream(new MemoryStream(HStation.WinFrmUI.Xhs.Core.Properties.Resources.pump));
                _vm_list = new List<CreateXhsSchemePumpChangeViewMdoel>();
                foreach (var pump in t.HydroInfo.Pumps)
                {
                    var vm = new Yw.WinFrmUI.HydroPumpViewModel(pump, t.HydroInfo);
                    _vm_list.Add(new CreateXhsSchemePumpChangeViewMdoel(vm, svg));
                }
            }
            this.createXhsSchemePumpChangeViewMdoelBindingSource.DataSource = _hydro_info.Pumps;
            this.createXhsSchemePumpChangeViewMdoelBindingSource.DataSource = _vm_list;
            this.createXhsSchemePumpChangeViewMdoelBindingSource.ResetBindings(false);
            ShowBimfaceCtrl();
        }
        private void InitialStatus()
        {
            this.repImgCmbStatus.BeginUpdate();
            this.repImgCmbStatus.Items.Clear();
            this.repImgCmbStatus.Items.Add("开启", Yw.Hydro.PumpStatus.Open, -1);
            this.repImgCmbStatus.Items.Add("关闭", Yw.Hydro.PumpStatus.Closed, -1);
            this.repImgCmbStatus.EndUpdate();
        }
        #region Bimface
@@ -66,20 +82,12 @@
                _bimfaceCtrl = new SimulationBimfaceCtrl();
                _bimfaceCtrl.Dock = DockStyle.Fill;
                await _bimfaceCtrl.InitialData(_project, _project_site);
                _bimfaceCtrl.LoadCompletedEvent += () =>
                _bimfaceCtrl.HydroMouseLeftClickEvent += (code) =>
                {
                    //view加载完成事件
                    if (_hydro_info == null)
                    {
                    if (_vm_list == null || !_vm_list.Any())
                        return;
                    }
                };
                _bimfaceCtrl.HydroMouseLeftClickEvent += (obj) =>
                {//鼠标左键点击事件
                    if (_hydro_info == null)
                    {
                        return;
                    }
                    var index = _vm_list.FindIndex(x => x.ViewModel.Code == code);
                    this.layoutView1.FocusedRowHandle = index;
                };
            }
            return _bimfaceCtrl;
@@ -96,6 +104,69 @@
        #endregion
        //保存
        private bool Save()
        {
            if (!_isInitialize)
            {
                return false;
            }
            if (_vm_list == null || !_vm_list.Any())
            {
                return false;
            }
            _vm_list.ForEach(x => x.ViewModel.UpdateVmoProperty());
            _vm.HydroInfo.Pumps = _vm_list.Select(x => x.ViewModel.Vmo).ToList();
            return true;
        }
        //点击
        private async void layoutView1_CardClick(object sender, DevExpress.XtraGrid.Views.Layout.Events.CardClickEventArgs e)
        {
            var row = this.layoutView1.GetRow(e.RowHandle) as CreateXhsSchemePumpChangeViewMdoel;
            if (row == null)
                return;
            await _bimfaceCtrl?.ZoomAndSelectComponent(row.ViewModel.Code);
        }
        //选中列变换
        private void layoutView1_FocusedColumnChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedColumnChangedEventArgs e)
        {
            if (e.FocusedColumn == this.colModelType)
            {
                this.layoutView1.FocusedColumn = null;
                if (this.layoutView1.GetFocusedRow() is not CreateXhsSchemePumpChangeViewMdoel row)
                    return;
                var link_status = row.LinkStatus;
                var current_hz = row.CurrentHz;
                var input = Yw.WinFrmUI.HydroMatchingHelper.Create(row.ViewModel.Vmo, _vm.HydroInfo);
                var dlg = new SimulationPumpSingleMatchingDlg();
                dlg.SetBindingData(input);
                dlg.ReloadDataEvent += (output) =>
                {
                    Yw.WinFrmUI.HydroMatchingHelper.Apply(row.ViewModel, output);
                    row.LinkStatus = link_status;
                    row.CurrentHz = current_hz;
                    if (!_vm.ChangeRecordList.Exists(x => x.Code == row.ViewModel.Code))
                    {
                        _vm.ChangeRecordList.Add(new(Yw.Hydro.ParterCatalog.Pump, row.ViewModel.Code, row.Name, row.SvgImage));
                    }
                };
                dlg.ShowDialog();
            }
        }
        //单元格值变换
        private void layoutView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            if (this.layoutView1.GetRow(e.RowHandle) is not CreateXhsSchemePumpChangeViewMdoel row)
                return;
            if (!_vm.ChangeRecordList.Exists(x => x.Code == row.ViewModel.Code))
            {
                _vm.ChangeRecordList.Add(new(Yw.Hydro.ParterCatalog.Pump, row.ViewModel.Code, row.Name,row.SvgImage));
            }
        }
        /// <summary>
        /// 允许上一步
@@ -140,7 +211,7 @@
        /// </summary>
        public bool CanPrev()
        {
            return false;
            return true;
        }
        /// <summary>
@@ -152,8 +223,7 @@
            {
                return false;
            }
            return true;
            return Save();
        }
        /// <summary>
@@ -172,8 +242,6 @@
            return false;
        }
        private void layoutView1_CardClick(object sender, DevExpress.XtraGrid.Views.Layout.Events.CardClickEventArgs e)
        {
        }
    }
}