using DevExpress.XtraEditors;
|
using IStation.Untity;
|
using System;
|
using System.ComponentModel;
|
using System.Linq;
|
|
namespace IStation.WinFrmUI.Monitor
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public partial class EquipmentExTreeListCtrl : XtraUserControl
|
{
|
public EquipmentExTreeListCtrl()
|
{
|
InitializeComponent();
|
treeList1.InitialDefaultSettings();
|
treeList1.SelectImageList = ImageLib.Lib;
|
// this.layoutControl1.SetupLayoutControl();
|
stationTreeListLookUpEdit1.SelectedChangedEvent += StationTreeListLookUpEdit1_SelectedChangedEvent;
|
}
|
|
public class CurrentViewModel
|
{
|
public CurrentViewModel() { }
|
public CurrentViewModel(Model.EquipmentGroup rhs)
|
{
|
ID = rhs.ID;
|
Name = rhs.Name;
|
ParentID = TreeParentIdsHelper.GetLastParentID(rhs.ParentIds);
|
ImageIndex = ImageLib.Group;
|
IsGroup = true;
|
Model = rhs;
|
}
|
|
public CurrentViewModel(Model.Equipment rhs)
|
{
|
ID = rhs.ID;
|
Name = rhs.Name;
|
ParentID = rhs.ParentIds == null || !rhs.ParentIds.Any() ? rhs.GroupID : TreeParentIdsHelper.GetLastParentID(rhs.ParentIds);
|
ImageIndex = ImageLib.GetEquipmentImage(rhs.Catalog);
|
Model = rhs;
|
}
|
|
public long ID { get; set; }
|
public string Name { get; set; }
|
public long ParentID { get; set; }
|
public int ImageIndex { get; set; }
|
public bool IsGroup { get; set; }
|
public object Model { get; set; }
|
}
|
|
|
/// <summary>
|
/// 泵站改变事件
|
/// </summary>
|
public event Action<Model.Station> StationChangedEvent;
|
|
/// <summary>
|
/// 聚焦改变事件
|
/// </summary>
|
public event Action<Model.Equipment> FocusedChangedEvent;
|
|
private BLL.Equipment _bll = new BLL.Equipment();
|
private BindingList<CurrentViewModel> _allBindingList = null;//所有绑定列表
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData()
|
{
|
stationTreeListLookUpEdit1.SetBindingData();
|
}
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void Clear()
|
{
|
_allBindingList = new BindingList<CurrentViewModel>();
|
treeList1.DataSource = _allBindingList;
|
FocusedChangedEvent?.Invoke(null);
|
}
|
|
|
//泵站变换
|
private void StationTreeListLookUpEdit1_SelectedChangedEvent(Model.Station obj)
|
{
|
StationChangedEvent?.Invoke(obj);
|
SetBindingData(obj);
|
}
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
private void SetBindingData(Model.Station model)
|
{
|
WaitFrmHelper.ShowWaitForm("正在加载数据...");
|
_allBindingList = new BindingList<CurrentViewModel>();
|
if (model != null)
|
{
|
var groups = new BLL.EquipmentGroup().GetByBelongTypeAndBelongID(IStation.ObjectType.Station, model.ID);
|
if (groups != null && groups.Any())
|
{
|
foreach (var item in groups)
|
{
|
var vm = new CurrentViewModel(item);
|
_allBindingList.Add(vm);
|
}
|
}
|
|
var equipmentList = _bll.GetEnginePumpListByBelongTypeAndBelongID(IStation.ObjectType.Station, model.ID);
|
if (equipmentList != null && equipmentList.Any())
|
{
|
foreach (var item in equipmentList)
|
{
|
var vm = new CurrentViewModel(item);
|
_allBindingList.Add(vm);
|
}
|
}
|
}
|
treeList1.DataSource = _allBindingList;
|
treeList1.RefreshDataSource();
|
treeList1.ExpandAll();
|
WaitFrmHelper.HideWaitForm();
|
}
|
|
|
//聚焦前
|
private void treeList1_BeforeFocusNode(object sender, DevExpress.XtraTreeList.BeforeFocusNodeEventArgs e)
|
{
|
var vm = treeList1.GetDataRecordByNode(e.Node) as CurrentViewModel;
|
if (vm == null)
|
return;
|
if (vm.IsGroup)
|
{
|
e.CanFocus = false;
|
}
|
}
|
|
//聚焦改变
|
private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
|
{
|
var vm = treeList1.GetCurrentViewModel(_allBindingList);
|
if (vm == null || vm.IsGroup)
|
return;
|
var model = vm.Model as Model.Equipment;
|
FocusedChangedEvent?.Invoke(model);
|
}
|
|
#region 菜单事件
|
|
//全部展开
|
private void barBtnExpandAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
treeList1.ExpandAll();
|
}
|
|
//全部折叠
|
private void barBtnCollapseAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
treeList1.CollapseAll();
|
}
|
|
//检索
|
private void barCkSearch_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (barCkSearch.Checked)
|
treeList1.ShowFindPanel();
|
else
|
treeList1.HideFindPanel();
|
}
|
#endregion
|
|
}
|
}
|