-
Notifications
You must be signed in to change notification settings - Fork 0
/
SettingsForm.cs
248 lines (202 loc) · 7.84 KB
/
SettingsForm.cs
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using Aveva.Pdms.Database;
using Aveva.PDMS.Database.Filters;
namespace Polymetal.Pdms.Design.DrawListManager
{
public partial class SettingsForm : Form
{
private bool _permitCheck;
private static readonly DbElementType[] Types =
{DbElementTypeInstance.EQUIPMENT, DbElementTypeInstance.BRANCH, DbElementTypeInstance.SCTN,
DbElementTypeInstance.FLOOR,DbElementTypeInstance.GWALL, DbElementTypeInstance.PANEL,
DbElementTypeInstance.CABLE, DbElementTypeInstance.CWBRAN};
internal List<DbElement> ListofElements = new List<DbElement>();
public SettingsForm()
{
InitializeComponent();
FillTreeView();
}
#region Events
private void TreeViewFilterAfterCheck(object sender, TreeViewEventArgs e)
{
if (_permitCheck)
return;
_permitCheck = true;
CheckParent(e.Node);
CheckChilds(e.Node, e.Node.Checked);
_permitCheck = false;
}
private static void CheckChilds(TreeNode root, bool check)
{
foreach (TreeNode node in root.Nodes)
{
node.Checked = check;
CheckChilds(node, check);
}
}
private static void CheckParent(TreeNode child)
{
var root = child.Parent;
if (root == null) return;
var checkedChilds = 0;
foreach (TreeNode node in root.Nodes)
{
if (node.Checked)
{
checkedChilds++;
}
}
var rChecked = root.Checked;
root.Checked = checkedChilds == root.Nodes.Count;
if (rChecked != root.Checked)
CheckParent(root);
}
private void SettingsForm_FormClosed(object sender, FormClosedEventArgs e)
{
CheckedElements();
}
private void SettingsForm_Load(object sender, EventArgs e)
{
foreach (TreeNode elem in treeView1.Nodes)
{
elem.Expand();
}
}
#endregion
#region Functions
private void FillTreeView()
{
treeView1.Nodes.Clear();
treeView2.Nodes.Clear();
var world = DbElement.GetElement("/*");
var siteList = new List<DbElement>();
var projList = new List<string>();
foreach (var site in world.Members(DbElementTypeInstance.SITE))
{
if (!site.GetAsString(DbAttributeInstance.PURP).ToUpper().Equals("JOB")) continue;
siteList.Add(site);
var projName = site.GetAsString(DbAttributeInstance.FLNN).Split('-')[0];
if (projList.Contains(projName)) continue;
projList.Add(projName);
}
foreach (var projName in projList)
{
var proektSite = "Проект " + projName;
var proekts = treeView1.Nodes.Add(proektSite);
proekts.ImageIndex = -1;
proekts.SelectedImageIndex = -1;
foreach (var site in siteList)
{
var siteName = site.GetAsString(DbAttributeInstance.FLNN);
if (!siteName.StartsWith(projName)) continue;
var splitName = siteName.Split('-');
var otdelName = splitName.Length > 1 ? "Отдел " + splitName[1] : siteName;
var otdels = proekts.Nodes.Add(site.GetAsString(DbAttributeInstance.REF), otdelName, 1, 1);
foreach (var zone in site.Members(DbElementTypeInstance.ZONE))
{
var spec = zone.GetAsString(DbAttributeInstance.FLNN).Replace(site.GetAsString(DbAttributeInstance.FLNN), "");
otdels.Nodes.Add(zone.GetAsString(DbAttributeInstance.REF), spec.Substring(spec.IndexOf("-", StringComparison.Ordinal) + 1), 2, 2);
}
}
proekts.Expand();
}
foreach (var dbtype in Types)
{
var node = treeView2.Nodes.Add(dbtype.ToString());
node.Checked = !dbtype.Equals(DbElementTypeInstance.CABLE) & !dbtype.Equals(DbElementTypeInstance.CWBRAN);
}
}
internal List<DbElement> GetCheckedRoots()
{
var list = new List<DbElement>();
foreach (TreeNode proj in treeView1.Nodes)
{
foreach (TreeNode site in proj.Nodes)
{
if (site.Checked)
{
var item = DbElement.GetElement(site.Name);
if (!item.IsNull)
list.Add(item);
}
else
{
foreach (TreeNode zone in site.Nodes)
{
if (!zone.Checked) continue;
var item = DbElement.GetElement(zone.Name);
if (!item.IsNull)
list.Add(item);
}
}
}
}
return list;
}
private List<DbElement> GetUnCheckedRoots()
{
var list = new List<DbElement>();
foreach (TreeNode element in treeView1.Nodes)
{
foreach (TreeNode node in element.Nodes)
{
var item = DbElement.GetElement(node.Name);
if (!item.IsNull)
list.Add(item);
}
}
return list;
}
internal List<DbElementType> GetCheckedTypes()
{
var list = new List<DbElementType>();
foreach (TreeNode element in treeView2.Nodes)
{
if (element.Checked)
{
list.Add(DbElementType.GetElementType(element.Text));
}
}
return list;
}
private void CheckedElements()
{
ListofElements = new List<DbElement>();
var roots = GetCheckedRoots();
var typeFilterList = new List<DbElementType>();
foreach (TreeNode element in treeView2.Nodes)
{
if (element.Checked)
{
typeFilterList.Add(DbElementType.GetElementType(element.Text));
}
}
foreach (var root in roots)
{
ListofElements.AddRange(new DBElementCollection(root, new TypeFilter(typeFilterList.ToArray())).Cast<DbElement>().ToList());
}
}
internal void CheckAllElements()
{
ListofElements = new List<DbElement>();
var roots = GetUnCheckedRoots();
var typeFilterList = new List<DbElementType>();
foreach (TreeNode element in treeView2.Nodes)
{
if (element.Checked)
{
typeFilterList.Add(DbElementType.GetElementType(element.Text));
}
}
foreach (var root in roots)
{
ListofElements.AddRange(new DBElementCollection(root, new TypeFilter(typeFilterList.ToArray())).Cast<DbElement>().ToList());
}
}
#endregion
}
}