hytos / DTI_PID / ID2PSN / PSN.cs @ 85eeb2be
이력 | 보기 | 이력해설 | 다운로드 (185 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 |
using DevExpress.XtraSplashScreen; |
12 |
|
13 |
namespace ID2PSN |
14 |
{ |
15 |
public enum PSNType |
16 |
{ |
17 |
None, |
18 |
Branch, |
19 |
Equipment, |
20 |
Header, |
21 |
Symbol, |
22 |
OPC, |
23 |
} |
24 |
|
25 |
public enum ErrorType |
26 |
{ |
27 |
Error = -1, |
28 |
OK, |
29 |
InValid //이값은 들어가는데가 없음.. |
30 |
} |
31 |
|
32 |
public class PSN |
33 |
{ |
34 |
private double[] DrawingSize = null; |
35 |
private double DrawingWidth = double.NaN; |
36 |
private double DrawingHeight = double.NaN; |
37 |
public int Revision; |
38 |
public string EquipTagNoAttributeName = string.Empty; |
39 |
public DataTable PathItems { get; set; } |
40 |
public DataTable SequenceData { get; set; } |
41 |
public DataTable PipeSystemNetwork { get; set; } |
42 |
public DataTable TopologySet { get; set; } |
43 |
public DataTable Equipment { get; set; } |
44 |
public DataTable Nozzle { get; set; } |
45 |
public DataTable PipeLine { get; set; } |
46 |
public DataTable PipeSystem { get; set; } |
47 |
|
48 |
public string Rule1 = "Missing LineNumber_1"; //Line Disconnected에서 변경 |
49 |
public string Rule2 = "Missing LineNumber_2"; //Missing LineNumber에서 변경 |
50 |
public string Rule3 = "OPC Disconnected"; |
51 |
public string Rule4 = "Missing ItemTag or Description"; |
52 |
public string Rule5 = "Line Disconnected"; |
53 |
|
54 |
int tieInPointIndex = 1; |
55 |
|
56 |
List<Document> Documents; |
57 |
List<Group> groups = new List<Group>(); |
58 |
List<PSNItem> PSNItems = new List<PSNItem>(); |
59 |
List<Topology> Topologies = new List<Topology>(); |
60 |
|
61 |
DataTable opcDT = null; |
62 |
DataTable topologyRuleDT = null; |
63 |
|
64 |
ID2Info id2Info = ID2Info.GetInstance(); |
65 |
|
66 |
|
67 |
|
68 |
//const string FluidPriorityType = "FLUIDCODE"; |
69 |
//const string PipingMaterialsPriorityType = "PIPINGMATERIALSCLASS"; |
70 |
|
71 |
public PSN() |
72 |
{ |
73 |
|
74 |
} |
75 |
|
76 |
public PSN(List<Document> documents, int Revision) |
77 |
{ |
78 |
try |
79 |
{ |
80 |
Documents = documents; |
81 |
foreach (Document document in Documents) |
82 |
groups.AddRange(document.Groups); |
83 |
opcDT = GetOPCInfo(); |
84 |
topologyRuleDT = GetTopologyRule(); |
85 |
this.Revision = Revision; |
86 |
DrawingSize = DB.GetDrawingSize(); |
87 |
if (DrawingSize == null) |
88 |
{ |
89 |
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); |
90 |
return; |
91 |
} |
92 |
DrawingWidth = DrawingSize[2] - DrawingSize[0]; |
93 |
DrawingHeight = DrawingSize[3] - DrawingSize[1]; |
94 |
} |
95 |
catch (Exception ex) |
96 |
{ |
97 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
98 |
MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
99 |
} |
100 |
} |
101 |
|
102 |
private string GetItemTag(Item item) |
103 |
{ |
104 |
string result = string.Empty; |
105 |
if (item.ItemType == ItemType.Line) |
106 |
result = item.LineNumber != null ? item.LineNumber.Name : string.Empty; |
107 |
else if (item.ItemType == ItemType.Symbol && item.SubItemType == SubItemType.Nozzle) |
108 |
result = Nozzle.Select(string.Format("OID = '{0}'", item.UID)).First()["ITEMTAG"].ToString(); |
109 |
|
110 |
return result; |
111 |
} |
112 |
private string GetItemName(Item item, string itemOID) |
113 |
{ |
114 |
string result = string.Empty; |
115 |
if (item.ItemType == ItemType.Line && (item.Name == "Secondary" || item.Name == "Primary")) |
116 |
{ |
117 |
if (itemOID.Contains("_")) |
118 |
{ |
119 |
string split = itemOID.Split(new char[] { '_' })[1]; |
120 |
if (split.StartsWith("B")) |
121 |
result = "Branch"; |
122 |
else |
123 |
result = "PipeRun"; |
124 |
} |
125 |
else |
126 |
result = "PipeRun"; |
127 |
} |
128 |
else if (item.ItemType == ItemType.Symbol) |
129 |
{ |
130 |
if (item.ID2DBCategory == "Instrumentation") |
131 |
result = "Instrument"; |
132 |
else if (item.ID2DBType == "Nozzles") |
133 |
result = "Nozzle"; |
134 |
else if (item.ID2DBType == "Fittings" || |
135 |
item.ID2DBType == "Piping OPC's" || |
136 |
item.ID2DBType == "Specialty Components" || |
137 |
item.ID2DBType == "Valves" || |
138 |
item.ID2DBType == "Reducers") |
139 |
result = "PipingComp"; |
140 |
} |
141 |
return result; |
142 |
} |
143 |
|
144 |
private string GetClass(Item item, string itemOID) |
145 |
{ |
146 |
string result = string.Empty; |
147 |
if (item.ItemType == ItemType.Line && (item.Name == "Secondary" || item.Name == "Primary")) |
148 |
{ |
149 |
if (itemOID.Contains("_")) |
150 |
{ |
151 |
string split = itemOID.Split(new char[] { '_' })[1]; |
152 |
if (split.StartsWith("B")) |
153 |
result = "Branch"; |
154 |
else |
155 |
result = "Piping"; |
156 |
} |
157 |
else |
158 |
result = "Piping"; |
159 |
} |
160 |
else if (item.ItemType == ItemType.Symbol) |
161 |
{ |
162 |
if (item.ID2DBCategory == "Instrumentation") |
163 |
result = item.ID2DBType; |
164 |
else if (item.ID2DBType == "Nozzles") |
165 |
result = string.Empty; |
166 |
else if (item.ID2DBType == "Fittings" || |
167 |
item.ID2DBType == "Piping OPC's" || |
168 |
item.ID2DBType == "Specialty Components" || |
169 |
item.ID2DBType == "Valves" || |
170 |
item.ID2DBType == "Reducers") |
171 |
result = item.ID2DBType; |
172 |
} |
173 |
return result; |
174 |
} |
175 |
|
176 |
private string GetSubClass(Item item, string itemOID) |
177 |
{ |
178 |
string result = string.Empty; |
179 |
if (item.ItemType == ItemType.Line && (item.Name == "Secondary" || item.Name == "Primary")) |
180 |
{ |
181 |
if (itemOID.Contains("_")) |
182 |
{ |
183 |
string split = itemOID.Split(new char[] { '_' })[1]; |
184 |
if (split.StartsWith("B")) |
185 |
result = "Tee"; |
186 |
else |
187 |
result = ""; |
188 |
} |
189 |
else |
190 |
result = ""; |
191 |
} |
192 |
else if (item.ItemType == ItemType.Symbol) |
193 |
{ |
194 |
if (item.ID2DBCategory == "Instrumentation") |
195 |
result = string.Empty; |
196 |
else if (item.ID2DBType == "Nozzles") |
197 |
result = string.Empty; |
198 |
else if (item.ID2DBType == "Fittings" || |
199 |
item.ID2DBType == "Piping OPC's" || |
200 |
item.ID2DBType == "Specialty Components" || |
201 |
item.ID2DBType == "Valves" || |
202 |
item.ID2DBType == "Reducers") |
203 |
result = "In-line component"; |
204 |
} |
205 |
return result; |
206 |
} |
207 |
|
208 |
public void SetPSNData(SplashScreenManager splashScreenManager1) |
209 |
{ |
210 |
// Item들의 속성으로 Topology Data를 생성한다. |
211 |
// Topology Data는 Topology Rule Setting을 기준으로 생성한다. |
212 |
int i = 1; |
213 |
splashScreenManager1.SetWaitFormDescription(i++ + " / 19 SetTopologyData ( 3 % )"); |
214 |
SetTopologyData(); |
215 |
// ID2의 OPC연결 Data 기반으로 Group(도면단위 PSN)을 연결한다. |
216 |
splashScreenManager1.SetWaitFormDescription(i++ + " / 19 ConnectByOPC ( 5 % )"); |
217 |
ConnectByOPC(); |
218 |
// 실제 PSN 생성 로직 |
219 |
// 연결된 Group을 하나의 PSN으로 만든다. |
220 |
splashScreenManager1.SetWaitFormDescription(i++ + " / 19 SetPSNItem ( 10 % )"); |
221 |
SetPSNItem(); |
222 |
// 생성된 PSN의 Type을 설정한다. |
223 |
splashScreenManager1.SetWaitFormDescription(i++ + " / 19 SetPSNType ( 15 % )"); |
224 |
SetPSNType(); |
225 |
// ID2에는 Branch 정보가 없어서 Branch 정보를 생성한다. |
226 |
splashScreenManager1.SetWaitFormDescription(i++ + " / 19 SetBranchInfo ( 20 % )"); |
227 |
SetBranchInfo(); |
228 |
// 생성된 Topology Data들을 정리하며 Main, Branch를 판단한다. |
229 |
splashScreenManager1.SetWaitFormDescription(i++ + " / 19 SetTopology ( 25 % )"); |
230 |
SetTopology(); |
231 |
// PSN이 Bypass인지 검사 |
232 |
splashScreenManager1.SetWaitFormDescription(i++ + " / 19 SetPSNBypass ( 30 % )"); |
233 |
SetPSNBypass(); |
234 |
// Topology들에게 Index를 부여한다 |
235 |
splashScreenManager1.SetWaitFormDescription(i++ + " / 19 SetTopologyIndex ( 35 % )"); |
236 |
SetTopologyIndex(); |
237 |
// Nozzle, Equipment의 정보를 저장 |
238 |
splashScreenManager1.SetWaitFormDescription(i++ + " / 19 SaveNozzleAndEquipment ( 40 % )"); |
239 |
SaveNozzleAndEquipment(); |
240 |
// PSN의 정보를 저장 |
241 |
splashScreenManager1.SetWaitFormDescription(i++ + " / 19 SetPSNData ( 45 % )"); |
242 |
SavePSNData(); |
243 |
// Update Keyword |
244 |
splashScreenManager1.SetWaitFormDescription(i++ + " / 19 UpdateKeywordForPSN ( 55 % )"); |
245 |
UpdateKeywordForPSN(); |
246 |
|
247 |
// Topology의 subtype을 update(bypass, Header, 등등) |
248 |
splashScreenManager1.SetWaitFormDescription(i++ + " / 19 UpdateSubType ( 60 % )"); |
249 |
UpdateSubType(); |
250 |
// Update Error |
251 |
splashScreenManager1.SetWaitFormDescription(i++ + " / 19 UpdateErrorForPSN ( 65 % )"); |
252 |
PathItemSorting(); |
253 |
UpdateErrorForPSN(); |
254 |
// Insert Tee |
255 |
splashScreenManager1.SetWaitFormDescription(i++ + " / 19 InsertTeePSN ( 70 % )"); |
256 |
InsertTeePSN(); |
257 |
|
258 |
// ValveGrouping |
259 |
splashScreenManager1.SetWaitFormDescription(i++ + " / 19 UpdateValveGrouping ( 75 % )"); |
260 |
UpdateValveGrouping(); |
261 |
|
262 |
splashScreenManager1.SetWaitFormDescription(i++ + " / 19 PathItemSorting ( 80 % )"); |
263 |
PathItemSorting(); |
264 |
|
265 |
// AirFinCooler |
266 |
splashScreenManager1.SetWaitFormDescription(i++ + " / 19 UpdateAirFinCooler ( 85 % )"); |
267 |
UpdateAirFinCooler(); |
268 |
|
269 |
// Vent/Drain PSN 데이터 제거 |
270 |
splashScreenManager1.SetWaitFormDescription(i++ + " / 19 DeleteVentDrain ( 90 % )"); |
271 |
DeleteVentDrain(); |
272 |
|
273 |
// 확도 계산 |
274 |
splashScreenManager1.SetWaitFormDescription(i++ + " / 19 UpdateAccuracy ( 95 % )"); |
275 |
UpdateAccuracy(); |
276 |
|
277 |
//UpdatePSNType(); |
278 |
|
279 |
} |
280 |
|
281 |
private void UpdatePSNType() |
282 |
{ |
283 |
try |
284 |
{ |
285 |
foreach (PSNItem PSNItem in PSNItems) |
286 |
{ |
287 |
foreach (Group group in PSNItem.Groups) |
288 |
{ |
289 |
foreach (Item item in group.Items) |
290 |
{ |
291 |
DataRow[] pipeSystems = PipeSystemNetwork.Select(string.Format("OID = '{0}'", PSNItem.PSN_OID())); |
292 |
// PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString()); |
293 |
|
294 |
foreach(DataRow dr in pipeSystems) |
295 |
{ |
296 |
dr["Type"] = PSNItem.GetPSNType(); |
297 |
} |
298 |
} |
299 |
} |
300 |
} |
301 |
} |
302 |
catch (Exception ex) |
303 |
{ |
304 |
MessageBox.Show(ex.Message, "ID2 ", MessageBoxButtons.OK, MessageBoxIcon.Error); |
305 |
} |
306 |
} |
307 |
|
308 |
private void PathItemSorting() |
309 |
{ |
310 |
try |
311 |
{ |
312 |
DataTable dtPathItems = PathItems.Clone(); |
313 |
DataTable dtPipeSystemNetwork = PipeSystemNetwork.DefaultView.ToTable(true, new string[] { "OID" }); |
314 |
|
315 |
foreach (DataRow drpipe in dtPipeSystemNetwork.Rows) |
316 |
{ |
317 |
DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", drpipe["OID"].ToString())); |
318 |
DataTable dtSequenceItems = SequenceData.Clone(); |
319 |
foreach (DataRow drpath in pathItemRows) |
320 |
{ |
321 |
DataRow sequenceRows = SequenceData.Select(string.Format("PathItem_OID = '{0}'", drpath.Field<string>("OID"))).First(); |
322 |
|
323 |
DataRow newRow = dtSequenceItems.NewRow(); |
324 |
foreach (DataColumn column in SequenceData.Columns) |
325 |
if (dtSequenceItems.Columns[column.ColumnName] != null) |
326 |
newRow[column.ColumnName] = sequenceRows[column.ColumnName]; |
327 |
|
328 |
dtSequenceItems.Rows.Add(newRow); |
329 |
} |
330 |
|
331 |
foreach (DataRow sqrow in dtSequenceItems.Select().OrderBy(x => Convert.ToInt32(x.Field<string>("SERIALNUMBER")))) |
332 |
{ |
333 |
DataRow newRow = dtPathItems.NewRow(); |
334 |
DataRow row = PathItems.Select(string.Format("OID = '{0}'", sqrow["PathItem_OID"])).First(); |
335 |
|
336 |
foreach (DataColumn column in PathItems.Columns) |
337 |
if (dtPathItems.Columns[column.ColumnName] != null) |
338 |
newRow[column.ColumnName] = row[column.ColumnName]; |
339 |
|
340 |
dtPathItems.Rows.Add(newRow); |
341 |
} |
342 |
} |
343 |
|
344 |
PathItems.Clear(); |
345 |
PathItems = dtPathItems.Copy(); |
346 |
} |
347 |
catch (Exception ex) |
348 |
{ |
349 |
MessageBox.Show(ex.Message, "ID2 ", MessageBoxButtons.OK, MessageBoxIcon.Error); |
350 |
} |
351 |
} |
352 |
|
353 |
private void UpdateAirFinCooler() |
354 |
{ |
355 |
try |
356 |
{ |
357 |
|
358 |
int pumpTagNum = 0; |
359 |
#region EquipmentAirFinCooler Info |
360 |
EquipmentAirFinCoolerInfo EquipmentAirFinCooler = new EquipmentAirFinCoolerInfo(); |
361 |
DataTable dtEquipmentAirFinCooler = DB.SelectAirFinCoolerSetting(); |
362 |
foreach (DataRow row in dtEquipmentAirFinCooler.Rows) |
363 |
{ |
364 |
EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Add(new EquipmentAirFinCoolerItem() |
365 |
{ |
366 |
Type = row["Type"].ToString(), |
367 |
TagIdentifier = row["TagIdentifier"].ToString(), |
368 |
AttributeName = row["AttributeName"].ToString(), |
369 |
Name = row["Name"].ToString() |
370 |
}); |
371 |
} |
372 |
#endregion |
373 |
|
374 |
|
375 |
DataRow[] pumpRows = PipeSystemNetwork.Select("PUMP = 'PUMP'"); |
376 |
// 1, 2번 |
377 |
foreach (DataRow dataRow in pumpRows) |
378 |
{ |
379 |
DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"].ToString())); |
380 |
|
381 |
string EGTAG = "EGTAG"; |
382 |
string ItemTag = "ItemTag"; |
383 |
string EGFlowDirection = string.Empty; |
384 |
string Prefix = string.Empty; |
385 |
Dictionary<string, string> eqkeyValuePairs = new Dictionary<string, string>(); |
386 |
|
387 |
PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString()); |
388 |
if (PSNItem.Groups.First().Items.First().Equipment != null) |
389 |
{ |
390 |
if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && PSNItem.Groups.First().Items.First().Equipment.Name.Contains(x.Name)).Count() > 0) |
391 |
{ |
392 |
EquipmentAirFinCoolerItem equipmentAirFinCoolerItem = EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && PSNItem.Groups.First().Items.First().Equipment.Name.Contains(x.Name)).First(); |
393 |
if (!string.IsNullOrEmpty(equipmentAirFinCoolerItem.AttributeName)) |
394 |
EGTAG = PSNItem.Groups.First().Items.First().Equipment.Attributes.Find(x => x.Name == equipmentAirFinCoolerItem.AttributeName) == null |
395 |
? string.Empty : PSNItem.Groups.First().Items.First().Equipment.Attributes.Find(x => x.Name == equipmentAirFinCoolerItem.AttributeName).Value; |
396 |
|
397 |
ItemTag = PSNItem.Groups.First().Items.First().Equipment.ItemTag; |
398 |
Prefix = equipmentAirFinCoolerItem.TagIdentifier; |
399 |
EGFlowDirection = "O"; |
400 |
} |
401 |
} |
402 |
else if(PSNItem.Groups.Last().Items.Last().Equipment != null) |
403 |
{ |
404 |
if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && PSNItem.Groups.Last().Items.Last().Equipment.Name.Contains(x.Name)).Count() > 0) |
405 |
{ |
406 |
EquipmentAirFinCoolerItem equipmentAirFinCoolerItem = EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && PSNItem.Groups.Last().Items.Last().Equipment.Name.Contains(x.Name)).First(); |
407 |
if (!string.IsNullOrEmpty(equipmentAirFinCoolerItem.AttributeName)) |
408 |
EGTAG = PSNItem.Groups.Last().Items.Last().Equipment.Attributes.Find(x => x.Name == equipmentAirFinCoolerItem.AttributeName) == null |
409 |
? string.Empty : PSNItem.Groups.Last().Items.Last().Equipment.Attributes.Find(x => x.Name == equipmentAirFinCoolerItem.AttributeName).Value; |
410 |
|
411 |
ItemTag = PSNItem.Groups.Last().Items.Last().Equipment.ItemTag; |
412 |
Prefix = equipmentAirFinCoolerItem.TagIdentifier; |
413 |
EGFlowDirection = "I"; |
414 |
} |
415 |
} |
416 |
|
417 |
//Attribute가 세팅되어있지 않다면 |
418 |
if (EGTAG.Equals("EGTAG")) |
419 |
{ |
420 |
if (!eqkeyValuePairs.ContainsKey(ItemTag)) |
421 |
{ |
422 |
pumpTagNum++; |
423 |
EGTAG = Prefix + string.Format("-{0}", string.Format("{0:D5}", pumpTagNum)); |
424 |
eqkeyValuePairs.Add(ItemTag, EGTAG); |
425 |
} |
426 |
else |
427 |
{ |
428 |
EGTAG = eqkeyValuePairs[ItemTag]; |
429 |
} |
430 |
} |
431 |
else |
432 |
{ |
433 |
EGTAG = Prefix + "-" + EGTAG; |
434 |
} |
435 |
|
436 |
foreach (DataRow dr in pathItemRows) |
437 |
{ |
438 |
dr["EqpGroupTag"] = EGTAG; |
439 |
dr["EGFlowDirection"] = EGFlowDirection; |
440 |
} |
441 |
} |
442 |
|
443 |
// 3, 4번 |
444 |
foreach (DataRow dataRow in pumpRows) |
445 |
{ |
446 |
|
447 |
DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"].ToString())); |
448 |
PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString()); |
449 |
string EGFlowDirection = string.Empty; |
450 |
|
451 |
if (PSNItem.Groups.First().Items.First().Equipment != null) |
452 |
{ |
453 |
if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && PSNItem.Groups.First().Items.First().Equipment.Name.Contains(x.Name)).Count() > 0) |
454 |
{ |
455 |
EGFlowDirection = "O"; |
456 |
} |
457 |
} |
458 |
else if (PSNItem.Groups.Last().Items.Last().Equipment != null) |
459 |
{ |
460 |
if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && PSNItem.Groups.Last().Items.Last().Equipment.Name.Contains(x.Name)).Count() > 0) |
461 |
{ |
462 |
EGFlowDirection = "I"; |
463 |
} |
464 |
} |
465 |
|
466 |
|
467 |
List<string> lstViewPipeSystemNetwork_OID = new List<string>(); |
468 |
|
469 |
foreach (DataRow dr in pathItemRows) |
470 |
{ |
471 |
if(dr.Field<string>("ViewPipeSystemNetwork_OID") != dataRow["OID"].ToString()) |
472 |
{ |
473 |
string viewEGFlowDirection = string.Empty; |
474 |
if (PipeSystemNetwork.Select(string.Format("OID = '{0}'", dr.Field<string>("ViewPipeSystemNetwork_OID"))).Count() > 0) |
475 |
{ |
476 |
PSNItem viewPSNItem = PSNItems.Find(x => x.PSN_OID() == dr.Field<string>("ViewPipeSystemNetwork_OID")); |
477 |
|
478 |
if (viewPSNItem.Groups.First().Items.First().Equipment != null) |
479 |
{ |
480 |
if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && viewPSNItem.Groups.First().Items.First().Equipment.Name.Contains(x.Name)).Count() > 0) |
481 |
{ |
482 |
viewEGFlowDirection = "O"; |
483 |
} |
484 |
} |
485 |
else if (viewPSNItem.Groups.Last().Items.Last().Equipment != null) |
486 |
{ |
487 |
if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && viewPSNItem.Groups.Last().Items.Last().Equipment.Name.Contains(x.Name)).Count() > 0) |
488 |
{ |
489 |
viewEGFlowDirection = "I"; |
490 |
} |
491 |
} |
492 |
|
493 |
if (EGFlowDirection.Equals(viewEGFlowDirection) && !lstViewPipeSystemNetwork_OID.Contains(dr.Field<string>("ViewPipeSystemNetwork_OID"))) |
494 |
lstViewPipeSystemNetwork_OID.Add(dr.Field<string>("ViewPipeSystemNetwork_OID")); |
495 |
} |
496 |
else |
497 |
{ |
498 |
} |
499 |
} |
500 |
} |
501 |
|
502 |
string selectViewOID = string.Empty; |
503 |
|
504 |
if (EGFlowDirection == "O") //From 이면 시작점에서 제일 먼 값 |
505 |
{ |
506 |
foreach (string viewOID in lstViewPipeSystemNetwork_OID) |
507 |
{ |
508 |
if (PipeSystemNetwork.Select(string.Format("PUMP = 'PUMP' AND OID = '{0}'", viewOID)).Count() > 0) |
509 |
{ |
510 |
selectViewOID = pathItemRows.Where(x => x.Field<string>("ViewPipeSystemNetwork_OID") == viewOID).Last().Field<string>("OID"); |
511 |
} |
512 |
} |
513 |
} |
514 |
else if (EGFlowDirection == "I") //To 이면 시작점에서 제일 가까운 값 |
515 |
{ |
516 |
foreach (string viewOID in lstViewPipeSystemNetwork_OID) |
517 |
{ |
518 |
if (PipeSystemNetwork.Select(string.Format("PUMP = 'PUMP' AND OID = '{0}'", viewOID)).Count() > 0) |
519 |
{ |
520 |
selectViewOID = pathItemRows.Where(x => x.Field<string>("ViewPipeSystemNetwork_OID") == viewOID).Last().Field<string>("OID"); |
521 |
break; |
522 |
} |
523 |
} |
524 |
} |
525 |
|
526 |
if (!string.IsNullOrEmpty(selectViewOID)) //selectViewOID 가 있으면 |
527 |
{ |
528 |
string EqpGroupTag = string.Empty; |
529 |
|
530 |
if((EGFlowDirection == "O" && lstViewPipeSystemNetwork_OID.Contains(pathItemRows.Last().Field<string>("ViewPipeSystemNetwork_OID"))) || |
531 |
(EGFlowDirection == "I" && lstViewPipeSystemNetwork_OID.Contains(pathItemRows.First().Field<string>("ViewPipeSystemNetwork_OID")))) |
532 |
{ |
533 |
DataRow[] viewpathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", pathItemRows.First().Field<string>("ViewPipeSystemNetwork_OID"))); |
534 |
|
535 |
foreach (DataRow row in viewpathItemRows) |
536 |
{ |
537 |
if (!string.IsNullOrEmpty(row.Field<string>("EqpGroupTag"))) |
538 |
{ |
539 |
EqpGroupTag = row.Field<string>("EqpGroupTag"); |
540 |
break; |
541 |
} |
542 |
} |
543 |
|
544 |
foreach (DataRow dr in pathItemRows) |
545 |
{ |
546 |
dr["EqpGroupTag"] = EqpGroupTag; |
547 |
} |
548 |
|
549 |
} |
550 |
else |
551 |
{ |
552 |
bool bCheck = false; |
553 |
if (EGFlowDirection == "I") //To 일때 |
554 |
{ |
555 |
foreach (DataRow dr in pathItemRows) |
556 |
{ |
557 |
if (selectViewOID == dr["OID"].ToString()) |
558 |
{ |
559 |
dr["EGTConnectedPoint"] = "1"; |
560 |
bCheck = true; |
561 |
} |
562 |
|
563 |
if (!bCheck) |
564 |
{ |
565 |
dr["EqpGroupTag"] = string.Empty; |
566 |
dr["MainLineTag"] = string.Empty; |
567 |
dr["EGTConnectedPoint"] = "0"; |
568 |
dr["EGFlowDirection"] = string.Empty; |
569 |
} |
570 |
else |
571 |
{ |
572 |
dr["MainLineTag"] = "M"; |
573 |
} |
574 |
|
575 |
} |
576 |
|
577 |
} |
578 |
else if (EGFlowDirection == "O") //From 일 때 |
579 |
{ |
580 |
foreach (DataRow dr in pathItemRows) |
581 |
{ |
582 |
if (bCheck) |
583 |
{ |
584 |
|
585 |
dr["EqpGroupTag"] = string.Empty; |
586 |
dr["MainLineTag"] = string.Empty; |
587 |
dr["EGTConnectedPoint"] = "0"; |
588 |
dr["EGFlowDirection"] = string.Empty; |
589 |
} |
590 |
else |
591 |
{ |
592 |
dr["MainLineTag"] = "M"; |
593 |
} |
594 |
|
595 |
if (selectViewOID == dr["OID"].ToString()) |
596 |
{ |
597 |
dr["EGTConnectedPoint"] = "1"; |
598 |
bCheck = true; |
599 |
} |
600 |
} |
601 |
} |
602 |
} |
603 |
} |
604 |
else |
605 |
{ |
606 |
foreach (DataRow dr in pathItemRows) |
607 |
{ |
608 |
dr["EqpGroupTag"] = string.Empty; |
609 |
dr["EGFlowDirection"] = string.Empty; |
610 |
} |
611 |
} |
612 |
} |
613 |
|
614 |
// 5번 |
615 |
foreach (DataRow dataRow in pumpRows) |
616 |
{ |
617 |
DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"].ToString())); |
618 |
|
619 |
bool bCheck = false; |
620 |
string EqpGroupTag = string.Empty; |
621 |
|
622 |
string EGFlowDirection = string.Empty; |
623 |
|
624 |
PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow.Field<string>("OID")); |
625 |
|
626 |
if (PSNItem.Groups.First().Items.First().Equipment != null) |
627 |
{ |
628 |
if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && PSNItem.Groups.First().Items.First().Equipment.Name.Contains(x.Name)).Count() > 0) |
629 |
{ |
630 |
EGFlowDirection = "O"; |
631 |
} |
632 |
} |
633 |
else if (PSNItem.Groups.Last().Items.Last().Equipment != null) |
634 |
{ |
635 |
if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && PSNItem.Groups.Last().Items.Last().Equipment.Name.Contains(x.Name)).Count() > 0) |
636 |
{ |
637 |
EGFlowDirection = "I"; |
638 |
} |
639 |
} |
640 |
|
641 |
List<string> lstViewPipeSystemNetwork_OID = new List<string>(); |
642 |
List<string> lstEqTagRows = new List<string>(); |
643 |
if (EGFlowDirection.Equals("I")) |
644 |
{ |
645 |
foreach (DataRow dr in pathItemRows) |
646 |
{ |
647 |
if (!string.IsNullOrEmpty(dr.Field<string>("MainLineTag")) && dr.Field<string>("MainLineTag").Equals("M") && !string.IsNullOrEmpty(dr.Field<string>("EqpGroupTag"))) |
648 |
{ |
649 |
bCheck = true; |
650 |
EqpGroupTag = dr.Field<string>("EqpGroupTag"); |
651 |
if(!lstEqTagRows.Contains(EqpGroupTag)) |
652 |
lstEqTagRows.Add(EqpGroupTag); |
653 |
|
654 |
if(dataRow["OID"].ToString() != dr.Field<string>("ViewPipeSystemNetwork_OID")) |
655 |
{ |
656 |
PSNItem viewPSNItem = PSNItems.Find(x => x.PSN_OID() == dr.Field<string>("ViewPipeSystemNetwork_OID")); |
657 |
if (viewPSNItem.Groups.Last().Items.Last().Equipment == null) |
658 |
continue; |
659 |
|
660 |
if (!lstEqTagRows.Contains(viewPSNItem.Groups.Last().Items.Last().Equipment.ItemTag)) |
661 |
lstEqTagRows.Add(viewPSNItem.Groups.Last().Items.Last().Equipment.ItemTag); |
662 |
} |
663 |
|
664 |
} |
665 |
|
666 |
} |
667 |
if(bCheck) |
668 |
{ |
669 |
foreach (DataRow row in pumpRows) |
670 |
{ |
671 |
if (row.Field<string>("OID").Equals(dataRow["OID"].ToString())) |
672 |
continue; |
673 |
|
674 |
PSNItem viewPSNItem = PSNItems.Find(x => x.PSN_OID() == row["OID"].ToString()); |
675 |
|
676 |
if (viewPSNItem.Groups.First().Items.First().Equipment == null) |
677 |
continue; |
678 |
|
679 |
if (lstEqTagRows.Contains(viewPSNItem.Groups.First().Items.First().Equipment.ItemTag) && !lstViewPipeSystemNetwork_OID.Contains(row.Field<string>("OID"))) |
680 |
lstViewPipeSystemNetwork_OID.Add(row.Field<string>("OID")); |
681 |
} |
682 |
|
683 |
|
684 |
|
685 |
if (lstViewPipeSystemNetwork_OID.Count() > 0) |
686 |
{ |
687 |
foreach (string viewPipesystem in lstViewPipeSystemNetwork_OID) |
688 |
{ |
689 |
DataRow[] viewpathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", viewPipesystem)); |
690 |
foreach (DataRow viewdr in viewpathItemRows) |
691 |
{ |
692 |
if (!string.IsNullOrEmpty(viewdr["EqpGroupTag"].ToString())) |
693 |
viewdr["EqpGroupTag"] = EqpGroupTag; |
694 |
} |
695 |
} |
696 |
} |
697 |
} |
698 |
} |
699 |
} |
700 |
|
701 |
int afcTagNum = 0; |
702 |
DataRow[] airFinCoolerRows = PipeSystemNetwork.Select("AFC Like 'P1%'"); |
703 |
Dictionary<string, string> keyValuePairs = new Dictionary<string, string>(); |
704 |
foreach (DataRow dataRow in airFinCoolerRows) |
705 |
{ |
706 |
string EGFlowDirection = string.Empty; |
707 |
string EGTAG = "EGTAG"; |
708 |
string Prefix = string.Empty; |
709 |
//item.Attributes.Find(x => x.Name == valveitem.AttributeName).Value; |
710 |
PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString()); |
711 |
if (PSNItem.Groups.First().Items.First().Equipment != null) |
712 |
{ |
713 |
if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type != "Pump" && PSNItem.Groups.First().Items.First().Equipment.Name.Contains(x.Name)).Count() > 0) |
714 |
{ |
715 |
EquipmentAirFinCoolerItem equipmentAirFinCoolerItem = EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type != "Pump" && PSNItem.Groups.First().Items.First().Equipment.Name.Contains(x.Name)).First(); |
716 |
if(!string.IsNullOrEmpty(equipmentAirFinCoolerItem.AttributeName)) |
717 |
EGTAG = PSNItem.Groups.First().Items.First().Equipment.Attributes.Find(x => x.Name == equipmentAirFinCoolerItem.AttributeName) == null |
718 |
? string.Empty : PSNItem.Groups.First().Items.First().Equipment.Attributes.Find(x => x.Name == equipmentAirFinCoolerItem.AttributeName).Value; |
719 |
|
720 |
Prefix = equipmentAirFinCoolerItem.TagIdentifier; |
721 |
EGFlowDirection = "O"; |
722 |
} |
723 |
} |
724 |
else if (PSNItem.Groups.Last().Items.Last().Equipment != null) |
725 |
{ |
726 |
if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type != "Pump" && PSNItem.Groups.Last().Items.Last().Equipment.Name.Contains(x.Name)).Count() > 0) |
727 |
{ |
728 |
EquipmentAirFinCoolerItem equipmentAirFinCoolerItem = EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type != "Pump" && PSNItem.Groups.Last().Items.Last().Equipment.Name.Contains(x.Name)).First(); |
729 |
if (!string.IsNullOrEmpty(equipmentAirFinCoolerItem.AttributeName)) |
730 |
EGTAG = PSNItem.Groups.Last().Items.Last().Equipment.Attributes.Find(x => x.Name == equipmentAirFinCoolerItem.AttributeName) == null |
731 |
? string.Empty : PSNItem.Groups.Last().Items.Last().Equipment.Attributes.Find(x => x.Name == equipmentAirFinCoolerItem.AttributeName).Value; |
732 |
|
733 |
Prefix = equipmentAirFinCoolerItem.TagIdentifier; |
734 |
EGFlowDirection = "I"; |
735 |
} |
736 |
} |
737 |
|
738 |
if(!string.IsNullOrEmpty(EGFlowDirection)) |
739 |
{ |
740 |
string[] afcTag = dataRow.Field<string>("AFC").Split(new string[] { "\\" }, StringSplitOptions.None); |
741 |
|
742 |
//Attribute가 세팅되어있지 않다면 |
743 |
if (EGTAG.Equals("EGTAG")) |
744 |
{ |
745 |
if (!keyValuePairs.ContainsKey(afcTag[1])) |
746 |
{ |
747 |
afcTagNum++; |
748 |
EGTAG = Prefix + string.Format("-{0}", string.Format("{0:D5}", afcTagNum)); |
749 |
keyValuePairs.Add(afcTag[1], EGTAG); |
750 |
} |
751 |
else |
752 |
{ |
753 |
EGTAG = keyValuePairs[afcTag[1]]; |
754 |
} |
755 |
} |
756 |
else |
757 |
{ |
758 |
EGTAG = Prefix + "-" + EGTAG; |
759 |
} |
760 |
|
761 |
DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"].ToString())); |
762 |
foreach (DataRow dr in pathItemRows) |
763 |
{ |
764 |
dr["EqpGroupTag"] = EGTAG; |
765 |
dr["EGFlowDirection"] = EGFlowDirection; |
766 |
} |
767 |
} |
768 |
|
769 |
} |
770 |
|
771 |
List<string> changePSN = new List<string>(); |
772 |
foreach (DataRow dataRow in airFinCoolerRows) |
773 |
{ |
774 |
if (changePSN.Contains(dataRow["OID"].ToString())) |
775 |
continue; |
776 |
|
777 |
DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"].ToString())); |
778 |
string AFCTag = string.Empty; |
779 |
if (pathItemRows.Where(x => !string.IsNullOrEmpty(x.Field<string>("EqpGroupTag"))).Count() > 0) |
780 |
AFCTag = pathItemRows.Where(x => !string.IsNullOrEmpty(x.Field<string>("EqpGroupTag"))).First().Field<string>("EqpGroupTag"); |
781 |
|
782 |
List<string> lstViewPipeSystemNetwork_OID = pathItemRows.Select(x => x.Field<string>("ViewPipeSystemNetwork_OID")).Distinct().ToList(); |
783 |
|
784 |
if (dataRow["Type"].ToString() == "E2E") |
785 |
{ |
786 |
foreach (DataRow dr in pathItemRows) |
787 |
{ |
788 |
dr["MainLineTag"] = "M"; |
789 |
} |
790 |
dataRow["AFC"] = "P3"; |
791 |
} |
792 |
else if (dataRow["Type"].ToString() == "E2B" || dataRow["Type"].ToString() == "B2E") |
793 |
{ |
794 |
foreach (string lstoid in lstViewPipeSystemNetwork_OID) |
795 |
{ |
796 |
DataRow[] viewPathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", lstoid)); |
797 |
List<string> lstview = viewPathItemRows.Select(x => x.Field<string>("ViewPipeSystemNetwork_OID")).Distinct().ToList(); |
798 |
lstview.Remove(dataRow["OID"].ToString()); // P1인 자기 자신 제거 |
799 |
//제거 후 다른 P2를 확인 |
800 |
foreach (string lstvw in lstview) |
801 |
{ |
802 |
DataRow[] pipesn = PipeSystemNetwork.Select(string.Format("OID = '{0}' AND AFC = 'P2'", lstvw)); |
803 |
if(pipesn.Count() > 0) |
804 |
{ |
805 |
List<string> lstpipe = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", lstvw)).Select(x=>x.Field<string>("ViewPipeSystemNetwork_OID")).Distinct().ToList(); |
806 |
lstpipe.Remove(lstvw); //현재 자기 라인 제거 |
807 |
lstpipe.Remove(dataRow["OID"].ToString()); //기준 P1 제거 |
808 |
List<string> lstnewpipe = new List<string>(); |
809 |
foreach (string pipe in lstpipe) |
810 |
{ |
811 |
if (airFinCoolerRows.Where(x => x.Field<string>("OID").Equals(pipe)).Count() > 0) //P1이면 리스트에 추가 |
812 |
lstnewpipe.Add(pipe); |
813 |
} |
814 |
|
815 |
if (lstnewpipe.Count() == 0) |
816 |
{ |
817 |
foreach (DataRow dr in pathItemRows) |
818 |
{ |
819 |
dr["MainLineTag"] = "M"; |
820 |
} |
821 |
dataRow["AFC"] = "P3"; |
822 |
} |
823 |
else if (lstnewpipe.Count() > 0) //P2에 기준 P1 말고 다른 P1이 있다면 P2에 ML값 AGT값 지정 후 P2에 연결된 모든 P1들의 AGT값 치환 |
824 |
{ |
825 |
// P2에 ML값 AGT값 지정 |
826 |
DataRow[] viewpathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", lstvw)); |
827 |
DataRow[] pipesystemRows = PipeSystemNetwork.Select(string.Format("OID = '{0}'", lstvw)); |
828 |
foreach (DataRow viewdr in pipesystemRows) |
829 |
{ |
830 |
viewdr["AFC"] = "P4"; |
831 |
} |
832 |
|
833 |
foreach (DataRow viewdr in viewpathItemRows) |
834 |
{ |
835 |
viewdr["EqpGroupTag"] = AFCTag; |
836 |
viewdr["MainLineTag"] = "M"; |
837 |
} |
838 |
// 연결된 모든 P1들의 AGT값 치환 |
839 |
foreach (string pipe in lstnewpipe) |
840 |
{ |
841 |
viewpathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", pipe)); |
842 |
foreach (DataRow viewdr in viewpathItemRows) |
843 |
{ |
844 |
viewdr["EqpGroupTag"] = AFCTag; |
845 |
} |
846 |
} |
847 |
} |
848 |
} |
849 |
} |
850 |
} |
851 |
} |
852 |
|
853 |
} |
854 |
//P3을 제외한 P1 |
855 |
airFinCoolerRows = PipeSystemNetwork.Select("AFC Like 'P1%'"); |
856 |
foreach (DataRow dataRow in airFinCoolerRows) |
857 |
{ |
858 |
DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"].ToString())); |
859 |
|
860 |
if (pathItemRows.Count() > 0) |
861 |
{ |
862 |
List<string> lstViewPipeSystemNetwork_OID = pathItemRows.Select(x => x.Field<string>("ViewPipeSystemNetwork_OID")).Distinct().ToList(); |
863 |
List<string> lstpsn = new List<string>(); |
864 |
List<string> lstAll = new List<string>(); |
865 |
string EqpGroupTag = string.Empty; |
866 |
foreach (string viewOID in lstViewPipeSystemNetwork_OID) |
867 |
{ |
868 |
if (dataRow["OID"].ToString() == viewOID) |
869 |
{ |
870 |
lstAll.Add(viewOID); |
871 |
continue; |
872 |
} |
873 |
|
874 |
//P3이면 |
875 |
DataRow viewPSN = null; |
876 |
if (PipeSystemNetwork.Select(string.Format("OID = '{0}' AND AFC = 'P3'", viewOID)).Count() > 0) |
877 |
viewPSN = PipeSystemNetwork.Select(string.Format("OID = '{0}' AND AFC = 'P3'", viewOID)).First(); |
878 |
|
879 |
if (viewPSN != null) |
880 |
{ |
881 |
//P3의 AGT를 가져와 P1에 입력 |
882 |
if(string.IsNullOrEmpty(EqpGroupTag)) |
883 |
EqpGroupTag = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", viewOID)).First().Field<string>("EqpGroupTag"); |
884 |
|
885 |
foreach (DataRow dr in pathItemRows) |
886 |
{ |
887 |
|
888 |
dr["EqpGroupTag"] = EqpGroupTag; |
889 |
|
890 |
//P1의 AGT와 같은 모든 AGT를 P3의 AGT로 변경하기위해 |
891 |
if (!string.IsNullOrEmpty(dr.Field<string>("ViewPipeSystemNetwork_OID")) && !lstpsn.Contains(dr.Field<string>("ViewPipeSystemNetwork_OID"))) |
892 |
{ |
893 |
//AND MainLineTag = '' |
894 |
if (PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}' ", dr.Field<string>("ViewPipeSystemNetwork_OID"))).Count() > 0) |
895 |
{ |
896 |
lstpsn.Add(dr.Field<string>("ViewPipeSystemNetwork_OID")); |
897 |
lstAll.Add(dr.Field<string>("ViewPipeSystemNetwork_OID")); |
898 |
} |
899 |
} |
900 |
} |
901 |
} |
902 |
|
903 |
} |
904 |
|
905 |
while (lstpsn.Count() != 0) |
906 |
{ |
907 |
DataRow[] rule4pathItems = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", lstpsn[0])); |
908 |
foreach (DataRow dr in rule4pathItems) |
909 |
{ |
910 |
if (!string.IsNullOrEmpty(dr.Field<string>("ViewPipeSystemNetwork_OID")) && !lstAll.Contains(dr.Field<string>("ViewPipeSystemNetwork_OID"))) |
911 |
{ |
912 |
DataRow viewPSN = null; |
913 |
|
914 |
if (airFinCoolerRows.Where(x => x.Field<string>("OID") == dr.Field<string>("ViewPipeSystemNetwork_OID")).Count() > 0) |
915 |
viewPSN = airFinCoolerRows.Where(x => x.Field<string>("OID") == dr.Field<string>("ViewPipeSystemNetwork_OID")).First(); |
916 |
|
917 |
//DataRow[] pathItemviewRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dr.Field<string>("ViewPipeSystemNetwork_OID"))); |
918 |
//if (pathItemviewRows.Select(x => x.Field<string>("MainLineTag") == "M").Count() > 0) |
919 |
//{ |
920 |
//} |
921 |
if (viewPSN != null) |
922 |
{ |
923 |
lstpsn.Add(dr.Field<string>("ViewPipeSystemNetwork_OID")); |
924 |
lstAll.Add(dr.Field<string>("ViewPipeSystemNetwork_OID")); |
925 |
} |
926 |
} |
927 |
|
928 |
|
929 |
|
930 |
dr["EqpGroupTag"] = EqpGroupTag; |
931 |
|
932 |
} |
933 |
lstpsn.Remove(lstpsn[0]); |
934 |
} |
935 |
} |
936 |
|
937 |
} |
938 |
|
939 |
foreach(DataRow dr in PipeSystemNetwork.Rows) |
940 |
{ |
941 |
DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}' AND MainLineTag = 'M'", dr["OID"].ToString())); |
942 |
if(pathItemRows.Count() > 0) |
943 |
{ |
944 |
if(dr["Type"].ToString() == "HD2") |
945 |
{ |
946 |
List<string> lstViewPipeSystemNetwork_OID = pathItemRows.Select(x => x.Field<string>("ViewPipeSystemNetwork_OID")).Distinct().ToList(); |
947 |
foreach(string viewpsn in lstViewPipeSystemNetwork_OID) |
948 |
{ |
949 |
if (PipeSystemNetwork.Select(string.Format("OID = '{0}' AND AFC = 'P2'", viewpsn)).Count() > 0) |
950 |
{ |
951 |
foreach(DataRow dataRow in pathItemRows.Where(x => x.Field<string>("ViewPipeSystemNetwork_OID") == viewpsn)) |
952 |
{ |
953 |
dataRow["EGTConnectedPoint"] = "1"; |
954 |
} |
955 |
} |
956 |
} |
957 |
} |
958 |
else if(dr["Type"].ToString() == "E2B" || dr["Type"].ToString() == "B2E" || dr["Type"].ToString() == "E2E") |
959 |
{ |
960 |
List<string> lstViewPipeSystemNetwork_OID = pathItemRows.Select(x => x.Field<string>("ViewPipeSystemNetwork_OID")).Distinct().ToList(); |
961 |
string lastP1 = string.Empty; |
962 |
foreach (string viewpsn in lstViewPipeSystemNetwork_OID) |
963 |
{ |
964 |
if (viewpsn == dr["OID"].ToString()) |
965 |
continue; |
966 |
|
967 |
if (PipeSystemNetwork.Select(string.Format("OID = '{0}' AND AFC Like 'P1%'", viewpsn)).Length == 0) |
968 |
continue; |
969 |
|
970 |
DataRow rows = PipeSystemNetwork.Select(string.Format("OID = '{0}' AND AFC Like 'P1%'", viewpsn)).First(); |
971 |
if(rows != null) |
972 |
{ |
973 |
lastP1 = viewpsn; |
974 |
} |
975 |
} |
976 |
|
977 |
if(!string.IsNullOrEmpty(lastP1)) |
978 |
{ |
979 |
bool bCheck = false; |
980 |
foreach (DataRow dataRow in pathItemRows) |
981 |
{ |
982 |
if (bCheck) |
983 |
dataRow["EqpGroupTag"] = string.Empty; |
984 |
|
985 |
if (dataRow.Field<string>("ViewPipeSystemNetwork_OID").Equals(lastP1)) |
986 |
{ |
987 |
bCheck = true; |
988 |
dataRow["EGTConnectedPoint"] = 1; |
989 |
} |
990 |
} |
991 |
} |
992 |
} |
993 |
} |
994 |
} |
995 |
|
996 |
//psn data 정리 |
997 |
foreach(DataRow pipesystem in PipeSystemNetwork.Rows) |
998 |
{ |
999 |
DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", pipesystem["OID"].ToString())); |
1000 |
string EGTag = string.Empty; |
1001 |
string HasMLTags = "False"; |
1002 |
|
1003 |
foreach (DataRow dataRow in pathItemRows) |
1004 |
{ |
1005 |
if (string.IsNullOrEmpty(EGTag) && !string.IsNullOrEmpty(dataRow.Field<string>("EqpGroupTag"))) |
1006 |
EGTag = dataRow.Field<string>("EqpGroupTag"); |
1007 |
|
1008 |
if (HasMLTags.Equals("False") && !string.IsNullOrEmpty(dataRow.Field<string>("MainLineTag")) && dataRow.Field<string>("MainLineTag").Equals("M")) |
1009 |
HasMLTags = "True"; |
1010 |
|
1011 |
if (!string.IsNullOrEmpty(EGTag) && HasMLTags == "True") |
1012 |
break; |
1013 |
} |
1014 |
|
1015 |
pipesystem["EGTag"] = EGTag; |
1016 |
pipesystem["HasMLTags"] = HasMLTags; |
1017 |
} |
1018 |
} |
1019 |
catch (Exception ex) |
1020 |
{ |
1021 |
MessageBox.Show(ex.Message, "ID2 ", MessageBoxButtons.OK, MessageBoxIcon.Error); |
1022 |
} |
1023 |
//} |
1024 |
} |
1025 |
|
1026 |
private void UpdateValveGrouping() |
1027 |
{ |
1028 |
try |
1029 |
{ |
1030 |
#region ValveGrouping Info |
1031 |
ValveGroupInfo ValveGrouping = new ValveGroupInfo(); |
1032 |
DataTable dtValveGroupung = DB.SelectValveGroupItemsSetting(); |
1033 |
foreach (DataRow row in dtValveGroupung.Rows) |
1034 |
{ |
1035 |
ValveGrouping.ValveGroupItems.Add(new ValveGroupItem() |
1036 |
{ |
1037 |
OID = row["OID"].ToString(), |
1038 |
GroupType = row["GroupType"].ToString(), |
1039 |
TagIdentifier = row["TagIdentifier"].ToString(), |
1040 |
AttributeName = row["AttributeName"].ToString(), |
1041 |
SppidSymbolName = row["SppidSymbolName"].ToString() |
1042 |
}); |
1043 |
} |
1044 |
#endregion |
1045 |
|
1046 |
|
1047 |
int vgTagNum = 1; |
1048 |
DataRow[] tagpathItemRows = PathItems.Select(string.Format("GROUPTAG Like '%\\%'")); |
1049 |
foreach (DataRow drPathitem in tagpathItemRows) |
1050 |
{ |
1051 |
string[] valvetag = drPathitem["GROUPTAG"].ToString().Split(new string[] { "\\" }, StringSplitOptions.None); |
1052 |
DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", drPathitem["PipeSystemNetwork_OID"].ToString())); |
1053 |
ValveGroupItem valveitem = ValveGrouping.ValveGroupItems.Where(x => x.SppidSymbolName == valvetag[0]).FirstOrDefault(); |
1054 |
if (valveitem == null || valveitem.GroupType == "Scope Break") |
1055 |
continue; |
1056 |
Dictionary<int, List<DataRow>> keyValuePairs = new Dictionary<int, List<DataRow>>(); |
1057 |
List<Item> valveGroupingItem = new List<Item>(); |
1058 |
int bCnt = 0; |
1059 |
|
1060 |
|
1061 |
List<DataRow> lstitem = new List<DataRow>(); |
1062 |
foreach (DataRow dr in pathItemRows) |
1063 |
{ |
1064 |
if (!string.IsNullOrEmpty(dr["BranchTopologySet_OID"].ToString())) |
1065 |
{ |
1066 |
DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", dr["BranchTopologySet_OID"].ToString())); |
1067 |
if (dr["GROUPTAG"].ToString() == "Scope Break") |
1068 |
{ |
1069 |
dr["GROUPTAG"] = string.Empty; |
1070 |
keyValuePairs.Add(bCnt, lstitem.ToList()); |
1071 |
bCnt++; |
1072 |
lstitem.Clear(); |
1073 |
} |
1074 |
else |
1075 |
{ |
1076 |
if (rows.First()["SubType"].ToString() != "Bypass" && rows.First()["SubType"].ToString() != "Vent_Drain") |
1077 |
{ |
1078 |
if (lstitem.ToList().Where(x => !string.IsNullOrEmpty(x.Field<string>("GROUPTAG"))).Count() > 0) |
1079 |
{ |
1080 |
lstitem.Add(dr); |
1081 |
keyValuePairs.Add(bCnt, lstitem.ToList()); |
1082 |
lstitem.Clear(); |
1083 |
} |
1084 |
else |
1085 |
{ |
1086 |
keyValuePairs.Add(bCnt, lstitem.ToList()); |
1087 |
lstitem.Clear(); |
1088 |
lstitem.Add(dr); |
1089 |
} |
1090 |
bCnt++; |
1091 |
|
1092 |
} |
1093 |
else |
1094 |
lstitem.Add(dr); |
1095 |
} |
1096 |
} |
1097 |
else |
1098 |
lstitem.Add(dr); |
1099 |
} |
1100 |
|
1101 |
if (lstitem.Count > 0) |
1102 |
{ |
1103 |
keyValuePairs.Add(bCnt, lstitem); |
1104 |
} |
1105 |
|
1106 |
if (keyValuePairs.Count() == 0) |
1107 |
continue; |
1108 |
|
1109 |
string VGTag = string.Empty; |
1110 |
if (valveitem.AttributeName == "NoSelection" || valveitem.AttributeName == string.Empty) |
1111 |
{ |
1112 |
VGTag = valveitem.TagIdentifier + string.Format("-{0}", string.Format("{0:D5}", vgTagNum)); |
1113 |
vgTagNum++; |
1114 |
} |
1115 |
else |
1116 |
{ |
1117 |
//if(string.IsNullOrEmpty(valvetag[1])) |
1118 |
// VGTag = valveitem.TagIdentifier + string.Format("-{0}", string.Format("{0:D5}", vgTagNum)); |
1119 |
//else |
1120 |
VGTag = valveitem.TagIdentifier + "-" + valvetag[1]; |
1121 |
} |
1122 |
|
1123 |
foreach (KeyValuePair<int, List<DataRow>> keyValuePair in keyValuePairs) |
1124 |
{ |
1125 |
if (keyValuePair.Value.Where(x => x.Field<string>("OID") == drPathitem.Field<string>("OID")).Count() > 0) |
1126 |
{ |
1127 |
foreach (DataRow dr in keyValuePair.Value) |
1128 |
{ |
1129 |
dr["GROUPTAG"] = VGTag; |
1130 |
|
1131 |
if(!string.IsNullOrEmpty(dr["BranchTopologySet_OID"].ToString())) |
1132 |
{ |
1133 |
if(TopologySet.Select(string.Format("OID = '{0}'", dr["BranchTopologySet_OID"].ToString())).First().Field<string>("SubType") == "Bypass") |
1134 |
{ |
1135 |
DataRow[] rows = keyValuePair.Value.Where(x => x.Field<string>("ViewPipeSystemNetwork_OID").Equals(dr["ViewPipeSystemNetwork_OID"].ToString())).ToArray(); |
1136 |
foreach(DataRow path in rows) |
1137 |
{ |
1138 |
DataRow topology = TopologySet.Select(string.Format("OID = '{0}'", path["BranchTopologySet_OID"].ToString())).First(); |
1139 |
if (topology.Field<string>("SubType").Equals("Bypass")) |
1140 |
{ |
1141 |
DataRow[] drPathItem = PathItems.Select(string.Format("TopologySet_OID = '{0}'", topology.Field<string>("OID"))); |
1142 |
foreach(DataRow pathitem in drPathItem) |
1143 |
{ |
1144 |
pathitem["GROUPTAG"] = VGTag; |
1145 |
} |
1146 |
} |
1147 |
} |
1148 |
} |
1149 |
} |
1150 |
} |
1151 |
} |
1152 |
} |
1153 |
if(valveitem.GroupType.Contains("PSV")) |
1154 |
{ |
1155 |
DataRow[] psnRows = PipeSystemNetwork.Select(string.Format("OID = '{0}'", drPathitem["PipeSystemNetwork_OID"].ToString())); |
1156 |
foreach (DataRow row in psnRows) |
1157 |
row["Pocket"] = "Yes"; |
1158 |
} |
1159 |
} |
1160 |
} |
1161 |
catch (Exception ex) |
1162 |
{ |
1163 |
MessageBox.Show(ex.Message, "ID2 ", MessageBoxButtons.OK, MessageBoxIcon.Error); |
1164 |
} |
1165 |
} |
1166 |
|
1167 |
private void SetTopologyData() |
1168 |
{ |
1169 |
// 13번 excel |
1170 |
foreach (Group group in groups) |
1171 |
{ |
1172 |
LineNumber prevLineNumber = null; |
1173 |
for (int i = 0; i < group.Items.Count; i++) |
1174 |
{ |
1175 |
Item item = group.Items[i]; |
1176 |
LineNumber lineNumber = item.Document.LineNumbers.Find(x => x.UID == item.Owner); |
1177 |
if (lineNumber == null) |
1178 |
{ |
1179 |
if (prevLineNumber != null) |
1180 |
{ |
1181 |
if (!prevLineNumber.IsCopy) |
1182 |
{ |
1183 |
prevLineNumber = prevLineNumber.Copy(); |
1184 |
item.Document.LineNumbers.Add(prevLineNumber); |
1185 |
item.Document.MissingLineNumber1 = true; |
1186 |
} |
1187 |
item.Owner = prevLineNumber.UID; |
1188 |
} |
1189 |
} |
1190 |
else |
1191 |
prevLineNumber = lineNumber; |
1192 |
} |
1193 |
|
1194 |
prevLineNumber = null; |
1195 |
for (int i = group.Items.Count - 1; i > -1; i--) |
1196 |
{ |
1197 |
Item item = group.Items[i]; |
1198 |
LineNumber lineNumber = item.Document.LineNumbers.Find(x => x.UID == item.Owner); |
1199 |
if (lineNumber == null) |
1200 |
{ |
1201 |
if (prevLineNumber != null) |
1202 |
{ |
1203 |
if (!prevLineNumber.IsCopy) |
1204 |
{ |
1205 |
prevLineNumber = prevLineNumber.Copy(); |
1206 |
item.Document.LineNumbers.Add(prevLineNumber); |
1207 |
item.Document.MissingLineNumber1 = true; |
1208 |
} |
1209 |
|
1210 |
item.Owner = prevLineNumber.UID; |
1211 |
} |
1212 |
} |
1213 |
else |
1214 |
prevLineNumber = lineNumber; |
1215 |
} |
1216 |
|
1217 |
if (prevLineNumber == null) |
1218 |
{ |
1219 |
List<LineNumber> lineNumbers = group.Document.LineNumbers.FindAll(x => !x.IsCopy); |
1220 |
Random random = new Random(); |
1221 |
int index = random.Next(lineNumbers.Count - 1); |
1222 |
|
1223 |
// Copy |
1224 |
LineNumber cLineNumber = lineNumbers[index].Copy(); |
1225 |
group.Document.LineNumbers.Add(cLineNumber); |
1226 |
|
1227 |
foreach (Item item in group.Items) |
1228 |
{ |
1229 |
item.Owner = cLineNumber.UID; |
1230 |
item.Document.MissingLineNumber2 = true; |
1231 |
} |
1232 |
} |
1233 |
} |
1234 |
|
1235 |
foreach (Document document in Documents) |
1236 |
{ |
1237 |
foreach (Item item in document.Items) |
1238 |
{ |
1239 |
item.TopologyData = string.Empty; |
1240 |
item.PSNPipeLineID = string.Empty; |
1241 |
List<string> pipeLineID = new List<string>(); |
1242 |
LineNumber lineNumber = document.LineNumbers.Find(x => x.UID == item.Owner); |
1243 |
|
1244 |
if (lineNumber != null) |
1245 |
{ |
1246 |
item.LineNumber = lineNumber; |
1247 |
|
1248 |
foreach (DataRow row in topologyRuleDT.Rows) |
1249 |
{ |
1250 |
string uid = row["UID"].ToString(); |
1251 |
//if (uid == "-") |
1252 |
// pipeLineID.Add(item.TopologyData);//item.TopologyData += "-"; |
1253 |
if (uid != "-") |
1254 |
{ |
1255 |
Attribute itemAttr = item.Attributes.Find(x => x.Name == uid); |
1256 |
|
1257 |
Attribute attribute = lineNumber.Attributes.Find(x => x.DisplayName == uid); |
1258 |
if (attribute != null && !string.IsNullOrEmpty(attribute.Value)) |
1259 |
{ |
1260 |
pipeLineID.Add(attribute.Value);//item.TopologyData += attribute.Value; |
1261 |
if (uid.Equals("Tag Seq No") && attribute.Value.ToString().Substring(attribute.Value.ToString().Length - 1, 1).Equals("V")) |
1262 |
{ |
1263 |
if (item.Document.MissingLineNumber1) |
1264 |
item.MissingLineNumber1 = true; |
1265 |
else if (item.Document.MissingLineNumber2) |
1266 |
item.MissingLineNumber2 = true; |
1267 |
} |
1268 |
} |
1269 |
} |
1270 |
} |
1271 |
|
1272 |
if (topologyRuleDT.Select(string.Format("UID = '{0}'", "InsulationPurpose")) == null) |
1273 |
{ |
1274 |
Attribute insulAttr = item.LineNumber.Attributes.Find(x => x.Name == "InsulationPurpose"); |
1275 |
if (insulAttr != null && !string.IsNullOrEmpty(insulAttr.Value)) |
1276 |
pipeLineID.Add(insulAttr.Value); //item.PSNPipeLineID = item.TopologyData + "-" + insulAttr.Value; |
1277 |
//else |
1278 |
// item.PSNPipeLineID = item.TopologyData; |
1279 |
} |
1280 |
|
1281 |
item.PSNPipeLineID = string.Join("-", pipeLineID); |
1282 |
item.TopologyData = string.Join("-", pipeLineID); |
1283 |
|
1284 |
} |
1285 |
else |
1286 |
{ |
1287 |
item.TopologyData = "Empty LineNumber"; |
1288 |
item.LineNumber = new LineNumber(); |
1289 |
} |
1290 |
} |
1291 |
} |
1292 |
|
1293 |
int emptyIndex = 1; |
1294 |
foreach (Group group in groups) |
1295 |
{ |
1296 |
List<Item> groupItems = group.Items.FindAll(x => x.TopologyData == "Empty LineNumber"); |
1297 |
if (groupItems.Count > 0) |
1298 |
{ |
1299 |
foreach (var item in groupItems) |
1300 |
item.TopologyData += string.Format("-{0}", emptyIndex); |
1301 |
emptyIndex++; |
1302 |
} |
1303 |
} |
1304 |
|
1305 |
} |
1306 |
|
1307 |
private void ConnectByOPC() |
1308 |
{ |
1309 |
try |
1310 |
{ |
1311 |
foreach (Group group in groups.FindAll(x => x.Items.Last().SubItemType == SubItemType.OPC)) |
1312 |
{ |
1313 |
Item opcItem = group.Items.Last(); |
1314 |
DataRow[] fromRows = opcDT.Select(string.Format("FromOPCUID = '{0}'", opcItem.UID)); |
1315 |
if (fromRows.Length.Equals(1)) |
1316 |
{ |
1317 |
DataRow opcRow = fromRows.First(); |
1318 |
string toDrawing = opcRow["ToDrawing"].ToString(); |
1319 |
string toOPCUID = opcRow["ToOPCUID"].ToString(); |
1320 |
|
1321 |
Document toDocument = Documents.Find(x => x.DrawingName == toDrawing); |
1322 |
if (toDocument != null) |
1323 |
{ |
1324 |
Group toGroup = toDocument.Groups.Find(x => x.Items.Find(y => y.UID == toOPCUID) != null); |
1325 |
DataRow[] toRows = opcDT.Select(string.Format("ToOPCUID = '{0}'", toGroup.Items.First().UID)); |
1326 |
//1대1 매칭이 아닐때 걸림 (2개 이상일 때) 2021.11.07 |
1327 |
if (toRows.Length > 1) |
1328 |
{ |
1329 |
//throw new Exception("OPC error(multi connect)"); |
1330 |
MessageBox.Show("OPC error(multi connect)", "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
1331 |
return; |
1332 |
} |
1333 |
group.EndGroup = toGroup; |
1334 |
toGroup.StartGroup = group; |
1335 |
} |
1336 |
} |
1337 |
} |
1338 |
} |
1339 |
catch (Exception ex) |
1340 |
{ |
1341 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1342 |
//MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
1343 |
} |
1344 |
} |
1345 |
|
1346 |
private void SetPSNItem() |
1347 |
{ |
1348 |
Dictionary<Group, string> groupDic = new Dictionary<Group, string>(); |
1349 |
foreach (Group group in groups) |
1350 |
groupDic.Add(group, Guid.NewGuid().ToString()); |
1351 |
|
1352 |
foreach (Group group in groups) |
1353 |
{ |
1354 |
string groupKey = groupDic[group]; |
1355 |
if (group.StartGroup != null) |
1356 |
{ |
1357 |
string otherKey = groupDic[group.StartGroup]; |
1358 |
ChangeGroupID(otherKey, groupKey); |
1359 |
} |
1360 |
} |
1361 |
|
1362 |
// PSN 정리 |
1363 |
foreach (var item in groupDic) |
1364 |
{ |
1365 |
Group group = item.Key; |
1366 |
string uid = item.Value; |
1367 |
PSNItem PSNItem = PSNItems.Find(x => x.UID == uid); |
1368 |
if (PSNItem == null) |
1369 |
{ |
1370 |
PSNItem = new PSNItem(PSNItems.Count, Revision) { UID = uid }; |
1371 |
PSNItems.Add(PSNItem); |
1372 |
} |
1373 |
PSNItem.Groups.Add(group); |
1374 |
foreach (Item groupItem in group.Items) |
1375 |
groupItem.PSNItem = PSNItem; |
1376 |
} |
1377 |
|
1378 |
// Sort PSN |
1379 |
foreach (PSNItem PSNItem in PSNItems) |
1380 |
{ |
1381 |
List<Group> _groups = new List<Group>(); |
1382 |
|
1383 |
Stack<Group> stacks = new Stack<Group>(); |
1384 |
stacks.Push(PSNItem.Groups.First()); |
1385 |
while (stacks.Count > 0) |
1386 |
{ |
1387 |
Group stack = stacks.Pop(); |
1388 |
if (_groups.Contains(stack)) |
1389 |
continue; |
1390 |
|
1391 |
if (_groups.Count == 0) |
1392 |
_groups.Add(stack); |
1393 |
else |
1394 |
{ |
1395 |
if (stack.StartGroup != null && _groups.Contains(stack.StartGroup)) |
1396 |
{ |
1397 |
int index = _groups.IndexOf(stack.StartGroup); |
1398 |
_groups.Insert(index + 1, stack); |
1399 |
} |
1400 |
else if (stack.EndGroup != null && _groups.Contains(stack.EndGroup)) |
1401 |
{ |
1402 |
int index = _groups.IndexOf(stack.EndGroup); |
1403 |
_groups.Insert(index, stack); |
1404 |
} |
1405 |
} |
1406 |
|
1407 |
if (stack.StartGroup != null) |
1408 |
stacks.Push(stack.StartGroup); |
1409 |
if (stack.EndGroup != null) |
1410 |
stacks.Push(stack.EndGroup); |
1411 |
} |
1412 |
|
1413 |
PSNItem.Groups.Clear(); |
1414 |
PSNItem.Groups.AddRange(_groups); |
1415 |
} |
1416 |
|
1417 |
void ChangeGroupID(string from, string to) |
1418 |
{ |
1419 |
if (from.Equals(to)) |
1420 |
return; |
1421 |
|
1422 |
List<Group> changeItems = new List<Group>(); |
1423 |
foreach (var _item in groupDic) |
1424 |
if (_item.Value.Equals(from)) |
1425 |
changeItems.Add(_item.Key); |
1426 |
foreach (var _item in changeItems) |
1427 |
groupDic[_item] = to; |
1428 |
} |
1429 |
} |
1430 |
|
1431 |
private void SetPSNType() |
1432 |
{ |
1433 |
foreach (PSNItem PSNItem in PSNItems) |
1434 |
{ |
1435 |
Group firstGroup = PSNItem.Groups.First(); |
1436 |
Group lastGroup = PSNItem.Groups.Last(); |
1437 |
|
1438 |
Item firstItem = firstGroup.Items.First(); |
1439 |
Item lastItem = lastGroup.Items.Last(); |
1440 |
|
1441 |
PSNItem.StartType = GetPSNType(firstItem, true); |
1442 |
PSNItem.EndType = GetPSNType(lastItem, false); |
1443 |
|
1444 |
} |
1445 |
|
1446 |
PSNType GetPSNType(Item item, bool bFirst = true) |
1447 |
{ |
1448 |
PSNType type = PSNType.None; |
1449 |
|
1450 |
if (item.ItemType == ItemType.Line) |
1451 |
{ |
1452 |
Group group = groups.Find(x => x.Items.Contains(item)); |
1453 |
if (bFirst && item.Relations[0].Item != null && !group.Items.Contains(item.Relations[0].Item)) |
1454 |
{ |
1455 |
Item connItem = item.Relations[0].Item; |
1456 |
if (connItem.ItemType == ItemType.Line && !IsConnected(item, connItem)) |
1457 |
type = PSNType.Branch; |
1458 |
else if (connItem.ItemType == ItemType.Symbol) |
1459 |
type = PSNType.Symbol; |
1460 |
} |
1461 |
else if (!bFirst && item.Relations[1].Item != null && !group.Items.Contains(item.Relations[1].Item)) |
1462 |
{ |
1463 |
Item connItem = item.Relations[1].Item; |
1464 |
if (connItem.ItemType == ItemType.Line && !IsConnected(item, connItem)) |
1465 |
type = PSNType.Branch; |
1466 |
else if (connItem.ItemType == ItemType.Symbol) |
1467 |
type = PSNType.Symbol; |
1468 |
} |
1469 |
} |
1470 |
else if (item.ItemType == ItemType.Symbol) |
1471 |
{ |
1472 |
if (item.SubItemType == SubItemType.Nozzle) |
1473 |
type = PSNType.Equipment; |
1474 |
else if (item.SubItemType == SubItemType.Header) |
1475 |
type = PSNType.Header; |
1476 |
else if (item.SubItemType == SubItemType.OPC) |
1477 |
type = PSNType.OPC; |
1478 |
} |
1479 |
|
1480 |
return type; |
1481 |
} |
1482 |
} |
1483 |
|
1484 |
private void SetBranchInfo() |
1485 |
{ |
1486 |
foreach (Document document in Documents) |
1487 |
{ |
1488 |
List<Item> lines = document.Items.FindAll(x => x.ItemType == ItemType.Line).ToList(); |
1489 |
foreach (Item line in lines) |
1490 |
{ |
1491 |
double[] point = line.Relations[0].Point; |
1492 |
List<Item> connLines = lines.FindAll(x => x.Relations.Find(y => y.UID == line.UID) != null && line.Relations.Find(y => y.UID == x.UID) == null); |
1493 |
connLines.Sort(SortBranchLine); |
1494 |
line.BranchItems.AddRange(connLines); |
1495 |
|
1496 |
int SortBranchLine(Item a, Item b) |
1497 |
{ |
1498 |
double[] pointA = a.Relations[0].UID == line.UID ? a.Relations[0].Point : a.Relations[1].Point; |
1499 |
double distanceA = CalcPointToPointdDistance(point[0], point[1], pointA[0], pointA[1]); |
1500 |
|
1501 |
double[] pointB = b.Relations[0].UID == line.UID ? b.Relations[0].Point : b.Relations[1].Point; |
1502 |
double distanceB = CalcPointToPointdDistance(point[0], point[1], pointB[0], pointB[1]); |
1503 |
|
1504 |
// 내림차순 |
1505 |
return distanceA.CompareTo(distanceB); |
1506 |
} |
1507 |
double CalcPointToPointdDistance(double x1, double y1, double x2, double y2) |
1508 |
{ |
1509 |
return Math.Pow(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2), 0.5); |
1510 |
} |
1511 |
} |
1512 |
} |
1513 |
} |
1514 |
|
1515 |
private void SetTopology() |
1516 |
{ |
1517 |
try |
1518 |
{ |
1519 |
#region 기본 topology 정리 |
1520 |
foreach (PSNItem PSNItem in PSNItems) |
1521 |
{ |
1522 |
Topology topology = null; |
1523 |
foreach (Group group in PSNItem.Groups) |
1524 |
{ |
1525 |
foreach (Item item in group.Items) |
1526 |
{ |
1527 |
if (string.IsNullOrEmpty(item.TopologyData)) |
1528 |
topology = null; |
1529 |
else |
1530 |
{ |
1531 |
if (topology == null) |
1532 |
{ |
1533 |
topology = new Topology() |
1534 |
{ |
1535 |
ID = item.TopologyData |
1536 |
}; |
1537 |
Topologies.Add(topology); |
1538 |
|
1539 |
if (!PSNItem.Topologies.Contains(topology)) |
1540 |
PSNItem.Topologies.Add(topology); |
1541 |
} |
1542 |
else |
1543 |
{ |
1544 |
if (topology.ID != item.TopologyData) |
1545 |
{ |
1546 |
topology = new Topology() |
1547 |
{ |
1548 |
ID = item.TopologyData |
1549 |
}; |
1550 |
Topologies.Add(topology); |
1551 |
|
1552 |
if (!PSNItem.Topologies.Contains(topology)) |
1553 |
PSNItem.Topologies.Add(topology); |
1554 |
} |
1555 |
} |
1556 |
|
1557 |
item.Topology = topology; |
1558 |
topology.Items.Add(item); |
1559 |
} |
1560 |
} |
1561 |
} |
1562 |
} |
1563 |
#endregion |
1564 |
|
1565 |
#region Type |
1566 |
List<string> ids = Topologies.Select(x => x.ID).Distinct().ToList(); |
1567 |
foreach (string id in ids) |
1568 |
{ |
1569 |
try |
1570 |
{ |
1571 |
|
1572 |
|
1573 |
List<Topology> topologies = Topologies.FindAll(x => x.ID == id); |
1574 |
|
1575 |
// Main |
1576 |
List<Topology> mainTopologies = FindMainTopology(topologies); |
1577 |
foreach (Topology topology in mainTopologies) |
1578 |
topology.Type = "M"; |
1579 |
|
1580 |
// Branch |
1581 |
List<Topology> branchToplogies = topologies.FindAll(x => string.IsNullOrEmpty(x.Type)); |
1582 |
foreach (Topology topology in branchToplogies) |
1583 |
topology.Type = "B"; |
1584 |
} |
1585 |
catch (Exception ex) |
1586 |
{ |
1587 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1588 |
MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
1589 |
} |
1590 |
} |
1591 |
#endregion |
1592 |
} |
1593 |
catch (Exception ex) |
1594 |
{ |
1595 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1596 |
MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
1597 |
} |
1598 |
|
1599 |
} |
1600 |
|
1601 |
private void SetTopologyIndex() |
1602 |
{ |
1603 |
List<string> ids = Topologies.Select(x => x.ID).Distinct().ToList(); |
1604 |
foreach (string id in ids) |
1605 |
{ |
1606 |
List<Topology> topologies = Topologies.FindAll(x => x.ID == id); |
1607 |
|
1608 |
// Main |
1609 |
List<Topology> mainTopologies = topologies.FindAll(x => x.Type == "M"); |
1610 |
foreach (Topology topology in mainTopologies) |
1611 |
topology.Index = mainTopologies.IndexOf(topology).ToString(); |
1612 |
|
1613 |
// Branch |
1614 |
List<Topology> branchToplogies = topologies.FindAll(x => x.Type == "B"); |
1615 |
foreach (Topology topology in branchToplogies) |
1616 |
topology.Index = (branchToplogies.IndexOf(topology) + 1).ToString(); |
1617 |
} |
1618 |
} |
1619 |
|
1620 |
private void SetPSNBypass() |
1621 |
{ |
1622 |
foreach (PSNItem PSNItem in PSNItems) |
1623 |
PSNItem.IsBypass = IsBypass(PSNItem); |
1624 |
} |
1625 |
|
1626 |
private List<Topology> FindMainTopology(List<Topology> data) |
1627 |
{ |
1628 |
DataTable nominalDiameterDT = DB.SelectNominalDiameter(); |
1629 |
DataTable PMCDT = DB.SelectPSNPIPINGMATLCLASS(); |
1630 |
//2021.11.17 안쓰네 JY |
1631 |
//DataTable fluidCodeDT = DB.SelectPSNFluidCode(); |
1632 |
|
1633 |
List<Topology> main = new List<Topology>(); |
1634 |
main.AddRange(data); |
1635 |
// |
1636 |
main = GetNozzleTopology(data); |
1637 |
if (main.Count == 1) |
1638 |
return main; |
1639 |
else |
1640 |
{ |
1641 |
if (main.Count > 0) |
1642 |
main = GetPMCTopology(main); |
1643 |
else |
1644 |
main = GetPMCTopology(data); |
1645 |
|
1646 |
if (main.Count == 1) |
1647 |
return main; |
1648 |
else |
1649 |
{ |
1650 |
if (main.Count > 0) |
1651 |
main = GetDiaTopology(main); |
1652 |
else |
1653 |
main = GetDiaTopology(data); |
1654 |
|
1655 |
|
1656 |
if (main.Count == 1) |
1657 |
return main; |
1658 |
else |
1659 |
{ |
1660 |
if (main.Count > 0) |
1661 |
main = GetItemTopology(main); |
1662 |
else |
1663 |
main = GetItemTopology(data); |
1664 |
} |
1665 |
} |
1666 |
} |
1667 |
|
1668 |
List<Topology> GetNozzleTopology(List<Topology> topologies) |
1669 |
{ |
1670 |
return topologies.FindAll(x => x.Items.Find(y => y.SubItemType == SubItemType.Nozzle) != null); |
1671 |
} |
1672 |
|
1673 |
List<Topology> GetPMCTopology(List<Topology> topologies) |
1674 |
{ |
1675 |
List<Topology> result = new List<Topology>(); |
1676 |
foreach (DataRow row in PMCDT.Rows) |
1677 |
{ |
1678 |
string value = row["CODE"].ToString(); |
1679 |
foreach (Topology topology in topologies) |
1680 |
{ |
1681 |
foreach (Item item in topology.Items) |
1682 |
{ |
1683 |
if (item.LineNumber == null) |
1684 |
continue; |
1685 |
Attribute attribute = item.LineNumber.Attributes.Find(x => x.Name == "PipingMaterialsClass"); |
1686 |
if (attribute != null && value == attribute.Value) |
1687 |
{ |
1688 |
result.Add(topology); |
1689 |
break; |
1690 |
} |
1691 |
} |
1692 |
} |
1693 |
|
1694 |
if (result.Count > 0) |
1695 |
break; |
1696 |
} |
1697 |
|
1698 |
return result; |
1699 |
} |
1700 |
|
1701 |
List<Topology> GetDiaTopology(List<Topology> topologies) |
1702 |
{ |
1703 |
List<Topology> result = new List<Topology>(); |
1704 |
foreach (DataRow row in nominalDiameterDT.Rows) |
1705 |
{ |
1706 |
string inchValue = row["InchStr"].ToString(); |
1707 |
string metricValue = row["MetricStr"].ToString(); |
1708 |
foreach (Topology topology in topologies) |
1709 |
{ |
1710 |
foreach (Item item in topology.Items) |
1711 |
{ |
1712 |
if (item.LineNumber == null) |
1713 |
continue; |
1714 |
Attribute attribute = item.LineNumber.Attributes.Find(x => x.Name == "NominalDiameter"); |
1715 |
if (attribute != null && (inchValue == attribute.Value || metricValue == attribute.Value)) |
1716 |
{ |
1717 |
result.Add(topology); |
1718 |
break; |
1719 |
} |
1720 |
} |
1721 |
} |
1722 |
|
1723 |
if (result.Count > 0) |
1724 |
break; |
1725 |
} |
1726 |
|
1727 |
return result; |
1728 |
} |
1729 |
|
1730 |
List<Topology> GetItemTopology(List<Topology> topologies) |
1731 |
{ |
1732 |
return new List<Topology>() { topologies.OrderByDescending(x => x.Items.Count).ToList().First() }; |
1733 |
} |
1734 |
|
1735 |
return main; |
1736 |
} |
1737 |
|
1738 |
private DataTable GetOPCInfo() |
1739 |
{ |
1740 |
DataTable opc = DB.SelectOPCRelations(); |
1741 |
DataTable drawing = DB.AllDrawings(); |
1742 |
|
1743 |
DataTable dt = new DataTable(); |
1744 |
dt.Columns.Add("FromDrawing", typeof(string)); |
1745 |
dt.Columns.Add("FromDrawingUID", typeof(string)); |
1746 |
dt.Columns.Add("FromOPCUID", typeof(string)); |
1747 |
dt.Columns.Add("ToDrawing", typeof(string)); |
1748 |
dt.Columns.Add("ToDrawingUID", typeof(string)); |
1749 |
dt.Columns.Add("ToOPCUID", typeof(string)); |
1750 |
foreach (DataRow row in opc.Rows) |
1751 |
{ |
1752 |
string fromDrawingUID = row["From_Drawings_UID"] == null ? string.Empty : row["From_Drawings_UID"].ToString(); |
1753 |
string fromOPCUID = row["From_OPC_UID"] == null ? string.Empty : row["From_OPC_UID"].ToString(); |
1754 |
string toDrawingUID = row["To_Drawings_UID"] == null ? string.Empty : row["To_Drawings_UID"].ToString(); |
1755 |
string toOPCUID = row["To_OPC_UID"] == null ? string.Empty : row["To_OPC_UID"].ToString(); |
1756 |
if (!string.IsNullOrEmpty(toOPCUID)) |
1757 |
{ |
1758 |
DataRow[] fromRows = drawing.Select(string.Format("UID = '{0}'", fromDrawingUID)); |
1759 |
DataRow[] toRows = drawing.Select(string.Format("UID = '{0}'", toDrawingUID)); |
1760 |
if (fromRows.Length.Equals(1) && toRows.Length.Equals(1)) |
1761 |
{ |
1762 |
string fromDrawingName = Path.GetFileNameWithoutExtension(fromRows.First()["NAME"].ToString()); |
1763 |
string toDrawingName = Path.GetFileNameWithoutExtension(toRows.First()["NAME"].ToString()); |
1764 |
|
1765 |
DataRow newRow = dt.NewRow(); |
1766 |
newRow["FromDrawing"] = fromDrawingName; |
1767 |
newRow["FromDrawingUID"] = fromDrawingUID; |
1768 |
newRow["FromOPCUID"] = fromOPCUID; |
1769 |
newRow["ToDrawing"] = toDrawingName; |
1770 |
newRow["ToDrawingUID"] = toDrawingUID; |
1771 |
newRow["ToOPCUID"] = toOPCUID; |
1772 |
|
1773 |
dt.Rows.Add(newRow); |
1774 |
} |
1775 |
} |
1776 |
} |
1777 |
|
1778 |
return dt; |
1779 |
} |
1780 |
|
1781 |
private DataTable GetTopologyRule() |
1782 |
{ |
1783 |
DataTable dt = DB.SelectTopologyRule(); |
1784 |
|
1785 |
return dt; |
1786 |
} |
1787 |
|
1788 |
private bool IsConnected(Item item1, Item item2) |
1789 |
{ |
1790 |
if (item1.Relations.Find(x => x.UID.Equals(item2.UID)) != null && |
1791 |
item2.Relations.Find(x => x.UID.Equals(item1.UID)) != null) |
1792 |
return true; |
1793 |
else |
1794 |
return false; |
1795 |
} |
1796 |
|
1797 |
private void SaveNozzleAndEquipment() |
1798 |
{ |
1799 |
List<Item> nozzles = new List<Item>(); |
1800 |
List<Equipment> equipments = new List<Equipment>(); |
1801 |
foreach (Document document in Documents) |
1802 |
{ |
1803 |
nozzles.AddRange(document.Items.FindAll(x => x.SubItemType == SubItemType.Nozzle)); |
1804 |
equipments.AddRange(document.Equipments); |
1805 |
} |
1806 |
|
1807 |
|
1808 |
DataTable nozzleDT = new DataTable(); |
1809 |
nozzleDT.Columns.Add("OID", typeof(string)); |
1810 |
nozzleDT.Columns.Add("ITEMTAG", typeof(string)); |
1811 |
nozzleDT.Columns.Add("XCOORDS", typeof(string)); |
1812 |
nozzleDT.Columns.Add("YCOORDS", typeof(string)); |
1813 |
nozzleDT.Columns.Add("Equipment_OID", typeof(string)); |
1814 |
nozzleDT.Columns.Add("FLUID", typeof(string)); |
1815 |
nozzleDT.Columns.Add("NPD", typeof(string)); |
1816 |
nozzleDT.Columns.Add("PMC", typeof(string)); |
1817 |
nozzleDT.Columns.Add("ROTATION", typeof(string)); |
1818 |
nozzleDT.Columns.Add("FlowDirection", typeof(string)); |
1819 |
|
1820 |
foreach (Item item in nozzles) |
1821 |
{ |
1822 |
DataRow row = nozzleDT.NewRow(); |
1823 |
row["OID"] = item.UID; |
1824 |
|
1825 |
Relation relation = item.Relations.Find(x => equipments.Find(y => y.UID == x.UID) != null); |
1826 |
if (relation != null) |
1827 |
{ |
1828 |
Equipment equipment = equipments.Find(x => x.UID == relation.UID); |
1829 |
equipment.Nozzles.Add(item); |
1830 |
row["ITEMTAG"] = string.Format("N{0}", string.Format("{0:D3}", equipment.Nozzles.Count + 100)); |
1831 |
row["Equipment_OID"] = equipment.UID; |
1832 |
item.Equipment = equipment; |
1833 |
} |
1834 |
row["XCOORDS"] = (item.POINT[0] / DrawingWidth).ToString(); |
1835 |
row["YCOORDS"] = (item.POINT[1] / DrawingHeight).ToString(); |
1836 |
Attribute fluidAttr = item.LineNumber.Attributes.Find(x => x.Name == "FluidCode"); |
1837 |
row["FLUID"] = fluidAttr != null ? fluidAttr.Value : string.Empty; |
1838 |
Attribute npdAttr = item.LineNumber.Attributes.Find(x => x.Name == "NominalDiameter"); |
1839 |
row["NPD"] = npdAttr != null ? npdAttr.Value : string.Empty; |
1840 |
Attribute pmcAttr = item.LineNumber.Attributes.Find(x => x.Name == "PipingMaterialsClass"); |
1841 |
row["PMC"] = pmcAttr != null ? pmcAttr.Value : string.Empty; |
1842 |
|
1843 |
double angle = Math.PI * 2 - Convert.ToDouble(item.ANGLE); |
1844 |
if (angle >= Math.PI * 2) |
1845 |
angle = angle - Math.PI * 2; |
1846 |
row["ROTATION"] = angle.ToString(); |
1847 |
|
1848 |
if (item.Topology.Items.First().Equals(item)) |
1849 |
row["FlowDirection"] = "Outlet"; |
1850 |
else if (item.Topology.Items.Last().Equals(item)) |
1851 |
row["FlowDirection"] = "Inlet"; |
1852 |
else |
1853 |
row["FlowDirection"] = string.Empty; |
1854 |
|
1855 |
nozzleDT.Rows.Add(row); |
1856 |
} |
1857 |
|
1858 |
DataTable equipDT = new DataTable(); |
1859 |
equipDT.Columns.Add("OID", typeof(string)); |
1860 |
equipDT.Columns.Add("ITEMTAG", typeof(string)); |
1861 |
equipDT.Columns.Add("XCOORDS", typeof(string)); |
1862 |
equipDT.Columns.Add("YCOORDS", typeof(string)); |
1863 |
|
1864 |
foreach (Equipment equipment in equipments) |
1865 |
{ |
1866 |
DataRow row = equipDT.NewRow(); |
1867 |
row["OID"] = equipment.UID; |
1868 |
if (!string.IsNullOrEmpty(EquipTagNoAttributeName)) |
1869 |
{ |
1870 |
Attribute attribute = equipment.Attributes.Find(x => x.Name == EquipTagNoAttributeName); |
1871 |
if (attribute != null) |
1872 |
equipment.ItemTag = attribute.Value; |
1873 |
} |
1874 |
else |
1875 |
equipment.ItemTag = equipment.Name; |
1876 |
|
1877 |
row["ITEMTAG"] = equipment.ItemTag; |
1878 |
List<double> xList = equipment.POINT.Select(x => x[0]).ToList(); |
1879 |
row["XCOORDS"] = (xList.Sum() / (double)xList.Count) / DrawingWidth; |
1880 |
|
1881 |
List<double> yList = equipment.POINT.Select(x => x[1]).ToList(); |
1882 |
row["YCOORDS"] = (yList.Sum() / (double)yList.Count) / DrawingHeight; |
1883 |
|
1884 |
equipDT.Rows.Add(row); |
1885 |
} |
1886 |
|
1887 |
Equipment = equipDT; |
1888 |
Nozzle = nozzleDT; |
1889 |
} |
1890 |
|
1891 |
private void SavePSNData() |
1892 |
{ |
1893 |
try |
1894 |
{ |
1895 |
DataTable pathItemsDT = new DataTable(); |
1896 |
pathItemsDT.Columns.Add("OID", typeof(string)); |
1897 |
pathItemsDT.Columns.Add("SequenceData_OID", typeof(string)); |
1898 |
pathItemsDT.Columns.Add("TopologySet_OID", typeof(string)); |
1899 |
pathItemsDT.Columns.Add("BranchTopologySet_OID", typeof(string)); |
1900 |
pathItemsDT.Columns.Add("PipeLine_OID", typeof(string)); |
1901 |
pathItemsDT.Columns.Add("ITEMNAME", typeof(string)); |
1902 |
pathItemsDT.Columns.Add("ITEMTAG", typeof(string)); |
1903 |
pathItemsDT.Columns.Add("DESCRIPTION", typeof(string)); |
1904 |
pathItemsDT.Columns.Add("Class", typeof(string)); |
1905 |
pathItemsDT.Columns.Add("SubClass", typeof(string)); |
1906 |
pathItemsDT.Columns.Add("TYPE", typeof(string)); |
1907 |
pathItemsDT.Columns.Add("PIDNAME", typeof(string)); |
1908 |
pathItemsDT.Columns.Add("Equipment_OID", typeof(string)); |
1909 |
pathItemsDT.Columns.Add("NPD", typeof(string)); |
1910 |
pathItemsDT.Columns.Add("GROUPTAG", typeof(string)); |
1911 |
pathItemsDT.Columns.Add("PipeSystemNetwork_OID", typeof(string)); |
1912 |
pathItemsDT.Columns.Add("ViewPipeSystemNetwork_OID", typeof(string)); |
1913 |
pathItemsDT.Columns.Add("PipeRun_OID", typeof(string)); |
1914 |
pathItemsDT.Columns.Add("EqpGroupTag", typeof(string)); |
1915 |
pathItemsDT.Columns.Add("MainLineTag", typeof(string)); |
1916 |
pathItemsDT.Columns.Add("EGTConnectedPoint", typeof(string)); |
1917 |
pathItemsDT.Columns.Add("EGFlowDirection", typeof(string)); |
1918 |
|
1919 |
DataTable sequenceDataDT = new DataTable(); |
1920 |
sequenceDataDT.Columns.Add("OID", typeof(string)); |
1921 |
sequenceDataDT.Columns.Add("SERIALNUMBER", typeof(string)); |
1922 |
sequenceDataDT.Columns.Add("PathItem_OID", typeof(string)); |
1923 |
sequenceDataDT.Columns.Add("TopologySet_OID_Key", typeof(string)); |
1924 |
|
1925 |
DataTable pipeSystemNetworkDT = new DataTable(); |
1926 |
pipeSystemNetworkDT.Columns.Add("OID", typeof(string)); |
1927 |
pipeSystemNetworkDT.Columns.Add("Type", typeof(string)); |
1928 |
pipeSystemNetworkDT.Columns.Add("OrderNumber", typeof(string)); |
1929 |
pipeSystemNetworkDT.Columns.Add("Pipeline_OID", typeof(string)); |
1930 |
pipeSystemNetworkDT.Columns.Add("FROM_DATA", typeof(string)); |
1931 |
pipeSystemNetworkDT.Columns.Add("TO_DATA", typeof(string)); |
1932 |
pipeSystemNetworkDT.Columns.Add("TopologySet_OID_Key", typeof(string)); |
1933 |
pipeSystemNetworkDT.Columns.Add("PSNRevisionNumber", typeof(string)); |
1934 |
pipeSystemNetworkDT.Columns.Add("PBS", typeof(string)); |
1935 |
pipeSystemNetworkDT.Columns.Add("Drawings", typeof(string)); |
1936 |
pipeSystemNetworkDT.Columns.Add("IsValid", typeof(string)); |
1937 |
pipeSystemNetworkDT.Columns.Add("Status", typeof(string)); |
1938 |
pipeSystemNetworkDT.Columns.Add("IncludingVirtualData", typeof(string)); |
1939 |
pipeSystemNetworkDT.Columns.Add("PSNAccuracy", typeof(string)); |
1940 |
pipeSystemNetworkDT.Columns.Add("Pocket", typeof(string)); |
1941 |
pipeSystemNetworkDT.Columns.Add("EGTag", typeof(string)); |
1942 |
pipeSystemNetworkDT.Columns.Add("HasMLTags", typeof(string)); |
1943 |
pipeSystemNetworkDT.Columns.Add("AFC", typeof(string)); |
1944 |
pipeSystemNetworkDT.Columns.Add("PUMP", typeof(string)); |
1945 |
|
1946 |
DataTable topologySetDT = new DataTable(); |
1947 |
topologySetDT.Columns.Add("OID", typeof(string)); |
1948 |
topologySetDT.Columns.Add("Type", typeof(string)); |
1949 |
topologySetDT.Columns.Add("SubType", typeof(string)); |
1950 |
topologySetDT.Columns.Add("HeadItemTag", typeof(string)); |
1951 |
topologySetDT.Columns.Add("TailItemTag", typeof(string)); |
1952 |
topologySetDT.Columns.Add("HeadItemSPID", typeof(string)); |
1953 |
topologySetDT.Columns.Add("TailItemSPID", typeof(string)); |
1954 |
|
1955 |
DataTable pipelineDT = new DataTable(); |
1956 |
pipelineDT.Columns.Add("OID", typeof(string)); |
1957 |
pipelineDT.Columns.Add("PipeSystem_OID", typeof(string)); |
1958 |
pipelineDT.Columns.Add("FLUID", typeof(string)); |
1959 |
pipelineDT.Columns.Add("PMC", typeof(string)); |
1960 |
pipelineDT.Columns.Add("SEQNUMBER", typeof(string)); |
1961 |
pipelineDT.Columns.Add("INSULATION", typeof(string)); |
1962 |
pipelineDT.Columns.Add("FROM_DATA", typeof(string)); |
1963 |
pipelineDT.Columns.Add("TO_DATA", typeof(string)); |
1964 |
pipelineDT.Columns.Add("Unit", typeof(string)); |
1965 |
|
1966 |
DataTable pipesystemDT = new DataTable(); |
1967 |
pipesystemDT.Columns.Add("OID", typeof(string)); |
1968 |
pipesystemDT.Columns.Add("DESCRIPTION", typeof(string)); |
1969 |
pipesystemDT.Columns.Add("FLUID", typeof(string)); |
1970 |
pipesystemDT.Columns.Add("PMC", typeof(string)); |
1971 |
pipesystemDT.Columns.Add("PipeLineQty", typeof(string)); |
1972 |
pipesystemDT.Columns.Add("GroundLevel", typeof(string)); |
1973 |
|
1974 |
// Set Vent/Drain Info |
1975 |
List<VentDrainInfo> VentDrainInfos = new List<VentDrainInfo>(); |
1976 |
DataTable dt = DB.SelectVentDrainSetting(); |
1977 |
foreach (DataRow row in dt.Rows) |
1978 |
{ |
1979 |
string groupID = row["GROUP_ID"].ToString(); |
1980 |
string desc = row["DESCRIPTION"].ToString(); |
1981 |
int index = Convert.ToInt32(row["INDEX"]); |
1982 |
string name = row["NAME"].ToString(); |
1983 |
|
1984 |
VentDrainInfo ventDrainInfo = VentDrainInfos.Find(x => x.UID.Equals(groupID)); |
1985 |
if (ventDrainInfo == null) |
1986 |
{ |
1987 |
ventDrainInfo = new VentDrainInfo(groupID); |
1988 |
ventDrainInfo.Description = desc; |
1989 |
VentDrainInfos.Add(ventDrainInfo); |
1990 |
} |
1991 |
|
1992 |
ventDrainInfo.VentDrainItems.Add(new VentDrainItem() |
1993 |
{ |
1994 |
Index = index, |
1995 |
Name = name |
1996 |
}); |
1997 |
} |
1998 |
foreach (VentDrainInfo ventDrainInfo in VentDrainInfos) |
1999 |
ventDrainInfo.VentDrainItems = ventDrainInfo.VentDrainItems.OrderBy(x => x.Index).ToList(); |
2000 |
|
2001 |
#region Keyword Info |
2002 |
KeywordInfo KeywordInfos = new KeywordInfo(); |
2003 |
DataTable dtKeyword = DB.SelectKeywordsSetting(); |
2004 |
foreach (DataRow row in dtKeyword.Rows) |
2005 |
{ |
2006 |
int index = Convert.ToInt32(row["INDEX"]); |
2007 |
string name = row["NAME"].ToString(); |
2008 |
string keyword = row["KEYWORD"].ToString(); |
2009 |
|
2010 |
//KeywordInfo keywordInfo = new KeywordInfo(); |
2011 |
KeywordInfos.KeywordItems.Add(new KeywordItem() |
2012 |
{ |
2013 |
Index = index, |
2014 |
Name = name, |
2015 |
Keyword = keyword |
2016 |
}); |
2017 |
} |
2018 |
#endregion |
2019 |
|
2020 |
#region ValveGrouping Info |
2021 |
ValveGroupInfo ValveGrouping = new ValveGroupInfo(); |
2022 |
DataTable dtValveGroupung = DB.SelectValveGroupItemsSetting(); |
2023 |
foreach (DataRow row in dtValveGroupung.Rows) |
2024 |
{ |
2025 |
ValveGrouping.ValveGroupItems.Add(new ValveGroupItem() |
2026 |
{ |
2027 |
OID = row["OID"].ToString(), |
2028 |
GroupType = row["GroupType"].ToString(), |
2029 |
TagIdentifier = row["TagIdentifier"].ToString(), |
2030 |
AttributeName = row["AttributeName"].ToString(), |
2031 |
SppidSymbolName = row["SppidSymbolName"].ToString() |
2032 |
}); |
2033 |
} |
2034 |
#endregion |
2035 |
|
2036 |
#region EquipmentNoPocket Info |
2037 |
EquipmentNoPocketInfo EquipmentNoPocket = new EquipmentNoPocketInfo(); |
2038 |
DataTable dtEquipmentNoPocket = DB.SelectEquipmentNoPocketSetting(); |
2039 |
foreach (DataRow row in dtEquipmentNoPocket.Rows) |
2040 |
{ |
2041 |
EquipmentNoPocket.EquipmentNoPocketItem.Add(new EquipmentNoPocketItem() |
2042 |
{ |
2043 |
Index = Convert.ToInt32(row["INDEX"]), |
2044 |
Type = row["TYPE"].ToString(), |
2045 |
Name = row["NAME"].ToString() |
2046 |
}); |
2047 |
} |
2048 |
#endregion |
2049 |
|
2050 |
#region EquipmentAirFinCooler Info |
2051 |
EquipmentAirFinCoolerInfo EquipmentAirFinCooler = new EquipmentAirFinCoolerInfo(); |
2052 |
DataTable dtEquipmentAirFinCooler = DB.SelectAirFinCoolerSetting(); |
2053 |
foreach (DataRow row in dtEquipmentAirFinCooler.Rows) |
2054 |
{ |
2055 |
EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Add(new EquipmentAirFinCoolerItem() |
2056 |
{ |
2057 |
Type = row["Type"].ToString(), |
2058 |
Name = row["Name"].ToString() |
2059 |
}); |
2060 |
} |
2061 |
#endregion |
2062 |
|
2063 |
// key = 미입력 branch |
2064 |
Dictionary<Item, Item> startBranchDic = new Dictionary<Item, Item>(); |
2065 |
Dictionary<Item, Item> endBranchDic = new Dictionary<Item, Item>(); |
2066 |
DataTable PSNFluidDT = DB.SelectPSNFluidCode(); |
2067 |
DataTable PSNPMCDT = DB.SelectPSNPIPINGMATLCLASS(); |
2068 |
foreach (PSNItem PSNItem in PSNItems) |
2069 |
{ |
2070 |
try |
2071 |
{ |
2072 |
int psnOrder = 0; |
2073 |
int index = 0; |
2074 |
bool bPSNStart = true; |
2075 |
string sPSNData = string.Empty; |
2076 |
bool bVentDrain = false; |
2077 |
|
2078 |
List<Group> Groups = PSNItem.Groups; |
2079 |
Dictionary<string, List<Item>> keyValuePairs = new Dictionary<string, List<Item>>(); |
2080 |
List<Item> valveGroupingItem = new List<Item>(); |
2081 |
|
2082 |
//VentDrain 검사 |
2083 |
if (PSNItem.Groups.Count.Equals(1)) |
2084 |
{ |
2085 |
List<VentDrainInfo> endInfos = new List<VentDrainInfo>(); |
2086 |
for (int g = 0; g < Groups.Count; g++) |
2087 |
{ |
2088 |
Group group = Groups[g]; |
2089 |
for (int i = 0; i < group.Items.Count; i++) |
2090 |
{ |
2091 |
Item item = group.Items[i]; |
2092 |
foreach (VentDrainInfo ventDrainInfo in VentDrainInfos) |
2093 |
{ |
2094 |
if (endInfos.Contains(ventDrainInfo)) |
2095 |
continue; |
2096 |
|
2097 |
if (!ventDrainInfo.VentDrainItems[i].Name.Equals(item.Name)) |
2098 |
{ |
2099 |
endInfos.Add(ventDrainInfo); |
2100 |
continue; |
2101 |
} |
2102 |
|
2103 |
if (ventDrainInfo.VentDrainItems.Count.Equals(i + 1)) |
2104 |
{ |
2105 |
bVentDrain = true; |
2106 |
break; |
2107 |
} |
2108 |
} |
2109 |
|
2110 |
if (bVentDrain || endInfos.Count.Equals(VentDrainInfos.Count)) |
2111 |
break; |
2112 |
} |
2113 |
|
2114 |
if (!bVentDrain) |
2115 |
{ |
2116 |
endInfos = new List<VentDrainInfo>(); |
2117 |
for (int i = 0; i < group.Items.Count; i++) |
2118 |
{ |
2119 |
Item item = group.Items[group.Items.Count - i - 1]; |
2120 |
foreach (VentDrainInfo ventDrainInfo in VentDrainInfos) |
2121 |
{ |
2122 |
if (endInfos.Contains(ventDrainInfo)) |
2123 |
continue; |
2124 |
|
2125 |
if (!ventDrainInfo.VentDrainItems[i].Name.Equals(item.Name)) |
2126 |
{ |
2127 |
endInfos.Add(ventDrainInfo); |
2128 |
continue; |
2129 |
} |
2130 |
|
2131 |
if (ventDrainInfo.VentDrainItems.Count.Equals(i + 1)) |
2132 |
{ |
2133 |
bVentDrain = true; |
2134 |
break; |
2135 |
} |
2136 |
} |
2137 |
|
2138 |
if (bVentDrain || endInfos.Count.Equals(VentDrainInfos.Count)) |
2139 |
break; |
2140 |
} |
2141 |
} |
2142 |
} |
2143 |
} |
2144 |
|
2145 |
try |
2146 |
{ |
2147 |
foreach (Group group in PSNItem.Groups) |
2148 |
{ |
2149 |
foreach (Item item in group.Items) |
2150 |
{ |
2151 |
string VgTag = string.Empty; |
2152 |
|
2153 |
if (ValveGrouping.ValveGroupItems.Where(x => x.SppidSymbolName == item.Name).Count() > 0) |
2154 |
{ |
2155 |
ValveGroupItem valveitem = ValveGrouping.ValveGroupItems.Where(x => x.SppidSymbolName == item.Name).First(); |
2156 |
string value = string.Empty; |
2157 |
|
2158 |
if (valveitem.GroupType == "Scope Break" || valveitem.AttributeName == "NoSelection" || valveitem.AttributeName == string.Empty) |
2159 |
value = "NoSelection"; |
2160 |
else |
2161 |
{ |
2162 |
if(item.Attributes.Find(x => x.Name == valveitem.AttributeName) == null) |
2163 |
value = "NoSelection"; |
2164 |
else |
2165 |
value = item.Attributes.Find(x => x.Name == valveitem.AttributeName).Value; |
2166 |
} |
2167 |
|
2168 |
if (valveitem.GroupType == "Scope Break") |
2169 |
VgTag = "Scope Break"; |
2170 |
else |
2171 |
VgTag = valveitem.SppidSymbolName + "\\" + value; |
2172 |
|
2173 |
} |
2174 |
|
2175 |
string PathitemUID = string.Empty; |
2176 |
if (item.BranchItems.Count == 0) |
2177 |
{ |
2178 |
PathitemUID = item.UID; |
2179 |
CreatePathItemsDataRow(PathitemUID, item.ID2DBType, VgTag); |
2180 |
CreateSequenceDataDataRow(PathitemUID); |
2181 |
index++; |
2182 |
} |
2183 |
else |
2184 |
{ |
2185 |
PathitemUID = item.UID + "_L1"; |
2186 |
CreatePathItemsDataRow(PathitemUID, item.ID2DBType, VgTag); |
2187 |
CreateSequenceDataDataRow(PathitemUID); |
2188 |
index++; |
2189 |
for (int i = 0; i < item.BranchItems.Count; i++) |
2190 |
{ |
2191 |
CreatePathItemsDataRow(string.Format(item.UID + "_B{0}", i + 1), "Branch", string.Empty, item.BranchItems[i].Topology.FullName, item.BranchItems[i]); |
2192 |
CreateSequenceDataDataRow(string.Format(item.UID + "_B{0}", i + 1)); |
2193 |
index++; |
2194 |
|
2195 |
CreatePathItemsDataRow(string.Format(item.UID + "_L{0}", i + 2), item.ID2DBType); |
2196 |
CreateSequenceDataDataRow(string.Format(item.UID + "_L{0}", i + 2)); |
2197 |
index++; |
2198 |
|
2199 |
if (item.BranchItems[i].Relations[0].Item != null && item.BranchItems[i].Relations[0].Item == item) |
2200 |
startBranchDic.Add(item.BranchItems[i], item); |
2201 |
else if (item.BranchItems[i].Relations[1].Item != null && item.BranchItems[i].Relations[1].Item == item) |
2202 |
endBranchDic.Add(item.BranchItems[i], item); |
2203 |
} |
2204 |
} |
2205 |
|
2206 |
if (bPSNStart) |
2207 |
{ |
2208 |
CreatePipeSystemNetworkDataRow(); |
2209 |
sPSNData = item.TopologyData; |
2210 |
psnOrder++; |
2211 |
bPSNStart = false; |
2212 |
} |
2213 |
else |
2214 |
{ |
2215 |
if (item.TopologyData != sPSNData) |
2216 |
{ |
2217 |
CreatePipeSystemNetworkDataRow(); |
2218 |
sPSNData = item.TopologyData; |
2219 |
psnOrder++; |
2220 |
} |
2221 |
} |
2222 |
|
2223 |
void CreatePathItemsDataRow(string itemOID, string itemType, string GROUPTAG = "", string branchTopologyName = "", Item branchItem = null) |
2224 |
{ |
2225 |
DataRow newRow = pathItemsDT.NewRow(); |
2226 |
|
2227 |
if (itemType == "Nozzles") |
2228 |
{ |
2229 |
newRow["Equipment_OID"] = item.Equipment != null ? item.Equipment.UID : ""; |
2230 |
} |
2231 |
|
2232 |
newRow["OID"] = itemOID; |
2233 |
newRow["SequenceData_OID"] = string.Format(item.Topology.FullName + "_{0}", index); |
2234 |
newRow["TopologySet_OID"] = item.Topology.FullName; |
2235 |
newRow["BranchTopologySet_OID"] = branchTopologyName; |
2236 |
newRow["PipeLine_OID"] = item.PSNPipeLineID; |
2237 |
newRow["ITEMNAME"] = GetItemName(item, itemOID); |
2238 |
newRow["ITEMTAG"] = GetItemTag(item); |
2239 |
newRow["Class"] = GetClass(item, itemOID); |
2240 |
string subClass = GetSubClass(item, itemOID); |
2241 |
newRow["SubClass"] = subClass; |
2242 |
|
2243 |
if (item.ItemType == ItemType.Symbol) |
2244 |
newRow["TYPE"] = item.ID2DBName; |
2245 |
else if (item.ItemType == ItemType.Line) |
2246 |
newRow["TYPE"] = item.ID2DBType; |
2247 |
newRow["PIDNAME"] = group.Document.DrawingName; |
2248 |
|
2249 |
// NPD |
2250 |
if (item.LineNumber != null) |
2251 |
{ |
2252 |
Attribute attribute = item.LineNumber.Attributes.Find(x => x.Name == "NominalDiameter"); |
2253 |
if (attribute != null) |
2254 |
newRow["NPD"] = attribute.Value; |
2255 |
} |
2256 |
else |
2257 |
newRow["NPD"] = null; |
2258 |
|
2259 |
newRow["GROUPTAG"] = GROUPTAG; |
2260 |
newRow["PipeSystemNetwork_OID"] = PSNItem.PSN_OID(); |
2261 |
if (branchItem == null) |
2262 |
newRow["ViewPipeSystemNetwork_OID"] = PSNItem.PSN_OID(); |
2263 |
else |
2264 |
newRow["ViewPipeSystemNetwork_OID"] = branchItem.PSNItem.PSN_OID(); |
2265 |
|
2266 |
newRow["PipeRun_OID"] = item.LineNumber != null ? item.LineNumber.Name : string.Empty; |
2267 |
newRow["EGTConnectedPoint"] = 0; |
2268 |
pathItemsDT.Rows.Add(newRow); |
2269 |
} |
2270 |
|
2271 |
|
2272 |
void CreateSequenceDataDataRow(string itemOID) |
2273 |
{ |
2274 |
DataRow newRow = sequenceDataDT.NewRow(); |
2275 |
newRow["OID"] = string.Format(item.Topology.FullName + "_{0}", index); |
2276 |
newRow["SERIALNUMBER"] = string.Format("{0}", index); |
2277 |
newRow["PathItem_OID"] = itemOID; |
2278 |
newRow["TopologySet_OID_Key"] = item.Topology.FullName; |
2279 |
|
2280 |
sequenceDataDT.Rows.Add(newRow); |
2281 |
} |
2282 |
|
2283 |
void CreatePipeSystemNetworkDataRow() |
2284 |
{ |
2285 |
LineNumber lineNumber = item.Document.LineNumbers.Find(x => x.UID == item.Owner); |
2286 |
string FluidCode = string.Empty; |
2287 |
if (lineNumber != null) |
2288 |
{ |
2289 |
List<Attribute> att = lineNumber.Attributes; |
2290 |
if (att != null) |
2291 |
{ |
2292 |
List<string> oid = new List<string>(); |
2293 |
FluidCode = att.Where(x => x.Name.ToUpper().Equals("FLUIDCODE")).FirstOrDefault() != null ? att.Where(x => x.Name.ToUpper().Equals("FLUIDCODE")).FirstOrDefault().Value : string.Empty; |
2294 |
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; |
2295 |
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; |
2296 |
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; |
2297 |
//InsulationPurpose |
2298 |
if (!string.IsNullOrEmpty(FluidCode)) oid.Add(FluidCode); |
2299 |
if (!string.IsNullOrEmpty(PMC)) oid.Add(PMC); |
2300 |
|
2301 |
string PipeSystem_OID = string.Join("-", oid); |
2302 |
|
2303 |
if (!string.IsNullOrEmpty(SEQNUMBER)) oid.Add(SEQNUMBER); |
2304 |
if (!string.IsNullOrEmpty(INSULATION)) oid.Add(INSULATION); |
2305 |
|
2306 |
string OID = string.Join("-", oid); |
2307 |
string FluidCodeGL = string.Empty; |
2308 |
string PMCGL = string.Empty; |
2309 |
|
2310 |
|
2311 |
if (pipelineDT.Select(string.Format("OID = '{0}'", OID)).Count() == 0) |
2312 |
{ |
2313 |
DataRow newPipelineRow = pipelineDT.NewRow(); |
2314 |
newPipelineRow["OID"] = OID; |
2315 |
newPipelineRow["PipeSystem_OID"] = PipeSystem_OID; |
2316 |
newPipelineRow["FLUID"] = FluidCode; |
2317 |
newPipelineRow["PMC"] = PMC; |
2318 |
newPipelineRow["SEQNUMBER"] = SEQNUMBER; |
2319 |
newPipelineRow["INSULATION"] = INSULATION; |
2320 |
newPipelineRow["FROM_DATA"] = string.Empty; |
2321 |
newPipelineRow["TO_DATA"] = string.Empty; |
2322 |
newPipelineRow["Unit"] = PSNItem.GetPBSData(); |
2323 |
pipelineDT.Rows.Add(newPipelineRow); |
2324 |
} |
2325 |
|
2326 |
if (pipesystemDT.Select(string.Format("OID = '{0}'", PipeSystem_OID)).Count() == 0) |
2327 |
{ |
2328 |
DataRow newPipesystemRow = pipesystemDT.NewRow(); |
2329 |
newPipesystemRow["OID"] = PipeSystem_OID; |
2330 |
newPipesystemRow["DESCRIPTION"] = string.Empty; |
2331 |
newPipesystemRow["FLUID"] = FluidCode; |
2332 |
newPipesystemRow["PMC"] = PMC; |
2333 |
newPipesystemRow["PipeLineQty"] = string.Empty; |
2334 |
string GroundLevel = string.Empty; |
2335 |
if (!string.IsNullOrEmpty(FluidCode) && !string.IsNullOrEmpty(PMC)) |
2336 |
{ |
2337 |
FluidCodeGL = PSNFluidDT.Select(string.Format("Code = '{0}'", FluidCode)).FirstOrDefault().Field<string>("GroundLevel"); |
2338 |
PMCGL = PSNPMCDT.Select(string.Format("Code= '{0}'", PMC)).FirstOrDefault().Field<string>("GroundLevel"); |
2339 |
if (FluidCodeGL == "AG" && PMCGL == "AG") |
2340 |
GroundLevel = "AG"; |
2341 |
else if (FluidCodeGL == "UG" && PMCGL == "UG") |
2342 |
GroundLevel = "UG"; |
2343 |
else |
2344 |
GroundLevel = "AG_UG"; |
2345 |
} |
2346 |
newPipesystemRow["GroundLevel"] = GroundLevel; |
2347 |
|
2348 |
pipesystemDT.Rows.Add(newPipesystemRow); |
2349 |
} |
2350 |
} |
2351 |
} |
2352 |
|
2353 |
DataRow newRow = pipeSystemNetworkDT.NewRow(); |
2354 |
newRow["OID"] = PSNItem.PSN_OID(); |
2355 |
|
2356 |
newRow["OrderNumber"] = psnOrder; |
2357 |
newRow["Pipeline_OID"] = item.PSNPipeLineID; |
2358 |
PSNItem.KeywordInfos = KeywordInfos; |
2359 |
PSNItem.Nozzle = Nozzle; |
2360 |
|
2361 |
string FromType = string.Empty; |
2362 |
Item From_item = new Item(); |
2363 |
|
2364 |
string FROM_DATA = PSNItem.GetFromData(ref FromType, ref From_item); |
2365 |
string status = string.Empty; |
2366 |
if (psnOrder == 0) |
2367 |
{ |
2368 |
status = PSNItem.Status; |
2369 |
} |
2370 |
|
2371 |
if (PSNItem.IsKeyword) |
2372 |
{ |
2373 |
PSNItem.StartType = PSNType.Equipment; |
2374 |
} |
2375 |
string ToType = string.Empty; |
2376 |
Item To_item = new Item(); |
2377 |
string TO_DATA = PSNItem.GetToData(ref ToType, ref To_item); |
2378 |
if (PSNItem.IsKeyword) |
2379 |
{ |
2380 |
PSNItem.EndType = PSNType.Equipment; |
2381 |
} |
2382 |
|
2383 |
//if (Groups.Count == psnOrder + 1 && !string.IsNullOrEmpty(PSNItem.Status)) |
2384 |
//{ |
2385 |
if (!string.IsNullOrEmpty(PSNItem.Status)) |
2386 |
status += PSNItem.Status; |
2387 |
//} |
2388 |
|
2389 |
newRow["FROM_DATA"] = FROM_DATA; |
2390 |
newRow["TO_DATA"] = TO_DATA; |
2391 |
//if(TO_DATA.Contains("Free Vent W-Screen") || TO_DATA.Contains("Empty LineNumber") || FROM_DATA.Contains("Empty LineNumber")) |
2392 |
//{ |
2393 |
|
2394 |
//} |
2395 |
newRow["Type"] = PSNItem.GetPSNType(); |
2396 |
|
2397 |
if (psnOrder > 0) |
2398 |
{ |
2399 |
DataRow dr = pipeSystemNetworkDT.Select(string.Format("OID = '{0}' AND OrderNumber = {1}", PSNItem.PSN_OID(), psnOrder - 1)).FirstOrDefault(); |
2400 |
if (!string.IsNullOrEmpty(PSNItem.Status)) |
2401 |
{//status = !string.IsNullOrEmpty(status) ? status.Remove(0, 2) : string.Empty; |
2402 |
if (dr["Status"].ToString().Contains(PSNItem.Status)) |
2403 |
dr["Status"] = dr["Status"].ToString().Replace(PSNItem.Status, string.Empty); |
2404 |
else if (dr["Status"].ToString().Contains(PSNItem.Status.Remove(0, 2))) |
2405 |
dr["Status"] = dr["Status"].ToString().Replace(PSNItem.Status.Remove(0, 2), string.Empty); |
2406 |
|
2407 |
} |
2408 |
|
2409 |
if (dr != null) |
2410 |
{ |
2411 |
newRow["FROM_DATA"] = dr.Field<string>("FROM_DATA"); |
2412 |
newRow["TO_DATA"] = dr.Field<string>("TO_DATA"); |
2413 |
newRow["Type"] = dr.Field<string>("Type"); |
2414 |
} |
2415 |
} |
2416 |
|
2417 |
status = !string.IsNullOrEmpty(status) ? status.Remove(0, 2) : string.Empty; |
2418 |
if (group.Items.Count == 1 && !string.IsNullOrEmpty(status)) |
2419 |
{ |
2420 |
MatchCollection matches = Regex.Matches(status, "Missing LineNumber_1"); |
2421 |
int cnt = matches.Count; |
2422 |
if (cnt > 1) |
2423 |
status.Replace(", Missing LineNumber_1", string.Empty); |
2424 |
} |
2425 |
newRow["TopologySet_OID_Key"] = item.Topology.FullName; |
2426 |
newRow["PSNRevisionNumber"] = string.Format("V{0:D4}", Revision); |
2427 |
|
2428 |
|
2429 |
newRow["IsValid"] = PSNItem.IsValid; |
2430 |
newRow["Status"] = status; |
2431 |
newRow["PBS"] = PSNItem.GetPBSData(); |
2432 |
|
2433 |
List<string> drawingNames = new List<string>(); |
2434 |
foreach (Group _group in PSNItem.Groups) |
2435 |
{ |
2436 |
if (!drawingNames.Contains(_group.Document.DrawingName)) |
2437 |
{ |
2438 |
if (drawingNames.Count == 0) |
2439 |
newRow["Drawings"] = _group.Document.DrawingName; |
2440 |
else |
2441 |
newRow["Drawings"] = newRow["Drawings"] + ", " + _group.Document.DrawingName; |
2442 |
drawingNames.Add(_group.Document.DrawingName); |
2443 |
} |
2444 |
} |
2445 |
|
2446 |
// VentDrain의 경우 제외 요청 (데이터를 아예 제거하였을 경우 후 가공에서 문제가 생김 마지막에 지우는것으로 변경) |
2447 |
if (bVentDrain) |
2448 |
newRow["IncludingVirtualData"] = "Vent_Drain"; |
2449 |
else |
2450 |
newRow["IncludingVirtualData"] = "No"; |
2451 |
// return; |
2452 |
//newRow["IncludingVirtualData"] = "No"; |
2453 |
newRow["PSNAccuracy"] = "100"; |
2454 |
|
2455 |
string Pocket = "No"; |
2456 |
string Condition = PSNFluidDT.Select(string.Format("Code = '{0}'", FluidCode)).FirstOrDefault().Field<string>("Condition"); |
2457 |
if (Condition.Equals("Flare")) |
2458 |
Pocket = "Yes"; |
2459 |
|
2460 |
if (item.ID2DBType == "Nozzles" && PSNItem.StartType == PSNType.Equipment && From_item.Equipment != null) |
2461 |
{ |
2462 |
// string itemName = From_item.Name; |
2463 |
Equipment Equipment = From_item.Equipment; |
2464 |
|
2465 |
EquipmentNoPocketItem nopocket = EquipmentNoPocket.EquipmentNoPocketItem.Where(x => x.Name == Equipment.Name && x.Type != "Pump").FirstOrDefault(); |
2466 |
|
2467 |
|
2468 |
if (nopocket != null) |
2469 |
{ |
2470 |
DataRow bNozzle = null; |
2471 |
if (nopocket.Type.Equals("Vertical Vessel")) |
2472 |
{ |
2473 |
DataRow drNozzle = Nozzle.Select(string.Format("Equipment_OID = '{0}' AND OID = '{1}'", Equipment.UID, From_item.UID)).FirstOrDefault(); |
2474 |
if (drNozzle != null) |
2475 |
{ |
2476 |
if (drNozzle.Field<string>("Rotation").Length >= 4 && drNozzle.Field<string>("Rotation").Substring(0, 4) == "4.71") |
2477 |
{ |
2478 |
bNozzle = drNozzle; |
2479 |
} |
2480 |
|
2481 |
if (bNozzle == null) |
2482 |
{ |
2483 |
DataRow[] nozzleRows = Nozzle.Select(string.Format("Equipment_OID = '{0}'", Equipment.UID)); |
2484 |
|
2485 |
if (drNozzle != null) |
2486 |
{ |
2487 |
bNozzle = drNozzle; |
2488 |
foreach (DataRow it in nozzleRows) |
2489 |
{ |
2490 |
if (Convert.ToDecimal(drNozzle.Field<string>("Ycoords")) > Convert.ToDecimal(it.Field<string>("Ycoords"))) |
2491 |
{ |
2492 |
bNozzle = null; |
2493 |
break; |
2494 |
} |
2495 |
} |
2496 |
} |
2497 |
} |
2498 |
} |
2499 |
|
2500 |
if (bNozzle != null) |
2501 |
Pocket = "Yes"; |
2502 |
} |
2503 |
else |
2504 |
Pocket = "Yes"; |
2505 |
} |
2506 |
} |
2507 |
|
2508 |
if (item.ID2DBType == "Nozzles" && PSNItem.EndType == PSNType.Equipment && To_item.Equipment != null) //To는 전체 |
2509 |
{ |
2510 |
// string itemName = To_item.Name; |
2511 |
Equipment Equipment = To_item.Equipment; |
2512 |
EquipmentNoPocketItem nopocket = EquipmentNoPocket.EquipmentNoPocketItem.Where(x => x.Name == Equipment.Name).FirstOrDefault(); |
2513 |
if (nopocket != null) |
2514 |
{ |
2515 |
DataRow bNozzle = null; |
2516 |
if (nopocket.Type.Equals("Vertical Vessel")) |
2517 |
{ |
2518 |
DataRow drNozzle = Nozzle.Select(string.Format("Equipment_OID = '{0}' AND OID = '{1}'", Equipment.UID, To_item.UID)).FirstOrDefault(); |
2519 |
if(drNozzle != null) |
2520 |
{ |
2521 |
if (drNozzle.Field<string>("Rotation").Length >= 4 && drNozzle.Field<string>("Rotation").Substring(0, 4) == "4.71") |
2522 |
{ |
2523 |
bNozzle = drNozzle; |
2524 |
} |
2525 |
|
2526 |
if (bNozzle == null) |
2527 |
{ |
2528 |
DataRow[] nozzleRows = Nozzle.Select(string.Format("Equipment_OID = '{0}'", Equipment.UID)); |
2529 |
|
2530 |
if (drNozzle != null) |
2531 |
{ |
2532 |
bNozzle = drNozzle; |
2533 |
foreach (DataRow it in nozzleRows) |
2534 |
{ |
2535 |
if (Convert.ToDecimal(drNozzle.Field<string>("Ycoords")) > Convert.ToDecimal(it.Field<string>("Ycoords"))) |
2536 |
{ |
2537 |
bNozzle = null; |
2538 |
break; |
2539 |
} |
2540 |
} |
2541 |
} |
2542 |
} |
2543 |
} |
2544 |
|
2545 |
if (bNozzle != null) |
2546 |
Pocket = "Yes"; |
2547 |
} |
2548 |
else |
2549 |
Pocket = "Yes"; |
2550 |
} |
2551 |
} |
2552 |
|
2553 |
newRow["Pocket"] = Pocket; |
2554 |
string AFC = "P2"; |
2555 |
if(PSNItem.StartType == PSNType.Equipment && From_item.Equipment != null) |
2556 |
{ |
2557 |
if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type != "Pump" && x.Name.Equals(From_item.Equipment.Name)).Count() > 0) |
2558 |
AFC = "P1\\" + From_item.Equipment.Name; |
2559 |
else if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && x.Name.Equals(From_item.Equipment.Name)).Count() > 0) |
2560 |
newRow["PUMP"] = "PUMP"; |
2561 |
} |
2562 |
|
2563 |
if (PSNItem.EndType == PSNType.Equipment && To_item.Equipment != null) |
2564 |
{ |
2565 |
if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type != "Pump" && x.Name.Equals(To_item.Equipment.Name)).Count() > 0) |
2566 |
AFC = "P1\\" + To_item.Equipment.Name; |
2567 |
else if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && x.Name.Equals(To_item.Equipment.Name)).Count() > 0) |
2568 |
newRow["PUMP"] = "PUMP"; |
2569 |
} |
2570 |
|
2571 |
newRow["AFC"] = AFC; |
2572 |
|
2573 |
newRow["EGTag"] = string.Empty; |
2574 |
newRow["HasMLTags"] = "False"; |
2575 |
pipeSystemNetworkDT.Rows.Add(newRow); |
2576 |
} |
2577 |
} |
2578 |
|
2579 |
} |
2580 |
|
2581 |
|
2582 |
} |
2583 |
catch (Exception ex) |
2584 |
{ |
2585 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
2586 |
MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
2587 |
} |
2588 |
|
2589 |
//TopologySet 관련 |
2590 |
foreach (Topology topology in PSNItem.Topologies) |
2591 |
{ |
2592 |
DataRow newRow = topologySetDT.NewRow(); |
2593 |
newRow["OID"] = topology.FullName; |
2594 |
newRow["Type"] = topology.FullName.Split(new char[] { '-' }).Last().StartsWith("M") ? "Main" : "Branch"; |
2595 |
if (bVentDrain) |
2596 |
newRow["SubType"] = "Vent_Drain"; |
2597 |
else |
2598 |
newRow["SubType"] = null; |
2599 |
newRow["HeadItemTag"] = GetItemTag(topology.Items.Last()); |
2600 |
newRow["TailItemTag"] = GetItemTag(topology.Items.First()); |
2601 |
newRow["HeadItemSPID"] = topology.Items.Last().UID; |
2602 |
newRow["TailItemSPID"] = topology.Items.First().UID; |
2603 |
topologySetDT.Rows.Add(newRow); |
2604 |
} |
2605 |
|
2606 |
} |
2607 |
catch (Exception ee) |
2608 |
{ |
2609 |
|
2610 |
} |
2611 |
} |
2612 |
|
2613 |
|
2614 |
foreach (var item in startBranchDic) |
2615 |
{ |
2616 |
string uid = item.Key.UID; |
2617 |
string topologyName = item.Value.Topology.FullName; |
2618 |
DataRow[] rows = pathItemsDT.Select(string.Format("OID LIKE '{0}%'", uid)); |
2619 |
|
2620 |
if (rows.Length == 1) |
2621 |
{ |
2622 |
rows.First()["BranchTopologySet_OID"] = topologyName; |
2623 |
rows.First()["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID(); |
2624 |
} |
2625 |
else if (rows.Length > 1) |
2626 |
{ |
2627 |
DataRow targetRow = null; |
2628 |
int index = int.MaxValue; |
2629 |
foreach (DataRow row in rows) |
2630 |
{ |
2631 |
string split = row["OID"].ToString().Split(new char[] { '_' })[1]; |
2632 |
if (split.StartsWith("L")) |
2633 |
{ |
2634 |
int num = Convert.ToInt32(split.Remove(0, 1)); |
2635 |
if (index > num) |
2636 |
{ |
2637 |
index = num; |
2638 |
targetRow = row; |
2639 |
} |
2640 |
} |
2641 |
} |
2642 |
|
2643 |
if (targetRow != null) |
2644 |
{ |
2645 |
targetRow["BranchTopologySet_OID"] = topologyName; |
2646 |
targetRow["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID(); |
2647 |
} |
2648 |
} |
2649 |
} |
2650 |
|
2651 |
foreach (var item in endBranchDic) |
2652 |
{ |
2653 |
string uid = item.Key.UID; |
2654 |
string topologyName = item.Value.Topology.FullName; |
2655 |
DataRow[] rows = pathItemsDT.Select(string.Format("OID LIKE '{0}%'", uid)); |
2656 |
if (rows.Length == 1) |
2657 |
{ |
2658 |
rows.First()["BranchTopologySet_OID"] = topologyName; |
2659 |
rows.First()["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID(); |
2660 |
} |
2661 |
else if (rows.Length > 1) |
2662 |
{ |
2663 |
DataRow targetRow = null; |
2664 |
int index = int.MinValue; |
2665 |
foreach (DataRow row in rows) |
2666 |
{ |
2667 |
string split = row["OID"].ToString().Split(new char[] { '_' })[1]; |
2668 |
if (split.StartsWith("L")) |
2669 |
{ |
2670 |
int num = Convert.ToInt32(split.Remove(0, 1)); |
2671 |
if (index < num) |
2672 |
{ |
2673 |
index = num; |
2674 |
targetRow = row; |
2675 |
} |
2676 |
} |
2677 |
} |
2678 |
|
2679 |
if (targetRow != null) |
2680 |
{ |
2681 |
targetRow["BranchTopologySet_OID"] = topologyName; |
2682 |
targetRow["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID(); |
2683 |
} |
2684 |
} |
2685 |
} |
2686 |
|
2687 |
PathItems = pathItemsDT; |
2688 |
SequenceData = sequenceDataDT; |
2689 |
PipeSystemNetwork = pipeSystemNetworkDT; |
2690 |
TopologySet = topologySetDT; |
2691 |
PipeLine = pipelineDT; |
2692 |
PipeSystem = pipesystemDT; |
2693 |
} |
2694 |
catch (Exception ex) |
2695 |
{ |
2696 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
2697 |
MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
2698 |
} |
2699 |
} |
2700 |
|
2701 |
private double AccuracyCalculation(List<double> lstAcc, double acc) |
2702 |
{ |
2703 |
foreach (double lacc in lstAcc) |
2704 |
{ |
2705 |
acc *= lacc; |
2706 |
} |
2707 |
return acc; |
2708 |
} |
2709 |
|
2710 |
private void UpdateSubType() |
2711 |
{ |
2712 |
try |
2713 |
{ |
2714 |
foreach (PSNItem PSNItem in PSNItems) |
2715 |
{ |
2716 |
if (PSNItem.IsBypass) |
2717 |
{ |
2718 |
foreach (Topology topology in PSNItem.Topologies) |
2719 |
{ |
2720 |
DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName)); |
2721 |
if (rows.Length.Equals(1)) |
2722 |
rows.First()["SubType"] = "Bypass"; |
2723 |
} |
2724 |
} |
2725 |
|
2726 |
if (PSNItem.StartType == PSNType.Header) |
2727 |
{ |
2728 |
Topology topology = PSNItem.Topologies.First(); |
2729 |
DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName)); |
2730 |
if (rows.Length.Equals(1)) |
2731 |
rows.First()["SubType"] = "Header"; |
2732 |
} |
2733 |
else if (PSNItem.EndType == PSNType.Header) |
2734 |
{ |
2735 |
Topology topology = PSNItem.Topologies.Last(); |
2736 |
DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName)); |
2737 |
if (rows.Length.Equals(1)) |
2738 |
rows.First()["SubType"] = "Header"; |
2739 |
} |
2740 |
} |
2741 |
|
2742 |
|
2743 |
foreach (Topology topology in Topologies) |
2744 |
{ |
2745 |
try |
2746 |
{ |
2747 |
DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName)); |
2748 |
|
2749 |
if (rows.Count() > 0) |
2750 |
{ |
2751 |
if (rows.Length.Equals(1) && rows.First()["SubType"] == null || string.IsNullOrEmpty(rows.First()["SubType"].ToString())) |
2752 |
{ |
2753 |
if (topology.Items == null) |
2754 |
continue; |
2755 |
|
2756 |
Item firstItem = topology.Items.First(); |
2757 |
Item lastItem = topology.Items.Last(); |
2758 |
|
2759 |
List<Relation> relations = new List<Relation>(); |
2760 |
|
2761 |
if (firstItem.Relations.FindAll(x => x.Item == null).Count() != 0) |
2762 |
relations.AddRange(firstItem.Relations.FindAll(x => x.Item != null && x.Item.Topology.ID != topology.ID)); |
2763 |
|
2764 |
if (lastItem.Relations.FindAll(x => x.Item == null).Count() != 0) |
2765 |
relations.AddRange(lastItem.Relations.FindAll(x => x.Item != null && x.Item.Topology.ID != topology.ID)); |
2766 |
|
2767 |
if (relations.Count > 0) |
2768 |
rows.First()["SubType"] = "OtherSystem"; |
2769 |
} |
2770 |
} |
2771 |
} |
2772 |
catch (Exception ex) |
2773 |
{ |
2774 |
|
2775 |
MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
2776 |
} |
2777 |
} |
2778 |
|
2779 |
foreach (DataRow row in TopologySet.Rows) |
2780 |
if (row["SubType"] == null || string.IsNullOrEmpty(row["SubType"].ToString())) |
2781 |
row["SubType"] = "Normal"; |
2782 |
} |
2783 |
catch (Exception ex) |
2784 |
{ |
2785 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
2786 |
MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
2787 |
} |
2788 |
} |
2789 |
|
2790 |
private bool IsBypass(PSNItem PSNItem) |
2791 |
{ |
2792 |
bool bResult = false; |
2793 |
|
2794 |
if (PSNItem.GetPSNType() == "B2B") |
2795 |
{ |
2796 |
Group firstGroup = PSNItem.Groups.First(); |
2797 |
Group lastGroup = PSNItem.Groups.Last(); |
2798 |
Item firstItem = firstGroup.Items.First(); |
2799 |
Item lastItem = lastGroup.Items.Last(); |
2800 |
|
2801 |
Item connectedFirstItem = GetConnectedItemByPSN(firstItem); |
2802 |
Item connectedLastItem = GetConnectedItemByPSN(lastItem); |
2803 |
|
2804 |
if (connectedFirstItem.LineNumber != null && connectedLastItem.LineNumber != null && |
2805 |
!string.IsNullOrEmpty(connectedFirstItem.LineNumber.Name) && !string.IsNullOrEmpty(connectedLastItem.LineNumber.Name) && |
2806 |
connectedFirstItem.LineNumber.Name == connectedLastItem.LineNumber.Name) |
2807 |
bResult = true; |
2808 |
else if (connectedFirstItem.PSNItem == connectedLastItem.PSNItem) |
2809 |
bResult = true; |
2810 |
} |
2811 |
|
2812 |
Item GetConnectedItemByPSN(Item item) |
2813 |
{ |
2814 |
Item result = null; |
2815 |
|
2816 |
Relation relation = item.Relations.Find(x => x.Item != null && x.Item.PSNItem != item.PSNItem); |
2817 |
if (relation != null) |
2818 |
result = relation.Item; |
2819 |
|
2820 |
|
2821 |
return result; |
2822 |
} |
2823 |
|
2824 |
return bResult; |
2825 |
} |
2826 |
|
2827 |
private void DeleteVentDrain() |
2828 |
{ |
2829 |
DataRow[] ventdrainRows = PipeSystemNetwork.Select(" IncludingVirtualData = 'Vent_Drain'"); |
2830 |
|
2831 |
foreach (DataRow dataRow in ventdrainRows) |
2832 |
{ |
2833 |
dataRow.Delete(); |
2834 |
} |
2835 |
} |
2836 |
|
2837 |
private void UpdateAccuracy() |
2838 |
{ |
2839 |
//DataRow[] statusRows = PipeSystemNetwork.Select(" Type = 'Error' OR IsValid = 'Error'"); |
2840 |
DataRow[] statusRows = PipeSystemNetwork.Select(" Type = 'Error' OR IsValid = 'Error'"); |
2841 |
List<double> lstAcc = null; |
2842 |
string Status = string.Empty; |
2843 |
|
2844 |
foreach (DataRow dataRow in statusRows) |
2845 |
{ |
2846 |
lstAcc = new List<double>(); |
2847 |
Status = dataRow.Field<string>("Status"); |
2848 |
if (!string.IsNullOrEmpty(Status)) |
2849 |
{ |
2850 |
string[] arrStatus = Status.Split(','); |
2851 |
foreach (string arrstr in arrStatus) |
2852 |
{ |
2853 |
if (arrstr.Contains(Rule1)) //Missing LineNumber_1 |
2854 |
lstAcc.Add(0.75); |
2855 |
|
2856 |
if (arrstr.Contains(Rule2)) //Missing LineNumber_2 |
2857 |
lstAcc.Add(0.7); |
2858 |
|
2859 |
if (arrstr.Contains(Rule3)) // OPC Disconnected |
2860 |
lstAcc.Add(0.5); |
2861 |
|
2862 |
if (arrstr.Contains(Rule4)) //Missing ItemTag or Description |
2863 |
lstAcc.Add(0.65); |
2864 |
|
2865 |
if (arrstr.Contains(Rule5)) //Line Disconnected |
2866 |
lstAcc.Add(0.6); |
2867 |
} |
2868 |
} |
2869 |
|
2870 |
string PSNAccuracy = dataRow["PSNAccuracy"].ToString(); |
2871 |
if (PSNAccuracy == "100") |
2872 |
PSNAccuracy = "1"; |
2873 |
|
2874 |
PSNAccuracy = Convert.ToString(Convert.ToDecimal(AccuracyCalculation(lstAcc, Convert.ToDouble(PSNAccuracy)))); |
2875 |
//if (PSNAccuracy != "100") |
2876 |
//{ |
2877 |
// //dataRow["IncludingVirtualData"] = "No"; |
2878 |
dataRow["PSNAccuracy"] = PSNAccuracy; |
2879 |
//} |
2880 |
} |
2881 |
DataTable dt = PipeSystemNetwork.DefaultView.ToTable(true, new string[] { "OID" }); |
2882 |
foreach (DataRow dr in dt.Rows) |
2883 |
{ |
2884 |
string oid = dr.Field<string>("OID"); |
2885 |
DataRow[] select = PipeSystemNetwork.Select(string.Format("OID = '{0}'", oid)); |
2886 |
double totalDdr = 0; |
2887 |
foreach (DataRow ddr in select) |
2888 |
{ |
2889 |
double acc = Convert.ToDouble(ddr.Field<string>("PSNAccuracy")); |
2890 |
if (acc == 100) acc = 1; |
2891 |
if (totalDdr == 0) totalDdr = acc; |
2892 |
else totalDdr *= acc; |
2893 |
} |
2894 |
|
2895 |
totalDdr *= 100; |
2896 |
|
2897 |
if (totalDdr != 100) |
2898 |
{ |
2899 |
foreach (DataRow ddr in select) |
2900 |
{ |
2901 |
ddr["IncludingVirtualData"] = "Yes"; |
2902 |
ddr["PSNAccuracy"] = String.Format("{0:0.00}", Math.Round(totalDdr, 2)); |
2903 |
} |
2904 |
} |
2905 |
else |
2906 |
{ |
2907 |
foreach (DataRow ddr in select) |
2908 |
{ |
2909 |
ddr["IncludingVirtualData"] = "No"; |
2910 |
ddr["PSNAccuracy"] = String.Format("{0:0.00}", Math.Round(totalDdr, 2)); |
2911 |
} |
2912 |
} |
2913 |
} |
2914 |
|
2915 |
} |
2916 |
|
2917 |
private void UpdateKeywordForPSN() |
2918 |
{ |
2919 |
#region Keyword Info |
2920 |
KeywordInfo KeywordInfos = new KeywordInfo(); |
2921 |
DataTable dtKeyword = DB.SelectKeywordsSetting(); |
2922 |
foreach (DataRow row in dtKeyword.Rows) |
2923 |
{ |
2924 |
int index = Convert.ToInt32(row["INDEX"]); |
2925 |
string name = row["NAME"].ToString(); |
2926 |
string keyword = row["KEYWORD"].ToString(); |
2927 |
|
2928 |
//KeywordInfo keywordInfo = new KeywordInfo(); |
2929 |
KeywordInfos.KeywordItems.Add(new KeywordItem() |
2930 |
{ |
2931 |
Index = index, |
2932 |
Name = name, |
2933 |
Keyword = keyword |
2934 |
}); |
2935 |
} |
2936 |
#endregion |
2937 |
|
2938 |
DataRow[] endofHeaderRows = PipeSystemNetwork.Select(string.Format(" From_Data = '{0}' OR To_Data = '{0}'", "ENDOFHEADER")); |
2939 |
foreach (DataRow dataRow in endofHeaderRows) |
2940 |
{ |
2941 |
PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString()); |
2942 |
|
2943 |
if (dataRow.Field<string>("From_Data") == "ENDOFHEADER") |
2944 |
{ |
2945 |
DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"])); |
2946 |
DataRow dr = pathItemRows.First(); |
2947 |
dr["CLASS"] = PSNItem.Groups.First().Items.First().ID2DBName; |
2948 |
dr["TYPE"] = "End"; |
2949 |
dr["ITEMTAG"] = "ENDOFHEADER"; |
2950 |
dr["DESCRIPTION"] = "ENDOFHEADER"; |
2951 |
} |
2952 |
|
2953 |
if (dataRow.Field<string>("To_Data") == "ENDOFHEADER") |
2954 |
{ |
2955 |
DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"])); |
2956 |
DataRow dr = pathItemRows.Last(); |
2957 |
dr["CLASS"] = PSNItem.Groups.Last().Items.Last().ID2DBName; |
2958 |
dr["TYPE"] = "End"; |
2959 |
dr["ITEMTAG"] = "ENDOFHEADER"; |
2960 |
dr["DESCRIPTION"] = "ENDOFHEADER"; |
2961 |
} |
2962 |
} |
2963 |
|
2964 |
foreach (KeywordItem keyitem in KeywordInfos.KeywordItems) |
2965 |
{ |
2966 |
DataRow[] keywordRows = PipeSystemNetwork.Select(string.Format(" From_Data = '{0}' OR To_Data = '{0}'", keyitem.Keyword)); |
2967 |
foreach (DataRow dataRow in keywordRows) |
2968 |
{ |
2969 |
PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString()); |
2970 |
|
2971 |
if (dataRow.Field<string>("From_Data") == keyitem.Keyword) |
2972 |
{ |
2973 |
DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"])); |
2974 |
|
2975 |
// |
2976 |
//if(.) |
2977 |
if (PSNItem.Groups.First().Items.First().Name.Equals(keyitem.Name)) |
2978 |
{ |
2979 |
DataRow dr = pathItemRows.First(); |
2980 |
//dr["CLASS"] = ""; //Type |
2981 |
dr["TYPE"] = "End"; |
2982 |
dr["ITEMTAG"] = keyitem.Keyword; |
2983 |
dr["DESCRIPTION"] = keyitem.Keyword; |
2984 |
} |
2985 |
|
2986 |
} |
2987 |
|
2988 |
if (dataRow.Field<string>("To_Data") == keyitem.Keyword) |
2989 |
{ |
2990 |
DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"])); |
2991 |
|
2992 |
if (PSNItem.Groups.Last().Items.Last().Name.Equals(keyitem.Name)) |
2993 |
{ |
2994 |
DataRow dr = pathItemRows.Last(); |
2995 |
//dr["CLASS"] = ""; //Type |
2996 |
dr["TYPE"] = "End"; |
2997 |
dr["ITEMTAG"] = keyitem.Keyword; |
2998 |
dr["DESCRIPTION"] = keyitem.Keyword; |
2999 |
//dr.Field<string>("Type") |
3000 |
} |
3001 |
|
3002 |
} |
3003 |
} |
3004 |
} |
3005 |
} |
3006 |
|
3007 |
private void UpdateErrorForPSN() |
3008 |
{ |
3009 |
DataRow[] errorRows = PipeSystemNetwork.Select(string.Format(" Type = '{0}'", ErrorType.Error)); |
3010 |
foreach (DataRow dataRow in errorRows) |
3011 |
{ |
3012 |
try |
3013 |
{ |
3014 |
PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString()); |
3015 |
|
3016 |
bool change = false; |
3017 |
bool bCheck = false; |
3018 |
if (!PSNItem.EnableType(PSNItem.StartType)) |
3019 |
{ |
3020 |
change = true; |
3021 |
DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"])); |
3022 |
int insertIndex = PathItems.Rows.IndexOf(pathItemRows.First()); |
3023 |
|
3024 |
Item item = PSNItem.Groups.First().Items.First(); |
3025 |
try |
3026 |
{ |
3027 |
string FROM_DATA = string.Format("TIEINPOINT_{0:D5}V", tieInPointIndex); |
3028 |
|
3029 |
foreach (DataRow loopRow in PipeSystemNetwork.Select(string.Format("OID = '{0}'", PSNItem.PSN_OID()))) |
3030 |
{ |
3031 |
loopRow["FROM_DATA"] = FROM_DATA; |
3032 |
if (item.ItemType == ItemType.Line) |
3033 |
{ |
3034 |
if (loopRow.Field<string>("OrderNumber") == "0") |
3035 |
{ |
3036 |
string status = loopRow.Field<string>("Status"); |
3037 |
//string isvali |
3038 |
if (string.IsNullOrEmpty(status)) |
3039 |
status = "Line Disconnected"; |
3040 |
else if (!status.Contains("Line Disconnected")) |
3041 |
status += ", Line Disconnected"; |
3042 |
loopRow["Status"] = status; |
3043 |
if (!string.IsNullOrEmpty(status)) |
3044 |
loopRow["IsValid"] = "Error"; |
3045 |
} |
3046 |
} |
3047 |
} |
3048 |
|
3049 |
tieInPointIndex++; |
3050 |
|
3051 |
if (item.ItemType == ItemType.Line) |
3052 |
{ |
3053 |
PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.First(), FROM_DATA), insertIndex); |
3054 |
} |
3055 |
else |
3056 |
{ |
3057 |
PathItems.Rows.InsertAt(createLineRow(PathItems.Select(string.Format("PipeLine_OID = '{0}' AND ItemName = 'PipeRun' AND PipeSystemNetwork_OID = '{1}'", item.PSNPipeLineID, dataRow["OID"])).First()), insertIndex); |
3058 |
PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.First(), FROM_DATA), insertIndex); |
3059 |
|
3060 |
bCheck = true; |
3061 |
} |
3062 |
|
3063 |
PSNItem.StartType = PSNType.Equipment; |
3064 |
} |
3065 |
catch (Exception ex) |
3066 |
{ |
3067 |
MessageBox.Show("Please check the item.\r\nDrawingName : " + item.Document.DrawingName + "\r\nUID : " + item.UID, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
3068 |
return; |
3069 |
} |
3070 |
} |
3071 |
|
3072 |
if (!PSNItem.EnableType(PSNItem.EndType)) |
3073 |
{ |
3074 |
DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"])); |
3075 |
//int insertIndex = PathItems.Rows.IndexOf(pathItemRows.First()) + pathItemRows.Count() - 1; |
3076 |
DataRow dr = pathItemRows.Last(); |
3077 |
if (change) |
3078 |
{ |
3079 |
if(bCheck) |
3080 |
dr = pathItemRows[pathItemRows.Count() - 3]; |
3081 |
else |
3082 |
{ |
3083 |
dr = pathItemRows[pathItemRows.Count() - 2]; |
3084 |
} |
3085 |
} |
3086 |
|
3087 |
change = true; |
3088 |
int insertIndex = PathItems.Rows.IndexOf(dr) + 1; |
3089 |
|
3090 |
Item item = PSNItem.Groups.Last().Items.Last(); |
3091 |
try |
3092 |
{ |
3093 |
string TO_DATA = string.Format("TIEINPOINT_{0:D5}V", tieInPointIndex); |
3094 |
|
3095 |
|
3096 |
foreach (DataRow loopRow in PipeSystemNetwork.Select(string.Format("OID = '{0}'", PSNItem.PSN_OID()))) |
3097 |
{ |
3098 |
loopRow["TO_DATA"] = TO_DATA; |
3099 |
if (item.ItemType == ItemType.Line) |
3100 |
{ |
3101 |
if (loopRow.Field<string>("OrderNumber") == Convert.ToString(PipeSystemNetwork.Select(string.Format("OID = '{0}'", PSNItem.PSN_OID())).Count() - 1)) |
3102 |
{ |
3103 |
string status = loopRow.Field<string>("Status"); |
3104 |
if (string.IsNullOrEmpty(status)) |
3105 |
status = "Line Disconnected"; |
3106 |
else if (!status.Contains("Line Disconnected")) |
3107 |
status += ", Line Disconnected"; |
3108 |
loopRow["Status"] = status; |
3109 |
if (!string.IsNullOrEmpty(status)) |
3110 |
loopRow["IsValid"] = "Error"; |
3111 |
} |
3112 |
} |
3113 |
} |
3114 |
|
3115 |
tieInPointIndex++; |
3116 |
|
3117 |
if (item.ItemType == ItemType.Line) |
3118 |
{ |
3119 |
PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.Last(), TO_DATA), insertIndex); |
3120 |
} |
3121 |
else |
3122 |
{ |
3123 |
PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.Last(), TO_DATA), insertIndex); |
3124 |
if(PathItems.Select(string.Format("PipeLine_OID = '{0}' AND ItemName = 'PipeRun' AND PipeSystemNetwork_OID = '{1}'", item.PSNPipeLineID, dataRow["OID"])).Count() > 0) |
3125 |
PathItems.Rows.InsertAt(createLineRow(PathItems.Select(string.Format("PipeLine_OID = '{0}' AND ItemName = 'PipeRun' AND PipeSystemNetwork_OID = '{1}'", item.PSNPipeLineID, dataRow["OID"])).Last()), insertIndex); |
3126 |
} |
3127 |
|
3128 |
PSNItem.EndType = PSNType.Equipment; |
3129 |
} |
3130 |
catch (Exception ex) |
3131 |
{ |
3132 |
MessageBox.Show("Please check the item.\r\nDrawingName : " + item.Document.DrawingName + "\r\nUID : " + item.UID, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
3133 |
return; |
3134 |
} |
3135 |
} |
3136 |
|
3137 |
dataRow["Type"] = PSNItem.GetPSNType(); |
3138 |
if (change) |
3139 |
{ |
3140 |
int rowIndex = 0; |
3141 |
for (int i = 0; i < PathItems.Rows.Count; i++) |
3142 |
{ |
3143 |
DataRow row = PathItems.Rows[i]; |
3144 |
if (row["PipeSystemNetwork_OID"].ToString() != dataRow["OID"].ToString()) |
3145 |
continue; |
3146 |
string sequenceData = row["SequenceData_OID"].ToString(); |
3147 |
string[] split = sequenceData.Split(new char[] { '_' }); |
3148 |
|
3149 |
StringBuilder sb = new StringBuilder(); |
3150 |
for (int j = 0; j < split.Length - 1; j++) |
3151 |
sb.Append(split[j] + "_"); |
3152 |
sb.Append(rowIndex++); |
3153 |
row["SequenceData_OID"] = sb.ToString(); |
3154 |
|
3155 |
DataRow seqItemRows = SequenceData.Select(string.Format("PathItem_OID = '{0}'", row["OID"])).FirstOrDefault(); |
3156 |
int insertSeqIndex = SequenceData.Rows.IndexOf(seqItemRows); |
3157 |
|
3158 |
string[] splitseq = sb.ToString().Split(new char[] { '_' }); |
3159 |
|
3160 |
if (seqItemRows == null) |
3161 |
{ |
3162 |
DataRow newRow = SequenceData.NewRow(); |
3163 |
newRow["OID"] = sb.ToString(); |
3164 |
newRow["SERIALNUMBER"] = splitseq[splitseq.Length - 1]; |
3165 |
newRow["PathItem_OID"] = row["OID"]; |
3166 |
newRow["TopologySet_OID_Key"] = row["TopologySet_OID"]; |
3167 |
SequenceData.Rows.InsertAt(newRow, Convert.ToInt32(splitseq[splitseq.Length - 1])); |
3168 |
} |
3169 |
else |
3170 |
{ |
3171 |
seqItemRows["OID"] = sb.ToString(); |
3172 |
seqItemRows["SERIALNUMBER"] = splitseq[splitseq.Length - 1]; |
3173 |
seqItemRows["PathItem_OID"] = row["OID"]; |
3174 |
seqItemRows["TopologySet_OID_Key"] = row["TopologySet_OID"]; |
3175 |
} |
3176 |
} |
3177 |
} |
3178 |
|
3179 |
DataRow createTerminatorRow(DataRow itemRow, string DATA) |
3180 |
{ |
3181 |
DataRow newRow = PathItems.NewRow(); |
3182 |
newRow["OID"] = Guid.NewGuid().ToString(); |
3183 |
newRow["SequenceData_OID"] = itemRow["SequenceData_OID"]; |
3184 |
newRow["TopologySet_OID"] = itemRow["TopologySet_OID"]; |
3185 |
newRow["BranchTopologySet_OID"] = itemRow["BranchTopologySet_OID"]; |
3186 |
newRow["PipeLine_OID"] = itemRow["PipeLine_OID"]; |
3187 |
newRow["ITEMNAME"] = "PipingComp"; //newRow["ITEMNAME"] = "End of line terminator"; |
3188 |
newRow["ITEMTAG"] = DATA; //itemRow["ITEMTAG"]; |
3189 |
newRow["DESCRIPTION"] = DATA; |
3190 |
newRow["Class"] = "End of line terminator"; |
3191 |
newRow["SubClass"] = "End of line terminator"; |
3192 |
newRow["TYPE"] = "End"; |
3193 |
newRow["PIDNAME"] = itemRow["PIDNAME"]; |
3194 |
newRow["NPD"] = itemRow["NPD"]; |
3195 |
newRow["PipeSystemNetwork_OID"] = itemRow["PipeSystemNetwork_OID"]; |
3196 |
newRow["ViewPipeSystemNetwork_OID"] = itemRow["ViewPipeSystemNetwork_OID"]; |
3197 |
newRow["PipeRun_OID"] = itemRow["PipeRun_OID"]; |
3198 |
newRow["EGTConnectedPoint"] = "0"; |
3199 |
return newRow; |
3200 |
} |
3201 |
|
3202 |
DataRow createLineRow(DataRow itemRow) |
3203 |
{ |
3204 |
DataRow newRow = PathItems.NewRow(); |
3205 |
newRow["OID"] = Guid.NewGuid().ToString(); |
3206 |
newRow["SequenceData_OID"] = itemRow["SequenceData_OID"]; |
3207 |
newRow["TopologySet_OID"] = itemRow["TopologySet_OID"]; |
3208 |
newRow["BranchTopologySet_OID"] = itemRow["BranchTopologySet_OID"]; |
3209 |
newRow["PipeLine_OID"] = itemRow["PipeLine_OID"]; |
3210 |
newRow["ITEMNAME"] = itemRow["ITEMNAME"]; |
3211 |
newRow["ITEMTAG"] = itemRow["ITEMTAG"]; |
3212 |
newRow["Class"] = itemRow["Class"]; |
3213 |
newRow["SubClass"] = itemRow["SubClass"]; |
3214 |
newRow["TYPE"] = itemRow["TYPE"]; |
3215 |
newRow["PIDNAME"] = itemRow["PIDNAME"]; |
3216 |
newRow["NPD"] = itemRow["NPD"]; |
3217 |
newRow["PipeSystemNetwork_OID"] = itemRow["PipeSystemNetwork_OID"]; |
3218 |
newRow["ViewPipeSystemNetwork_OID"] = itemRow["ViewPipeSystemNetwork_OID"]; |
3219 |
newRow["PipeRun_OID"] = itemRow["PipeRun_OID"]; |
3220 |
newRow["EGTConnectedPoint"] = "0"; |
3221 |
return newRow; |
3222 |
} |
3223 |
} |
3224 |
catch (Exception ex) |
3225 |
{ |
3226 |
|
3227 |
} |
3228 |
} |
3229 |
} |
3230 |
|
3231 |
private void InsertTeePSN() |
3232 |
{ |
3233 |
DataTable dt = PipeSystemNetwork.DefaultView.ToTable(true, new string[] { "OID", "Type" }); |
3234 |
DataRow[] branchRows = dt.Select("Type Like '%B%'"); |
3235 |
bool change = false; |
3236 |
foreach (DataRow dataRow in branchRows) |
3237 |
{ |
3238 |
try |
3239 |
{ |
3240 |
PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString()); |
3241 |
change = false; |
3242 |
|
3243 |
if (PSNItem.StartType == PSNType.Branch) |
3244 |
{ |
3245 |
DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", PSNItem.PSN_OID())); |
3246 |
int insertIndex = PathItems.Rows.IndexOf(pathItemRows.First()); |
3247 |
Item Teeitem = PSNItem.Groups.First().Items.First(); |
3248 |
try |
3249 |
{ |
3250 |
if (Teeitem.ItemType == ItemType.Line) |
3251 |
{ |
3252 |
if (pathItemRows.First().Field<string>("SubClass") != "Tee") |
3253 |
{ |
3254 |
PathItems.Rows.InsertAt(createTeeRow(pathItemRows.First()), insertIndex); |
3255 |
pathItemRows.First().SetField("BranchTopologySet_OID", string.Empty); |
3256 |
pathItemRows.First().SetField("ViewPipeSystemNetwork_OID", dataRow["OID"].ToString()); |
3257 |
change = true; |
3258 |
} |
3259 |
|
3260 |
} |
3261 |
} |
3262 |
catch (Exception ex) |
3263 |
{ |
3264 |
MessageBox.Show("Please check the item.\r\nDrawingName : " + Teeitem.Document.DrawingName + "\r\nUID : " + Teeitem.UID, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
3265 |
return; |
3266 |
} |
3267 |
} |
3268 |
|
3269 |
if (PSNItem.EndType == PSNType.Branch) |
3270 |
{ |
3271 |
//change = true; |
3272 |
DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", PSNItem.PSN_OID())); |
3273 |
|
3274 |
Item Teeitem = PSNItem.Groups.Last().Items.Last(); |
3275 |
|
3276 |
DataRow dr = pathItemRows.Last(); |
3277 |
if (change) |
3278 |
dr = pathItemRows[pathItemRows.Count() - 2]; |
3279 |
|
3280 |
int insertIndex = PathItems.Rows.IndexOf(dr) + 1; |
3281 |
|
3282 |
try |
3283 |
{ |
3284 |
if (Teeitem.ItemType == ItemType.Line) |
3285 |
{ |
3286 |
if (dr.Field<string>("SubClass") != "Tee") |
3287 |
{ |
3288 |
PathItems.Rows.InsertAt(createTeeRow(dr), insertIndex); |
3289 |
change = true; |
3290 |
dr.SetField("BranchTopologySet_OID", string.Empty); |
3291 |
dr.SetField("ViewPipeSystemNetwork_OID", dataRow["OID"].ToString()); |
3292 |
} |
3293 |
|
3294 |
} |
3295 |
} |
3296 |
catch (Exception ex) |
3297 |
{ |
3298 |
MessageBox.Show("Please check the item.\r\nDrawingName : " + Teeitem.Document.DrawingName + "\r\nUID : " + Teeitem.UID, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
3299 |
return; |
3300 |
} |
3301 |
} |
3302 |
|
3303 |
if (change) |
3304 |
{ |
3305 |
//DataRow[] pathItemRows = pathItemsDT.Select(string.Format("PipeSystemNetwork_OID = '{0}'", PSNItem.PSN_OID())); |
3306 |
int rowIndex = 0; |
3307 |
for (int i = 0; i < PathItems.Rows.Count; i++) |
3308 |
{ |
3309 |
DataRow row = PathItems.Rows[i]; |
3310 |
if (row["PipeSystemNetwork_OID"].ToString() != PSNItem.PSN_OID()) |
3311 |
continue; |
3312 |
string sequenceData = row["SequenceData_OID"].ToString(); |
3313 |
string[] split = sequenceData.Split(new char[] { '_' }); |
3314 |
|
3315 |
StringBuilder sb = new StringBuilder(); |
3316 |
for (int j = 0; j < split.Length - 1; j++) |
3317 |
sb.Append(split[j] + "_"); |
3318 |
sb.Append(rowIndex++); |
3319 |
row["SequenceData_OID"] = sb.ToString(); |
3320 |
|
3321 |
DataRow seqItemRows = SequenceData.Select(string.Format("PathItem_OID = '{0}'", row["OID"])).FirstOrDefault(); |
3322 |
int insertSeqIndex = SequenceData.Rows.IndexOf(seqItemRows); |
3323 |
|
3324 |
string[] splitseq = sb.ToString().Split(new char[] { '_' }); |
3325 |
|
3326 |
if (seqItemRows == null) |
3327 |
{ |
3328 |
DataRow newRow = SequenceData.NewRow(); |
3329 |
newRow["OID"] = sb.ToString(); |
3330 |
newRow["SERIALNUMBER"] = splitseq[splitseq.Length - 1]; |
3331 |
newRow["PathItem_OID"] = row["OID"]; |
3332 |
newRow["TopologySet_OID_Key"] = row["TopologySet_OID"]; |
3333 |
SequenceData.Rows.InsertAt(newRow, Convert.ToInt32(splitseq[splitseq.Length - 1])); |
3334 |
} |
3335 |
else |
3336 |
{ |
3337 |
seqItemRows["OID"] = sb.ToString(); |
3338 |
seqItemRows["SERIALNUMBER"] = splitseq[splitseq.Length - 1]; |
3339 |
seqItemRows["PathItem_OID"] = row["OID"]; |
3340 |
seqItemRows["TopologySet_OID_Key"] = row["TopologySet_OID"]; |
3341 |
} |
3342 |
} |
3343 |
} |
3344 |
|
3345 |
DataRow createTeeRow(DataRow itemRow) |
3346 |
{ |
3347 |
DataRow newRow = PathItems.NewRow(); |
3348 |
newRow["OID"] = Guid.NewGuid().ToString(); |
3349 |
newRow["SequenceData_OID"] = itemRow["SequenceData_OID"]; |
3350 |
newRow["TopologySet_OID"] = itemRow["TopologySet_OID"]; |
3351 |
newRow["BranchTopologySet_OID"] = itemRow["BranchTopologySet_OID"]; |
3352 |
newRow["PipeLine_OID"] = itemRow["PipeLine_OID"]; |
3353 |
newRow["ITEMNAME"] = "Branch"; //newRow["ITEMNAME"] = "End of line terminator"; |
3354 |
newRow["ITEMTAG"] = itemRow["ITEMTAG"]; |
3355 |
newRow["DESCRIPTION"] = ""; |
3356 |
newRow["Class"] = "Branch"; |
3357 |
newRow["SubClass"] = "Tee"; |
3358 |
newRow["TYPE"] = itemRow["TYPE"]; |
3359 |
newRow["PIDNAME"] = itemRow["PIDNAME"]; |
3360 |
newRow["NPD"] = itemRow["NPD"]; |
3361 |
newRow["PipeSystemNetwork_OID"] = itemRow["PipeSystemNetwork_OID"]; |
3362 |
newRow["ViewPipeSystemNetwork_OID"] = itemRow["ViewPipeSystemNetwork_OID"]; |
3363 |
newRow["PipeRun_OID"] = itemRow["PipeRun_OID"]; |
3364 |
|
3365 |
newRow["EGTConnectedPoint"] = 0; |
3366 |
return newRow; |
3367 |
} |
3368 |
} |
3369 |
catch (Exception ex) |
3370 |
{ |
3371 |
|
3372 |
} |
3373 |
} |
3374 |
} |
3375 |
} |
3376 |
|
3377 |
public class PSNItem |
3378 |
{ |
3379 |
public PSNItem(int count, int Revision) |
3380 |
{ |
3381 |
Groups = new List<Group>(); |
3382 |
Topologies = new List<Topology>(); |
3383 |
|
3384 |
Index = count + 1; |
3385 |
this.Revision = Revision; |
3386 |
} |
3387 |
|
3388 |
private int Revision; |
3389 |
public string UID { get; set; } |
3390 |
public List<Group> Groups { get; set; } |
3391 |
public List<Topology> Topologies { get; set; } |
3392 |
public PSNType StartType { get; set; } |
3393 |
public PSNType EndType { get; set; } |
3394 |
public int Index { get; set; } |
3395 |
public string IsValid { get; set; } |
3396 |
public bool IsKeyword { get; set; } |
3397 |
public string Status { get; set; } |
3398 |
public string IncludingVirtualData { get; set; } |
3399 |
public string PSNAccuracy { get; set; } |
3400 |
public KeywordInfo KeywordInfos = new KeywordInfo(); |
3401 |
public DataTable Nozzle = new DataTable(); |
3402 |
|
3403 |
public string PSN_OID() |
3404 |
{ |
3405 |
return string.Format("V{0}-PSN-{1}", string.Format("{0:D4}", Revision), string.Format("{0:D5}", Index)); |
3406 |
} |
3407 |
|
3408 |
public string GetPSNType() |
3409 |
{ |
3410 |
string result = string.Empty; |
3411 |
|
3412 |
if (EnableType(StartType) && EnableType(EndType)) |
3413 |
{ |
3414 |
if (StartType == PSNType.Equipment && EndType == PSNType.Equipment) |
3415 |
result = "E2E"; |
3416 |
else if (StartType == PSNType.Branch && EndType == PSNType.Branch) |
3417 |
result = "B2B"; |
3418 |
else if (StartType == PSNType.Header && EndType == PSNType.Header) |
3419 |
result = "HD2"; |
3420 |
|
3421 |
else if (StartType == PSNType.Equipment && EndType == PSNType.Branch) |
3422 |
result = "E2B"; |
3423 |
else if (StartType == PSNType.Branch && EndType == PSNType.Equipment) |
3424 |
result = "B2E"; |
3425 |
|
3426 |
else if (StartType == PSNType.Header && EndType == PSNType.Branch) |
3427 |
result = "HDB"; |
3428 |
else if (StartType == PSNType.Branch && EndType == PSNType.Header) |
3429 |
result = "HDB"; |
3430 |
|
3431 |
else if (StartType == PSNType.Header && EndType == PSNType.Equipment) |
3432 |
result = "HDE"; |
3433 |
else if (StartType == PSNType.Equipment && EndType == PSNType.Header) |
3434 |
result = "HDE"; |
3435 |
else |
3436 |
result = "Error"; |
3437 |
} |
3438 |
else |
3439 |
result = "Error"; |
3440 |
|
3441 |
return result; |
3442 |
|
3443 |
|
3444 |
} |
3445 |
|
3446 |
public bool EnableType(PSNType type) |
3447 |
{ |
3448 |
bool result = false; |
3449 |
|
3450 |
if (type == PSNType.Branch || |
3451 |
type == PSNType.Equipment || |
3452 |
type == PSNType.Header) |
3453 |
{ |
3454 |
result = true; |
3455 |
} |
3456 |
|
3457 |
return result; |
3458 |
} |
3459 |
|
3460 |
public bool IsBypass { get; set; } |
3461 |
|
3462 |
public string GetFromData(ref string Type, ref Item item) |
3463 |
{ |
3464 |
Status = string.Empty; |
3465 |
string result = string.Empty; |
3466 |
if (IsKeyword) |
3467 |
IsKeyword = false; |
3468 |
try |
3469 |
{ |
3470 |
item = Groups.First().Items.First(); |
3471 |
|
3472 |
if (StartType == PSNType.Header) |
3473 |
result = "ENDOFHEADER"; |
3474 |
else if (StartType == PSNType.Branch) |
3475 |
{ |
3476 |
if (item.Relations.First().Item.LineNumber != null && !string.IsNullOrEmpty(item.Relations.First().Item.LineNumber.Name)) |
3477 |
{ |
3478 |
result = item.Relations.First().Item.LineNumber.Name; |
3479 |
if (item.MissingLineNumber2) |
3480 |
{ |
3481 |
Status += ", Missing LineNumber_2"; |
3482 |
IsValid = "Error"; |
3483 |
} |
3484 |
if (item.MissingLineNumber1) |
3485 |
{ |
3486 |
Status += ", Missing LineNumber_1"; |
3487 |
IsValid = "Error"; |
3488 |
} |
3489 |
} |
3490 |
else |
3491 |
{ |
3492 |
IsValid = "Error"; |
3493 |
result = "Empty LineNumber"; |
3494 |
} |
3495 |
} |
3496 |
else if (StartType == PSNType.Equipment) |
3497 |
{ |
3498 |
if (Groups.First().Items.First().Equipment != null) |
3499 |
result = Groups.First().Items.First().Equipment.ItemTag; |
3500 |
DataRow drNozzle = Nozzle.Select(string.Format("OID = '{0}'", Groups.First().Items.First().UID)).FirstOrDefault(); |
3501 |
|
3502 |
if (drNozzle != null) |
3503 |
result += " [" + drNozzle.Field<string>("ITEMTAG") + "]"; |
3504 |
} |
3505 |
else |
3506 |
{ |
3507 |
IsValid = "Error"; |
3508 |
item = Groups.First().Items.First(); |
3509 |
if (item.ItemType == ItemType.Symbol) |
3510 |
{ |
3511 |
|
3512 |
string keyword = string.Empty; |
3513 |
keyword = GetFromKeywordData(ref Type, item); |
3514 |
|
3515 |
if (string.IsNullOrEmpty(keyword)) |
3516 |
{ |
3517 |
if (item.ID2DBType.Contains("OPC's")) |
3518 |
Status += ", OPC Disconnected"; |
3519 |
else |
3520 |
Status += ", Missing ItemTag or Description"; |
3521 |
|
3522 |
result = item.ID2DBName; |
3523 |
} |
3524 |
else |
3525 |
{ |
3526 |
result = keyword; |
3527 |
IsKeyword = true; |
3528 |
IsValid = string.Empty; |
3529 |
} |
3530 |
|
3531 |
} |
3532 |
else if (item.ItemType == ItemType.Line) |
3533 |
{ |
3534 |
|
3535 |
if (item.LineNumber != null && !string.IsNullOrEmpty(item.LineNumber.Name)) |
3536 |
{ |
3537 |
result = item.LineNumber.Name; |
3538 |
if (item.MissingLineNumber2) |
3539 |
{ |
3540 |
Status += ", Missing LineNumber_2"; |
3541 |
IsValid = "Error"; |
3542 |
} |
3543 |
if (item.MissingLineNumber1) |
3544 |
{ |
3545 |
Status += ", Missing LineNumber_1"; |
3546 |
IsValid = "Error"; |
3547 |
} |
3548 |
} |
3549 |
else |
3550 |
{ |
3551 |
IsValid = "Error"; |
3552 |
result = "Empty LineNumber"; |
3553 |
} |
3554 |
} |
3555 |
else |
3556 |
result = "Unknown"; |
3557 |
} |
3558 |
} |
3559 |
catch (Exception ex) |
3560 |
{ |
3561 |
|
3562 |
} |
3563 |
|
3564 |
return result; |
3565 |
} |
3566 |
|
3567 |
public string GetFromKeywordData(ref string Type, Item item) |
3568 |
{ |
3569 |
string result = string.Empty; |
3570 |
|
3571 |
foreach (KeywordItem keyitem in KeywordInfos.KeywordItems) |
3572 |
{ |
3573 |
if (keyitem.Name.Equals(item.Name)) |
3574 |
{ |
3575 |
result = keyitem.Keyword; |
3576 |
Type = item.ID2DBType; |
3577 |
break; |
3578 |
} |
3579 |
} |
3580 |
|
3581 |
return result; |
3582 |
} |
3583 |
|
3584 |
public string GetToKeywordData(ref string Type, Item item) |
3585 |
{ |
3586 |
string result = string.Empty; |
3587 |
|
3588 |
foreach (KeywordItem keyitem in KeywordInfos.KeywordItems) |
3589 |
{ |
3590 |
if (keyitem.Name.Equals(item.Name)) |
3591 |
{ |
3592 |
result = keyitem.Keyword; |
3593 |
Type = item.ID2DBType; |
3594 |
break; |
3595 |
} |
3596 |
} |
3597 |
return result; |
3598 |
} |
3599 |
|
3600 |
public string GetToData(ref string ToType, ref Item item) |
3601 |
{ |
3602 |
string result = string.Empty; |
3603 |
Status = string.Empty; |
3604 |
|
3605 |
if (IsKeyword) |
3606 |
IsKeyword = false; |
3607 |
|
3608 |
item = Groups.Last().Items.Last(); |
3609 |
|
3610 |
if (EndType == PSNType.Header) |
3611 |
result = "ENDOFHEADER"; |
3612 |
else if (EndType == PSNType.Branch) |
3613 |
{ |
3614 |
if (item.Relations.Last().Item.LineNumber != null && !string.IsNullOrEmpty(item.Relations.Last().Item.LineNumber.Name)) |
3615 |
{ |
3616 |
result = item.Relations.Last().Item.LineNumber.Name; |
3617 |
if (item.MissingLineNumber2) |
3618 |
{ |
3619 |
Status += ", Missing LineNumber_2"; |
3620 |
IsValid = "Error"; |
3621 |
} |
3622 |
if (item.MissingLineNumber1) |
3623 |
{ |
3624 |
Status += ", Missing LineNumber_1"; |
3625 |
IsValid = "Error"; |
3626 |
} |
3627 |
} |
3628 |
else |
3629 |
{ |
3630 |
IsValid = "Error"; |
3631 |
result = "Empty LineNumber"; |
3632 |
} |
3633 |
} |
3634 |
else if (EndType == PSNType.Equipment) |
3635 |
{ |
3636 |
if (Groups.Last().Items.Last().Equipment != null) |
3637 |
result = Groups.Last().Items.Last().Equipment.ItemTag; |
3638 |
|
3639 |
DataRow drNozzle = Nozzle.Select(string.Format("OID = '{0}'", Groups.Last().Items.Last().UID)).FirstOrDefault(); |
3640 |
|
3641 |
if (drNozzle != null) |
3642 |
result += " [" + drNozzle.Field<string>("ITEMTAG") + "]"; |
3643 |
} |
3644 |
else |
3645 |
{ |
3646 |
IsValid = "Error"; |
3647 |
item = Groups.Last().Items.Last(); |
3648 |
if (item.ItemType == ItemType.Symbol) |
3649 |
{ |
3650 |
string keyword = string.Empty; |
3651 |
keyword = GetToKeywordData(ref ToType, item); |
3652 |
|
3653 |
if (string.IsNullOrEmpty(keyword)) |
3654 |
{ |
3655 |
if (item.ID2DBType.Contains("OPC's")) |
3656 |
Status += ", OPC Disconnected"; |
3657 |
else |
3658 |
Status += ", Missing ItemTag or Description"; |
3659 |
|
3660 |
result = item.ID2DBName; |
3661 |
} |
3662 |
else |
3663 |
{ |
3664 |
result = keyword; |
3665 |
IsValid = string.Empty; |
3666 |
IsKeyword = true; |
3667 |
} |
3668 |
|
3669 |
} |
3670 |
else if (item.ItemType == ItemType.Line) |
3671 |
{ |
3672 |
if (item.LineNumber != null && !string.IsNullOrEmpty(item.LineNumber.Name)) |
3673 |
{ |
3674 |
result = item.LineNumber.Name; |
3675 |
if (item.MissingLineNumber2) |
3676 |
{ |
3677 |
Status += ", Missing LineNumber_2"; |
3678 |
IsValid = "Error"; |
3679 |
} |
3680 |
if (item.MissingLineNumber1) |
3681 |
{ |
3682 |
Status += ", Missing LineNumber_1"; |
3683 |
IsValid = "Error"; |
3684 |
} |
3685 |
} |
3686 |
else |
3687 |
{ |
3688 |
IsValid = "Error"; |
3689 |
result = "Empty LineNumber"; |
3690 |
} |
3691 |
} |
3692 |
else |
3693 |
result = "Unknown"; |
3694 |
} |
3695 |
return result; |
3696 |
} |
3697 |
|
3698 |
public string GetPBSData() |
3699 |
{ |
3700 |
string result = string.Empty; |
3701 |
List<string> PBSList = new List<string>(); |
3702 |
if (Settings.Default.PBSSetting.Equals("Line Number")) |
3703 |
{ |
3704 |
string attrValue = Settings.Default.PBSSettingValue; |
3705 |
|
3706 |
foreach (Group group in Groups) |
3707 |
{ |
3708 |
List<LineNumber> lineNumbers = group.Items.Select(x => x.LineNumber).Distinct().ToList(); |
3709 |
foreach (LineNumber lineNumber in lineNumbers) |
3710 |
{ |
3711 |
Attribute attribute = lineNumber.Attributes.Find(x => x.Name == attrValue && !string.IsNullOrEmpty(x.Value)); |
3712 |
if (attribute != null) |
3713 |
{ |
3714 |
string value = attribute.Value; |
3715 |
if (!PBSList.Contains(value)) |
3716 |
PBSList.Add(value); |
3717 |
} |
3718 |
} |
3719 |
} |
3720 |
} |
3721 |
else if (Settings.Default.PBSSetting.Equals("Item Attribute")) |
3722 |
{ |
3723 |
string attrValue = Settings.Default.PBSSettingValue; |
3724 |
|
3725 |
foreach (Group group in Groups) |
3726 |
{ |
3727 |
List<Item> items = group.Items.FindAll(x => x.Attributes.Find(y => y.Name == attrValue && !string.IsNullOrEmpty(y.Value)) != null); |
3728 |
foreach (Item item in items) |
3729 |
{ |
3730 |
string value = item.Attributes.Find(x => x.Name == attrValue).Value; |
3731 |
if (!PBSList.Contains(value)) |
3732 |
PBSList.Add(value); |
3733 |
} |
3734 |
} |
3735 |
} |
3736 |
else if (Settings.Default.PBSSetting.Equals("Drawing No")) |
3737 |
{ |
3738 |
string attrValue = Settings.Default.PBSSettingValue; |
3739 |
|
3740 |
foreach (Group group in Groups) |
3741 |
{ |
3742 |
List<Document> documents = group.Items.Select(x => x.Document).Distinct().ToList(); |
3743 |
foreach (Document document in documents) |
3744 |
{ |
3745 |
string name = document.DrawingName; |
3746 |
|
3747 |
int startIndex = Settings.Default.PBSSettingStartValue; |
3748 |
int endIndex = Settings.Default.PBSSettingEndValue; |
3749 |
|
3750 |
string subStr = name.Substring(startIndex - 1, endIndex - startIndex + 1); |
3751 |
if (!PBSList.Contains(subStr)) |
3752 |
PBSList.Add(subStr); |
3753 |
} |
3754 |
} |
3755 |
} |
3756 |
else if (Settings.Default.PBSSetting.Equals("Unit Area")) |
3757 |
{ |
3758 |
foreach (Group group in Groups) |
3759 |
{ |
3760 |
List<Document> documents = group.Items.Select(x => x.Document).Distinct().ToList(); |
3761 |
foreach (Document document in documents) |
3762 |
{ |
3763 |
List<TextInfo> textInfos = document.TextInfos.FindAll(x => x.Area == "Unit"); |
3764 |
foreach (TextInfo textInfo in textInfos) |
3765 |
{ |
3766 |
if (!PBSList.Contains(textInfo.Value)) |
3767 |
PBSList.Add(textInfo.Value); |
3768 |
} |
3769 |
} |
3770 |
} |
3771 |
} |
3772 |
|
3773 |
foreach (var item in PBSList) |
3774 |
{ |
3775 |
if (string.IsNullOrEmpty(result)) |
3776 |
result = item; |
3777 |
else |
3778 |
result += ", " + item; |
3779 |
} |
3780 |
return result; |
3781 |
} |
3782 |
} |
3783 |
} |