프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / ID2PSN / PSN.cs @ 91c75c0b

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