Shuxia Ning
2024-12-17 33b5627e2d1092f6931165b7f9f1a16de65d765d
WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/04-scheme/00-core/CreateXhsSchemeDlg.cs
@@ -1,5 +1,5 @@
using DevExpress.XtraLayout.Utils;
using HStation.WinFrmUI.Xhs.Core.Properties;
using Mapster;
namespace HStation.WinFrmUI
{
@@ -9,14 +9,14 @@
        {
            InitializeComponent();
            this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
        }
        private readonly CreateXhsSchemeViewModel _vm = new();
        private CreateXhsSchemeManager _wizard;
        private CreateXhsSchemeManager _wizard=null;
        private bool _initial_wizard_manager = false;//运行下一步
        private List<string> _change_type_list = null;
        /// <summary>
        ///
        /// </summary>
@@ -24,7 +24,38 @@
        {
            get { return _vm; }
        }
        /// <summary>
        ///
        /// </summary>
        public int SelectedPageIndex
        {
            get
            {
                return this.navigationFrameMain.SelectedPageIndex;
            }
            set
            {
                if (value == 0)
                {
                    _initial_wizard_manager = false;
                    InitialButtonStatus(_change_type_list);
                }
                else
                {
                    _initial_wizard_manager = true;
                    InitialWizardManager(_change_type_list);
                }
                this.navigationFrameMain.SelectedPageIndex = value;
            }
        }
        /// <summary>
        ///
        /// </summary>
        public event Action<HStation.Vmo.XhsSchemeVmo> ReloadDataEvent;
        /// <summary>
        ///
@@ -36,82 +67,143 @@
                Yw.Model.HydroModelInfo hydro_info
            )
        {
            this.itemForNext.Visibility = LayoutVisibility.Never;
            this.itemForPrev.Visibility = LayoutVisibility.Never;
            this.itemForComplete.Visibility = LayoutVisibility.Always;
            this.itemForCancel.Visibility = LayoutVisibility.Always;
            if (project == null)
            {
                return;
            }
            _vm.Project = project;
            _vm.ProjectSite = project_site;
            _vm.HydroInfo = hydro_info;
            _vm.HydroInfo = hydro_info.Adapt<Yw.Model.HydroModelInfo>();
            _vm.ProjectSite ??= await BLLFactory<HStation.BLL.XhsProjectSite>.Instance.GetDefaultByProjectID(_vm.Project.ID);
            if (_vm.HydroInfo == null)
            {
                var hydroRelation = await BLLFactory<Yw.BLL.HydroModelRelation>.Instance
                    .GetDefaultByObjectTypeAndObjectIDOfPurpose(HStation.Xhs.DataType.XhsProjectSite, _vm.ProjectSite.ID, HStation.Xhs.Purpose.Simulation);
                _vm.HydroInfo = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.GetByID(hydroRelation.ModelID);
            }
            _vm.AllSchemeList = await BLLFactory < HStation.BLL.XhsScheme>.Instance.GetBySiteID(_vm.ProjectSite.ID);
            }
            _vm.AllSchemeList = await BLLFactory<HStation.BLL.XhsScheme>.Instance.GetBySiteID(_vm.ProjectSite.ID);
            this.createXhsSchemeInfoPage1.InitialPage(_vm);
            this.createXhsSchemeInfoPage1.ChangeTypeChangedEvent += (List<string> change_type_list) =>
            {
                _initial_wizard_manager = false;
                _change_type_list = change_type_list;
                InitialButtonStatus(change_type_list);
            };
            _wizard = new CreateXhsSchemeManager(_vm);
            _wizard.SelectedPageChangedEvent += _wizard_SelectedPageChangedEvent;
            _wizard.SelectedPageStateChangedEvent += _wizard_SelectedPageStateChangedEvent; ;
            _wizard.InitialManager(new IWizardPage<CreateXhsSchemeViewModel>[] {
                this.createXhsSchemeInfoPage1,
                this.createXhsSchemePumpChangePage1,
            });
            this.createXhsSchemeInfoPage1.ChangeTypeChangedEvent += CreateXhsSchemeInfoPage1_ChangeTypeChangedEvent;
            this.FormClosing += (s, e) =>
            {
                if (_wizard != null)
                {
                    if (this.DialogResult == DialogResult.OK)
                    {
                        if (!_wizard.Complete())
                        {
                            e.Cancel = true;
                        }
                    }
                    else if (this.DialogResult == DialogResult.Cancel)
                    {
                        //if (!_wizard.Cancel())
                        //{
                        //    e.Cancel = true;
                        //}
                    }
                    else
                    {
                        e.Cancel = true;
                    }
                }
            };
        }
        //添加步骤项
        private void AddStepProgressBarItem(string caption)
        {
            this.stepProgressBar1.BeginInit();
            var item = new StepProgressBarItem();
            item.ContentBlock2.Caption = caption;
            item.Options.Indicator.ActiveStateDrawMode = IndicatorDrawMode.Full;
            item.Options.Indicator.ActiveStateImageOptions.SvgImage = null;
            item.Options.Indicator.InactiveStateImageOptions.SvgImage = null;
            item.State = StepProgressBarItemState.Inactive;
            this.stepProgressBar1.Items.Add(item);
            this.stepProgressBar1.EndInit();
        }
        //变更类型变换
        private void CreateXhsSchemeInfoPage1_ChangeTypeChangedEvent(List<string> change_type_list)
        //初始化按钮状态
        private void InitialButtonStatus(List<string> change_type_list)
        {
            for (int i = this.stepProgressBar1.Items.Count; i > 0; i--)
            {
                if (this.stepProgressBar1.Items.Count < 2)
                    break;
                this.stepProgressBar1.Items.RemoveAt(1);
            }
            if (change_type_list == null || !change_type_list.Any())
            {
                this.itemForNext.Visibility = LayoutVisibility.Never;
                this.itemForComplete.Visibility = LayoutVisibility.Always;
            }
            else
            {
                foreach (var change_type in change_type_list)
                {
                    var name = HydroParterCatalogHelper.GetName(change_type);
                    Add(name);
                }
                Add("变更记录");
                this.itemForPrev.Visibility = LayoutVisibility.Never;
                this.itemForNext.Visibility = LayoutVisibility.Always;
                this.itemForComplete.Visibility = LayoutVisibility.Never;
                this.itemForCancel.Visibility = LayoutVisibility.Always;
            }
            //
        }
        private void Add(string caption)
        //初始化步骤管理器
        private void InitialWizardManager(List<string> change_type_list)
        {
            var step_pb_item = new StepProgressBarItem();
            step_pb_item.ContentBlock2.Caption = caption;
            //step_pb_item.Name = "stepPbBasicInfo";
            step_pb_item.Options.Indicator.ActiveStateDrawMode = IndicatorDrawMode.Full;
            step_pb_item.Options.Indicator.ActiveStateImageOptions.SvgImage = null;
            step_pb_item.Options.Indicator.InactiveStateImageOptions.SvgImage = null;
            step_pb_item.State = StepProgressBarItemState.Inactive;
            this.stepProgressBar1.Items.Add(step_pb_item);
            if (change_type_list == null || !change_type_list.Any())
                return;
            var overlay = this.ShowOverlay();
            this.stepProgressBar1.Items.Clear();
            this.navigationFrameStep.Pages.Clear();
            var page_list = new List<IWizardPage<CreateXhsSchemeViewModel>>();
            if (change_type_list.Contains(Yw.Hydro.ParterCatalog.Pipe))
            {
                var caption = HydroParterCatalogHelper.GetName(Yw.Hydro.ParterCatalog.Pipe);
                AddStepProgressBarItem(caption);
                page_list.Add(new CreateXhsSchemePipeChangePage());
            }
            if (change_type_list.Contains(Yw.Hydro.ParterCatalog.Pump))
            {
                var caption = HydroParterCatalogHelper.GetName(Yw.Hydro.ParterCatalog.Pump);
                AddStepProgressBarItem(caption);
                page_list.Add(new CreateXhsSchemePumpChangePage());
            }
            if (change_type_list.Contains(Yw.Hydro.ParterCatalog.Valve))
            {
                var caption = HydroParterCatalogHelper.GetName(Yw.Hydro.ParterCatalog.Valve);
                AddStepProgressBarItem(caption);
                page_list.Add(new CreateXhsSchemeValveChangePage());
            }
            AddStepProgressBarItem("变更记录");
            page_list.Add(new CreateXhsSchemeChangeRecordPage());
            foreach (var item in page_list)
            {
                var ctrl = item as XtraUserControl;
                ctrl.Dock = DockStyle.Fill;
                this.navigationFrameStep.AddPage(ctrl);
            }
            _wizard = new CreateXhsSchemeManager(_vm);
            _wizard.SelectedPageChangedEvent += _wizard_SelectedPageChangedEvent;
            _wizard.SelectedPageStateChangedEvent += _wizard_SelectedPageStateChangedEvent;
            _wizard.InitialManager(page_list.ToArray());
            overlay.Close();
        }
        //选择页面改变
        private void _wizard_SelectedPageChangedEvent(IWizardPage<CreateXhsSchemeViewModel> page, int index)
        {
            this.itemForPrev.Visibility = page.AllowPrev ? LayoutVisibility.Always : LayoutVisibility.Never;
            this.itemForNext.Visibility = page.AllowNext ? LayoutVisibility.Always : LayoutVisibility.Never;
            this.itemForCancel.Visibility = page.AllowCancel ? LayoutVisibility.Always : LayoutVisibility.Never;
            this.itemForComplete.Visibility = page.AllowComplete ? LayoutVisibility.Always : LayoutVisibility.Never;
            this.navigationFrame1.SelectedPageIndex = index;
            this.itemForComplete.Visibility = page.AllowComplete ? LayoutVisibility.Always : LayoutVisibility.Never;
            this.navigationFrameStep.SelectedPageIndex = index;
            this.stepProgressBar1.SelectedItemIndex = index;
        }
@@ -129,17 +221,35 @@
        {
            if (_wizard != null)
            {
                _wizard.Prev();
                if (_wizard.SelectedIndex == 0)
                {
                    this.SelectedPageIndex = 0;
                }
                else
                {
                    _wizard.Prev();
                }
            }
        }
        //下一步
        private void btnNext_Click(object sender, EventArgs e)
        {
            if (_wizard != null)
            if (!_initial_wizard_manager)
            {
                _wizard.Next();
                if (this.createXhsSchemeInfoPage1.CanNext())
                {
                    this.SelectedPageIndex = 1;
                }
            }
            else
            {
                if (_wizard != null)
                {
                    _wizard.Next();
                }
            }
        }
        //取消
@@ -154,49 +264,37 @@
                    this.Close();
                }
            }
        }
        //完成
        private void btnComplete_Click(object sender, EventArgs e)
        {
            if (_wizard != null)
            if (this.SelectedPageIndex == 0)
            {
                var bol = _wizard.Complete();
                if (bol)
                if (this.createXhsSchemeInfoPage1.CanComplete())
                {
                    this.ReloadDataEvent?.Invoke(_vm.Scheme);
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
        }
        //正在关闭
        private void CreateXhsSchemeDlg_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (_wizard != null)
            else
            {
                if (this.DialogResult == DialogResult.OK)
                if (_wizard != null)
                {
                    /*  if (!_wizard.Complete())
                      {
                          e.Cancel = true;
                      }*/
                }
                else if (this.DialogResult == DialogResult.Cancel)
                {
                    if (!_wizard.Cancel())
                    var bol = _wizard.Complete();
                    if (bol)
                    {
                        e.Cancel = true;
                        this.ReloadDataEvent?.Invoke(_vm.Scheme);
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                }
                else
                {
                    e.Cancel = true;
                }
            }
        }
    }
}