using Yw.Model;
|
|
namespace Yw.WinFrmUI
|
{
|
public partial class HydroTranslationListCtrl : DevExpress.XtraEditors.XtraUserControl, IHydroVisualList
|
{
|
public HydroTranslationListCtrl()
|
{
|
InitializeComponent();
|
this.gridView1.SetNormalView(30);
|
this.gridView1.RegistCustomDrawRowIndicator(40);
|
this.layoutControl1.SetupLayoutControl();
|
this.generalSearchAndSetCtrl1.SearchEvent += Search;
|
this.generalSearchAndSetCtrl1.ClearEvent += Reset;
|
this.generalSearchAndSetCtrl1.SetEvent += Set;
|
}
|
|
/// <summary>
|
/// 水力点击事件
|
/// </summary>
|
public event Action<Yw.Model.HydroVisualInfo> HydroClickInfoEvent;
|
/// <summary>
|
/// 水力点击视图事件
|
/// </summary>
|
public event Action<HydroVisualViewModel> HydroClickViewEvent;
|
/// <summary>
|
/// 水力改变事件
|
/// </summary>
|
public event Action<List<Yw.Model.HydroVisualInfo>> HydroChangedInfoEvent;
|
/// <summary>
|
/// 水力改变视图事件
|
/// </summary>
|
public event Action<List<HydroVisualViewModel>> HydroChangedViewEvent;
|
|
/// <summary>
|
/// 是否拥有水力列表
|
/// </summary>
|
public bool HasHydroList
|
{
|
get { return _allList != null && _allList.Count > 0; }
|
}
|
|
//所有列表
|
private List<HydroTranslationViewModel> _allList = null;
|
//所有绑定列表
|
private List<HydroTranslationViewModel> _allBindingList = null;
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData(Yw.Model.HydroModelInfo hydroInfo)
|
{
|
SetBindingData(hydroInfo, allCalcuResultVisualDict: null);
|
}
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData(Yw.Model.HydroModelInfo hydroInfo, List<HydroCalcuVisualResult> allCalcuResultList)
|
{
|
var allCalcuResultVisualDict = allCalcuResultList?.ToDictionary(x => x.Code);
|
SetBindingData(hydroInfo, allCalcuResultVisualDict);
|
}
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData(Yw.Model.HydroModelInfo hydroInfo, Dictionary<string, HydroCalcuVisualResult> allCalcuResultVisualDict)
|
{
|
_allList = new List<HydroTranslationViewModel>();
|
if (hydroInfo != null && hydroInfo.Translations != null && hydroInfo.Translations.Count > 0)
|
{
|
foreach (var visual in hydroInfo.Translations)
|
{
|
var vm = new HydroTranslationViewModel(visual, hydroInfo);
|
var calcuResult = allCalcuResultVisualDict?.GetValue(visual.Code);
|
if (calcuResult != null)
|
{
|
vm.UpdateCalcuProperty(calcuResult);
|
}
|
_allList.Add(vm);
|
}
|
}
|
Search();
|
}
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData(List<HydroVisualViewModel> allVisualViewModelList)
|
{
|
_allList = new List<HydroTranslationViewModel>();
|
allVisualViewModelList?.ForEach(x =>
|
{
|
if (x.Vmo.Catalog == Yw.Hydro.ParterCatalog.Translation)
|
{
|
_allList.Add(x as HydroTranslationViewModel);
|
}
|
});
|
Search();
|
}
|
|
/// <summary>
|
/// 更新绑定
|
/// </summary>
|
public void UpdateBindingData()
|
{
|
this.hydroTranslationViewModelBindingSource.ResetBindings(false);
|
}
|
|
/// <summary>
|
/// 更新属性
|
/// </summary>
|
public void UpdateProperty()
|
{
|
if (_allList == null || _allList.Count < 1)
|
{
|
return;
|
}
|
_allList.ForEach(x => x.UpdateProperty());
|
this.hydroTranslationViewModelBindingSource.ResetBindings(false);
|
}
|
|
/// <summary>
|
/// 更新属性
|
/// </summary>
|
public void UpdateProperty(Yw.Model.HydroVisualInfo visual)
|
{
|
if (_allList == null || _allList.Count < 1)
|
{
|
return;
|
}
|
if (visual == null)
|
{
|
return;
|
}
|
var vm = _allList.Find(x => x.Code == visual.Code);
|
if (vm == null)
|
{
|
return;
|
}
|
vm.UpdateProperty();
|
this.hydroTranslationViewModelBindingSource.ResetBindings(false);
|
}
|
|
/// <summary>
|
/// 更新属性
|
/// </summary>
|
public void UpdateProperty(List<Yw.Model.HydroVisualInfo> visualList)
|
{
|
if (_allList == null || _allList.Count < 1)
|
{
|
return;
|
}
|
if (visualList == null || visualList.Count < 1)
|
{
|
return;
|
}
|
visualList.ForEach(x =>
|
{
|
var vm = _allList.Find(t => x.Code == x.Code);
|
if (vm != null)
|
{
|
vm.UpdateProperty();
|
}
|
});
|
this.hydroTranslationViewModelBindingSource.ResetBindings(false);
|
}
|
|
/// <summary>
|
/// 更新计算属性
|
/// </summary>
|
public void UpdateCalcuProperty(List<HydroCalcuVisualResult> allCalcuResultList)
|
{
|
var allCalcuResultVisualDict = allCalcuResultList?.ToDictionary(x => x.Code);
|
UpdateCalcuProperty(allCalcuResultVisualDict);
|
}
|
|
/// <summary>
|
/// 更新计算属性
|
/// </summary>
|
public void UpdateCalcuProperty(Dictionary<string, HydroCalcuVisualResult> allCalcuResultVisualDict)
|
{
|
if (allCalcuResultVisualDict != null && allCalcuResultVisualDict.Count > 0)
|
{
|
if (_allList != null && _allList.Count > 0)
|
{
|
foreach (var visual in _allList)
|
{
|
var calcuResult = allCalcuResultVisualDict.GetValue(visual.Code);
|
if (calcuResult != null)
|
{
|
visual.UpdateCalcuProperty(calcuResult);
|
}
|
}
|
this.hydroTranslationViewModelBindingSource.ResetBindings(false);
|
}
|
}
|
}
|
|
//查询
|
private void Search()
|
{
|
if (_allList == null || _allList.Count < 1)
|
{
|
return;
|
}
|
var name = this.txtName.Text.Trim();
|
var code = this.txtCode.Text.Trim();
|
var modelType = this.txtModelType.Text.Trim();
|
_allBindingList = _allList;
|
if (!string.IsNullOrEmpty(name))
|
{
|
_allBindingList = _allBindingList.Where(x => !string.IsNullOrEmpty(x.Name) && x.Name.Contains(name)).ToList();
|
}
|
if (!string.IsNullOrEmpty(code))
|
{
|
_allBindingList = _allBindingList.Where(x => !string.IsNullOrEmpty(x.Code) && x.Code.Contains(code)).ToList();
|
}
|
if (!string.IsNullOrEmpty(modelType))
|
{
|
_allBindingList = _allBindingList.Where(x => !string.IsNullOrEmpty(x.ModelType) && x.ModelType.Contains(modelType)).ToList();
|
}
|
this.hydroTranslationViewModelBindingSource.DataSource = _allBindingList;
|
this.hydroTranslationViewModelBindingSource.ResetBindings(false);
|
}
|
|
//重置
|
private void Reset()
|
{
|
this.txtName.EditValue = null;
|
this.txtCode.EditValue = null;
|
this.txtModelType.EditValue = null;
|
Search();
|
}
|
|
//设置
|
private void Set()
|
{
|
Search();
|
if (_allBindingList == null || _allBindingList.Count < 1)
|
{
|
TipFormHelper.ShowWarn("无数据!");
|
return;
|
}
|
var dlg = new SetHydroTranslationDlg();
|
dlg.SetBindingData(_allBindingList.Select(x => x.Vmo).ToList());
|
dlg.ReloadDataEvent += (list) =>
|
{
|
_allBindingList.ForEach(x => x.UpdateProperty());
|
this.hydroTranslationViewModelBindingSource.ResetBindings(false);
|
var allVisualViewModelList = _allBindingList.Select(x => x as HydroVisualViewModel).ToList();
|
this.HydroChangedViewEvent?.Invoke(allVisualViewModelList);
|
var allVisualInfoList = allVisualViewModelList.Select(x => x.Vmo).ToList();
|
this.HydroChangedInfoEvent?.Invoke(allVisualInfoList);
|
};
|
dlg.ShowDialog();
|
}
|
|
//行单元格点击事件
|
private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
|
{
|
var row = this.gridView1.GetRow(e.RowHandle) as HydroTranslationViewModel;
|
if (row == null)
|
{
|
return;
|
}
|
|
if (e.Column == this.colSet)
|
{
|
var dlg = new SetHydroTranslationDlg();
|
dlg.SetBindingData(row.Vmo);
|
dlg.ReloadDataEvent += (list) =>
|
{
|
row.UpdateProperty();
|
this.gridView1.RefreshRow(e.RowHandle);
|
this.HydroChangedViewEvent?.Invoke(new List<HydroVisualViewModel>() { row });
|
this.HydroChangedInfoEvent?.Invoke(new List<HydroVisualInfo>() { row.Vmo });
|
};
|
dlg.ShowDialog();
|
}
|
else
|
{
|
this.HydroClickViewEvent?.Invoke(row);
|
this.HydroClickInfoEvent?.Invoke(row.Vmo);
|
}
|
}
|
|
/// <summary>
|
/// 设置简单显示模式
|
/// </summary>
|
public void SetSimpleView()
|
{
|
this.groupForHead.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
|
this.colDbLocked.Visible = false;
|
this.colName.Visible = true;
|
this.colCode.Visible = true;
|
this.colModelType.Visible = true;
|
this.colMaterial.Visible = true;
|
this.colDiameter.Visible = true;
|
this.colLength.Visible = true;
|
this.colRoughness.Visible = false;
|
this.colMinorLoss.Visible = false;
|
this.colHasDb.Visible = false;
|
this.colFlags.Visible = true;
|
this.colDescription.Visible = true;
|
this.colCalcuFrictionLoss.Visible = false;
|
this.colCalcuMinorLoss.Visible = false;
|
this.colCalcuHeadLoss.Visible = false;
|
this.colCalcuVelocity.Visible = false;
|
this.colCalcuFlow.Visible = false;
|
this.colSet.Visible = false;
|
}
|
|
/// <summary>
|
/// 设置正常显示模式
|
/// </summary>
|
public void SetNormalView()
|
{
|
this.groupForHead.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
|
this.colDbLocked.Visible = true;
|
this.colName.Visible = true;
|
this.colCode.Visible = true;
|
this.colModelType.Visible = true;
|
this.colMaterial.Visible = true;
|
this.colDiameter.Visible = true;
|
this.colLength.Visible = true;
|
this.colRoughness.Visible = true;
|
this.colMinorLoss.Visible = true;
|
this.colCalcuFlow.Visible = false;
|
this.colCalcuVelocity.Visible = false;
|
this.colCalcuHeadLoss.Visible = false;
|
this.colHasDb.Visible = true;
|
this.colFlags.Visible = true;
|
this.colDescription.Visible = true;
|
this.colSet.Visible = true;
|
}
|
|
/// <summary>
|
/// 设置计算显示模式
|
/// </summary>
|
public void SetCalcuView()
|
{
|
this.groupForHead.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
|
this.colDbLocked.Visible = true;
|
this.colName.Visible = true;
|
this.colCode.Visible = true;
|
this.colModelType.Visible = true;
|
this.colMaterial.Visible = true;
|
this.colDiameter.Visible = true;
|
this.colLength.Visible = true;
|
this.colRoughness.Visible = true;
|
this.colMinorLoss.Visible = true;
|
this.colHasDb.Visible = true;
|
this.colFlags.Visible = true;
|
this.colDescription.Visible = true;
|
this.colCalcuFlow.Visible = true;
|
this.colCalcuVelocity.Visible = true;
|
this.colCalcuHeadLoss.Visible = true;
|
this.colCalcuMinorLoss.Visible = true;
|
this.colCalcuFrictionLoss.Visible = true;
|
this.colSet.Visible = true;
|
}
|
|
/// <summary>
|
/// 设置批量模式
|
/// </summary>
|
public void SetBulkView()
|
{
|
this.groupForHead.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
|
this.colDbLocked.Visible = true;
|
this.colName.Visible = true;
|
this.colCode.Visible = true;
|
this.colModelType.Visible = true;
|
this.colMaterial.Visible = true;
|
this.colDiameter.Visible = true;
|
this.colLength.Visible = true;
|
this.colRoughness.Visible = true;
|
this.colMinorLoss.Visible = true;
|
this.colCalcuFlow.Visible = false;
|
this.colCalcuVelocity.Visible = false;
|
this.colCalcuHeadLoss.Visible = false;
|
this.colHasDb.Visible = true;
|
this.colFlags.Visible = true;
|
this.colDescription.Visible = true;
|
this.colSet.Visible = true;
|
}
|
|
/// <summary>
|
/// 设置结果视图
|
/// </summary>
|
public void SetResultView()
|
{
|
this.groupForHead.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
|
this.colDbLocked.Visible = true;
|
this.colName.Visible = true;
|
this.colCode.Visible = true;
|
this.colModelType.Visible = true;
|
this.colMaterial.Visible = true;
|
this.colDiameter.Visible = true;
|
this.colLength.Visible = true;
|
this.colRoughness.Visible = true;
|
this.colMinorLoss.Visible = true;
|
this.colHasDb.Visible = true;
|
this.colFlags.Visible = true;
|
this.colDescription.Visible = true;
|
this.colCalcuFlow.Visible = true;
|
this.colCalcuVelocity.Visible = true;
|
this.colCalcuHeadLoss.Visible = true;
|
this.colSet.Visible = false;
|
}
|
}
|
}
|