using DevExpress.XtraEditors; using System; using System.Collections.Generic; using System.Windows.Forms; namespace IStation.WinFrmUI.Basic { public partial class PumpCurveMgrCtrl : XtraUserControl { public PumpCurveMgrCtrl() { InitializeComponent(); this.chartFeatCurveViewCtrl1.IsDispCurvePoint = false; this.pumpCurveMappingListCtrl1.FocusedChangedEvent += PumpCurveMappingListCtrl1_FocusedChangedEvent; } private Model.PumpCurveMapping _pumpCurveMapping = null; private Model.PumpCurve _pumpCurve = null; private List _allPumpCurveList = null; /// /// 初始化数据 /// public void SetBindingData() { _pumpCurve = null; _allPumpCurveList = new BLL.PumpCurve().GetAll(); this.pumpCurveMappingListCtrl1.SetBindingData(); } //曲线变换列表 private void PumpCurveMappingListCtrl1_FocusedChangedEvent(Model.PumpCurveMapping obj) { _pumpCurveMapping = obj; _pumpCurve = null; this.chartFeatCurveViewCtrl1.ClearData(); if (_allPumpCurveList != null && _pumpCurveMapping != null) { _pumpCurve = _allPumpCurveList?.Find(x => x.ID == obj?.CurveID); } if (_pumpCurve == null) return; SetBindingData(_pumpCurve); } //绑定数据 private void SetBindingData(Model.PumpCurve pumpCurve) { if (pumpCurve == null || pumpCurve.CurveInfo == null) return; if (pumpCurve.CurveInfo.CurveQH == null) return; var curveInfo = pumpCurve.CurveInfo; this.chartFeatCurveViewCtrl1.SetCurveInfo(curveInfo.CurveQH, curveInfo.CurveQE, curveInfo.CurveQP); this.chartFeatCurveViewCtrl1.SetPointInfo(pumpCurve.PointInfo); this.chartFeatCurveViewCtrl1.UpdateChart(true); this.chartFeatCurveViewCtrl1.SetWorkPointQ_Auto(); } /// /// 通过Excel导入曲线 /// public void ImportCurveByExcel() { WaitFrmHelper.ShowWaitForm(); var dlg = new ImportCurveByExcelDlg(); dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); }; dlg.SetBindingData(); dlg.ReloadDataEvent += (rhs, pumpId) => { var model = new Model.PumpCurve(rhs); model.CreateTime = DateTime.Now; var pumpCurveId = new BLL.PumpCurve().Insert(model); if (pumpCurveId > 0) { model.ID = pumpCurveId; var pumpCurveMapping = new Model.PumpCurveMapping(); pumpCurveMapping.PumpID = pumpId; pumpCurveMapping.CurveID = pumpCurveId; pumpCurveMapping.OtherName = model.CurveCode; pumpCurveMapping.SortCode = 1; pumpCurveMapping.IsWorking = false; var pumpCurveMappingId = new BLL.PumpCurveMapping().Insert(pumpCurveMapping); if (pumpCurveMappingId < 1) { var result = new BLL.PumpCurve().DeleteByID(pumpCurveId, out string msg); return false; } pumpCurveMapping.ID = pumpCurveMappingId; _allPumpCurveList.Add(model); this.pumpCurveMappingListCtrl1.AddPumpCurveMapping(pumpCurveMapping); } return true; }; dlg.ShowDialog(); } /// /// 通过 Express 导入曲线 /// public void ImportCurveByExpress() { WaitFrmHelper.ShowWaitForm(); var dlg = new ImportCurveByFeatCurveExpressGroupDlg(); dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); }; dlg.SetBindingData(); dlg.ReloadDataEvent += (rhs, pumpId) => { var model = new Model.PumpCurve(rhs); model.CreateTime = DateTime.Now; var pumpCurveId = new BLL.PumpCurve().Insert(model); if (pumpCurveId > 0) { model.ID = pumpCurveId; var pumpCurveMapping = new Model.PumpCurveMapping(); pumpCurveMapping.PumpID = pumpId; pumpCurveMapping.CurveID = pumpCurveId; pumpCurveMapping.OtherName = model.CurveCode; pumpCurveMapping.SortCode = 1; pumpCurveMapping.IsWorking = false; var pumpCurveMappingId = new BLL.PumpCurveMapping().Insert(pumpCurveMapping); if (pumpCurveMappingId < 1) { var result = new BLL.PumpCurve().DeleteByID(pumpCurveId, out string msg); return false; } pumpCurveMapping.ID = pumpCurveMappingId; _allPumpCurveList.Add(model); this.pumpCurveMappingListCtrl1.AddPumpCurveMapping(pumpCurveMapping); } return true; }; dlg.ShowDialog(); } public void DispCurveDefintPoins(bool isShow) { this.chartFeatCurveViewCtrl1.IsDispCurvePoint = isShow; this.chartFeatCurveViewCtrl1.UpdatePoint(); } //设置工作曲线 public void SetWorkPumpCurve() { if (_pumpCurveMapping == null) return; if (XtraMessageBox.Show("是否设置为工作曲线?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) != DialogResult.Yes) return; var result = new BLL.PumpCurveMapping().UpdateWokrCurve(_pumpCurveMapping.ID); if (result) { _pumpCurveMapping.IsWorking = true; this.pumpCurveMappingListCtrl1.UpdateWorkingCurve(); } } //删除曲线 public void DeleteCurve() { if (_pumpCurve == null) return; if (XtraMessageBox.Show("是否删除曲线?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) != DialogResult.Yes) return; var result = new BLL.PumpCurve().DeleteByID(_pumpCurve.ID, out string msg); if (!result) { XtraMessageBox.Show("删除失败!"); return; } _allPumpCurveList.Remove(_pumpCurve); this.pumpCurveMappingListCtrl1.DeletePumpMapping(_pumpCurveMapping.ID); } /// /// 修改泵曲线信息 /// public void EditPumpCurveInfo() { if (_pumpCurve == null) return; WaitFrmHelper.ShowWaitForm(); var dlg = new EditPumpCurveInfoDlg(); dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); }; dlg.SetBindingData(_pumpCurve); dlg.ReloadDataEvent += (rhs) => { rhs.UpdateTime = DateTime.Now; var result = new BLL.PumpCurve().Update(rhs); if (result) { _pumpCurve.Reset(rhs); SetBindingData(_pumpCurve); } return result; }; dlg.ShowDialog(); } /// /// 修改泵曲线名称 /// public void EditPumpCurveOtherName() { if (_pumpCurveMapping == null) return; WaitFrmHelper.ShowWaitForm(); var dlg = new EditOtherNameDlg(); dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); }; dlg.SetBindingData(_pumpCurveMapping.OtherName); dlg.ReloadDataEvent += (rhs) => { var model = new Model.PumpCurveMapping(_pumpCurveMapping); model.OtherName = rhs; var result = new BLL.PumpCurveMapping().Update(model); if (result) { _pumpCurveMapping.Reset(model); this.pumpCurveMappingListCtrl1.UpdateOtherName(rhs); } return result; }; dlg.ShowDialog(); } //刷新 public void Reload() { } } }