프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / ID2PSN / PSN.cs @ 4f02de16

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