using DevExpress.Utils;
|
using DevExpress.XtraEditors;
|
using IStation.Untity;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Drawing;
|
using System.Linq;
|
using System.Windows.Forms;
|
|
|
namespace IStation.WinFrmUI.Scatl.Monitor
|
{
|
/// <summary>
|
/// 分析测点树列表控件
|
/// </summary>
|
public partial class MultiSelectAnaMonitorPointTreeListCtrl : XtraUserControl
|
{
|
public MultiSelectAnaMonitorPointTreeListCtrl()
|
{
|
InitializeComponent();
|
this.treeList1.InitialDefaultSettings();
|
this.treeList1.SelectImageList = CurrentViewModel.Image16Store;
|
this.layoutControl1.SetupLayoutControl();
|
}
|
|
#region 当前视图
|
|
public class CurrentViewModel
|
{
|
public CurrentViewModel() { }
|
|
public CurrentViewModel(Model.Scatl.LogicTreeEx rhs)
|
{
|
this.ID = $"{rhs.LogicType}_{rhs.LogicId}";
|
this.Name = rhs.LogicName;
|
this.DispName = rhs.LogicName;
|
this.ObjectType = rhs.LogicType;
|
this.ObjectID = rhs.LogicId;
|
this.SortCode = rhs.SortCode;
|
this.Description = rhs.Description;
|
this.ImageIndex = Get16ObjectTypeImageIndex(rhs.LogicType);
|
this.Model = rhs;
|
}
|
|
public CurrentViewModel(Model.Scatl.MonitorPointGroup rhs)
|
{
|
this.ID = $"{IStation.Scatl.ObjectType.MonitorPointGroup_监测点组}_{rhs.Id}";
|
if (rhs.ParentIds != null && rhs.ParentIds.Count > 0)
|
{
|
this.ParentID = $"{IStation.Scatl.ObjectType.MonitorPointGroup_监测点组}_{TreeParentIdsHelper.GetLastParentID(rhs.ParentIds)}";
|
}
|
else
|
{
|
this.ParentID = $"{rhs.BelongType}_{rhs.BelongId}";
|
}
|
this.Name = rhs.Name;
|
this.DispName = rhs.Name;
|
this.ObjectType = IStation.Scatl.ObjectType.MonitorPointGroup_监测点组;
|
this.ObjectID = rhs.Id;
|
this.SortCode = rhs.SortCode;
|
this.Description = rhs.Description;
|
this.ImageIndex = Get16ObjectTypeImageIndex(this.ObjectType);
|
this.Model = rhs;
|
}
|
|
public CurrentViewModel(Model.Scatl.MonitorPoint rhs)
|
{
|
this.ID = $"{IStation.Scatl.ObjectType.MonitorPoint_监测点}_{rhs.Id}";
|
if (rhs.GroupId < 1)
|
{
|
|
}
|
else
|
{
|
this.ParentID = $"{IStation.Scatl.ObjectType.MonitorPointGroup_监测点组}_{rhs.GroupId}";
|
}
|
|
this.Name = rhs.Name;
|
this.DispName = rhs.Name;
|
this.ObjectType = IStation.Scatl.ObjectType.MonitorPoint_监测点;
|
this.ObjectID = rhs.Id;
|
this.SortCode = rhs.SortCode;
|
this.Description = rhs.Description;
|
this.ImageIndex = Get16ObjectTypeImageIndex(this.ObjectType);
|
this.Model = rhs;
|
}
|
|
public string ID { get; set; }
|
public string ParentID { get; set; }
|
public string DispName { 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; }
|
public bool? Checked { get; set; }
|
|
/// <summary>
|
/// 图标仓库
|
/// </summary>
|
public static ImageCollection Image16Store
|
{
|
get
|
{
|
if (_image16Store == null)
|
{
|
_image16Store = new ImageCollection();
|
_image16Store.ImageSize = new Size(16, 16);
|
_image16Store.Images.Add(WinFrmUI.Scatl.Properties.Resources.Logic32, "Logic");
|
_image16Store.Images.Add(WinFrmUI.Scatl.Properties.Resources.Station32, "Station");
|
_image16Store.Images.Add(WinFrmUI.Scatl.Properties.Resources.Group32, "Group");
|
_image16Store.Images.Add(WinFrmUI.Scatl.Properties.Resources.MonitorPoint32, "MonitorPoint");
|
}
|
return _image16Store;
|
}
|
}
|
private static ImageCollection _image16Store;
|
|
|
public static Image Get16ObjectTypeImage(string objectType)
|
{
|
Image img = null;
|
switch (objectType)
|
{
|
case IStation.Scatl.ObjectType.LogicArea_业务区域: img = Image16Store.Images["Logic"]; break;
|
case IStation.Scatl.ObjectType.Station_泵站: img = Image16Store.Images["Station"]; break;
|
case IStation.Scatl.ObjectType.MonitorPointGroup_监测点组: img = Image16Store.Images["Group"]; break;
|
case IStation.Scatl.ObjectType.MonitorPoint_监测点: img = Image16Store.Images["MonitorPoint"]; break;
|
}
|
return img;
|
}
|
|
//获取
|
public static int Get16ObjectTypeImageIndex(string objectType)
|
{
|
var img = Get16ObjectTypeImage(objectType);
|
return Image16Store.Images.IndexOf(img);
|
}
|
}
|
|
#endregion
|
|
/// <summary>
|
/// check 改变后
|
/// </summary>
|
public event Action<List<Model.Scatl.MonitorPointExSignalList>> CheckedChangedEvent;
|
|
private List<Model.Scatl.LogicCatalog> _allCatalogList = null;//所有业务类别列表
|
private BindingList<CurrentViewModel> _allBindingList = null;//所有绑定列表
|
|
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData(long projectId, Model.Scatl.Monitor.eSourceType sourceType, List<long> monitorPointIds = null)
|
{
|
_allCatalogList = new BLL.Scatl.LogicCatalog().GetAll(projectId);
|
if (_allCatalogList == null)
|
_allCatalogList = new List<Model.Scatl.LogicCatalog>();
|
var logicTree = new BLL.Scatl.LogicTree().GetAllEx(projectId);
|
var logicGroup = logicTree.GroupBy(x => x.CatalogId).ToList();
|
logicTree = logicGroup?.OrderByDescending(x => x.Count()).First().Select(x => x).ToList();
|
var group_list = new BLL.Scatl.MonitorPointGroup().GetAll(projectId);
|
var point_list = new BLL.Scatl.MonitorPoint().GetExSignalList(projectId);
|
point_list = point_list?.Where(x => x.SourceType == sourceType).ToList();
|
this.SetBindingData(logicTree, group_list, point_list, monitorPointIds);
|
}
|
|
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData(
|
List<Model.Scatl.LogicTreeEx> all_logic_list,
|
List<Model.Scatl.MonitorPointGroup> all_group_list,
|
List<Model.Scatl.MonitorPointExSignalList> all_point_list,
|
List<long> MonitorPointIds = null)
|
{
|
_allBindingList = new BindingList<CurrentViewModel>();
|
if (all_point_list == null)
|
all_point_list = new List<Model.Scatl.MonitorPointExSignalList>();
|
if (all_logic_list != null && all_logic_list.Count > 0)
|
{
|
foreach (var logic in all_logic_list)
|
{
|
var monitorPoints = all_point_list.Where(x => x.BelongType == logic.LogicType && x.BelongId == logic.LogicId).ToList();
|
if (monitorPoints == null || monitorPoints.Count() < 1)
|
continue;
|
var groups = all_group_list?.Where(x => x.BelongType == logic.LogicType && x.BelongId == logic.LogicId).ToList();
|
if (groups == null || groups.Count() < 1)
|
{
|
AddMoniorNodeList(monitorPoints, MonitorPointIds);
|
}
|
else
|
{
|
groups = groups.Where(x => monitorPoints.Exists(point => point.GroupId == x.Id)).ToList();
|
if (groups == null || groups.Count < 1)
|
{
|
AddMoniorNodeList(monitorPoints, MonitorPointIds);
|
}
|
else
|
{
|
foreach (var g in groups)
|
{
|
var g_moinotrPoints = monitorPoints.FindAll(x => x.GroupId == g.Id);
|
if (g_moinotrPoints == null || g_moinotrPoints.Count < 1)
|
continue;
|
var v_grp_monitor = new CurrentViewModel(g);
|
var grp_check_status = AddMoniorNodeList(g_moinotrPoints, MonitorPointIds);
|
v_grp_monitor.Checked = grp_check_status;
|
_allBindingList.Add(v_grp_monitor);
|
}
|
//未分组的
|
var point_list0 = from x in monitorPoints where x.GroupId == 0 orderby x.SortCode select x;
|
AddMoniorNodeList(point_list0, MonitorPointIds);
|
}
|
}
|
}
|
}
|
|
this.treeList1.DataSource = _allBindingList;
|
this.treeList1.ForceInitialize();
|
CheckedChanged();
|
}
|
|
private bool? AddMoniorNodeList(
|
IEnumerable<Model.Scatl.MonitorPointExSignalList> all_point_list,
|
List<long> MonitorPointIds = null)
|
{
|
if (all_point_list == null || all_point_list.Count() == 0)
|
return false;
|
var point_list = all_point_list.OrderBy(x => x.SortCode).ToList();
|
int check_num = 0;
|
foreach (var point in point_list)
|
{
|
var vm = new CurrentViewModel(point);
|
if (MonitorPointIds != null && MonitorPointIds.Count > 0)
|
{
|
if (MonitorPointIds.Contains(point.Id))
|
{
|
check_num++;
|
vm.Checked = true;
|
}
|
}
|
_allBindingList.Add(vm);
|
}
|
if (check_num == 0)
|
return false;
|
if (check_num == all_point_list.Count())
|
return true;
|
return null;
|
}
|
|
|
//全部展开
|
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 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;
|
}
|
//显示ID
|
private void barBtnDisplayID_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
var isDisp = barBtnDisplayID.Checked;
|
if (_allBindingList == null)
|
return;
|
foreach (var m in _allBindingList)
|
{
|
if (isDisp)
|
m.DispName = string.Format("{0} ({1})", m.Name, m.ObjectID);
|
else
|
m.DispName = m.Name;
|
}
|
this.treeList1.DataSource = _allBindingList;
|
this.treeList1.RefreshDataSource();
|
}
|
|
//树线
|
private void barCkTreeLine_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
this.treeList1.OptionsView.ShowTreeLines = this.barCkTreeLine.Checked ? DefaultBoolean.True : DefaultBoolean.False;
|
}
|
|
//选中节点后触发
|
private void treeList1_AfterCheckNode(object sender, DevExpress.XtraTreeList.NodeEventArgs e)
|
{
|
SetCheckedChildNodes(e.Node, e.Node.CheckState);
|
SetCheckedParentNodes(e.Node, e.Node.CheckState);
|
CheckedChanged();
|
}
|
|
//选中事件
|
private void CheckedChanged()
|
{
|
if (_allBindingList == null)
|
return;
|
var list = _allBindingList.Where(x => x.ObjectType == IStation.Scatl.ObjectType.MonitorPoint_监测点 && x.Checked == true).Select(x => x.Model as Model.Scatl.MonitorPointExSignalList).ToList();
|
this.CheckedChangedEvent?.Invoke(list);
|
}
|
|
|
private void treeList1_BeforeCheckNode(object sender, DevExpress.XtraTreeList.CheckNodeEventArgs e)
|
{
|
e.State = (e.PrevState == CheckState.Checked ? CheckState.Unchecked : CheckState.Checked);
|
}
|
|
|
/// 设置子节点的状态
|
private void SetCheckedChildNodes(DevExpress.XtraTreeList.Nodes.TreeListNode node, CheckState check)
|
{
|
for (int i = 0; i < node.Nodes.Count; i++)
|
{
|
node.Nodes[i].CheckState = check;
|
SetCheckedChildNodes(node.Nodes[i], check);
|
}
|
}
|
|
|
|
|
/// 设置父节点的状态
|
private void SetCheckedParentNodes(DevExpress.XtraTreeList.Nodes.TreeListNode node, CheckState check)
|
{
|
if (node.ParentNode != null)
|
{
|
bool b = false;
|
CheckState state;
|
for (int i = 0; i < node.ParentNode.Nodes.Count; i++)
|
{
|
state = node.ParentNode.Nodes[i].CheckState;
|
if (!check.Equals(state))
|
{
|
b = !b;
|
break;
|
}
|
}
|
node.ParentNode.CheckState = b ? CheckState.Indeterminate : check;
|
SetCheckedParentNodes(node.ParentNode, check);
|
}
|
}
|
|
}
|
}
|