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