using DevExpress.XtraEditors;
using IStation.Untity;
using System;
using System.Collections.Generic;
using System.Linq;
namespace IStation.WinFrmUI.Monitor
{
///
///
///
public partial class MonitorPointTreeList : XtraUserControl
{
public MonitorPointTreeList()
{
InitializeComponent();
treeList1.InitialDefaultSettings();
treeList1.SelectImageList = ImageLib.Lib;
layoutControl1.SetupLayoutControl();
}
public class CurrentViewModel
{
public CurrentViewModel() { }
public CurrentViewModel(Model.Station rhs)
{
ID = rhs.ID;
Name = rhs.Name;
ObjectType = IStation.ObjectType.Station;
SortCode = rhs.SortCode;
ImageIndex = ImageLib.Station;
Model = rhs;
}
public CurrentViewModel(Model.MonitorPointGroup rhs)
{
ID = rhs.ID;
ParentID = rhs.ParentIds == null || !rhs.ParentIds.Any()
? rhs.BelongID : TreeParentIdsHelper.GetLastParentID(rhs.ParentIds);
Name = rhs.Name;
ObjectType = IStation.ObjectType.MonitorPointGroup;
SortCode = rhs.SortCode;
ImageIndex = ImageLib.Group;
Model = rhs;
}
public CurrentViewModel(Model.MonitorPointExSignal rhs)
{
ID = rhs.MonitorPointID;
ParentID = rhs.GroupID;
Name = rhs.Name;
ObjectType = IStation.ObjectType.MonitorPoint;
SortCode = rhs.SortCode;
ImageIndex = ImageLib.MonitorPoint;
Model = rhs;
}
public long ID { get; set; }
public long ParentID { get; set; }
public string Name { get; set; }
public string ObjectType { get; set; }
public int SortCode { get; set; }
public int ImageIndex { get; set; }
public bool IsVirtual { get; set; }
public object Model { get; set; }
}
///
/// 聚焦改变事件
///
public event Action FocusedChangedEvent;
private BLL.MonitorPoint _bll = new BLL.MonitorPoint();
private BLL.MonitorPointGroup _bllGroup = new BLL.MonitorPointGroup();
private List _allBindingList = null;//所有绑定列表
///
/// 绑定数据
///
public void Clear()
{
_allBindingList = new List();
treeList1.DataSource = _allBindingList;
FocusedChangedEvent?.Invoke(null);
}
///
/// 绑定数据
///
public void SetBindingData()
{
WaitFrmHelper.ShowWaitForm("正在加载数据...");
_allBindingList = new List();
var stations = new BLL.Station().GetAll();
if (stations != null && stations.Any())
{
foreach (var station in stations)
{
var vmStation = new CurrentViewModel(station);
_allBindingList.Add(vmStation);
var monitorPointGroups = _bllGroup.GetByBelongTypeAndBelongID(IStation.ObjectType.Station, station.ID);
if (monitorPointGroups == null || !monitorPointGroups.Any())
continue;
foreach (var group in monitorPointGroups)
{
var vmGroup = new CurrentViewModel(group);
_allBindingList.Add(vmGroup);
var monitorPoints = _bll.GetExSignalWithSignalTypeByBelongTypeAndBelongIDAndGroupID(group.BelongType, group.BelongID, group.ID);
if (monitorPoints == null || !monitorPoints.Any())
continue;
foreach (var item in monitorPoints)
{
var vm = new CurrentViewModel(item);
_allBindingList.Add(vm);
}
}
}
}
bindingSource1.DataSource = _allBindingList;
WaitFrmHelper.HideWaitForm();
}
//全部展开
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();
}
//聚焦改变
private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
{
var vm = treeList1.GetCurrentViewModel(_allBindingList);
if (vm == null)
return;
FocusedChangedEvent?.Invoke(vm.Model as Model.MonitorPointExSignalWithSignalType);
}
}
}