hytos / DTI_PID / ID2PSN / PSN.cs @ a5616391
이력 | 보기 | 이력해설 | 다운로드 (106 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Data; |
4 |
using System.IO; |
5 |
using System.Linq; |
6 |
using System.Text; |
7 |
using System.Threading.Tasks; |
8 |
using ID2PSN.Properties; |
9 |
using System.Text.RegularExpressions; |
10 |
using System.Windows.Forms; |
11 |
|
12 |
namespace ID2PSN |
13 |
{ |
14 |
public enum PSNType |
15 |
{ |
16 |
None, |
17 |
Branch, |
18 |
Equipment, |
19 |
Header, |
20 |
Symbol, |
21 |
OPC, |
22 |
} |
23 |
|
24 |
public enum ErrorType |
25 |
{ |
26 |
Error = -1, |
27 |
OK, |
28 |
InValid //이값은 들어가는데가 없음.. |
29 |
} |
30 |
|
31 |
public class PSN |
32 |
{ |
33 |
private double[] DrawingSize = null; |
34 |
private double DrawingWidth = double.NaN; |
35 |
private double DrawingHeight = double.NaN; |
36 |
public int Revision; |
37 |
public string EquipTagNoAttributeName = string.Empty; |
38 |
public DataTable PathItems { get; set; } |
39 |
public DataTable SequenceData { get; set; } |
40 |
public DataTable PipeSystemNetwork { get; set; } |
41 |
public DataTable TopologySet { get; set; } |
42 |
public DataTable Equipment { get; set; } |
43 |
public DataTable Nozzle { get; set; } |
44 |
public DataTable PipeLine { get; set; } |
45 |
|
46 |
public string Rule1 = "Line Disconnected"; |
47 |
public string Rule2 = "Missing LineNumber"; //토폴로지데이터가 = Empty LineNumber 인것 ??.. |
48 |
public string Rule3 = "OPC Disconneted"; |
49 |
public string Rule4 = "Missing ItemTag or Description"; |
50 |
public string Rule5 = ""; |
51 |
|
52 |
int tieInPointIndex = 1; |
53 |
|
54 |
List<Document> Documents; |
55 |
List<Group> groups = new List<Group>(); |
56 |
List<PSNItem> PSNItems = new List<PSNItem>(); |
57 |
List<Topology> Topologies = new List<Topology>(); |
58 |
|
59 |
DataTable opcDT = null; |
60 |
DataTable topologyRuleDT = null; |
61 |
|
62 |
ID2Info id2Info = ID2Info.GetInstance(); |
63 |
|
64 |
|
65 |
|
66 |
//const string FluidPriorityType = "FLUIDCODE"; |
67 |
//const string PipingMaterialsPriorityType = "PIPINGMATERIALSCLASS"; |
68 |
|
69 |
public PSN() |
70 |
{ |
71 |
|
72 |
} |
73 |
|
74 |
public PSN(List<Document> documents, int Revision) |
75 |
{ |
76 |
try |
77 |
{ |
78 |
Documents = documents; |
79 |
foreach (Document document in Documents) |
80 |
groups.AddRange(document.Groups); |
81 |
opcDT = GetOPCInfo(); |
82 |
topologyRuleDT = GetTopologyRule(); |
83 |
this.Revision = Revision; |
84 |
DrawingSize = DB.GetDrawingSize(); |
85 |
if (DrawingSize == null) |
86 |
{ |
87 |
MessageBox.Show("There is no data whose Section is Area and Key is Drawing in the drawing table.", "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
88 |
return; |
89 |
} |
90 |
DrawingWidth = DrawingSize[2] - DrawingSize[0]; |
91 |
DrawingHeight = DrawingSize[3] - DrawingSize[1]; |
92 |
} |
93 |
catch (Exception ex) |
94 |
{ |
95 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
96 |
MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
97 |
} |
98 |
} |
99 |
|
100 |
private string GetItemTag(Item item) |
101 |
{ |
102 |
string result = string.Empty; |
103 |
if (item.ItemType == ItemType.Line) |
104 |
result = item.LineNumber != null ? item.LineNumber.Name : string.Empty; |
105 |
else if (item.ItemType == ItemType.Symbol && item.SubItemType == SubItemType.Nozzle) |
106 |
result = Nozzle.Select(string.Format("OID = '{0}'", item.UID)).First()["ITEMTAG"].ToString(); |
107 |
|
108 |
return result; |
109 |
} |
110 |
private string GetItemName(Item item, string itemOID) |
111 |
{ |
112 |
string result = string.Empty; |
113 |
if (item.ItemType == ItemType.Line && (item.Name == "Secondary" || item.Name == "Primary")) |
114 |
{ |
115 |
if (itemOID.Contains("_")) |
116 |
{ |
117 |
string split = itemOID.Split(new char[] { '_' })[1]; |
118 |
if (split.StartsWith("B")) |
119 |
result = "Branch"; |
120 |
else |
121 |
result = "PipeRun"; |
122 |
} |
123 |
else |
124 |
result = "PipeRun"; |
125 |
} |
126 |
else if (item.ItemType == ItemType.Symbol) |
127 |
{ |
128 |
if (item.ID2DBCategory == "Instrumentation") |
129 |
result = "Instrument"; |
130 |
else if (item.ID2DBType == "Nozzles") |
131 |
result = "Nozzle"; |
132 |
else if (item.ID2DBType == "Fittings" || |
133 |
item.ID2DBType == "Piping OPC's" || |
134 |
item.ID2DBType == "Specialty Components" || |
135 |
item.ID2DBType == "Valves" || |
136 |
item.ID2DBType == "Reducers") |
137 |
result = "PipingComp"; |
138 |
} |
139 |
return result; |
140 |
} |
141 |
|
142 |
private string GetClass(Item item, string itemOID) |
143 |
{ |
144 |
string result = string.Empty; |
145 |
if (item.ItemType == ItemType.Line && (item.Name == "Secondary" || item.Name == "Primary")) |
146 |
{ |
147 |
if (itemOID.Contains("_")) |
148 |
{ |
149 |
string split = itemOID.Split(new char[] { '_' })[1]; |
150 |
if (split.StartsWith("B")) |
151 |
result = "Branch"; |
152 |
else |
153 |
result = "Piping"; |
154 |
} |
155 |
else |
156 |
result = "Piping"; |
157 |
} |
158 |
else if (item.ItemType == ItemType.Symbol) |
159 |
{ |
160 |
if (item.ID2DBCategory == "Instrumentation") |
161 |
result = item.ID2DBType; |
162 |
else if (item.ID2DBType == "Nozzles") |
163 |
result = string.Empty; |
164 |
else if (item.ID2DBType == "Fittings" || |
165 |
item.ID2DBType == "Piping OPC's" || |
166 |
item.ID2DBType == "Specialty Components" || |
167 |
item.ID2DBType == "Valves" || |
168 |
item.ID2DBType == "Reducers") |
169 |
result = item.ID2DBType; |
170 |
} |
171 |
return result; |
172 |
} |
173 |
|
174 |
private string GetSubClass(Item item, string itemOID) |
175 |
{ |
176 |
string result = string.Empty; |
177 |
if (item.ItemType == ItemType.Line && (item.Name == "Secondary" || item.Name == "Primary")) |
178 |
{ |
179 |
if (itemOID.Contains("_")) |
180 |
{ |
181 |
string split = itemOID.Split(new char[] { '_' })[1]; |
182 |
if (split.StartsWith("B")) |
183 |
result = "Tee"; |
184 |
else |
185 |
result = ""; |
186 |
} |
187 |
else |
188 |
result = ""; |
189 |
} |
190 |
else if (item.ItemType == ItemType.Symbol) |
191 |
{ |
192 |
if (item.ID2DBCategory == "Instrumentation") |
193 |
result = string.Empty; |
194 |
else if (item.ID2DBType == "Nozzles") |
195 |
result = string.Empty; |
196 |
else if (item.ID2DBType == "Fittings" || |
197 |
item.ID2DBType == "Piping OPC's" || |
198 |
item.ID2DBType == "Specialty Components" || |
199 |
item.ID2DBType == "Valves" || |
200 |
item.ID2DBType == "Reducers") |
201 |
result = "In-line component"; |
202 |
} |
203 |
return result; |
204 |
} |
205 |
|
206 |
public void SetPSNData() |
207 |
{ |
208 |
// Item들의 속성으로 Topology Data를 생성한다. |
209 |
// Topology Data는 Topology Rule Setting을 기준으로 생성한다. |
210 |
SetTopologyData(); |
211 |
// ID2의 OPC연결 Data 기반으로 Group(도면단위 PSN)을 연결한다. |
212 |
ConnectByOPC(); |
213 |
// 실제 PSN 생성 로직 |
214 |
// 연결된 Group을 하나의 PSN으로 만든다. |
215 |
SetPSNItem(); |
216 |
// 생성된 PSN의 Type을 설정한다. |
217 |
SetPSNType(); |
218 |
// ID2에는 Branch 정보가 없어서 Branch 정보를 생성한다. |
219 |
SetBranchInfo(); |
220 |
// 생성된 Topology Data들을 정리하며 Main, Branch를 판단한다. |
221 |
SetTopology(); |
222 |
// PSN이 Bypass인지 검사 |
223 |
SetPSNBypass(); |
224 |
// Topology들에게 Index를 부여한다 |
225 |
SetTopologyIndex(); |
226 |
// Nozzle, Equipment의 정보를 저장 |
227 |
SaveNozzleAndEquipment(); |
228 |
// PSN의 정보를 저장 |
229 |
SavePSNData(); |
230 |
// Topology의 subtype을 update(bypass, Header, 등등) |
231 |
UpdateSubType(); |
232 |
// Update Error |
233 |
UpdateErrorForPSN(); |
234 |
// Update Keyword |
235 |
//UpdateKeywordForPSN(); |
236 |
|
237 |
// 확도 계산 |
238 |
UpdateAccuracy(); |
239 |
} |
240 |
|
241 |
private void SetTopologyData() |
242 |
{ |
243 |
// 13번 excel |
244 |
foreach (Group group in groups) |
245 |
{ |
246 |
LineNumber prevLineNumber = null; |
247 |
for (int i = 0; i < group.Items.Count; i++) |
248 |
{ |
249 |
Item item = group.Items[i]; |
250 |
LineNumber lineNumber = item.Document.LineNumbers.Find(x => x.UID == item.Owner); |
251 |
if (lineNumber == null) |
252 |
{ |
253 |
if (prevLineNumber != null) |
254 |
{ |
255 |
if (!prevLineNumber.IsCopy) |
256 |
{ |
257 |
prevLineNumber = prevLineNumber.Copy(); |
258 |
item.Document.LineNumbers.Add(prevLineNumber); |
259 |
} |
260 |
|
261 |
item.Owner = prevLineNumber.UID; |
262 |
} |
263 |
} |
264 |
else |
265 |
prevLineNumber = lineNumber; |
266 |
} |
267 |
|
268 |
prevLineNumber = null; |
269 |
for (int i = group.Items.Count - 1; i > -1; i--) |
270 |
{ |
271 |
Item item = group.Items[i]; |
272 |
LineNumber lineNumber = item.Document.LineNumbers.Find(x => x.UID == item.Owner); |
273 |
if (lineNumber == null) |
274 |
{ |
275 |
if (prevLineNumber != null) |
276 |
{ |
277 |
if (!prevLineNumber.IsCopy) |
278 |
{ |
279 |
prevLineNumber = prevLineNumber.Copy(); |
280 |
item.Document.LineNumbers.Add(prevLineNumber); |
281 |
} |
282 |
|
283 |
item.Owner = prevLineNumber.UID; |
284 |
} |
285 |
} |
286 |
else |
287 |
prevLineNumber = lineNumber; |
288 |
} |
289 |
|
290 |
if (prevLineNumber == null) |
291 |
{ |
292 |
List<LineNumber> lineNumbers = group.Document.LineNumbers.FindAll(x => !x.IsCopy); |
293 |
Random random = new Random(); |
294 |
int index = random.Next(lineNumbers.Count - 1); |
295 |
|
296 |
// Copy |
297 |
LineNumber cLineNumber = lineNumbers[index].Copy(); |
298 |
group.Document.LineNumbers.Add(cLineNumber); |
299 |
|
300 |
foreach (Item item in group.Items) |
301 |
item.Owner = cLineNumber.UID; |
302 |
} |
303 |
} |
304 |
|
305 |
foreach (Document document in Documents) |
306 |
{ |
307 |
foreach (Item item in document.Items) |
308 |
{ |
309 |
item.TopologyData = string.Empty; |
310 |
item.PSNPipeLineID = string.Empty; |
311 |
List<string> pipeLineID = new List<string>(); |
312 |
LineNumber lineNumber = document.LineNumbers.Find(x => x.UID == item.Owner); |
313 |
if (lineNumber != null) |
314 |
{ |
315 |
item.LineNumber = lineNumber; |
316 |
|
317 |
foreach (DataRow row in topologyRuleDT.Rows) |
318 |
{ |
319 |
string uid = row["UID"].ToString(); |
320 |
//if (uid == "-") |
321 |
// pipeLineID.Add(item.TopologyData);//item.TopologyData += "-"; |
322 |
if (uid != "-") |
323 |
{ |
324 |
Attribute itemAttr = item.Attributes.Find(x => x.Name == uid); |
325 |
|
326 |
Attribute attribute = lineNumber.Attributes.Find(x => x.Name == uid); |
327 |
if (attribute != null && !string.IsNullOrEmpty(attribute.Value)) |
328 |
pipeLineID.Add(attribute.Value);//item.TopologyData += attribute.Value; |
329 |
} |
330 |
} |
331 |
|
332 |
if(topologyRuleDT.Select(string.Format("UID = '{0}'", "InsulationPurpose")) == null) |
333 |
{ |
334 |
Attribute insulAttr = item.LineNumber.Attributes.Find(x => x.Name == "InsulationPurpose"); |
335 |
if (insulAttr != null && !string.IsNullOrEmpty(insulAttr.Value)) |
336 |
pipeLineID.Add(insulAttr.Value); //item.PSNPipeLineID = item.TopologyData + "-" + insulAttr.Value; |
337 |
//else |
338 |
// item.PSNPipeLineID = item.TopologyData; |
339 |
} |
340 |
|
341 |
item.PSNPipeLineID = string.Join("-", pipeLineID); |
342 |
item.TopologyData = string.Join("-", pipeLineID); |
343 |
} |
344 |
else |
345 |
{ |
346 |
item.TopologyData = "Empty LineNumber"; |
347 |
item.LineNumber = new LineNumber(); |
348 |
} |
349 |
} |
350 |
} |
351 |
|
352 |
int emptyIndex = 1; |
353 |
foreach (Group group in groups) |
354 |
{ |
355 |
List<Item> groupItems = group.Items.FindAll(x => x.TopologyData == "Empty LineNumber"); |
356 |
if (groupItems.Count > 0) |
357 |
{ |
358 |
foreach (var item in groupItems) |
359 |
item.TopologyData += string.Format("-{0}", emptyIndex); |
360 |
emptyIndex++; |
361 |
} |
362 |
} |
363 |
|
364 |
} |
365 |
|
366 |
private void ConnectByOPC() |
367 |
{ |
368 |
try |
369 |
{ |
370 |
foreach (Group group in groups.FindAll(x => x.Items.Last().SubItemType == SubItemType.OPC)) |
371 |
{ |
372 |
Item opcItem = group.Items.Last(); |
373 |
DataRow[] fromRows = opcDT.Select(string.Format("FromOPCUID = '{0}'", opcItem.UID)); |
374 |
if (fromRows.Length.Equals(1)) |
375 |
{ |
376 |
DataRow opcRow = fromRows.First(); |
377 |
string toDrawing = opcRow["ToDrawing"].ToString(); |
378 |
string toOPCUID = opcRow["ToOPCUID"].ToString(); |
379 |
|
380 |
Document toDocument = Documents.Find(x => x.DrawingName == toDrawing); |
381 |
if (toDocument != null) |
382 |
{ |
383 |
Group toGroup = toDocument.Groups.Find(x => x.Items.Find(y => y.UID == toOPCUID) != null); |
384 |
DataRow[] toRows = opcDT.Select(string.Format("ToOPCUID = '{0}'", toGroup.Items.First().UID)); |
385 |
//1대1 매칭이 아닐때 걸림 (2개 이상일 때) 2021.11.07 |
386 |
if (toRows.Length > 1) |
387 |
{ |
388 |
//throw new Exception("OPC error(multi connect)"); |
389 |
MessageBox.Show("OPC error(multi connect)", "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
390 |
return; |
391 |
} |
392 |
group.EndGroup = toGroup; |
393 |
toGroup.StartGroup = group; |
394 |
} |
395 |
} |
396 |
} |
397 |
} |
398 |
catch (Exception ex) |
399 |
{ |
400 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
401 |
//MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
402 |
} |
403 |
} |
404 |
|
405 |
private void SetPSNItem() |
406 |
{ |
407 |
Dictionary<Group, string> groupDic = new Dictionary<Group, string>(); |
408 |
foreach (Group group in groups) |
409 |
groupDic.Add(group, Guid.NewGuid().ToString()); |
410 |
|
411 |
foreach (Group group in groups) |
412 |
{ |
413 |
string groupKey = groupDic[group]; |
414 |
if (group.StartGroup != null) |
415 |
{ |
416 |
string otherKey = groupDic[group.StartGroup]; |
417 |
ChangeGroupID(otherKey, groupKey); |
418 |
} |
419 |
} |
420 |
|
421 |
// PSN 정리 |
422 |
foreach (var item in groupDic) |
423 |
{ |
424 |
Group group = item.Key; |
425 |
string uid = item.Value; |
426 |
PSNItem PSNItem = PSNItems.Find(x => x.UID == uid); |
427 |
if (PSNItem == null) |
428 |
{ |
429 |
PSNItem = new PSNItem(PSNItems.Count, Revision) { UID = uid }; |
430 |
PSNItems.Add(PSNItem); |
431 |
} |
432 |
PSNItem.Groups.Add(group); |
433 |
foreach (Item groupItem in group.Items) |
434 |
groupItem.PSNItem = PSNItem; |
435 |
} |
436 |
|
437 |
// Sort PSN |
438 |
foreach (PSNItem PSNItem in PSNItems) |
439 |
{ |
440 |
List<Group> _groups = new List<Group>(); |
441 |
|
442 |
Stack<Group> stacks = new Stack<Group>(); |
443 |
stacks.Push(PSNItem.Groups.First()); |
444 |
while (stacks.Count > 0) |
445 |
{ |
446 |
Group stack = stacks.Pop(); |
447 |
if (_groups.Contains(stack)) |
448 |
continue; |
449 |
|
450 |
if (_groups.Count == 0) |
451 |
_groups.Add(stack); |
452 |
else |
453 |
{ |
454 |
if (stack.StartGroup != null && _groups.Contains(stack.StartGroup)) |
455 |
{ |
456 |
int index = _groups.IndexOf(stack.StartGroup); |
457 |
_groups.Insert(index + 1, stack); |
458 |
} |
459 |
else if (stack.EndGroup != null && _groups.Contains(stack.EndGroup)) |
460 |
{ |
461 |
int index = _groups.IndexOf(stack.EndGroup); |
462 |
_groups.Insert(index, stack); |
463 |
} |
464 |
} |
465 |
|
466 |
if (stack.StartGroup != null) |
467 |
stacks.Push(stack.StartGroup); |
468 |
if (stack.EndGroup != null) |
469 |
stacks.Push(stack.EndGroup); |
470 |
} |
471 |
|
472 |
PSNItem.Groups.Clear(); |
473 |
PSNItem.Groups.AddRange(_groups); |
474 |
} |
475 |
|
476 |
void ChangeGroupID(string from, string to) |
477 |
{ |
478 |
if (from.Equals(to)) |
479 |
return; |
480 |
|
481 |
List<Group> changeItems = new List<Group>(); |
482 |
foreach (var _item in groupDic) |
483 |
if (_item.Value.Equals(from)) |
484 |
changeItems.Add(_item.Key); |
485 |
foreach (var _item in changeItems) |
486 |
groupDic[_item] = to; |
487 |
} |
488 |
} |
489 |
|
490 |
private void SetPSNType() |
491 |
{ |
492 |
foreach (PSNItem PSNItem in PSNItems) |
493 |
{ |
494 |
Group firstGroup = PSNItem.Groups.First(); |
495 |
Group lastGroup = PSNItem.Groups.Last(); |
496 |
|
497 |
Item firstItem = firstGroup.Items.First(); |
498 |
Item lastItem = lastGroup.Items.Last(); |
499 |
|
500 |
PSNItem.StartType = GetPSNType(firstItem, true); |
501 |
PSNItem.EndType = GetPSNType(lastItem, false); |
502 |
} |
503 |
|
504 |
PSNType GetPSNType(Item item, bool bFirst = true) |
505 |
{ |
506 |
PSNType type = PSNType.None; |
507 |
|
508 |
if (item.ItemType == ItemType.Line) |
509 |
{ |
510 |
Group group = groups.Find(x => x.Items.Contains(item)); |
511 |
if (bFirst && item.Relations[0].Item != null && !group.Items.Contains(item.Relations[0].Item)) |
512 |
{ |
513 |
Item connItem = item.Relations[0].Item; |
514 |
if (connItem.ItemType == ItemType.Line && !IsConnected(item, connItem)) |
515 |
type = PSNType.Branch; |
516 |
else if (connItem.ItemType == ItemType.Symbol) |
517 |
type = PSNType.Symbol; |
518 |
} |
519 |
else if (!bFirst && item.Relations[1].Item != null && !group.Items.Contains(item.Relations[1].Item)) |
520 |
{ |
521 |
Item connItem = item.Relations[1].Item; |
522 |
if (connItem.ItemType == ItemType.Line && !IsConnected(item, connItem)) |
523 |
type = PSNType.Branch; |
524 |
else if (connItem.ItemType == ItemType.Symbol) |
525 |
type = PSNType.Symbol; |
526 |
} |
527 |
} |
528 |
else if (item.ItemType == ItemType.Symbol) |
529 |
{ |
530 |
if (item.SubItemType == SubItemType.Nozzle) |
531 |
type = PSNType.Equipment; |
532 |
else if (item.SubItemType == SubItemType.Header) |
533 |
type = PSNType.Header; |
534 |
else if (item.SubItemType == SubItemType.OPC) |
535 |
type = PSNType.OPC; |
536 |
} |
537 |
|
538 |
return type; |
539 |
} |
540 |
} |
541 |
|
542 |
private void SetBranchInfo() |
543 |
{ |
544 |
foreach (Document document in Documents) |
545 |
{ |
546 |
List<Item> lines = document.Items.FindAll(x => x.ItemType == ItemType.Line).ToList(); |
547 |
foreach (Item line in lines) |
548 |
{ |
549 |
double[] point = line.Relations[0].Point; |
550 |
List<Item> connLines = lines.FindAll(x => x.Relations.Find(y => y.UID == line.UID) != null && line.Relations.Find(y => y.UID == x.UID) == null); |
551 |
connLines.Sort(SortBranchLine); |
552 |
line.BranchItems.AddRange(connLines); |
553 |
|
554 |
int SortBranchLine(Item a, Item b) |
555 |
{ |
556 |
double[] pointA = a.Relations[0].UID == line.UID ? a.Relations[0].Point : a.Relations[1].Point; |
557 |
double distanceA = CalcPointToPointdDistance(point[0], point[1], pointA[0], pointA[1]); |
558 |
|
559 |
double[] pointB = b.Relations[0].UID == line.UID ? b.Relations[0].Point : b.Relations[1].Point; |
560 |
double distanceB = CalcPointToPointdDistance(point[0], point[1], pointB[0], pointB[1]); |
561 |
|
562 |
// 내림차순 |
563 |
return distanceA.CompareTo(distanceB); |
564 |
} |
565 |
double CalcPointToPointdDistance(double x1, double y1, double x2, double y2) |
566 |
{ |
567 |
return Math.Pow(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2), 0.5); |
568 |
} |
569 |
} |
570 |
} |
571 |
} |
572 |
|
573 |
private void SetTopology() |
574 |
{ |
575 |
try |
576 |
{ |
577 |
#region 기본 topology 정리 |
578 |
foreach (PSNItem PSNItem in PSNItems) |
579 |
{ |
580 |
Topology topology = null; |
581 |
foreach (Group group in PSNItem.Groups) |
582 |
{ |
583 |
foreach (Item item in group.Items) |
584 |
{ |
585 |
if (string.IsNullOrEmpty(item.TopologyData)) |
586 |
topology = null; |
587 |
else |
588 |
{ |
589 |
if (topology == null) |
590 |
{ |
591 |
topology = new Topology() |
592 |
{ |
593 |
ID = item.TopologyData |
594 |
}; |
595 |
Topologies.Add(topology); |
596 |
|
597 |
if (!PSNItem.Topologies.Contains(topology)) |
598 |
PSNItem.Topologies.Add(topology); |
599 |
} |
600 |
else |
601 |
{ |
602 |
if (topology.ID != item.TopologyData) |
603 |
{ |
604 |
topology = new Topology() |
605 |
{ |
606 |
ID = item.TopologyData |
607 |
}; |
608 |
Topologies.Add(topology); |
609 |
|
610 |
if (!PSNItem.Topologies.Contains(topology)) |
611 |
PSNItem.Topologies.Add(topology); |
612 |
} |
613 |
} |
614 |
|
615 |
item.Topology = topology; |
616 |
topology.Items.Add(item); |
617 |
} |
618 |
} |
619 |
} |
620 |
} |
621 |
#endregion |
622 |
|
623 |
#region Type |
624 |
List<string> ids = Topologies.Select(x => x.ID).Distinct().ToList(); |
625 |
foreach (string id in ids) |
626 |
{ |
627 |
try |
628 |
{ |
629 |
|
630 |
|
631 |
List<Topology> topologies = Topologies.FindAll(x => x.ID == id); |
632 |
|
633 |
// Main |
634 |
List<Topology> mainTopologies = FindMainTopology(topologies); |
635 |
foreach (Topology topology in mainTopologies) |
636 |
topology.Type = "M"; |
637 |
|
638 |
// Branch |
639 |
List<Topology> branchToplogies = topologies.FindAll(x => string.IsNullOrEmpty(x.Type)); |
640 |
foreach (Topology topology in branchToplogies) |
641 |
topology.Type = "B"; |
642 |
} |
643 |
catch (Exception ex) |
644 |
{ |
645 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
646 |
MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
647 |
} |
648 |
} |
649 |
#endregion |
650 |
} |
651 |
catch (Exception ex) |
652 |
{ |
653 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
654 |
MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
655 |
} |
656 |
|
657 |
} |
658 |
|
659 |
private void SetTopologyIndex() |
660 |
{ |
661 |
List<string> ids = Topologies.Select(x => x.ID).Distinct().ToList(); |
662 |
foreach (string id in ids) |
663 |
{ |
664 |
List<Topology> topologies = Topologies.FindAll(x => x.ID == id); |
665 |
|
666 |
// Main |
667 |
List<Topology> mainTopologies = topologies.FindAll(x => x.Type == "M"); |
668 |
foreach (Topology topology in mainTopologies) |
669 |
topology.Index = mainTopologies.IndexOf(topology).ToString(); |
670 |
|
671 |
// Branch |
672 |
List<Topology> branchToplogies = topologies.FindAll(x => x.Type == "B"); |
673 |
foreach (Topology topology in branchToplogies) |
674 |
topology.Index = (branchToplogies.IndexOf(topology) + 1).ToString(); |
675 |
} |
676 |
} |
677 |
|
678 |
private void SetPSNBypass() |
679 |
{ |
680 |
foreach (PSNItem PSNItem in PSNItems) |
681 |
PSNItem.IsBypass = IsBypass(PSNItem); |
682 |
} |
683 |
|
684 |
private List<Topology> FindMainTopology(List<Topology> data) |
685 |
{ |
686 |
DataTable nominalDiameterDT = DB.SelectNominalDiameter(); |
687 |
DataTable PMCDT = DB.SelectPSNPIPINGMATLCLASS(); |
688 |
//2021.11.17 안쓰네 JY |
689 |
//DataTable fluidCodeDT = DB.SelectPSNFluidCode(); |
690 |
|
691 |
List<Topology> main = new List<Topology>(); |
692 |
main.AddRange(data); |
693 |
// |
694 |
main = GetNozzleTopology(data); |
695 |
if (main.Count == 1) |
696 |
return main; |
697 |
else |
698 |
{ |
699 |
if (main.Count > 0) |
700 |
main = GetPMCTopology(main); |
701 |
else |
702 |
main = GetPMCTopology(data); |
703 |
|
704 |
if (main.Count == 1) |
705 |
return main; |
706 |
else |
707 |
{ |
708 |
if (main.Count > 0) |
709 |
main = GetDiaTopology(main); |
710 |
else |
711 |
main = GetDiaTopology(data); |
712 |
|
713 |
|
714 |
if (main.Count == 1) |
715 |
return main; |
716 |
else |
717 |
{ |
718 |
if (main.Count > 0) |
719 |
main = GetItemTopology(main); |
720 |
else |
721 |
main = GetItemTopology(data); |
722 |
} |
723 |
} |
724 |
} |
725 |
|
726 |
List<Topology> GetNozzleTopology(List<Topology> topologies) |
727 |
{ |
728 |
return topologies.FindAll(x => x.Items.Find(y => y.SubItemType == SubItemType.Nozzle) != null); |
729 |
} |
730 |
|
731 |
List<Topology> GetPMCTopology(List<Topology> topologies) |
732 |
{ |
733 |
List<Topology> result = new List<Topology>(); |
734 |
foreach (DataRow row in PMCDT.Rows) |
735 |
{ |
736 |
string value = row["CODE"].ToString(); |
737 |
foreach (Topology topology in topologies) |
738 |
{ |
739 |
foreach (Item item in topology.Items) |
740 |
{ |
741 |
if (item.LineNumber == null) |
742 |
continue; |
743 |
Attribute attribute = item.LineNumber.Attributes.Find(x => x.Name == "PipingMaterialsClass"); |
744 |
if (attribute != null && value == attribute.Value) |
745 |
{ |
746 |
result.Add(topology); |
747 |
break; |
748 |
} |
749 |
} |
750 |
} |
751 |
|
752 |
if (result.Count > 0) |
753 |
break; |
754 |
} |
755 |
|
756 |
return result; |
757 |
} |
758 |
|
759 |
List<Topology> GetDiaTopology(List<Topology> topologies) |
760 |
{ |
761 |
List<Topology> result = new List<Topology>(); |
762 |
foreach (DataRow row in nominalDiameterDT.Rows) |
763 |
{ |
764 |
string inchValue = row["InchStr"].ToString(); |
765 |
string metricValue = row["MetricStr"].ToString(); |
766 |
foreach (Topology topology in topologies) |
767 |
{ |
768 |
foreach (Item item in topology.Items) |
769 |
{ |
770 |
if (item.LineNumber == null) |
771 |
continue; |
772 |
Attribute attribute = item.LineNumber.Attributes.Find(x => x.Name == "NominalDiameter"); |
773 |
if (attribute != null && (inchValue == attribute.Value || metricValue == attribute.Value)) |
774 |
{ |
775 |
result.Add(topology); |
776 |
break; |
777 |
} |
778 |
} |
779 |
} |
780 |
|
781 |
if (result.Count > 0) |
782 |
break; |
783 |
} |
784 |
|
785 |
return result; |
786 |
} |
787 |
|
788 |
List<Topology> GetItemTopology(List<Topology> topologies) |
789 |
{ |
790 |
return new List<Topology>() { topologies.OrderByDescending(x => x.Items.Count).ToList().First() }; |
791 |
} |
792 |
|
793 |
return main; |
794 |
} |
795 |
|
796 |
private DataTable GetOPCInfo() |
797 |
{ |
798 |
DataTable opc = DB.SelectOPCRelations(); |
799 |
DataTable drawing = DB.SelectDrawings(); |
800 |
|
801 |
DataTable dt = new DataTable(); |
802 |
dt.Columns.Add("FromDrawing", typeof(string)); |
803 |
dt.Columns.Add("FromDrawingUID", typeof(string)); |
804 |
dt.Columns.Add("FromOPCUID", typeof(string)); |
805 |
dt.Columns.Add("ToDrawing", typeof(string)); |
806 |
dt.Columns.Add("ToDrawingUID", typeof(string)); |
807 |
dt.Columns.Add("ToOPCUID", typeof(string)); |
808 |
foreach (DataRow row in opc.Rows) |
809 |
{ |
810 |
string fromDrawingUID = row["From_Drawings_UID"] == null ? string.Empty : row["From_Drawings_UID"].ToString(); |
811 |
string fromOPCUID = row["From_OPC_UID"] == null ? string.Empty : row["From_OPC_UID"].ToString(); |
812 |
string toDrawingUID = row["To_Drawings_UID"] == null ? string.Empty : row["To_Drawings_UID"].ToString(); |
813 |
string toOPCUID = row["To_OPC_UID"] == null ? string.Empty : row["To_OPC_UID"].ToString(); |
814 |
if (!string.IsNullOrEmpty(toOPCUID)) |
815 |
{ |
816 |
DataRow[] fromRows = drawing.Select(string.Format("UID = '{0}'", fromDrawingUID)); |
817 |
DataRow[] toRows = drawing.Select(string.Format("UID = '{0}'", toDrawingUID)); |
818 |
if (fromRows.Length.Equals(1) && toRows.Length.Equals(1)) |
819 |
{ |
820 |
string fromDrawingName = Path.GetFileNameWithoutExtension(fromRows.First()["NAME"].ToString()); |
821 |
string toDrawingName = Path.GetFileNameWithoutExtension(toRows.First()["NAME"].ToString()); |
822 |
|
823 |
DataRow newRow = dt.NewRow(); |
824 |
newRow["FromDrawing"] = fromDrawingName; |
825 |
newRow["FromDrawingUID"] = fromDrawingUID; |
826 |
newRow["FromOPCUID"] = fromOPCUID; |
827 |
newRow["ToDrawing"] = toDrawingName; |
828 |
newRow["ToDrawingUID"] = toDrawingUID; |
829 |
newRow["ToOPCUID"] = toOPCUID; |
830 |
|
831 |
dt.Rows.Add(newRow); |
832 |
} |
833 |
} |
834 |
} |
835 |
|
836 |
return dt; |
837 |
} |
838 |
|
839 |
private DataTable GetTopologyRule() |
840 |
{ |
841 |
DataTable dt = DB.SelectTopologyRule(); |
842 |
|
843 |
return dt; |
844 |
} |
845 |
|
846 |
private bool IsConnected(Item item1, Item item2) |
847 |
{ |
848 |
if (item1.Relations.Find(x => x.UID.Equals(item2.UID)) != null && |
849 |
item2.Relations.Find(x => x.UID.Equals(item1.UID)) != null) |
850 |
return true; |
851 |
else |
852 |
return false; |
853 |
} |
854 |
|
855 |
private void SaveNozzleAndEquipment() |
856 |
{ |
857 |
List<Item> nozzles = new List<Item>(); |
858 |
List<Equipment> equipments = new List<Equipment>(); |
859 |
foreach (Document document in Documents) |
860 |
{ |
861 |
nozzles.AddRange(document.Items.FindAll(x => x.SubItemType == SubItemType.Nozzle)); |
862 |
equipments.AddRange(document.Equipments); |
863 |
} |
864 |
|
865 |
|
866 |
DataTable nozzleDT = new DataTable(); |
867 |
nozzleDT.Columns.Add("OID", typeof(string)); |
868 |
nozzleDT.Columns.Add("ITEMTAG", typeof(string)); |
869 |
nozzleDT.Columns.Add("XCOORDS", typeof(string)); |
870 |
nozzleDT.Columns.Add("YCOORDS", typeof(string)); |
871 |
nozzleDT.Columns.Add("Equipment_OID", typeof(string)); |
872 |
nozzleDT.Columns.Add("FLUID", typeof(string)); |
873 |
nozzleDT.Columns.Add("NPD", typeof(string)); |
874 |
nozzleDT.Columns.Add("PMC", typeof(string)); |
875 |
nozzleDT.Columns.Add("ROTATION", typeof(string)); |
876 |
nozzleDT.Columns.Add("FlowDirection", typeof(string)); |
877 |
|
878 |
foreach (Item item in nozzles) |
879 |
{ |
880 |
DataRow row = nozzleDT.NewRow(); |
881 |
row["OID"] = item.UID; |
882 |
|
883 |
Relation relation = item.Relations.Find(x => equipments.Find(y => y.UID == x.UID) != null); |
884 |
if (relation != null) |
885 |
{ |
886 |
Equipment equipment = equipments.Find(x => x.UID == relation.UID); |
887 |
equipment.Nozzles.Add(item); |
888 |
row["ITEMTAG"] = string.Format("N{0}", string.Format("{0:D3}", equipment.Nozzles.Count + 100)); |
889 |
row["Equipment_OID"] = equipment.UID; |
890 |
item.Equipment = equipment; |
891 |
} |
892 |
row["XCOORDS"] = (item.POINT[0] / DrawingWidth).ToString(); |
893 |
row["YCOORDS"] = (item.POINT[1] / DrawingHeight).ToString(); |
894 |
Attribute fluidAttr = item.LineNumber.Attributes.Find(x => x.Name == "FluidCode"); |
895 |
row["FLUID"] = fluidAttr != null ? fluidAttr.Value : string.Empty; |
896 |
Attribute npdAttr = item.LineNumber.Attributes.Find(x => x.Name == "NominalDiameter"); |
897 |
row["NPD"] = npdAttr != null ? npdAttr.Value : string.Empty; |
898 |
Attribute pmcAttr = item.LineNumber.Attributes.Find(x => x.Name == "PipingMaterialsClass"); |
899 |
row["PMC"] = pmcAttr != null ? pmcAttr.Value : string.Empty; |
900 |
|
901 |
double angle = Math.PI * 2 - Convert.ToDouble(item.ANGLE); |
902 |
if (angle >= Math.PI * 2) |
903 |
angle = angle - Math.PI * 2; |
904 |
row["ROTATION"] = angle.ToString(); |
905 |
|
906 |
if (item.Topology.Items.First().Equals(item)) |
907 |
row["FlowDirection"] = "Outlet"; |
908 |
else if (item.Topology.Items.Last().Equals(item)) |
909 |
row["FlowDirection"] = "Inlet"; |
910 |
else |
911 |
row["FlowDirection"] = string.Empty; |
912 |
|
913 |
nozzleDT.Rows.Add(row); |
914 |
} |
915 |
|
916 |
DataTable equipDT = new DataTable(); |
917 |
equipDT.Columns.Add("OID", typeof(string)); |
918 |
equipDT.Columns.Add("ITEMTAG", typeof(string)); |
919 |
equipDT.Columns.Add("XCOORDS", typeof(string)); |
920 |
equipDT.Columns.Add("YCOORDS", typeof(string)); |
921 |
|
922 |
foreach (Equipment equipment in equipments) |
923 |
{ |
924 |
DataRow row = equipDT.NewRow(); |
925 |
row["OID"] = equipment.UID; |
926 |
if (!string.IsNullOrEmpty(EquipTagNoAttributeName)) |
927 |
{ |
928 |
Attribute attribute = equipment.Attributes.Find(x => x.Name == EquipTagNoAttributeName); |
929 |
if (attribute != null) |
930 |
equipment.ItemTag = attribute.Value; |
931 |
} |
932 |
else |
933 |
equipment.ItemTag = equipment.Name; |
934 |
|
935 |
row["ITEMTAG"] = equipment.ItemTag; |
936 |
List<double> xList = equipment.POINT.Select(x => x[0]).ToList(); |
937 |
row["XCOORDS"] = (xList.Sum() / (double)xList.Count) / DrawingWidth; |
938 |
|
939 |
List<double> yList = equipment.POINT.Select(x => x[1]).ToList(); |
940 |
row["YCOORDS"] = (yList.Sum() / (double)yList.Count) / DrawingHeight; |
941 |
|
942 |
equipDT.Rows.Add(row); |
943 |
} |
944 |
|
945 |
Equipment = equipDT; |
946 |
Nozzle = nozzleDT; |
947 |
} |
948 |
|
949 |
private void SavePSNData() |
950 |
{ |
951 |
try |
952 |
{ |
953 |
DataTable pathItemsDT = new DataTable(); |
954 |
pathItemsDT.Columns.Add("OID", typeof(string)); |
955 |
pathItemsDT.Columns.Add("SequenceData_OID", typeof(string)); |
956 |
pathItemsDT.Columns.Add("TopologySet_OID", typeof(string)); |
957 |
pathItemsDT.Columns.Add("BranchTopologySet_OID", typeof(string)); |
958 |
pathItemsDT.Columns.Add("PipeLine_OID", typeof(string)); |
959 |
pathItemsDT.Columns.Add("ITEMNAME", typeof(string)); |
960 |
pathItemsDT.Columns.Add("ITEMTAG", typeof(string)); |
961 |
pathItemsDT.Columns.Add("DESCRIPTION", typeof(string)); |
962 |
pathItemsDT.Columns.Add("Class", typeof(string)); |
963 |
pathItemsDT.Columns.Add("SubClass", typeof(string)); |
964 |
pathItemsDT.Columns.Add("TYPE", typeof(string)); |
965 |
pathItemsDT.Columns.Add("PIDNAME", typeof(string)); |
966 |
pathItemsDT.Columns.Add("Equipment_OID", typeof(string)); |
967 |
pathItemsDT.Columns.Add("NPD", typeof(string)); |
968 |
pathItemsDT.Columns.Add("PipeSystemNetwork_OID", typeof(string)); |
969 |
pathItemsDT.Columns.Add("ViewPipeSystemNetwork_OID", typeof(string)); |
970 |
pathItemsDT.Columns.Add("PipeRun_OID", typeof(string)); |
971 |
|
972 |
DataTable sequenceDataDT = new DataTable(); |
973 |
sequenceDataDT.Columns.Add("OID", typeof(string)); |
974 |
sequenceDataDT.Columns.Add("SERIALNUMBER", typeof(string)); |
975 |
sequenceDataDT.Columns.Add("PathItem_OID", typeof(string)); |
976 |
sequenceDataDT.Columns.Add("TopologySet_OID_Key", typeof(string)); |
977 |
|
978 |
DataTable pipeSystemNetworkDT = new DataTable(); |
979 |
pipeSystemNetworkDT.Columns.Add("OID", typeof(string)); |
980 |
pipeSystemNetworkDT.Columns.Add("Type", typeof(string)); |
981 |
pipeSystemNetworkDT.Columns.Add("OrderNumber", typeof(string)); |
982 |
pipeSystemNetworkDT.Columns.Add("Pipeline_OID", typeof(string)); |
983 |
pipeSystemNetworkDT.Columns.Add("FROM_DATA", typeof(string)); |
984 |
pipeSystemNetworkDT.Columns.Add("TO_DATA", typeof(string)); |
985 |
pipeSystemNetworkDT.Columns.Add("TopologySet_OID_Key", typeof(string)); |
986 |
pipeSystemNetworkDT.Columns.Add("PSNRevisionNumber", typeof(string)); |
987 |
pipeSystemNetworkDT.Columns.Add("PBS", typeof(string)); |
988 |
pipeSystemNetworkDT.Columns.Add("Drawings", typeof(string)); |
989 |
pipeSystemNetworkDT.Columns.Add("IsValid", typeof(string)); |
990 |
pipeSystemNetworkDT.Columns.Add("Status", typeof(string)); |
991 |
pipeSystemNetworkDT.Columns.Add("IncludingVirtualData", typeof(string)); |
992 |
pipeSystemNetworkDT.Columns.Add("PSNAccuracy", typeof(string)); |
993 |
|
994 |
DataTable topologySetDT = new DataTable(); |
995 |
topologySetDT.Columns.Add("OID", typeof(string)); |
996 |
topologySetDT.Columns.Add("Type", typeof(string)); |
997 |
topologySetDT.Columns.Add("SubType", typeof(string)); |
998 |
topologySetDT.Columns.Add("HeadItemTag", typeof(string)); |
999 |
topologySetDT.Columns.Add("TailItemTag", typeof(string)); |
1000 |
topologySetDT.Columns.Add("HeadItemSPID", typeof(string)); |
1001 |
topologySetDT.Columns.Add("TailItemSPID", typeof(string)); |
1002 |
|
1003 |
DataTable pipelineDT = new DataTable(); |
1004 |
pipelineDT.Columns.Add("OID", typeof(string)); |
1005 |
pipelineDT.Columns.Add("PipeSystem_OID", typeof(string)); |
1006 |
pipelineDT.Columns.Add("FLUID", typeof(string)); |
1007 |
pipelineDT.Columns.Add("PMC", typeof(string)); |
1008 |
pipelineDT.Columns.Add("SEQNUMBER", typeof(string)); |
1009 |
pipelineDT.Columns.Add("INSULATION", typeof(string)); |
1010 |
pipelineDT.Columns.Add("FROM_DATA", typeof(string)); |
1011 |
pipelineDT.Columns.Add("TO_DATA", typeof(string)); |
1012 |
pipelineDT.Columns.Add("Unit", typeof(string)); |
1013 |
|
1014 |
// Set Vent/Drain Info |
1015 |
List<VentDrainInfo> VentDrainInfos = new List<VentDrainInfo>(); |
1016 |
DataTable dt = DB.SelectVentDrainSetting(); |
1017 |
foreach (DataRow row in dt.Rows) |
1018 |
{ |
1019 |
string groupID = row["GROUP_ID"].ToString(); |
1020 |
string desc = row["DESCRIPTION"].ToString(); |
1021 |
int index = Convert.ToInt32(row["INDEX"]); |
1022 |
string name = row["NAME"].ToString(); |
1023 |
|
1024 |
VentDrainInfo ventDrainInfo = VentDrainInfos.Find(x => x.UID.Equals(groupID)); |
1025 |
if (ventDrainInfo == null) |
1026 |
{ |
1027 |
ventDrainInfo = new VentDrainInfo(groupID); |
1028 |
ventDrainInfo.Description = desc; |
1029 |
VentDrainInfos.Add(ventDrainInfo); |
1030 |
} |
1031 |
|
1032 |
ventDrainInfo.VentDrainItems.Add(new VentDrainItem() |
1033 |
{ |
1034 |
Index = index, |
1035 |
Name = name |
1036 |
}); |
1037 |
} |
1038 |
|
1039 |
#region Keyword Info |
1040 |
KeywordInfo KeywordInfos = new KeywordInfo(); |
1041 |
DataTable dtKeyword = DB.SelectKeywordsSetting(); |
1042 |
foreach (DataRow row in dtKeyword.Rows) |
1043 |
{ |
1044 |
int index = Convert.ToInt32(row["INDEX"]); |
1045 |
string name = row["NAME"].ToString(); |
1046 |
string keyword = row["KEYWORD"].ToString(); |
1047 |
|
1048 |
//KeywordInfo keywordInfo = new KeywordInfo(); |
1049 |
KeywordInfos.KeywordItems.Add(new KeywordItem() |
1050 |
{ |
1051 |
Index = index, |
1052 |
Name = name, |
1053 |
Keyword = keyword |
1054 |
}); |
1055 |
} |
1056 |
#endregion |
1057 |
|
1058 |
// key = 미입력 branch |
1059 |
Dictionary<Item, Item> startBranchDic = new Dictionary<Item, Item>(); |
1060 |
Dictionary<Item, Item> endBranchDic = new Dictionary<Item, Item>(); |
1061 |
|
1062 |
foreach (PSNItem PSNItem in PSNItems) |
1063 |
{ |
1064 |
try |
1065 |
{ |
1066 |
int psnOrder = 0; |
1067 |
int index = 0; |
1068 |
bool bPSNStart = true; |
1069 |
string sPSNData = string.Empty; |
1070 |
bool bVentDrain = false; |
1071 |
|
1072 |
//VentDrain 검사 |
1073 |
if (PSNItem.Groups.Count.Equals(1)) |
1074 |
{ |
1075 |
List<VentDrainInfo> endInfos = new List<VentDrainInfo>(); |
1076 |
Group group = PSNItem.Groups[0]; |
1077 |
List<Item> items = group.Items.FindAll(x => x.Name != "PSN_Nozzle"); |
1078 |
for (int i = 0; i < items.Count; i++) |
1079 |
{ |
1080 |
Item item = items[i]; |
1081 |
|
1082 |
foreach (VentDrainInfo ventDrainInfo in VentDrainInfos) |
1083 |
{ |
1084 |
if (endInfos.Contains(ventDrainInfo) || ventDrainInfo.VentDrainItems.Count != items.Count) |
1085 |
continue; |
1086 |
if (!ventDrainInfo.VentDrainItems[i].Name.Equals(item.Name)) |
1087 |
{ |
1088 |
endInfos.Add(ventDrainInfo); |
1089 |
continue; |
1090 |
} |
1091 |
|
1092 |
if (i + 1 == items.Count && items.Count.Equals(ventDrainInfo.VentDrainItems.Count)) |
1093 |
{ |
1094 |
bVentDrain = true; |
1095 |
} |
1096 |
} |
1097 |
} |
1098 |
|
1099 |
if (!bVentDrain) |
1100 |
{ |
1101 |
endInfos = new List<VentDrainInfo>(); |
1102 |
for (int i = 0; i < items.Count; i++) |
1103 |
{ |
1104 |
Item item = items[items.Count - i - 1]; |
1105 |
|
1106 |
foreach (VentDrainInfo ventDrainInfo in VentDrainInfos) |
1107 |
{ |
1108 |
if (endInfos.Contains(ventDrainInfo) || ventDrainInfo.VentDrainItems.Count != items.Count) |
1109 |
continue; |
1110 |
if (!ventDrainInfo.VentDrainItems[i].Name.Equals(item.Name)) |
1111 |
{ |
1112 |
endInfos.Add(ventDrainInfo); |
1113 |
continue; |
1114 |
} |
1115 |
|
1116 |
if (i + 1 == items.Count && items.Count.Equals(ventDrainInfo.VentDrainItems.Count)) |
1117 |
{ |
1118 |
bVentDrain = true; |
1119 |
} |
1120 |
} |
1121 |
} |
1122 |
} |
1123 |
} |
1124 |
|
1125 |
try |
1126 |
{ |
1127 |
//PSN, PathItems, SequenceData 관련 |
1128 |
foreach (Group group in PSNItem.Groups) |
1129 |
{ |
1130 |
foreach (Item item in group.Items) |
1131 |
{ |
1132 |
string PathitemUID = string.Empty; |
1133 |
if (item.BranchItems.Count == 0) |
1134 |
{ |
1135 |
PathitemUID = item.UID; |
1136 |
CreatePathItemsDataRow(PathitemUID, item.ID2DBType); |
1137 |
CreateSequenceDataDataRow(PathitemUID); |
1138 |
index++; |
1139 |
} |
1140 |
else |
1141 |
{ |
1142 |
PathitemUID = item.UID + "_L1"; |
1143 |
CreatePathItemsDataRow(PathitemUID, item.ID2DBType); |
1144 |
CreateSequenceDataDataRow(PathitemUID); |
1145 |
index++; |
1146 |
for (int i = 0; i < item.BranchItems.Count; i++) |
1147 |
{ |
1148 |
CreatePathItemsDataRow(string.Format(item.UID + "_B{0}", i + 1), "Branch", item.BranchItems[i].Topology.FullName, item.BranchItems[i]); |
1149 |
CreateSequenceDataDataRow(string.Format(item.UID + "_B{0}", i + 1)); |
1150 |
index++; |
1151 |
|
1152 |
CreatePathItemsDataRow(string.Format(item.UID + "_L{0}", i + 2), item.ID2DBType); |
1153 |
CreateSequenceDataDataRow(string.Format(item.UID + "_L{0}", i + 2)); |
1154 |
index++; |
1155 |
|
1156 |
if (item.BranchItems[i].Relations[0].Item != null && item.BranchItems[i].Relations[0].Item == item) |
1157 |
startBranchDic.Add(item.BranchItems[i], item); |
1158 |
else if (item.BranchItems[i].Relations[1].Item != null && item.BranchItems[i].Relations[1].Item == item) |
1159 |
endBranchDic.Add(item.BranchItems[i], item); |
1160 |
} |
1161 |
} |
1162 |
if (bPSNStart) |
1163 |
{ |
1164 |
CreatePipeSystemNetworkDataRow(); |
1165 |
sPSNData = item.TopologyData; |
1166 |
psnOrder++; |
1167 |
bPSNStart = false; |
1168 |
} |
1169 |
else |
1170 |
{ |
1171 |
if (item.TopologyData != sPSNData) |
1172 |
{ |
1173 |
CreatePipeSystemNetworkDataRow(); |
1174 |
sPSNData = item.TopologyData; |
1175 |
psnOrder++; |
1176 |
} |
1177 |
} |
1178 |
void CreatePathItemsDataRow(string itemOID, string itemType, string branchTopologyName = "", Item branchItem = null) |
1179 |
{ |
1180 |
DataRow newRow = pathItemsDT.NewRow(); |
1181 |
|
1182 |
if (itemType == "Nozzles") |
1183 |
{ |
1184 |
newRow["Equipment_OID"] = item.Equipment.UID; |
1185 |
} |
1186 |
|
1187 |
newRow["OID"] = itemOID; |
1188 |
newRow["SequenceData_OID"] = string.Format(item.Topology.FullName + "_{0}", index); |
1189 |
newRow["TopologySet_OID"] = item.Topology.FullName; |
1190 |
newRow["BranchTopologySet_OID"] = branchTopologyName; |
1191 |
newRow["PipeLine_OID"] = item.PSNPipeLineID; |
1192 |
newRow["ITEMNAME"] = GetItemName(item, itemOID); |
1193 |
newRow["ITEMTAG"] = GetItemTag(item); |
1194 |
newRow["Class"] = GetClass(item, itemOID); |
1195 |
string subClass = GetSubClass(item, itemOID); |
1196 |
newRow["SubClass"] = subClass; |
1197 |
|
1198 |
if (item.ItemType == ItemType.Symbol) |
1199 |
newRow["TYPE"] = item.ID2DBName; |
1200 |
else if (item.ItemType == ItemType.Line) |
1201 |
newRow["TYPE"] = item.ID2DBType; |
1202 |
newRow["PIDNAME"] = group.Document.DrawingName; |
1203 |
|
1204 |
// NPD |
1205 |
if (item.LineNumber != null) |
1206 |
{ |
1207 |
Attribute attribute = item.LineNumber.Attributes.Find(x => x.Name == "NominalDiameter"); |
1208 |
if (attribute != null) |
1209 |
newRow["NPD"] = attribute.Value; |
1210 |
} |
1211 |
else |
1212 |
newRow["NPD"] = null; |
1213 |
|
1214 |
|
1215 |
newRow["PipeSystemNetwork_OID"] = PSNItem.PSN_OID(); |
1216 |
if (branchItem == null) |
1217 |
newRow["ViewPipeSystemNetwork_OID"] = PSNItem.PSN_OID(); |
1218 |
else |
1219 |
newRow["ViewPipeSystemNetwork_OID"] = branchItem.PSNItem.PSN_OID(); |
1220 |
|
1221 |
newRow["PipeRun_OID"] = item.LineNumber != null ? item.LineNumber.Name : string.Empty; |
1222 |
|
1223 |
pathItemsDT.Rows.Add(newRow); |
1224 |
} |
1225 |
void UpdatePathItemsDataRow(string itemOID, string Type, string Text) |
1226 |
{ |
1227 |
if (pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault() != null) |
1228 |
{ |
1229 |
//pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault()["TYPE"] = Type; |
1230 |
pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault()["ITEMTAG"] = Text; |
1231 |
pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault()["DESCRIPTION"] = Text; |
1232 |
pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault()["ITEMNAME"] = "PipingComp"; |
1233 |
} |
1234 |
} |
1235 |
void UpdatePathItemsKeywordDataRow(string itemOID, string Text, string Type) |
1236 |
{ |
1237 |
if (pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault() != null) |
1238 |
{ |
1239 |
pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault()["CLASS"] = Type; |
1240 |
pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault()["TYPE"] = "End"; |
1241 |
pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault()["ITEMTAG"] = Text; |
1242 |
pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault()["DESCRIPTION"] = Text; |
1243 |
} |
1244 |
} |
1245 |
void CreateSequenceDataDataRow(string itemOID) |
1246 |
{ |
1247 |
DataRow newRow = sequenceDataDT.NewRow(); |
1248 |
newRow["OID"] = string.Format(item.Topology.FullName + "_{0}", index); |
1249 |
newRow["SERIALNUMBER"] = string.Format("{0}", index); |
1250 |
newRow["PathItem_OID"] = itemOID; |
1251 |
newRow["TopologySet_OID_Key"] = item.Topology.FullName; |
1252 |
|
1253 |
sequenceDataDT.Rows.Add(newRow); |
1254 |
} |
1255 |
void CreatePipeSystemNetworkDataRow() |
1256 |
{ |
1257 |
LineNumber lineNumber = item.Document.LineNumbers.Find(x => x.UID == item.Owner); |
1258 |
if (lineNumber != null) |
1259 |
{ |
1260 |
List<Attribute> att = lineNumber.Attributes; |
1261 |
if (att != null) |
1262 |
{ |
1263 |
List<string> oid = new List<string>(); |
1264 |
string FluidCode = att.Where(x => x.Name.ToUpper().Equals("FLUIDCODE")).FirstOrDefault() != null ? att.Where(x => x.Name.ToUpper().Equals("FLUIDCODE")).FirstOrDefault().Value : string.Empty; |
1265 |
string PMC = lineNumber.Attributes.Where(x => x.Name.ToUpper().Equals("PIPINGMATERIALSCLASS")).FirstOrDefault() != null ? lineNumber.Attributes.Where(x => x.Name.ToUpper().Equals("PIPINGMATERIALSCLASS")).FirstOrDefault().Value : string.Empty; |
1266 |
string SEQNUMBER = lineNumber.Attributes.Where(x => x.Name.ToUpper().Equals("TAG SEQ NO")).FirstOrDefault() != null ? lineNumber.Attributes.Where(x => x.Name.ToUpper().Equals("TAG SEQ NO")).FirstOrDefault().Value : string.Empty; |
1267 |
string INSULATION = lineNumber.Attributes.Where(x => x.Name.ToUpper().Equals("INSULATIONPURPOSE")).FirstOrDefault() != null ? lineNumber.Attributes.Where(x => x.Name.ToUpper().Equals("INSULATIONPURPOSE")).FirstOrDefault().Value : string.Empty; |
1268 |
//InsulationPurpose |
1269 |
if (!string.IsNullOrEmpty(FluidCode)) oid.Add(FluidCode); |
1270 |
if (!string.IsNullOrEmpty(PMC)) oid.Add(PMC); |
1271 |
|
1272 |
string PipeSystem_OID = string.Join("-", oid); |
1273 |
|
1274 |
if (!string.IsNullOrEmpty(SEQNUMBER)) oid.Add(SEQNUMBER); |
1275 |
if (!string.IsNullOrEmpty(INSULATION)) oid.Add(INSULATION); |
1276 |
|
1277 |
string OID = string.Join("-", oid); |
1278 |
|
1279 |
if (pipelineDT.Select(string.Format("OID = '{0}'", OID)).Count() == 0) |
1280 |
{ |
1281 |
DataRow newPipelineRow = pipelineDT.NewRow(); |
1282 |
newPipelineRow["OID"] = OID; |
1283 |
newPipelineRow["PipeSystem_OID"] = PipeSystem_OID; |
1284 |
newPipelineRow["FLUID"] = FluidCode; |
1285 |
newPipelineRow["PMC"] = PMC; |
1286 |
newPipelineRow["SEQNUMBER"] = SEQNUMBER; |
1287 |
newPipelineRow["INSULATION"] = INSULATION; |
1288 |
newPipelineRow["FROM_DATA"] = string.Empty; |
1289 |
newPipelineRow["TO_DATA"] = string.Empty; |
1290 |
newPipelineRow["Unit"] = PSNItem.GetPBSData(); |
1291 |
pipelineDT.Rows.Add(newPipelineRow); |
1292 |
} |
1293 |
} |
1294 |
} |
1295 |
|
1296 |
DataRow newRow = pipeSystemNetworkDT.NewRow(); |
1297 |
newRow["OID"] = PSNItem.PSN_OID(); |
1298 |
|
1299 |
newRow["OrderNumber"] = psnOrder; |
1300 |
newRow["Pipeline_OID"] = item.PSNPipeLineID; |
1301 |
PSNItem.KeywordInfos = KeywordInfos; |
1302 |
PSNItem.Nozzle = Nozzle; |
1303 |
|
1304 |
string FromType = string.Empty; |
1305 |
Item From_item = new Item(); |
1306 |
string FROM_DATA = PSNItem.GetFromData(ref FromType, ref From_item); |
1307 |
newRow["FROM_DATA"] = FROM_DATA; |
1308 |
|
1309 |
if (PSNItem.IsKeyword) |
1310 |
{ |
1311 |
PSNItem.StartType = PSNType.Equipment; |
1312 |
UpdatePathItemsKeywordDataRow(From_item.UID, FROM_DATA, FromType); |
1313 |
} |
1314 |
else if (FROM_DATA == "ENDOFHEADER") |
1315 |
{ |
1316 |
UpdatePathItemsDataRow(From_item.UID, From_item.ID2DBName, FROM_DATA); |
1317 |
} |
1318 |
|
1319 |
string ToType = string.Empty; |
1320 |
Item To_item = new Item(); |
1321 |
|
1322 |
string TO_DATA = PSNItem.GetToData(ref ToType, ref To_item); |
1323 |
newRow["TO_DATA"] = TO_DATA; |
1324 |
|
1325 |
if (PSNItem.IsKeyword) |
1326 |
{ |
1327 |
PSNItem.EndType = PSNType.Equipment; |
1328 |
UpdatePathItemsKeywordDataRow(To_item.UID, TO_DATA, ToType); |
1329 |
} |
1330 |
else if (TO_DATA == "ENDOFHEADER") |
1331 |
{ |
1332 |
UpdatePathItemsDataRow(To_item.UID, To_item.ID2DBName, TO_DATA); |
1333 |
} |
1334 |
|
1335 |
// VentDrain의 경우 제외 요청 |
1336 |
//if (bVentDrain) |
1337 |
// return; |
1338 |
|
1339 |
newRow["Type"] = PSNItem.GetPSNType(); |
1340 |
|
1341 |
newRow["TopologySet_OID_Key"] = item.Topology.FullName; |
1342 |
newRow["PSNRevisionNumber"] = string.Format("V{0:D4}", Revision); |
1343 |
|
1344 |
newRow["IsValid"] = PSNItem.IsValid; |
1345 |
newRow["Status"] = !string.IsNullOrEmpty(PSNItem.Status) ? PSNItem.Status.Remove(0, 2) : string.Empty; |
1346 |
newRow["PBS"] = PSNItem.GetPBSData(); |
1347 |
|
1348 |
List<string> drawingNames = new List<string>(); |
1349 |
foreach (Group _group in PSNItem.Groups) |
1350 |
{ |
1351 |
if (!drawingNames.Contains(_group.Document.DrawingName)) |
1352 |
{ |
1353 |
if (drawingNames.Count == 0) |
1354 |
newRow["Drawings"] = _group.Document.DrawingName; |
1355 |
else |
1356 |
newRow["Drawings"] = newRow["Drawings"] + ", " + _group.Document.DrawingName; |
1357 |
drawingNames.Add(_group.Document.DrawingName); |
1358 |
} |
1359 |
} |
1360 |
newRow["IncludingVirtualData"] = "No"; |
1361 |
newRow["PSNAccuracy"] = "100"; |
1362 |
pipeSystemNetworkDT.Rows.Add(newRow); |
1363 |
} |
1364 |
} |
1365 |
} |
1366 |
} |
1367 |
catch (Exception ex) |
1368 |
{ |
1369 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1370 |
MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
1371 |
} |
1372 |
|
1373 |
//TopologySet 관련 |
1374 |
foreach (Topology topology in PSNItem.Topologies) |
1375 |
{ |
1376 |
DataRow newRow = topologySetDT.NewRow(); |
1377 |
newRow["OID"] = topology.FullName; |
1378 |
newRow["Type"] = topology.FullName.Split(new char[] { '-' }).Last().StartsWith("M") ? "Main" : "Branch"; |
1379 |
if (bVentDrain) |
1380 |
newRow["SubType"] = "Vent_Drain"; |
1381 |
else |
1382 |
newRow["SubType"] = null; |
1383 |
newRow["HeadItemTag"] = GetItemTag(topology.Items.Last()); |
1384 |
newRow["TailItemTag"] = GetItemTag(topology.Items.First()); |
1385 |
newRow["HeadItemSPID"] = topology.Items.Last().UID; |
1386 |
newRow["TailItemSPID"] = topology.Items.First().UID; |
1387 |
topologySetDT.Rows.Add(newRow); |
1388 |
} |
1389 |
|
1390 |
} |
1391 |
catch(Exception ee) |
1392 |
{ |
1393 |
|
1394 |
} |
1395 |
} |
1396 |
|
1397 |
|
1398 |
foreach (var item in startBranchDic) |
1399 |
{ |
1400 |
string uid = item.Key.UID; |
1401 |
string topologyName = item.Value.Topology.FullName; |
1402 |
DataRow[] rows = pathItemsDT.Select(string.Format("OID LIKE '{0}%'", uid)); |
1403 |
|
1404 |
if (rows.Length == 1) |
1405 |
{ |
1406 |
rows.First()["BranchTopologySet_OID"] = topologyName; |
1407 |
rows.First()["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID(); |
1408 |
} |
1409 |
else if (rows.Length > 1) |
1410 |
{ |
1411 |
DataRow targetRow = null; |
1412 |
int index = int.MaxValue; |
1413 |
foreach (DataRow row in rows) |
1414 |
{ |
1415 |
string split = row["OID"].ToString().Split(new char[] { '_' })[1]; |
1416 |
if (split.StartsWith("L")) |
1417 |
{ |
1418 |
int num = Convert.ToInt32(split.Remove(0, 1)); |
1419 |
if (index > num) |
1420 |
{ |
1421 |
index = num; |
1422 |
targetRow = row; |
1423 |
} |
1424 |
} |
1425 |
} |
1426 |
|
1427 |
if (targetRow != null) |
1428 |
{ |
1429 |
targetRow["BranchTopologySet_OID"] = topologyName; |
1430 |
targetRow["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID(); |
1431 |
} |
1432 |
} |
1433 |
} |
1434 |
|
1435 |
foreach (var item in endBranchDic) |
1436 |
{ |
1437 |
string uid = item.Key.UID; |
1438 |
string topologyName = item.Value.Topology.FullName; |
1439 |
DataRow[] rows = pathItemsDT.Select(string.Format("OID LIKE '{0}%'", uid)); |
1440 |
if (rows.Length == 1) |
1441 |
{ |
1442 |
rows.First()["BranchTopologySet_OID"] = topologyName; |
1443 |
rows.First()["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID(); |
1444 |
} |
1445 |
else if (rows.Length > 1) |
1446 |
{ |
1447 |
DataRow targetRow = null; |
1448 |
int index = int.MinValue; |
1449 |
foreach (DataRow row in rows) |
1450 |
{ |
1451 |
string split = row["OID"].ToString().Split(new char[] { '_' })[1]; |
1452 |
if (split.StartsWith("L")) |
1453 |
{ |
1454 |
int num = Convert.ToInt32(split.Remove(0, 1)); |
1455 |
if (index < num) |
1456 |
{ |
1457 |
index = num; |
1458 |
targetRow = row; |
1459 |
} |
1460 |
} |
1461 |
} |
1462 |
|
1463 |
if (targetRow != null) |
1464 |
{ |
1465 |
targetRow["BranchTopologySet_OID"] = topologyName; |
1466 |
targetRow["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID(); |
1467 |
} |
1468 |
} |
1469 |
} |
1470 |
|
1471 |
PathItems = pathItemsDT; |
1472 |
SequenceData = sequenceDataDT; |
1473 |
PipeSystemNetwork = pipeSystemNetworkDT; |
1474 |
TopologySet = topologySetDT; |
1475 |
PipeLine = pipelineDT; |
1476 |
} |
1477 |
catch (Exception ex) |
1478 |
{ |
1479 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1480 |
MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
1481 |
} |
1482 |
} |
1483 |
|
1484 |
private double AccuracyCalculation(List<double> lstAcc, double acc) |
1485 |
{ |
1486 |
foreach(double lacc in lstAcc) |
1487 |
{ |
1488 |
acc *= lacc; |
1489 |
} |
1490 |
acc = acc; |
1491 |
return acc; |
1492 |
} |
1493 |
|
1494 |
private void UpdateSubType() |
1495 |
{ |
1496 |
try |
1497 |
{ |
1498 |
|
1499 |
|
1500 |
foreach (PSNItem PSNItem in PSNItems) |
1501 |
{ |
1502 |
if (PSNItem.IsBypass) |
1503 |
{ |
1504 |
foreach (Topology topology in PSNItem.Topologies) |
1505 |
{ |
1506 |
DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName)); |
1507 |
if (rows.Length.Equals(1)) |
1508 |
rows.First()["SubType"] = "Bypass"; |
1509 |
} |
1510 |
} |
1511 |
|
1512 |
if (PSNItem.StartType == PSNType.Header) |
1513 |
{ |
1514 |
Topology topology = PSNItem.Topologies.First(); |
1515 |
DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName)); |
1516 |
if (rows.Length.Equals(1)) |
1517 |
rows.First()["SubType"] = "Header"; |
1518 |
} |
1519 |
else if (PSNItem.EndType == PSNType.Header) |
1520 |
{ |
1521 |
Topology topology = PSNItem.Topologies.Last(); |
1522 |
DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName)); |
1523 |
if (rows.Length.Equals(1)) |
1524 |
rows.First()["SubType"] = "Header"; |
1525 |
} |
1526 |
} |
1527 |
|
1528 |
|
1529 |
foreach (Topology topology in Topologies) |
1530 |
{ |
1531 |
try |
1532 |
{ |
1533 |
DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName)); |
1534 |
|
1535 |
if(rows.Count() > 0) |
1536 |
{ |
1537 |
if (rows.Length.Equals(1) && rows.First()["SubType"] == null || string.IsNullOrEmpty(rows.First()["SubType"].ToString())) |
1538 |
{ |
1539 |
if (topology.Items == null) |
1540 |
continue; |
1541 |
|
1542 |
Item firstItem = topology.Items.First(); |
1543 |
Item lastItem = topology.Items.Last(); |
1544 |
|
1545 |
List<Relation> relations = new List<Relation>(); |
1546 |
|
1547 |
if (firstItem.Relations.FindAll(x => x.Item == null).Count() != 0) |
1548 |
relations.AddRange(firstItem.Relations.FindAll(x => x.Item != null && x.Item.Topology.ID != topology.ID)); |
1549 |
|
1550 |
if (lastItem.Relations.FindAll(x => x.Item == null).Count() != 0) |
1551 |
relations.AddRange(lastItem.Relations.FindAll(x => x.Item != null && x.Item.Topology.ID != topology.ID)); |
1552 |
|
1553 |
if (relations.Count > 0) |
1554 |
rows.First()["SubType"] = "OtherSystem"; |
1555 |
} |
1556 |
} |
1557 |
} |
1558 |
catch (Exception ex) |
1559 |
{ |
1560 |
|
1561 |
MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
1562 |
} |
1563 |
} |
1564 |
|
1565 |
foreach (DataRow row in TopologySet.Rows) |
1566 |
if (row["SubType"] == null || string.IsNullOrEmpty(row["SubType"].ToString())) |
1567 |
row["SubType"] = "Normal"; |
1568 |
} |
1569 |
catch (Exception ex) |
1570 |
{ |
1571 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1572 |
MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
1573 |
} |
1574 |
} |
1575 |
|
1576 |
private bool IsBypass(PSNItem PSNItem) |
1577 |
{ |
1578 |
bool bResult = false; |
1579 |
|
1580 |
if (PSNItem.GetPSNType() == "B2B") |
1581 |
{ |
1582 |
Group firstGroup = PSNItem.Groups.First(); |
1583 |
Group lastGroup = PSNItem.Groups.Last(); |
1584 |
Item firstItem = firstGroup.Items.First(); |
1585 |
Item lastItem = lastGroup.Items.Last(); |
1586 |
|
1587 |
Item connectedFirstItem = GetConnectedItemByPSN(firstItem); |
1588 |
Item connectedLastItem = GetConnectedItemByPSN(lastItem); |
1589 |
|
1590 |
if (connectedFirstItem.LineNumber != null && connectedLastItem.LineNumber != null && |
1591 |
!string.IsNullOrEmpty(connectedFirstItem.LineNumber.Name) && !string.IsNullOrEmpty(connectedLastItem.LineNumber.Name) && |
1592 |
connectedFirstItem.LineNumber.Name == connectedLastItem.LineNumber.Name) |
1593 |
bResult = true; |
1594 |
else if (connectedFirstItem.PSNItem == connectedLastItem.PSNItem) |
1595 |
bResult = true; |
1596 |
} |
1597 |
|
1598 |
Item GetConnectedItemByPSN(Item item) |
1599 |
{ |
1600 |
Item result = null; |
1601 |
|
1602 |
Relation relation = item.Relations.Find(x => x.Item != null && x.Item.PSNItem != item.PSNItem); |
1603 |
if (relation != null) |
1604 |
result = relation.Item; |
1605 |
|
1606 |
|
1607 |
return result; |
1608 |
} |
1609 |
|
1610 |
return bResult; |
1611 |
} |
1612 |
|
1613 |
|
1614 |
private void UpdateAccuracy() |
1615 |
{ |
1616 |
DataRow[] statusRows = PipeSystemNetwork.Select(" Type = 'Error' OR IsValid = 'Error'"); |
1617 |
List<double> lstAcc = null; |
1618 |
string Status = string.Empty; |
1619 |
|
1620 |
foreach (DataRow dataRow in statusRows) |
1621 |
{ |
1622 |
lstAcc = new List<double>(); |
1623 |
Status = dataRow.Field<string>("Status"); |
1624 |
|
1625 |
if (!string.IsNullOrEmpty(Status)) |
1626 |
{ |
1627 |
if (Status.Contains(Rule1)) //Line Disconnected |
1628 |
lstAcc.Add(0.75); |
1629 |
|
1630 |
if (Status.Contains(Rule2)) //Missing LineNumber |
1631 |
lstAcc.Add(0.7); |
1632 |
|
1633 |
if (Status.Contains(Rule3)) //OPC Disconneted |
1634 |
lstAcc.Add(0.5); |
1635 |
|
1636 |
if (Status.Contains(Rule4)) //Missing ItemTag or Description |
1637 |
lstAcc.Add(0.65); |
1638 |
//else if (Status.Contains(Rule5)) |
1639 |
// lstAcc.Add(0.6); |
1640 |
} |
1641 |
|
1642 |
string PSNAccuracy = dataRow["PSNAccuracy"].ToString(); |
1643 |
if (PSNAccuracy == "100") |
1644 |
PSNAccuracy = "1"; |
1645 |
|
1646 |
PSNAccuracy = Convert.ToString(Math.Round(Convert.ToDouble(AccuracyCalculation(lstAcc, Convert.ToDouble(PSNAccuracy))), 2)); |
1647 |
if (PSNAccuracy != "100") |
1648 |
{ |
1649 |
dataRow["IncludingVirtualData"] = "No"; |
1650 |
dataRow["PSNAccuracy"] = PSNAccuracy; |
1651 |
} |
1652 |
} |
1653 |
DataTable dt = PipeSystemNetwork.DefaultView.ToTable(true, new string[] { "OID" }); |
1654 |
foreach (DataRow dr in dt.Rows) |
1655 |
{ |
1656 |
string oid = dr.Field<string>("OID"); |
1657 |
DataRow[] select = PipeSystemNetwork.Select(string.Format("OID = '{0}'", oid)); |
1658 |
double totalDdr = 0; |
1659 |
foreach (DataRow ddr in select) |
1660 |
{ |
1661 |
double acc = Convert.ToDouble(ddr.Field<string>("PSNAccuracy")); |
1662 |
if (acc == 100) acc = 1; |
1663 |
if (totalDdr == 0) totalDdr = acc; |
1664 |
else totalDdr *= acc; |
1665 |
} |
1666 |
|
1667 |
totalDdr *= 100; |
1668 |
|
1669 |
if(totalDdr != 100) |
1670 |
{ |
1671 |
foreach (DataRow ddr in select) |
1672 |
{ |
1673 |
ddr["IncludingVirtualData"] = "Yes"; |
1674 |
ddr["PSNAccuracy"] = Math.Round(totalDdr, 2); |
1675 |
} |
1676 |
} |
1677 |
} |
1678 |
|
1679 |
} |
1680 |
|
1681 |
private void UpdateKeywordForPSN() |
1682 |
{ |
1683 |
#region Keyword Info |
1684 |
KeywordInfo KeywordInfos = new KeywordInfo(); |
1685 |
DataTable dtKeyword = DB.SelectKeywordsSetting(); |
1686 |
foreach (DataRow row in dtKeyword.Rows) |
1687 |
{ |
1688 |
int index = Convert.ToInt32(row["INDEX"]); |
1689 |
string name = row["NAME"].ToString(); |
1690 |
string keyword = row["KEYWORD"].ToString(); |
1691 |
|
1692 |
//KeywordInfo keywordInfo = new KeywordInfo(); |
1693 |
KeywordInfos.KeywordItems.Add(new KeywordItem() |
1694 |
{ |
1695 |
Index = index, |
1696 |
Name = name, |
1697 |
Keyword = keyword |
1698 |
}); |
1699 |
} |
1700 |
#endregion |
1701 |
|
1702 |
foreach (KeywordItem keyitem in KeywordInfos.KeywordItems) |
1703 |
{ |
1704 |
DataRow[] keywordRows = PipeSystemNetwork.Select(string.Format(" From_Data = '{0}' OR To_Data = '{0}'", keyitem.Name)); |
1705 |
foreach (DataRow dataRow in keywordRows) |
1706 |
{ |
1707 |
PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString()); |
1708 |
bool change = false; |
1709 |
|
1710 |
if(dataRow.Field<string>("From_Data") == keyitem.Name) |
1711 |
{ |
1712 |
change = true; |
1713 |
DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"])); |
1714 |
|
1715 |
if(pathItemRows.First().Field<string>("Type").Equals(keyitem.Name)) |
1716 |
{ |
1717 |
DataRow dr = pathItemRows.First(); |
1718 |
//dr["CLASS"] = ""; //Type |
1719 |
dr["TYPE"] = "End"; |
1720 |
dr["ITEMTAG"] = keyitem.Keyword; |
1721 |
dr["DESCRIPTION"] = keyitem.Keyword; |
1722 |
} |
1723 |
|
1724 |
} |
1725 |
|
1726 |
if (dataRow.Field<string>("To_Data") == keyitem.Name) |
1727 |
{ |
1728 |
change = true; |
1729 |
DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"])); |
1730 |
|
1731 |
if (pathItemRows.Last().Field<string>("Type").Equals(keyitem.Name)) |
1732 |
{ |
1733 |
DataRow dr = pathItemRows.Last(); |
1734 |
//dr["CLASS"] = ""; //Type |
1735 |
dr["TYPE"] = "End"; |
1736 |
dr["ITEMTAG"] = keyitem.Keyword; |
1737 |
dr["DESCRIPTION"] = keyitem.Keyword; |
1738 |
//dr.Field<string>("Type") |
1739 |
} |
1740 |
|
1741 |
} |
1742 |
} |
1743 |
} |
1744 |
} |
1745 |
|
1746 |
private void UpdateErrorForPSN() |
1747 |
{ |
1748 |
DataRow[] errorRows = PipeSystemNetwork.Select(string.Format(" Type = '{0}'", ErrorType.Error)); |
1749 |
bool bCheckRule5 = false; |
1750 |
foreach (DataRow dataRow in errorRows) |
1751 |
{ |
1752 |
try |
1753 |
{ |
1754 |
|
1755 |
PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString()); |
1756 |
bool change = false; |
1757 |
bCheckRule5 = false; |
1758 |
|
1759 |
if (!PSNItem.EnableType(PSNItem.StartType)) |
1760 |
{ |
1761 |
change = true; |
1762 |
DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"])); |
1763 |
int insertIndex = PathItems.Rows.IndexOf(pathItemRows.First()); |
1764 |
|
1765 |
DataRow[] seqItemRows = SequenceData.Select(string.Format("PathItem_OID = '{0}'", pathItemRows.First()["OID"])); |
1766 |
int insertSeqIndex = SequenceData.Rows.IndexOf(seqItemRows.First()); |
1767 |
|
1768 |
Item item = PSNItem.Groups.First().Items.First(); |
1769 |
try |
1770 |
{ |
1771 |
string FROM_DATA = string.Format("TIEINPOINT_{0:D5}V", tieInPointIndex); |
1772 |
foreach (DataRow loopRow in PipeSystemNetwork.Select(string.Format("OID = '{0}'", PSNItem.PSN_OID()))) |
1773 |
loopRow["FROM_DATA"] = FROM_DATA; |
1774 |
tieInPointIndex++; |
1775 |
|
1776 |
|
1777 |
if (item.ItemType == ItemType.Line) |
1778 |
{ |
1779 |
//createTerminatorRow - Rule 5번 |
1780 |
PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.First(), FROM_DATA), insertIndex); |
1781 |
//SequenceData.Rows.InsertAt(createSequenceTerminatorRow(pathItemRows.First(), insertSeqIndex), insertSeqIndex); |
1782 |
|
1783 |
bCheckRule5 = true; |
1784 |
} |
1785 |
else |
1786 |
{ |
1787 |
PathItems.Rows.InsertAt(createLineRow(PathItems.Select(string.Format("PipeLine_OID = '{0}' AND ItemName = 'PipeRun' AND PipeSystemNetwork_OID = '{1}'", item.PSNPipeLineID, dataRow["OID"])).First()), insertIndex); |
1788 |
//SequenceData.Rows.InsertAt(createSequenceTerminatorRow(PathItems.Select(string.Format("PipeLine_OID = '{0}' AND ItemName = 'PipeRun' AND PipeSystemNetwork_OID = '{1}'", item.PSNPipeLineID, dataRow["OID"])).First(), insertSeqIndex), insertSeqIndex); |
1789 |
//createTerminatorRow - Rule 5번 |
1790 |
PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.First(), FROM_DATA), insertIndex); |
1791 |
//SequenceData.Rows.InsertAt(createSequenceTerminatorRow(pathItemRows.First(), insertSeqIndex), insertSeqIndex); |
1792 |
|
1793 |
bCheckRule5 = true; |
1794 |
} |
1795 |
|
1796 |
PSNItem.StartType = PSNType.Equipment; |
1797 |
} |
1798 |
catch (Exception ex) |
1799 |
{ |
1800 |
MessageBox.Show("Please check the item.\r\nDrawingName : " + item.Document.DrawingName + "\r\nUID : " + item.UID, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
1801 |
return; |
1802 |
} |
1803 |
} |
1804 |
|
1805 |
|
1806 |
if (!PSNItem.EnableType(PSNItem.EndType)) |
1807 |
{ |
1808 |
change = true; |
1809 |
DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"])); |
1810 |
int insertIndex = PathItems.Rows.IndexOf(pathItemRows.Last()); |
1811 |
|
1812 |
|
1813 |
|
1814 |
Item item = PSNItem.Groups.Last().Items.Last(); |
1815 |
try |
1816 |
{ |
1817 |
string TO_DATA = string.Format("TIEINPOINT_{0:D5}V", tieInPointIndex); |
1818 |
|
1819 |
foreach (DataRow loopRow in PipeSystemNetwork.Select(string.Format("OID = '{0}'", PSNItem.PSN_OID()))) |
1820 |
loopRow["TO_DATA"] = TO_DATA; |
1821 |
tieInPointIndex++; |
1822 |
|
1823 |
|
1824 |
if (item.ItemType == ItemType.Line) |
1825 |
{ |
1826 |
//createTerminatorRow - Rule 5번 |
1827 |
PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.Last(), TO_DATA), insertIndex + 1); |
1828 |
//SequenceData.Rows.InsertAt(createSequenceTerminatorRow(pathItemRows.Last(), insertSeqIndex + 1), insertSeqIndex + 1); |
1829 |
|
1830 |
bCheckRule5 = true; |
1831 |
} |
1832 |
else |
1833 |
{ |
1834 |
//createTerminatorRow - Rule 5번 |
1835 |
PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.Last(), TO_DATA), insertIndex + 1); |
1836 |
//SequenceData.Rows.InsertAt(createSequenceTerminatorRow(pathItemRows.Last(), insertSeqIndex + 1), insertSeqIndex + 1); |
1837 |
PathItems.Rows.InsertAt(createLineRow(PathItems.Select(string.Format("PipeLine_OID = '{0}' AND ItemName = 'PipeRun' AND PipeSystemNetwork_OID = '{1}'", item.PSNPipeLineID, dataRow["OID"])).Last()), insertIndex + 1); |
1838 |
//SequenceData.Rows.InsertAt(createSequenceTerminatorRow(PathItems.Select(string.Format("PipeLine_OID = '{0}' AND ItemName = 'PipeRun' AND PipeSystemNetwork_OID = '{1}'", item.PSNPipeLineID, dataRow["OID"])).Last(), insertSeqIndex + 1), insertSeqIndex + 1); |
1839 |
bCheckRule5 = true; |
1840 |
} |
1841 |
|
1842 |
PSNItem.EndType = PSNType.Equipment; |
1843 |
} |
1844 |
catch(Exception ex) |
1845 |
{ |
1846 |
MessageBox.Show("Please check the item.\r\nDrawingName : " + item.Document.DrawingName + "\r\nUID : " + item.UID, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
1847 |
return; |
1848 |
} |
1849 |
} |
1850 |
|
1851 |
dataRow["Type"] = PSNItem.GetPSNType(); |
1852 |
if (change) |
1853 |
{ |
1854 |
int rowIndex = 0; |
1855 |
for (int i = 0; i < PathItems.Rows.Count; i++) |
1856 |
{ |
1857 |
DataRow row = PathItems.Rows[i]; |
1858 |
if (row["PipeSystemNetwork_OID"].ToString() != dataRow["OID"].ToString()) |
1859 |
continue; |
1860 |
string sequenceData = row["SequenceData_OID"].ToString(); |
1861 |
string[] split = sequenceData.Split(new char[] { '_' }); |
1862 |
|
1863 |
StringBuilder sb = new StringBuilder(); |
1864 |
for (int j = 0; j < split.Length - 1; j++) |
1865 |
sb.Append(split[j] + "_"); |
1866 |
sb.Append(rowIndex++); |
1867 |
row["SequenceData_OID"] = sb.ToString(); |
1868 |
|
1869 |
DataRow seqItemRows = SequenceData.Select(string.Format("PathItem_OID = '{0}'", row["OID"])).FirstOrDefault(); |
1870 |
int insertSeqIndex = SequenceData.Rows.IndexOf(seqItemRows); |
1871 |
|
1872 |
string[] splitseq = sb.ToString().Split(new char[] { '_' }); |
1873 |
|
1874 |
if (seqItemRows == null) |
1875 |
{ |
1876 |
DataRow newRow = SequenceData.NewRow(); |
1877 |
newRow["OID"] = sb.ToString(); |
1878 |
newRow["SERIALNUMBER"] = splitseq[splitseq.Length - 1]; |
1879 |
newRow["PathItem_OID"] = row["OID"]; |
1880 |
newRow["TopologySet_OID_Key"] = row["TopologySet_OID"]; |
1881 |
SequenceData.Rows.InsertAt(newRow, Convert.ToInt32(splitseq[splitseq.Length - 1])); |
1882 |
} |
1883 |
else |
1884 |
{ |
1885 |
seqItemRows["OID"] = sb.ToString(); |
1886 |
seqItemRows["SERIALNUMBER"] = splitseq[splitseq.Length - 1]; |
1887 |
seqItemRows["PathItem_OID"] = row["OID"]; |
1888 |
seqItemRows["TopologySet_OID_Key"] = row["TopologySet_OID"]; |
1889 |
|
1890 |
} |
1891 |
|
1892 |
|
1893 |
} |
1894 |
|
1895 |
//rowIndex = 0; |
1896 |
//for (int i = 0; i < SequenceData.Rows.Count; i++) |
1897 |
//{ |
1898 |
// DataRow row = SequenceData.Rows[i]; |
1899 |
// if (row["PathItem_OID"].ToString() != dataRow["OID"].ToString()) |
1900 |
// continue; |
1901 |
// string sequenceData = row["SequenceData_OID"].ToString(); |
1902 |
// string[] split = sequenceData.Split(new char[] { '_' }); |
1903 |
|
1904 |
// row["SERIALNUMBER"] = rowIndex++; |
1905 |
//} |
1906 |
} |
1907 |
|
1908 |
if (bCheckRule5) |
1909 |
{ |
1910 |
string PSNAccuracy = "0.6"; |
1911 |
dataRow["IncludingVirtualData"] = "Yes"; |
1912 |
dataRow["PSNAccuracy"] = PSNAccuracy; |
1913 |
|
1914 |
} |
1915 |
|
1916 |
DataRow createTerminatorRow(DataRow itemRow, string DATA) |
1917 |
{ |
1918 |
DataRow newRow = PathItems.NewRow(); |
1919 |
newRow["OID"] = Guid.NewGuid().ToString(); |
1920 |
newRow["SequenceData_OID"] = itemRow["SequenceData_OID"]; |
1921 |
newRow["TopologySet_OID"] = itemRow["TopologySet_OID"]; |
1922 |
newRow["BranchTopologySet_OID"] = itemRow["BranchTopologySet_OID"]; |
1923 |
newRow["PipeLine_OID"] = itemRow["PipeLine_OID"]; |
1924 |
newRow["ITEMNAME"] = "PipingComp"; //newRow["ITEMNAME"] = "End of line terminator"; |
1925 |
newRow["ITEMTAG"] = DATA; //itemRow["ITEMTAG"]; |
1926 |
newRow["DESCRIPTION"] = DATA; |
1927 |
newRow["Class"] = "End of line terminator"; |
1928 |
newRow["SubClass"] = "End of line terminator"; |
1929 |
newRow["TYPE"] = "End"; |
1930 |
newRow["PIDNAME"] = itemRow["PIDNAME"]; |
1931 |
newRow["NPD"] = itemRow["NPD"]; |
1932 |
newRow["PipeSystemNetwork_OID"] = itemRow["PipeSystemNetwork_OID"]; |
1933 |
newRow["ViewPipeSystemNetwork_OID"] = itemRow["ViewPipeSystemNetwork_OID"]; |
1934 |
newRow["PipeRun_OID"] = itemRow["PipeRun_OID"]; |
1935 |
|
1936 |
|
1937 |
|
1938 |
return newRow; |
1939 |
} |
1940 |
|
1941 |
//DataRow createSequenceTerminatorRow(DataRow itemRow, int insertIndex) |
1942 |
//{ |
1943 |
// DataRow newRow = SequenceData.NewRow(); |
1944 |
// newRow["OID"] = itemRow["SequenceData_OID"]; |
1945 |
// newRow["SERIALNUMBER"] = string.Format("{0}", insertIndex); |
1946 |
// newRow["PathItem_OID"] = itemRow["OID"]; |
1947 |
// newRow["TopologySet_OID_Key"] = itemRow["TopologySet_OID"]; |
1948 |
|
1949 |
// return newRow; |
1950 |
//} |
1951 |
|
1952 |
DataRow createLineRow(DataRow itemRow) |
1953 |
{ |
1954 |
DataRow newRow = PathItems.NewRow(); |
1955 |
newRow["OID"] = Guid.NewGuid().ToString(); |
1956 |
newRow["SequenceData_OID"] = itemRow["SequenceData_OID"]; |
1957 |
newRow["TopologySet_OID"] = itemRow["TopologySet_OID"]; |
1958 |
newRow["BranchTopologySet_OID"] = itemRow["BranchTopologySet_OID"]; |
1959 |
newRow["PipeLine_OID"] = itemRow["PipeLine_OID"]; |
1960 |
newRow["ITEMNAME"] = itemRow["ITEMNAME"]; |
1961 |
newRow["ITEMTAG"] = itemRow["ITEMTAG"]; |
1962 |
newRow["Class"] = itemRow["Class"]; |
1963 |
newRow["SubClass"] = itemRow["SubClass"]; |
1964 |
newRow["TYPE"] = itemRow["TYPE"]; |
1965 |
newRow["PIDNAME"] = itemRow["PIDNAME"]; |
1966 |
newRow["NPD"] = itemRow["NPD"]; |
1967 |
newRow["PipeSystemNetwork_OID"] = itemRow["PipeSystemNetwork_OID"]; |
1968 |
newRow["ViewPipeSystemNetwork_OID"] = itemRow["ViewPipeSystemNetwork_OID"]; |
1969 |
newRow["PipeRun_OID"] = itemRow["PipeRun_OID"]; |
1970 |
|
1971 |
return newRow; |
1972 |
} |
1973 |
} |
1974 |
catch(Exception ex) |
1975 |
{ |
1976 |
|
1977 |
} |
1978 |
} |
1979 |
} |
1980 |
} |
1981 |
|
1982 |
public class PSNItem |
1983 |
{ |
1984 |
public PSNItem(int count, int Revision) |
1985 |
{ |
1986 |
Groups = new List<Group>(); |
1987 |
Topologies = new List<Topology>(); |
1988 |
|
1989 |
Index = count + 1; |
1990 |
this.Revision = Revision; |
1991 |
} |
1992 |
|
1993 |
private int Revision; |
1994 |
public string UID { get; set; } |
1995 |
public List<Group> Groups { get; set; } |
1996 |
public List<Topology> Topologies { get; set; } |
1997 |
public PSNType StartType { get; set; } |
1998 |
public PSNType EndType { get; set; } |
1999 |
public int Index { get; set; } |
2000 |
public string IsValid { get; set; } |
2001 |
public bool IsKeyword { get; set; } |
2002 |
public string Status { get; set; } |
2003 |
public string IncludingVirtualData { get; set; } |
2004 |
public string PSNAccuracy { get; set; } |
2005 |
public KeywordInfo KeywordInfos = new KeywordInfo(); |
2006 |
public DataTable Nozzle = new DataTable(); |
2007 |
|
2008 |
public string PSN_OID() |
2009 |
{ |
2010 |
return string.Format("V{0}-PSN-{1}", string.Format("{0:D4}", Revision), string.Format("{0:D5}", Index)); |
2011 |
} |
2012 |
public string GetPSNType() |
2013 |
{ |
2014 |
string result = string.Empty; |
2015 |
|
2016 |
if (EnableType(StartType) && EnableType(EndType)) |
2017 |
{ |
2018 |
if (StartType == PSNType.Equipment && EndType == PSNType.Equipment) |
2019 |
result = "E2E"; |
2020 |
else if (StartType == PSNType.Branch && EndType == PSNType.Branch) |
2021 |
result = "B2B"; |
2022 |
else if (StartType == PSNType.Header && EndType == PSNType.Header) |
2023 |
result = "HD2"; |
2024 |
|
2025 |
else if (StartType == PSNType.Equipment && EndType == PSNType.Branch) |
2026 |
result = "E2B"; |
2027 |
else if (StartType == PSNType.Branch && EndType == PSNType.Equipment) |
2028 |
result = "B2E"; |
2029 |
|
2030 |
else if (StartType == PSNType.Header && EndType == PSNType.Branch) |
2031 |
result = "HDB"; |
2032 |
else if (StartType == PSNType.Branch && EndType == PSNType.Header) |
2033 |
result = "HDB"; |
2034 |
|
2035 |
else if (StartType == PSNType.Header && EndType == PSNType.Equipment) |
2036 |
result = "HDE"; |
2037 |
else if (StartType == PSNType.Equipment && EndType == PSNType.Header) |
2038 |
result = "HDE"; |
2039 |
else |
2040 |
result = "Error"; |
2041 |
} |
2042 |
else |
2043 |
result = "Error"; |
2044 |
|
2045 |
return result; |
2046 |
|
2047 |
|
2048 |
} |
2049 |
public bool EnableType(PSNType type) |
2050 |
{ |
2051 |
bool result = false; |
2052 |
|
2053 |
if (type == PSNType.Branch || |
2054 |
type == PSNType.Equipment || |
2055 |
type == PSNType.Header) |
2056 |
{ |
2057 |
result = true; |
2058 |
} |
2059 |
|
2060 |
return result; |
2061 |
} |
2062 |
public bool IsBypass { get; set; } |
2063 |
|
2064 |
public string GetFromData(ref string Type, ref Item item) |
2065 |
{ |
2066 |
string result = string.Empty; |
2067 |
if (IsKeyword) |
2068 |
IsKeyword = false; |
2069 |
try |
2070 |
{ |
2071 |
if (StartType == PSNType.Header) |
2072 |
result = "ENDOFHEADER"; |
2073 |
else if (StartType == PSNType.Branch) |
2074 |
{ |
2075 |
item = Groups.First().Items.First(); |
2076 |
if (item.Relations.First().Item.LineNumber != null && !string.IsNullOrEmpty(item.Relations.First().Item.LineNumber.Name)) |
2077 |
result = item.Relations.First().Item.LineNumber.Name; |
2078 |
else |
2079 |
{ |
2080 |
Status += ", Missing LineNumber"; |
2081 |
result = "Empty LineNumber"; |
2082 |
} |
2083 |
} |
2084 |
else if (StartType == PSNType.Equipment) |
2085 |
{ |
2086 |
if (Groups.First().Items.First().Equipment != null) |
2087 |
result = Groups.First().Items.First().Equipment.ItemTag; |
2088 |
DataRow drNozzle = Nozzle.Select(string.Format("OID = '{0}'", Groups.First().Items.First().UID)).FirstOrDefault(); |
2089 |
|
2090 |
if (drNozzle != null) |
2091 |
result += " ["+ drNozzle.Field<string>("ITEMTAG") + "]"; |
2092 |
} |
2093 |
|
2094 |
else |
2095 |
{ |
2096 |
IsValid = "Error"; |
2097 |
item = Groups.First().Items.First(); |
2098 |
if (item.ItemType == ItemType.Symbol) |
2099 |
{ |
2100 |
|
2101 |
string keyword = string.Empty; |
2102 |
keyword = GetFromKeywordData(ref Type, item); |
2103 |
|
2104 |
if (string.IsNullOrEmpty(keyword)) |
2105 |
{ |
2106 |
if (item.ID2DBType.Contains("OPC's")) |
2107 |
Status += ", OPC Disconneted"; |
2108 |
else |
2109 |
Status += ", Missing ItemTag or Description"; |
2110 |
|
2111 |
result = item.ID2DBName; |
2112 |
} |
2113 |
else |
2114 |
{ |
2115 |
result = keyword; |
2116 |
IsKeyword = true; |
2117 |
IsValid = string.Empty; |
2118 |
} |
2119 |
|
2120 |
} |
2121 |
else if (item.ItemType == ItemType.Line) |
2122 |
{ |
2123 |
Status += ", Line Disconnected"; |
2124 |
result = item.LineNumber != null && !string.IsNullOrEmpty(item.LineNumber.Name) ? item.LineNumber.Name : "Empty LineNumber"; |
2125 |
} |
2126 |
else |
2127 |
result = "Unknown"; |
2128 |
} |
2129 |
} |
2130 |
catch(Exception ex) |
2131 |
{ |
2132 |
|
2133 |
} |
2134 |
|
2135 |
return result; |
2136 |
} |
2137 |
|
2138 |
public string GetFromKeywordData(ref string Type, Item item) |
2139 |
{ |
2140 |
string result = string.Empty; |
2141 |
|
2142 |
foreach(KeywordItem keyitem in KeywordInfos.KeywordItems) |
2143 |
{ |
2144 |
if(keyitem.Name.Equals(item.Name)) |
2145 |
{ |
2146 |
result = keyitem.Keyword; |
2147 |
Type = item.ID2DBType; |
2148 |
//break; |
2149 |
} |
2150 |
} |
2151 |
|
2152 |
return result; |
2153 |
} |
2154 |
|
2155 |
public string GetToKeywordData(ref string Type, Item item) |
2156 |
{ |
2157 |
string result = string.Empty; |
2158 |
|
2159 |
foreach (KeywordItem keyitem in KeywordInfos.KeywordItems) |
2160 |
{ |
2161 |
if (keyitem.Name.Equals(item.Name)) |
2162 |
{ |
2163 |
result = keyitem.Keyword; |
2164 |
Type = item.ID2DBType; |
2165 |
// break; |
2166 |
} |
2167 |
} |
2168 |
return result; |
2169 |
} |
2170 |
|
2171 |
public string GetToData(ref string ToType, ref Item item) |
2172 |
{ |
2173 |
string result = string.Empty; |
2174 |
|
2175 |
|
2176 |
if (IsKeyword) |
2177 |
IsKeyword = false; |
2178 |
|
2179 |
if (EndType == PSNType.Header) |
2180 |
result = "ENDOFHEADER"; |
2181 |
else if (EndType == PSNType.Branch) |
2182 |
{ |
2183 |
item = Groups.Last().Items.Last(); |
2184 |
if (item.Relations.Last().Item.LineNumber != null && !string.IsNullOrEmpty(item.Relations.Last().Item.LineNumber.Name)) |
2185 |
result = item.Relations.Last().Item.LineNumber.Name; |
2186 |
else |
2187 |
{ |
2188 |
Status += ", Missing LineNumber"; |
2189 |
result = "Empty LineNumber"; |
2190 |
} |
2191 |
} |
2192 |
else if (EndType == PSNType.Equipment) |
2193 |
{ |
2194 |
if(Groups.Last().Items.Last().Equipment != null) |
2195 |
result = Groups.Last().Items.Last().Equipment.ItemTag; |
2196 |
|
2197 |
DataRow drNozzle = Nozzle.Select(string.Format("OID = '{0}'", Groups.First().Items.First().UID)).FirstOrDefault(); |
2198 |
|
2199 |
if (drNozzle != null) |
2200 |
result += " [" + drNozzle.Field<string>("ITEMTAG") + "]"; |
2201 |
} |
2202 |
else |
2203 |
{ |
2204 |
IsValid = "Error"; |
2205 |
item = Groups.Last().Items.Last(); |
2206 |
if (item.ItemType == ItemType.Symbol) |
2207 |
{ |
2208 |
string keyword = string.Empty; |
2209 |
keyword = GetToKeywordData(ref ToType, item); |
2210 |
|
2211 |
if (string.IsNullOrEmpty(keyword)) |
2212 |
{ |
2213 |
if (item.ID2DBType.Contains("OPC's")) |
2214 |
Status += ", OPC Disconneted"; |
2215 |
else |
2216 |
Status += ", Missing ItemTag or Description"; |
2217 |
|
2218 |
result = item.ID2DBName; |
2219 |
} |
2220 |
else |
2221 |
{ |
2222 |
result = keyword; |
2223 |
IsValid = string.Empty; |
2224 |
IsKeyword = true; |
2225 |
} |
2226 |
|
2227 |
} |
2228 |
else if (item.ItemType == ItemType.Line) |
2229 |
{ |
2230 |
Status += ", Line Disconnected"; |
2231 |
result = item.LineNumber != null && !string.IsNullOrEmpty(item.LineNumber.Name) ? item.LineNumber.Name : "Empty LineNumber"; |
2232 |
} |
2233 |
else |
2234 |
result = "Unknown"; |
2235 |
} |
2236 |
|
2237 |
|
2238 |
return result; |
2239 |
} |
2240 |
|
2241 |
public string GetPBSData() |
2242 |
{ |
2243 |
string result = string.Empty; |
2244 |
List<string> PBSList = new List<string>(); |
2245 |
if (Settings.Default.PBSSetting.Equals("Line Number")) |
2246 |
{ |
2247 |
string attrValue = Settings.Default.PBSSettingValue; |
2248 |
|
2249 |
foreach (Group group in Groups) |
2250 |
{ |
2251 |
List<LineNumber> lineNumbers = group.Items.Select(x =>x.LineNumber).Distinct().ToList(); |
2252 |
foreach (LineNumber lineNumber in lineNumbers) |
2253 |
{ |
2254 |
Attribute attribute = lineNumber.Attributes.Find(x => x.Name == attrValue && !string.IsNullOrEmpty(x.Value)); |
2255 |
if (attribute != null) |
2256 |
{ |
2257 |
string value = attribute.Value; |
2258 |
if (!PBSList.Contains(value)) |
2259 |
PBSList.Add(value); |
2260 |
} |
2261 |
} |
2262 |
} |
2263 |
} |
2264 |
else if (Settings.Default.PBSSetting.Equals("Item Attribute")) |
2265 |
{ |
2266 |
string attrValue = Settings.Default.PBSSettingValue; |
2267 |
|
2268 |
foreach (Group group in Groups) |
2269 |
{ |
2270 |
List<Item> items = group.Items.FindAll(x => x.Attributes.Find(y => y.Name == attrValue && !string.IsNullOrEmpty(y.Value)) != null); |
2271 |
foreach (Item item in items) |
2272 |
{ |
2273 |
string value = item.Attributes.Find(x => x.Name == attrValue).Value; |
2274 |
if (!PBSList.Contains(value)) |
2275 |
PBSList.Add(value); |
2276 |
} |
2277 |
} |
2278 |
} |
2279 |
else if (Settings.Default.PBSSetting.Equals("Drawing No")) |
2280 |
{ |
2281 |
string attrValue = Settings.Default.PBSSettingValue; |
2282 |
|
2283 |
foreach (Group group in Groups) |
2284 |
{ |
2285 |
List<Document> documents = group.Items.Select(x => x.Document).Distinct().ToList(); |
2286 |
foreach (Document document in documents) |
2287 |
{ |
2288 |
string name = document.DrawingName; |
2289 |
|
2290 |
int startIndex = Settings.Default.PBSSettingStartValue; |
2291 |
int endIndex = Settings.Default.PBSSettingEndValue; |
2292 |
|
2293 |
string subStr = name.Substring(startIndex - 1, endIndex - startIndex + 1); |
2294 |
if (!PBSList.Contains(subStr)) |
2295 |
PBSList.Add(subStr); |
2296 |
} |
2297 |
} |
2298 |
} |
2299 |
else if (Settings.Default.PBSSetting.Equals("Unit Area")) |
2300 |
{ |
2301 |
foreach (Group group in Groups) |
2302 |
{ |
2303 |
List<Document> documents = group.Items.Select(x => x.Document).Distinct().ToList(); |
2304 |
foreach (Document document in documents) |
2305 |
{ |
2306 |
List<TextInfo> textInfos = document.TextInfos.FindAll(x => x.Area == "Unit"); |
2307 |
foreach (TextInfo textInfo in textInfos) |
2308 |
{ |
2309 |
if (!PBSList.Contains(textInfo.Value)) |
2310 |
PBSList.Add(textInfo.Value); |
2311 |
} |
2312 |
} |
2313 |
} |
2314 |
} |
2315 |
|
2316 |
foreach (var item in PBSList) |
2317 |
{ |
2318 |
if (string.IsNullOrEmpty(result)) |
2319 |
result = item; |
2320 |
else |
2321 |
result += ", " + item; |
2322 |
} |
2323 |
return result; |
2324 |
} |
2325 |
} |
2326 |
} |