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