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