using DevExpress.Mvvm.Native; using DevExpress.XtraEditors.Repository; using DevExpress.XtraRichEdit.Design; using DevExpress.XtraSpreadsheet; using Yw.WinFrmUI.Hydro; namespace Yw.WinFrmUI { public partial class ApplyHydroGradingCtrl : DevExpress.XtraEditors.XtraUserControl { public ApplyHydroGradingCtrl() { InitializeComponent(); this.gridView1.SetNormalEditView(); this.colName.OptionsColumn.AllowEdit = false; this.gridView1.CustomRowCellEdit += GridView1_CustomRowCellEdit; } private Func _hydroInfoFunc; private BindingList _allBindingList = null; private List _allCalcuResultList = null; /// /// /// public void SetBindingData ( Func hydroInfoFunc, List allApplyList, List allCalcuList ) { _hydroInfoFunc = hydroInfoFunc; _allBindingList = new BindingList(); allApplyList?.ForEach(x => { _allBindingList.Add(x); }); _allCalcuResultList = allCalcuList; this.hydroGradingApplyViewModelBindingSource.DataSource = _allBindingList; this.hydroGradingApplyViewModelBindingSource.ResetBindings(false); } /// /// 获取结果列表 /// public async Task> GetResultList() { var hydroInfo = _hydroInfoFunc?.Invoke(); if (hydroInfo == null) { return default; } var allGradingList = await BLLFactory.Instance.GetByModelID(hydroInfo.ID); if (allGradingList == null || allGradingList.Count < 1) { return default; } var resultList = new List(); _allBindingList?.ToList().ForEach(x => { var allCatalogGradingList = allGradingList.Where(t => t.Catalog == x.Code).ToList(); if (allCatalogGradingList != null || allCatalogGradingList.Count > 0) { switch (x.Code) { case Yw.Hydro.ParterCatalog.Pump: { if (hydroInfo.Pumps != null && hydroInfo.Pumps.Count > 0) { foreach (var pump in hydroInfo.Pumps) { switch (x.PropName) { case Yw.Hydro.ParterProp.LinkStatus: { var gradingList = allCatalogGradingList.Where(x => x.PropName == Yw.Hydro.ParterProp.LinkStatus).OrderBy(t => t.SortCode).ToList(); if (gradingList != null && gradingList.Count > 0) { var grading = gradingList.Meet(pump.LinkStatus); if (grading != null) { var result = new HydroGradingApplyResultViewModel() { Code = pump.Code, Color = grading.Color }; resultList.Add(result); } } } break; case Yw.Hydro.ParterProp.CalcuFlow: { var gradingList = allCatalogGradingList.Where(x => x.PropName == Yw.Hydro.ParterProp.CalcuFlow).OrderBy(t => t.SortCode).ToList(); if (gradingList != null && gradingList.Count > 0) { var calcuResult = _allCalcuResultList?.Find(t => t.Code == pump.Code); if (calcuResult is HydroCalcuLinkResult calcuLinkResult) { if (calcuLinkResult.CalcuFlow.HasValue) { var grading = gradingList.Meet(Math.Abs(calcuLinkResult.CalcuFlow.Value)); if (grading != null) { var result = new HydroGradingApplyResultViewModel() { Code = pump.Code, Color = grading.Color }; resultList.Add(result); } } } } } break; case Yw.Hydro.ParterProp.CalcuVelocity: { var gradingList = allCatalogGradingList.Where(x => x.PropName == Yw.Hydro.ParterProp.CalcuVelocity).OrderBy(t => t.SortCode).ToList(); if (gradingList != null && gradingList.Count > 0) { var calcuResult = _allCalcuResultList?.Find(t => t.Code == pump.Code); if (calcuResult is HydroCalcuLinkResult calcuLinkResult) { if (calcuLinkResult.CalcuVelocity.HasValue) { var grading = gradingList.Meet(Math.Abs(calcuLinkResult.CalcuVelocity.Value)); if (grading != null) { var result = new HydroGradingApplyResultViewModel() { Code = pump.Code, Color = grading.Color }; resultList.Add(result); } } } } } break; case Yw.Hydro.ParterProp.CalcuHeadLoss: { var gradingList = allCatalogGradingList.Where(x => x.PropName == Yw.Hydro.ParterProp.CalcuHeadLoss).OrderBy(t => t.SortCode).ToList(); if (gradingList != null && gradingList.Count > 0) { var calcuResult = _allCalcuResultList?.Find(t => t.Code == pump.Code); if (calcuResult is HydroCalcuLinkResult calcuLinkResult) { if (calcuLinkResult.CalcuHeadLoss.HasValue) { var grading = gradingList.Meet(Math.Abs(calcuLinkResult.CalcuHeadLoss.Value)); if (grading != null) { var result = new HydroGradingApplyResultViewModel() { Code = pump.Code, Color = grading.Color }; resultList.Add(result); } } } } } break; default: break; } } } } break; case Yw.Hydro.ParterCatalog.Valve: { if (hydroInfo.Valves != null && hydroInfo.Valves.Count > 0) { foreach (var valve in hydroInfo.Valves) { switch (x.PropName) { case Yw.Hydro.ParterProp.LinkStatus: { var gradingList = allCatalogGradingList.Where(x => x.PropName == Yw.Hydro.ParterProp.LinkStatus).OrderBy(t => t.SortCode).ToList(); if (gradingList != null && gradingList.Count > 0) { var grading = gradingList.Meet(valve.LinkStatus); if (grading != null) { var result = new HydroGradingApplyResultViewModel() { Code = valve.Code, Color = grading.Color }; resultList.Add(result); } } } break; case Yw.Hydro.ParterProp.CalcuFlow: { var gradingList = allCatalogGradingList.Where(x => x.PropName == Yw.Hydro.ParterProp.CalcuFlow).OrderBy(t => t.SortCode).ToList(); if (gradingList != null && gradingList.Count > 0) { var calcuResult = _allCalcuResultList?.Find(t => t.Code == valve.Code); if (calcuResult is HydroCalcuLinkResult calcuLinkResult) { if (calcuLinkResult.CalcuFlow.HasValue) { var grading = gradingList.Meet(Math.Abs(calcuLinkResult.CalcuFlow.Value)); if (grading != null) { var result = new HydroGradingApplyResultViewModel() { Code = valve.Code, Color = grading.Color }; resultList.Add(result); } } } } } break; case Yw.Hydro.ParterProp.CalcuVelocity: { var gradingList = allCatalogGradingList.Where(x => x.PropName == Yw.Hydro.ParterProp.CalcuVelocity).OrderBy(t => t.SortCode).ToList(); if (gradingList != null && gradingList.Count > 0) { var calcuResult = _allCalcuResultList?.Find(t => t.Code == valve.Code); if (calcuResult is HydroCalcuLinkResult calcuLinkResult) { if (calcuLinkResult.CalcuVelocity.HasValue) { var grading = gradingList.Meet(Math.Abs(calcuLinkResult.CalcuVelocity.Value)); if (grading != null) { var result = new HydroGradingApplyResultViewModel() { Code = valve.Code, Color = grading.Color }; resultList.Add(result); } } } } } break; case Yw.Hydro.ParterProp.CalcuHeadLoss: { var gradingList = allCatalogGradingList.Where(x => x.PropName == Yw.Hydro.ParterProp.CalcuHeadLoss).OrderBy(t => t.SortCode).ToList(); if (gradingList != null && gradingList.Count > 0) { var calcuResult = _allCalcuResultList?.Find(t => t.Code == valve.Code); if (calcuResult is HydroCalcuLinkResult calcuLinkResult) { if (calcuLinkResult.CalcuHeadLoss.HasValue) { var grading = gradingList.Meet(Math.Abs(calcuLinkResult.CalcuHeadLoss.Value)); if (grading != null) { var result = new HydroGradingApplyResultViewModel() { Code = valve.Code, Color = grading.Color }; resultList.Add(result); } } } } } break; default: break; } } } } break; case Yw.Hydro.ParterCatalog.Pipe: { if (hydroInfo.Pipes != null && hydroInfo.Pipes.Count > 0) { foreach (var pipe in hydroInfo.Pipes) { switch (x.PropName) { case Yw.Hydro.ParterProp.CalcuFlow: { var gradingList = allCatalogGradingList.Where(x => x.PropName == Yw.Hydro.ParterProp.CalcuFlow).OrderBy(t => t.SortCode).ToList(); if (gradingList != null && gradingList.Count > 0) { var calcuResult = _allCalcuResultList?.Find(t => t.Code == pipe.Code); if (calcuResult is HydroCalcuLinkResult calcuLinkResult) { if (calcuLinkResult.CalcuFlow.HasValue) { var grading = gradingList.Meet(Math.Abs(calcuLinkResult.CalcuFlow.Value)); if (grading != null) { var result = new HydroGradingApplyResultViewModel() { Code = pipe.Code, Color = grading.Color }; resultList.Add(result); } } } } } break; case Yw.Hydro.ParterProp.CalcuVelocity: { var gradingList = allCatalogGradingList.Where(x => x.PropName == Yw.Hydro.ParterProp.CalcuVelocity).OrderBy(t => t.SortCode).ToList(); if (gradingList != null && gradingList.Count > 0) { var calcuResult = _allCalcuResultList?.Find(t => t.Code == pipe.Code); if (calcuResult is HydroCalcuLinkResult calcuLinkResult) { if (calcuLinkResult.CalcuVelocity.HasValue) { var grading = gradingList.Meet(Math.Abs(calcuLinkResult.CalcuVelocity.Value)); if (grading != null) { var result = new HydroGradingApplyResultViewModel() { Code = pipe.Code, Color = grading.Color }; resultList.Add(result); } } } } } break; case Yw.Hydro.ParterProp.CalcuHeadLoss: { var gradingList = allCatalogGradingList.Where(x => x.PropName == Yw.Hydro.ParterProp.CalcuHeadLoss).OrderBy(t => t.SortCode).ToList(); if (gradingList != null && gradingList.Count > 0) { var calcuResult = _allCalcuResultList?.Find(t => t.Code == pipe.Code); if (calcuResult is HydroCalcuLinkResult calcuLinkResult) { if (calcuLinkResult.CalcuHeadLoss.HasValue) { var grading = gradingList.Meet(Math.Abs(calcuLinkResult.CalcuHeadLoss.Value)); if (grading != null) { var result = new HydroGradingApplyResultViewModel() { Code = pipe.Code, Color = grading.Color }; resultList.Add(result); } } } } } break; default: break; } } } } break; default: break; } } }); return resultList; } //自定义 private void GridView1_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e) { var row = this.gridView1.GetRow(e.RowHandle) as HydroGradingApplyViewModel; if (row == null) { return; } if (e.Column == this.colPropName) { var repositoryItem = new RepositoryItemImageComboBox(); var dict = HydroParterPropHelper.GetDict(row.Code); repositoryItem.Items.Add("无", string.Empty, 0); if (dict != null && dict.Count > 0) { dict.ForEach(x => { repositoryItem.Items.Add(x.Value, x.Key, 0); }); } e.RepositoryItem = repositoryItem; } } } }