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