lixiaojun
2024-09-15 9c9a27924cbaac23e179bbd7aac0899563d19572
WinFrmUI/HStation.WinFrmUI.Xhs.Core/04-simulation/06-simulation/XhsProjectSimulationCorePage.cs
@@ -1,7 +1,4 @@
using Yw.EPAnet;
using HStation.Vmo;
using Yw.DAL.Basic;
global using Yw.EPAnet;
namespace HStation.WinFrmUI
{
    public partial class XhsProjectSimulationCorePage : DocumentPage
@@ -16,9 +13,12 @@
        private HStation.Vmo.XhsProjectVmo _project = null;//项目
        private HStation.Vmo.XhsProjectSiteVmo _projectSite = null;//项目站
        private Yw.Model.HydroModelInfo _hydroInfo = null;//水力信息
        private List<string> _showHideCodeList = null;//显隐编码列表
        private Yw.Model.HydroParterInfo _parter = null;
        private List<CalcuParter> _allCalcuParterList = null;
        private Yw.EPAnet.CheckResult _checkResult = null;
        private Yw.EPAnet.CalcuResult _calcuResult = null;
        /// <summary>
        /// 绑定数据
@@ -47,6 +47,7 @@
                    .GetDefaultByObjectTypeAndObjectIDOfPurpose(HStation.Xhs.DataType.XhsProjectSite, _projectSite.ID, HStation.Xhs.Purpose.Simulation);
                _hydroInfo = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.GetByID(hydroRelation.ModelID);
            }
            this.xhsProjectSimulationPropertyCtrl1.SetBindingData(_hydroInfo);
        }
        /// <summary>
@@ -63,147 +64,197 @@
            await this.xhsProjectSimulationBimfaceCtrl1.SetBindingData(_project, _projectSite);
        }
        #region 模型
        //一键显隐
        private void barBtnShowHide_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_hydroInfo == null)
            {
                return;
            }
            if (_showHideCodeList == null)
            {
            }
        }
        #endregion
        #region 水力
        //水力验证
        private void barBtnHydroCheck_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_hydroInfo == null)
            {
                return;
            }
            var netWork = Yw.Hydro.ParseHelper.ToNetwork(_hydroInfo);
            _checkResult = netWork.Check();
            if (_checkResult.Succeed)
            {
                TipFormHelper.ShowSucceed("校验通过!");
                return;
            }
            var dlg = new XhsProjectSimulationHydroCheckFailedDlg();
            dlg.TopMost = true;
            dlg.HydroClickEvent += async (code) =>
            {
                if (_hydroInfo == null)
                {
                    return;
                }
                await this.xhsProjectSimulationBimfaceCtrl1.SetSelectedComponents(new List<string>() { code });
                var allParterList = _hydroInfo.GetAllParters();
                _parter = allParterList.Find(x => x.Code == code);
                ShowProperty();
            };
            dlg.SetBindingData(_checkResult.FailedList);
            dlg.Show();
        }
        //水力计算
        private void barBtnHydroCalcu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_hydroInfo == null)
            {
                return;
            }
            var netWork = Yw.Hydro.ParseHelper.ToNetwork(_hydroInfo);
            _calcuResult = netWork.Calcu();
            if (_calcuResult.Succeed)
            {
                ShowProperty();
                TipFormHelper.ShowSucceed("计算成功!");
                return;
            }
            var dlg = new XhsProjectSimulationHydroCalcuFailedDlg();
            dlg.SetBindingData(_calcuResult.FailedList);
            dlg.ShowDialog();
        }
        //水力构件列表
        private void barBtnHydroParterList_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var dlg = new HydroParterListDlg();
            dlg.TopMost = true;
            dlg.HydroClickEvent += async (parter) =>
            {
                _parter = parter;
                await this.xhsProjectSimulationBimfaceCtrl1.SetSelectedComponents(new List<string>() { parter.Code });
                ShowProperty();
            };
            dlg.SetBindingData(_hydroInfo);
            dlg.Show();
        }
        //导出水力INP文件
        private void barBtnHydroExportInp_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_hydroInfo == null)
            {
                return;
            }
            var fileName = Yw.WinFrmUI.FileDialogHelper.SaveInp("导出Inp文件");
            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }
            var netWork = Yw.Hydro.ParseHelper.ToNetwork(_hydroInfo);
            var result = netWork.ToInpString();
            File.WriteAllText(fileName, result);
            TipFormHelper.ShowSucceed("导出成功");
        }
        //bimface 构件点击
        private void XhsProjectHydroQ3dCtrl1_ClickParterEvent(string objectId)
        private void xhsProjectSimulationBimfaceCtrl1_ClickParterEvent(string objectId)
        {
            //if (_hydro == null)
            //{
            //    _parter = null;
            //    return;
            //}
            //var allParterList = _hydro.GetAllParters();
            //_parter = allParterList.Find(x => x.Code == objectId);
            //this.xhsProjectSimulationPropertyCtrl1.SelectParter(_parter, allParterList);
            //if (_parter != null)
            //{
            //    if (_allCalcuParterList != null && _allCalcuParterList.Count > 0)
            //    {
            //        var calcuParter = _allCalcuParterList.Find(x => x.Id == _parter.Code);
            //        if (calcuParter != null)
            //        {
            //            IHydroCalcuProperty calcuProperty = null;
            //            if (calcuParter is CalcuNode calcuNode)
            //            {
            //                var calcuNodeProperty = new Yw.WinFrmUI.HydroCalcuNodeProperty();
            //                calcuNodeProperty.ID = _parter.ID;
            //                calcuNodeProperty.CalcuPress = calcuNode.Press;
            //                calcuNodeProperty.CalcuDemand = calcuNode.Demand;
            //                calcuNodeProperty.CalcuHead = calcuNode.Head;
            //                calcuProperty = calcuNodeProperty;
            //            }
            //            else if (calcuParter is CalcuLink calcuLink)
            //            {
            //                var calcuLinkProperty = new Yw.WinFrmUI.HydroCalcuLinkProperty();
            //                calcuLinkProperty.ID = _parter.ID;
            //                calcuLinkProperty.CalcuHeadLoss = calcuLink.Headloss;
            //                calcuLinkProperty.CalcuFlow = calcuLink.Flow;
            //                calcuLinkProperty.CalcuVelocity = calcuLink.Velocity;
            //                calcuProperty = calcuLinkProperty;
            //            }
            //            if (calcuProperty != null)
            //            {
            //                this.xhsProjectSimulationPropertyCtrl1.UpdateCalcuProperty(calcuProperty);
            //            }
            //        }
            //    }
            //}
            if (_hydroInfo == null)
            {
                return;
            }
            var allParterList = _hydroInfo.GetAllParters();
            _parter = allParterList.Find(x => x.Code == objectId);
            ShowProperty();
        }
        private void barBtnCheck_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        //显示属性
        private void ShowProperty()
        {
            //if (_hydro == null)
            //{
            //    return;
            //}
            //var netWork = Yw.Hydro.ParseHelper.ToNetwork(_hydro);
            //var result = netWork.Check();
            //XtraMessageBox.Show(JsonHelper.Object2FormatJson(result));
            if (_hydroInfo == null)
            {
                return;
            }
            if (_parter == null)
            {
                return;
            }
            var allParterList = _hydroInfo.GetAllParters();
            this.xhsProjectSimulationPropertyCtrl1.SelectParter(_parter, allParterList);
            if (_calcuResult != null)
            {
                if (_calcuResult.Succeed)
                {
                    var allCalcuParterList = _calcuResult.GetParterList();
                    var calcuParter = allCalcuParterList.Find(x => x.Id == _parter.Code);
                    if (calcuParter != null)
                    {
                        IHydroCalcuProperty calcuProperty = null;
                        if (calcuParter is Yw.EPAnet.CalcuNode calcuNode)
                        {
                            var calcuNodeProperty = new Yw.WinFrmUI.HydroCalcuNodeProperty();
                            calcuNodeProperty.ID = _parter.ID;
                            calcuNodeProperty.CalcuPress = calcuNode.Press;
                            calcuNodeProperty.CalcuDemand = calcuNode.Demand;
                            calcuNodeProperty.CalcuHead = calcuNode.Head;
                            calcuProperty = calcuNodeProperty;
                        }
                        else if (calcuParter is Yw.EPAnet.CalcuLink calcuLink)
                        {
                            var calcuLinkProperty = new Yw.WinFrmUI.HydroCalcuLinkProperty();
                            calcuLinkProperty.ID = _parter.ID;
                            calcuLinkProperty.CalcuHeadLoss = calcuLink.Headloss;
                            calcuLinkProperty.CalcuFlow = calcuLink.Flow;
                            calcuLinkProperty.CalcuVelocity = calcuLink.Velocity;
                            calcuProperty = calcuLinkProperty;
                        }
                        if (calcuProperty != null)
                        {
                            this.xhsProjectSimulationPropertyCtrl1.UpdateCalcuProperty(calcuProperty);
                        }
                    }
                }
            }
        }
        #endregion
        private void barBtnCalcu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //if (_hydro == null)
            //{
            //    return;
            //}
            //var netWork = Yw.Hydro.ParseHelper.ToNetwork(_hydro);
            //var result = netWork.Calcu();
            //if (!result.Succeed)
            //{
            //    XtraMessageBox.Show(JsonHelper.Object2FormatJson(result));
            //    return;
            //}
            //_allCalcuParterList = result.GetParterList();
            //TipFormHelper.ShowSucceed("计算成功");
            //if (_parter != null)
            //{
            //    var calcuParter = _allCalcuParterList.Find(x => x.Id == _parter.Code);
            //    if (calcuParter != null)
            //    {
            //        IHydroCalcuProperty calcuProperty = null;
            //        if (calcuParter is CalcuNode calcuNode)
            //        {
            //            var calcuNodeProperty = new Yw.WinFrmUI.HydroCalcuNodeProperty();
            //            calcuNodeProperty.ID = _parter.ID;
            //            calcuNodeProperty.CalcuPress = calcuNode.Press;
            //            calcuNodeProperty.CalcuDemand = calcuNode.Demand;
            //            calcuNodeProperty.CalcuHead = calcuNode.Head;
            //            calcuProperty = calcuNodeProperty;
            //        }
            //        else if (calcuParter is CalcuLink calcuLink)
            //        {
            //            var calcuLinkProperty = new Yw.WinFrmUI.HydroCalcuLinkProperty();
            //            calcuLinkProperty.ID = _parter.ID;
            //            calcuLinkProperty.CalcuHeadLoss = calcuLink.Headloss;
            //            calcuLinkProperty.CalcuFlow = calcuLink.Flow;
            //            calcuLinkProperty.CalcuVelocity = calcuLink.Velocity;
            //            calcuProperty = calcuLinkProperty;
            //        }
        #region 更多
            //        if (calcuProperty != null)
            //        {
            //            this.xhsProjectSimulationPropertyCtrl1.UpdateCalcuProperty(calcuProperty);
            //        }
            //    }
            //}
        }
        private void barBtnParter_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //var dlg = new HydroParterListDlg();
            //dlg.SetBindingData(_hydro);
            //dlg.Show();
        }
        private void barBtnInp_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //var fileName = Yw.WinFrmUI.FileDialogHelper.SaveInp("导出Inp文件");
            //if (string.IsNullOrEmpty(fileName))
            //{
            //    return;
            //}
            //var netWork = Yw.Hydro.ParseHelper.ToNetwork(_hydro);
            //var result = netWork.ToInpString();
            //File.WriteAllText(fileName, result);
            //TipFormHelper.ShowSucceed("导出成功");
        }
        //保存
        private async void barBtnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //if (_hydro == null)
            //{
            //    return;
            //}
            //var bll = new Yw.BLL.HydroModelInfo();
            //var result = await bll.Save(_hydro);
            //if (result > 0)
            //{
            //    Yw.WinFrmUI.TipFormHelper.ShowSucceed("保存成功");
            //}
            if (_hydroInfo == null)
            {
                return;
            }
            var id = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.Save(_hydroInfo);
            if (id < 1)
            {
                TipFormHelper.ShowError("保存失败!");
                return;
            }
            _hydroInfo = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.GetByID(id);
            TipFormHelper.ShowSucceed("保存成功!");
        }
        #endregion
    }
}