프로젝트

일반

사용자정보

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

hytos / DTI_PID / ID2PSN / PSN.cs @ 0e402f7d

이력 | 보기 | 이력해설 | 다운로드 (199 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 0eefef3d 이지연
                pipeSystemNetworkDT.Columns.Add("AFC", typeof(string));
2186 d1afd412 이지연
                pipeSystemNetworkDT.Columns.Add("PUMP", typeof(string));
2187 2c46461b LJIYEON
2188
                DataTable topologySetDT = new DataTable();
2189
                topologySetDT.Columns.Add("OID", typeof(string));
2190
                topologySetDT.Columns.Add("Type", typeof(string));
2191
                topologySetDT.Columns.Add("SubType", typeof(string));
2192
                topologySetDT.Columns.Add("HeadItemTag", typeof(string));
2193
                topologySetDT.Columns.Add("TailItemTag", typeof(string));
2194 72775f2e LJIYEON
                topologySetDT.Columns.Add("HeadItemSPID", typeof(string));
2195
                topologySetDT.Columns.Add("TailItemSPID", typeof(string));
2196 2c46461b LJIYEON
2197 f9f2787b LJIYEON
                DataTable pipelineDT = new DataTable();
2198
                pipelineDT.Columns.Add("OID", typeof(string));
2199
                pipelineDT.Columns.Add("PipeSystem_OID", typeof(string));
2200
                pipelineDT.Columns.Add("FLUID", typeof(string));
2201
                pipelineDT.Columns.Add("PMC", typeof(string));
2202
                pipelineDT.Columns.Add("SEQNUMBER", typeof(string));
2203
                pipelineDT.Columns.Add("INSULATION", typeof(string));
2204
                pipelineDT.Columns.Add("FROM_DATA", typeof(string));
2205
                pipelineDT.Columns.Add("TO_DATA", typeof(string));
2206
                pipelineDT.Columns.Add("Unit", typeof(string));
2207
2208 531fb158 LJIYEON
                DataTable pipesystemDT = new DataTable();
2209
                pipesystemDT.Columns.Add("OID", typeof(string));
2210
                pipesystemDT.Columns.Add("DESCRIPTION", typeof(string));
2211
                pipesystemDT.Columns.Add("FLUID", typeof(string));
2212
                pipesystemDT.Columns.Add("PMC", typeof(string));
2213
                pipesystemDT.Columns.Add("PipeLineQty", typeof(string));
2214
                pipesystemDT.Columns.Add("GroundLevel", typeof(string));
2215
2216 879ce10b LJIYEON
                // Set Vent/Drain Info
2217 2c46461b LJIYEON
                List<VentDrainInfo> VentDrainInfos = new List<VentDrainInfo>();
2218
                DataTable dt = DB.SelectVentDrainSetting();
2219
                foreach (DataRow row in dt.Rows)
2220 36a45f13 gaqhf
                {
2221 2c46461b LJIYEON
                    string groupID = row["GROUP_ID"].ToString();
2222
                    string desc = row["DESCRIPTION"].ToString();
2223
                    int index = Convert.ToInt32(row["INDEX"]);
2224
                    string name = row["NAME"].ToString();
2225 36a45f13 gaqhf
2226 2c46461b LJIYEON
                    VentDrainInfo ventDrainInfo = VentDrainInfos.Find(x => x.UID.Equals(groupID));
2227
                    if (ventDrainInfo == null)
2228 36a45f13 gaqhf
                    {
2229 2c46461b LJIYEON
                        ventDrainInfo = new VentDrainInfo(groupID);
2230
                        ventDrainInfo.Description = desc;
2231
                        VentDrainInfos.Add(ventDrainInfo);
2232 36a45f13 gaqhf
                    }
2233
2234 2c46461b LJIYEON
                    ventDrainInfo.VentDrainItems.Add(new VentDrainItem()
2235
                    {
2236
                        Index = index,
2237
                        Name = name
2238
                    });
2239
                }
2240 51974d2b LJIYEON
                foreach (VentDrainInfo ventDrainInfo in VentDrainInfos)
2241
                    ventDrainInfo.VentDrainItems = ventDrainInfo.VentDrainItems.OrderBy(x => x.Index).ToList();
2242 2c46461b LJIYEON
2243 879ce10b LJIYEON
                #region Keyword Info
2244 eb44d82c LJIYEON
                KeywordInfo KeywordInfos = new KeywordInfo();
2245 879ce10b LJIYEON
                DataTable dtKeyword = DB.SelectKeywordsSetting();
2246
                foreach (DataRow row in dtKeyword.Rows)
2247
                {
2248
                    int index = Convert.ToInt32(row["INDEX"]);
2249
                    string name = row["NAME"].ToString();
2250
                    string keyword = row["KEYWORD"].ToString();
2251
2252 eb44d82c LJIYEON
                    //KeywordInfo keywordInfo = new KeywordInfo();   
2253
                    KeywordInfos.KeywordItems.Add(new KeywordItem()
2254 879ce10b LJIYEON
                    {
2255
                        Index = index,
2256
                        Name = name,
2257
                        Keyword = keyword
2258
                    });
2259 811d7949 LJIYEON
                }
2260
                #endregion
2261
2262
                #region ValveGrouping Info
2263
                ValveGroupInfo ValveGrouping = new ValveGroupInfo();
2264
                DataTable dtValveGroupung = DB.SelectValveGroupItemsSetting();
2265
                foreach (DataRow row in dtValveGroupung.Rows)
2266
                {
2267
                    ValveGrouping.ValveGroupItems.Add(new ValveGroupItem()
2268
                    {
2269
                        OID = row["OID"].ToString(),
2270
                        GroupType = row["GroupType"].ToString(),
2271
                        TagIdentifier = row["TagIdentifier"].ToString(),
2272
                        AttributeName = row["AttributeName"].ToString(),
2273
                        SppidSymbolName = row["SppidSymbolName"].ToString()
2274
                    });
2275
                }
2276 879ce10b LJIYEON
                #endregion
2277
2278 08b33e44 gaqhf
                #region EquipmentNoPocket Info
2279
                EquipmentNoPocketInfo EquipmentNoPocket = new EquipmentNoPocketInfo();
2280
                DataTable dtEquipmentNoPocket = DB.SelectEquipmentNoPocketSetting();
2281
                foreach (DataRow row in dtEquipmentNoPocket.Rows)
2282
                {
2283
                    EquipmentNoPocket.EquipmentNoPocketItem.Add(new EquipmentNoPocketItem()
2284
                    {
2285
                        Index = Convert.ToInt32(row["INDEX"]),
2286
                        Type = row["TYPE"].ToString(),
2287
                        Name = row["NAME"].ToString()
2288
                    });
2289
                }
2290
                #endregion
2291
2292 0eefef3d 이지연
                #region EquipmentAirFinCooler Info
2293
                EquipmentAirFinCoolerInfo EquipmentAirFinCooler = new EquipmentAirFinCoolerInfo();
2294
                DataTable dtEquipmentAirFinCooler = DB.SelectAirFinCoolerSetting();
2295
                foreach (DataRow row in dtEquipmentAirFinCooler.Rows)
2296
                {
2297
                    EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Add(new EquipmentAirFinCoolerItem()
2298
                    {
2299
                        Type = row["Type"].ToString(),
2300
                        Name = row["Name"].ToString()
2301
                    });
2302
                }
2303
                #endregion
2304
2305 2c46461b LJIYEON
                // key = 미입력 branch
2306
                Dictionary<Item, Item> startBranchDic = new Dictionary<Item, Item>();
2307
                Dictionary<Item, Item> endBranchDic = new Dictionary<Item, Item>();
2308 531fb158 LJIYEON
                DataTable PSNFluidDT = DB.SelectPSNFluidCode();
2309
                DataTable PSNPMCDT = DB.SelectPSNPIPINGMATLCLASS();
2310 2c46461b LJIYEON
                foreach (PSNItem PSNItem in PSNItems)
2311
                {
2312 3210f690 LJIYEON
                    try
2313 36a45f13 gaqhf
                    {
2314 3210f690 LJIYEON
                        int psnOrder = 0;
2315
                        int index = 0;
2316
                        bool bPSNStart = true;
2317
                        string sPSNData = string.Empty;
2318
                        bool bVentDrain = false;
2319 7106e181 LJIYEON
2320 7d6d1693 이지연
                      List<Group> Groups = PSNItem.Groups;
2321 811d7949 LJIYEON
                        Dictionary<string, List<Item>> keyValuePairs = new Dictionary<string, List<Item>>();
2322 7106e181 LJIYEON
                        List<Item> valveGroupingItem = new List<Item>();
2323
2324 3210f690 LJIYEON
                        //VentDrain 검사
2325
                        if (PSNItem.Groups.Count.Equals(1))
2326 36a45f13 gaqhf
                        {
2327 7106e181 LJIYEON
                            List<VentDrainInfo> endInfos = new List<VentDrainInfo>();
2328
                            for (int g = 0; g < Groups.Count; g++)
2329 2c46461b LJIYEON
                            {
2330 51974d2b LJIYEON
                                Group group = Groups[g];
2331 7d6d1693 이지연
2332
                                foreach (VentDrainInfo ventDrainInfo in VentDrainInfos)
2333 2c46461b LJIYEON
                                {
2334 7d6d1693 이지연
                                    if(!bVentDrain)
2335 27d06aa8 LJIYEON
                                    {
2336 7d6d1693 이지연
                                        for (int i = 0; i < group.Items.Count; i++)
2337 3210f690 LJIYEON
                                        {
2338 7d6d1693 이지연
                                            Item item = group.Items[i];
2339
                                            if (ventDrainInfo.VentDrainItems[endInfos.Count()].Name.Equals(item.Name))
2340
                                                endInfos.Add(ventDrainInfo);
2341
                                            else
2342
                                            {
2343
                                                endInfos.Clear();
2344
                                                if (ventDrainInfo.VentDrainItems[endInfos.Count()].Name.Equals(item.Name))
2345
                                                    endInfos.Add(ventDrainInfo);
2346
                                            }
2347 6b9e7a56 gaqhf
2348 7d6d1693 이지연
                                            if (ventDrainInfo.VentDrainItems.Count().Equals(endInfos.Count()))
2349
                                            {
2350
                                                bVentDrain = true;
2351
                                                break;
2352
                                            }
2353 3210f690 LJIYEON
                                        }
2354 7d6d1693 이지연
                                    }                                   
2355
                                }                               
2356 51974d2b LJIYEON
2357
                                if (!bVentDrain)
2358
                                {
2359
                                    endInfos = new List<VentDrainInfo>();
2360 7d6d1693 이지연
2361
                                    foreach (VentDrainInfo ventDrainInfo in VentDrainInfos)
2362 51974d2b LJIYEON
                                    {
2363 7d6d1693 이지연
                                        if (!bVentDrain)
2364 51974d2b LJIYEON
                                        {
2365 7d6d1693 이지연
                                            for (int i = 0; i < group.Items.Count; i++)
2366 51974d2b LJIYEON
                                            {
2367 7d6d1693 이지연
                                                Item item = group.Items[group.Items.Count - i - 1];
2368 51974d2b LJIYEON
2369 7d6d1693 이지연
                                                if (ventDrainInfo.VentDrainItems[endInfos.Count()].Name.Equals(item.Name))
2370
                                                    endInfos.Add(ventDrainInfo);
2371
                                                else
2372
                                                {
2373
                                                    endInfos.Clear();
2374
                                                    if (ventDrainInfo.VentDrainItems[endInfos.Count()].Name.Equals(item.Name))
2375
                                                        endInfos.Add(ventDrainInfo);
2376
                                                }
2377
2378
                                                if (ventDrainInfo.VentDrainItems.Count().Equals(endInfos.Count()))
2379
                                                {
2380
                                                    bVentDrain = true;
2381
                                                    break;
2382
                                                }
2383 51974d2b LJIYEON
                                            }
2384
                                        }
2385
                                    }
2386 27d06aa8 LJIYEON
                                }
2387 3210f690 LJIYEON
                            }
2388
                        }
2389 7106e181 LJIYEON
2390 a5616391 LJIYEON
                        try
2391 7106e181 LJIYEON
                        {
2392 a5616391 LJIYEON
                            foreach (Group group in PSNItem.Groups)
2393 7106e181 LJIYEON
                            {
2394 a5616391 LJIYEON
                                foreach (Item item in group.Items)
2395 7106e181 LJIYEON
                                {
2396 811d7949 LJIYEON
                                    string VgTag = string.Empty;
2397 0eefef3d 이지연
                                    
2398 7106e181 LJIYEON
                                    if (ValveGrouping.ValveGroupItems.Where(x => x.SppidSymbolName == item.Name).Count() > 0)
2399 811d7949 LJIYEON
                                    {
2400
                                        ValveGroupItem valveitem = ValveGrouping.ValveGroupItems.Where(x => x.SppidSymbolName == item.Name).First();
2401 7106e181 LJIYEON
                                        string value = string.Empty;
2402
2403 dd27861e 이지연
                                        if (valveitem.GroupType == "Scope Break" || valveitem.AttributeName == "NoSelection" || valveitem.AttributeName == string.Empty)
2404 54b6df95 LJIYEON
                                            value = "NoSelection";
2405
                                        else
2406 dd27861e 이지연
                                        {
2407
                                            if(item.Attributes.Find(x => x.Name == valveitem.AttributeName) == null)
2408
                                                value = "NoSelection";
2409
                                            else
2410
                                                value = item.Attributes.Find(x => x.Name == valveitem.AttributeName).Value;
2411
                                        }
2412 54b6df95 LJIYEON
2413
                                        if (valveitem.GroupType == "Scope Break")
2414
                                            VgTag = "Scope Break";
2415
                                        else
2416
                                            VgTag = valveitem.SppidSymbolName + "\\" + value;
2417 7106e181 LJIYEON
2418 811d7949 LJIYEON
                                    }
2419
2420 a5616391 LJIYEON
                                    string PathitemUID = string.Empty;
2421
                                    if (item.BranchItems.Count == 0)
2422 a36541fb LJIYEON
                                    {
2423 a5616391 LJIYEON
                                        PathitemUID = item.UID;
2424 811d7949 LJIYEON
                                        CreatePathItemsDataRow(PathitemUID, item.ID2DBType, VgTag);
2425 a5616391 LJIYEON
                                        CreateSequenceDataDataRow(PathitemUID);
2426
                                        index++;
2427
                                    }
2428
                                    else
2429
                                    {
2430
                                        PathitemUID = item.UID + "_L1";
2431 811d7949 LJIYEON
                                        CreatePathItemsDataRow(PathitemUID, item.ID2DBType, VgTag);
2432 a5616391 LJIYEON
                                        CreateSequenceDataDataRow(PathitemUID);
2433
                                        index++;
2434
                                        for (int i = 0; i < item.BranchItems.Count; i++)
2435 3210f690 LJIYEON
                                        {
2436 811d7949 LJIYEON
                                            CreatePathItemsDataRow(string.Format(item.UID + "_B{0}", i + 1), "Branch", string.Empty, item.BranchItems[i].Topology.FullName, item.BranchItems[i]);
2437 a5616391 LJIYEON
                                            CreateSequenceDataDataRow(string.Format(item.UID + "_B{0}", i + 1));
2438 3210f690 LJIYEON
                                            index++;
2439 7106e181 LJIYEON
2440 a5616391 LJIYEON
                                            CreatePathItemsDataRow(string.Format(item.UID + "_L{0}", i + 2), item.ID2DBType);
2441
                                            CreateSequenceDataDataRow(string.Format(item.UID + "_L{0}", i + 2));
2442
                                            index++;
2443 a36541fb LJIYEON
2444 a5616391 LJIYEON
                                            if (item.BranchItems[i].Relations[0].Item != null && item.BranchItems[i].Relations[0].Item == item)
2445
                                                startBranchDic.Add(item.BranchItems[i], item);
2446
                                            else if (item.BranchItems[i].Relations[1].Item != null && item.BranchItems[i].Relations[1].Item == item)
2447
                                                endBranchDic.Add(item.BranchItems[i], item);
2448
                                        }
2449
                                    }
2450 7106e181 LJIYEON
2451 a5616391 LJIYEON
                                    if (bPSNStart)
2452 7106e181 LJIYEON
                                    {
2453 a5616391 LJIYEON
                                        CreatePipeSystemNetworkDataRow();
2454 7106e181 LJIYEON
                                        sPSNData = item.TopologyData;
2455 a5616391 LJIYEON
                                        psnOrder++;
2456
                                        bPSNStart = false;
2457
                                    }
2458
                                    else
2459
                                    {
2460
                                        if (item.TopologyData != sPSNData)
2461 3210f690 LJIYEON
                                        {
2462
                                            CreatePipeSystemNetworkDataRow();
2463
                                            sPSNData = item.TopologyData;
2464
                                            psnOrder++;
2465
                                        }
2466 a5616391 LJIYEON
                                    }
2467 7106e181 LJIYEON
2468 811d7949 LJIYEON
                                    void CreatePathItemsDataRow(string itemOID, string itemType, string GROUPTAG = "", string branchTopologyName = "", Item branchItem = null)
2469 a5616391 LJIYEON
                                    {
2470
                                        DataRow newRow = pathItemsDT.NewRow();
2471
2472
                                        if (itemType == "Nozzles")
2473 3210f690 LJIYEON
                                        {
2474 485040d4 esham21
                                            newRow["Equipment_OID"] = item.Equipment != null ? item.Equipment.UID : "";
2475 3210f690 LJIYEON
                                        }
2476 7106e181 LJIYEON
2477 a5616391 LJIYEON
                                        newRow["OID"] = itemOID;
2478
                                        newRow["SequenceData_OID"] = string.Format(item.Topology.FullName + "_{0}", index);
2479
                                        newRow["TopologySet_OID"] = item.Topology.FullName;
2480
                                        newRow["BranchTopologySet_OID"] = branchTopologyName;
2481
                                        newRow["PipeLine_OID"] = item.PSNPipeLineID;
2482
                                        newRow["ITEMNAME"] = GetItemName(item, itemOID);
2483
                                        newRow["ITEMTAG"] = GetItemTag(item);
2484
                                        newRow["Class"] = GetClass(item, itemOID);
2485 7106e181 LJIYEON
                                        string subClass = GetSubClass(item, itemOID);
2486 a5616391 LJIYEON
                                        newRow["SubClass"] = subClass;
2487 7106e181 LJIYEON
2488 a5616391 LJIYEON
                                        if (item.ItemType == ItemType.Symbol)
2489
                                            newRow["TYPE"] = item.ID2DBName;
2490
                                        else if (item.ItemType == ItemType.Line)
2491
                                            newRow["TYPE"] = item.ID2DBType;
2492
                                        newRow["PIDNAME"] = group.Document.DrawingName;
2493
2494
                                        // NPD
2495
                                        if (item.LineNumber != null)
2496
                                        {
2497
                                            Attribute attribute = item.LineNumber.Attributes.Find(x => x.Name == "NominalDiameter");
2498
                                            if (attribute != null)
2499
                                                newRow["NPD"] = attribute.Value;
2500
                                        }
2501
                                        else
2502
                                            newRow["NPD"] = null;
2503 7881ec8f gaqhf
2504 811d7949 LJIYEON
                                        newRow["GROUPTAG"] = GROUPTAG;
2505 a5616391 LJIYEON
                                        newRow["PipeSystemNetwork_OID"] = PSNItem.PSN_OID();
2506
                                        if (branchItem == null)
2507
                                            newRow["ViewPipeSystemNetwork_OID"] = PSNItem.PSN_OID();
2508
                                        else
2509
                                            newRow["ViewPipeSystemNetwork_OID"] = branchItem.PSNItem.PSN_OID();
2510 27d06aa8 LJIYEON
2511 a5616391 LJIYEON
                                        newRow["PipeRun_OID"] = item.LineNumber != null ? item.LineNumber.Name : string.Empty;
2512 0eefef3d 이지연
                                        newRow["EGTConnectedPoint"] = 0;
2513 a5616391 LJIYEON
                                        pathItemsDT.Rows.Add(newRow);
2514 7106e181 LJIYEON
                                    }
2515 0eefef3d 이지연
2516
2517 a5616391 LJIYEON
                                    void CreateSequenceDataDataRow(string itemOID)
2518
                                    {
2519
                                        DataRow newRow = sequenceDataDT.NewRow();
2520
                                        newRow["OID"] = string.Format(item.Topology.FullName + "_{0}", index);
2521
                                        newRow["SERIALNUMBER"] = string.Format("{0}", index);
2522
                                        newRow["PathItem_OID"] = itemOID;
2523
                                        newRow["TopologySet_OID_Key"] = item.Topology.FullName;
2524 839708c6 LJIYEON
2525 a5616391 LJIYEON
                                        sequenceDataDT.Rows.Add(newRow);
2526
                                    }
2527 0eefef3d 이지연
2528 a5616391 LJIYEON
                                    void CreatePipeSystemNetworkDataRow()
2529 7106e181 LJIYEON
                                    {
2530 a5616391 LJIYEON
                                        LineNumber lineNumber = item.Document.LineNumbers.Find(x => x.UID == item.Owner);
2531 08b33e44 gaqhf
                                        string FluidCode = string.Empty;
2532 a5616391 LJIYEON
                                        if (lineNumber != null)
2533 3210f690 LJIYEON
                                        {
2534 a5616391 LJIYEON
                                            List<Attribute> att = lineNumber.Attributes;
2535
                                            if (att != null)
2536 3210f690 LJIYEON
                                            {
2537 a5616391 LJIYEON
                                                List<string> oid = new List<string>();
2538 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;
2539 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;
2540
                                                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;
2541
                                                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;
2542
                                                //InsulationPurpose
2543
                                                if (!string.IsNullOrEmpty(FluidCode)) oid.Add(FluidCode);
2544
                                                if (!string.IsNullOrEmpty(PMC)) oid.Add(PMC);
2545
2546
                                                string PipeSystem_OID = string.Join("-", oid);
2547
2548
                                                if (!string.IsNullOrEmpty(SEQNUMBER)) oid.Add(SEQNUMBER);
2549
                                                if (!string.IsNullOrEmpty(INSULATION)) oid.Add(INSULATION);
2550
2551
                                                string OID = string.Join("-", oid);
2552 531fb158 LJIYEON
                                                string FluidCodeGL = string.Empty;
2553
                                                string PMCGL = string.Empty;
2554 7106e181 LJIYEON
2555 3210f690 LJIYEON
2556 a5616391 LJIYEON
                                                if (pipelineDT.Select(string.Format("OID = '{0}'", OID)).Count() == 0)
2557
                                                {
2558
                                                    DataRow newPipelineRow = pipelineDT.NewRow();
2559
                                                    newPipelineRow["OID"] = OID;
2560
                                                    newPipelineRow["PipeSystem_OID"] = PipeSystem_OID;
2561
                                                    newPipelineRow["FLUID"] = FluidCode;
2562
                                                    newPipelineRow["PMC"] = PMC;
2563
                                                    newPipelineRow["SEQNUMBER"] = SEQNUMBER;
2564
                                                    newPipelineRow["INSULATION"] = INSULATION;
2565
                                                    newPipelineRow["FROM_DATA"] = string.Empty;
2566
                                                    newPipelineRow["TO_DATA"] = string.Empty;
2567
                                                    newPipelineRow["Unit"] = PSNItem.GetPBSData();
2568 7106e181 LJIYEON
                                                    pipelineDT.Rows.Add(newPipelineRow);
2569 531fb158 LJIYEON
                                                }
2570
2571
                                                if (pipesystemDT.Select(string.Format("OID = '{0}'", PipeSystem_OID)).Count() == 0)
2572
                                                {
2573 54b6df95 LJIYEON
                                                    DataRow newPipesystemRow = pipesystemDT.NewRow();
2574
                                                    newPipesystemRow["OID"] = PipeSystem_OID;
2575
                                                    newPipesystemRow["DESCRIPTION"] = string.Empty;
2576
                                                    newPipesystemRow["FLUID"] = FluidCode;
2577
                                                    newPipesystemRow["PMC"] = PMC;
2578
                                                    newPipesystemRow["PipeLineQty"] = string.Empty;
2579
                                                    string GroundLevel = string.Empty;
2580
                                                    if (!string.IsNullOrEmpty(FluidCode) && !string.IsNullOrEmpty(PMC))
2581
                                                    {
2582
                                                        FluidCodeGL = PSNFluidDT.Select(string.Format("Code = '{0}'", FluidCode)).FirstOrDefault().Field<string>("GroundLevel");
2583
                                                        PMCGL = PSNPMCDT.Select(string.Format("Code= '{0}'", PMC)).FirstOrDefault().Field<string>("GroundLevel");
2584
                                                        if (FluidCodeGL == "AG" && PMCGL == "AG")
2585
                                                            GroundLevel = "AG";
2586
                                                        else if (FluidCodeGL == "UG" && PMCGL == "UG")
2587
                                                            GroundLevel = "UG";
2588
                                                        else
2589
                                                            GroundLevel = "AG_UG";
2590
                                                    }
2591
                                                    newPipesystemRow["GroundLevel"] = GroundLevel;
2592
2593
                                                    pipesystemDT.Rows.Add(newPipesystemRow);
2594 3210f690 LJIYEON
                                                }
2595
                                            }
2596 a5616391 LJIYEON
                                        }
2597 3210f690 LJIYEON
2598 a5616391 LJIYEON
                                        DataRow newRow = pipeSystemNetworkDT.NewRow();
2599
                                        newRow["OID"] = PSNItem.PSN_OID();
2600 7106e181 LJIYEON
2601 a5616391 LJIYEON
                                        newRow["OrderNumber"] = psnOrder;
2602
                                        newRow["Pipeline_OID"] = item.PSNPipeLineID;
2603
                                        PSNItem.KeywordInfos = KeywordInfos;
2604
                                        PSNItem.Nozzle = Nozzle;
2605 7106e181 LJIYEON
2606 a5616391 LJIYEON
                                        string FromType = string.Empty;
2607
                                        Item From_item = new Item();
2608 7106e181 LJIYEON
2609 a5616391 LJIYEON
                                        string FROM_DATA = PSNItem.GetFromData(ref FromType, ref From_item);
2610 51974d2b LJIYEON
                                        string status = string.Empty;
2611 7d6d1693 이지연
                                        status = PSNItem.Status;                                      
2612 51974d2b LJIYEON
2613 a5616391 LJIYEON
                                        if (PSNItem.IsKeyword)
2614
                                        {
2615 e552da48 LJIYEON
                                            PSNItem.StartType = PSNType.Equipment;
2616 a5616391 LJIYEON
                                        }
2617
                                        string ToType = string.Empty;
2618
                                        Item To_item = new Item();
2619
                                        string TO_DATA = PSNItem.GetToData(ref ToType, ref To_item);
2620
                                        if (PSNItem.IsKeyword)
2621
                                        {
2622 e552da48 LJIYEON
                                            PSNItem.EndType = PSNType.Equipment;
2623 a5616391 LJIYEON
                                        }
2624 7d6d1693 이지연
                                                   
2625 e552da48 LJIYEON
                                        newRow["FROM_DATA"] = FROM_DATA;
2626 7106e181 LJIYEON
                                        newRow["TO_DATA"] = TO_DATA;
2627 7d6d1693 이지연
                                       
2628 a5616391 LJIYEON
                                        newRow["Type"] = PSNItem.GetPSNType();
2629 e552da48 LJIYEON
2630 7d6d1693 이지연
                                       
2631
                                        if(psnOrder == 0) //order 0일땐 그냥 붙여줌
2632
                                        {
2633
                                            if (!string.IsNullOrEmpty(PSNItem.Status)) //to에 status가 있다면
2634
                                            {
2635
                                                status += PSNItem.Status;
2636
                                            }                                            
2637
                                        }
2638
                                        else if (psnOrder > 0) //0보다 크면 
2639 e552da48 LJIYEON
                                        {
2640 7106e181 LJIYEON
                                            DataRow dr = pipeSystemNetworkDT.Select(string.Format("OID = '{0}' AND OrderNumber = {1}", PSNItem.PSN_OID(), psnOrder - 1)).FirstOrDefault();
2641 7d6d1693 이지연
                                            if (psnOrder == 1) //1이면 0번 Order에 From Status 값만 남김 
2642
                                            {
2643
                                                dr["Status"] = !string.IsNullOrEmpty(status) ? status.Remove(0, 2) : string.Empty; //status;
2644 7106e181 LJIYEON
                                            }
2645 7d6d1693 이지연
                                            if (psnOrder > 1) // 2 -> 1 3->2 엔 status 값 삭제
2646 e552da48 LJIYEON
                                            {
2647 7d6d1693 이지연
                                                dr["Status"] = string.Empty;
2648 e552da48 LJIYEON
                                            }
2649 7d6d1693 이지연
2650
                                            status = PSNItem.Status;
2651 6805be6e 이지연
                                            if (dr != null)
2652
                                            {
2653
                                                newRow["FROM_DATA"] = dr.Field<string>("FROM_DATA");
2654
                                                newRow["TO_DATA"] = dr.Field<string>("TO_DATA");
2655
                                                newRow["Type"] = dr.Field<string>("Type");
2656
                                            }
2657 7106e181 LJIYEON
                                        }
2658 eb44d82c LJIYEON
2659 7d6d1693 이지연
                                        
2660
                                    
2661 48870200 LJIYEON
                                        status = !string.IsNullOrEmpty(status) ? status.Remove(0, 2) : string.Empty;
2662 7d6d1693 이지연
                                        string[] st = status.Split(new string[] { ", " }, StringSplitOptions.None);
2663
                                        if (st.Count() > 1)
2664 48870200 LJIYEON
                                        {
2665 7d6d1693 이지연
                                            status = string.Join(", ", st.Distinct());                                                                                     
2666 48870200 LJIYEON
                                        }
2667 a5616391 LJIYEON
                                        newRow["TopologySet_OID_Key"] = item.Topology.FullName;
2668
                                        newRow["PSNRevisionNumber"] = string.Format("V{0:D4}", Revision);
2669 5e4c2ad1 LJIYEON
2670 7106e181 LJIYEON
2671 a5616391 LJIYEON
                                        newRow["IsValid"] = PSNItem.IsValid;
2672 48870200 LJIYEON
                                        newRow["Status"] = status;
2673 a5616391 LJIYEON
                                        newRow["PBS"] = PSNItem.GetPBSData();
2674 7106e181 LJIYEON
2675 a5616391 LJIYEON
                                        List<string> drawingNames = new List<string>();
2676
                                        foreach (Group _group in PSNItem.Groups)
2677
                                        {
2678
                                            if (!drawingNames.Contains(_group.Document.DrawingName))
2679 3210f690 LJIYEON
                                            {
2680 a5616391 LJIYEON
                                                if (drawingNames.Count == 0)
2681
                                                    newRow["Drawings"] = _group.Document.DrawingName;
2682
                                                else
2683
                                                    newRow["Drawings"] = newRow["Drawings"] + ", " + _group.Document.DrawingName;
2684
                                                drawingNames.Add(_group.Document.DrawingName);
2685 3210f690 LJIYEON
                                            }
2686 27d06aa8 LJIYEON
                                        }
2687 419055fa LJIYEON
2688
                                        // VentDrain의 경우 제외 요청 (데이터를 아예 제거하였을 경우 후 가공에서 문제가 생김 마지막에 지우는것으로 변경)
2689
                                        if (bVentDrain)
2690
                                            newRow["IncludingVirtualData"] = "Vent_Drain";
2691
                                        else
2692
                                            newRow["IncludingVirtualData"] = "No";
2693
                                        //    return;
2694 a2973aa3 LJIYEON
                                        //newRow["IncludingVirtualData"] = "No";
2695 a5616391 LJIYEON
                                        newRow["PSNAccuracy"] = "100";
2696 08b33e44 gaqhf
2697
                                        string Pocket = "No";
2698
                                        string Condition = PSNFluidDT.Select(string.Format("Code = '{0}'", FluidCode)).FirstOrDefault().Field<string>("Condition");
2699
                                        if (Condition.Equals("Flare"))
2700
                                            Pocket = "Yes";
2701
2702 485040d4 esham21
                                        if (item.ID2DBType == "Nozzles" && PSNItem.StartType == PSNType.Equipment && From_item.Equipment != null) 
2703 08b33e44 gaqhf
                                        {
2704
                                          //  string itemName = From_item.Name;
2705
                                            Equipment Equipment = From_item.Equipment;
2706 91c75c0b 이지연
                                      
2707
                                            EquipmentNoPocketItem nopocket = EquipmentNoPocket.EquipmentNoPocketItem.Where(x => x.Name == Equipment.Name && x.Type != "Pump").FirstOrDefault();
2708
                                          
2709
2710
                                            if (nopocket != null)
2711 08b33e44 gaqhf
                                            {
2712 91c75c0b 이지연
                                                DataRow bNozzle = null;
2713
                                                if (nopocket.Type.Equals("Vertical Vessel"))
2714
                                                {
2715
                                                    DataRow drNozzle = Nozzle.Select(string.Format("Equipment_OID = '{0}' AND OID = '{1}'", Equipment.UID, From_item.UID)).FirstOrDefault();
2716
                                                    if (drNozzle != null)
2717
                                                    {
2718
                                                        if (drNozzle.Field<string>("Rotation").Length >= 4 && drNozzle.Field<string>("Rotation").Substring(0, 4) == "4.71")
2719
                                                        {
2720
                                                            bNozzle = drNozzle;
2721
                                                        }
2722
2723
                                                        if (bNozzle == null)
2724
                                                        {
2725
                                                            DataRow[] nozzleRows = Nozzle.Select(string.Format("Equipment_OID = '{0}'", Equipment.UID));
2726
2727
                                                            if (drNozzle != null)
2728
                                                            {
2729
                                                                bNozzle = drNozzle;
2730
                                                                foreach (DataRow it in nozzleRows)
2731
                                                                {
2732
                                                                    if (Convert.ToDecimal(drNozzle.Field<string>("Ycoords")) > Convert.ToDecimal(it.Field<string>("Ycoords")))
2733
                                                                    {
2734
                                                                        bNozzle = null;
2735
                                                                        break;
2736
                                                                    }
2737
                                                                }
2738
                                                            }
2739
                                                        }
2740
                                                    }
2741
2742
                                                    if (bNozzle != null)
2743
                                                        Pocket = "Yes";
2744
                                                }
2745
                                                else
2746
                                                    Pocket = "Yes";
2747 08b33e44 gaqhf
                                            }
2748
                                        }
2749 91c75c0b 이지연
                                        
2750 485040d4 esham21
                                        if (item.ID2DBType == "Nozzles" && PSNItem.EndType == PSNType.Equipment && To_item.Equipment != null) //To는 전체
2751 08b33e44 gaqhf
                                        {
2752
                                           // string itemName = To_item.Name;
2753
                                            Equipment Equipment = To_item.Equipment;
2754
                                            EquipmentNoPocketItem nopocket = EquipmentNoPocket.EquipmentNoPocketItem.Where(x => x.Name == Equipment.Name).FirstOrDefault();
2755
                                            if (nopocket != null)
2756
                                            {
2757 91c75c0b 이지연
                                                DataRow bNozzle = null;
2758
                                                if (nopocket.Type.Equals("Vertical Vessel"))
2759
                                                {
2760
                                                    DataRow drNozzle = Nozzle.Select(string.Format("Equipment_OID = '{0}' AND OID = '{1}'", Equipment.UID, To_item.UID)).FirstOrDefault();
2761
                                                    if(drNozzle != null)
2762
                                                    {
2763
                                                        if (drNozzle.Field<string>("Rotation").Length >= 4 && drNozzle.Field<string>("Rotation").Substring(0, 4) == "4.71")
2764
                                                        {
2765
                                                            bNozzle = drNozzle;
2766
                                                        }
2767
2768
                                                        if (bNozzle == null)
2769
                                                        {
2770
                                                            DataRow[] nozzleRows = Nozzle.Select(string.Format("Equipment_OID = '{0}'", Equipment.UID));
2771
2772
                                                            if (drNozzle != null)
2773
                                                            {
2774
                                                                bNozzle = drNozzle;
2775
                                                                foreach (DataRow it in nozzleRows)
2776
                                                                {
2777
                                                                    if (Convert.ToDecimal(drNozzle.Field<string>("Ycoords")) > Convert.ToDecimal(it.Field<string>("Ycoords")))
2778
                                                                    {
2779
                                                                        bNozzle = null;
2780
                                                                        break;
2781
                                                                    }
2782
                                                                }
2783
                                                            }
2784
                                                        }
2785
                                                    }                                                   
2786
2787
                                                    if (bNozzle != null)
2788
                                                        Pocket = "Yes";
2789
                                                }
2790
                                                else
2791
                                                    Pocket = "Yes";
2792 08b33e44 gaqhf
                                            }
2793
                                        }
2794 91c75c0b 이지연
                                        
2795 08b33e44 gaqhf
                                        newRow["Pocket"] = Pocket;
2796 0eefef3d 이지연
                                        string AFC = "P2";
2797
                                        if(PSNItem.StartType == PSNType.Equipment && From_item.Equipment != null)
2798
                                        {
2799 d1afd412 이지연
                                            if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type != "Pump" && x.Name.Equals(From_item.Equipment.Name)).Count() > 0)
2800 284fa2c9 이지연
                                                AFC = "P1\\" + From_item.Equipment.Name;
2801 d1afd412 이지연
                                            else if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && x.Name.Equals(From_item.Equipment.Name)).Count() > 0)
2802
                                                newRow["PUMP"] = "PUMP";
2803 0eefef3d 이지연
                                        }
2804
2805
                                        if (PSNItem.EndType == PSNType.Equipment && To_item.Equipment != null)
2806
                                        {
2807 d1afd412 이지연
                                            if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type != "Pump" && x.Name.Equals(To_item.Equipment.Name)).Count() > 0)
2808 284fa2c9 이지연
                                                AFC = "P1\\" + To_item.Equipment.Name;
2809 d1afd412 이지연
                                            else if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && x.Name.Equals(To_item.Equipment.Name)).Count() > 0)
2810
                                                newRow["PUMP"] = "PUMP";
2811 0eefef3d 이지연
                                        }
2812
2813
                                        newRow["AFC"] = AFC;
2814 d1afd412 이지연
2815
                                        newRow["EGTag"] = string.Empty;
2816
                                        newRow["HasMLTags"] = "False";
2817 a5616391 LJIYEON
                                        pipeSystemNetworkDT.Rows.Add(newRow);
2818 2c46461b LJIYEON
                                    }
2819 27d06aa8 LJIYEON
                                }
2820 7106e181 LJIYEON
2821 820e283f LJIYEON
                            }
2822 91c75c0b 이지연
                        
2823 7106e181 LJIYEON
2824 a5616391 LJIYEON
                        }
2825
                        catch (Exception ex)
2826
                        {
2827
                            Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2828
                            MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
2829
                        }
2830 3210f690 LJIYEON
2831 a5616391 LJIYEON
                        //TopologySet 관련
2832
                        foreach (Topology topology in PSNItem.Topologies)
2833
                        {
2834
                            DataRow newRow = topologySetDT.NewRow();
2835
                            newRow["OID"] = topology.FullName;
2836
                            newRow["Type"] = topology.FullName.Split(new char[] { '-' }).Last().StartsWith("M") ? "Main" : "Branch";
2837
                            if (bVentDrain)
2838
                                newRow["SubType"] = "Vent_Drain";
2839
                            else
2840
                                newRow["SubType"] = null;
2841
                            newRow["HeadItemTag"] = GetItemTag(topology.Items.Last());
2842
                            newRow["TailItemTag"] = GetItemTag(topology.Items.First());
2843
                            newRow["HeadItemSPID"] = topology.Items.Last().UID;
2844
                            newRow["TailItemSPID"] = topology.Items.First().UID;
2845
                            topologySetDT.Rows.Add(newRow);
2846 94a117ca gaqhf
                        }
2847 7106e181 LJIYEON
2848 6b9e7a56 gaqhf
                    }
2849 7106e181 LJIYEON
                    catch (Exception ee)
2850 27d06aa8 LJIYEON
                    {
2851 879ce10b LJIYEON
2852 2c46461b LJIYEON
                    }
2853 6b9e7a56 gaqhf
                }
2854
2855 3210f690 LJIYEON
2856 2c46461b LJIYEON
                foreach (var item in startBranchDic)
2857 5c248ee3 gaqhf
                {
2858 2c46461b LJIYEON
                    string uid = item.Key.UID;
2859
                    string topologyName = item.Value.Topology.FullName;
2860
                    DataRow[] rows = pathItemsDT.Select(string.Format("OID LIKE '{0}%'", uid));
2861 7106e181 LJIYEON
2862 2c46461b LJIYEON
                    if (rows.Length == 1)
2863 9c151350 gaqhf
                    {
2864 2c46461b LJIYEON
                        rows.First()["BranchTopologySet_OID"] = topologyName;
2865 9c151350 gaqhf
                        rows.First()["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID();
2866
                    }
2867 2c46461b LJIYEON
                    else if (rows.Length > 1)
2868 5c248ee3 gaqhf
                    {
2869 2c46461b LJIYEON
                        DataRow targetRow = null;
2870
                        int index = int.MaxValue;
2871
                        foreach (DataRow row in rows)
2872 5c248ee3 gaqhf
                        {
2873 2c46461b LJIYEON
                            string split = row["OID"].ToString().Split(new char[] { '_' })[1];
2874
                            if (split.StartsWith("L"))
2875 5c248ee3 gaqhf
                            {
2876 2c46461b LJIYEON
                                int num = Convert.ToInt32(split.Remove(0, 1));
2877
                                if (index > num)
2878
                                {
2879
                                    index = num;
2880
                                    targetRow = row;
2881
                                }
2882 5c248ee3 gaqhf
                            }
2883
                        }
2884
2885 2c46461b LJIYEON
                        if (targetRow != null)
2886 9c151350 gaqhf
                        {
2887 2c46461b LJIYEON
                            targetRow["BranchTopologySet_OID"] = topologyName;
2888 9c151350 gaqhf
                            targetRow["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID();
2889
                        }
2890 2c46461b LJIYEON
                    }
2891 5c248ee3 gaqhf
                }
2892 f9f2787b LJIYEON
2893 2c46461b LJIYEON
                foreach (var item in endBranchDic)
2894 5c248ee3 gaqhf
                {
2895 2c46461b LJIYEON
                    string uid = item.Key.UID;
2896
                    string topologyName = item.Value.Topology.FullName;
2897
                    DataRow[] rows = pathItemsDT.Select(string.Format("OID LIKE '{0}%'", uid));
2898
                    if (rows.Length == 1)
2899 9c151350 gaqhf
                    {
2900 2c46461b LJIYEON
                        rows.First()["BranchTopologySet_OID"] = topologyName;
2901 9c151350 gaqhf
                        rows.First()["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID();
2902
                    }
2903 2c46461b LJIYEON
                    else if (rows.Length > 1)
2904 5c248ee3 gaqhf
                    {
2905 2c46461b LJIYEON
                        DataRow targetRow = null;
2906
                        int index = int.MinValue;
2907
                        foreach (DataRow row in rows)
2908 5c248ee3 gaqhf
                        {
2909 2c46461b LJIYEON
                            string split = row["OID"].ToString().Split(new char[] { '_' })[1];
2910
                            if (split.StartsWith("L"))
2911 5c248ee3 gaqhf
                            {
2912 2c46461b LJIYEON
                                int num = Convert.ToInt32(split.Remove(0, 1));
2913
                                if (index < num)
2914
                                {
2915
                                    index = num;
2916
                                    targetRow = row;
2917
                                }
2918 5c248ee3 gaqhf
                            }
2919
                        }
2920
2921 2c46461b LJIYEON
                        if (targetRow != null)
2922 9c151350 gaqhf
                        {
2923 2c46461b LJIYEON
                            targetRow["BranchTopologySet_OID"] = topologyName;
2924 9c151350 gaqhf
                            targetRow["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID();
2925
                        }
2926 2c46461b LJIYEON
                    }
2927 5c248ee3 gaqhf
                }
2928
2929 2c46461b LJIYEON
                PathItems = pathItemsDT;
2930
                SequenceData = sequenceDataDT;
2931
                PipeSystemNetwork = pipeSystemNetworkDT;
2932
                TopologySet = topologySetDT;
2933 f9f2787b LJIYEON
                PipeLine = pipelineDT;
2934 531fb158 LJIYEON
                PipeSystem = pipesystemDT;
2935 2c46461b LJIYEON
            }
2936
            catch (Exception ex)
2937
            {
2938
                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2939
                MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
2940
            }
2941 36a45f13 gaqhf
        }
2942 2ada3be8 LJIYEON
2943 5e4c2ad1 LJIYEON
        private double AccuracyCalculation(List<double> lstAcc, double acc)
2944 2ada3be8 LJIYEON
        {
2945 7106e181 LJIYEON
            foreach (double lacc in lstAcc)
2946 2ada3be8 LJIYEON
            {
2947
                acc *= lacc;
2948
            }
2949
            return acc;
2950
        }
2951
2952 7881ec8f gaqhf
        private void UpdateSubType()
2953 36a45f13 gaqhf
        {
2954 27d06aa8 LJIYEON
            try
2955 36a45f13 gaqhf
            {
2956 27d06aa8 LJIYEON
                foreach (PSNItem PSNItem in PSNItems)
2957 36a45f13 gaqhf
                {
2958 27d06aa8 LJIYEON
                    if (PSNItem.IsBypass)
2959 36a45f13 gaqhf
                    {
2960 27d06aa8 LJIYEON
                        foreach (Topology topology in PSNItem.Topologies)
2961
                        {
2962
                            DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName));
2963
                            if (rows.Length.Equals(1))
2964
                                rows.First()["SubType"] = "Bypass";
2965
                        }
2966
                    }
2967
2968
                    if (PSNItem.StartType == PSNType.Header)
2969
                    {
2970
                        Topology topology = PSNItem.Topologies.First();
2971
                        DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName));
2972
                        if (rows.Length.Equals(1))
2973
                            rows.First()["SubType"] = "Header";
2974
                    }
2975
                    else if (PSNItem.EndType == PSNType.Header)
2976
                    {
2977
                        Topology topology = PSNItem.Topologies.Last();
2978 7881ec8f gaqhf
                        DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName));
2979
                        if (rows.Length.Equals(1))
2980 27d06aa8 LJIYEON
                            rows.First()["SubType"] = "Header";
2981 36a45f13 gaqhf
                    }
2982
                }
2983 7881ec8f gaqhf
2984 36a45f13 gaqhf
2985 27d06aa8 LJIYEON
                foreach (Topology topology in Topologies)
2986 7881ec8f gaqhf
                {
2987 27d06aa8 LJIYEON
                    try
2988
                    {
2989
                        DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName));
2990 7106e181 LJIYEON
2991
                        if (rows.Count() > 0)
2992 27d06aa8 LJIYEON
                        {
2993 3210f690 LJIYEON
                            if (rows.Length.Equals(1) && rows.First()["SubType"] == null || string.IsNullOrEmpty(rows.First()["SubType"].ToString()))
2994
                            {
2995
                                if (topology.Items == null)
2996
                                    continue;
2997 27d06aa8 LJIYEON
2998 3210f690 LJIYEON
                                Item firstItem = topology.Items.First();
2999
                                Item lastItem = topology.Items.Last();
3000 27d06aa8 LJIYEON
3001 3210f690 LJIYEON
                                List<Relation> relations = new List<Relation>();
3002 7881ec8f gaqhf
3003 3210f690 LJIYEON
                                if (firstItem.Relations.FindAll(x => x.Item == null).Count() != 0)
3004
                                    relations.AddRange(firstItem.Relations.FindAll(x => x.Item != null && x.Item.Topology.ID != topology.ID));
3005 7881ec8f gaqhf
3006 3210f690 LJIYEON
                                if (lastItem.Relations.FindAll(x => x.Item == null).Count() != 0)
3007
                                    relations.AddRange(lastItem.Relations.FindAll(x => x.Item != null && x.Item.Topology.ID != topology.ID));
3008
3009
                                if (relations.Count > 0)
3010
                                    rows.First()["SubType"] = "OtherSystem";
3011
                            }
3012 27d06aa8 LJIYEON
                        }
3013
                    }
3014
                    catch (Exception ex)
3015
                    {
3016 7106e181 LJIYEON
3017 27d06aa8 LJIYEON
                        MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
3018
                    }
3019 7881ec8f gaqhf
                }
3020
3021 7106e181 LJIYEON
                foreach (DataRow row in TopologySet.Rows)
3022 27d06aa8 LJIYEON
                    if (row["SubType"] == null || string.IsNullOrEmpty(row["SubType"].ToString()))
3023
                        row["SubType"] = "Normal";
3024
            }
3025
            catch (Exception ex)
3026
            {
3027
                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
3028
                MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
3029
            }
3030 7881ec8f gaqhf
        }
3031 5e4c2ad1 LJIYEON
3032 7881ec8f gaqhf
        private bool IsBypass(PSNItem PSNItem)
3033
        {
3034
            bool bResult = false;
3035
3036
            if (PSNItem.GetPSNType() == "B2B")
3037
            {
3038
                Group firstGroup = PSNItem.Groups.First();
3039
                Group lastGroup = PSNItem.Groups.Last();
3040
                Item firstItem = firstGroup.Items.First();
3041
                Item lastItem = lastGroup.Items.Last();
3042
3043
                Item connectedFirstItem = GetConnectedItemByPSN(firstItem);
3044
                Item connectedLastItem = GetConnectedItemByPSN(lastItem);
3045 36a45f13 gaqhf
3046 7881ec8f gaqhf
                if (connectedFirstItem.LineNumber != null && connectedLastItem.LineNumber != null &&
3047
                    !string.IsNullOrEmpty(connectedFirstItem.LineNumber.Name) && !string.IsNullOrEmpty(connectedLastItem.LineNumber.Name) &&
3048
                    connectedFirstItem.LineNumber.Name == connectedLastItem.LineNumber.Name)
3049
                    bResult = true;
3050
                else if (connectedFirstItem.PSNItem == connectedLastItem.PSNItem)
3051
                    bResult = true;
3052
            }
3053 36a45f13 gaqhf
3054
            Item GetConnectedItemByPSN(Item item)
3055
            {
3056
                Item result = null;
3057
3058
                Relation relation = item.Relations.Find(x => x.Item != null && x.Item.PSNItem != item.PSNItem);
3059
                if (relation != null)
3060
                    result = relation.Item;
3061
3062 3210f690 LJIYEON
3063 36a45f13 gaqhf
                return result;
3064
            }
3065 7881ec8f gaqhf
3066
            return bResult;
3067
        }
3068 5e4c2ad1 LJIYEON
3069 419055fa LJIYEON
        private void DeleteVentDrain()
3070
        {
3071
            DataRow[] ventdrainRows = PipeSystemNetwork.Select(" IncludingVirtualData = 'Vent_Drain'");
3072 7106e181 LJIYEON
3073 419055fa LJIYEON
            foreach (DataRow dataRow in ventdrainRows)
3074
            {
3075 7106e181 LJIYEON
                dataRow.Delete();
3076
            }
3077 419055fa LJIYEON
        }
3078
3079 5e4c2ad1 LJIYEON
        private void UpdateAccuracy()
3080
        {
3081 54b6df95 LJIYEON
            //DataRow[] statusRows = PipeSystemNetwork.Select(" Type = 'Error' OR IsValid = 'Error'"); 
3082
            DataRow[] statusRows = PipeSystemNetwork.Select(" Type = 'Error' OR IsValid = 'Error'");
3083 5e4c2ad1 LJIYEON
            List<double> lstAcc = null;
3084
            string Status = string.Empty;
3085 f9f2787b LJIYEON
3086 5e4c2ad1 LJIYEON
            foreach (DataRow dataRow in statusRows)
3087
            {
3088
                lstAcc = new List<double>();
3089
                Status = dataRow.Field<string>("Status");
3090
                if (!string.IsNullOrEmpty(Status))
3091
                {
3092 51974d2b LJIYEON
                    string[] arrStatus = Status.Split(',');
3093 7106e181 LJIYEON
                    foreach (string arrstr in arrStatus)
3094 51974d2b LJIYEON
                    {
3095
                        if (arrstr.Contains(Rule1)) //Missing LineNumber_1
3096
                            lstAcc.Add(0.75);
3097 f9f2787b LJIYEON
3098 51974d2b LJIYEON
                        if (arrstr.Contains(Rule2)) //Missing LineNumber_2
3099
                            lstAcc.Add(0.7);
3100 f9f2787b LJIYEON
3101 51974d2b LJIYEON
                        if (arrstr.Contains(Rule3)) // OPC Disconnected
3102
                            lstAcc.Add(0.5);
3103 f9f2787b LJIYEON
3104 51974d2b LJIYEON
                        if (arrstr.Contains(Rule4)) //Missing ItemTag or Description
3105
                            lstAcc.Add(0.65);
3106
3107
                        if (arrstr.Contains(Rule5)) //Line Disconnected
3108
                            lstAcc.Add(0.6);
3109
                    }
3110 5e4c2ad1 LJIYEON
                }
3111
3112
                string PSNAccuracy = dataRow["PSNAccuracy"].ToString();
3113
                if (PSNAccuracy == "100")
3114
                    PSNAccuracy = "1";
3115
3116 51974d2b LJIYEON
                PSNAccuracy = Convert.ToString(Convert.ToDecimal(AccuracyCalculation(lstAcc, Convert.ToDouble(PSNAccuracy))));
3117
                //if (PSNAccuracy != "100")
3118
                //{
3119
                //    //dataRow["IncludingVirtualData"] = "No";
3120 7106e181 LJIYEON
                dataRow["PSNAccuracy"] = PSNAccuracy;
3121 51974d2b LJIYEON
                //}
3122 5e4c2ad1 LJIYEON
            }
3123 bfe278bb LJIYEON
            DataTable dt = PipeSystemNetwork.DefaultView.ToTable(true, new string[] { "OID" });
3124
            foreach (DataRow dr in dt.Rows)
3125
            {
3126
                string oid = dr.Field<string>("OID");
3127
                DataRow[] select = PipeSystemNetwork.Select(string.Format("OID = '{0}'", oid));
3128
                double totalDdr = 0;
3129
                foreach (DataRow ddr in select)
3130
                {
3131
                    double acc = Convert.ToDouble(ddr.Field<string>("PSNAccuracy"));
3132
                    if (acc == 100) acc = 1;
3133
                    if (totalDdr == 0) totalDdr = acc;
3134
                    else totalDdr *= acc;
3135
                }
3136
3137
                totalDdr *= 100;
3138
3139 7106e181 LJIYEON
                if (totalDdr != 100)
3140 bfe278bb LJIYEON
                {
3141 f9f2787b LJIYEON
                    foreach (DataRow ddr in select)
3142
                    {
3143
                        ddr["IncludingVirtualData"] = "Yes";
3144 51974d2b LJIYEON
                        ddr["PSNAccuracy"] = String.Format("{0:0.00}", Math.Round(totalDdr, 2));
3145 7d6d1693 이지연
                        ddr["IsValid"] = "Error";
3146 51974d2b LJIYEON
                    }
3147
                }
3148
                else
3149
                {
3150
                    foreach (DataRow ddr in select)
3151
                    {
3152
                        ddr["IncludingVirtualData"] = "No";
3153
                        ddr["PSNAccuracy"] = String.Format("{0:0.00}", Math.Round(totalDdr, 2));
3154 f9f2787b LJIYEON
                    }
3155 bfe278bb LJIYEON
                }
3156
            }
3157
3158 5e4c2ad1 LJIYEON
        }
3159
3160 a5616391 LJIYEON
        private void UpdateKeywordForPSN()
3161
        {
3162
            #region Keyword Info
3163
            KeywordInfo KeywordInfos = new KeywordInfo();
3164
            DataTable dtKeyword = DB.SelectKeywordsSetting();
3165
            foreach (DataRow row in dtKeyword.Rows)
3166
            {
3167
                int index = Convert.ToInt32(row["INDEX"]);
3168
                string name = row["NAME"].ToString();
3169
                string keyword = row["KEYWORD"].ToString();
3170
3171
                //KeywordInfo keywordInfo = new KeywordInfo();   
3172
                KeywordInfos.KeywordItems.Add(new KeywordItem()
3173
                {
3174
                    Index = index,
3175
                    Name = name,
3176
                    Keyword = keyword
3177
                });
3178
            }
3179
            #endregion
3180
3181 a2973aa3 LJIYEON
            DataRow[] endofHeaderRows = PipeSystemNetwork.Select(string.Format(" From_Data = '{0}' OR To_Data = '{0}'", "ENDOFHEADER"));
3182
            foreach (DataRow dataRow in endofHeaderRows)
3183
            {
3184
                PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString());
3185
3186
                if (dataRow.Field<string>("From_Data") == "ENDOFHEADER")
3187
                {
3188
                    DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
3189
                    DataRow dr = pathItemRows.First();
3190
                    dr["CLASS"] = PSNItem.Groups.First().Items.First().ID2DBName;
3191
                    dr["TYPE"] = "End";
3192
                    dr["ITEMTAG"] = "ENDOFHEADER";
3193
                    dr["DESCRIPTION"] = "ENDOFHEADER";
3194
                }
3195
3196
                if (dataRow.Field<string>("To_Data") == "ENDOFHEADER")
3197
                {
3198
                    DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
3199
                    DataRow dr = pathItemRows.Last();
3200
                    dr["CLASS"] = PSNItem.Groups.Last().Items.Last().ID2DBName;
3201
                    dr["TYPE"] = "End";
3202
                    dr["ITEMTAG"] = "ENDOFHEADER";
3203
                    dr["DESCRIPTION"] = "ENDOFHEADER";
3204
                }
3205
            }
3206
3207 a5616391 LJIYEON
            foreach (KeywordItem keyitem in KeywordInfos.KeywordItems)
3208
            {
3209 a2973aa3 LJIYEON
                DataRow[] keywordRows = PipeSystemNetwork.Select(string.Format(" From_Data = '{0}' OR To_Data = '{0}'", keyitem.Keyword));
3210 a5616391 LJIYEON
                foreach (DataRow dataRow in keywordRows)
3211 7106e181 LJIYEON
                {
3212
                    PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString());
3213 a5616391 LJIYEON
3214 7106e181 LJIYEON
                    if (dataRow.Field<string>("From_Data") == keyitem.Keyword)
3215
                    {
3216 a5616391 LJIYEON
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
3217 7106e181 LJIYEON
3218 a2973aa3 LJIYEON
                        //
3219
                        //if(.)
3220 7106e181 LJIYEON
                        if (PSNItem.Groups.First().Items.First().Name.Equals(keyitem.Name))
3221 a5616391 LJIYEON
                        {
3222
                            DataRow dr = pathItemRows.First();
3223
                            //dr["CLASS"] = ""; //Type
3224
                            dr["TYPE"] = "End";
3225
                            dr["ITEMTAG"] = keyitem.Keyword;
3226
                            dr["DESCRIPTION"] = keyitem.Keyword;
3227
                        }
3228 7106e181 LJIYEON
3229 a5616391 LJIYEON
                    }
3230
3231 a2973aa3 LJIYEON
                    if (dataRow.Field<string>("To_Data") == keyitem.Keyword)
3232 a5616391 LJIYEON
                    {
3233
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
3234
3235 a2973aa3 LJIYEON
                        if (PSNItem.Groups.Last().Items.Last().Name.Equals(keyitem.Name))
3236 a5616391 LJIYEON
                        {
3237
                            DataRow dr = pathItemRows.Last();
3238
                            //dr["CLASS"] = ""; //Type
3239
                            dr["TYPE"] = "End";
3240
                            dr["ITEMTAG"] = keyitem.Keyword;
3241
                            dr["DESCRIPTION"] = keyitem.Keyword;
3242
                            //dr.Field<string>("Type")
3243
                        }
3244
3245 7106e181 LJIYEON
                    }
3246 a5616391 LJIYEON
                }
3247 7106e181 LJIYEON
            }
3248 a5616391 LJIYEON
        }
3249
3250 7881ec8f gaqhf
        private void UpdateErrorForPSN()
3251
        {
3252 45529c16 LJIYEON
            DataRow[] errorRows = PipeSystemNetwork.Select(string.Format(" Type = '{0}'", ErrorType.Error));
3253 7881ec8f gaqhf
            foreach (DataRow dataRow in errorRows)
3254
            {
3255 eb44d82c LJIYEON
                try
3256 710a49f1 gaqhf
                {
3257 eb44d82c LJIYEON
                    PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString());
3258 dd27861e 이지연
                   
3259 eb44d82c LJIYEON
                    bool change = false;
3260 aa195a5b LJIYEON
                    bool bCheck = false;
3261 eb44d82c LJIYEON
                    if (!PSNItem.EnableType(PSNItem.StartType))
3262 710a49f1 gaqhf
                    {
3263 eb44d82c LJIYEON
                        change = true;
3264 7106e181 LJIYEON
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
3265 eb44d82c LJIYEON
                        int insertIndex = PathItems.Rows.IndexOf(pathItemRows.First());
3266 7106e181 LJIYEON
3267 eb44d82c LJIYEON
                        Item item = PSNItem.Groups.First().Items.First();
3268
                        try
3269 a36541fb LJIYEON
                        {
3270
                            string FROM_DATA = string.Format("TIEINPOINT_{0:D5}V", tieInPointIndex);
3271 7106e181 LJIYEON
3272 dd27861e 이지연
                            foreach (DataRow loopRow in PipeSystemNetwork.Select(string.Format("OID = '{0}'", PSNItem.PSN_OID())))
3273 eb44d82c LJIYEON
                            {
3274 dd27861e 이지연
                                loopRow["FROM_DATA"] = FROM_DATA;
3275
                                if (item.ItemType == ItemType.Line)
3276 48870200 LJIYEON
                                {
3277
                                    if (loopRow.Field<string>("OrderNumber") == "0")
3278
                                    {
3279
                                        string status = loopRow.Field<string>("Status");
3280 7106e181 LJIYEON
                                        //string isvali
3281 48870200 LJIYEON
                                        if (string.IsNullOrEmpty(status))
3282
                                            status = "Line Disconnected";
3283
                                        else if (!status.Contains("Line Disconnected"))
3284
                                            status += ", Line Disconnected";
3285
                                        loopRow["Status"] = status;
3286 7106e181 LJIYEON
                                        if (!string.IsNullOrEmpty(status))
3287
                                            loopRow["IsValid"] = "Error";
3288 48870200 LJIYEON
                                    }
3289
                                }
3290 eb44d82c LJIYEON
                            }
3291 dd27861e 이지연
3292
                            tieInPointIndex++;
3293
3294
                            if (item.ItemType == ItemType.Line)
3295
                            {
3296
                                PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.First(), FROM_DATA), insertIndex);                                
3297
                            }
3298 eb44d82c LJIYEON
                            else
3299
                            {
3300 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);
3301
                                PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.First(), FROM_DATA), insertIndex);
3302 7106e181 LJIYEON
3303 dd27861e 이지연
                                bCheck = true;
3304 eb44d82c LJIYEON
                            }
3305 710a49f1 gaqhf
3306 eb44d82c LJIYEON
                            PSNItem.StartType = PSNType.Equipment;
3307
                        }
3308
                        catch (Exception ex)
3309
                        {
3310
                            MessageBox.Show("Please check the item.\r\nDrawingName : " + item.Document.DrawingName + "\r\nUID : " + item.UID, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
3311
                            return;
3312
                        }
3313
                    }
3314 710a49f1 gaqhf
3315 eb44d82c LJIYEON
                    if (!PSNItem.EnableType(PSNItem.EndType))
3316 dd27861e 이지연
                    {                        
3317 eb44d82c LJIYEON
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
3318 f6c9db1a 이지연
                        //int insertIndex = PathItems.Rows.IndexOf(pathItemRows.First()) + pathItemRows.Count() - 1;
3319
                        DataRow dr = pathItemRows.Last();
3320
                        if (change)
3321 dd27861e 이지연
                        {
3322
                            if(bCheck)
3323
                                dr = pathItemRows[pathItemRows.Count() - 3];
3324
                            else
3325
                            {
3326
                                dr = pathItemRows[pathItemRows.Count() - 2];
3327
                            }
3328
                        }
3329 f6c9db1a 이지연
3330 dd27861e 이지연
                        change = true;
3331 f6c9db1a 이지연
                        int insertIndex = PathItems.Rows.IndexOf(dr) + 1;
3332 a36541fb LJIYEON
3333 eb44d82c LJIYEON
                        Item item = PSNItem.Groups.Last().Items.Last();
3334
                        try
3335 a36541fb LJIYEON
                        {
3336
                            string TO_DATA = string.Format("TIEINPOINT_{0:D5}V", tieInPointIndex);
3337
3338 7d6d1693 이지연
                            
3339 dd27861e 이지연
                            foreach (DataRow loopRow in PipeSystemNetwork.Select(string.Format("OID = '{0}'", PSNItem.PSN_OID())))
3340 51974d2b LJIYEON
                            {
3341 dd27861e 이지연
                                loopRow["TO_DATA"] = TO_DATA;
3342
                                if (item.ItemType == ItemType.Line)
3343 51974d2b LJIYEON
                                {
3344 48870200 LJIYEON
                                    if (loopRow.Field<string>("OrderNumber") == Convert.ToString(PipeSystemNetwork.Select(string.Format("OID = '{0}'", PSNItem.PSN_OID())).Count() - 1))
3345
                                    {
3346
                                        string status = loopRow.Field<string>("Status");
3347
                                        if (string.IsNullOrEmpty(status))
3348
                                            status = "Line Disconnected";
3349
                                        else if (!status.Contains("Line Disconnected"))
3350
                                            status += ", Line Disconnected";
3351
                                        loopRow["Status"] = status;
3352 7106e181 LJIYEON
                                        if (!string.IsNullOrEmpty(status))
3353
                                            loopRow["IsValid"] = "Error";
3354 48870200 LJIYEON
                                    }
3355 51974d2b LJIYEON
                                }
3356 7d6d1693 이지연
3357 dd27861e 이지연
                            }                            
3358 48870200 LJIYEON
3359 eb44d82c LJIYEON
                            tieInPointIndex++;
3360 7106e181 LJIYEON
3361 f6c9db1a 이지연
                            if (item.ItemType == ItemType.Line)
3362 eb44d82c LJIYEON
                            {
3363 f6c9db1a 이지연
                                PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.Last(), TO_DATA), insertIndex);
3364 eb44d82c LJIYEON
                            }
3365
                            else
3366
                            {
3367 f6c9db1a 이지연
                                PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.Last(), TO_DATA), insertIndex);
3368 d1afd412 이지연
                                if(PathItems.Select(string.Format("PipeLine_OID = '{0}' AND ItemName = 'PipeRun' AND PipeSystemNetwork_OID = '{1}'", item.PSNPipeLineID, dataRow["OID"])).Count() > 0)
3369
                                    PathItems.Rows.InsertAt(createLineRow(PathItems.Select(string.Format("PipeLine_OID = '{0}' AND ItemName = 'PipeRun' AND PipeSystemNetwork_OID = '{1}'", item.PSNPipeLineID, dataRow["OID"])).Last()), insertIndex);
3370 a89e25a0 이지연
                               
3371 eb44d82c LJIYEON
                            }
3372 7106e181 LJIYEON
3373 eb44d82c LJIYEON
                            PSNItem.EndType = PSNType.Equipment;
3374
                        }
3375 7106e181 LJIYEON
                        catch (Exception ex)
3376 eb44d82c LJIYEON
                        {
3377
                            MessageBox.Show("Please check the item.\r\nDrawingName : " + item.Document.DrawingName + "\r\nUID : " + item.UID, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
3378
                            return;
3379
                        }
3380 710a49f1 gaqhf
                    }
3381 eb44d82c LJIYEON
3382
                    dataRow["Type"] = PSNItem.GetPSNType();
3383
                    if (change)
3384 710a49f1 gaqhf
                    {
3385 eb44d82c LJIYEON
                        int rowIndex = 0;
3386
                        for (int i = 0; i < PathItems.Rows.Count; i++)
3387
                        {
3388
                            DataRow row = PathItems.Rows[i];
3389
                            if (row["PipeSystemNetwork_OID"].ToString() != dataRow["OID"].ToString())
3390
                                continue;
3391
                            string sequenceData = row["SequenceData_OID"].ToString();
3392
                            string[] split = sequenceData.Split(new char[] { '_' });
3393
3394
                            StringBuilder sb = new StringBuilder();
3395
                            for (int j = 0; j < split.Length - 1; j++)
3396
                                sb.Append(split[j] + "_");
3397
                            sb.Append(rowIndex++);
3398
                            row["SequenceData_OID"] = sb.ToString();
3399 a36541fb LJIYEON
3400 3210f690 LJIYEON
                            DataRow seqItemRows = SequenceData.Select(string.Format("PathItem_OID = '{0}'", row["OID"])).FirstOrDefault();
3401
                            int insertSeqIndex = SequenceData.Rows.IndexOf(seqItemRows);
3402
3403
                            string[] splitseq = sb.ToString().Split(new char[] { '_' });
3404
3405
                            if (seqItemRows == null)
3406
                            {
3407 7106e181 LJIYEON
                                DataRow newRow = SequenceData.NewRow();
3408 3210f690 LJIYEON
                                newRow["OID"] = sb.ToString();
3409
                                newRow["SERIALNUMBER"] = splitseq[splitseq.Length - 1];
3410
                                newRow["PathItem_OID"] = row["OID"];
3411
                                newRow["TopologySet_OID_Key"] = row["TopologySet_OID"];
3412
                                SequenceData.Rows.InsertAt(newRow, Convert.ToInt32(splitseq[splitseq.Length - 1]));
3413
                            }
3414
                            else
3415
                            {
3416
                                seqItemRows["OID"] = sb.ToString();
3417
                                seqItemRows["SERIALNUMBER"] = splitseq[splitseq.Length - 1];
3418
                                seqItemRows["PathItem_OID"] = row["OID"];
3419
                                seqItemRows["TopologySet_OID_Key"] = row["TopologySet_OID"];
3420 7106e181 LJIYEON
                            }
3421
                        }
3422 eb44d82c LJIYEON
                    }
3423 5e4c2ad1 LJIYEON
3424 a36541fb LJIYEON
                    DataRow createTerminatorRow(DataRow itemRow, string DATA)
3425 eb44d82c LJIYEON
                    {
3426
                        DataRow newRow = PathItems.NewRow();
3427
                        newRow["OID"] = Guid.NewGuid().ToString();
3428
                        newRow["SequenceData_OID"] = itemRow["SequenceData_OID"];
3429
                        newRow["TopologySet_OID"] = itemRow["TopologySet_OID"];
3430
                        newRow["BranchTopologySet_OID"] = itemRow["BranchTopologySet_OID"];
3431 7106e181 LJIYEON
                        newRow["PipeLine_OID"] = itemRow["PipeLine_OID"];
3432 a36541fb LJIYEON
                        newRow["ITEMNAME"] = "PipingComp"; //newRow["ITEMNAME"] = "End of line terminator";
3433
                        newRow["ITEMTAG"] = DATA; //itemRow["ITEMTAG"];
3434 7106e181 LJIYEON
                        newRow["DESCRIPTION"] = DATA;
3435 eb44d82c LJIYEON
                        newRow["Class"] = "End of line terminator";
3436
                        newRow["SubClass"] = "End of line terminator";
3437 a36541fb LJIYEON
                        newRow["TYPE"] = "End";
3438 eb44d82c LJIYEON
                        newRow["PIDNAME"] = itemRow["PIDNAME"];
3439
                        newRow["NPD"] = itemRow["NPD"];
3440
                        newRow["PipeSystemNetwork_OID"] = itemRow["PipeSystemNetwork_OID"];
3441
                        newRow["ViewPipeSystemNetwork_OID"] = itemRow["ViewPipeSystemNetwork_OID"];
3442 7106e181 LJIYEON
                        newRow["PipeRun_OID"] = itemRow["PipeRun_OID"];
3443 0d4b3dee 이지연
                        newRow["EGTConnectedPoint"] = "0";
3444 a36541fb LJIYEON
                        return newRow;
3445
                    }
3446
3447 eb44d82c LJIYEON
                    DataRow createLineRow(DataRow itemRow)
3448 710a49f1 gaqhf
                    {
3449 eb44d82c LJIYEON
                        DataRow newRow = PathItems.NewRow();
3450
                        newRow["OID"] = Guid.NewGuid().ToString();
3451
                        newRow["SequenceData_OID"] = itemRow["SequenceData_OID"];
3452
                        newRow["TopologySet_OID"] = itemRow["TopologySet_OID"];
3453
                        newRow["BranchTopologySet_OID"] = itemRow["BranchTopologySet_OID"];
3454
                        newRow["PipeLine_OID"] = itemRow["PipeLine_OID"];
3455
                        newRow["ITEMNAME"] = itemRow["ITEMNAME"];
3456
                        newRow["ITEMTAG"] = itemRow["ITEMTAG"];
3457
                        newRow["Class"] = itemRow["Class"];
3458
                        newRow["SubClass"] = itemRow["SubClass"];
3459
                        newRow["TYPE"] = itemRow["TYPE"];
3460
                        newRow["PIDNAME"] = itemRow["PIDNAME"];
3461
                        newRow["NPD"] = itemRow["NPD"];
3462
                        newRow["PipeSystemNetwork_OID"] = itemRow["PipeSystemNetwork_OID"];
3463
                        newRow["ViewPipeSystemNetwork_OID"] = itemRow["ViewPipeSystemNetwork_OID"];
3464
                        newRow["PipeRun_OID"] = itemRow["PipeRun_OID"];
3465 0d4b3dee 이지연
                        newRow["EGTConnectedPoint"] = "0";
3466 eb44d82c LJIYEON
                        return newRow;
3467 710a49f1 gaqhf
                    }
3468
                }
3469 7106e181 LJIYEON
                catch (Exception ex)
3470 5e4c2ad1 LJIYEON
                {
3471 710a49f1 gaqhf
3472
                }
3473 eb44d82c LJIYEON
            }
3474 6b9e7a56 gaqhf
        }
3475 4e2e0aa1 LJIYEON
3476
        private void InsertTeePSN()
3477
        {
3478 3f5cb4dc LJIYEON
            DataTable dt = PipeSystemNetwork.DefaultView.ToTable(true, new string[] { "OID", "Type" });
3479
            DataRow[] branchRows = dt.Select("Type Like '%B%'");
3480 820e283f LJIYEON
            bool change = false;
3481 4e2e0aa1 LJIYEON
            foreach (DataRow dataRow in branchRows)
3482
            {
3483
                try
3484 7106e181 LJIYEON
                {
3485 4e2e0aa1 LJIYEON
                    PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString());
3486 820e283f LJIYEON
                    change = false;
3487
3488 4e2e0aa1 LJIYEON
                    if (PSNItem.StartType == PSNType.Branch)
3489
                    {
3490 820e283f LJIYEON
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", PSNItem.PSN_OID()));
3491 4e2e0aa1 LJIYEON
                        int insertIndex = PathItems.Rows.IndexOf(pathItemRows.First());
3492 820e283f LJIYEON
                        Item Teeitem = PSNItem.Groups.First().Items.First();
3493 4e2e0aa1 LJIYEON
                        try
3494 820e283f LJIYEON
                        {
3495
                            if (Teeitem.ItemType == ItemType.Line)
3496 4e2e0aa1 LJIYEON
                            {
3497
                                if (pathItemRows.First().Field<string>("SubClass") != "Tee")
3498 7106e181 LJIYEON
                                {
3499 4e2e0aa1 LJIYEON
                                    PathItems.Rows.InsertAt(createTeeRow(pathItemRows.First()), insertIndex);
3500 0e9d868c LJIYEON
                                    pathItemRows.First().SetField("BranchTopologySet_OID", string.Empty);
3501
                                    pathItemRows.First().SetField("ViewPipeSystemNetwork_OID", dataRow["OID"].ToString());
3502 820e283f LJIYEON
                                    change = true;
3503 4e2e0aa1 LJIYEON
                                }
3504
3505 820e283f LJIYEON
                            }
3506 4e2e0aa1 LJIYEON
                        }
3507
                        catch (Exception ex)
3508
                        {
3509 820e283f LJIYEON
                            MessageBox.Show("Please check the item.\r\nDrawingName : " + Teeitem.Document.DrawingName + "\r\nUID : " + Teeitem.UID, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
3510 4e2e0aa1 LJIYEON
                            return;
3511
                        }
3512
                    }
3513
3514
                    if (PSNItem.EndType == PSNType.Branch)
3515
                    {
3516 820e283f LJIYEON
                        //change = true;
3517
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", PSNItem.PSN_OID()));
3518 7106e181 LJIYEON
3519 820e283f LJIYEON
                        Item Teeitem = PSNItem.Groups.Last().Items.Last();
3520 4e2e0aa1 LJIYEON
3521 820e283f LJIYEON
                        DataRow dr = pathItemRows.Last();
3522
                        if (change)
3523
                            dr = pathItemRows[pathItemRows.Count() - 2];
3524 e36ca22f LJIYEON
3525 b683578e LJIYEON
                        int insertIndex = PathItems.Rows.IndexOf(dr) + 1;
3526 e36ca22f LJIYEON
3527 4e2e0aa1 LJIYEON
                        try
3528
                        {
3529 820e283f LJIYEON
                            if (Teeitem.ItemType == ItemType.Line)
3530 4e2e0aa1 LJIYEON
                            {
3531 820e283f LJIYEON
                                if (dr.Field<string>("SubClass") != "Tee")
3532
                                {
3533
                                    PathItems.Rows.InsertAt(createTeeRow(dr), insertIndex);
3534
                                    change = true;
3535 0e9d868c LJIYEON
                                    dr.SetField("BranchTopologySet_OID", string.Empty);
3536
                                    dr.SetField("ViewPipeSystemNetwork_OID", dataRow["OID"].ToString());
3537 820e283f LJIYEON
                                }
3538
3539 4e2e0aa1 LJIYEON
                            }
3540
                        }
3541
                        catch (Exception ex)
3542
                        {
3543 820e283f LJIYEON
                            MessageBox.Show("Please check the item.\r\nDrawingName : " + Teeitem.Document.DrawingName + "\r\nUID : " + Teeitem.UID, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
3544 4e2e0aa1 LJIYEON
                            return;
3545
                        }
3546
                    }
3547
3548
                    if (change)
3549
                    {
3550 820e283f LJIYEON
                        //DataRow[] pathItemRows = pathItemsDT.Select(string.Format("PipeSystemNetwork_OID = '{0}'", PSNItem.PSN_OID()));
3551 4e2e0aa1 LJIYEON
                        int rowIndex = 0;
3552
                        for (int i = 0; i < PathItems.Rows.Count; i++)
3553
                        {
3554
                            DataRow row = PathItems.Rows[i];
3555 820e283f LJIYEON
                            if (row["PipeSystemNetwork_OID"].ToString() != PSNItem.PSN_OID())
3556 4e2e0aa1 LJIYEON
                                continue;
3557
                            string sequenceData = row["SequenceData_OID"].ToString();
3558
                            string[] split = sequenceData.Split(new char[] { '_' });
3559
3560
                            StringBuilder sb = new StringBuilder();
3561
                            for (int j = 0; j < split.Length - 1; j++)
3562
                                sb.Append(split[j] + "_");
3563
                            sb.Append(rowIndex++);
3564
                            row["SequenceData_OID"] = sb.ToString();
3565
3566
                            DataRow seqItemRows = SequenceData.Select(string.Format("PathItem_OID = '{0}'", row["OID"])).FirstOrDefault();
3567
                            int insertSeqIndex = SequenceData.Rows.IndexOf(seqItemRows);
3568
3569
                            string[] splitseq = sb.ToString().Split(new char[] { '_' });
3570
3571
                            if (seqItemRows == null)
3572
                            {
3573
                                DataRow newRow = SequenceData.NewRow();
3574
                                newRow["OID"] = sb.ToString();
3575
                                newRow["SERIALNUMBER"] = splitseq[splitseq.Length - 1];
3576
                                newRow["PathItem_OID"] = row["OID"];
3577
                                newRow["TopologySet_OID_Key"] = row["TopologySet_OID"];
3578
                                SequenceData.Rows.InsertAt(newRow, Convert.ToInt32(splitseq[splitseq.Length - 1]));
3579
                            }
3580
                            else
3581
                            {
3582
                                seqItemRows["OID"] = sb.ToString();
3583
                                seqItemRows["SERIALNUMBER"] = splitseq[splitseq.Length - 1];
3584
                                seqItemRows["PathItem_OID"] = row["OID"];
3585
                                seqItemRows["TopologySet_OID_Key"] = row["TopologySet_OID"];
3586
                            }
3587
                        }
3588 820e283f LJIYEON
                    }
3589 7106e181 LJIYEON
3590 4e2e0aa1 LJIYEON
                    DataRow createTeeRow(DataRow itemRow)
3591
                    {
3592
                        DataRow newRow = PathItems.NewRow();
3593
                        newRow["OID"] = Guid.NewGuid().ToString();
3594
                        newRow["SequenceData_OID"] = itemRow["SequenceData_OID"];
3595
                        newRow["TopologySet_OID"] = itemRow["TopologySet_OID"];
3596
                        newRow["BranchTopologySet_OID"] = itemRow["BranchTopologySet_OID"];
3597
                        newRow["PipeLine_OID"] = itemRow["PipeLine_OID"];
3598
                        newRow["ITEMNAME"] = "Branch"; //newRow["ITEMNAME"] = "End of line terminator";
3599
                        newRow["ITEMTAG"] = itemRow["ITEMTAG"];
3600
                        newRow["DESCRIPTION"] = "";
3601
                        newRow["Class"] = "Branch";
3602
                        newRow["SubClass"] = "Tee";
3603
                        newRow["TYPE"] = itemRow["TYPE"];
3604
                        newRow["PIDNAME"] = itemRow["PIDNAME"];
3605
                        newRow["NPD"] = itemRow["NPD"];
3606
                        newRow["PipeSystemNetwork_OID"] = itemRow["PipeSystemNetwork_OID"];
3607
                        newRow["ViewPipeSystemNetwork_OID"] = itemRow["ViewPipeSystemNetwork_OID"];
3608
                        newRow["PipeRun_OID"] = itemRow["PipeRun_OID"];
3609 0eefef3d 이지연
                      
3610
                        newRow["EGTConnectedPoint"] = 0;
3611 4e2e0aa1 LJIYEON
                        return newRow;
3612
                    }
3613
                }
3614
                catch (Exception ex)
3615
                {
3616
3617
                }
3618
            }
3619
        }
3620 6b9e7a56 gaqhf
    }
3621
3622
    public class PSNItem
3623
    {
3624 8f24b438 gaqhf
        public PSNItem(int count, int Revision)
3625 6b9e7a56 gaqhf
        {
3626
            Groups = new List<Group>();
3627
            Topologies = new List<Topology>();
3628 94a117ca gaqhf
3629
            Index = count + 1;
3630 8f24b438 gaqhf
            this.Revision = Revision;
3631 6b9e7a56 gaqhf
        }
3632 eb44d82c LJIYEON
3633 8f24b438 gaqhf
        private int Revision;
3634 6b9e7a56 gaqhf
        public string UID { get; set; }
3635
        public List<Group> Groups { get; set; }
3636
        public List<Topology> Topologies { get; set; }
3637
        public PSNType StartType { get; set; }
3638
        public PSNType EndType { get; set; }
3639 94a117ca gaqhf
        public int Index { get; set; }
3640 72775f2e LJIYEON
        public string IsValid { get; set; }
3641 a36541fb LJIYEON
        public bool IsKeyword { get; set; }
3642 36a45f13 gaqhf
        public string Status { get; set; }
3643 ddc1c369 LJIYEON
        public string IncludingVirtualData { get; set; }
3644
        public string PSNAccuracy { get; set; }
3645 eb44d82c LJIYEON
        public KeywordInfo KeywordInfos = new KeywordInfo();
3646 a36541fb LJIYEON
        public DataTable Nozzle = new DataTable();
3647 ddc1c369 LJIYEON
3648 94a117ca gaqhf
        public string PSN_OID()
3649
        {
3650 36a45f13 gaqhf
            return string.Format("V{0}-PSN-{1}", string.Format("{0:D4}", Revision), string.Format("{0:D5}", Index));
3651 94a117ca gaqhf
        }
3652 3610fd3f LJIYEON
3653 94a117ca gaqhf
        public string GetPSNType()
3654
        {
3655
            string result = string.Empty;
3656
3657
            if (EnableType(StartType) && EnableType(EndType))
3658
            {
3659
                if (StartType == PSNType.Equipment && EndType == PSNType.Equipment)
3660
                    result = "E2E";
3661
                else if (StartType == PSNType.Branch && EndType == PSNType.Branch)
3662
                    result = "B2B";
3663
                else if (StartType == PSNType.Header && EndType == PSNType.Header)
3664
                    result = "HD2";
3665
3666
                else if (StartType == PSNType.Equipment && EndType == PSNType.Branch)
3667
                    result = "E2B";
3668
                else if (StartType == PSNType.Branch && EndType == PSNType.Equipment)
3669
                    result = "B2E";
3670
3671
                else if (StartType == PSNType.Header && EndType == PSNType.Branch)
3672
                    result = "HDB";
3673
                else if (StartType == PSNType.Branch && EndType == PSNType.Header)
3674
                    result = "HDB";
3675
3676
                else if (StartType == PSNType.Header && EndType == PSNType.Equipment)
3677
                    result = "HDE";
3678
                else if (StartType == PSNType.Equipment && EndType == PSNType.Header)
3679
                    result = "HDE";
3680
                else
3681
                    result = "Error";
3682
            }
3683
            else
3684
                result = "Error";
3685
3686
            return result;
3687
3688 7106e181 LJIYEON
3689 94a117ca gaqhf
        }
3690 3610fd3f LJIYEON
3691 710a49f1 gaqhf
        public bool EnableType(PSNType type)
3692 94a117ca gaqhf
        {
3693
            bool result = false;
3694
3695
            if (type == PSNType.Branch ||
3696
                type == PSNType.Equipment ||
3697
                type == PSNType.Header)
3698
            {
3699
                result = true;
3700
            }
3701
3702
            return result;
3703
        }
3704 3610fd3f LJIYEON
3705 7881ec8f gaqhf
        public bool IsBypass { get; set; }
3706 94a117ca gaqhf
3707 a5616391 LJIYEON
        public string GetFromData(ref string Type, ref Item item)
3708 94a117ca gaqhf
        {
3709 51974d2b LJIYEON
            Status = string.Empty;
3710 94a117ca gaqhf
            string result = string.Empty;
3711 a36541fb LJIYEON
            if (IsKeyword)
3712
                IsKeyword = false;
3713 27d06aa8 LJIYEON
            try
3714 36a45f13 gaqhf
            {
3715 08b33e44 gaqhf
                item = Groups.First().Items.First();
3716
3717 27d06aa8 LJIYEON
                if (StartType == PSNType.Header)
3718
                    result = "ENDOFHEADER";
3719
                else if (StartType == PSNType.Branch)
3720
                {
3721 dd27861e 이지연
                    if (item.Relations.First().Item.LineNumber != null && !string.IsNullOrEmpty(item.Relations.First().Item.LineNumber.Name))
3722 85eeb2be 이지연
                    {
3723 27d06aa8 LJIYEON
                        result = item.Relations.First().Item.LineNumber.Name;
3724 7d6d1693 이지연
                        if (item.Relations.First().Item.LineNumber.MissingLineNumber2)
3725 85eeb2be 이지연
                        {
3726
                            Status += ", Missing LineNumber_2";
3727
                            IsValid = "Error";
3728
                        }
3729 7d6d1693 이지연
                        if (item.Relations.First().Item.LineNumber.MissingLineNumber1)
3730 85eeb2be 이지연
                        {
3731
                            Status += ", Missing LineNumber_1";
3732
                            IsValid = "Error";
3733
                        }
3734
                    }
3735 27d06aa8 LJIYEON
                    else
3736
                    {
3737 7106e181 LJIYEON
                        IsValid = "Error";
3738 27d06aa8 LJIYEON
                        result = "Empty LineNumber";
3739
                    }
3740
                }
3741
                else if (StartType == PSNType.Equipment)
3742 a36541fb LJIYEON
                {
3743 3210f690 LJIYEON
                    if (Groups.First().Items.First().Equipment != null)
3744
                        result = Groups.First().Items.First().Equipment.ItemTag;
3745 a36541fb LJIYEON
                    DataRow drNozzle = Nozzle.Select(string.Format("OID = '{0}'", Groups.First().Items.First().UID)).FirstOrDefault();
3746
3747
                    if (drNozzle != null)
3748 7106e181 LJIYEON
                        result += " [" + drNozzle.Field<string>("ITEMTAG") + "]";
3749
                }
3750 36a45f13 gaqhf
                else
3751
                {
3752 2f7c4151 이지연
                    
3753 a5616391 LJIYEON
                    item = Groups.First().Items.First();
3754 27d06aa8 LJIYEON
                    if (item.ItemType == ItemType.Symbol)
3755
                    {
3756 8ab98ea3 LJIYEON
                        string keyword = string.Empty;
3757 a5616391 LJIYEON
                        keyword = GetFromKeywordData(ref Type, item);
3758 8ab98ea3 LJIYEON
3759
                        if (string.IsNullOrEmpty(keyword))
3760
                        {
3761
                            if (item.ID2DBType.Contains("OPC's"))
3762 51974d2b LJIYEON
                                Status += ", OPC Disconnected";
3763 8ab98ea3 LJIYEON
                            else
3764
                                Status += ", Missing ItemTag or Description";
3765
3766
                            result = item.ID2DBName;
3767 2f7c4151 이지연
                            IsValid = "Error";
3768 8ab98ea3 LJIYEON
                        }
3769
                        else
3770 eb44d82c LJIYEON
                        {
3771 8ab98ea3 LJIYEON
                            result = keyword;
3772 a36541fb LJIYEON
                            IsKeyword = true;
3773 eb44d82c LJIYEON
                        }
3774 7106e181 LJIYEON
3775 27d06aa8 LJIYEON
                    }
3776
                    else if (item.ItemType == ItemType.Line)
3777
                    {
3778 85eeb2be 이지연
                        if (item.LineNumber != null && !string.IsNullOrEmpty(item.LineNumber.Name))
3779 48870200 LJIYEON
                        {
3780 85eeb2be 이지연
                            result = item.LineNumber.Name;
3781 7d6d1693 이지연
                            if (item.LineNumber.MissingLineNumber2)
3782 85eeb2be 이지연
                            {
3783
                                Status += ", Missing LineNumber_2";
3784
                                IsValid = "Error";
3785
                            }
3786 7d6d1693 이지연
                            if (item.LineNumber.MissingLineNumber1)
3787 85eeb2be 이지연
                            {
3788
                                Status += ", Missing LineNumber_1";
3789
                                IsValid = "Error";
3790
                            }
3791 48870200 LJIYEON
                        }
3792 f6c9db1a 이지연
                        else
3793 85eeb2be 이지연
                        {
3794
                            IsValid = "Error";
3795
                            result = "Empty LineNumber";
3796
                        }
3797 27d06aa8 LJIYEON
                    }
3798
                    else
3799
                        result = "Unknown";
3800 36a45f13 gaqhf
                }
3801
            }
3802 7106e181 LJIYEON
            catch (Exception ex)
3803 36a45f13 gaqhf
            {
3804
3805
            }
3806 94a117ca gaqhf
3807
            return result;
3808
        }
3809
3810 a5616391 LJIYEON
        public string GetFromKeywordData(ref string Type, Item item)
3811 879ce10b LJIYEON
        {
3812
            string result = string.Empty;
3813 7106e181 LJIYEON
3814
            foreach (KeywordItem keyitem in KeywordInfos.KeywordItems)
3815 879ce10b LJIYEON
            {
3816 7106e181 LJIYEON
                if (keyitem.Name.Equals(item.Name))
3817 a5616391 LJIYEON
                {
3818 eb44d82c LJIYEON
                    result = keyitem.Keyword;
3819 a5616391 LJIYEON
                    Type = item.ID2DBType;
3820 a2973aa3 LJIYEON
                    break;
3821 a5616391 LJIYEON
                }
3822 879ce10b LJIYEON
            }
3823 7106e181 LJIYEON
3824 879ce10b LJIYEON
            return result;
3825
        }
3826
3827 a5616391 LJIYEON
        public string GetToKeywordData(ref string Type, Item item)
3828 879ce10b LJIYEON
        {
3829
            string result = string.Empty;
3830
3831 eb44d82c LJIYEON
            foreach (KeywordItem keyitem in KeywordInfos.KeywordItems)
3832 879ce10b LJIYEON
            {
3833 eb44d82c LJIYEON
                if (keyitem.Name.Equals(item.Name))
3834 a5616391 LJIYEON
                {
3835 eb44d82c LJIYEON
                    result = keyitem.Keyword;
3836 a5616391 LJIYEON
                    Type = item.ID2DBType;
3837 a2973aa3 LJIYEON
                    break;
3838 a5616391 LJIYEON
                }
3839 879ce10b LJIYEON
            }
3840
            return result;
3841
        }
3842
3843 a5616391 LJIYEON
        public string GetToData(ref string ToType, ref Item item)
3844 94a117ca gaqhf
        {
3845
            string result = string.Empty;
3846 51974d2b LJIYEON
            Status = string.Empty;
3847 eb44d82c LJIYEON
3848 a2973aa3 LJIYEON
            if (IsKeyword)
3849
                IsKeyword = false;
3850 3210f690 LJIYEON
3851 08b33e44 gaqhf
            item = Groups.Last().Items.Last();
3852
3853 a2973aa3 LJIYEON
            if (EndType == PSNType.Header)
3854
                result = "ENDOFHEADER";
3855
            else if (EndType == PSNType.Branch)
3856
            {
3857 dd27861e 이지연
                if (item.Relations.Last().Item.LineNumber != null && !string.IsNullOrEmpty(item.Relations.Last().Item.LineNumber.Name))
3858 85eeb2be 이지연
                {
3859 a2973aa3 LJIYEON
                    result = item.Relations.Last().Item.LineNumber.Name;
3860 7d6d1693 이지연
                    if (item.Relations.Last().Item.LineNumber.MissingLineNumber2)
3861 85eeb2be 이지연
                    {
3862
                        Status += ", Missing LineNumber_2";
3863
                        IsValid = "Error";
3864
                    }
3865 7d6d1693 이지연
                    if (item.Relations.Last().Item.LineNumber.MissingLineNumber1)
3866 85eeb2be 이지연
                    {
3867
                        Status += ", Missing LineNumber_1";
3868
                        IsValid = "Error";
3869
                    }
3870
                }
3871 a2973aa3 LJIYEON
                else
3872 36a45f13 gaqhf
                {
3873 85eeb2be 이지연
                    IsValid = "Error";
3874 a2973aa3 LJIYEON
                    result = "Empty LineNumber";
3875 85eeb2be 이지연
                }                
3876 a2973aa3 LJIYEON
            }
3877
            else if (EndType == PSNType.Equipment)
3878
            {
3879 7106e181 LJIYEON
                if (Groups.Last().Items.Last().Equipment != null)
3880 a2973aa3 LJIYEON
                    result = Groups.Last().Items.Last().Equipment.ItemTag;
3881 8ab98ea3 LJIYEON
3882 a2973aa3 LJIYEON
                DataRow drNozzle = Nozzle.Select(string.Format("OID = '{0}'", Groups.Last().Items.Last().UID)).FirstOrDefault();
3883 3210f690 LJIYEON
3884 a2973aa3 LJIYEON
                if (drNozzle != null)
3885
                    result += " [" + drNozzle.Field<string>("ITEMTAG") + "]";
3886
            }
3887
            else
3888
            {
3889 2f7c4151 이지연
                
3890 a2973aa3 LJIYEON
                item = Groups.Last().Items.Last();
3891
                if (item.ItemType == ItemType.Symbol)
3892 3210f690 LJIYEON
                {
3893 a2973aa3 LJIYEON
                    string keyword = string.Empty;
3894
                    keyword = GetToKeywordData(ref ToType, item);
3895 3210f690 LJIYEON
3896 a2973aa3 LJIYEON
                    if (string.IsNullOrEmpty(keyword))
3897
                    {
3898
                        if (item.ID2DBType.Contains("OPC's"))
3899 51974d2b LJIYEON
                            Status += ", OPC Disconnected";
3900 8ab98ea3 LJIYEON
                        else
3901 a2973aa3 LJIYEON
                            Status += ", Missing ItemTag or Description";
3902 8ab98ea3 LJIYEON
3903 a2973aa3 LJIYEON
                        result = item.ID2DBName;
3904 2f7c4151 이지연
                        IsValid = "Error";
3905 8ab98ea3 LJIYEON
                    }
3906 a2973aa3 LJIYEON
                    else
3907 eb44d82c LJIYEON
                    {
3908 a2973aa3 LJIYEON
                        result = keyword;
3909
                        IsKeyword = true;
3910 eb44d82c LJIYEON
                    }
3911 a2973aa3 LJIYEON
3912
                }
3913
                else if (item.ItemType == ItemType.Line)
3914
                {
3915 85eeb2be 이지연
                    if (item.LineNumber != null && !string.IsNullOrEmpty(item.LineNumber.Name))
3916 48870200 LJIYEON
                    {
3917 85eeb2be 이지연
                        result = item.LineNumber.Name;
3918 7d6d1693 이지연
                        if (item.LineNumber.MissingLineNumber2)
3919 85eeb2be 이지연
                        {
3920
                            Status += ", Missing LineNumber_2";
3921
                            IsValid = "Error";
3922
                        }
3923 7d6d1693 이지연
                        if (item.LineNumber.MissingLineNumber1)
3924 85eeb2be 이지연
                        {
3925
                            Status += ", Missing LineNumber_1";
3926
                            IsValid = "Error";
3927
                        }
3928 48870200 LJIYEON
                    }
3929 f6c9db1a 이지연
                    else
3930 85eeb2be 이지연
                    {
3931
                        IsValid = "Error";
3932
                        result = "Empty LineNumber";
3933
                    }
3934 36a45f13 gaqhf
                }
3935 a2973aa3 LJIYEON
                else
3936
                    result = "Unknown";
3937
            }
3938 94a117ca gaqhf
            return result;
3939
        }
3940 7881ec8f gaqhf
3941
        public string GetPBSData()
3942
        {
3943
            string result = string.Empty;
3944
            List<string> PBSList = new List<string>();
3945
            if (Settings.Default.PBSSetting.Equals("Line Number"))
3946
            {
3947
                string attrValue = Settings.Default.PBSSettingValue;
3948
3949
                foreach (Group group in Groups)
3950
                {
3951 7106e181 LJIYEON
                    List<LineNumber> lineNumbers = group.Items.Select(x => x.LineNumber).Distinct().ToList();
3952 7881ec8f gaqhf
                    foreach (LineNumber lineNumber in lineNumbers)
3953
                    {
3954
                        Attribute attribute = lineNumber.Attributes.Find(x => x.Name == attrValue && !string.IsNullOrEmpty(x.Value));
3955
                        if (attribute != null)
3956
                        {
3957
                            string value = attribute.Value;
3958
                            if (!PBSList.Contains(value))
3959
                                PBSList.Add(value);
3960
                        }
3961
                    }
3962
                }
3963
            }
3964
            else if (Settings.Default.PBSSetting.Equals("Item Attribute"))
3965
            {
3966
                string attrValue = Settings.Default.PBSSettingValue;
3967
3968
                foreach (Group group in Groups)
3969
                {
3970
                    List<Item> items = group.Items.FindAll(x => x.Attributes.Find(y => y.Name == attrValue && !string.IsNullOrEmpty(y.Value)) != null);
3971
                    foreach (Item item in items)
3972
                    {
3973
                        string value = item.Attributes.Find(x => x.Name == attrValue).Value;
3974
                        if (!PBSList.Contains(value))
3975
                            PBSList.Add(value);
3976
                    }
3977
                }
3978
            }
3979
            else if (Settings.Default.PBSSetting.Equals("Drawing No"))
3980
            {
3981
                string attrValue = Settings.Default.PBSSettingValue;
3982
3983
                foreach (Group group in Groups)
3984
                {
3985
                    List<Document> documents = group.Items.Select(x => x.Document).Distinct().ToList();
3986
                    foreach (Document document in documents)
3987
                    {
3988
                        string name = document.DrawingName;
3989
3990
                        int startIndex = Settings.Default.PBSSettingStartValue;
3991
                        int endIndex = Settings.Default.PBSSettingEndValue;
3992
3993
                        string subStr = name.Substring(startIndex - 1, endIndex - startIndex + 1);
3994
                        if (!PBSList.Contains(subStr))
3995
                            PBSList.Add(subStr);
3996
                    }
3997
                }
3998
            }
3999
            else if (Settings.Default.PBSSetting.Equals("Unit Area"))
4000
            {
4001
                foreach (Group group in Groups)
4002
                {
4003
                    List<Document> documents = group.Items.Select(x => x.Document).Distinct().ToList();
4004
                    foreach (Document document in documents)
4005
                    {
4006
                        List<TextInfo> textInfos = document.TextInfos.FindAll(x => x.Area == "Unit");
4007
                        foreach (TextInfo textInfo in textInfos)
4008
                        {
4009
                            if (!PBSList.Contains(textInfo.Value))
4010
                                PBSList.Add(textInfo.Value);
4011
                        }
4012
                    }
4013
                }
4014
            }
4015
4016
            foreach (var item in PBSList)
4017
            {
4018
                if (string.IsNullOrEmpty(result))
4019
                    result = item;
4020
                else
4021
                    result += ", " + item;
4022
            }
4023
            return result;
4024
        }
4025 6b9e7a56 gaqhf
    }
4026
}
클립보드 이미지 추가 (최대 크기: 500 MB)