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 DevExpress.XtraTreeList;
|
using DevExpress.XtraTreeList.Nodes;
|
using IStation.Untity;
|
|
namespace IStation.WinFormUI.MonitorDataSet
|
{
|
/// <summary>
|
/// 测点树列表控件
|
/// </summary>
|
public partial class CurveCompareMultiSelectMonitorPointTreeListCtrl : XtraUserControl
|
{
|
public CurveCompareMultiSelectMonitorPointTreeListCtrl()
|
{
|
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 = "监测点组";
|
this.ObjectID = rhs.Id;
|
this.SortCode = rhs.SortCode;
|
this.Description = rhs.Description;
|
this.Checked = false;
|
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 = "监测点";
|
this.ObjectID = rhs.Id;
|
this.SortCode = rhs.SortCode;
|
this.Description = rhs.Description;
|
this.Checked = false;
|
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 bool? Checked { get; set; }
|
public int ImageIndex { get; set; }
|
public object Model { get; set; }
|
public Color? Color { 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");
|
}
|
return _image16Store;
|
}
|
}
|
private static ImageCollection _image16Store;
|
}
|
|
#endregion
|
|
/// <summary>
|
/// check 改变后
|
/// </summary>
|
public event Action<Model.MonitorPointExSignalList,System.Drawing.Color> SelectedEvent;
|
/// <summary>
|
///
|
/// </summary>
|
public event Action<Model.MonitorPointExSignalList> UncheckEvent;
|
|
private long _projectId;//项目标识
|
private List<CurrentViewModel> _allBindingList = null;//所有绑定列表
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData()
|
{
|
_projectId = 0;
|
this.SetBindingData(null, null);
|
}
|
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData(long projectId)
|
{
|
_projectId = projectId;
|
var group_list = new BLL.MonitorPointGroup().QueryAll(_projectId);
|
var point_list = new BLL.MonitorPoint().QueryExSignalList(_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().QueryByBelongTypeAndBelongId(_projectId, belongType, belongId);
|
var point_list = new BLL.MonitorPoint().QueryExSignalListByBelongTypeAndBelongId(_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)));
|
}
|
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();
|
point_list.ForEach(x => _allBindingList.Add(new CurrentViewModel(x)));
|
}
|
this.treeList1.DataSource = _allBindingList;
|
this.treeList1.ForceInitialize();
|
this.treeList1.ExpandAll();
|
}
|
|
//全部展开
|
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 List<Color> _colorArray = new List<Color>() { Color.Blue, Color.DarkCyan,Color.MediumTurquoise,Color.MediumSeaGreen, Color.GreenYellow
|
, Color.IndianRed,Color.Chocolate,Color.Orange,Color.Bisque,Color.SlateBlue,Color.Violet,Color.SkyBlue,Color.LightGreen};
|
//Check改变
|
private void treeList1_AfterCheckNode(object sender, DevExpress.XtraTreeList.NodeEventArgs e)
|
{
|
if (_allBindingList == null)
|
return;
|
if (_allBindingList.Where(x => x.ObjectType != "监测点组" && x.Checked == true).Count() > 11)
|
{
|
XtraMessageBox.Show("目前最多支持十个展示!");
|
return;
|
}
|
var node = this.treeList1.GetDataRecordByNode(e.Node) as CurrentViewModel;
|
if (node == null)
|
return;
|
if (node.ObjectType != "监测点")
|
return;
|
var monitorPoint = node.Model as Model.MonitorPointExSignalList;
|
if (monitorPoint == null)
|
return;
|
if (e.Node.Checked)
|
{
|
node.Color = QueryColor();
|
this.SelectedEvent?.Invoke(monitorPoint, node.Color.Value);
|
}
|
else
|
{
|
node.Color = null;
|
this.UncheckEvent?.Invoke(monitorPoint);
|
}
|
}
|
|
Color QueryColor()
|
{
|
foreach(var c in _colorArray)
|
{
|
var f = _allBindingList.Find(x => x.Color == c);
|
if (f == null)
|
return c;
|
}
|
return Color.Black;
|
}
|
|
//隐藏父节点多选框
|
private void treeList1_CustomDrawNodeCheckBox(object sender, DevExpress.XtraTreeList.CustomDrawNodeCheckBoxEventArgs e)
|
{
|
TreeList _curTree = (TreeList)sender;
|
HideCheckBox(n => (this.treeList1.GetDataRecordByNode(n) as CurrentViewModel)?.ObjectType == "监测点组", e);
|
}
|
|
/// <summary>
|
|
public static void HideCheckBox(Predicate<TreeListNode> conditionHanlder, CustomDrawNodeCheckBoxEventArgs e)
|
{
|
if (conditionHanlder(e.Node))
|
{
|
e.Handled = true;
|
}
|
}
|
/// <summary>
|
/// /
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void barClearSelect_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (_allBindingList == null)
|
return;
|
|
|
foreach (var item in _allBindingList)
|
{
|
if(item.Checked == true)
|
{
|
item.Checked = false;
|
|
var monitorPoint = item.Model as Model.MonitorPointExSignalList;
|
if (monitorPoint == null)
|
continue;
|
this.UncheckEvent?.Invoke(monitorPoint );
|
}
|
}
|
this.treeList1.DataSource = _allBindingList;
|
this.treeList1.RefreshDataSource();
|
}
|
|
private void treeList1_CustomDrawNodeCell(object sender, CustomDrawNodeCellEventArgs e)
|
{
|
var node = this.treeList1.GetDataRecordByNode(e.Node) as CurrentViewModel;
|
if (node == null)
|
return;
|
if (node.Color == null)
|
return;
|
e.Appearance.ForeColor = node.Color.Value;
|
}
|
}
|
}
|