프로젝트

일반

사용자정보

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

hytos / DTI_PID / ID2PSN / PSN.cs @ 63ff8e26

이력 | 보기 | 이력해설 | 다운로드 (168 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 a2973aa3 LJIYEON
            // Update Keyword
232
            UpdateKeywordForPSN();
233
            // Vent/Drain PSN 데이터 제거
234
            DeleteVentDrain();
235 7881ec8f gaqhf
            // Topology의 subtype을 update(bypass, Header, 등등) 
236
            UpdateSubType();
237
            // Update Error
238 4e2e0aa1 LJIYEON
            UpdateErrorForPSN();
239
            // Insert Tee
240
            InsertTeePSN();
241 5e4c2ad1 LJIYEON
            // 확도 계산
242 811d7949 LJIYEON
            UpdateAccuracy();
243 7106e181 LJIYEON
            // ValveGrouping
244 811d7949 LJIYEON
            UpdateValveGrouping();
245 63ff8e26 이지연
246
            DataTable dtPathItems = PathItems.Clone();
247
            DataTable dtPipeSystemNetwork = PipeSystemNetwork.DefaultView.ToTable(true, new string[] { "OID" });
248
249
            foreach (DataRow drpipe in dtPipeSystemNetwork.Rows)
250
            {
251
                DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", drpipe["OID"].ToString()));
252
                DataTable dtSequenceItems = SequenceData.Clone();
253
                foreach (DataRow drpath in pathItemRows)
254
                {
255
                    DataRow sequenceRows = SequenceData.Select(string.Format("PathItem_OID = '{0}'", drpath.Field<string>("OID"))).First();
256
                    
257
                    DataRow newRow = dtSequenceItems.NewRow();
258
                    foreach (DataColumn column in SequenceData.Columns)
259
                        if (dtSequenceItems.Columns[column.ColumnName] != null)
260
                            newRow[column.ColumnName] = sequenceRows[column.ColumnName];
261
262
                    dtSequenceItems.Rows.Add(newRow);
263
                }
264
265
                foreach (DataRow sqrow in dtSequenceItems.Select().OrderBy(x => Convert.ToInt32(x.Field<string>("SERIALNUMBER"))))
266
                {
267
                    DataRow newRow = dtPathItems.NewRow();
268
                    DataRow row = PathItems.Select(string.Format("OID = '{0}'", sqrow["PathItem_OID"])).First();
269
                    
270
                    foreach (DataColumn column in PathItems.Columns)
271
                        if (dtPathItems.Columns[column.ColumnName] != null)
272
                            newRow[column.ColumnName] = row[column.ColumnName];
273
274
                    dtPathItems.Rows.Add(newRow);
275
                }
276
277
                //foreach (DataRow sqrow in datasqDT.Select().OrderBy(x => Convert.ToInt32(x.Field<string>("SERIALNUMBER"))))
278
                //{
279
                //    DataRow newRow = gridDT.NewRow();
280
281
                    //    DataRow row = dataDT.Select(string.Format("OID = '{0}'", sqrow["PathItem_OID"])).First();
282
283
                    //    foreach (DataColumn column in dataDT.Columns)
284
                    //        if (gridDT.Columns[column.ColumnName] != null)
285
                    //            newRow[column.ColumnName] = row[column.ColumnName];
286
287
                    //    gridDT.Rows.Add(newRow);
288
                    //}
289
290
            }
291
292
            PathItems.Clear();
293
            PathItems = dtPathItems.Copy();
294 bf9e8432 이지연
            // AirFinCooler 
295
            UpdateAirFinCooler();
296 63ff8e26 이지연
297 811d7949 LJIYEON
        }
298
299 bf9e8432 이지연
        private void UpdateAirFinCooler()
300
        {
301
            try
302
            {
303 0eefef3d 이지연
                int afcTagNum = 0;
304 d1afd412 이지연
                int pumpTagNum = 0;
305 bf9e8432 이지연
                #region EquipmentAirFinCooler Info
306
                EquipmentAirFinCoolerInfo EquipmentAirFinCooler = new EquipmentAirFinCoolerInfo();
307
                DataTable dtEquipmentAirFinCooler = DB.SelectAirFinCoolerSetting();
308
                foreach (DataRow row in dtEquipmentAirFinCooler.Rows)
309
                {
310
                    EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Add(new EquipmentAirFinCoolerItem()
311
                    {
312
                        Type = row["Type"].ToString(),
313
                        Name = row["Name"].ToString()
314
                    });
315
                }
316
                #endregion
317
318 0eefef3d 이지연
                DataRow[] airFinCoolerRows = PipeSystemNetwork.Select("AFC = 'P1'");
319 d1afd412 이지연
                DataRow[] pumpRows = PipeSystemNetwork.Select("PUMP = 'PUMP'");
320
                // 1, 2번
321
                foreach (DataRow dataRow in pumpRows) 
322
                {
323
                    pumpTagNum++;
324
325
                    DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"].ToString()));
326
327 63ff8e26 이지연
                    string eqTag = string.Empty;
328 d1afd412 이지연
                    string EGFlowDirection = string.Empty;
329 63ff8e26 이지연
                    PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString());
330
                    if (PSNItem.Groups.First().Items.First().Equipment != null)
331
                    {
332
                        if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && PSNItem.Groups.First().Items.First().Equipment.Name.Contains(x.Name)).Count() > 0)
333
                        {
334
                            eqTag = PSNItem.Groups.First().Items.First().Equipment.ItemTag;
335
                            EGFlowDirection = "O";
336
                        }                        
337
                    } 
338
                    else if(PSNItem.Groups.Last().Items.Last().Equipment != null)
339
                    {
340
                        if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && PSNItem.Groups.Last().Items.Last().Equipment.Name.Contains(x.Name)).Count() > 0)
341
                        {
342
                            eqTag = PSNItem.Groups.Last().Items.Last().Equipment.ItemTag;
343
                            EGFlowDirection = "I";
344
                        }
345
                    }
346 d1afd412 이지연
347 63ff8e26 이지연
                    if(!string.IsNullOrEmpty(eqTag))
348 d1afd412 이지연
                    {
349 63ff8e26 이지연
                        foreach (DataRow dr in pathItemRows)
350
                        {
351
                            dr["EqpGroupTag"] = eqTag;
352
                            dr["EGFlowDirection"] = EGFlowDirection;
353
                        }
354 d1afd412 이지연
                    }
355
                }
356
357
                // 3, 4번
358
                foreach (DataRow dataRow in pumpRows) 
359
                {
360
361
                    DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"].ToString()));
362 63ff8e26 이지연
                    PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString());
363 d1afd412 이지연
                    string EGFlowDirection = string.Empty;
364 63ff8e26 이지연
365
                    if (PSNItem.Groups.First().Items.First().Equipment != null)
366
                    {
367
                        if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && PSNItem.Groups.First().Items.First().Equipment.Name.Contains(x.Name)).Count() > 0)
368
                        {
369
                            EGFlowDirection = "O";
370
                        }
371
                    }
372
                    else if (PSNItem.Groups.Last().Items.Last().Equipment != null)
373
                    {
374
                        if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && PSNItem.Groups.Last().Items.Last().Equipment.Name.Contains(x.Name)).Count() > 0)
375
                        {
376
                            EGFlowDirection = "I";
377
                        }
378
                    }
379
380 d1afd412 이지연
381
                    List<string> lstViewPipeSystemNetwork_OID = new List<string>();
382
383
                    foreach (DataRow dr in pathItemRows)
384
                    {
385
                        if(dr.Field<string>("ViewPipeSystemNetwork_OID") != dataRow["OID"].ToString())
386
                        {
387
                            string viewEGFlowDirection = string.Empty;
388
                            if (PipeSystemNetwork.Select(string.Format("OID = '{0}'", dr.Field<string>("ViewPipeSystemNetwork_OID"))).Count() > 0)
389
                            {
390 63ff8e26 이지연
                                PSNItem viewPSNItem = PSNItems.Find(x => x.PSN_OID() == dr.Field<string>("ViewPipeSystemNetwork_OID"));                               
391
392
                                if (viewPSNItem.Groups.First().Items.First().Equipment != null)
393
                                {
394
                                    if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && viewPSNItem.Groups.First().Items.First().Equipment.Name.Contains(x.Name)).Count() > 0)
395
                                    {
396
                                        viewEGFlowDirection = "O";
397
                                    }
398
                                }
399
                                else if (viewPSNItem.Groups.Last().Items.Last().Equipment != null)
400
                                {
401
                                    if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && viewPSNItem.Groups.Last().Items.Last().Equipment.Name.Contains(x.Name)).Count() > 0)
402
                                    {
403
                                        viewEGFlowDirection = "I";
404
                                    }
405
                                }
406 d1afd412 이지연
407
                                if (EGFlowDirection.Equals(viewEGFlowDirection) && !lstViewPipeSystemNetwork_OID.Contains(dr.Field<string>("ViewPipeSystemNetwork_OID")))
408
                                    lstViewPipeSystemNetwork_OID.Add(dr.Field<string>("ViewPipeSystemNetwork_OID"));
409
                            }
410
                            else
411
                            {
412
                            }
413
                        }
414
                    }
415
416
                    string selectViewOID = string.Empty;
417
418
                    if (EGFlowDirection == "O") //From 이면 시작점에서 제일 먼 값
419
                    {
420
                        foreach (string viewOID in lstViewPipeSystemNetwork_OID)
421
                        {
422
                            if (PipeSystemNetwork.Select(string.Format("PUMP = 'PUMP' AND OID = '{0}'", viewOID)).Count() > 0)
423
                            {                                
424
                                selectViewOID = pathItemRows.Where(x => x.Field<string>("ViewPipeSystemNetwork_OID") == viewOID).Last().Field<string>("OID");
425
                            }
426
                        }
427
                    }
428
                    else if (EGFlowDirection == "I") //To 이면 시작점에서 제일 가까운 값
429
                    {
430
                        foreach (string viewOID in lstViewPipeSystemNetwork_OID)
431
                        {
432
                            if (PipeSystemNetwork.Select(string.Format("PUMP = 'PUMP' AND OID = '{0}'", viewOID)).Count() > 0)
433
                            {
434
                                selectViewOID = pathItemRows.Where(x => x.Field<string>("ViewPipeSystemNetwork_OID") == viewOID).Last().Field<string>("OID");
435
                                break;
436
                            }
437
                        }
438
                    }
439
440
                    if (!string.IsNullOrEmpty(selectViewOID)) //selectViewOID 가 있으면
441
                    {              
442
                        string EqpGroupTag = string.Empty;                       
443
444 63ff8e26 이지연
                        if((EGFlowDirection == "O" && lstViewPipeSystemNetwork_OID.Contains(pathItemRows.Last().Field<string>("ViewPipeSystemNetwork_OID"))) ||
445
                            (EGFlowDirection == "I" && lstViewPipeSystemNetwork_OID.Contains(pathItemRows.First().Field<string>("ViewPipeSystemNetwork_OID"))))
446
                        { 
447 d1afd412 이지연
                            DataRow[] viewpathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", pathItemRows.First().Field<string>("ViewPipeSystemNetwork_OID")));
448
449
                            foreach (DataRow row in viewpathItemRows)
450
                            {
451
                                if (!string.IsNullOrEmpty(row.Field<string>("EqpGroupTag")))
452
                                {
453
                                    EqpGroupTag = row.Field<string>("EqpGroupTag");
454
                                    break;
455
                                }
456
                            }
457
458
                            foreach (DataRow dr in pathItemRows)
459
                            {
460
                                dr["EqpGroupTag"] = EqpGroupTag;
461
                            }
462
463
                        }
464
                        else
465
                        {
466
                            bool bCheck = false;
467 add4c093 이지연
                            if (EGFlowDirection == "I") //To 일때
468 d1afd412 이지연
                            {
469
                                foreach (DataRow dr in pathItemRows)
470
                                {
471 63ff8e26 이지연
                                    if (selectViewOID == dr["OID"].ToString())
472
                                    {
473
                                        dr["EGTConnectedPoint"] = "1";
474
                                        bCheck = true;
475
                                    }
476
477 d1afd412 이지연
                                    if (!bCheck)
478
                                    {
479 add4c093 이지연
                                        dr["EqpGroupTag"] = string.Empty;
480
                                        dr["MainLineTag"] = string.Empty;
481 63ff8e26 이지연
                                        dr["EGTConnectedPoint"] = "0";
482
                                        dr["EGFlowDirection"] = string.Empty;
483 d1afd412 이지연
                                    }
484
                                    else
485
                                    {
486 add4c093 이지연
                                        dr["MainLineTag"] = "M";
487 d1afd412 이지연
                                    }
488 63ff8e26 이지연
                                    
489 d1afd412 이지연
                                }
490
491
                            }
492 add4c093 이지연
                            else if (EGFlowDirection == "O") //From 일 때
493 d1afd412 이지연
                            {
494
                                foreach (DataRow dr in pathItemRows)
495
                                {
496 add4c093 이지연
                                    if (bCheck)
497 d1afd412 이지연
                                    {
498 63ff8e26 이지연
                                        
499 d1afd412 이지연
                                        dr["EqpGroupTag"] = string.Empty;
500
                                        dr["MainLineTag"] = string.Empty;
501
                                        dr["EGTConnectedPoint"] = "0";
502 63ff8e26 이지연
                                        dr["EGFlowDirection"] = string.Empty;
503 d1afd412 이지연
                                    }
504
                                    else
505
                                    {
506
                                        dr["MainLineTag"] = "M";
507
                                    }
508
509
                                    if (selectViewOID == dr["OID"].ToString())
510
                                    {
511
                                        dr["EGTConnectedPoint"] = "1";
512
                                        bCheck = true;
513
                                    }
514
                                }
515
                            }
516
                        }
517
                    }
518
                    else
519
                    {
520
                        foreach (DataRow dr in pathItemRows)
521
                        {
522
                            dr["EqpGroupTag"] = string.Empty;
523
                            dr["EGFlowDirection"] = string.Empty;
524
                        }
525
                    }
526
                }
527
                                
528
                // 5번
529
                foreach (DataRow dataRow in pumpRows)
530
                {
531
                    DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"].ToString()));
532
533
                    bool bCheck = false;
534
                    string EqpGroupTag = string.Empty;
535
536 63ff8e26 이지연
                    string EGFlowDirection = string.Empty;                   
537 d1afd412 이지연
538 63ff8e26 이지연
                    PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow.Field<string>("OID"));
539 d1afd412 이지연
540 63ff8e26 이지연
                    if (PSNItem.Groups.First().Items.First().Equipment != null)
541
                    {
542
                        if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && PSNItem.Groups.First().Items.First().Equipment.Name.Contains(x.Name)).Count() > 0)
543
                        {
544
                            EGFlowDirection = "O";
545
                        }
546
                    }
547
                    else if (PSNItem.Groups.Last().Items.Last().Equipment != null)
548
                    {
549
                        if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && PSNItem.Groups.Last().Items.Last().Equipment.Name.Contains(x.Name)).Count() > 0)
550
                        {
551
                            EGFlowDirection = "I";
552
                        }
553
                    }
554
555
                    List<string> lstViewPipeSystemNetwork_OID = new List<string>();
556
                    List<string> lstEqTagRows = new List<string>();
557 d1afd412 이지연
                    if (EGFlowDirection.Equals("I"))
558
                    {
559
                        foreach (DataRow dr in pathItemRows)
560 63ff8e26 이지연
                        {                            
561
                            if (!string.IsNullOrEmpty(dr.Field<string>("MainLineTag")) && dr.Field<string>("MainLineTag").Equals("M") && !string.IsNullOrEmpty(dr.Field<string>("EqpGroupTag")))
562
                            {
563 d1afd412 이지연
                                bCheck = true;
564
                                EqpGroupTag = dr.Field<string>("EqpGroupTag");
565 63ff8e26 이지연
                                if(!lstEqTagRows.Contains(EqpGroupTag))
566
                                    lstEqTagRows.Add(EqpGroupTag);
567 d1afd412 이지연
568 63ff8e26 이지연
                                if(dataRow["OID"].ToString() != dr.Field<string>("ViewPipeSystemNetwork_OID"))
569
                                {
570
                                    PSNItem viewPSNItem = PSNItems.Find(x => x.PSN_OID() == dr.Field<string>("ViewPipeSystemNetwork_OID"));
571
                                    if (viewPSNItem.Groups.Last().Items.Last().Equipment == null)
572
                                        continue;
573 d1afd412 이지연
574 63ff8e26 이지연
                                    if (!lstEqTagRows.Contains(viewPSNItem.Groups.Last().Items.Last().Equipment.ItemTag))
575
                                        lstEqTagRows.Add(viewPSNItem.Groups.Last().Items.Last().Equipment.ItemTag);
576
                                }
577
                                
578 d1afd412 이지연
                            }
579 63ff8e26 이지연
580 d1afd412 이지연
                        }
581 63ff8e26 이지연
                        if(bCheck)
582 d1afd412 이지연
                        {
583 63ff8e26 이지연
                            foreach (DataRow row in pumpRows)
584 d1afd412 이지연
                            {
585 63ff8e26 이지연
                                if (row.Field<string>("OID").Equals(dataRow["OID"].ToString()))
586
                                    continue;
587
588
                                PSNItem viewPSNItem = PSNItems.Find(x => x.PSN_OID() == row["OID"].ToString());
589
590
                                if (viewPSNItem.Groups.First().Items.First().Equipment == null)
591 d1afd412 이지연
                                    continue;
592 63ff8e26 이지연
                                
593
                                if (lstEqTagRows.Contains(viewPSNItem.Groups.First().Items.First().Equipment.ItemTag) && !lstViewPipeSystemNetwork_OID.Contains(row.Field<string>("OID")))
594
                                    lstViewPipeSystemNetwork_OID.Add(row.Field<string>("OID"));
595
                            }
596 d1afd412 이지연
597 63ff8e26 이지연
                                
598 d1afd412 이지연
599 63ff8e26 이지연
                            if (lstViewPipeSystemNetwork_OID.Count() > 0)
600
                            {
601
                                foreach (string viewPipesystem in lstViewPipeSystemNetwork_OID)
602 d1afd412 이지연
                                {
603
                                    DataRow[] viewpathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", viewPipesystem));
604
                                    foreach (DataRow viewdr in viewpathItemRows)
605
                                    {
606
                                        if (!string.IsNullOrEmpty(viewdr["EqpGroupTag"].ToString()))
607
                                            viewdr["EqpGroupTag"] = EqpGroupTag;
608
                                    }
609
                                }
610
                            }
611 63ff8e26 이지연
                        }                        
612
                    }                   
613 d1afd412 이지연
                }
614
                
615 0eefef3d 이지연
                foreach (DataRow dataRow in airFinCoolerRows)
616
                {
617
                    afcTagNum++;
618 5b0805a5 이지연
                    string EGFlowDirection = string.Empty;
619 63ff8e26 이지연
620
                    PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString());
621
                    if (PSNItem.Groups.First().Items.First().Equipment != null)
622
                    {
623
                        if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && PSNItem.Groups.First().Items.First().Equipment.Name.Contains(x.Name)).Count() > 0)
624
                        {
625
                            EGFlowDirection = "O";
626
                        }
627
                    }
628
                    else if (PSNItem.Groups.Last().Items.Last().Equipment != null)
629
                    {
630
                        if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && PSNItem.Groups.Last().Items.Last().Equipment.Name.Contains(x.Name)).Count() > 0)
631
                        {
632
                            EGFlowDirection = "I";
633
                        }
634
                    }
635 5b0805a5 이지연
636 0eefef3d 이지연
                    DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"].ToString()));
637
                    List<string> lstViewPipeSystemNetwork_OID = pathItemRows.Select(x => x.Field<string>("ViewPipeSystemNetwork_OID")).Distinct().ToList();
638
                    //ViewPipeSystemNetwork_OID
639
                    string MainLineTag = "";
640
                    if (dataRow["Type"].ToString() == "E2E")
641
                    {
642
                        MainLineTag = "M";
643
                         dataRow["AFC"] = "P3";
644
                    }
645
                    else if (dataRow["Type"].ToString() == "E2B" || dataRow["Type"].ToString() == "B2E")
646
                    {
647
                        int bCount = 0;
648
                        foreach (string viewOID in lstViewPipeSystemNetwork_OID)
649
                        {
650
                            if (viewOID == dataRow["OID"].ToString())
651
                                continue;
652
653
                            DataRow dr = PipeSystemNetwork.Select(string.Format("OID = '{0}'", viewOID)).First();
654
                            if (dr.Field<string>("AFC") != "P1")
655
                            {
656
                                bCount++;
657
                                string[] arr = dr.Field<string>("AFC").Split('_');
658
                                if (arr.Length == 1)
659
                                    dr["AFC"] = arr[0] + "_1";
660
                                else
661
                                {
662
                                    dr["AFC"] = arr[0] + "_" + Convert.ToInt32(arr[1]) + 1;
663
                                    afcTagNum++;
664
                                    DataRow[] viewpathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", viewOID));
665
                                    foreach (DataRow viewdr in viewpathItemRows)
666
                                    {
667 5b0805a5 이지연
                                        viewdr["EqpGroupTag"] = "AFC" + string.Format("-{0}", string.Format("{0:D3}", afcTagNum));  //ATG Sequence No Rule 여쭤봐야함.
668 0eefef3d 이지연
                                        viewdr["MainLineTag"] = "M";
669
                                    }
670
                                }
671
672
                            }
673
                        }
674
                        
675
                        if(bCount == 1)
676
                        {
677
                            MainLineTag = "M";
678
                           // dataRow["AFC"] = "P3";
679
                        }
680
                            
681
                    }
682
683
                    foreach (DataRow dr in pathItemRows)
684
                    {
685 5b0805a5 이지연
                        dr["EqpGroupTag"] = "AFC" + string.Format("-{0}", string.Format("{0:D3}", afcTagNum));  //ATG Sequence No Rule 여쭤봐야함.
686
                        dr["MainLineTag"] = MainLineTag; 
687
                        dr["EGFlowDirection"] = EGFlowDirection; 
688 0eefef3d 이지연
                    }
689
                }
690
                
691
                foreach (DataRow dataRow in airFinCoolerRows)
692 bf9e8432 이지연
                {
693 0eefef3d 이지연
                    DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}' AND MainLineTag = ''", dataRow["OID"].ToString()));
694
                    //ML이 공란인 PSN - P1이 있다면 해당 Pathitem에 P3인 psn이 있는지 확인 : 해당 값은 전부 돌린후 확인 가능하기 때문에 다시 조회
695
                    if (pathItemRows.Count() > 0)
696 bf9e8432 이지연
                    {
697 0eefef3d 이지연
                        List<string> lstViewPipeSystemNetwork_OID = pathItemRows.Select(x => x.Field<string>("ViewPipeSystemNetwork_OID")).Distinct().ToList();
698
                        List<string> lstpsn = new List<string>();
699
                        string EqpGroupTag = string.Empty;
700
                        foreach (string viewOID in lstViewPipeSystemNetwork_OID)
701
                        {
702
                            if (dataRow["OID"].ToString() == viewOID)
703
                            {
704
                                //lstViewPipeSystemNetwork_OID.Remove(viewOID);
705
                                continue;
706
                            }
707
                            DataRow viewPSN = null;
708
                            if (PipeSystemNetwork.Select(string.Format("OID = '{0}' AND AFC = 'P3'", viewOID)).Count() > 0)
709
                                viewPSN = PipeSystemNetwork.Select(string.Format("OID = '{0}' AND AFC = 'P3'", viewOID)).First();
710
                            
711
                            if (viewPSN != null)
712
                            {
713
                                EqpGroupTag = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", viewOID)).First().Field<string>("EqpGroupTag");
714
                                foreach (DataRow dr in pathItemRows)
715
                                {
716
                                    dr["EqpGroupTag"] = EqpGroupTag;
717
718
                                    if (!string.IsNullOrEmpty(dr.Field<string>("ViewPipeSystemNetwork_OID")) && !lstpsn.Contains("ViewPipeSystemNetwork_OID"))
719
                                        lstpsn.Add(dr.Field<string>("ViewPipeSystemNetwork_OID"));
720
                                }
721
                            }
722
                            
723
                        }
724
725
                        while(lstpsn.Count() != 0)
726 bf9e8432 이지연
                        {
727 0eefef3d 이지연
                            foreach(string psn in lstpsn)
728
                            {
729
                                DataRow[] rule4pathItems = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", psn));
730
                                foreach (DataRow dr in rule4pathItems)
731
                                {
732
                                    dr["EqpGroupTag"] = EqpGroupTag;
733
734
                                    if (!string.IsNullOrEmpty(dr.Field<string>("ViewPipeSystemNetwork_OID")) && !lstpsn.Contains("ViewPipeSystemNetwork_OID"))
735
                                        lstpsn.Add(dr.Field<string>("ViewPipeSystemNetwork_OID"));
736
                                }
737
738
                                lstpsn.Remove(psn);
739
                            }                        
740
741
                        }
742
                    }
743
                    
744
                }
745
746
                //DataRow[]  = PipeSystemNetwork.Select("AFC = 'P1'");
747
                foreach(DataRow dr in PipeSystemNetwork.Rows)
748
                {
749
                    DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}' AND MainLineTag = 'M'", dr["OID"].ToString()));
750
                    if(pathItemRows.Count() > 0)
751
                    {
752
                        if(dr["Type"].ToString() == "HD2")
753
                        {
754
                            List<string> lstViewPipeSystemNetwork_OID = pathItemRows.Select(x => x.Field<string>("ViewPipeSystemNetwork_OID")).Distinct().ToList();
755
                            foreach(string viewpsn in lstViewPipeSystemNetwork_OID)
756
                            {                              
757
                                if (PipeSystemNetwork.Select(string.Format("OID = '{0}' AND AFC = 'P2'", viewpsn)).Count() > 0)
758
                                {
759
                                    foreach(DataRow dataRow in pathItemRows.Where(x => x.Field<string>("ViewPipeSystemNetwork_OID") == viewpsn))
760
                                    {
761
                                        dataRow["EGTConnectedPoint"] = "1";
762
                                    }
763
                                }
764
                            }
765
                        }
766
                        else if(dr["Type"].ToString() == "E2B" || dr["Type"].ToString() == "B2E" || dr["Type"].ToString() == "E2E")
767
                        {
768
                            List<string> lstViewPipeSystemNetwork_OID = pathItemRows.Select(x => x.Field<string>("ViewPipeSystemNetwork_OID")).Distinct().ToList();
769
                            string lastP1 = string.Empty;
770
                            foreach (string viewpsn in lstViewPipeSystemNetwork_OID)
771
                            {
772
                                if (viewpsn == dr["OID"].ToString())
773
                                    continue;
774
775
                                if (PipeSystemNetwork.Select(string.Format("OID = '{0}' AND AFC = 'P1'", viewpsn)).Length == 0)
776
                                    continue;
777
778
                                DataRow rows = PipeSystemNetwork.Select(string.Format("OID = '{0}' AND AFC = 'P1'", viewpsn)).First();
779
                                if(rows != null)
780
                                {
781
                                    lastP1 = viewpsn;
782
                                }
783
                            }
784
785
                            if(!string.IsNullOrEmpty(lastP1))
786
                            {
787
                                bool bCheck = false;
788
                                foreach (DataRow dataRow in pathItemRows)
789
                                {
790
                                    if (bCheck)
791
                                        dataRow["EqpGroupTag"] = string.Empty;
792
793
                                    if (dataRow.Field<string>("ViewPipeSystemNetwork_OID").Equals(lastP1))
794
                                    {
795
                                        bCheck = true;
796
                                        dataRow["EGTConnectedPoint"] = 1;
797
                                    }                       
798
                                }
799
                            }
800
                        }
801 bf9e8432 이지연
                    }
802
                }
803 d1afd412 이지연
804
                //psn data 정리
805
                foreach(DataRow pipesystem in PipeSystemNetwork.Rows)
806
                {
807
                    DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", pipesystem["OID"].ToString()));
808
                    string EGTag = string.Empty;
809
                    string HasMLTags = "False";
810
811
                    foreach (DataRow dataRow in pathItemRows)
812
                    {
813
                        if (string.IsNullOrEmpty(EGTag) && !string.IsNullOrEmpty(dataRow.Field<string>("EqpGroupTag")))
814
                            EGTag = dataRow.Field<string>("EqpGroupTag");
815
816
                        if (HasMLTags.Equals("False") && !string.IsNullOrEmpty(dataRow.Field<string>("MainLineTag")) && dataRow.Field<string>("MainLineTag").Equals("M"))
817
                            HasMLTags = "True";
818
819
                        if (!string.IsNullOrEmpty(EGTag) && HasMLTags == "True")
820
                            break;
821
                    }
822
823
                    pipesystem["EGTag"] = EGTag;
824
                    pipesystem["HasMLTags"] = HasMLTags;
825
                }
826 bf9e8432 이지연
            }
827
            catch (Exception ex)
828
            {
829
                MessageBox.Show(ex.Message, "ID2 ", MessageBoxButtons.OK, MessageBoxIcon.Error);
830
            }
831
            //}
832
        }
833 9ba9dcd2 LJIYEON
834 811d7949 LJIYEON
        private void UpdateValveGrouping()
835
        {
836
            try
837
            {
838
                #region ValveGrouping Info
839
                ValveGroupInfo ValveGrouping = new ValveGroupInfo();
840
                DataTable dtValveGroupung = DB.SelectValveGroupItemsSetting();
841
                foreach (DataRow row in dtValveGroupung.Rows)
842
                {
843
                    ValveGrouping.ValveGroupItems.Add(new ValveGroupItem()
844
                    {
845
                        OID = row["OID"].ToString(),
846
                        GroupType = row["GroupType"].ToString(),
847
                        TagIdentifier = row["TagIdentifier"].ToString(),
848
                        AttributeName = row["AttributeName"].ToString(),
849
                        SppidSymbolName = row["SppidSymbolName"].ToString()
850
                    });
851
                }
852
                #endregion
853
854 7106e181 LJIYEON
855 811d7949 LJIYEON
                int vgTagNum = 1;
856
                DataRow[] tagpathItemRows = PathItems.Select(string.Format("GROUPTAG Like '%\\%'"));
857
                foreach (DataRow drPathitem in tagpathItemRows)
858
                {
859
                    string[] valvetag = drPathitem["GROUPTAG"].ToString().Split(new string[] { "\\" }, StringSplitOptions.None);
860
                    DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", drPathitem["PipeSystemNetwork_OID"].ToString()));
861
                    ValveGroupItem valveitem = ValveGrouping.ValveGroupItems.Where(x => x.SppidSymbolName == valvetag[0]).FirstOrDefault();
862 54b6df95 LJIYEON
                    if (valveitem == null || valveitem.GroupType == "Scope Break")
863 0a2fbe44 LJIYEON
                        continue;
864 811d7949 LJIYEON
                    Dictionary<int, List<DataRow>> keyValuePairs = new Dictionary<int, List<DataRow>>();
865
                    List<Item> valveGroupingItem = new List<Item>();
866
                    int bCnt = 0;
867
868 f2a63376 이지연
                    //bool bCheck = false;
869 811d7949 LJIYEON
                    List<DataRow> lstitem = new List<DataRow>();
870
                    foreach (DataRow dr in pathItemRows)
871
                    {
872 0a2fbe44 LJIYEON
                        //if (!string.IsNullOrEmpty(dr["GROUPTAG"].ToString()))
873
                        //    break;
874 9ba9dcd2 LJIYEON
875 f2a63376 이지연
                       if (!string.IsNullOrEmpty(dr["BranchTopologySet_OID"].ToString()))
876 811d7949 LJIYEON
                        {
877
                            DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", dr["BranchTopologySet_OID"].ToString()));
878 54b6df95 LJIYEON
                            if (dr["GROUPTAG"].ToString() == "Scope Break")
879
                            {
880
                                dr["GROUPTAG"] = string.Empty;
881
                                break;
882
                            }
883
884 f2a63376 이지연
                            if (rows.First()["SubType"].ToString() != "Bypass" && rows.First()["SubType"].ToString() != "Vent_Drain")
885 811d7949 LJIYEON
                            {
886 f2a63376 이지연
                               // bCheck = true;
887 54b6df95 LJIYEON
                                lstitem.Add(dr);
888 811d7949 LJIYEON
                                keyValuePairs.Add(bCnt, lstitem.ToList());
889
                                bCnt++;
890
                                lstitem.Clear();
891
                            }
892
                            else
893
                                lstitem.Add(dr);
894
                        }
895
                        else
896
                            lstitem.Add(dr);
897
                    }
898
899 54b6df95 LJIYEON
                    if (lstitem.Count > 0)
900 811d7949 LJIYEON
                    {
901
                        keyValuePairs.Add(bCnt, lstitem);
902 f2a63376 이지연
                        //bCnt++;
903 811d7949 LJIYEON
                    }
904 9ba9dcd2 LJIYEON
905
                    if (keyValuePairs.Count() == 0)
906
                        continue;
907
908 811d7949 LJIYEON
                    string VGTag = string.Empty;
909
                    if (valveitem.AttributeName == "NoSelection")
910
                    {
911
                        VGTag = valveitem.TagIdentifier + string.Format("-{0}", string.Format("{0:D5}", vgTagNum));
912
                        vgTagNum++;
913
                    }
914
                    else
915
                    {
916
                        VGTag = valveitem.TagIdentifier + "-" + valvetag[1];
917
                    }
918
919
                    foreach (KeyValuePair<int, List<DataRow>> keyValuePair in keyValuePairs)
920
                    {
921
                        if (keyValuePair.Value.Where(x => x.Field<string>("OID") == drPathitem.Field<string>("OID")).Count() > 0)
922
                        {
923
                            foreach (DataRow dr in keyValuePair.Value)
924
                            {
925
                                dr["GROUPTAG"] = VGTag;
926
                            }
927
                        }
928
                    }
929 08b33e44 gaqhf
930
                    if(valveitem.GroupType.Contains("PSV"))
931
                    {
932
                        DataRow[] psnRows = PipeSystemNetwork.Select(string.Format("OID = '{0}'", drPathitem["PipeSystemNetwork_OID"].ToString()));
933
                        foreach (DataRow row in psnRows)
934
                            row["Pocket"] = "Yes";
935 f2a63376 이지연
                    }                    
936 811d7949 LJIYEON
                }
937 bf9e8432 이지연
938
939 811d7949 LJIYEON
            }
940 7106e181 LJIYEON
            catch (Exception ex)
941 811d7949 LJIYEON
            {
942
                MessageBox.Show(ex.Message, "ID2 ", MessageBoxButtons.OK, MessageBoxIcon.Error);
943
            }
944
            //}
945 6b9e7a56 gaqhf
        }
946 7881ec8f gaqhf
947 6b9e7a56 gaqhf
        private void SetTopologyData()
948
        {
949 710a49f1 gaqhf
            // 13번 excel
950
            foreach (Group group in groups)
951
            {
952
                LineNumber prevLineNumber = null;
953
                for (int i = 0; i < group.Items.Count; i++)
954
                {
955
                    Item item = group.Items[i];
956
                    LineNumber lineNumber = item.Document.LineNumbers.Find(x => x.UID == item.Owner);
957
                    if (lineNumber == null)
958
                    {
959
                        if (prevLineNumber != null)
960
                        {
961
                            if (!prevLineNumber.IsCopy)
962
                            {
963
                                prevLineNumber = prevLineNumber.Copy();
964 48870200 LJIYEON
                                item.Document.LineNumbers.Add(prevLineNumber);
965
                                item.MissingLineNumber1 = true;
966 710a49f1 gaqhf
                            }
967
                            item.Owner = prevLineNumber.UID;
968
                        }
969
                    }
970
                    else
971
                        prevLineNumber = lineNumber;
972
                }
973
974
                prevLineNumber = null;
975
                for (int i = group.Items.Count - 1; i > -1; i--)
976
                {
977
                    Item item = group.Items[i];
978
                    LineNumber lineNumber = item.Document.LineNumbers.Find(x => x.UID == item.Owner);
979
                    if (lineNumber == null)
980
                    {
981
                        if (prevLineNumber != null)
982
                        {
983
                            if (!prevLineNumber.IsCopy)
984
                            {
985
                                prevLineNumber = prevLineNumber.Copy();
986
                                item.Document.LineNumbers.Add(prevLineNumber);
987 48870200 LJIYEON
                                item.MissingLineNumber1 = true;
988 710a49f1 gaqhf
                            }
989
990
                            item.Owner = prevLineNumber.UID;
991
                        }
992
                    }
993
                    else
994
                        prevLineNumber = lineNumber;
995
                }
996
997
                if (prevLineNumber == null)
998
                {
999
                    List<LineNumber> lineNumbers = group.Document.LineNumbers.FindAll(x => !x.IsCopy);
1000
                    Random random = new Random();
1001
                    int index = random.Next(lineNumbers.Count - 1);
1002 a2973aa3 LJIYEON
1003 710a49f1 gaqhf
                    // Copy
1004
                    LineNumber cLineNumber = lineNumbers[index].Copy();
1005
                    group.Document.LineNumbers.Add(cLineNumber);
1006 7106e181 LJIYEON
1007 710a49f1 gaqhf
                    foreach (Item item in group.Items)
1008 a2973aa3 LJIYEON
                    {
1009 710a49f1 gaqhf
                        item.Owner = cLineNumber.UID;
1010 48870200 LJIYEON
                        item.MissingLineNumber2 = true;
1011 7106e181 LJIYEON
                    }
1012 710a49f1 gaqhf
                }
1013
            }
1014
1015 6b9e7a56 gaqhf
            foreach (Document document in Documents)
1016
            {
1017
                foreach (Item item in document.Items)
1018
                {
1019
                    item.TopologyData = string.Empty;
1020 8f24b438 gaqhf
                    item.PSNPipeLineID = string.Empty;
1021 33cee849 LJIYEON
                    List<string> pipeLineID = new List<string>();
1022 6b9e7a56 gaqhf
                    LineNumber lineNumber = document.LineNumbers.Find(x => x.UID == item.Owner);
1023
                    if (lineNumber != null)
1024
                    {
1025
                        item.LineNumber = lineNumber;
1026
1027
                        foreach (DataRow row in topologyRuleDT.Rows)
1028
                        {
1029
                            string uid = row["UID"].ToString();
1030 33cee849 LJIYEON
                            //if (uid == "-")
1031
                            //    pipeLineID.Add(item.TopologyData);//item.TopologyData += "-"; 
1032
                            if (uid != "-")
1033 6b9e7a56 gaqhf
                            {
1034 7106e181 LJIYEON
                                Attribute itemAttr = item.Attributes.Find(x => x.Name == uid);
1035 f25b787a gaqhf
1036
                                Attribute attribute = lineNumber.Attributes.Find(x => x.Name == uid);
1037 33cee849 LJIYEON
                                if (attribute != null && !string.IsNullOrEmpty(attribute.Value))
1038
                                    pipeLineID.Add(attribute.Value);//item.TopologyData += attribute.Value;
1039 6b9e7a56 gaqhf
                            }
1040
                        }
1041 8f24b438 gaqhf
1042 7106e181 LJIYEON
                        if (topologyRuleDT.Select(string.Format("UID = '{0}'", "InsulationPurpose")) == null)
1043 3210f690 LJIYEON
                        {
1044
                            Attribute insulAttr = item.LineNumber.Attributes.Find(x => x.Name == "InsulationPurpose");
1045
                            if (insulAttr != null && !string.IsNullOrEmpty(insulAttr.Value))
1046
                                pipeLineID.Add(insulAttr.Value); //item.PSNPipeLineID = item.TopologyData + "-" + insulAttr.Value;
1047
                                                                 //else
1048
                                                                 //    item.PSNPipeLineID = item.TopologyData;
1049
                        }
1050
1051 33cee849 LJIYEON
                        item.PSNPipeLineID = string.Join("-", pipeLineID);
1052
                        item.TopologyData = string.Join("-", pipeLineID);
1053 7106e181 LJIYEON
1054 6b9e7a56 gaqhf
                    }
1055 0f07fa34 gaqhf
                    else
1056
                    {
1057
                        item.TopologyData = "Empty LineNumber";
1058
                        item.LineNumber = new LineNumber();
1059
                    }
1060 6b9e7a56 gaqhf
                }
1061
            }
1062
1063 0f07fa34 gaqhf
            int emptyIndex = 1;
1064
            foreach (Group group in groups)
1065
            {
1066
                List<Item> groupItems = group.Items.FindAll(x => x.TopologyData == "Empty LineNumber");
1067
                if (groupItems.Count > 0)
1068
                {
1069
                    foreach (var item in groupItems)
1070
                        item.TopologyData += string.Format("-{0}", emptyIndex);
1071
                    emptyIndex++;
1072
                }
1073
            }
1074 6b9e7a56 gaqhf
1075
        }
1076 7106e181 LJIYEON
1077 6b9e7a56 gaqhf
        private void ConnectByOPC()
1078
        {
1079 21edb7bc LJIYEON
            try
1080 6b9e7a56 gaqhf
            {
1081 21edb7bc LJIYEON
                foreach (Group group in groups.FindAll(x => x.Items.Last().SubItemType == SubItemType.OPC))
1082 6b9e7a56 gaqhf
                {
1083 21edb7bc LJIYEON
                    Item opcItem = group.Items.Last();
1084
                    DataRow[] fromRows = opcDT.Select(string.Format("FromOPCUID = '{0}'", opcItem.UID));
1085
                    if (fromRows.Length.Equals(1))
1086
                    {
1087
                        DataRow opcRow = fromRows.First();
1088
                        string toDrawing = opcRow["ToDrawing"].ToString();
1089
                        string toOPCUID = opcRow["ToOPCUID"].ToString();
1090
1091
                        Document toDocument = Documents.Find(x => x.DrawingName == toDrawing);
1092
                        if (toDocument != null)
1093 710a49f1 gaqhf
                        {
1094 21edb7bc LJIYEON
                            Group toGroup = toDocument.Groups.Find(x => x.Items.Find(y => y.UID == toOPCUID) != null);
1095
                            DataRow[] toRows = opcDT.Select(string.Format("ToOPCUID = '{0}'", toGroup.Items.First().UID));
1096
                            //1대1 매칭이 아닐때 걸림 (2개 이상일 때) 2021.11.07 
1097
                            if (toRows.Length > 1)
1098
                            {
1099
                                //throw new Exception("OPC error(multi connect)");
1100
                                MessageBox.Show("OPC error(multi connect)", "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
1101
                                return;
1102
                            }
1103
                            group.EndGroup = toGroup;
1104
                            toGroup.StartGroup = group;
1105 710a49f1 gaqhf
                        }
1106 0fe04b33 LJIYEON
                    }
1107 6b9e7a56 gaqhf
                }
1108
            }
1109 21edb7bc LJIYEON
            catch (Exception ex)
1110
            {
1111
                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1112
                //MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
1113
            }
1114 6b9e7a56 gaqhf
        }
1115 5e4c2ad1 LJIYEON
1116 6b9e7a56 gaqhf
        private void SetPSNItem()
1117
        {
1118 7106e181 LJIYEON
            Dictionary<Group, string> groupDic = new Dictionary<Group, string>();
1119 6b9e7a56 gaqhf
            foreach (Group group in groups)
1120
                groupDic.Add(group, Guid.NewGuid().ToString());
1121
1122
            foreach (Group group in groups)
1123
            {
1124
                string groupKey = groupDic[group];
1125
                if (group.StartGroup != null)
1126
                {
1127
                    string otherKey = groupDic[group.StartGroup];
1128
                    ChangeGroupID(otherKey, groupKey);
1129
                }
1130
            }
1131
1132
            // PSN 정리
1133
            foreach (var item in groupDic)
1134
            {
1135
                Group group = item.Key;
1136
                string uid = item.Value;
1137
                PSNItem PSNItem = PSNItems.Find(x => x.UID == uid);
1138
                if (PSNItem == null)
1139
                {
1140 8f24b438 gaqhf
                    PSNItem = new PSNItem(PSNItems.Count, Revision) { UID = uid };
1141 6b9e7a56 gaqhf
                    PSNItems.Add(PSNItem);
1142
                }
1143
                PSNItem.Groups.Add(group);
1144 36a45f13 gaqhf
                foreach (Item groupItem in group.Items)
1145
                    groupItem.PSNItem = PSNItem;
1146 6b9e7a56 gaqhf
            }
1147
1148
            // Sort PSN
1149
            foreach (PSNItem PSNItem in PSNItems)
1150
            {
1151
                List<Group> _groups = new List<Group>();
1152
1153
                Stack<Group> stacks = new Stack<Group>();
1154
                stacks.Push(PSNItem.Groups.First());
1155
                while (stacks.Count > 0)
1156
                {
1157
                    Group stack = stacks.Pop();
1158
                    if (_groups.Contains(stack))
1159
                        continue;
1160
1161
                    if (_groups.Count == 0)
1162
                        _groups.Add(stack);
1163
                    else
1164
                    {
1165
                        if (stack.StartGroup != null && _groups.Contains(stack.StartGroup))
1166
                        {
1167
                            int index = _groups.IndexOf(stack.StartGroup);
1168
                            _groups.Insert(index + 1, stack);
1169
                        }
1170
                        else if (stack.EndGroup != null && _groups.Contains(stack.EndGroup))
1171
                        {
1172
                            int index = _groups.IndexOf(stack.EndGroup);
1173
                            _groups.Insert(index, stack);
1174
                        }
1175
                    }
1176
1177
                    if (stack.StartGroup != null)
1178
                        stacks.Push(stack.StartGroup);
1179
                    if (stack.EndGroup != null)
1180
                        stacks.Push(stack.EndGroup);
1181
                }
1182
1183
                PSNItem.Groups.Clear();
1184
                PSNItem.Groups.AddRange(_groups);
1185
            }
1186
1187
            void ChangeGroupID(string from, string to)
1188
            {
1189
                if (from.Equals(to))
1190
                    return;
1191
1192
                List<Group> changeItems = new List<Group>();
1193
                foreach (var _item in groupDic)
1194
                    if (_item.Value.Equals(from))
1195
                        changeItems.Add(_item.Key);
1196
                foreach (var _item in changeItems)
1197
                    groupDic[_item] = to;
1198
            }
1199
        }
1200 5e4c2ad1 LJIYEON
1201 6b9e7a56 gaqhf
        private void SetPSNType()
1202
        {
1203
            foreach (PSNItem PSNItem in PSNItems)
1204
            {
1205
                Group firstGroup = PSNItem.Groups.First();
1206
                Group lastGroup = PSNItem.Groups.Last();
1207
1208
                Item firstItem = firstGroup.Items.First();
1209
                Item lastItem = lastGroup.Items.Last();
1210
1211
                PSNItem.StartType = GetPSNType(firstItem, true);
1212
                PSNItem.EndType = GetPSNType(lastItem, false);
1213
            }
1214
1215
            PSNType GetPSNType(Item item, bool bFirst = true)
1216
            {
1217
                PSNType type = PSNType.None;
1218
1219
                if (item.ItemType == ItemType.Line)
1220
                {
1221
                    Group group = groups.Find(x => x.Items.Contains(item));
1222
                    if (bFirst && item.Relations[0].Item != null && !group.Items.Contains(item.Relations[0].Item))
1223
                    {
1224
                        Item connItem = item.Relations[0].Item;
1225
                        if (connItem.ItemType == ItemType.Line && !IsConnected(item, connItem))
1226
                            type = PSNType.Branch;
1227
                        else if (connItem.ItemType == ItemType.Symbol)
1228
                            type = PSNType.Symbol;
1229
                    }
1230
                    else if (!bFirst && item.Relations[1].Item != null && !group.Items.Contains(item.Relations[1].Item))
1231
                    {
1232
                        Item connItem = item.Relations[1].Item;
1233
                        if (connItem.ItemType == ItemType.Line && !IsConnected(item, connItem))
1234
                            type = PSNType.Branch;
1235
                        else if (connItem.ItemType == ItemType.Symbol)
1236
                            type = PSNType.Symbol;
1237
                    }
1238
                }
1239
                else if (item.ItemType == ItemType.Symbol)
1240
                {
1241
                    if (item.SubItemType == SubItemType.Nozzle)
1242
                        type = PSNType.Equipment;
1243
                    else if (item.SubItemType == SubItemType.Header)
1244
                        type = PSNType.Header;
1245
                    else if (item.SubItemType == SubItemType.OPC)
1246
                        type = PSNType.OPC;
1247
                }
1248
1249
                return type;
1250
            }
1251
        }
1252 5e4c2ad1 LJIYEON
1253 6b9e7a56 gaqhf
        private void SetBranchInfo()
1254
        {
1255
            foreach (Document document in Documents)
1256
            {
1257
                List<Item> lines = document.Items.FindAll(x => x.ItemType == ItemType.Line).ToList();
1258
                foreach (Item line in lines)
1259
                {
1260
                    double[] point = line.Relations[0].Point;
1261
                    List<Item> connLines = lines.FindAll(x => x.Relations.Find(y => y.UID == line.UID) != null && line.Relations.Find(y => y.UID == x.UID) == null);
1262
                    connLines.Sort(SortBranchLine);
1263
                    line.BranchItems.AddRange(connLines);
1264
1265
                    int SortBranchLine(Item a, Item b)
1266
                    {
1267
                        double[] pointA = a.Relations[0].UID == line.UID ? a.Relations[0].Point : a.Relations[1].Point;
1268
                        double distanceA = CalcPointToPointdDistance(point[0], point[1], pointA[0], pointA[1]);
1269
1270
                        double[] pointB = b.Relations[0].UID == line.UID ? b.Relations[0].Point : b.Relations[1].Point;
1271
                        double distanceB = CalcPointToPointdDistance(point[0], point[1], pointB[0], pointB[1]);
1272
1273
                        // 내림차순
1274
                        return distanceA.CompareTo(distanceB);
1275
                    }
1276
                    double CalcPointToPointdDistance(double x1, double y1, double x2, double y2)
1277
                    {
1278
                        return Math.Pow(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2), 0.5);
1279
                    }
1280
                }
1281
            }
1282
        }
1283 5e4c2ad1 LJIYEON
1284 6b9e7a56 gaqhf
        private void SetTopology()
1285
        {
1286 27d06aa8 LJIYEON
            try
1287 6b9e7a56 gaqhf
            {
1288 27d06aa8 LJIYEON
                #region 기본 topology 정리
1289
                foreach (PSNItem PSNItem in PSNItems)
1290 6b9e7a56 gaqhf
                {
1291 27d06aa8 LJIYEON
                    Topology topology = null;
1292
                    foreach (Group group in PSNItem.Groups)
1293 6b9e7a56 gaqhf
                    {
1294 27d06aa8 LJIYEON
                        foreach (Item item in group.Items)
1295 6b9e7a56 gaqhf
                        {
1296 27d06aa8 LJIYEON
                            if (string.IsNullOrEmpty(item.TopologyData))
1297
                                topology = null;
1298 6b9e7a56 gaqhf
                            else
1299
                            {
1300 27d06aa8 LJIYEON
                                if (topology == null)
1301 6b9e7a56 gaqhf
                                {
1302
                                    topology = new Topology()
1303
                                    {
1304
                                        ID = item.TopologyData
1305
                                    };
1306
                                    Topologies.Add(topology);
1307
1308
                                    if (!PSNItem.Topologies.Contains(topology))
1309
                                        PSNItem.Topologies.Add(topology);
1310
                                }
1311 27d06aa8 LJIYEON
                                else
1312
                                {
1313
                                    if (topology.ID != item.TopologyData)
1314
                                    {
1315
                                        topology = new Topology()
1316
                                        {
1317
                                            ID = item.TopologyData
1318
                                        };
1319
                                        Topologies.Add(topology);
1320
1321
                                        if (!PSNItem.Topologies.Contains(topology))
1322
                                            PSNItem.Topologies.Add(topology);
1323
                                    }
1324
                                }
1325 6b9e7a56 gaqhf
1326 27d06aa8 LJIYEON
                                item.Topology = topology;
1327
                                topology.Items.Add(item);
1328
                            }
1329 6b9e7a56 gaqhf
                        }
1330
                    }
1331
                }
1332 27d06aa8 LJIYEON
                #endregion
1333 6b9e7a56 gaqhf
1334 27d06aa8 LJIYEON
                #region Type
1335
                List<string> ids = Topologies.Select(x => x.ID).Distinct().ToList();
1336
                foreach (string id in ids)
1337
                {
1338
                    try
1339
                    {
1340 678760c6 gaqhf
1341 6b9e7a56 gaqhf
1342 27d06aa8 LJIYEON
                        List<Topology> topologies = Topologies.FindAll(x => x.ID == id);
1343
1344
                        // Main
1345
                        List<Topology> mainTopologies = FindMainTopology(topologies);
1346
                        foreach (Topology topology in mainTopologies)
1347
                            topology.Type = "M";
1348
1349
                        // Branch
1350
                        List<Topology> branchToplogies = topologies.FindAll(x => string.IsNullOrEmpty(x.Type));
1351
                        foreach (Topology topology in branchToplogies)
1352
                            topology.Type = "B";
1353
                    }
1354
                    catch (Exception ex)
1355
                    {
1356
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1357
                        MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
1358
                    }
1359
                }
1360
                #endregion
1361
            }
1362
            catch (Exception ex)
1363
            {
1364
                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1365
                MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
1366 6b9e7a56 gaqhf
            }
1367 27d06aa8 LJIYEON
1368 6b9e7a56 gaqhf
        }
1369 5e4c2ad1 LJIYEON
1370 7881ec8f gaqhf
        private void SetTopologyIndex()
1371
        {
1372
            List<string> ids = Topologies.Select(x => x.ID).Distinct().ToList();
1373
            foreach (string id in ids)
1374
            {
1375
                List<Topology> topologies = Topologies.FindAll(x => x.ID == id);
1376
1377
                // Main
1378
                List<Topology> mainTopologies = topologies.FindAll(x => x.Type == "M");
1379
                foreach (Topology topology in mainTopologies)
1380
                    topology.Index = mainTopologies.IndexOf(topology).ToString();
1381
1382
                // Branch
1383
                List<Topology> branchToplogies = topologies.FindAll(x => x.Type == "B");
1384
                foreach (Topology topology in branchToplogies)
1385
                    topology.Index = (branchToplogies.IndexOf(topology) + 1).ToString();
1386
            }
1387
        }
1388 5e4c2ad1 LJIYEON
1389 7881ec8f gaqhf
        private void SetPSNBypass()
1390
        {
1391
            foreach (PSNItem PSNItem in PSNItems)
1392
                PSNItem.IsBypass = IsBypass(PSNItem);
1393
        }
1394 5e4c2ad1 LJIYEON
1395 6b9e7a56 gaqhf
        private List<Topology> FindMainTopology(List<Topology> data)
1396
        {
1397 678760c6 gaqhf
            DataTable nominalDiameterDT = DB.SelectNominalDiameter();
1398
            DataTable PMCDT = DB.SelectPSNPIPINGMATLCLASS();
1399 a36541fb LJIYEON
            //2021.11.17 안쓰네 JY
1400
            //DataTable fluidCodeDT = DB.SelectPSNFluidCode(); 
1401 678760c6 gaqhf
1402
            List<Topology> main = new List<Topology>();
1403
            main.AddRange(data);
1404 6b9e7a56 gaqhf
            //
1405 678760c6 gaqhf
            main = GetNozzleTopology(data);
1406
            if (main.Count == 1)
1407
                return main;
1408
            else
1409
            {
1410
                if (main.Count > 0)
1411
                    main = GetPMCTopology(main);
1412
                else
1413
                    main = GetPMCTopology(data);
1414
1415
                if (main.Count == 1)
1416
                    return main;
1417
                else
1418
                {
1419
                    if (main.Count > 0)
1420
                        main = GetDiaTopology(main);
1421
                    else
1422
                        main = GetDiaTopology(data);
1423
1424
1425
                    if (main.Count == 1)
1426
                        return main;
1427
                    else
1428
                    {
1429
                        if (main.Count > 0)
1430
                            main = GetItemTopology(main);
1431
                        else
1432
                            main = GetItemTopology(data);
1433
                    }
1434
                }
1435
            }
1436
1437
            List<Topology> GetNozzleTopology(List<Topology> topologies)
1438
            {
1439
                return topologies.FindAll(x => x.Items.Find(y => y.SubItemType == SubItemType.Nozzle) != null);
1440
            }
1441 6b9e7a56 gaqhf
1442 678760c6 gaqhf
            List<Topology> GetPMCTopology(List<Topology> topologies)
1443
            {
1444
                List<Topology> result = new List<Topology>();
1445
                foreach (DataRow row in PMCDT.Rows)
1446
                {
1447
                    string value = row["CODE"].ToString();
1448
                    foreach (Topology topology in topologies)
1449
                    {
1450
                        foreach (Item item in topology.Items)
1451
                        {
1452
                            if (item.LineNumber == null)
1453
                                continue;
1454 0f07fa34 gaqhf
                            Attribute attribute = item.LineNumber.Attributes.Find(x => x.Name == "PipingMaterialsClass");
1455
                            if (attribute != null && value == attribute.Value)
1456 678760c6 gaqhf
                            {
1457
                                result.Add(topology);
1458
                                break;
1459
                            }
1460
                        }
1461
                    }
1462
1463
                    if (result.Count > 0)
1464
                        break;
1465
                }
1466
1467
                return result;
1468
            }
1469
1470
            List<Topology> GetDiaTopology(List<Topology> topologies)
1471
            {
1472
                List<Topology> result = new List<Topology>();
1473
                foreach (DataRow row in nominalDiameterDT.Rows)
1474
                {
1475
                    string inchValue = row["InchStr"].ToString();
1476
                    string metricValue = row["MetricStr"].ToString();
1477
                    foreach (Topology topology in topologies)
1478
                    {
1479
                        foreach (Item item in topology.Items)
1480
                        {
1481
                            if (item.LineNumber == null)
1482
                                continue;
1483 0f07fa34 gaqhf
                            Attribute attribute = item.LineNumber.Attributes.Find(x => x.Name == "NominalDiameter");
1484
                            if (attribute != null && (inchValue == attribute.Value || metricValue == attribute.Value))
1485 678760c6 gaqhf
                            {
1486
                                result.Add(topology);
1487
                                break;
1488
                            }
1489
                        }
1490
                    }
1491
1492
                    if (result.Count > 0)
1493
                        break;
1494
                }
1495
1496
                return result;
1497
            }
1498
1499
            List<Topology> GetItemTopology(List<Topology> topologies)
1500
            {
1501
                return new List<Topology>() { topologies.OrderByDescending(x => x.Items.Count).ToList().First() };
1502
            }
1503 6b9e7a56 gaqhf
1504 678760c6 gaqhf
            return main;
1505 6b9e7a56 gaqhf
        }
1506
1507
        private DataTable GetOPCInfo()
1508
        {
1509
            DataTable opc = DB.SelectOPCRelations();
1510 ec1cc293 LJIYEON
            DataTable drawing = DB.AllDrawings();
1511 6b9e7a56 gaqhf
1512
            DataTable dt = new DataTable();
1513
            dt.Columns.Add("FromDrawing", typeof(string));
1514
            dt.Columns.Add("FromDrawingUID", typeof(string));
1515
            dt.Columns.Add("FromOPCUID", typeof(string));
1516
            dt.Columns.Add("ToDrawing", typeof(string));
1517
            dt.Columns.Add("ToDrawingUID", typeof(string));
1518
            dt.Columns.Add("ToOPCUID", typeof(string));
1519
            foreach (DataRow row in opc.Rows)
1520
            {
1521
                string fromDrawingUID = row["From_Drawings_UID"] == null ? string.Empty : row["From_Drawings_UID"].ToString();
1522 7106e181 LJIYEON
                string fromOPCUID = row["From_OPC_UID"] == null ? string.Empty : row["From_OPC_UID"].ToString();
1523
                string toDrawingUID = row["To_Drawings_UID"] == null ? string.Empty : row["To_Drawings_UID"].ToString();
1524 6b9e7a56 gaqhf
                string toOPCUID = row["To_OPC_UID"] == null ? string.Empty : row["To_OPC_UID"].ToString();
1525
                if (!string.IsNullOrEmpty(toOPCUID))
1526
                {
1527
                    DataRow[] fromRows = drawing.Select(string.Format("UID = '{0}'", fromDrawingUID));
1528
                    DataRow[] toRows = drawing.Select(string.Format("UID = '{0}'", toDrawingUID));
1529
                    if (fromRows.Length.Equals(1) && toRows.Length.Equals(1))
1530
                    {
1531
                        string fromDrawingName = Path.GetFileNameWithoutExtension(fromRows.First()["NAME"].ToString());
1532
                        string toDrawingName = Path.GetFileNameWithoutExtension(toRows.First()["NAME"].ToString());
1533
1534
                        DataRow newRow = dt.NewRow();
1535
                        newRow["FromDrawing"] = fromDrawingName;
1536
                        newRow["FromDrawingUID"] = fromDrawingUID;
1537
                        newRow["FromOPCUID"] = fromOPCUID;
1538
                        newRow["ToDrawing"] = toDrawingName;
1539
                        newRow["ToDrawingUID"] = toDrawingUID;
1540
                        newRow["ToOPCUID"] = toOPCUID;
1541
1542
                        dt.Rows.Add(newRow);
1543
                    }
1544
                }
1545
            }
1546
1547
            return dt;
1548
        }
1549 5e4c2ad1 LJIYEON
1550 6b9e7a56 gaqhf
        private DataTable GetTopologyRule()
1551
        {
1552
            DataTable dt = DB.SelectTopologyRule();
1553
1554
            return dt;
1555
        }
1556 5e4c2ad1 LJIYEON
1557 6b9e7a56 gaqhf
        private bool IsConnected(Item item1, Item item2)
1558
        {
1559
            if (item1.Relations.Find(x => x.UID.Equals(item2.UID)) != null &&
1560
                item2.Relations.Find(x => x.UID.Equals(item1.UID)) != null)
1561
                return true;
1562
            else
1563
                return false;
1564
        }
1565
1566
        private void SaveNozzleAndEquipment()
1567
        {
1568
            List<Item> nozzles = new List<Item>();
1569
            List<Equipment> equipments = new List<Equipment>();
1570
            foreach (Document document in Documents)
1571
            {
1572
                nozzles.AddRange(document.Items.FindAll(x => x.SubItemType == SubItemType.Nozzle));
1573
                equipments.AddRange(document.Equipments);
1574
            }
1575 7106e181 LJIYEON
1576 6b9e7a56 gaqhf
1577
            DataTable nozzleDT = new DataTable();
1578
            nozzleDT.Columns.Add("OID", typeof(string));
1579
            nozzleDT.Columns.Add("ITEMTAG", typeof(string));
1580
            nozzleDT.Columns.Add("XCOORDS", typeof(string));
1581
            nozzleDT.Columns.Add("YCOORDS", typeof(string));
1582
            nozzleDT.Columns.Add("Equipment_OID", typeof(string));
1583
            nozzleDT.Columns.Add("FLUID", typeof(string));
1584
            nozzleDT.Columns.Add("NPD", typeof(string));
1585 33cee849 LJIYEON
            nozzleDT.Columns.Add("PMC", typeof(string));
1586 6b9e7a56 gaqhf
            nozzleDT.Columns.Add("ROTATION", typeof(string));
1587
            nozzleDT.Columns.Add("FlowDirection", typeof(string));
1588
1589
            foreach (Item item in nozzles)
1590
            {
1591
                DataRow row = nozzleDT.NewRow();
1592
                row["OID"] = item.UID;
1593
1594
                Relation relation = item.Relations.Find(x => equipments.Find(y => y.UID == x.UID) != null);
1595
                if (relation != null)
1596
                {
1597
                    Equipment equipment = equipments.Find(x => x.UID == relation.UID);
1598
                    equipment.Nozzles.Add(item);
1599 a36541fb LJIYEON
                    row["ITEMTAG"] = string.Format("N{0}", string.Format("{0:D3}", equipment.Nozzles.Count + 100));
1600 7106e181 LJIYEON
                    row["Equipment_OID"] = equipment.UID;
1601 4c76a67a gaqhf
                    item.Equipment = equipment;
1602 6b9e7a56 gaqhf
                }
1603 8f24b438 gaqhf
                row["XCOORDS"] = (item.POINT[0] / DrawingWidth).ToString();
1604
                row["YCOORDS"] = (item.POINT[1] / DrawingHeight).ToString();
1605 6b9e7a56 gaqhf
                Attribute fluidAttr = item.LineNumber.Attributes.Find(x => x.Name == "FluidCode");
1606
                row["FLUID"] = fluidAttr != null ? fluidAttr.Value : string.Empty;
1607
                Attribute npdAttr = item.LineNumber.Attributes.Find(x => x.Name == "NominalDiameter");
1608
                row["NPD"] = npdAttr != null ? npdAttr.Value : string.Empty;
1609 33cee849 LJIYEON
                Attribute pmcAttr = item.LineNumber.Attributes.Find(x => x.Name == "PipingMaterialsClass");
1610
                row["PMC"] = pmcAttr != null ? pmcAttr.Value : string.Empty;
1611 f25b787a gaqhf
1612
                double angle = Math.PI * 2 - Convert.ToDouble(item.ANGLE);
1613
                if (angle >= Math.PI * 2)
1614
                    angle = angle - Math.PI * 2;
1615
                row["ROTATION"] = angle.ToString();
1616 6b9e7a56 gaqhf
1617
                if (item.Topology.Items.First().Equals(item))
1618
                    row["FlowDirection"] = "Outlet";
1619
                else if (item.Topology.Items.Last().Equals(item))
1620
                    row["FlowDirection"] = "Inlet";
1621
                else
1622
                    row["FlowDirection"] = string.Empty;
1623
1624
                nozzleDT.Rows.Add(row);
1625
            }
1626
1627
            DataTable equipDT = new DataTable();
1628
            equipDT.Columns.Add("OID", typeof(string));
1629
            equipDT.Columns.Add("ITEMTAG", typeof(string));
1630
            equipDT.Columns.Add("XCOORDS", typeof(string));
1631
            equipDT.Columns.Add("YCOORDS", typeof(string));
1632
1633
            foreach (Equipment equipment in equipments)
1634
            {
1635
                DataRow row = equipDT.NewRow();
1636
                row["OID"] = equipment.UID;
1637 c6503eaa gaqhf
                if (!string.IsNullOrEmpty(EquipTagNoAttributeName))
1638
                {
1639
                    Attribute attribute = equipment.Attributes.Find(x => x.Name == EquipTagNoAttributeName);
1640
                    if (attribute != null)
1641
                        equipment.ItemTag = attribute.Value;
1642
                }
1643
                else
1644
                    equipment.ItemTag = equipment.Name;
1645 6b9e7a56 gaqhf
1646 c6503eaa gaqhf
                row["ITEMTAG"] = equipment.ItemTag;
1647 6b9e7a56 gaqhf
                List<double> xList = equipment.POINT.Select(x => x[0]).ToList();
1648 8f24b438 gaqhf
                row["XCOORDS"] = (xList.Sum() / (double)xList.Count) / DrawingWidth;
1649 6b9e7a56 gaqhf
1650
                List<double> yList = equipment.POINT.Select(x => x[1]).ToList();
1651 8f24b438 gaqhf
                row["YCOORDS"] = (yList.Sum() / (double)yList.Count) / DrawingHeight;
1652 6b9e7a56 gaqhf
1653
                equipDT.Rows.Add(row);
1654
            }
1655
1656
            Equipment = equipDT;
1657
            Nozzle = nozzleDT;
1658
        }
1659 5e4c2ad1 LJIYEON
1660 6b9e7a56 gaqhf
        private void SavePSNData()
1661
        {
1662 2c46461b LJIYEON
            try
1663 36a45f13 gaqhf
            {
1664 2c46461b LJIYEON
                DataTable pathItemsDT = new DataTable();
1665
                pathItemsDT.Columns.Add("OID", typeof(string));
1666
                pathItemsDT.Columns.Add("SequenceData_OID", typeof(string));
1667
                pathItemsDT.Columns.Add("TopologySet_OID", typeof(string));
1668
                pathItemsDT.Columns.Add("BranchTopologySet_OID", typeof(string));
1669
                pathItemsDT.Columns.Add("PipeLine_OID", typeof(string));
1670
                pathItemsDT.Columns.Add("ITEMNAME", typeof(string));
1671
                pathItemsDT.Columns.Add("ITEMTAG", typeof(string));
1672 7106e181 LJIYEON
                pathItemsDT.Columns.Add("DESCRIPTION", typeof(string));
1673 2c46461b LJIYEON
                pathItemsDT.Columns.Add("Class", typeof(string));
1674
                pathItemsDT.Columns.Add("SubClass", typeof(string));
1675
                pathItemsDT.Columns.Add("TYPE", typeof(string));
1676
                pathItemsDT.Columns.Add("PIDNAME", typeof(string));
1677 a36541fb LJIYEON
                pathItemsDT.Columns.Add("Equipment_OID", typeof(string));
1678 2c46461b LJIYEON
                pathItemsDT.Columns.Add("NPD", typeof(string));
1679 811d7949 LJIYEON
                pathItemsDT.Columns.Add("GROUPTAG", typeof(string));
1680 2c46461b LJIYEON
                pathItemsDT.Columns.Add("PipeSystemNetwork_OID", typeof(string));
1681
                pathItemsDT.Columns.Add("ViewPipeSystemNetwork_OID", typeof(string));
1682
                pathItemsDT.Columns.Add("PipeRun_OID", typeof(string));
1683 bf9e8432 이지연
                pathItemsDT.Columns.Add("EqpGroupTag", typeof(string));
1684
                pathItemsDT.Columns.Add("MainLineTag", typeof(string));
1685
                pathItemsDT.Columns.Add("EGTConnectedPoint", typeof(string));
1686
                pathItemsDT.Columns.Add("EGFlowDirection", typeof(string));
1687 2c46461b LJIYEON
1688
                DataTable sequenceDataDT = new DataTable();
1689
                sequenceDataDT.Columns.Add("OID", typeof(string));
1690
                sequenceDataDT.Columns.Add("SERIALNUMBER", typeof(string));
1691
                sequenceDataDT.Columns.Add("PathItem_OID", typeof(string));
1692
                sequenceDataDT.Columns.Add("TopologySet_OID_Key", typeof(string));
1693
1694
                DataTable pipeSystemNetworkDT = new DataTable();
1695
                pipeSystemNetworkDT.Columns.Add("OID", typeof(string));
1696
                pipeSystemNetworkDT.Columns.Add("Type", typeof(string));
1697
                pipeSystemNetworkDT.Columns.Add("OrderNumber", typeof(string));
1698
                pipeSystemNetworkDT.Columns.Add("Pipeline_OID", typeof(string));
1699
                pipeSystemNetworkDT.Columns.Add("FROM_DATA", typeof(string));
1700
                pipeSystemNetworkDT.Columns.Add("TO_DATA", typeof(string));
1701
                pipeSystemNetworkDT.Columns.Add("TopologySet_OID_Key", typeof(string));
1702
                pipeSystemNetworkDT.Columns.Add("PSNRevisionNumber", typeof(string));
1703
                pipeSystemNetworkDT.Columns.Add("PBS", typeof(string));
1704 72775f2e LJIYEON
                pipeSystemNetworkDT.Columns.Add("Drawings", typeof(string));
1705
                pipeSystemNetworkDT.Columns.Add("IsValid", typeof(string));
1706 2c46461b LJIYEON
                pipeSystemNetworkDT.Columns.Add("Status", typeof(string));
1707 ddc1c369 LJIYEON
                pipeSystemNetworkDT.Columns.Add("IncludingVirtualData", typeof(string));
1708
                pipeSystemNetworkDT.Columns.Add("PSNAccuracy", typeof(string));
1709 08b33e44 gaqhf
                pipeSystemNetworkDT.Columns.Add("Pocket", typeof(string));
1710 d1afd412 이지연
                pipeSystemNetworkDT.Columns.Add("EGTag", typeof(string));
1711
                pipeSystemNetworkDT.Columns.Add("HasMLTags", typeof(string));
1712 0eefef3d 이지연
                pipeSystemNetworkDT.Columns.Add("AFC", typeof(string));
1713 d1afd412 이지연
                pipeSystemNetworkDT.Columns.Add("PUMP", typeof(string));
1714 2c46461b LJIYEON
1715
                DataTable topologySetDT = new DataTable();
1716
                topologySetDT.Columns.Add("OID", typeof(string));
1717
                topologySetDT.Columns.Add("Type", typeof(string));
1718
                topologySetDT.Columns.Add("SubType", typeof(string));
1719
                topologySetDT.Columns.Add("HeadItemTag", typeof(string));
1720
                topologySetDT.Columns.Add("TailItemTag", typeof(string));
1721 72775f2e LJIYEON
                topologySetDT.Columns.Add("HeadItemSPID", typeof(string));
1722
                topologySetDT.Columns.Add("TailItemSPID", typeof(string));
1723 2c46461b LJIYEON
1724 f9f2787b LJIYEON
                DataTable pipelineDT = new DataTable();
1725
                pipelineDT.Columns.Add("OID", typeof(string));
1726
                pipelineDT.Columns.Add("PipeSystem_OID", typeof(string));
1727
                pipelineDT.Columns.Add("FLUID", typeof(string));
1728
                pipelineDT.Columns.Add("PMC", typeof(string));
1729
                pipelineDT.Columns.Add("SEQNUMBER", typeof(string));
1730
                pipelineDT.Columns.Add("INSULATION", typeof(string));
1731
                pipelineDT.Columns.Add("FROM_DATA", typeof(string));
1732
                pipelineDT.Columns.Add("TO_DATA", typeof(string));
1733
                pipelineDT.Columns.Add("Unit", typeof(string));
1734
1735 531fb158 LJIYEON
                DataTable pipesystemDT = new DataTable();
1736
                pipesystemDT.Columns.Add("OID", typeof(string));
1737
                pipesystemDT.Columns.Add("DESCRIPTION", typeof(string));
1738
                pipesystemDT.Columns.Add("FLUID", typeof(string));
1739
                pipesystemDT.Columns.Add("PMC", typeof(string));
1740
                pipesystemDT.Columns.Add("PipeLineQty", typeof(string));
1741
                pipesystemDT.Columns.Add("GroundLevel", typeof(string));
1742
1743 879ce10b LJIYEON
                // Set Vent/Drain Info
1744 2c46461b LJIYEON
                List<VentDrainInfo> VentDrainInfos = new List<VentDrainInfo>();
1745
                DataTable dt = DB.SelectVentDrainSetting();
1746
                foreach (DataRow row in dt.Rows)
1747 36a45f13 gaqhf
                {
1748 2c46461b LJIYEON
                    string groupID = row["GROUP_ID"].ToString();
1749
                    string desc = row["DESCRIPTION"].ToString();
1750
                    int index = Convert.ToInt32(row["INDEX"]);
1751
                    string name = row["NAME"].ToString();
1752 36a45f13 gaqhf
1753 2c46461b LJIYEON
                    VentDrainInfo ventDrainInfo = VentDrainInfos.Find(x => x.UID.Equals(groupID));
1754
                    if (ventDrainInfo == null)
1755 36a45f13 gaqhf
                    {
1756 2c46461b LJIYEON
                        ventDrainInfo = new VentDrainInfo(groupID);
1757
                        ventDrainInfo.Description = desc;
1758
                        VentDrainInfos.Add(ventDrainInfo);
1759 36a45f13 gaqhf
                    }
1760
1761 2c46461b LJIYEON
                    ventDrainInfo.VentDrainItems.Add(new VentDrainItem()
1762
                    {
1763
                        Index = index,
1764
                        Name = name
1765
                    });
1766
                }
1767 51974d2b LJIYEON
                foreach (VentDrainInfo ventDrainInfo in VentDrainInfos)
1768
                    ventDrainInfo.VentDrainItems = ventDrainInfo.VentDrainItems.OrderBy(x => x.Index).ToList();
1769 2c46461b LJIYEON
1770 879ce10b LJIYEON
                #region Keyword Info
1771 eb44d82c LJIYEON
                KeywordInfo KeywordInfos = new KeywordInfo();
1772 879ce10b LJIYEON
                DataTable dtKeyword = DB.SelectKeywordsSetting();
1773
                foreach (DataRow row in dtKeyword.Rows)
1774
                {
1775
                    int index = Convert.ToInt32(row["INDEX"]);
1776
                    string name = row["NAME"].ToString();
1777
                    string keyword = row["KEYWORD"].ToString();
1778
1779 eb44d82c LJIYEON
                    //KeywordInfo keywordInfo = new KeywordInfo();   
1780
                    KeywordInfos.KeywordItems.Add(new KeywordItem()
1781 879ce10b LJIYEON
                    {
1782
                        Index = index,
1783
                        Name = name,
1784
                        Keyword = keyword
1785
                    });
1786 811d7949 LJIYEON
                }
1787
                #endregion
1788
1789
                #region ValveGrouping Info
1790
                ValveGroupInfo ValveGrouping = new ValveGroupInfo();
1791
                DataTable dtValveGroupung = DB.SelectValveGroupItemsSetting();
1792
                foreach (DataRow row in dtValveGroupung.Rows)
1793
                {
1794
                    ValveGrouping.ValveGroupItems.Add(new ValveGroupItem()
1795
                    {
1796
                        OID = row["OID"].ToString(),
1797
                        GroupType = row["GroupType"].ToString(),
1798
                        TagIdentifier = row["TagIdentifier"].ToString(),
1799
                        AttributeName = row["AttributeName"].ToString(),
1800
                        SppidSymbolName = row["SppidSymbolName"].ToString()
1801
                    });
1802
                }
1803 879ce10b LJIYEON
                #endregion
1804
1805 08b33e44 gaqhf
                #region EquipmentNoPocket Info
1806
                EquipmentNoPocketInfo EquipmentNoPocket = new EquipmentNoPocketInfo();
1807
                DataTable dtEquipmentNoPocket = DB.SelectEquipmentNoPocketSetting();
1808
                foreach (DataRow row in dtEquipmentNoPocket.Rows)
1809
                {
1810
                    EquipmentNoPocket.EquipmentNoPocketItem.Add(new EquipmentNoPocketItem()
1811
                    {
1812
                        Index = Convert.ToInt32(row["INDEX"]),
1813
                        Type = row["TYPE"].ToString(),
1814
                        Name = row["NAME"].ToString()
1815
                    });
1816
                }
1817
                #endregion
1818
1819 0eefef3d 이지연
                #region EquipmentAirFinCooler Info
1820
                EquipmentAirFinCoolerInfo EquipmentAirFinCooler = new EquipmentAirFinCoolerInfo();
1821
                DataTable dtEquipmentAirFinCooler = DB.SelectAirFinCoolerSetting();
1822
                foreach (DataRow row in dtEquipmentAirFinCooler.Rows)
1823
                {
1824
                    //pump type도 마찬가지?
1825
                    EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Add(new EquipmentAirFinCoolerItem()
1826
                    {
1827
                        Type = row["Type"].ToString(),
1828
                        Name = row["Name"].ToString()
1829
                    });
1830
                }
1831
                #endregion
1832
1833 2c46461b LJIYEON
                // key = 미입력 branch
1834
                Dictionary<Item, Item> startBranchDic = new Dictionary<Item, Item>();
1835
                Dictionary<Item, Item> endBranchDic = new Dictionary<Item, Item>();
1836 531fb158 LJIYEON
                DataTable PSNFluidDT = DB.SelectPSNFluidCode();
1837
                DataTable PSNPMCDT = DB.SelectPSNPIPINGMATLCLASS();
1838 2c46461b LJIYEON
                foreach (PSNItem PSNItem in PSNItems)
1839
                {
1840 3210f690 LJIYEON
                    try
1841 36a45f13 gaqhf
                    {
1842 3210f690 LJIYEON
                        int psnOrder = 0;
1843
                        int index = 0;
1844
                        bool bPSNStart = true;
1845
                        string sPSNData = string.Empty;
1846
                        bool bVentDrain = false;
1847 7106e181 LJIYEON
1848 51974d2b LJIYEON
                        List<Group> Groups = PSNItem.Groups;
1849 811d7949 LJIYEON
                        Dictionary<string, List<Item>> keyValuePairs = new Dictionary<string, List<Item>>();
1850 7106e181 LJIYEON
                        List<Item> valveGroupingItem = new List<Item>();
1851
1852 3210f690 LJIYEON
                        //VentDrain 검사
1853
                        if (PSNItem.Groups.Count.Equals(1))
1854 36a45f13 gaqhf
                        {
1855 7106e181 LJIYEON
                            List<VentDrainInfo> endInfos = new List<VentDrainInfo>();
1856
                            for (int g = 0; g < Groups.Count; g++)
1857 2c46461b LJIYEON
                            {
1858 51974d2b LJIYEON
                                Group group = Groups[g];
1859
                                for (int i = 0; i < group.Items.Count; i++)
1860 2c46461b LJIYEON
                                {
1861 51974d2b LJIYEON
                                    Item item = group.Items[i];
1862 3210f690 LJIYEON
                                    foreach (VentDrainInfo ventDrainInfo in VentDrainInfos)
1863 27d06aa8 LJIYEON
                                    {
1864 51974d2b LJIYEON
                                        if (endInfos.Contains(ventDrainInfo))
1865 3210f690 LJIYEON
                                            continue;
1866 51974d2b LJIYEON
1867 3210f690 LJIYEON
                                        if (!ventDrainInfo.VentDrainItems[i].Name.Equals(item.Name))
1868
                                        {
1869
                                            endInfos.Add(ventDrainInfo);
1870
                                            continue;
1871
                                        }
1872 6b9e7a56 gaqhf
1873 51974d2b LJIYEON
                                        if (ventDrainInfo.VentDrainItems.Count.Equals(i + 1))
1874 3210f690 LJIYEON
                                        {
1875
                                            bVentDrain = true;
1876 51974d2b LJIYEON
                                            break;
1877 3210f690 LJIYEON
                                        }
1878 27d06aa8 LJIYEON
                                    }
1879 51974d2b LJIYEON
1880
                                    if (bVentDrain || endInfos.Count.Equals(VentDrainInfos.Count))
1881
                                        break;
1882
                                }
1883
1884
                                if (!bVentDrain)
1885
                                {
1886
                                    endInfos = new List<VentDrainInfo>();
1887
                                    for (int i = 0; i < group.Items.Count; i++)
1888
                                    {
1889
                                        Item item = group.Items[group.Items.Count - i - 1];
1890
                                        foreach (VentDrainInfo ventDrainInfo in VentDrainInfos)
1891
                                        {
1892
                                            if (endInfos.Contains(ventDrainInfo))
1893
                                                continue;
1894
1895
                                            if (!ventDrainInfo.VentDrainItems[i].Name.Equals(item.Name))
1896
                                            {
1897
                                                endInfos.Add(ventDrainInfo);
1898
                                                continue;
1899
                                            }
1900
1901
                                            if (ventDrainInfo.VentDrainItems.Count.Equals(i + 1))
1902
                                            {
1903
                                                bVentDrain = true;
1904
                                                break;
1905
                                            }
1906
                                        }
1907
1908
                                        if (bVentDrain || endInfos.Count.Equals(VentDrainInfos.Count))
1909
                                            break;
1910
                                    }
1911 27d06aa8 LJIYEON
                                }
1912 3210f690 LJIYEON
                            }
1913
                        }
1914 7106e181 LJIYEON
1915 a5616391 LJIYEON
                        try
1916 7106e181 LJIYEON
                        {
1917 a5616391 LJIYEON
                            foreach (Group group in PSNItem.Groups)
1918 7106e181 LJIYEON
                            {
1919 a5616391 LJIYEON
                                foreach (Item item in group.Items)
1920 7106e181 LJIYEON
                                {
1921 811d7949 LJIYEON
                                    string VgTag = string.Empty;
1922 0eefef3d 이지연
                                    
1923 7106e181 LJIYEON
                                    if (ValveGrouping.ValveGroupItems.Where(x => x.SppidSymbolName == item.Name).Count() > 0)
1924 811d7949 LJIYEON
                                    {
1925
                                        ValveGroupItem valveitem = ValveGrouping.ValveGroupItems.Where(x => x.SppidSymbolName == item.Name).First();
1926 7106e181 LJIYEON
                                        string value = string.Empty;
1927
1928
                                        if (valveitem.GroupType == "Scope Break" || valveitem.AttributeName == "NoSelection")
1929 54b6df95 LJIYEON
                                            value = "NoSelection";
1930
                                        else
1931
                                            value = item.Attributes.Find(x => x.Name == valveitem.AttributeName).Value;
1932
1933
                                        if (valveitem.GroupType == "Scope Break")
1934
                                            VgTag = "Scope Break";
1935
                                        else
1936
                                            VgTag = valveitem.SppidSymbolName + "\\" + value;
1937 7106e181 LJIYEON
1938 811d7949 LJIYEON
                                    }
1939
1940 a5616391 LJIYEON
                                    string PathitemUID = string.Empty;
1941
                                    if (item.BranchItems.Count == 0)
1942 a36541fb LJIYEON
                                    {
1943 a5616391 LJIYEON
                                        PathitemUID = item.UID;
1944 811d7949 LJIYEON
                                        CreatePathItemsDataRow(PathitemUID, item.ID2DBType, VgTag);
1945 a5616391 LJIYEON
                                        CreateSequenceDataDataRow(PathitemUID);
1946
                                        index++;
1947
                                    }
1948
                                    else
1949
                                    {
1950
                                        PathitemUID = item.UID + "_L1";
1951 811d7949 LJIYEON
                                        CreatePathItemsDataRow(PathitemUID, item.ID2DBType, VgTag);
1952 a5616391 LJIYEON
                                        CreateSequenceDataDataRow(PathitemUID);
1953
                                        index++;
1954
                                        for (int i = 0; i < item.BranchItems.Count; i++)
1955 3210f690 LJIYEON
                                        {
1956 811d7949 LJIYEON
                                            CreatePathItemsDataRow(string.Format(item.UID + "_B{0}", i + 1), "Branch", string.Empty, item.BranchItems[i].Topology.FullName, item.BranchItems[i]);
1957 a5616391 LJIYEON
                                            CreateSequenceDataDataRow(string.Format(item.UID + "_B{0}", i + 1));
1958 3210f690 LJIYEON
                                            index++;
1959 7106e181 LJIYEON
1960 a5616391 LJIYEON
                                            CreatePathItemsDataRow(string.Format(item.UID + "_L{0}", i + 2), item.ID2DBType);
1961
                                            CreateSequenceDataDataRow(string.Format(item.UID + "_L{0}", i + 2));
1962
                                            index++;
1963 a36541fb LJIYEON
1964 a5616391 LJIYEON
                                            if (item.BranchItems[i].Relations[0].Item != null && item.BranchItems[i].Relations[0].Item == item)
1965
                                                startBranchDic.Add(item.BranchItems[i], item);
1966
                                            else if (item.BranchItems[i].Relations[1].Item != null && item.BranchItems[i].Relations[1].Item == item)
1967
                                                endBranchDic.Add(item.BranchItems[i], item);
1968
                                        }
1969
                                    }
1970 7106e181 LJIYEON
1971 a5616391 LJIYEON
                                    if (bPSNStart)
1972 7106e181 LJIYEON
                                    {
1973 a5616391 LJIYEON
                                        CreatePipeSystemNetworkDataRow();
1974 7106e181 LJIYEON
                                        sPSNData = item.TopologyData;
1975 a5616391 LJIYEON
                                        psnOrder++;
1976
                                        bPSNStart = false;
1977
                                    }
1978
                                    else
1979
                                    {
1980
                                        if (item.TopologyData != sPSNData)
1981 3210f690 LJIYEON
                                        {
1982
                                            CreatePipeSystemNetworkDataRow();
1983
                                            sPSNData = item.TopologyData;
1984
                                            psnOrder++;
1985
                                        }
1986 a5616391 LJIYEON
                                    }
1987 7106e181 LJIYEON
1988 811d7949 LJIYEON
                                    void CreatePathItemsDataRow(string itemOID, string itemType, string GROUPTAG = "", string branchTopologyName = "", Item branchItem = null)
1989 a5616391 LJIYEON
                                    {
1990
                                        DataRow newRow = pathItemsDT.NewRow();
1991
1992
                                        if (itemType == "Nozzles")
1993 3210f690 LJIYEON
                                        {
1994 a5616391 LJIYEON
                                            newRow["Equipment_OID"] = item.Equipment.UID;
1995 3210f690 LJIYEON
                                        }
1996 7106e181 LJIYEON
1997 a5616391 LJIYEON
                                        newRow["OID"] = itemOID;
1998
                                        newRow["SequenceData_OID"] = string.Format(item.Topology.FullName + "_{0}", index);
1999
                                        newRow["TopologySet_OID"] = item.Topology.FullName;
2000
                                        newRow["BranchTopologySet_OID"] = branchTopologyName;
2001
                                        newRow["PipeLine_OID"] = item.PSNPipeLineID;
2002
                                        newRow["ITEMNAME"] = GetItemName(item, itemOID);
2003
                                        newRow["ITEMTAG"] = GetItemTag(item);
2004
                                        newRow["Class"] = GetClass(item, itemOID);
2005 7106e181 LJIYEON
                                        string subClass = GetSubClass(item, itemOID);
2006 a5616391 LJIYEON
                                        newRow["SubClass"] = subClass;
2007 7106e181 LJIYEON
2008 a5616391 LJIYEON
                                        if (item.ItemType == ItemType.Symbol)
2009
                                            newRow["TYPE"] = item.ID2DBName;
2010
                                        else if (item.ItemType == ItemType.Line)
2011
                                            newRow["TYPE"] = item.ID2DBType;
2012
                                        newRow["PIDNAME"] = group.Document.DrawingName;
2013
2014
                                        // NPD
2015
                                        if (item.LineNumber != null)
2016
                                        {
2017
                                            Attribute attribute = item.LineNumber.Attributes.Find(x => x.Name == "NominalDiameter");
2018
                                            if (attribute != null)
2019
                                                newRow["NPD"] = attribute.Value;
2020
                                        }
2021
                                        else
2022
                                            newRow["NPD"] = null;
2023 7881ec8f gaqhf
2024 811d7949 LJIYEON
                                        newRow["GROUPTAG"] = GROUPTAG;
2025 a5616391 LJIYEON
                                        newRow["PipeSystemNetwork_OID"] = PSNItem.PSN_OID();
2026
                                        if (branchItem == null)
2027
                                            newRow["ViewPipeSystemNetwork_OID"] = PSNItem.PSN_OID();
2028
                                        else
2029
                                            newRow["ViewPipeSystemNetwork_OID"] = branchItem.PSNItem.PSN_OID();
2030 27d06aa8 LJIYEON
2031 a5616391 LJIYEON
                                        newRow["PipeRun_OID"] = item.LineNumber != null ? item.LineNumber.Name : string.Empty;
2032 0eefef3d 이지연
                                        newRow["EGTConnectedPoint"] = 0;
2033 a5616391 LJIYEON
                                        pathItemsDT.Rows.Add(newRow);
2034 7106e181 LJIYEON
                                    }
2035 0eefef3d 이지연
2036
2037 a5616391 LJIYEON
                                    void CreateSequenceDataDataRow(string itemOID)
2038
                                    {
2039
                                        DataRow newRow = sequenceDataDT.NewRow();
2040
                                        newRow["OID"] = string.Format(item.Topology.FullName + "_{0}", index);
2041
                                        newRow["SERIALNUMBER"] = string.Format("{0}", index);
2042
                                        newRow["PathItem_OID"] = itemOID;
2043
                                        newRow["TopologySet_OID_Key"] = item.Topology.FullName;
2044 839708c6 LJIYEON
2045 a5616391 LJIYEON
                                        sequenceDataDT.Rows.Add(newRow);
2046
                                    }
2047 0eefef3d 이지연
2048 a5616391 LJIYEON
                                    void CreatePipeSystemNetworkDataRow()
2049 7106e181 LJIYEON
                                    {
2050 a5616391 LJIYEON
                                        LineNumber lineNumber = item.Document.LineNumbers.Find(x => x.UID == item.Owner);
2051 08b33e44 gaqhf
                                        string FluidCode = string.Empty;
2052 a5616391 LJIYEON
                                        if (lineNumber != null)
2053 3210f690 LJIYEON
                                        {
2054 a5616391 LJIYEON
                                            List<Attribute> att = lineNumber.Attributes;
2055
                                            if (att != null)
2056 3210f690 LJIYEON
                                            {
2057 a5616391 LJIYEON
                                                List<string> oid = new List<string>();
2058 08b33e44 gaqhf
                                                FluidCode = att.Where(x => x.Name.ToUpper().Equals("FLUIDCODE")).FirstOrDefault() != null ? att.Where(x => x.Name.ToUpper().Equals("FLUIDCODE")).FirstOrDefault().Value : string.Empty;
2059 a5616391 LJIYEON
                                                string PMC = lineNumber.Attributes.Where(x => x.Name.ToUpper().Equals("PIPINGMATERIALSCLASS")).FirstOrDefault() != null ? lineNumber.Attributes.Where(x => x.Name.ToUpper().Equals("PIPINGMATERIALSCLASS")).FirstOrDefault().Value : string.Empty;
2060
                                                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;
2061
                                                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;
2062
                                                //InsulationPurpose
2063
                                                if (!string.IsNullOrEmpty(FluidCode)) oid.Add(FluidCode);
2064
                                                if (!string.IsNullOrEmpty(PMC)) oid.Add(PMC);
2065
2066
                                                string PipeSystem_OID = string.Join("-", oid);
2067
2068
                                                if (!string.IsNullOrEmpty(SEQNUMBER)) oid.Add(SEQNUMBER);
2069
                                                if (!string.IsNullOrEmpty(INSULATION)) oid.Add(INSULATION);
2070
2071
                                                string OID = string.Join("-", oid);
2072 531fb158 LJIYEON
                                                string FluidCodeGL = string.Empty;
2073
                                                string PMCGL = string.Empty;
2074 7106e181 LJIYEON
2075 3210f690 LJIYEON
2076 a5616391 LJIYEON
                                                if (pipelineDT.Select(string.Format("OID = '{0}'", OID)).Count() == 0)
2077
                                                {
2078
                                                    DataRow newPipelineRow = pipelineDT.NewRow();
2079
                                                    newPipelineRow["OID"] = OID;
2080
                                                    newPipelineRow["PipeSystem_OID"] = PipeSystem_OID;
2081
                                                    newPipelineRow["FLUID"] = FluidCode;
2082
                                                    newPipelineRow["PMC"] = PMC;
2083
                                                    newPipelineRow["SEQNUMBER"] = SEQNUMBER;
2084
                                                    newPipelineRow["INSULATION"] = INSULATION;
2085
                                                    newPipelineRow["FROM_DATA"] = string.Empty;
2086
                                                    newPipelineRow["TO_DATA"] = string.Empty;
2087
                                                    newPipelineRow["Unit"] = PSNItem.GetPBSData();
2088 7106e181 LJIYEON
                                                    pipelineDT.Rows.Add(newPipelineRow);
2089 531fb158 LJIYEON
                                                }
2090
2091
                                                if (pipesystemDT.Select(string.Format("OID = '{0}'", PipeSystem_OID)).Count() == 0)
2092
                                                {
2093 54b6df95 LJIYEON
                                                    DataRow newPipesystemRow = pipesystemDT.NewRow();
2094
                                                    newPipesystemRow["OID"] = PipeSystem_OID;
2095
                                                    newPipesystemRow["DESCRIPTION"] = string.Empty;
2096
                                                    newPipesystemRow["FLUID"] = FluidCode;
2097
                                                    newPipesystemRow["PMC"] = PMC;
2098
                                                    newPipesystemRow["PipeLineQty"] = string.Empty;
2099
                                                    string GroundLevel = string.Empty;
2100
                                                    if (!string.IsNullOrEmpty(FluidCode) && !string.IsNullOrEmpty(PMC))
2101
                                                    {
2102
                                                        FluidCodeGL = PSNFluidDT.Select(string.Format("Code = '{0}'", FluidCode)).FirstOrDefault().Field<string>("GroundLevel");
2103
                                                        PMCGL = PSNPMCDT.Select(string.Format("Code= '{0}'", PMC)).FirstOrDefault().Field<string>("GroundLevel");
2104
                                                        if (FluidCodeGL == "AG" && PMCGL == "AG")
2105
                                                            GroundLevel = "AG";
2106
                                                        else if (FluidCodeGL == "UG" && PMCGL == "UG")
2107
                                                            GroundLevel = "UG";
2108
                                                        else
2109
                                                            GroundLevel = "AG_UG";
2110
                                                    }
2111
                                                    newPipesystemRow["GroundLevel"] = GroundLevel;
2112
2113
                                                    pipesystemDT.Rows.Add(newPipesystemRow);
2114 3210f690 LJIYEON
                                                }
2115
                                            }
2116 a5616391 LJIYEON
                                        }
2117 3210f690 LJIYEON
2118 a5616391 LJIYEON
                                        DataRow newRow = pipeSystemNetworkDT.NewRow();
2119
                                        newRow["OID"] = PSNItem.PSN_OID();
2120 7106e181 LJIYEON
2121 a5616391 LJIYEON
                                        newRow["OrderNumber"] = psnOrder;
2122
                                        newRow["Pipeline_OID"] = item.PSNPipeLineID;
2123
                                        PSNItem.KeywordInfos = KeywordInfos;
2124
                                        PSNItem.Nozzle = Nozzle;
2125 7106e181 LJIYEON
2126 a5616391 LJIYEON
                                        string FromType = string.Empty;
2127
                                        Item From_item = new Item();
2128 7106e181 LJIYEON
2129 a5616391 LJIYEON
                                        string FROM_DATA = PSNItem.GetFromData(ref FromType, ref From_item);
2130 51974d2b LJIYEON
                                        string status = string.Empty;
2131
                                        if (psnOrder == 0)
2132
                                        {
2133
                                            status = PSNItem.Status;
2134
                                        }
2135
2136 a5616391 LJIYEON
                                        if (PSNItem.IsKeyword)
2137
                                        {
2138 e552da48 LJIYEON
                                            PSNItem.StartType = PSNType.Equipment;
2139 a5616391 LJIYEON
                                        }
2140
                                        string ToType = string.Empty;
2141
                                        Item To_item = new Item();
2142
                                        string TO_DATA = PSNItem.GetToData(ref ToType, ref To_item);
2143
                                        if (PSNItem.IsKeyword)
2144
                                        {
2145 e552da48 LJIYEON
                                            PSNItem.EndType = PSNType.Equipment;
2146 a5616391 LJIYEON
                                        }
2147 54b6df95 LJIYEON
2148 7106e181 LJIYEON
                                        //if (Groups.Count == psnOrder + 1 && !string.IsNullOrEmpty(PSNItem.Status))
2149
                                        //{
2150
                                        if (!string.IsNullOrEmpty(PSNItem.Status))
2151 51974d2b LJIYEON
                                            status += PSNItem.Status;
2152 7106e181 LJIYEON
                                        //}
2153 33cee849 LJIYEON
2154 e552da48 LJIYEON
                                        newRow["FROM_DATA"] = FROM_DATA;
2155 7106e181 LJIYEON
                                        newRow["TO_DATA"] = TO_DATA;
2156 a5616391 LJIYEON
                                        newRow["Type"] = PSNItem.GetPSNType();
2157 e552da48 LJIYEON
2158
                                        if (psnOrder > 0)
2159
                                        {
2160 7106e181 LJIYEON
                                            DataRow dr = pipeSystemNetworkDT.Select(string.Format("OID = '{0}' AND OrderNumber = {1}", PSNItem.PSN_OID(), psnOrder - 1)).FirstOrDefault();
2161
                                            if (!string.IsNullOrEmpty(PSNItem.Status))
2162
                                            {//status = !string.IsNullOrEmpty(status) ? status.Remove(0, 2) : string.Empty;
2163
                                                if (dr["Status"].ToString().Contains(PSNItem.Status))
2164
                                                    dr["Status"] = dr["Status"].ToString().Replace(PSNItem.Status, string.Empty);
2165
                                                else if (dr["Status"].ToString().Contains(PSNItem.Status.Remove(0, 2)))
2166
                                                    dr["Status"] = dr["Status"].ToString().Replace(PSNItem.Status.Remove(0, 2), string.Empty);
2167
2168
                                            }
2169
2170
                                            if (dr != null)
2171 e552da48 LJIYEON
                                            {
2172
                                                newRow["FROM_DATA"] = dr.Field<string>("FROM_DATA");
2173
                                                newRow["TO_DATA"] = dr.Field<string>("TO_DATA");
2174
                                                newRow["Type"] = dr.Field<string>("Type");
2175
                                            }
2176 7106e181 LJIYEON
                                        }
2177 eb44d82c LJIYEON
2178 48870200 LJIYEON
                                        status = !string.IsNullOrEmpty(status) ? status.Remove(0, 2) : string.Empty;
2179
                                        if (group.Items.Count == 1 && !string.IsNullOrEmpty(status))
2180
                                        {
2181
                                            MatchCollection matches = Regex.Matches(status, "Missing LineNumber_1");
2182
                                            int cnt = matches.Count;
2183
                                            if (cnt > 1)
2184
                                                status.Replace(", Missing LineNumber_1", string.Empty);
2185
                                        }
2186 a5616391 LJIYEON
                                        newRow["TopologySet_OID_Key"] = item.Topology.FullName;
2187
                                        newRow["PSNRevisionNumber"] = string.Format("V{0:D4}", Revision);
2188 5e4c2ad1 LJIYEON
2189 7106e181 LJIYEON
2190 a5616391 LJIYEON
                                        newRow["IsValid"] = PSNItem.IsValid;
2191 48870200 LJIYEON
                                        newRow["Status"] = status;
2192 a5616391 LJIYEON
                                        newRow["PBS"] = PSNItem.GetPBSData();
2193 7106e181 LJIYEON
2194 a5616391 LJIYEON
                                        List<string> drawingNames = new List<string>();
2195
                                        foreach (Group _group in PSNItem.Groups)
2196
                                        {
2197
                                            if (!drawingNames.Contains(_group.Document.DrawingName))
2198 3210f690 LJIYEON
                                            {
2199 a5616391 LJIYEON
                                                if (drawingNames.Count == 0)
2200
                                                    newRow["Drawings"] = _group.Document.DrawingName;
2201
                                                else
2202
                                                    newRow["Drawings"] = newRow["Drawings"] + ", " + _group.Document.DrawingName;
2203
                                                drawingNames.Add(_group.Document.DrawingName);
2204 3210f690 LJIYEON
                                            }
2205 27d06aa8 LJIYEON
                                        }
2206 419055fa LJIYEON
2207
                                        // VentDrain의 경우 제외 요청 (데이터를 아예 제거하였을 경우 후 가공에서 문제가 생김 마지막에 지우는것으로 변경)
2208
                                        if (bVentDrain)
2209
                                            newRow["IncludingVirtualData"] = "Vent_Drain";
2210
                                        else
2211
                                            newRow["IncludingVirtualData"] = "No";
2212
                                        //    return;
2213 a2973aa3 LJIYEON
                                        //newRow["IncludingVirtualData"] = "No";
2214 a5616391 LJIYEON
                                        newRow["PSNAccuracy"] = "100";
2215 08b33e44 gaqhf
2216
                                        string Pocket = "No";
2217
                                        string Condition = PSNFluidDT.Select(string.Format("Code = '{0}'", FluidCode)).FirstOrDefault().Field<string>("Condition");
2218
                                        if (Condition.Equals("Flare"))
2219
                                            Pocket = "Yes";
2220
2221 91c75c0b 이지연
                                        if (item.ID2DBType == "Nozzles" && PSNItem.StartType == PSNType.Equipment) 
2222 08b33e44 gaqhf
                                        {
2223
                                          //  string itemName = From_item.Name;
2224
                                            Equipment Equipment = From_item.Equipment;
2225 91c75c0b 이지연
                                      
2226
                                            EquipmentNoPocketItem nopocket = EquipmentNoPocket.EquipmentNoPocketItem.Where(x => x.Name == Equipment.Name && x.Type != "Pump").FirstOrDefault();
2227
                                          
2228
2229
                                            if (nopocket != null)
2230 08b33e44 gaqhf
                                            {
2231 91c75c0b 이지연
                                                DataRow bNozzle = null;
2232
                                                if (nopocket.Type.Equals("Vertical Vessel"))
2233
                                                {
2234
                                                    DataRow drNozzle = Nozzle.Select(string.Format("Equipment_OID = '{0}' AND OID = '{1}'", Equipment.UID, From_item.UID)).FirstOrDefault();
2235
                                                    if (drNozzle != null)
2236
                                                    {
2237
                                                        if (drNozzle.Field<string>("Rotation").Length >= 4 && drNozzle.Field<string>("Rotation").Substring(0, 4) == "4.71")
2238
                                                        {
2239
                                                            bNozzle = drNozzle;
2240
                                                        }
2241
2242
                                                        if (bNozzle == null)
2243
                                                        {
2244
                                                            DataRow[] nozzleRows = Nozzle.Select(string.Format("Equipment_OID = '{0}'", Equipment.UID));
2245
2246
                                                            if (drNozzle != null)
2247
                                                            {
2248
                                                                bNozzle = drNozzle;
2249
                                                                foreach (DataRow it in nozzleRows)
2250
                                                                {
2251
                                                                    if (Convert.ToDecimal(drNozzle.Field<string>("Ycoords")) > Convert.ToDecimal(it.Field<string>("Ycoords")))
2252
                                                                    {
2253
                                                                        bNozzle = null;
2254
                                                                        break;
2255
                                                                    }
2256
                                                                }
2257
                                                            }
2258
                                                        }
2259
                                                    }
2260
2261
                                                    if (bNozzle != null)
2262
                                                        Pocket = "Yes";
2263
                                                }
2264
                                                else
2265
                                                    Pocket = "Yes";
2266 08b33e44 gaqhf
                                            }
2267
                                        }
2268 91c75c0b 이지연
                                        
2269
                                        if (item.ID2DBType == "Nozzles" && PSNItem.EndType == PSNType.Equipment) //To는 전체
2270 08b33e44 gaqhf
                                        {
2271
                                           // string itemName = To_item.Name;
2272
                                            Equipment Equipment = To_item.Equipment;
2273
                                            EquipmentNoPocketItem nopocket = EquipmentNoPocket.EquipmentNoPocketItem.Where(x => x.Name == Equipment.Name).FirstOrDefault();
2274
                                            if (nopocket != null)
2275
                                            {
2276 91c75c0b 이지연
                                                DataRow bNozzle = null;
2277
                                                if (nopocket.Type.Equals("Vertical Vessel"))
2278
                                                {
2279
                                                    DataRow drNozzle = Nozzle.Select(string.Format("Equipment_OID = '{0}' AND OID = '{1}'", Equipment.UID, To_item.UID)).FirstOrDefault();
2280
                                                    if(drNozzle != null)
2281
                                                    {
2282
                                                        if (drNozzle.Field<string>("Rotation").Length >= 4 && drNozzle.Field<string>("Rotation").Substring(0, 4) == "4.71")
2283
                                                        {
2284
                                                            bNozzle = drNozzle;
2285
                                                        }
2286
2287
                                                        if (bNozzle == null)
2288
                                                        {
2289
                                                            DataRow[] nozzleRows = Nozzle.Select(string.Format("Equipment_OID = '{0}'", Equipment.UID));
2290
2291
                                                            if (drNozzle != null)
2292
                                                            {
2293
                                                                bNozzle = drNozzle;
2294
                                                                foreach (DataRow it in nozzleRows)
2295
                                                                {
2296
                                                                    if (Convert.ToDecimal(drNozzle.Field<string>("Ycoords")) > Convert.ToDecimal(it.Field<string>("Ycoords")))
2297
                                                                    {
2298
                                                                        bNozzle = null;
2299
                                                                        break;
2300
                                                                    }
2301
                                                                }
2302
                                                            }
2303
                                                        }
2304
                                                    }                                                   
2305
2306
                                                    if (bNozzle != null)
2307
                                                        Pocket = "Yes";
2308
                                                }
2309
                                                else
2310
                                                    Pocket = "Yes";
2311 08b33e44 gaqhf
                                            }
2312
                                        }
2313 91c75c0b 이지연
                                        
2314 08b33e44 gaqhf
                                        newRow["Pocket"] = Pocket;
2315 0eefef3d 이지연
                                        string AFC = "P2";
2316
                                        if(PSNItem.StartType == PSNType.Equipment && From_item.Equipment != null)
2317
                                        {
2318 d1afd412 이지연
                                            if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type != "Pump" && x.Name.Equals(From_item.Equipment.Name)).Count() > 0)
2319 0eefef3d 이지연
                                                AFC = "P1";
2320 d1afd412 이지연
                                            else if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && x.Name.Equals(From_item.Equipment.Name)).Count() > 0)
2321
                                                newRow["PUMP"] = "PUMP";
2322 0eefef3d 이지연
                                        }
2323
2324
                                        if (PSNItem.EndType == PSNType.Equipment && To_item.Equipment != null)
2325
                                        {
2326 d1afd412 이지연
                                            if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type != "Pump" && x.Name.Equals(To_item.Equipment.Name)).Count() > 0)
2327 0eefef3d 이지연
                                                AFC = "P1";
2328 d1afd412 이지연
                                            else if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && x.Name.Equals(To_item.Equipment.Name)).Count() > 0)
2329
                                                newRow["PUMP"] = "PUMP";
2330 0eefef3d 이지연
                                        }
2331
2332
                                        newRow["AFC"] = AFC;
2333 d1afd412 이지연
2334
                                        newRow["EGTag"] = string.Empty;
2335
                                        newRow["HasMLTags"] = "False";
2336 a5616391 LJIYEON
                                        pipeSystemNetworkDT.Rows.Add(newRow);
2337 2c46461b LJIYEON
                                    }
2338 27d06aa8 LJIYEON
                                }
2339 7106e181 LJIYEON
2340 820e283f LJIYEON
                            }
2341 91c75c0b 이지연
                        
2342 7106e181 LJIYEON
2343 a5616391 LJIYEON
                        }
2344
                        catch (Exception ex)
2345
                        {
2346
                            Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2347
                            MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
2348
                        }
2349 3210f690 LJIYEON
2350 a5616391 LJIYEON
                        //TopologySet 관련
2351
                        foreach (Topology topology in PSNItem.Topologies)
2352
                        {
2353
                            DataRow newRow = topologySetDT.NewRow();
2354
                            newRow["OID"] = topology.FullName;
2355
                            newRow["Type"] = topology.FullName.Split(new char[] { '-' }).Last().StartsWith("M") ? "Main" : "Branch";
2356
                            if (bVentDrain)
2357
                                newRow["SubType"] = "Vent_Drain";
2358
                            else
2359
                                newRow["SubType"] = null;
2360
                            newRow["HeadItemTag"] = GetItemTag(topology.Items.Last());
2361
                            newRow["TailItemTag"] = GetItemTag(topology.Items.First());
2362
                            newRow["HeadItemSPID"] = topology.Items.Last().UID;
2363
                            newRow["TailItemSPID"] = topology.Items.First().UID;
2364
                            topologySetDT.Rows.Add(newRow);
2365 94a117ca gaqhf
                        }
2366 7106e181 LJIYEON
2367 6b9e7a56 gaqhf
                    }
2368 7106e181 LJIYEON
                    catch (Exception ee)
2369 27d06aa8 LJIYEON
                    {
2370 879ce10b LJIYEON
2371 2c46461b LJIYEON
                    }
2372 6b9e7a56 gaqhf
                }
2373
2374 3210f690 LJIYEON
2375 2c46461b LJIYEON
                foreach (var item in startBranchDic)
2376 5c248ee3 gaqhf
                {
2377 2c46461b LJIYEON
                    string uid = item.Key.UID;
2378
                    string topologyName = item.Value.Topology.FullName;
2379
                    DataRow[] rows = pathItemsDT.Select(string.Format("OID LIKE '{0}%'", uid));
2380 7106e181 LJIYEON
2381 2c46461b LJIYEON
                    if (rows.Length == 1)
2382 9c151350 gaqhf
                    {
2383 2c46461b LJIYEON
                        rows.First()["BranchTopologySet_OID"] = topologyName;
2384 9c151350 gaqhf
                        rows.First()["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID();
2385
                    }
2386 2c46461b LJIYEON
                    else if (rows.Length > 1)
2387 5c248ee3 gaqhf
                    {
2388 2c46461b LJIYEON
                        DataRow targetRow = null;
2389
                        int index = int.MaxValue;
2390
                        foreach (DataRow row in rows)
2391 5c248ee3 gaqhf
                        {
2392 2c46461b LJIYEON
                            string split = row["OID"].ToString().Split(new char[] { '_' })[1];
2393
                            if (split.StartsWith("L"))
2394 5c248ee3 gaqhf
                            {
2395 2c46461b LJIYEON
                                int num = Convert.ToInt32(split.Remove(0, 1));
2396
                                if (index > num)
2397
                                {
2398
                                    index = num;
2399
                                    targetRow = row;
2400
                                }
2401 5c248ee3 gaqhf
                            }
2402
                        }
2403
2404 2c46461b LJIYEON
                        if (targetRow != null)
2405 9c151350 gaqhf
                        {
2406 2c46461b LJIYEON
                            targetRow["BranchTopologySet_OID"] = topologyName;
2407 9c151350 gaqhf
                            targetRow["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID();
2408
                        }
2409 2c46461b LJIYEON
                    }
2410 5c248ee3 gaqhf
                }
2411 f9f2787b LJIYEON
2412 2c46461b LJIYEON
                foreach (var item in endBranchDic)
2413 5c248ee3 gaqhf
                {
2414 2c46461b LJIYEON
                    string uid = item.Key.UID;
2415
                    string topologyName = item.Value.Topology.FullName;
2416
                    DataRow[] rows = pathItemsDT.Select(string.Format("OID LIKE '{0}%'", uid));
2417
                    if (rows.Length == 1)
2418 9c151350 gaqhf
                    {
2419 2c46461b LJIYEON
                        rows.First()["BranchTopologySet_OID"] = topologyName;
2420 9c151350 gaqhf
                        rows.First()["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID();
2421
                    }
2422 2c46461b LJIYEON
                    else if (rows.Length > 1)
2423 5c248ee3 gaqhf
                    {
2424 2c46461b LJIYEON
                        DataRow targetRow = null;
2425
                        int index = int.MinValue;
2426
                        foreach (DataRow row in rows)
2427 5c248ee3 gaqhf
                        {
2428 2c46461b LJIYEON
                            string split = row["OID"].ToString().Split(new char[] { '_' })[1];
2429
                            if (split.StartsWith("L"))
2430 5c248ee3 gaqhf
                            {
2431 2c46461b LJIYEON
                                int num = Convert.ToInt32(split.Remove(0, 1));
2432
                                if (index < num)
2433
                                {
2434
                                    index = num;
2435
                                    targetRow = row;
2436
                                }
2437 5c248ee3 gaqhf
                            }
2438
                        }
2439
2440 2c46461b LJIYEON
                        if (targetRow != null)
2441 9c151350 gaqhf
                        {
2442 2c46461b LJIYEON
                            targetRow["BranchTopologySet_OID"] = topologyName;
2443 9c151350 gaqhf
                            targetRow["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID();
2444
                        }
2445 2c46461b LJIYEON
                    }
2446 5c248ee3 gaqhf
                }
2447
2448 2c46461b LJIYEON
                PathItems = pathItemsDT;
2449
                SequenceData = sequenceDataDT;
2450
                PipeSystemNetwork = pipeSystemNetworkDT;
2451
                TopologySet = topologySetDT;
2452 f9f2787b LJIYEON
                PipeLine = pipelineDT;
2453 531fb158 LJIYEON
                PipeSystem = pipesystemDT;
2454 2c46461b LJIYEON
            }
2455
            catch (Exception ex)
2456
            {
2457
                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2458
                MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
2459
            }
2460 36a45f13 gaqhf
        }
2461 2ada3be8 LJIYEON
2462 5e4c2ad1 LJIYEON
        private double AccuracyCalculation(List<double> lstAcc, double acc)
2463 2ada3be8 LJIYEON
        {
2464 7106e181 LJIYEON
            foreach (double lacc in lstAcc)
2465 2ada3be8 LJIYEON
            {
2466
                acc *= lacc;
2467
            }
2468
            return acc;
2469
        }
2470
2471 7881ec8f gaqhf
        private void UpdateSubType()
2472 36a45f13 gaqhf
        {
2473 27d06aa8 LJIYEON
            try
2474 36a45f13 gaqhf
            {
2475 27d06aa8 LJIYEON
                foreach (PSNItem PSNItem in PSNItems)
2476 36a45f13 gaqhf
                {
2477 27d06aa8 LJIYEON
                    if (PSNItem.IsBypass)
2478 36a45f13 gaqhf
                    {
2479 27d06aa8 LJIYEON
                        foreach (Topology topology in PSNItem.Topologies)
2480
                        {
2481
                            DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName));
2482
                            if (rows.Length.Equals(1))
2483
                                rows.First()["SubType"] = "Bypass";
2484
                        }
2485
                    }
2486
2487
                    if (PSNItem.StartType == PSNType.Header)
2488
                    {
2489
                        Topology topology = PSNItem.Topologies.First();
2490
                        DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName));
2491
                        if (rows.Length.Equals(1))
2492
                            rows.First()["SubType"] = "Header";
2493
                    }
2494
                    else if (PSNItem.EndType == PSNType.Header)
2495
                    {
2496
                        Topology topology = PSNItem.Topologies.Last();
2497 7881ec8f gaqhf
                        DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName));
2498
                        if (rows.Length.Equals(1))
2499 27d06aa8 LJIYEON
                            rows.First()["SubType"] = "Header";
2500 36a45f13 gaqhf
                    }
2501
                }
2502 7881ec8f gaqhf
2503 36a45f13 gaqhf
2504 27d06aa8 LJIYEON
                foreach (Topology topology in Topologies)
2505 7881ec8f gaqhf
                {
2506 27d06aa8 LJIYEON
                    try
2507
                    {
2508
                        DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName));
2509 7106e181 LJIYEON
2510
                        if (rows.Count() > 0)
2511 27d06aa8 LJIYEON
                        {
2512 3210f690 LJIYEON
                            if (rows.Length.Equals(1) && rows.First()["SubType"] == null || string.IsNullOrEmpty(rows.First()["SubType"].ToString()))
2513
                            {
2514
                                if (topology.Items == null)
2515
                                    continue;
2516 27d06aa8 LJIYEON
2517 3210f690 LJIYEON
                                Item firstItem = topology.Items.First();
2518
                                Item lastItem = topology.Items.Last();
2519 27d06aa8 LJIYEON
2520 3210f690 LJIYEON
                                List<Relation> relations = new List<Relation>();
2521 7881ec8f gaqhf
2522 3210f690 LJIYEON
                                if (firstItem.Relations.FindAll(x => x.Item == null).Count() != 0)
2523
                                    relations.AddRange(firstItem.Relations.FindAll(x => x.Item != null && x.Item.Topology.ID != topology.ID));
2524 7881ec8f gaqhf
2525 3210f690 LJIYEON
                                if (lastItem.Relations.FindAll(x => x.Item == null).Count() != 0)
2526
                                    relations.AddRange(lastItem.Relations.FindAll(x => x.Item != null && x.Item.Topology.ID != topology.ID));
2527
2528
                                if (relations.Count > 0)
2529
                                    rows.First()["SubType"] = "OtherSystem";
2530
                            }
2531 27d06aa8 LJIYEON
                        }
2532
                    }
2533
                    catch (Exception ex)
2534
                    {
2535 7106e181 LJIYEON
2536 27d06aa8 LJIYEON
                        MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
2537
                    }
2538 7881ec8f gaqhf
                }
2539
2540 7106e181 LJIYEON
                foreach (DataRow row in TopologySet.Rows)
2541 27d06aa8 LJIYEON
                    if (row["SubType"] == null || string.IsNullOrEmpty(row["SubType"].ToString()))
2542
                        row["SubType"] = "Normal";
2543
            }
2544
            catch (Exception ex)
2545
            {
2546
                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2547
                MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
2548
            }
2549 7881ec8f gaqhf
        }
2550 5e4c2ad1 LJIYEON
2551 7881ec8f gaqhf
        private bool IsBypass(PSNItem PSNItem)
2552
        {
2553
            bool bResult = false;
2554
2555
            if (PSNItem.GetPSNType() == "B2B")
2556
            {
2557
                Group firstGroup = PSNItem.Groups.First();
2558
                Group lastGroup = PSNItem.Groups.Last();
2559
                Item firstItem = firstGroup.Items.First();
2560
                Item lastItem = lastGroup.Items.Last();
2561
2562
                Item connectedFirstItem = GetConnectedItemByPSN(firstItem);
2563
                Item connectedLastItem = GetConnectedItemByPSN(lastItem);
2564 36a45f13 gaqhf
2565 7881ec8f gaqhf
                if (connectedFirstItem.LineNumber != null && connectedLastItem.LineNumber != null &&
2566
                    !string.IsNullOrEmpty(connectedFirstItem.LineNumber.Name) && !string.IsNullOrEmpty(connectedLastItem.LineNumber.Name) &&
2567
                    connectedFirstItem.LineNumber.Name == connectedLastItem.LineNumber.Name)
2568
                    bResult = true;
2569
                else if (connectedFirstItem.PSNItem == connectedLastItem.PSNItem)
2570
                    bResult = true;
2571
            }
2572 36a45f13 gaqhf
2573
            Item GetConnectedItemByPSN(Item item)
2574
            {
2575
                Item result = null;
2576
2577
                Relation relation = item.Relations.Find(x => x.Item != null && x.Item.PSNItem != item.PSNItem);
2578
                if (relation != null)
2579
                    result = relation.Item;
2580
2581 3210f690 LJIYEON
2582 36a45f13 gaqhf
                return result;
2583
            }
2584 7881ec8f gaqhf
2585
            return bResult;
2586
        }
2587 5e4c2ad1 LJIYEON
2588 419055fa LJIYEON
        private void DeleteVentDrain()
2589
        {
2590
            DataRow[] ventdrainRows = PipeSystemNetwork.Select(" IncludingVirtualData = 'Vent_Drain'");
2591 7106e181 LJIYEON
2592 419055fa LJIYEON
            foreach (DataRow dataRow in ventdrainRows)
2593
            {
2594 7106e181 LJIYEON
                dataRow.Delete();
2595
            }
2596 419055fa LJIYEON
        }
2597
2598 5e4c2ad1 LJIYEON
        private void UpdateAccuracy()
2599
        {
2600 54b6df95 LJIYEON
            //DataRow[] statusRows = PipeSystemNetwork.Select(" Type = 'Error' OR IsValid = 'Error'"); 
2601
            DataRow[] statusRows = PipeSystemNetwork.Select(" Type = 'Error' OR IsValid = 'Error'");
2602 5e4c2ad1 LJIYEON
            List<double> lstAcc = null;
2603
            string Status = string.Empty;
2604 f9f2787b LJIYEON
2605 5e4c2ad1 LJIYEON
            foreach (DataRow dataRow in statusRows)
2606
            {
2607
                lstAcc = new List<double>();
2608
                Status = dataRow.Field<string>("Status");
2609
                if (!string.IsNullOrEmpty(Status))
2610
                {
2611 51974d2b LJIYEON
                    string[] arrStatus = Status.Split(',');
2612 7106e181 LJIYEON
                    foreach (string arrstr in arrStatus)
2613 51974d2b LJIYEON
                    {
2614
                        if (arrstr.Contains(Rule1)) //Missing LineNumber_1
2615
                            lstAcc.Add(0.75);
2616 f9f2787b LJIYEON
2617 51974d2b LJIYEON
                        if (arrstr.Contains(Rule2)) //Missing LineNumber_2
2618
                            lstAcc.Add(0.7);
2619 f9f2787b LJIYEON
2620 51974d2b LJIYEON
                        if (arrstr.Contains(Rule3)) // OPC Disconnected
2621
                            lstAcc.Add(0.5);
2622 f9f2787b LJIYEON
2623 51974d2b LJIYEON
                        if (arrstr.Contains(Rule4)) //Missing ItemTag or Description
2624
                            lstAcc.Add(0.65);
2625
2626
                        if (arrstr.Contains(Rule5)) //Line Disconnected
2627
                            lstAcc.Add(0.6);
2628
                    }
2629 5e4c2ad1 LJIYEON
                }
2630
2631
                string PSNAccuracy = dataRow["PSNAccuracy"].ToString();
2632
                if (PSNAccuracy == "100")
2633
                    PSNAccuracy = "1";
2634
2635 51974d2b LJIYEON
                PSNAccuracy = Convert.ToString(Convert.ToDecimal(AccuracyCalculation(lstAcc, Convert.ToDouble(PSNAccuracy))));
2636
                //if (PSNAccuracy != "100")
2637
                //{
2638
                //    //dataRow["IncludingVirtualData"] = "No";
2639 7106e181 LJIYEON
                dataRow["PSNAccuracy"] = PSNAccuracy;
2640 51974d2b LJIYEON
                //}
2641 5e4c2ad1 LJIYEON
            }
2642 bfe278bb LJIYEON
            DataTable dt = PipeSystemNetwork.DefaultView.ToTable(true, new string[] { "OID" });
2643
            foreach (DataRow dr in dt.Rows)
2644
            {
2645
                string oid = dr.Field<string>("OID");
2646
                DataRow[] select = PipeSystemNetwork.Select(string.Format("OID = '{0}'", oid));
2647
                double totalDdr = 0;
2648
                foreach (DataRow ddr in select)
2649
                {
2650
                    double acc = Convert.ToDouble(ddr.Field<string>("PSNAccuracy"));
2651
                    if (acc == 100) acc = 1;
2652
                    if (totalDdr == 0) totalDdr = acc;
2653
                    else totalDdr *= acc;
2654
                }
2655
2656
                totalDdr *= 100;
2657
2658 7106e181 LJIYEON
                if (totalDdr != 100)
2659 bfe278bb LJIYEON
                {
2660 f9f2787b LJIYEON
                    foreach (DataRow ddr in select)
2661
                    {
2662
                        ddr["IncludingVirtualData"] = "Yes";
2663 51974d2b LJIYEON
                        ddr["PSNAccuracy"] = String.Format("{0:0.00}", Math.Round(totalDdr, 2));
2664
                    }
2665
                }
2666
                else
2667
                {
2668
                    foreach (DataRow ddr in select)
2669
                    {
2670
                        ddr["IncludingVirtualData"] = "No";
2671
                        ddr["PSNAccuracy"] = String.Format("{0:0.00}", Math.Round(totalDdr, 2));
2672 f9f2787b LJIYEON
                    }
2673 bfe278bb LJIYEON
                }
2674
            }
2675
2676 5e4c2ad1 LJIYEON
        }
2677
2678 a5616391 LJIYEON
        private void UpdateKeywordForPSN()
2679
        {
2680
            #region Keyword Info
2681
            KeywordInfo KeywordInfos = new KeywordInfo();
2682
            DataTable dtKeyword = DB.SelectKeywordsSetting();
2683
            foreach (DataRow row in dtKeyword.Rows)
2684
            {
2685
                int index = Convert.ToInt32(row["INDEX"]);
2686
                string name = row["NAME"].ToString();
2687
                string keyword = row["KEYWORD"].ToString();
2688
2689
                //KeywordInfo keywordInfo = new KeywordInfo();   
2690
                KeywordInfos.KeywordItems.Add(new KeywordItem()
2691
                {
2692
                    Index = index,
2693
                    Name = name,
2694
                    Keyword = keyword
2695
                });
2696
            }
2697
            #endregion
2698
2699 a2973aa3 LJIYEON
            DataRow[] endofHeaderRows = PipeSystemNetwork.Select(string.Format(" From_Data = '{0}' OR To_Data = '{0}'", "ENDOFHEADER"));
2700
            foreach (DataRow dataRow in endofHeaderRows)
2701
            {
2702
                PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString());
2703
2704
                if (dataRow.Field<string>("From_Data") == "ENDOFHEADER")
2705
                {
2706
                    DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
2707
                    DataRow dr = pathItemRows.First();
2708
                    dr["CLASS"] = PSNItem.Groups.First().Items.First().ID2DBName;
2709
                    dr["TYPE"] = "End";
2710
                    dr["ITEMTAG"] = "ENDOFHEADER";
2711
                    dr["DESCRIPTION"] = "ENDOFHEADER";
2712
                }
2713
2714
                if (dataRow.Field<string>("To_Data") == "ENDOFHEADER")
2715
                {
2716
                    DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
2717
                    DataRow dr = pathItemRows.Last();
2718
                    dr["CLASS"] = PSNItem.Groups.Last().Items.Last().ID2DBName;
2719
                    dr["TYPE"] = "End";
2720
                    dr["ITEMTAG"] = "ENDOFHEADER";
2721
                    dr["DESCRIPTION"] = "ENDOFHEADER";
2722
                }
2723
            }
2724
2725 a5616391 LJIYEON
            foreach (KeywordItem keyitem in KeywordInfos.KeywordItems)
2726
            {
2727 a2973aa3 LJIYEON
                DataRow[] keywordRows = PipeSystemNetwork.Select(string.Format(" From_Data = '{0}' OR To_Data = '{0}'", keyitem.Keyword));
2728 a5616391 LJIYEON
                foreach (DataRow dataRow in keywordRows)
2729 7106e181 LJIYEON
                {
2730
                    PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString());
2731 a5616391 LJIYEON
2732 7106e181 LJIYEON
                    if (dataRow.Field<string>("From_Data") == keyitem.Keyword)
2733
                    {
2734 a5616391 LJIYEON
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
2735 7106e181 LJIYEON
2736 a2973aa3 LJIYEON
                        //
2737
                        //if(.)
2738 7106e181 LJIYEON
                        if (PSNItem.Groups.First().Items.First().Name.Equals(keyitem.Name))
2739 a5616391 LJIYEON
                        {
2740
                            DataRow dr = pathItemRows.First();
2741
                            //dr["CLASS"] = ""; //Type
2742
                            dr["TYPE"] = "End";
2743
                            dr["ITEMTAG"] = keyitem.Keyword;
2744
                            dr["DESCRIPTION"] = keyitem.Keyword;
2745
                        }
2746 7106e181 LJIYEON
2747 a5616391 LJIYEON
                    }
2748
2749 a2973aa3 LJIYEON
                    if (dataRow.Field<string>("To_Data") == keyitem.Keyword)
2750 a5616391 LJIYEON
                    {
2751
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
2752
2753 a2973aa3 LJIYEON
                        if (PSNItem.Groups.Last().Items.Last().Name.Equals(keyitem.Name))
2754 a5616391 LJIYEON
                        {
2755
                            DataRow dr = pathItemRows.Last();
2756
                            //dr["CLASS"] = ""; //Type
2757
                            dr["TYPE"] = "End";
2758
                            dr["ITEMTAG"] = keyitem.Keyword;
2759
                            dr["DESCRIPTION"] = keyitem.Keyword;
2760
                            //dr.Field<string>("Type")
2761
                        }
2762
2763 7106e181 LJIYEON
                    }
2764 a5616391 LJIYEON
                }
2765 7106e181 LJIYEON
            }
2766 a5616391 LJIYEON
        }
2767
2768 7881ec8f gaqhf
        private void UpdateErrorForPSN()
2769
        {
2770 45529c16 LJIYEON
            DataRow[] errorRows = PipeSystemNetwork.Select(string.Format(" Type = '{0}'", ErrorType.Error));
2771 7881ec8f gaqhf
            foreach (DataRow dataRow in errorRows)
2772
            {
2773 eb44d82c LJIYEON
                try
2774 710a49f1 gaqhf
                {
2775 eb44d82c LJIYEON
                    PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString());
2776
                    bool change = false;
2777 aa195a5b LJIYEON
                    bool bCheck = false;
2778
                    int bCount = 0;
2779 eb44d82c LJIYEON
                    if (!PSNItem.EnableType(PSNItem.StartType))
2780 710a49f1 gaqhf
                    {
2781 eb44d82c LJIYEON
                        change = true;
2782 aa195a5b LJIYEON
                        bCheck = change;
2783 7106e181 LJIYEON
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
2784 eb44d82c LJIYEON
                        int insertIndex = PathItems.Rows.IndexOf(pathItemRows.First());
2785 7106e181 LJIYEON
2786 eb44d82c LJIYEON
                        Item item = PSNItem.Groups.First().Items.First();
2787
                        try
2788 a36541fb LJIYEON
                        {
2789
                            string FROM_DATA = string.Format("TIEINPOINT_{0:D5}V", tieInPointIndex);
2790 7106e181 LJIYEON
2791 eb44d82c LJIYEON
                            tieInPointIndex++;
2792 5e4c2ad1 LJIYEON
2793 7881ec8f gaqhf
2794 eb44d82c LJIYEON
                            if (item.ItemType == ItemType.Line)
2795
                            {
2796 a36541fb LJIYEON
                                PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.First(), FROM_DATA), insertIndex);
2797 aa195a5b LJIYEON
                                bCount = 2;
2798 48870200 LJIYEON
2799
                                foreach (DataRow loopRow in PipeSystemNetwork.Select(string.Format("OID = '{0}'", PSNItem.PSN_OID())))
2800
                                {
2801
                                    loopRow["FROM_DATA"] = FROM_DATA;
2802
                                    if (loopRow.Field<string>("OrderNumber") == "0")
2803
                                    {
2804
                                        string status = loopRow.Field<string>("Status");
2805 7106e181 LJIYEON
                                        //string isvali
2806 48870200 LJIYEON
                                        if (string.IsNullOrEmpty(status))
2807
                                            status = "Line Disconnected";
2808
                                        else if (!status.Contains("Line Disconnected"))
2809
                                            status += ", Line Disconnected";
2810
                                        loopRow["Status"] = status;
2811 7106e181 LJIYEON
                                        if (!string.IsNullOrEmpty(status))
2812
                                            loopRow["IsValid"] = "Error";
2813 48870200 LJIYEON
                                    }
2814
                                }
2815 eb44d82c LJIYEON
                            }
2816
                            else
2817
                            {
2818 d1afd412 이지연
                                if(PathItems.Select(string.Format("PipeLine_OID = '{0}' AND ItemName = 'PipeRun' AND PipeSystemNetwork_OID = '{1}'", item.PSNPipeLineID, dataRow["OID"])).Count() > 0)
2819
                                    PathItems.Rows.InsertAt(createLineRow(PathItems.Select(string.Format("PipeLine_OID = '{0}' AND ItemName = 'PipeRun' AND PipeSystemNetwork_OID = '{1}'", item.PSNPipeLineID, dataRow["OID"])).First()), insertIndex);
2820 7106e181 LJIYEON
2821 d1afd412 이지연
                                    PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.First(), FROM_DATA), insertIndex);
2822
                                   
2823
                                
2824 aa195a5b LJIYEON
                                bCount = 3;
2825 eb44d82c LJIYEON
                            }
2826 710a49f1 gaqhf
2827 eb44d82c LJIYEON
                            PSNItem.StartType = PSNType.Equipment;
2828
                        }
2829
                        catch (Exception ex)
2830
                        {
2831
                            MessageBox.Show("Please check the item.\r\nDrawingName : " + item.Document.DrawingName + "\r\nUID : " + item.UID, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
2832
                            return;
2833
                        }
2834
                    }
2835 710a49f1 gaqhf
2836 eb44d82c LJIYEON
                    if (!PSNItem.EnableType(PSNItem.EndType))
2837 710a49f1 gaqhf
                    {
2838 eb44d82c LJIYEON
                        change = true;
2839
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
2840 f6c9db1a 이지연
                        //int insertIndex = PathItems.Rows.IndexOf(pathItemRows.First()) + pathItemRows.Count() - 1;
2841
                        DataRow dr = pathItemRows.Last();
2842
                        if (change)
2843
                            dr = pathItemRows[pathItemRows.Count() - bCount];
2844
2845
                        int insertIndex = PathItems.Rows.IndexOf(dr) + 1;
2846 a36541fb LJIYEON
2847 eb44d82c LJIYEON
                        Item item = PSNItem.Groups.Last().Items.Last();
2848
                        try
2849 a36541fb LJIYEON
                        {
2850
                            string TO_DATA = string.Format("TIEINPOINT_{0:D5}V", tieInPointIndex);
2851
2852 48870200 LJIYEON
                            if (item.ItemType == ItemType.Line)
2853 51974d2b LJIYEON
                            {
2854 48870200 LJIYEON
                                foreach (DataRow loopRow in PipeSystemNetwork.Select(string.Format("OID = '{0}'", PSNItem.PSN_OID())))
2855 51974d2b LJIYEON
                                {
2856 48870200 LJIYEON
                                    loopRow["TO_DATA"] = TO_DATA;
2857
                                    if (loopRow.Field<string>("OrderNumber") == Convert.ToString(PipeSystemNetwork.Select(string.Format("OID = '{0}'", PSNItem.PSN_OID())).Count() - 1))
2858
                                    {
2859
                                        string status = loopRow.Field<string>("Status");
2860
                                        if (string.IsNullOrEmpty(status))
2861
                                            status = "Line Disconnected";
2862
                                        else if (!status.Contains("Line Disconnected"))
2863
                                            status += ", Line Disconnected";
2864
                                        loopRow["Status"] = status;
2865 7106e181 LJIYEON
                                        if (!string.IsNullOrEmpty(status))
2866
                                            loopRow["IsValid"] = "Error";
2867 48870200 LJIYEON
                                    }
2868 51974d2b LJIYEON
                                }
2869
                            }
2870 48870200 LJIYEON
2871 eb44d82c LJIYEON
                            tieInPointIndex++;
2872 7106e181 LJIYEON
2873 f6c9db1a 이지연
                            if (item.ItemType == ItemType.Line)
2874 eb44d82c LJIYEON
                            {
2875 f6c9db1a 이지연
                                PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.Last(), TO_DATA), insertIndex);
2876 eb44d82c LJIYEON
                            }
2877
                            else
2878
                            {
2879 f6c9db1a 이지연
                                PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.Last(), TO_DATA), insertIndex);
2880 d1afd412 이지연
                                if(PathItems.Select(string.Format("PipeLine_OID = '{0}' AND ItemName = 'PipeRun' AND PipeSystemNetwork_OID = '{1}'", item.PSNPipeLineID, dataRow["OID"])).Count() > 0)
2881
                                    PathItems.Rows.InsertAt(createLineRow(PathItems.Select(string.Format("PipeLine_OID = '{0}' AND ItemName = 'PipeRun' AND PipeSystemNetwork_OID = '{1}'", item.PSNPipeLineID, dataRow["OID"])).Last()), insertIndex);
2882 eb44d82c LJIYEON
                            }
2883 7106e181 LJIYEON
2884 eb44d82c LJIYEON
                            PSNItem.EndType = PSNType.Equipment;
2885
                        }
2886 7106e181 LJIYEON
                        catch (Exception ex)
2887 eb44d82c LJIYEON
                        {
2888
                            MessageBox.Show("Please check the item.\r\nDrawingName : " + item.Document.DrawingName + "\r\nUID : " + item.UID, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
2889
                            return;
2890
                        }
2891 710a49f1 gaqhf
                    }
2892 eb44d82c LJIYEON
2893
                    dataRow["Type"] = PSNItem.GetPSNType();
2894
                    if (change)
2895 710a49f1 gaqhf
                    {
2896 eb44d82c LJIYEON
                        int rowIndex = 0;
2897
                        for (int i = 0; i < PathItems.Rows.Count; i++)
2898
                        {
2899
                            DataRow row = PathItems.Rows[i];
2900
                            if (row["PipeSystemNetwork_OID"].ToString() != dataRow["OID"].ToString())
2901
                                continue;
2902
                            string sequenceData = row["SequenceData_OID"].ToString();
2903
                            string[] split = sequenceData.Split(new char[] { '_' });
2904
2905
                            StringBuilder sb = new StringBuilder();
2906
                            for (int j = 0; j < split.Length - 1; j++)
2907
                                sb.Append(split[j] + "_");
2908
                            sb.Append(rowIndex++);
2909
                            row["SequenceData_OID"] = sb.ToString();
2910 a36541fb LJIYEON
2911 3210f690 LJIYEON
                            DataRow seqItemRows = SequenceData.Select(string.Format("PathItem_OID = '{0}'", row["OID"])).FirstOrDefault();
2912
                            int insertSeqIndex = SequenceData.Rows.IndexOf(seqItemRows);
2913
2914
                            string[] splitseq = sb.ToString().Split(new char[] { '_' });
2915
2916
                            if (seqItemRows == null)
2917
                            {
2918 7106e181 LJIYEON
                                DataRow newRow = SequenceData.NewRow();
2919 3210f690 LJIYEON
                                newRow["OID"] = sb.ToString();
2920
                                newRow["SERIALNUMBER"] = splitseq[splitseq.Length - 1];
2921
                                newRow["PathItem_OID"] = row["OID"];
2922
                                newRow["TopologySet_OID_Key"] = row["TopologySet_OID"];
2923
                                SequenceData.Rows.InsertAt(newRow, Convert.ToInt32(splitseq[splitseq.Length - 1]));
2924
                            }
2925
                            else
2926
                            {
2927
                                seqItemRows["OID"] = sb.ToString();
2928
                                seqItemRows["SERIALNUMBER"] = splitseq[splitseq.Length - 1];
2929
                                seqItemRows["PathItem_OID"] = row["OID"];
2930
                                seqItemRows["TopologySet_OID_Key"] = row["TopologySet_OID"];
2931 7106e181 LJIYEON
                            }
2932
                        }
2933 eb44d82c LJIYEON
                    }
2934 5e4c2ad1 LJIYEON
2935 a36541fb LJIYEON
                    DataRow createTerminatorRow(DataRow itemRow, string DATA)
2936 eb44d82c LJIYEON
                    {
2937
                        DataRow newRow = PathItems.NewRow();
2938
                        newRow["OID"] = Guid.NewGuid().ToString();
2939
                        newRow["SequenceData_OID"] = itemRow["SequenceData_OID"];
2940
                        newRow["TopologySet_OID"] = itemRow["TopologySet_OID"];
2941
                        newRow["BranchTopologySet_OID"] = itemRow["BranchTopologySet_OID"];
2942 7106e181 LJIYEON
                        newRow["PipeLine_OID"] = itemRow["PipeLine_OID"];
2943 a36541fb LJIYEON
                        newRow["ITEMNAME"] = "PipingComp"; //newRow["ITEMNAME"] = "End of line terminator";
2944
                        newRow["ITEMTAG"] = DATA; //itemRow["ITEMTAG"];
2945 7106e181 LJIYEON
                        newRow["DESCRIPTION"] = DATA;
2946 eb44d82c LJIYEON
                        newRow["Class"] = "End of line terminator";
2947
                        newRow["SubClass"] = "End of line terminator";
2948 a36541fb LJIYEON
                        newRow["TYPE"] = "End";
2949 eb44d82c LJIYEON
                        newRow["PIDNAME"] = itemRow["PIDNAME"];
2950
                        newRow["NPD"] = itemRow["NPD"];
2951
                        newRow["PipeSystemNetwork_OID"] = itemRow["PipeSystemNetwork_OID"];
2952
                        newRow["ViewPipeSystemNetwork_OID"] = itemRow["ViewPipeSystemNetwork_OID"];
2953 7106e181 LJIYEON
                        newRow["PipeRun_OID"] = itemRow["PipeRun_OID"];
2954 0d4b3dee 이지연
                        newRow["EGTConnectedPoint"] = "0";
2955 a36541fb LJIYEON
                        return newRow;
2956
                    }
2957
2958 eb44d82c LJIYEON
                    DataRow createLineRow(DataRow itemRow)
2959 710a49f1 gaqhf
                    {
2960 eb44d82c LJIYEON
                        DataRow newRow = PathItems.NewRow();
2961
                        newRow["OID"] = Guid.NewGuid().ToString();
2962
                        newRow["SequenceData_OID"] = itemRow["SequenceData_OID"];
2963
                        newRow["TopologySet_OID"] = itemRow["TopologySet_OID"];
2964
                        newRow["BranchTopologySet_OID"] = itemRow["BranchTopologySet_OID"];
2965
                        newRow["PipeLine_OID"] = itemRow["PipeLine_OID"];
2966
                        newRow["ITEMNAME"] = itemRow["ITEMNAME"];
2967
                        newRow["ITEMTAG"] = itemRow["ITEMTAG"];
2968
                        newRow["Class"] = itemRow["Class"];
2969
                        newRow["SubClass"] = itemRow["SubClass"];
2970
                        newRow["TYPE"] = itemRow["TYPE"];
2971
                        newRow["PIDNAME"] = itemRow["PIDNAME"];
2972
                        newRow["NPD"] = itemRow["NPD"];
2973
                        newRow["PipeSystemNetwork_OID"] = itemRow["PipeSystemNetwork_OID"];
2974
                        newRow["ViewPipeSystemNetwork_OID"] = itemRow["ViewPipeSystemNetwork_OID"];
2975
                        newRow["PipeRun_OID"] = itemRow["PipeRun_OID"];
2976 0d4b3dee 이지연
                        newRow["EGTConnectedPoint"] = "0";
2977 eb44d82c LJIYEON
                        return newRow;
2978 710a49f1 gaqhf
                    }
2979
                }
2980 7106e181 LJIYEON
                catch (Exception ex)
2981 5e4c2ad1 LJIYEON
                {
2982 710a49f1 gaqhf
2983
                }
2984 eb44d82c LJIYEON
            }
2985 6b9e7a56 gaqhf
        }
2986 4e2e0aa1 LJIYEON
2987
        private void InsertTeePSN()
2988
        {
2989 3f5cb4dc LJIYEON
            DataTable dt = PipeSystemNetwork.DefaultView.ToTable(true, new string[] { "OID", "Type" });
2990
            DataRow[] branchRows = dt.Select("Type Like '%B%'");
2991 820e283f LJIYEON
            bool change = false;
2992 4e2e0aa1 LJIYEON
            foreach (DataRow dataRow in branchRows)
2993
            {
2994
                try
2995 7106e181 LJIYEON
                {
2996 4e2e0aa1 LJIYEON
                    PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString());
2997 820e283f LJIYEON
                    change = false;
2998
2999 4e2e0aa1 LJIYEON
                    if (PSNItem.StartType == PSNType.Branch)
3000
                    {
3001 820e283f LJIYEON
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", PSNItem.PSN_OID()));
3002 4e2e0aa1 LJIYEON
                        int insertIndex = PathItems.Rows.IndexOf(pathItemRows.First());
3003 820e283f LJIYEON
                        Item Teeitem = PSNItem.Groups.First().Items.First();
3004 4e2e0aa1 LJIYEON
                        try
3005 820e283f LJIYEON
                        {
3006
                            if (Teeitem.ItemType == ItemType.Line)
3007 4e2e0aa1 LJIYEON
                            {
3008
                                if (pathItemRows.First().Field<string>("SubClass") != "Tee")
3009 7106e181 LJIYEON
                                {
3010 4e2e0aa1 LJIYEON
                                    PathItems.Rows.InsertAt(createTeeRow(pathItemRows.First()), insertIndex);
3011 0e9d868c LJIYEON
                                    pathItemRows.First().SetField("BranchTopologySet_OID", string.Empty);
3012
                                    pathItemRows.First().SetField("ViewPipeSystemNetwork_OID", dataRow["OID"].ToString());
3013 820e283f LJIYEON
                                    change = true;
3014 4e2e0aa1 LJIYEON
                                }
3015
3016 820e283f LJIYEON
                            }
3017 4e2e0aa1 LJIYEON
                        }
3018
                        catch (Exception ex)
3019
                        {
3020 820e283f LJIYEON
                            MessageBox.Show("Please check the item.\r\nDrawingName : " + Teeitem.Document.DrawingName + "\r\nUID : " + Teeitem.UID, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
3021 4e2e0aa1 LJIYEON
                            return;
3022
                        }
3023
                    }
3024
3025
                    if (PSNItem.EndType == PSNType.Branch)
3026
                    {
3027 820e283f LJIYEON
                        //change = true;
3028
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", PSNItem.PSN_OID()));
3029 7106e181 LJIYEON
3030 820e283f LJIYEON
                        Item Teeitem = PSNItem.Groups.Last().Items.Last();
3031 4e2e0aa1 LJIYEON
3032 820e283f LJIYEON
                        DataRow dr = pathItemRows.Last();
3033
                        if (change)
3034
                            dr = pathItemRows[pathItemRows.Count() - 2];
3035 e36ca22f LJIYEON
3036 b683578e LJIYEON
                        int insertIndex = PathItems.Rows.IndexOf(dr) + 1;
3037 e36ca22f LJIYEON
3038 4e2e0aa1 LJIYEON
                        try
3039
                        {
3040 820e283f LJIYEON
                            if (Teeitem.ItemType == ItemType.Line)
3041 4e2e0aa1 LJIYEON
                            {
3042 820e283f LJIYEON
                                if (dr.Field<string>("SubClass") != "Tee")
3043
                                {
3044
                                    PathItems.Rows.InsertAt(createTeeRow(dr), insertIndex);
3045
                                    change = true;
3046 0e9d868c LJIYEON
                                    dr.SetField("BranchTopologySet_OID", string.Empty);
3047
                                    dr.SetField("ViewPipeSystemNetwork_OID", dataRow["OID"].ToString());
3048 820e283f LJIYEON
                                }
3049
3050 4e2e0aa1 LJIYEON
                            }
3051
                        }
3052
                        catch (Exception ex)
3053
                        {
3054 820e283f LJIYEON
                            MessageBox.Show("Please check the item.\r\nDrawingName : " + Teeitem.Document.DrawingName + "\r\nUID : " + Teeitem.UID, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
3055 4e2e0aa1 LJIYEON
                            return;
3056
                        }
3057
                    }
3058
3059
                    if (change)
3060
                    {
3061 820e283f LJIYEON
                        //DataRow[] pathItemRows = pathItemsDT.Select(string.Format("PipeSystemNetwork_OID = '{0}'", PSNItem.PSN_OID()));
3062 4e2e0aa1 LJIYEON
                        int rowIndex = 0;
3063
                        for (int i = 0; i < PathItems.Rows.Count; i++)
3064
                        {
3065
                            DataRow row = PathItems.Rows[i];
3066 820e283f LJIYEON
                            if (row["PipeSystemNetwork_OID"].ToString() != PSNItem.PSN_OID())
3067 4e2e0aa1 LJIYEON
                                continue;
3068
                            string sequenceData = row["SequenceData_OID"].ToString();
3069
                            string[] split = sequenceData.Split(new char[] { '_' });
3070
3071
                            StringBuilder sb = new StringBuilder();
3072
                            for (int j = 0; j < split.Length - 1; j++)
3073
                                sb.Append(split[j] + "_");
3074
                            sb.Append(rowIndex++);
3075
                            row["SequenceData_OID"] = sb.ToString();
3076
3077
                            DataRow seqItemRows = SequenceData.Select(string.Format("PathItem_OID = '{0}'", row["OID"])).FirstOrDefault();
3078
                            int insertSeqIndex = SequenceData.Rows.IndexOf(seqItemRows);
3079
3080
                            string[] splitseq = sb.ToString().Split(new char[] { '_' });
3081
3082
                            if (seqItemRows == null)
3083
                            {
3084
                                DataRow newRow = SequenceData.NewRow();
3085
                                newRow["OID"] = sb.ToString();
3086
                                newRow["SERIALNUMBER"] = splitseq[splitseq.Length - 1];
3087
                                newRow["PathItem_OID"] = row["OID"];
3088
                                newRow["TopologySet_OID_Key"] = row["TopologySet_OID"];
3089
                                SequenceData.Rows.InsertAt(newRow, Convert.ToInt32(splitseq[splitseq.Length - 1]));
3090
                            }
3091
                            else
3092
                            {
3093
                                seqItemRows["OID"] = sb.ToString();
3094
                                seqItemRows["SERIALNUMBER"] = splitseq[splitseq.Length - 1];
3095
                                seqItemRows["PathItem_OID"] = row["OID"];
3096
                                seqItemRows["TopologySet_OID_Key"] = row["TopologySet_OID"];
3097
                            }
3098
                        }
3099 820e283f LJIYEON
                    }
3100 7106e181 LJIYEON
3101 4e2e0aa1 LJIYEON
                    DataRow createTeeRow(DataRow itemRow)
3102
                    {
3103
                        DataRow newRow = PathItems.NewRow();
3104
                        newRow["OID"] = Guid.NewGuid().ToString();
3105
                        newRow["SequenceData_OID"] = itemRow["SequenceData_OID"];
3106
                        newRow["TopologySet_OID"] = itemRow["TopologySet_OID"];
3107
                        newRow["BranchTopologySet_OID"] = itemRow["BranchTopologySet_OID"];
3108
                        newRow["PipeLine_OID"] = itemRow["PipeLine_OID"];
3109
                        newRow["ITEMNAME"] = "Branch"; //newRow["ITEMNAME"] = "End of line terminator";
3110
                        newRow["ITEMTAG"] = itemRow["ITEMTAG"];
3111
                        newRow["DESCRIPTION"] = "";
3112
                        newRow["Class"] = "Branch";
3113
                        newRow["SubClass"] = "Tee";
3114
                        newRow["TYPE"] = itemRow["TYPE"];
3115
                        newRow["PIDNAME"] = itemRow["PIDNAME"];
3116
                        newRow["NPD"] = itemRow["NPD"];
3117
                        newRow["PipeSystemNetwork_OID"] = itemRow["PipeSystemNetwork_OID"];
3118
                        newRow["ViewPipeSystemNetwork_OID"] = itemRow["ViewPipeSystemNetwork_OID"];
3119
                        newRow["PipeRun_OID"] = itemRow["PipeRun_OID"];
3120 0eefef3d 이지연
                      
3121
                        newRow["EGTConnectedPoint"] = 0;
3122 4e2e0aa1 LJIYEON
                        return newRow;
3123
                    }
3124
                }
3125
                catch (Exception ex)
3126
                {
3127
3128
                }
3129
            }
3130
        }
3131 6b9e7a56 gaqhf
    }
3132
3133
    public class PSNItem
3134
    {
3135 8f24b438 gaqhf
        public PSNItem(int count, int Revision)
3136 6b9e7a56 gaqhf
        {
3137
            Groups = new List<Group>();
3138
            Topologies = new List<Topology>();
3139 94a117ca gaqhf
3140
            Index = count + 1;
3141 8f24b438 gaqhf
            this.Revision = Revision;
3142 6b9e7a56 gaqhf
        }
3143 eb44d82c LJIYEON
3144 8f24b438 gaqhf
        private int Revision;
3145 6b9e7a56 gaqhf
        public string UID { get; set; }
3146
        public List<Group> Groups { get; set; }
3147
        public List<Topology> Topologies { get; set; }
3148
        public PSNType StartType { get; set; }
3149
        public PSNType EndType { get; set; }
3150 94a117ca gaqhf
        public int Index { get; set; }
3151 72775f2e LJIYEON
        public string IsValid { get; set; }
3152 a36541fb LJIYEON
        public bool IsKeyword { get; set; }
3153 36a45f13 gaqhf
        public string Status { get; set; }
3154 ddc1c369 LJIYEON
        public string IncludingVirtualData { get; set; }
3155
        public string PSNAccuracy { get; set; }
3156 eb44d82c LJIYEON
        public KeywordInfo KeywordInfos = new KeywordInfo();
3157 a36541fb LJIYEON
        public DataTable Nozzle = new DataTable();
3158 ddc1c369 LJIYEON
3159 94a117ca gaqhf
        public string PSN_OID()
3160
        {
3161 36a45f13 gaqhf
            return string.Format("V{0}-PSN-{1}", string.Format("{0:D4}", Revision), string.Format("{0:D5}", Index));
3162 94a117ca gaqhf
        }
3163 3610fd3f LJIYEON
3164 94a117ca gaqhf
        public string GetPSNType()
3165
        {
3166
            string result = string.Empty;
3167
3168
            if (EnableType(StartType) && EnableType(EndType))
3169
            {
3170
                if (StartType == PSNType.Equipment && EndType == PSNType.Equipment)
3171
                    result = "E2E";
3172
                else if (StartType == PSNType.Branch && EndType == PSNType.Branch)
3173
                    result = "B2B";
3174
                else if (StartType == PSNType.Header && EndType == PSNType.Header)
3175
                    result = "HD2";
3176
3177
                else if (StartType == PSNType.Equipment && EndType == PSNType.Branch)
3178
                    result = "E2B";
3179
                else if (StartType == PSNType.Branch && EndType == PSNType.Equipment)
3180
                    result = "B2E";
3181
3182
                else if (StartType == PSNType.Header && EndType == PSNType.Branch)
3183
                    result = "HDB";
3184
                else if (StartType == PSNType.Branch && EndType == PSNType.Header)
3185
                    result = "HDB";
3186
3187
                else if (StartType == PSNType.Header && EndType == PSNType.Equipment)
3188
                    result = "HDE";
3189
                else if (StartType == PSNType.Equipment && EndType == PSNType.Header)
3190
                    result = "HDE";
3191
                else
3192
                    result = "Error";
3193
            }
3194
            else
3195
                result = "Error";
3196
3197
            return result;
3198
3199 7106e181 LJIYEON
3200 94a117ca gaqhf
        }
3201 3610fd3f LJIYEON
3202 710a49f1 gaqhf
        public bool EnableType(PSNType type)
3203 94a117ca gaqhf
        {
3204
            bool result = false;
3205
3206
            if (type == PSNType.Branch ||
3207
                type == PSNType.Equipment ||
3208
                type == PSNType.Header)
3209
            {
3210
                result = true;
3211
            }
3212
3213
            return result;
3214
        }
3215 3610fd3f LJIYEON
3216 7881ec8f gaqhf
        public bool IsBypass { get; set; }
3217 94a117ca gaqhf
3218 a5616391 LJIYEON
        public string GetFromData(ref string Type, ref Item item)
3219 94a117ca gaqhf
        {
3220 51974d2b LJIYEON
            Status = string.Empty;
3221 94a117ca gaqhf
            string result = string.Empty;
3222 a36541fb LJIYEON
            if (IsKeyword)
3223
                IsKeyword = false;
3224 27d06aa8 LJIYEON
            try
3225 36a45f13 gaqhf
            {
3226 08b33e44 gaqhf
                item = Groups.First().Items.First();
3227
3228 27d06aa8 LJIYEON
                if (StartType == PSNType.Header)
3229
                    result = "ENDOFHEADER";
3230
                else if (StartType == PSNType.Branch)
3231
                {
3232 48870200 LJIYEON
                    //if (!item.MissingLineNumber && item.Relations.First().Item.LineNumber != null && !string.IsNullOrEmpty(item.Relations.First().Item.LineNumber.Name))
3233 f2a63376 이지연
                    if (!item.MissingLineNumber2 && item.Relations.First().Item.LineNumber != null && !string.IsNullOrEmpty(item.Relations.First().Item.LineNumber.Name))
3234 27d06aa8 LJIYEON
                        result = item.Relations.First().Item.LineNumber.Name;
3235
                    else
3236
                    {
3237 7106e181 LJIYEON
                        IsValid = "Error";
3238 51974d2b LJIYEON
                        Status += ", Missing LineNumber_2";
3239 27d06aa8 LJIYEON
                        result = "Empty LineNumber";
3240
                    }
3241 48870200 LJIYEON
3242
                    //if (item.MissingLineNumber1)
3243
                    //{
3244
                    //    Status += ", Missing LineNumber_1";
3245
                    //    result = item.MissingLineNumber1 && item.LineNumber != null && !string.IsNullOrEmpty(item.LineNumber.Name) ? item.LineNumber.Name : "Empty LineNumber";
3246
3247
                    //}
3248 27d06aa8 LJIYEON
                }
3249
                else if (StartType == PSNType.Equipment)
3250 a36541fb LJIYEON
                {
3251 3210f690 LJIYEON
                    if (Groups.First().Items.First().Equipment != null)
3252
                        result = Groups.First().Items.First().Equipment.ItemTag;
3253 a36541fb LJIYEON
                    DataRow drNozzle = Nozzle.Select(string.Format("OID = '{0}'", Groups.First().Items.First().UID)).FirstOrDefault();
3254
3255
                    if (drNozzle != null)
3256 7106e181 LJIYEON
                        result += " [" + drNozzle.Field<string>("ITEMTAG") + "]";
3257
                }
3258 36a45f13 gaqhf
                else
3259
                {
3260 72775f2e LJIYEON
                    IsValid = "Error";
3261 a5616391 LJIYEON
                    item = Groups.First().Items.First();
3262 27d06aa8 LJIYEON
                    if (item.ItemType == ItemType.Symbol)
3263
                    {
3264 7106e181 LJIYEON
3265 8ab98ea3 LJIYEON
                        string keyword = string.Empty;
3266 a5616391 LJIYEON
                        keyword = GetFromKeywordData(ref Type, item);
3267 8ab98ea3 LJIYEON
3268
                        if (string.IsNullOrEmpty(keyword))
3269
                        {
3270
                            if (item.ID2DBType.Contains("OPC's"))
3271 51974d2b LJIYEON
                                Status += ", OPC Disconnected";
3272 8ab98ea3 LJIYEON
                            else
3273
                                Status += ", Missing ItemTag or Description";
3274
3275
                            result = item.ID2DBName;
3276
                        }
3277
                        else
3278 eb44d82c LJIYEON
                        {
3279 8ab98ea3 LJIYEON
                            result = keyword;
3280 a36541fb LJIYEON
                            IsKeyword = true;
3281
                            IsValid = string.Empty;
3282 eb44d82c LJIYEON
                        }
3283 7106e181 LJIYEON
3284 27d06aa8 LJIYEON
                    }
3285
                    else if (item.ItemType == ItemType.Line)
3286
                    {
3287 7106e181 LJIYEON
3288 48870200 LJIYEON
                        if (item.MissingLineNumber1)
3289
                        {
3290 7106e181 LJIYEON
                            IsValid = "Error";
3291 48870200 LJIYEON
                            Status += ", Missing LineNumber_1";
3292
                            result = item.MissingLineNumber1 && item.LineNumber != null && !string.IsNullOrEmpty(item.LineNumber.Name) ? item.LineNumber.Name : "Empty LineNumber";
3293
                        }
3294 f6c9db1a 이지연
                        else
3295
                            result = !string.IsNullOrEmpty(item.LineNumber.Name) ? item.LineNumber.Name : "Empty LineNumber";
3296 27d06aa8 LJIYEON
                    }
3297
                    else
3298
                        result = "Unknown";
3299 48870200 LJIYEON
3300 36a45f13 gaqhf
                }
3301
            }
3302 7106e181 LJIYEON
            catch (Exception ex)
3303 36a45f13 gaqhf
            {
3304
3305
            }
3306 94a117ca gaqhf
3307
            return result;
3308
        }
3309
3310 a5616391 LJIYEON
        public string GetFromKeywordData(ref string Type, Item item)
3311 879ce10b LJIYEON
        {
3312
            string result = string.Empty;
3313 7106e181 LJIYEON
3314
            foreach (KeywordItem keyitem in KeywordInfos.KeywordItems)
3315 879ce10b LJIYEON
            {
3316 7106e181 LJIYEON
                if (keyitem.Name.Equals(item.Name))
3317 a5616391 LJIYEON
                {
3318 eb44d82c LJIYEON
                    result = keyitem.Keyword;
3319 a5616391 LJIYEON
                    Type = item.ID2DBType;
3320 a2973aa3 LJIYEON
                    break;
3321 a5616391 LJIYEON
                }
3322 879ce10b LJIYEON
            }
3323 7106e181 LJIYEON
3324 879ce10b LJIYEON
            return result;
3325
        }
3326
3327 a5616391 LJIYEON
        public string GetToKeywordData(ref string Type, Item item)
3328 879ce10b LJIYEON
        {
3329
            string result = string.Empty;
3330
3331 eb44d82c LJIYEON
            foreach (KeywordItem keyitem in KeywordInfos.KeywordItems)
3332 879ce10b LJIYEON
            {
3333 eb44d82c LJIYEON
                if (keyitem.Name.Equals(item.Name))
3334 a5616391 LJIYEON
                {
3335 eb44d82c LJIYEON
                    result = keyitem.Keyword;
3336 a5616391 LJIYEON
                    Type = item.ID2DBType;
3337 a2973aa3 LJIYEON
                    break;
3338 a5616391 LJIYEON
                }
3339 879ce10b LJIYEON
            }
3340
            return result;
3341
        }
3342
3343 a5616391 LJIYEON
        public string GetToData(ref string ToType, ref Item item)
3344 94a117ca gaqhf
        {
3345
            string result = string.Empty;
3346 51974d2b LJIYEON
            Status = string.Empty;
3347 eb44d82c LJIYEON
3348 a2973aa3 LJIYEON
            if (IsKeyword)
3349
                IsKeyword = false;
3350 3210f690 LJIYEON
3351 08b33e44 gaqhf
            item = Groups.Last().Items.Last();
3352
3353 a2973aa3 LJIYEON
            if (EndType == PSNType.Header)
3354
                result = "ENDOFHEADER";
3355
            else if (EndType == PSNType.Branch)
3356
            {
3357 48870200 LJIYEON
                //if (!item.MissingLineNumber && item.Relations.Last().Item.LineNumber != null && !string.IsNullOrEmpty(item.Relations.Last().Item.LineNumber.Name))
3358 f2a63376 이지연
                if (!item.MissingLineNumber2 && item.Relations.Last().Item.LineNumber != null && !string.IsNullOrEmpty(item.Relations.Last().Item.LineNumber.Name))
3359 a2973aa3 LJIYEON
                    result = item.Relations.Last().Item.LineNumber.Name;
3360
                else
3361 36a45f13 gaqhf
                {
3362 7106e181 LJIYEON
                    IsValid = "Error";
3363 51974d2b LJIYEON
                    Status += ", Missing LineNumber_2";
3364 a2973aa3 LJIYEON
                    result = "Empty LineNumber";
3365 36a45f13 gaqhf
                }
3366 48870200 LJIYEON
3367
                //if (item.MissingLineNumber1)
3368
                //{
3369
                //    Status += ", Missing LineNumber_1";
3370
                //    result = item.MissingLineNumber1 && item.LineNumber != null && !string.IsNullOrEmpty(item.LineNumber.Name) ? item.LineNumber.Name : "Empty LineNumber";
3371
3372
                //}
3373 a2973aa3 LJIYEON
            }
3374
            else if (EndType == PSNType.Equipment)
3375
            {
3376 7106e181 LJIYEON
                if (Groups.Last().Items.Last().Equipment != null)
3377 a2973aa3 LJIYEON
                    result = Groups.Last().Items.Last().Equipment.ItemTag;
3378 8ab98ea3 LJIYEON
3379 a2973aa3 LJIYEON
                DataRow drNozzle = Nozzle.Select(string.Format("OID = '{0}'", Groups.Last().Items.Last().UID)).FirstOrDefault();
3380 3210f690 LJIYEON
3381 a2973aa3 LJIYEON
                if (drNozzle != null)
3382
                    result += " [" + drNozzle.Field<string>("ITEMTAG") + "]";
3383
            }
3384
            else
3385
            {
3386
                IsValid = "Error";
3387
                item = Groups.Last().Items.Last();
3388
                if (item.ItemType == ItemType.Symbol)
3389 3210f690 LJIYEON
                {
3390 a2973aa3 LJIYEON
                    string keyword = string.Empty;
3391
                    keyword = GetToKeywordData(ref ToType, item);
3392 3210f690 LJIYEON
3393 a2973aa3 LJIYEON
                    if (string.IsNullOrEmpty(keyword))
3394
                    {
3395
                        if (item.ID2DBType.Contains("OPC's"))
3396 51974d2b LJIYEON
                            Status += ", OPC Disconnected";
3397 8ab98ea3 LJIYEON
                        else
3398 a2973aa3 LJIYEON
                            Status += ", Missing ItemTag or Description";
3399 8ab98ea3 LJIYEON
3400 a2973aa3 LJIYEON
                        result = item.ID2DBName;
3401 8ab98ea3 LJIYEON
                    }
3402 a2973aa3 LJIYEON
                    else
3403 eb44d82c LJIYEON
                    {
3404 a2973aa3 LJIYEON
                        result = keyword;
3405
                        IsValid = string.Empty;
3406
                        IsKeyword = true;
3407 eb44d82c LJIYEON
                    }
3408 a2973aa3 LJIYEON
3409
                }
3410
                else if (item.ItemType == ItemType.Line)
3411
                {
3412 48870200 LJIYEON
                    if (item.MissingLineNumber1)
3413
                    {
3414 7106e181 LJIYEON
                        IsValid = "Error";
3415 48870200 LJIYEON
                        Status += ", Missing LineNumber_1";
3416
                        result = item.MissingLineNumber1 && item.LineNumber != null && !string.IsNullOrEmpty(item.LineNumber.Name) ? item.LineNumber.Name : "Empty LineNumber";
3417
                    }
3418 f6c9db1a 이지연
                    else
3419
                        result = !string.IsNullOrEmpty(item.LineNumber.Name) ? item.LineNumber.Name : "Empty LineNumber";
3420 36a45f13 gaqhf
                }
3421 a2973aa3 LJIYEON
                else
3422
                    result = "Unknown";
3423 7106e181 LJIYEON
3424
3425 a2973aa3 LJIYEON
            }
3426 7106e181 LJIYEON
3427
3428
3429 94a117ca gaqhf
            return result;
3430
        }
3431 7881ec8f gaqhf
3432
        public string GetPBSData()
3433
        {
3434
            string result = string.Empty;
3435
            List<string> PBSList = new List<string>();
3436
            if (Settings.Default.PBSSetting.Equals("Line Number"))
3437
            {
3438
                string attrValue = Settings.Default.PBSSettingValue;
3439
3440
                foreach (Group group in Groups)
3441
                {
3442 7106e181 LJIYEON
                    List<LineNumber> lineNumbers = group.Items.Select(x => x.LineNumber).Distinct().ToList();
3443 7881ec8f gaqhf
                    foreach (LineNumber lineNumber in lineNumbers)
3444
                    {
3445
                        Attribute attribute = lineNumber.Attributes.Find(x => x.Name == attrValue && !string.IsNullOrEmpty(x.Value));
3446
                        if (attribute != null)
3447
                        {
3448
                            string value = attribute.Value;
3449
                            if (!PBSList.Contains(value))
3450
                                PBSList.Add(value);
3451
                        }
3452
                    }
3453
                }
3454
            }
3455
            else if (Settings.Default.PBSSetting.Equals("Item Attribute"))
3456
            {
3457
                string attrValue = Settings.Default.PBSSettingValue;
3458
3459
                foreach (Group group in Groups)
3460
                {
3461
                    List<Item> items = group.Items.FindAll(x => x.Attributes.Find(y => y.Name == attrValue && !string.IsNullOrEmpty(y.Value)) != null);
3462
                    foreach (Item item in items)
3463
                    {
3464
                        string value = item.Attributes.Find(x => x.Name == attrValue).Value;
3465
                        if (!PBSList.Contains(value))
3466
                            PBSList.Add(value);
3467
                    }
3468
                }
3469
            }
3470
            else if (Settings.Default.PBSSetting.Equals("Drawing No"))
3471
            {
3472
                string attrValue = Settings.Default.PBSSettingValue;
3473
3474
                foreach (Group group in Groups)
3475
                {
3476
                    List<Document> documents = group.Items.Select(x => x.Document).Distinct().ToList();
3477
                    foreach (Document document in documents)
3478
                    {
3479
                        string name = document.DrawingName;
3480
3481
                        int startIndex = Settings.Default.PBSSettingStartValue;
3482
                        int endIndex = Settings.Default.PBSSettingEndValue;
3483
3484
                        string subStr = name.Substring(startIndex - 1, endIndex - startIndex + 1);
3485
                        if (!PBSList.Contains(subStr))
3486
                            PBSList.Add(subStr);
3487
                    }
3488
                }
3489
            }
3490
            else if (Settings.Default.PBSSetting.Equals("Unit Area"))
3491
            {
3492
                foreach (Group group in Groups)
3493
                {
3494
                    List<Document> documents = group.Items.Select(x => x.Document).Distinct().ToList();
3495
                    foreach (Document document in documents)
3496
                    {
3497
                        List<TextInfo> textInfos = document.TextInfos.FindAll(x => x.Area == "Unit");
3498
                        foreach (TextInfo textInfo in textInfos)
3499
                        {
3500
                            if (!PBSList.Contains(textInfo.Value))
3501
                                PBSList.Add(textInfo.Value);
3502
                        }
3503
                    }
3504
                }
3505
            }
3506
3507
            foreach (var item in PBSList)
3508
            {
3509
                if (string.IsNullOrEmpty(result))
3510
                    result = item;
3511
                else
3512
                    result += ", " + item;
3513
            }
3514
            return result;
3515
        }
3516 6b9e7a56 gaqhf
    }
3517
}
클립보드 이미지 추가 (최대 크기: 500 MB)