using DevExpress.XtraEditors;
|
using IStation.Untity;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Windows.Forms;
|
|
namespace IStation.WinFrmUI.Monitor
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public partial class MonitorPointListCtrl : XtraUserControl
|
{
|
public MonitorPointListCtrl()
|
{
|
InitializeComponent();
|
this.treeList1.InitialDefaultSettings();
|
this.treeList1.SelectImageList = ImageLib.Lib;
|
this.layoutControl1.SetupLayoutControl();
|
}
|
|
|
public class CurrentViewModel
|
{
|
public CurrentViewModel() { }
|
public CurrentViewModel(Model.MonitorPointGroup rhs)
|
{
|
this.ID = rhs.ID;
|
this.ParentID = TreeParentIdsHelper.GetLastParentID(rhs.ParentIds);
|
this.Name = rhs.Name;
|
this.ObjectID = rhs.ID;
|
this.SortCode = rhs.SortCode;
|
this.Description = rhs.Description;
|
this.ImageIndex = ImageLib.Group;
|
this.IsGroup = true;
|
this.Model = rhs;
|
}
|
|
public CurrentViewModel(Model.MonitorPointExSignalExSignalType rhs)
|
{
|
this.ID = rhs.MonitorPointID;
|
this.ParentID = rhs.GroupID == 0 ? -1 : rhs.GroupID;
|
this.Name = rhs.Name;
|
this.ObjectID = rhs.MonitorPointID;
|
this.SortCode = rhs.SortCode;
|
this.Description = rhs.Description;
|
this.ImageIndex = ImageLib.MonitorPoint;
|
this.IsGroup = false;
|
this.Model = rhs;
|
}
|
|
public long ID { get; set; }
|
public long ParentID { get; set; }
|
public string Name { get; set; }
|
public long ObjectID { get; set; }
|
public int SortCode { get; set; }
|
public string Description { get; set; }
|
public bool IsGroup { get; set; }
|
public int ImageIndex { get; set; }
|
public object Model { get; set; }
|
}
|
|
/// <summary>
|
/// 聚焦改变事件
|
/// </summary>
|
public event Action<Model.MonitorPointExSignalExSignalType> FocusedChangedEvent;
|
|
private List<CurrentViewModel> _allBindingList = null;//所有绑定列表
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData()
|
{
|
var monitorPointGroups = new BLL.MonitorPointGroup().GetAll();
|
var monitorPoints = new BLL.MonitorPoint().GetAllExSignalExSignalType();
|
this.SetBindingData(monitorPointGroups, monitorPoints);
|
}
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData(List<Model.MonitorPointGroup> monitorPointGroups, List<Model.MonitorPointExSignalExSignalType> monitorPoints)
|
{
|
_allBindingList = new List<CurrentViewModel>();
|
var stationGroup = new Model.MonitorPointGroup();
|
stationGroup.ID = -1;
|
stationGroup.Name = "总站";
|
stationGroup.SortCode = int.MinValue;
|
stationGroup.Description = "虚拟分组";
|
_allBindingList.Add(new CurrentViewModel(stationGroup));
|
|
if (monitorPointGroups != null && monitorPointGroups.Count > 0)
|
{
|
monitorPointGroups = monitorPointGroups.OrderBy(x => x.SortCode).ToList();
|
monitorPointGroups.ForEach(x => _allBindingList.Add(new CurrentViewModel(x)));
|
}
|
|
if (monitorPoints != null && monitorPoints.Count > 0)
|
{
|
monitorPoints = monitorPoints.OrderBy(x => x.SortCode).ToList();
|
foreach (var point in monitorPoints)
|
{
|
_allBindingList.Add(new CurrentViewModel(point));
|
}
|
}
|
|
this.treeList1.DataSource = _allBindingList;
|
this.treeList1.ForceInitialize();
|
}
|
|
//全部展开
|
private void barBtnExpandAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
this.treeList1.ExpandAll();
|
}
|
|
//全部折叠
|
private void barBtnCollpseAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
this.treeList1.CollapseAll();
|
}
|
|
//检索
|
private void barCkSearch_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (this.barCkSearch.Checked)
|
this.treeList1.ShowFindPanel();
|
else
|
this.treeList1.HideFindPanel();
|
}
|
|
//详细信息
|
private void barBtnDetail_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
XtraMessageBox.Show("待补充!");
|
}
|
|
//聚焦前
|
private void treeList1_BeforeFocusNode(object sender, DevExpress.XtraTreeList.BeforeFocusNodeEventArgs e)
|
{
|
var row = this.treeList1.GetDataRecordByNode(e.Node) as CurrentViewModel;
|
if (row != null)
|
{
|
if (row.IsGroup)
|
{
|
e.CanFocus = false;
|
}
|
}
|
}
|
|
//聚焦改变
|
private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
|
{
|
var vm = this.treeList1.GetCurrentViewModel(_allBindingList);
|
if (vm == null)
|
return;
|
if (vm.IsGroup)
|
return;
|
var model = vm.Model as Model.MonitorPointExSignalExSignalType;
|
this.FocusedChangedEvent?.Invoke(model);
|
}
|
|
|
}
|
|
}
|