using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Drawing;
|
using System.Data;
|
using System.Text;
|
using System.Linq;
|
using System.Threading.Tasks;
|
using System.Windows.Forms;
|
using DevExpress.XtraEditors;
|
using DevExpress.Utils;
|
using IStation.Untity;
|
|
|
namespace IStation.WinFormUI.MonitorDataSet
|
{
|
/// <summary>
|
/// 测点树列表控件
|
/// </summary>
|
public partial class MonitorPointExSignalListTreeCtrl : XtraUserControl
|
{
|
public MonitorPointExSignalListTreeCtrl()
|
{
|
InitializeComponent();
|
this.treeList1.InitialDefaultSettings();
|
this.treeList1.SelectImageList = CurrentViewModel.Image16Store;
|
this.layoutControl1.SetupLayoutControl();
|
}
|
|
#region 当前视图
|
|
public class CurrentViewModel
|
{
|
public CurrentViewModel() { }
|
public CurrentViewModel(Model.MonitorPointGroup rhs)
|
{
|
this.ID = $"{IStation.ObjectType.MonitorPointGroup}_{rhs.Id}";
|
this.ParentID = $"{IStation.ObjectType.MonitorPointGroup}_{TreeParentIdsHelper.GetLastParentID(rhs.ParentIds)}";
|
this.Name = rhs.Name;
|
this.ObjectType = IStation.ObjectType.MonitorPointGroup;
|
this.ObjectID = rhs.Id;
|
this.SortCode = rhs.SortCode;
|
this.Description = rhs.Description;
|
this.ImageIndex = 0;
|
this.Model = rhs;
|
}
|
|
public CurrentViewModel(Model.MonitorPointExSignalList rhs)
|
{
|
this.ID = $"{IStation.ObjectType.MonitorPoint}_{rhs.Id}";
|
this.ParentID = $"{IStation.ObjectType.MonitorPointGroup}_{rhs.GroupId}";
|
this.Name = rhs.Name;
|
this.ObjectType = IStation.ObjectType.MonitorPoint;
|
this.ObjectID = rhs.Id;
|
this.SortCode = rhs.SortCode;
|
this.Description = rhs.Description;
|
this.ImageIndex = 1;
|
this.Model = rhs;
|
}
|
|
public string ID { get; set; }
|
public string ParentID { get; set; }
|
public string Name { get; set; }
|
public string ObjectType { get; set; }
|
public long ObjectID { get; set; }
|
public int SortCode { get; set; }
|
public string Description { get; set; }
|
public int ImageIndex { get; set; }
|
public object Model { get; set; }
|
|
/// <summary>
|
/// 图标仓库
|
/// </summary>
|
public static ImageCollection Image16Store
|
{
|
get
|
{
|
if (_image16Store == null)
|
{
|
_image16Store = new ImageCollection();
|
_image16Store.ImageSize = new Size(16, 16);
|
_image16Store.Images.Add(WinFormUI.Properties.Resource.Group, "Group");
|
_image16Store.Images.Add(WinFormUI.Properties.Resource.MonitorPoint, "MonitorPoint");
|
//_image16Store.Images.Add(WinFormUI.Properties.Resource.Signal, "Signal");
|
}
|
return _image16Store;
|
}
|
}
|
private static ImageCollection _image16Store;
|
|
public static Image Get16ObjectTypeImage(string objectType)
|
{
|
|
Image img = null;
|
switch (objectType)
|
{
|
case IStation.ObjectType.MonitorPointGroup: img = Image16Store.Images["Group"]; break;
|
case IStation.ObjectType.MonitorPoint: img = Image16Store.Images["MonitorPoint"]; break;
|
case IStation.ObjectType.Signal: img = Image16Store.Images["Signal"]; break;
|
}
|
|
if (img == null)
|
img = Image16Store.Images["Question"];
|
return img;
|
}
|
|
//获取
|
public static int Get16ObjectTypeImageIndex(string objectId)
|
{
|
var img = Get16ObjectTypeImage(objectId);
|
return Image16Store.Images.IndexOf(img);
|
}
|
|
}
|
|
#endregion
|
|
/// <summary>
|
/// 聚焦改变事件
|
/// </summary>
|
public event Action<string, object> FocusedChangedEvent;
|
|
/// <summary>
|
/// 选择事件
|
/// </summary>
|
public event Action<string, object, MouseEventArgs> SelectEvent;
|
|
private long _projectId;//项目标识
|
private List<CurrentViewModel> _allBindingList = null;//所有绑定列表
|
private CurrentViewModel _focused = null;//当前聚焦
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData(long projectId)
|
{
|
_projectId = projectId;
|
var group_list = new BLL.MonitorPointGroup().GetAll(_projectId);
|
var point_list = new BLL.MonitorPoint().GetExSignalList(_projectId);
|
this.SetBindingData(group_list, point_list);
|
}
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData(long projectId, string belongType, long belongId)
|
{
|
_projectId = projectId;
|
var group_list = new BLL.MonitorPointGroup().GetByBelongTypeAndBelongId(_projectId,belongType,belongId);
|
var point_list = new BLL.MonitorPoint().GetExSignalListByBelongTypeAndBelongId(_projectId, belongType,belongId);
|
this.SetBindingData(group_list, point_list);
|
}
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData(List<Model.MonitorPointGroup> group_list, List<Model.MonitorPointExSignalList> point_list)
|
{
|
_allBindingList = new List<CurrentViewModel>();
|
if (group_list != null && group_list.Count > 0)
|
{
|
group_list = group_list.OrderBy(x => x.SortCode).ToList();
|
group_list.ForEach(x => _allBindingList.Add(new CurrentViewModel(x)));
|
}
|
else
|
{
|
var group = new Model.MonitorPointGroup();
|
group.Id = -1;
|
group.Name = "未分组";
|
group.SortCode = int.MaxValue;
|
group.Description = "虚拟分组";
|
_allBindingList.Add(new CurrentViewModel(group));
|
}
|
|
if (point_list != null && point_list.Count > 0)
|
{
|
point_list = point_list.OrderBy(x => x.SortCode).ToList();
|
foreach (var point in point_list)
|
{
|
_allBindingList.Add(new CurrentViewModel(point));
|
}
|
}
|
|
this.treeList1.DataSource = _allBindingList;
|
this.treeList1.ForceInitialize();
|
this.treeList1.ExpandAll();
|
if (_allBindingList.Count < 1)
|
{
|
if (_focused != null)
|
{
|
_focused = null;
|
this.FocusedChangedEvent?.Invoke(string.Empty, null);
|
}
|
}
|
}
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData(long projectId, long groupId)
|
{
|
if (groupId < 1)
|
return;
|
_allBindingList = new List<CurrentViewModel>();
|
var group = new BLL.MonitorPointGroup().GetById(projectId, groupId);
|
_allBindingList.Add(new CurrentViewModel(group));
|
var point_list = new BLL.MonitorPoint().GetExSignalListByGroupId(projectId, groupId);
|
if (point_list != null && point_list.Count > 0)
|
{
|
point_list = point_list.OrderBy(x => x.SortCode).ToList();
|
point_list.ForEach(x => _allBindingList.Add(new CurrentViewModel(x)));
|
}
|
this.treeList1.DataSource = _allBindingList;
|
this.treeList1.ForceInitialize();
|
this.treeList1.ExpandAll();
|
if (_allBindingList.Count < 1)
|
{
|
if (_focused != null)
|
{
|
_focused = null;
|
this.FocusedChangedEvent?.Invoke(string.Empty, null);
|
}
|
}
|
}
|
|
|
/// <summary>
|
/// 获取聚焦
|
/// </summary>
|
public object GetFocused()
|
{
|
var vm = this.treeList1.GetFocusedRow() as CurrentViewModel;
|
return vm?.Model;
|
}
|
|
/// <summary>
|
/// 设置聚焦
|
/// </summary>
|
public bool SetFocused(string objectType,long objectId)
|
{
|
var key = $"{objectType}_{objectId}";
|
var node = this.treeList1.FindNodeByKeyID(key);
|
if (node == null)
|
return false;
|
this.treeList1.FocusedNode = node;
|
return true;
|
}
|
|
|
//全部展开
|
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();
|
}
|
|
//检索(menu)
|
private void barBtnSearch_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (this.layoutControlItem1.Visibility == DevExpress.XtraLayout.Utils.LayoutVisibility.Always)
|
this.layoutControlItem1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
|
else
|
this.layoutControlItem1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
|
}
|
|
//树线
|
private void barCkTreeLine_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
this.treeList1.OptionsView.ShowTreeLines = this.barCkTreeLine.Checked ? DefaultBoolean.True : DefaultBoolean.False;
|
}
|
|
//聚焦改变
|
private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
|
{
|
var vm = this.treeList1.GetFocusedRow() as CurrentViewModel;
|
this.FocusedChangedEvent?.Invoke(vm.ObjectType, vm?.Model);
|
}
|
|
//鼠标点击
|
private void treeList1_RowCellClick(object sender, DevExpress.XtraTreeList.RowCellClickEventArgs e)
|
{
|
if (e.Button == MouseButtons.Left)
|
{
|
var vm = this.treeList1.GetDataRecordByNode(e.Node) as CurrentViewModel;
|
this.SelectEvent?.Invoke(vm.ObjectType, vm.Model, e);
|
}
|
}
|
|
|
public List<Model.MonitorPointGroup> GetMonitorPointGroups()
|
{
|
if (_allBindingList == null || _allBindingList.Count < 1)
|
return default;
|
return _allBindingList.Where(x => x.ObjectType == IStation.ObjectType.MonitorPointGroup).Select(x => x.Model as Model.MonitorPointGroup).ToList();
|
}
|
|
public List<Model.MonitorPointExSignalList> GetMonitorPointExSignalList()
|
{
|
if (_allBindingList == null || _allBindingList.Count < 1)
|
return default;
|
return _allBindingList.Where(x => x.ObjectType == IStation.ObjectType.MonitorPoint).Select(x => x.Model as Model.MonitorPointExSignalList).ToList();
|
}
|
|
|
}
|
|
}
|