프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / DTI_PID / ID2PSN / PSN.cs @ 88c1965b

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