using DevExpress.XtraEditors; using HStation.Vmo; using Yw; namespace HStation.WinFrmUI { public partial class AssetsExchangerCurveQLMgrPage : DocumentPage { public AssetsExchangerCurveQLMgrPage() { InitializeComponent(); this.PageTitle.Caption = "水头损失曲线"; this.PageTitle.HeaderSvgImage = AssetsMainSvgImageHelper.Curve; this.PageTitle.SvgImageSize = new Size(24, 24); this.phartDiagramRelationListCtrl1.SelectedChangedEvent += PhartDiagramRelationListCtrl1_SelectedChangedEvent; } private AssetsExchangerMainVmo _vmo = null; private List _allBindingList = null; private PhartDiagramRelationVmo _relation = null; /// /// /// public async void SetBindingData(AssetsExchangerMainVmo vmo) { if (vmo == null) { return; } _vmo = vmo; this.PageTitle.Caption = $"{vmo.Name}\r\n水头损失曲线"; _allBindingList = new List(); var allList = await BLLFactory.Instance .GetByObjectTypeAndObjectID(HStation.Assets.DataType.ExchangerMain, vmo.ID); allList?.ForEach(x => _allBindingList.Add(x)); this.phartDiagramRelationListCtrl1.SetBindingData(_allBindingList); } //excel private void Excel() { if (_vmo == null) { return; } var dlg = new ImportAssetsExchangerCurveQLByExcelDlg(); dlg.ReloadDataEvent += (rhs) => { _allBindingList.Add(rhs); this.phartDiagramRelationListCtrl1.SetBindingData(_allBindingList); }; dlg.SetBindingData(_vmo); dlg.ShowDialog(); } //图片 private void Picture() { if (_vmo == null) { return; } var vm = GetCurrentViewModel(); if (vm == null) { return; } var dlg = new ImportAssetsExchangerCurveQLByPictureDlg(); dlg.ReloadDataEvent += (rhs) => { _allBindingList.Add(rhs); this.phartDiagramRelationListCtrl1.SetBindingData(_allBindingList); }; dlg.SetBindingData(_vmo); dlg.ShowDialog(); } //基本信息 private void Info() { var vm = GetCurrentViewModel(); if (vm == null) { return; } var dlg = new EditPhartDiagramRelationDlg(); dlg.ReloadDataEvent += (rhs) => { var item = _allBindingList?.Find(x => x.ID == rhs.ID); if (item == null) { return; } item.Reset(rhs); this.phartDiagramRelationListCtrl1.SetBindingData(_allBindingList); }; dlg.SetBindingData(vm); dlg.ShowDialog(); } //曲线 private async void Curve() { var vm = GetCurrentViewModel(); if (vm == null) { return; } var vmo = await BLLFactory.Instance.GetByID(vm.DiagramID); var dlg = new EditAssetsExchangerCurveQLDlg(); dlg.ReloadDataEvent += (rhs) => { this.universalChartViewCtrl1.SetBindingData(rhs); }; dlg.SetBindingData(vmo); dlg.ShowDialog(); } //删除 private async void Delete() { var vm = GetCurrentViewModel(); if (vm == null) { return; } var result = XtraMessageBox.Show("请问确认删除当前数据吗?", "询问", MessageBoxButtons.YesNo) == DialogResult.Yes; if (!result) { return; } var bol = await BLLFactory.Instance.DeleteByID(vm.ID); if (!bol) { TipFormHelper.ShowError("删除失败!"); return; } _allBindingList.Remove(vm); this.universalChartViewCtrl1.ClearBindingData(); this.phartDiagramRelationListCtrl1.SetBindingData(_allBindingList); TipFormHelper.ShowSucceed("删除成功!"); } #region 当前 //获取当前 private PhartDiagramRelationVmo GetCurrentViewModel() { if (_allBindingList == null) { TipFormHelper.ShowError("数据初始化错误!"); return null; } if (_allBindingList.Count < 1) { TipFormHelper.ShowInfo("无数据!"); return null; } if (_relation == null) { TipFormHelper.ShowWarn("请选择数据行!"); return null; } return _relation; } #endregion 当前 //Excel导入 private void barBtnImportByExcel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { Excel(); } //图片导入 private void barBtnImportByPicture_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { Picture(); } //基本信息 private void barBtnInfo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { Info(); } //曲线 private void barBtnCurve_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { Curve(); } //删除 private void barBtnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { Delete(); } //选择改变 private void PhartDiagramRelationListCtrl1_SelectedChangedEvent(PhartDiagramRelationVmo obj) { _relation = obj; LoadPhart(_relation); } //加载图表 private async void LoadPhart(PhartDiagramRelationVmo relation) { if (relation == null) { this.universalChartViewCtrl1.SetBindingData(null); return; } var vmo = await BLLFactory.Instance.GetByID(relation.DiagramID); this.universalChartViewCtrl1.SetBindingData(vmo); } } }