NodeManager.cs
4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DeviceLibrary.manager;
using System.Windows.Forms;
using System.Drawing;
namespace DeviceLibrary.manager
{
public class NodeManager
{
/// <summary>
/// 节点信息
/// </summary>
public static List<Node> nodeInfo;
public static void InitNodesInfos()
{
nodeInfo = new List<Node>();
XmlConfigOpManager.LoadNodeInfos(nodeInfo);
}
public static void InitView(DataGridView DgvNode)
{
//BindingSource bindingSource = new BindingSource();
//foreach (Node node in NodeManager.nodeInfo)
//{
// if (!node.Type.Equals(NodeType.Node))
// continue;
// bindingSource.Add(node);
//}
//DgvNode.AutoGenerateColumns = false;
//DgvNode.AutoSize = true;
//DgvNode.DataSource = bindingSource;
//DgvNode.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "名称",DataPropertyName="AliceName" });
//DgvNode.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "IP",DataPropertyName= "IP" });
//DgvNode.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "动作", DataPropertyName = "nodeStatus" });
//DgvNode.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "等级", DataPropertyName = "ClientLevel" });
//DgvNode.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "RFID", DataPropertyName = "RFID" });
//DgvNode.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "状态", DataPropertyName = "Online" });
//DgvNode.Columns.Add(new DataGridViewCheckBoxColumn() { HeaderText = "启用", DataPropertyName = "IsUse" });
//DgvNode.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
//for (int n = 0; n < DgvNode.Rows.Count; n++)
//{
// if (n % 2 == 0)
// DgvNode.Rows[n].DefaultCellStyle.BackColor = Color.LightBlue;
//}
int n;
DgvNode.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "名称", });
DgvNode.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "IP" });
DgvNode.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "动作" });
DgvNode.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "等级" });
DgvNode.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "RFID" });
DgvNode.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "状态" });
DgvNode.Columns.Add(new DataGridViewButtonColumn() { HeaderText = "启用" });
DgvNode.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
for (int i = 0; i < NodeManager.nodeInfo.Count; i++)
{
//if (!NodeManager.nodeInfo[i].Type.Equals(NodeType.Node))
// continue;
n = DgvNode.Rows.Add(NodeManager.nodeInfo[i].ToRow());
DgvNode.Rows[n].HeaderCell.Value = (n + 1).ToString();
if (i % 2 == 0)
DgvNode.Rows[n].DefaultCellStyle.BackColor = Color.LightBlue;
if (!NodeManager.nodeInfo[i].Online)
DgvNode.Rows[n].DefaultCellStyle.ForeColor = Color.Red;
}
}
public static Node GetNodeById(int id)
{
return nodeInfo.Find(s=>s.Id.Equals(id));
}
public static Node GetNodeByName(string name)
{
return nodeInfo.Find(s => s.Name.Equals(name));
}
public static Node GetNodeByType(NodeType nodeType = NodeType.AutoCharge)
{
return nodeInfo.Find(s => s.Type.Equals(nodeType));
}
/// <summary>
/// 是否存在节点
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static bool HasNode(string name)
{
int idx = nodeInfo.FindIndex(s=>s.Name.Equals(name));
return idx == -1 ? false : true;
}
}
}