프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / ID2PSN / PSN.cs @ 6b9e7a56

이력 | 보기 | 이력해설 | 다운로드 (27.9 KB)

1
using System;
2
using System.Collections.Generic;
3
using System.Data;
4
using System.IO;
5
using System.Linq;
6
using System.Text;
7
using System.Threading.Tasks;
8

    
9
namespace ID2PSN
10
{
11
    public enum PSNType
12
    {
13
        None,
14
        Branch,
15
        Equipment,
16
        Header,
17
        Symbol,
18
        OPC,
19
    }
20

    
21
    public class PSN
22
    {
23
        public DataTable PathItems { get; set; }
24
        public DataTable SequenceData { get; set; }
25
        public DataTable PipeSystemNetwork { get; set; }
26
        public DataTable Equipment { get; set; }
27
        public DataTable Nozzle { get; set; }
28

    
29
        List<Document> Documents;
30
        List<Group> groups = new List<Group>();
31
        List<PSNItem> PSNItems = new List<PSNItem>();
32
        List<Topology> Topologies = new List<Topology>();
33

    
34
        DataTable opcDT = null;
35
        DataTable topologyRuleDT = null;
36

    
37
        const string FluidPriorityType = "FLUIDCODE";
38
        const string PipingMaterialsPriorityType = "PIPINGMATERIALSCLASS";
39

    
40
        public PSN(List<Document> documents)
41
        {
42
            Documents = documents;
43
            foreach (Document document in Documents)
44
                groups.AddRange(document.Groups);
45
            opcDT = GetOPCInfo();
46
            topologyRuleDT = GetTopologyRule();
47
        }
48

    
49
        public void SetPSNData()
50
        {
51
            SetTopologyData();
52
            ConnectByOPC();
53
            SetPSNItem();
54
            SetPSNType();
55
            SetBranchInfo();
56
            SetTopology();
57

    
58
            SaveNozzleAndEquipment();
59
            SavePSNData();
60
        }
61
        private void SetTopologyData()
62
        {
63
            foreach (Document document in Documents)
64
            {
65
                foreach (Item item in document.Items)
66
                {
67
                    item.TopologyData = string.Empty;
68
                    LineNumber lineNumber = document.LineNumbers.Find(x => x.UID == item.Owner);
69
                    if (lineNumber != null)
70
                    {
71
                        item.LineNumber = lineNumber;
72

    
73
                        foreach (DataRow row in topologyRuleDT.Rows)
74
                        {
75
                            string uid = row["UID"].ToString();
76
                            if (uid == "-")
77
                                item.TopologyData += "-"; 
78
                            else
79
                            {
80
                                Attribute attribute = lineNumber.Attributes.Find(x => x.UID == uid);
81
                                if (attribute != null)
82
                                    item.TopologyData += attribute.Value;
83
                            }
84
                        }
85
                    }
86
                }
87
            }
88

    
89

    
90
        }
91
        private void ConnectByOPC()
92
        {
93
            foreach (Group group in groups.FindAll(x => x.Items.Last().SubItemType == SubItemType.OPC))
94
            {
95
                Item opcItem = group.Items.Last();
96
                DataRow[] fromRows = opcDT.Select(string.Format("FromOPCUID = '{0}'", opcItem.UID));
97
                if (fromRows.Length.Equals(1))
98
                {
99
                    DataRow opcRow = fromRows.First();
100
                    string toDrawing = opcRow["ToDrawing"].ToString();
101
                    string toOPCUID = opcRow["ToOPCUID"].ToString();
102

    
103
                    Document toDocument = Documents.Find(x => x.DrawingName == toDrawing);
104
                    Group toGroup = toDocument.Groups.Find(x => x.Items.Find(y => y.UID == toOPCUID) != null);
105
                    group.EndGroup = toGroup;
106
                    toGroup.StartGroup = group;
107
                }
108
            }
109
        }
110
        private void SetPSNItem()
111
        {
112
            Dictionary<Group, string> groupDic = new Dictionary<Group, string>(); 
113
            foreach (Group group in groups)
114
                groupDic.Add(group, Guid.NewGuid().ToString());
115

    
116
            foreach (Group group in groups)
117
            {
118
                string groupKey = groupDic[group];
119
                if (group.StartGroup != null)
120
                {
121
                    string otherKey = groupDic[group.StartGroup];
122
                    ChangeGroupID(otherKey, groupKey);
123
                }
124
            }
125

    
126
            // PSN 정리
127
            foreach (var item in groupDic)
128
            {
129
                Group group = item.Key;
130
                string uid = item.Value;
131
                PSNItem PSNItem = PSNItems.Find(x => x.UID == uid);
132
                if (PSNItem == null)
133
                {
134
                    PSNItem = new PSNItem() { UID = uid };
135
                    PSNItems.Add(PSNItem);
136
                }
137
                PSNItem.Groups.Add(group);
138
            }
139

    
140
            // Sort PSN
141
            foreach (PSNItem PSNItem in PSNItems)
142
            {
143
                List<Group> _groups = new List<Group>();
144

    
145
                Stack<Group> stacks = new Stack<Group>();
146
                stacks.Push(PSNItem.Groups.First());
147
                while (stacks.Count > 0)
148
                {
149
                    Group stack = stacks.Pop();
150
                    if (_groups.Contains(stack))
151
                        continue;
152

    
153
                    if (_groups.Count == 0)
154
                        _groups.Add(stack);
155
                    else
156
                    {
157
                        if (stack.StartGroup != null && _groups.Contains(stack.StartGroup))
158
                        {
159
                            int index = _groups.IndexOf(stack.StartGroup);
160
                            _groups.Insert(index + 1, stack);
161
                        }
162
                        else if (stack.EndGroup != null && _groups.Contains(stack.EndGroup))
163
                        {
164
                            int index = _groups.IndexOf(stack.EndGroup);
165
                            _groups.Insert(index, stack);
166
                        }
167
                    }
168

    
169
                    if (stack.StartGroup != null)
170
                        stacks.Push(stack.StartGroup);
171
                    if (stack.EndGroup != null)
172
                        stacks.Push(stack.EndGroup);
173
                }
174

    
175
                PSNItem.Groups.Clear();
176
                PSNItem.Groups.AddRange(_groups);
177
            }
178

    
179

    
180
            void ChangeGroupID(string from, string to)
181
            {
182
                if (from.Equals(to))
183
                    return;
184

    
185
                List<Group> changeItems = new List<Group>();
186
                foreach (var _item in groupDic)
187
                    if (_item.Value.Equals(from))
188
                        changeItems.Add(_item.Key);
189
                foreach (var _item in changeItems)
190
                    groupDic[_item] = to;
191
            }
192
        }
193
        private void SetPSNType()
194
        {
195
            foreach (PSNItem PSNItem in PSNItems)
196
            {
197
                Group firstGroup = PSNItem.Groups.First();
198
                Group lastGroup = PSNItem.Groups.Last();
199

    
200
                Item firstItem = firstGroup.Items.First();
201
                Item lastItem = lastGroup.Items.Last();
202

    
203
                PSNItem.StartType = GetPSNType(firstItem, true);
204
                PSNItem.EndType = GetPSNType(lastItem, false);
205
            }
206

    
207
            PSNType GetPSNType(Item item, bool bFirst = true)
208
            {
209
                PSNType type = PSNType.None;
210

    
211
                if (item.ItemType == ItemType.Line)
212
                {
213
                    Group group = groups.Find(x => x.Items.Contains(item));
214
                    if (bFirst && item.Relations[0].Item != null && !group.Items.Contains(item.Relations[0].Item))
215
                    {
216
                        Item connItem = item.Relations[0].Item;
217
                        if (connItem.ItemType == ItemType.Line && !IsConnected(item, connItem))
218
                            type = PSNType.Branch;
219
                        else if (connItem.ItemType == ItemType.Symbol)
220
                            type = PSNType.Symbol;
221
                    }
222
                    else if (!bFirst && item.Relations[1].Item != null && !group.Items.Contains(item.Relations[1].Item))
223
                    {
224
                        Item connItem = item.Relations[1].Item;
225
                        if (connItem.ItemType == ItemType.Line && !IsConnected(item, connItem))
226
                            type = PSNType.Branch;
227
                        else if (connItem.ItemType == ItemType.Symbol)
228
                            type = PSNType.Symbol;
229
                    }
230
                }
231
                else if (item.ItemType == ItemType.Symbol)
232
                {
233
                    if (item.SubItemType == SubItemType.Nozzle)
234
                        type = PSNType.Equipment;
235
                    else if (item.SubItemType == SubItemType.Header)
236
                        type = PSNType.Header;
237
                    else if (item.SubItemType == SubItemType.OPC)
238
                        type = PSNType.OPC;
239
                }
240

    
241
                return type;
242
            }
243
        }
244
        private void SetBranchInfo()
245
        {
246
            foreach (Document document in Documents)
247
            {
248
                List<Item> lines = document.Items.FindAll(x => x.ItemType == ItemType.Line).ToList();
249
                foreach (Item line in lines)
250
                {
251
                    double[] point = line.Relations[0].Point;
252
                    List<Item> connLines = lines.FindAll(x => x.Relations.Find(y => y.UID == line.UID) != null && line.Relations.Find(y => y.UID == x.UID) == null);
253
                    connLines.Sort(SortBranchLine);
254
                    line.BranchItems.AddRange(connLines);
255

    
256
                    int SortBranchLine(Item a, Item b)
257
                    {
258
                        double[] pointA = a.Relations[0].UID == line.UID ? a.Relations[0].Point : a.Relations[1].Point;
259
                        double distanceA = CalcPointToPointdDistance(point[0], point[1], pointA[0], pointA[1]);
260

    
261
                        double[] pointB = b.Relations[0].UID == line.UID ? b.Relations[0].Point : b.Relations[1].Point;
262
                        double distanceB = CalcPointToPointdDistance(point[0], point[1], pointB[0], pointB[1]);
263

    
264
                        // 내림차순
265
                        return distanceA.CompareTo(distanceB);
266
                    }
267
                    double CalcPointToPointdDistance(double x1, double y1, double x2, double y2)
268
                    {
269
                        return Math.Pow(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2), 0.5);
270
                    }
271
                }
272
            }
273
        }
274
        private void SetTopology()
275
        {
276
            #region 기본 topology 정리
277
            foreach (PSNItem PSNItem in PSNItems)
278
            {
279
                Topology topology = null;
280
                foreach (Group group in PSNItem.Groups)
281
                {
282
                    foreach (Item item in group.Items)
283
                    {
284
                        if (string.IsNullOrEmpty(item.TopologyData))
285
                            topology = null;
286
                        else
287
                        {
288
                            if (topology == null)
289
                            {
290
                                topology = new Topology()
291
                                {
292
                                    ID = item.TopologyData
293
                                };
294
                                Topologies.Add(topology);
295

    
296
                                if (!PSNItem.Topologies.Contains(topology))
297
                                    PSNItem.Topologies.Add(topology);
298
                            }
299
                            else
300
                            {
301
                                if (topology.ID != item.TopologyData)
302
                                {
303
                                    topology = new Topology()
304
                                    {
305
                                        ID = item.TopologyData
306
                                    };
307
                                    Topologies.Add(topology);
308

    
309
                                    if (!PSNItem.Topologies.Contains(topology))
310
                                        PSNItem.Topologies.Add(topology);
311
                                }
312
                            }
313

    
314
                            item.Topology = topology;
315
                            topology.Items.Add(item);
316
                        }
317
                    }
318
                }
319
            }
320
            #endregion
321

    
322
            #region Type
323
            DataTable nominalDiameterDT = DB.SelectNominalDiameter();
324

    
325
            List<string> ids = Topologies.Select(x => x.ID).Distinct().ToList();
326
            foreach (string id in ids)
327
            {
328
                List<Topology> topologies = Topologies.FindAll(x => x.ID == id);
329
                FindMainTopology(topologies);
330
                // Main
331
                List<Topology> mainTopologies = topologies.FindAll(x => x.Items.Find(y => y.SubItemType == SubItemType.Nozzle) != null);
332
                if (mainTopologies.Count != 0)
333
                {
334

    
335
                    foreach (Topology topology in mainTopologies)
336
                    {
337
                        topology.Type = "M";
338
                        topology.Index = mainTopologies.IndexOf(topology).ToString();
339
                    }
340
                }
341
                else
342
                {
343

    
344
                }
345
                // Branch
346
                List<Topology> branchToplogies = topologies.FindAll(x => string.IsNullOrEmpty(x.Type));
347
                foreach (Topology topology in branchToplogies)
348
                {
349
                    topology.Type = "B";
350
                    topology.Index = (branchToplogies.IndexOf(topology) + 1).ToString();
351
                }
352
            }
353
            #endregion
354
        }
355
        private List<Topology> FindMainTopology(List<Topology> data)
356
        {
357
            List<Topology> result = new List<Topology>();
358
            result.AddRange(data);
359
            //
360
            result  = data.FindAll(x => x.Items.Find(y => y.SubItemType == SubItemType.Nozzle) != null);
361

    
362

    
363
            return result;
364
        }
365

    
366
        private DataTable GetOPCInfo()
367
        {
368
            DataTable opc = DB.SelectOPCRelations();
369
            DataTable drawing = DB.SelectDrawings();
370

    
371
            DataTable dt = new DataTable();
372
            dt.Columns.Add("FromDrawing", typeof(string));
373
            dt.Columns.Add("FromDrawingUID", typeof(string));
374
            dt.Columns.Add("FromOPCUID", typeof(string));
375
            dt.Columns.Add("ToDrawing", typeof(string));
376
            dt.Columns.Add("ToDrawingUID", typeof(string));
377
            dt.Columns.Add("ToOPCUID", typeof(string));
378
            foreach (DataRow row in opc.Rows)
379
            {
380
                string fromDrawingUID = row["From_Drawings_UID"] == null ? string.Empty : row["From_Drawings_UID"].ToString();
381
                string fromOPCUID = row["From_OPC_UID"] == null ? string.Empty : row["From_OPC_UID"].ToString(); 
382
                string toDrawingUID = row["To_Drawings_UID"] == null ? string.Empty : row["To_Drawings_UID"].ToString(); 
383
                string toOPCUID = row["To_OPC_UID"] == null ? string.Empty : row["To_OPC_UID"].ToString();
384
                if (!string.IsNullOrEmpty(toOPCUID))
385
                {
386
                    DataRow[] fromRows = drawing.Select(string.Format("UID = '{0}'", fromDrawingUID));
387
                    DataRow[] toRows = drawing.Select(string.Format("UID = '{0}'", toDrawingUID));
388
                    if (fromRows.Length.Equals(1) && toRows.Length.Equals(1))
389
                    {
390
                        string fromDrawingName = Path.GetFileNameWithoutExtension(fromRows.First()["NAME"].ToString());
391
                        string toDrawingName = Path.GetFileNameWithoutExtension(toRows.First()["NAME"].ToString());
392

    
393
                        DataRow newRow = dt.NewRow();
394
                        newRow["FromDrawing"] = fromDrawingName;
395
                        newRow["FromDrawingUID"] = fromDrawingUID;
396
                        newRow["FromOPCUID"] = fromOPCUID;
397
                        newRow["ToDrawing"] = toDrawingName;
398
                        newRow["ToDrawingUID"] = toDrawingUID;
399
                        newRow["ToOPCUID"] = toOPCUID;
400

    
401
                        dt.Rows.Add(newRow);
402
                    }
403
                }
404
            }
405

    
406
            return dt;
407
        }
408
        private DataTable GetTopologyRule()
409
        {
410
            DataTable dt = DB.SelectTopologyRule();
411

    
412
            return dt;
413
        }
414
        private bool IsConnected(Item item1, Item item2)
415
        {
416
            if (item1.Relations.Find(x => x.UID.Equals(item2.UID)) != null &&
417
                item2.Relations.Find(x => x.UID.Equals(item1.UID)) != null)
418
                return true;
419
            else
420
                return false;
421
        }
422

    
423
        private void SaveNozzleAndEquipment()
424
        {
425
            List<Item> nozzles = new List<Item>();
426
            List<Equipment> equipments = new List<Equipment>();
427
            foreach (Document document in Documents)
428
            {
429
                nozzles.AddRange(document.Items.FindAll(x => x.SubItemType == SubItemType.Nozzle));
430
                equipments.AddRange(document.Equipments);
431
            }
432
                
433

    
434
            DataTable nozzleDT = new DataTable();
435
            nozzleDT.Columns.Add("OID", typeof(string));
436
            nozzleDT.Columns.Add("ITEMTAG", typeof(string));
437
            nozzleDT.Columns.Add("XCOORDS", typeof(string));
438
            nozzleDT.Columns.Add("YCOORDS", typeof(string));
439
            nozzleDT.Columns.Add("Equipment_OID", typeof(string));
440
            nozzleDT.Columns.Add("FLUID", typeof(string));
441
            nozzleDT.Columns.Add("NPD", typeof(string));
442
            nozzleDT.Columns.Add("ROTATION", typeof(string));
443
            nozzleDT.Columns.Add("FlowDirection", typeof(string));
444

    
445
            foreach (Item item in nozzles)
446
            {
447
                DataRow row = nozzleDT.NewRow();
448
                row["OID"] = item.UID;
449

    
450
                Relation relation = item.Relations.Find(x => equipments.Find(y => y.UID == x.UID) != null);
451
                if (relation != null)
452
                {
453
                    Equipment equipment = equipments.Find(x => x.UID == relation.UID);
454
                    equipment.Nozzles.Add(item);
455
                    row["ITEMTAG"] = string.Format("N-{0}", equipment.Nozzles.Count);
456
                    row["Equipment_OID"] = equipment.UID;
457
                }
458
                row["XCOORDS"] = item.POINT[0].ToString();
459
                row["YCOORDS"] = item.POINT[1].ToString();
460
                Attribute fluidAttr = item.LineNumber.Attributes.Find(x => x.Name == "FluidCode");
461
                row["FLUID"] = fluidAttr != null ? fluidAttr.Value : string.Empty;
462
                Attribute npdAttr = item.LineNumber.Attributes.Find(x => x.Name == "NominalDiameter");
463
                row["NPD"] = npdAttr != null ? npdAttr.Value : string.Empty;
464
                row["ROTATION"] = item.ANGLE;
465

    
466
                if (item.Topology.Items.First().Equals(item))
467
                    row["FlowDirection"] = "Outlet";
468
                else if (item.Topology.Items.Last().Equals(item))
469
                    row["FlowDirection"] = "Inlet";
470
                else
471
                    row["FlowDirection"] = string.Empty;
472

    
473
                nozzleDT.Rows.Add(row);
474
            }
475

    
476
            DataTable equipDT = new DataTable();
477
            equipDT.Columns.Add("OID", typeof(string));
478
            equipDT.Columns.Add("ITEMTAG", typeof(string));
479
            equipDT.Columns.Add("XCOORDS", typeof(string));
480
            equipDT.Columns.Add("YCOORDS", typeof(string));
481

    
482
            foreach (Equipment equipment in equipments)
483
            {
484
                DataRow row = equipDT.NewRow();
485
                row["OID"] = equipment.UID;
486
                row["ITEMTAG"] = null;
487

    
488
                List<double> xList = equipment.POINT.Select(x => x[0]).ToList();
489
                row["XCOORDS"] = xList.Sum() / (double)xList.Count;
490

    
491
                List<double> yList = equipment.POINT.Select(x => x[1]).ToList();
492
                row["YCOORDS"] = yList.Sum() / (double)yList.Count;
493

    
494
                equipDT.Rows.Add(row);
495
            }
496

    
497
            Equipment = equipDT;
498
            Nozzle = nozzleDT;
499
        }
500
        private void SavePSNData()
501
        {
502
            DataTable pathItemsDT = new DataTable();
503
            pathItemsDT.Columns.Add("OID", typeof(string));
504
            pathItemsDT.Columns.Add("SequenceData_OID", typeof(string));
505
            pathItemsDT.Columns.Add("TopologySet_OID", typeof(string));
506
            pathItemsDT.Columns.Add("BranchTopologySet_OID", typeof(string));
507
            pathItemsDT.Columns.Add("PipeLine_OID", typeof(string));
508
            pathItemsDT.Columns.Add("ITEMNAME", typeof(string));
509
            pathItemsDT.Columns.Add("ITEMTAG", typeof(string));
510
            pathItemsDT.Columns.Add("TYPE", typeof(string));
511
            pathItemsDT.Columns.Add("PIDNAME", typeof(string));
512
            pathItemsDT.Columns.Add("NPD", typeof(string));
513
            pathItemsDT.Columns.Add("PipeSystemNetwork_OID", typeof(string));
514
            pathItemsDT.Columns.Add("PipeRun_OID", typeof(string));
515
            pathItemsDT.Columns.Add("DrawingName", typeof(string));
516

    
517
            DataTable sequenceDataDT = new DataTable();
518
            sequenceDataDT.Columns.Add("OID", typeof(string));
519
            sequenceDataDT.Columns.Add("SERIALNUMBER", typeof(string));
520
            sequenceDataDT.Columns.Add("PathItem_OID", typeof(string));
521
            sequenceDataDT.Columns.Add("TopologySet_OID_Key", typeof(string));
522

    
523
            DataTable pipeSystemNetworkDT = new DataTable();
524
            pipeSystemNetworkDT.Columns.Add("OID", typeof(string));
525
            pipeSystemNetworkDT.Columns.Add("Type", typeof(string));
526
            pipeSystemNetworkDT.Columns.Add("OrderNumber", typeof(string));
527
            pipeSystemNetworkDT.Columns.Add("Pipeline_OID", typeof(string));
528
            pipeSystemNetworkDT.Columns.Add("FROM_DATA", typeof(string));
529
            pipeSystemNetworkDT.Columns.Add("TO_DATA", typeof(string));
530
            pipeSystemNetworkDT.Columns.Add("TopologySet_OID_Key", typeof(string));
531
            pipeSystemNetworkDT.Columns.Add("PSNRevisionNumber", typeof(string));
532
            pipeSystemNetworkDT.Columns.Add("PathOID", typeof(string));
533
            pipeSystemNetworkDT.Columns.Add("PBS", typeof(string));
534
            pipeSystemNetworkDT.Columns.Add("PIDDrawings", typeof(string));
535

    
536
            foreach (PSNItem PSNItem in PSNItems)
537
            {
538
                int index = 0;
539
                foreach (Group group in PSNItem.Groups)
540
                {
541
                    foreach (Item item in group.Items)
542
                    {
543
                        if (item.BranchItems.Count == 0)
544
                        {
545
                            CreatePathItemsDataRow(item.UID, item.Type);
546
                            CreateSequenceDataDataRow(item.UID);
547
                            index++;
548
                        }
549
                        else
550
                        {
551
                            CreatePathItemsDataRow(item.UID + "-L1", item.Type);
552
                            CreateSequenceDataDataRow(item.UID + "-L1");
553
                            index++;
554
                            for (int i = 0; i < item.BranchItems.Count; i++)
555
                            {
556
                                CreatePathItemsDataRow(string.Format(item.UID + "-B{0}", i + 1), "Branch", item.BranchItems[i].Topology.FullName);
557
                                CreateSequenceDataDataRow(string.Format(item.UID + "-B{0}", i + 1));
558
                                index++;
559

    
560
                                CreatePathItemsDataRow(string.Format(item.UID + "-L{0}", i + 2), item.Type);
561
                                CreateSequenceDataDataRow(string.Format(item.UID + "-L{0}", i + 2));
562
                                index++;
563
                            }
564
                        }
565

    
566
                        void CreatePathItemsDataRow(string itemOID, string itemType, string branchTopologyName = "")
567
                        {
568
                            DataRow newRow = pathItemsDT.NewRow();
569
                            newRow["OID"] = itemOID;
570

    
571
                            newRow["SequenceData_OID"] = string.Format(item.Topology.FullName + "-{0}", index);
572

    
573
                            newRow["TopologySet_OID"] = item.Topology.FullName;
574

    
575
                            newRow["BranchTopologySet_OID"] = branchTopologyName;
576
                            newRow["PipeLine_OID"] = null;
577
                            newRow["ITEMNAME"] = null;
578
                            newRow["ITEMTAG"] = GetItemTag();
579
                            newRow["TYPE"] = item.Name;
580
                            newRow["PIDNAME"] = group.Document.DrawingName;
581

    
582
                            // NPD
583
                            if (item.LineNumber != null)
584
                            {
585
                                Attribute attribute = item.LineNumber.Attributes.Find(x => x.Name == "NominalDiameter");
586
                                if (attribute != null)
587
                                    newRow["NPD"] = attribute.Value;
588
                            }
589
                            else
590
                                newRow["NPD"] = null;
591

    
592
                            newRow["PipeSystemNetwork_OID"] = string.Empty;//PSNItem.UID;
593
                            newRow["PipeRun_OID"] = item.LineNumber != null ? item.LineNumber.Name : string.Empty;
594
                            newRow["DrawingName"] = group.Document.DrawingName;
595

    
596
                            pathItemsDT.Rows.Add(newRow);
597
                        }
598
                        void CreateSequenceDataDataRow(string itemOID)
599
                        {
600
                            DataRow newRow = sequenceDataDT.NewRow();
601
                            newRow["OID"] = string.Format(item.Topology.FullName + "-{0}", index);
602
                            newRow["SERIALNUMBER"] = string.Format("{0}", index);
603
                            newRow["PathItem_OID"] = itemOID;
604
                            newRow["TopologySet_OID_Key"] = item.Topology.FullName;
605

    
606
                            sequenceDataDT.Rows.Add(newRow);
607
                        }
608

    
609

    
610
                        string GetItemTag()
611
                        {
612
                            string result = string.Empty;
613
                            if (item.ItemType == ItemType.Line)
614
                                result = item.LineNumber != null ? item.LineNumber.Name : string.Empty; ;
615

    
616
                            return result;
617
                        }
618
                    }
619
                }
620

    
621
                CreatePipeSystemNetworkDataRow();
622

    
623
                void CreatePipeSystemNetworkDataRow()
624
                {
625
                    DataRow newRow = pipeSystemNetworkDT.NewRow();
626
                    newRow["OID"] = PSNItem.UID;
627
                    newRow["Type"] = null;
628
                    newRow["OrderNumber"] = null;
629
                    newRow["Pipeline_OID"] = PSNItem.Groups.First().Items.First().TopologyData;
630
                    newRow["FROM_DATA"] = PSNItem.StartType.ToString();
631
                    newRow["TO_DATA"] = PSNItem.EndType.ToString();
632
                    newRow["TopologySet_OID_Key"] = PSNItem.Groups.First().Items.First().Topology.FullName;
633
                    newRow["PSNRevisionNumber"] = null;
634
                    newRow["PathOID"] = null;
635
                    newRow["PBS"] = null;
636

    
637

    
638
                    List<string> drawingNames = new List<string>();
639
                    foreach (Group group in PSNItem.Groups)
640
                    {
641
                        if (!drawingNames.Contains(group.Document.DrawingName))
642
                        {
643

    
644
                            if (drawingNames.Count == 0)
645
                                newRow["PIDDrawings"] = group.Document.DrawingName;
646
                            else
647
                                newRow["PIDDrawings"] = newRow["PIDDrawings"] + ", " + group.Document.DrawingName;
648
                            drawingNames.Add(group.Document.DrawingName);
649
                        }
650
                    }
651

    
652

    
653
                    pipeSystemNetworkDT.Rows.Add(newRow);
654
                }
655
            }
656

    
657
            PathItems = pathItemsDT;
658
            SequenceData = sequenceDataDT;
659
            PipeSystemNetwork = pipeSystemNetworkDT;
660
        }
661
    }
662

    
663
    public class PSNItem
664
    {
665
        public PSNItem()
666
        {
667
            Groups = new List<Group>();
668
            Topologies = new List<Topology>();
669
        }
670
        public string UID { get; set; }
671
        public List<Group> Groups { get; set; }
672
        public List<Topology> Topologies { get; set; }
673
        public PSNType StartType { get; set; }
674
        public PSNType EndType { get; set; }
675
    }
676
}
클립보드 이미지 추가 (최대 크기: 500 MB)