프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / ID2PSN / PSN.cs @ 30a35908

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