프로젝트

일반

사용자정보

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

hytos / DTI_PID / ID2PSN / PSN.cs @ bd86dd48

이력 | 보기 | 이력해설 | 다운로드 (205 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
                                        if (item.ItemType != ID2PSN.ItemType.Line && item.ID2DBName.ToUpper().Equals("TIEINPOINT"))
2557
                                        {
2558
                                            
2559
                                            newRow["ITEMNAME"] = "PipingComp";
2560
                                            if (!string.IsNullOrEmpty(TieInPointAttributeName))
2561
                                                newRow["ITEMTAG"] = string.Format("TIEINPOINT_{0:D3}V", tieInPointSymbolIndex);
2562
                                            else
2563
                                                newRow["ITEMTAG"] = item.Attributes.Find(x => x.Name == TieInPointAttributeName).Value;
2564
                                                    
2565
                                            newRow["Class"] = "In-Line Fitting";
2566
                                            newRow["SubClass"] = "";
2567
                                            newRow["TYPE"] = "End";
2568
                                            tieInPointSymbolIndex++;
2569
                                        }
2570
                                        else
2571
                                        {
2572
                                            newRow["ITEMNAME"] = GetItemName(item, itemOID);
2573
                                            newRow["ITEMTAG"] = GetItemTag(item);
2574
                                            newRow["Class"] = GetClass(item, itemOID);
2575
                                            string subClass = GetSubClass(item, itemOID);
2576
                                            newRow["SubClass"] = subClass;
2577
2578
                                            if (item.ItemType == ItemType.Symbol)
2579
                                                newRow["TYPE"] = item.ID2DBName;
2580
                                            else if (item.ItemType == ItemType.Line)
2581
                                                newRow["TYPE"] = item.ID2DBType;
2582
                                        }
2583
                                       
2584
                                        
2585
                                       
2586 a5616391 LJIYEON
                                        newRow["PIDNAME"] = group.Document.DrawingName;
2587
2588
                                        // NPD
2589
                                        if (item.LineNumber != null)
2590
                                        {
2591
                                            Attribute attribute = item.LineNumber.Attributes.Find(x => x.Name == "NominalDiameter");
2592
                                            if (attribute != null)
2593
                                                newRow["NPD"] = attribute.Value;
2594
                                        }
2595
                                        else
2596
                                            newRow["NPD"] = null;
2597 7881ec8f gaqhf
2598 811d7949 LJIYEON
                                        newRow["GROUPTAG"] = GROUPTAG;
2599 a5616391 LJIYEON
                                        newRow["PipeSystemNetwork_OID"] = PSNItem.PSN_OID();
2600
                                        if (branchItem == null)
2601
                                            newRow["ViewPipeSystemNetwork_OID"] = PSNItem.PSN_OID();
2602
                                        else
2603
                                            newRow["ViewPipeSystemNetwork_OID"] = branchItem.PSNItem.PSN_OID();
2604 27d06aa8 LJIYEON
2605 a5616391 LJIYEON
                                        newRow["PipeRun_OID"] = item.LineNumber != null ? item.LineNumber.Name : string.Empty;
2606 0eefef3d 이지연
                                        newRow["EGTConnectedPoint"] = 0;
2607 a5616391 LJIYEON
                                        pathItemsDT.Rows.Add(newRow);
2608 7106e181 LJIYEON
                                    }
2609 0eefef3d 이지연
2610
2611 a5616391 LJIYEON
                                    void CreateSequenceDataDataRow(string itemOID)
2612
                                    {
2613
                                        DataRow newRow = sequenceDataDT.NewRow();
2614
                                        newRow["OID"] = string.Format(item.Topology.FullName + "_{0}", index);
2615
                                        newRow["SERIALNUMBER"] = string.Format("{0}", index);
2616
                                        newRow["PathItem_OID"] = itemOID;
2617
                                        newRow["TopologySet_OID_Key"] = item.Topology.FullName;
2618 839708c6 LJIYEON
2619 a5616391 LJIYEON
                                        sequenceDataDT.Rows.Add(newRow);
2620
                                    }
2621 0eefef3d 이지연
2622 a5616391 LJIYEON
                                    void CreatePipeSystemNetworkDataRow()
2623 7106e181 LJIYEON
                                    {
2624 a5616391 LJIYEON
                                        LineNumber lineNumber = item.Document.LineNumbers.Find(x => x.UID == item.Owner);
2625 08b33e44 gaqhf
                                        string FluidCode = string.Empty;
2626 4842b66a 이지연
                                        string GroundLevel = string.Empty;
2627 a5616391 LJIYEON
                                        if (lineNumber != null)
2628 3210f690 LJIYEON
                                        {
2629 a5616391 LJIYEON
                                            List<Attribute> att = lineNumber.Attributes;
2630
                                            if (att != null)
2631 3210f690 LJIYEON
                                            {
2632 a5616391 LJIYEON
                                                List<string> oid = new List<string>();
2633 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;
2634 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;
2635
                                                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;
2636
                                                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;
2637
                                                //InsulationPurpose
2638
                                                if (!string.IsNullOrEmpty(FluidCode)) oid.Add(FluidCode);
2639
                                                if (!string.IsNullOrEmpty(PMC)) oid.Add(PMC);
2640
2641
                                                string PipeSystem_OID = string.Join("-", oid);
2642
2643
                                                if (!string.IsNullOrEmpty(SEQNUMBER)) oid.Add(SEQNUMBER);
2644
                                                if (!string.IsNullOrEmpty(INSULATION)) oid.Add(INSULATION);
2645
2646
                                                string OID = string.Join("-", oid);
2647 531fb158 LJIYEON
                                                string FluidCodeGL = string.Empty;
2648
                                                string PMCGL = string.Empty;
2649 7106e181 LJIYEON
2650 a5616391 LJIYEON
                                                if (pipelineDT.Select(string.Format("OID = '{0}'", OID)).Count() == 0)
2651
                                                {
2652
                                                    DataRow newPipelineRow = pipelineDT.NewRow();
2653
                                                    newPipelineRow["OID"] = OID;
2654
                                                    newPipelineRow["PipeSystem_OID"] = PipeSystem_OID;
2655
                                                    newPipelineRow["FLUID"] = FluidCode;
2656
                                                    newPipelineRow["PMC"] = PMC;
2657
                                                    newPipelineRow["SEQNUMBER"] = SEQNUMBER;
2658
                                                    newPipelineRow["INSULATION"] = INSULATION;
2659
                                                    newPipelineRow["FROM_DATA"] = string.Empty;
2660
                                                    newPipelineRow["TO_DATA"] = string.Empty;
2661
                                                    newPipelineRow["Unit"] = PSNItem.GetPBSData();
2662 7106e181 LJIYEON
                                                    pipelineDT.Rows.Add(newPipelineRow);
2663 531fb158 LJIYEON
                                                }
2664
2665
                                                if (pipesystemDT.Select(string.Format("OID = '{0}'", PipeSystem_OID)).Count() == 0)
2666
                                                {
2667 54b6df95 LJIYEON
                                                    DataRow newPipesystemRow = pipesystemDT.NewRow();
2668
                                                    newPipesystemRow["OID"] = PipeSystem_OID;
2669
                                                    newPipesystemRow["DESCRIPTION"] = string.Empty;
2670
                                                    newPipesystemRow["FLUID"] = FluidCode;
2671
                                                    newPipesystemRow["PMC"] = PMC;
2672
                                                    newPipesystemRow["PipeLineQty"] = string.Empty;
2673 4842b66a 이지연
                                                    
2674 54b6df95 LJIYEON
                                                    if (!string.IsNullOrEmpty(FluidCode) && !string.IsNullOrEmpty(PMC))
2675
                                                    {
2676
                                                        FluidCodeGL = PSNFluidDT.Select(string.Format("Code = '{0}'", FluidCode)).FirstOrDefault().Field<string>("GroundLevel");
2677
                                                        PMCGL = PSNPMCDT.Select(string.Format("Code= '{0}'", PMC)).FirstOrDefault().Field<string>("GroundLevel");
2678
                                                        if (FluidCodeGL == "AG" && PMCGL == "AG")
2679
                                                            GroundLevel = "AG";
2680
                                                        else if (FluidCodeGL == "UG" && PMCGL == "UG")
2681
                                                            GroundLevel = "UG";
2682
                                                        else
2683
                                                            GroundLevel = "AG_UG";
2684
                                                    }
2685
                                                    newPipesystemRow["GroundLevel"] = GroundLevel;
2686
                                                    pipesystemDT.Rows.Add(newPipesystemRow);
2687 3210f690 LJIYEON
                                                }
2688 4842b66a 이지연
                                                else
2689
                                                {
2690
                                                    GroundLevel = pipesystemDT.Select(string.Format("OID = '{0}'", PipeSystem_OID)).First().Field<string>("GroundLevel");
2691
                                                }
2692 3210f690 LJIYEON
                                            }
2693 a5616391 LJIYEON
                                        }
2694 3210f690 LJIYEON
2695 a5616391 LJIYEON
                                        DataRow newRow = pipeSystemNetworkDT.NewRow();
2696
                                        newRow["OID"] = PSNItem.PSN_OID();
2697 7106e181 LJIYEON
2698 a5616391 LJIYEON
                                        newRow["OrderNumber"] = psnOrder;
2699
                                        newRow["Pipeline_OID"] = item.PSNPipeLineID;
2700
                                        PSNItem.KeywordInfos = KeywordInfos;
2701
                                        PSNItem.Nozzle = Nozzle;
2702 7106e181 LJIYEON
2703 a5616391 LJIYEON
                                        string FromType = string.Empty;
2704
                                        Item From_item = new Item();
2705 7106e181 LJIYEON
2706 23204ef6 이지연
                                        string oStatus = string.Empty;
2707
                                        string FROM_DATA = PSNItem.GetFromData(ref FromType, ref From_item, item, ref oStatus);
2708 51974d2b LJIYEON
                                        string status = string.Empty;
2709 23204ef6 이지연
                                        if (psnOrder == 0)
2710
                                            status = PSNItem.Status;
2711 51974d2b LJIYEON
2712 a5616391 LJIYEON
                                        if (PSNItem.IsKeyword)
2713
                                        {
2714 e552da48 LJIYEON
                                            PSNItem.StartType = PSNType.Equipment;
2715 a5616391 LJIYEON
                                        }
2716
                                        string ToType = string.Empty;
2717
                                        Item To_item = new Item();
2718 23204ef6 이지연
                                        string TO_DATA = PSNItem.GetToData(ref ToType, ref To_item, item);
2719 a5616391 LJIYEON
                                        if (PSNItem.IsKeyword)
2720
                                        {
2721 e552da48 LJIYEON
                                            PSNItem.EndType = PSNType.Equipment;
2722 a5616391 LJIYEON
                                        }
2723 7d6d1693 이지연
                                                   
2724 e552da48 LJIYEON
                                        newRow["FROM_DATA"] = FROM_DATA;
2725 7106e181 LJIYEON
                                        newRow["TO_DATA"] = TO_DATA;
2726 7d6d1693 이지연
                                       
2727 a5616391 LJIYEON
                                        newRow["Type"] = PSNItem.GetPSNType();
2728 e552da48 LJIYEON
2729 23204ef6 이지연
                                        if (psnOrder == 0) //order 0일땐 그냥 붙여줌
2730 7d6d1693 이지연
                                        {
2731 a653883a 이지연
                                           status += oStatus + PSNItem.Status;                                                                                      
2732 7d6d1693 이지연
                                        }
2733
                                        else if (psnOrder > 0) //0보다 크면 
2734 e552da48 LJIYEON
                                        {
2735 7106e181 LJIYEON
                                            DataRow dr = pipeSystemNetworkDT.Select(string.Format("OID = '{0}' AND OrderNumber = {1}", PSNItem.PSN_OID(), psnOrder - 1)).FirstOrDefault();
2736 23204ef6 이지연
                                            
2737
                                            if (psnOrder >= 1) 
2738 e552da48 LJIYEON
                                            {
2739 a653883a 이지연
                                                if (!string.IsNullOrEmpty(PSNItem.Status))
2740 23204ef6 이지연
                                                {
2741 a653883a 이지연
                                                    if (dr["Status"].ToString().Contains(PSNItem.Status))
2742
                                                    {
2743
                                                        dr["Status"] = dr["Status"].ToString().Replace(PSNItem.Status, string.Empty);
2744
                                                    }
2745
                                                    else
2746
                                                    {
2747
                                                        dr["Status"] = dr["Status"].ToString().Replace(PSNItem.Status.Remove(0, 2), string.Empty);
2748
                                                    }    
2749 23204ef6 이지연
                                                }
2750
                                            }                                                                                    
2751
                                            
2752
                                            status = oStatus + PSNItem.Status;
2753 6805be6e 이지연
                                            if (dr != null)
2754
                                            {
2755
                                                newRow["FROM_DATA"] = dr.Field<string>("FROM_DATA");
2756
                                                newRow["TO_DATA"] = dr.Field<string>("TO_DATA");
2757
                                                newRow["Type"] = dr.Field<string>("Type");
2758
                                            }
2759 23204ef6 이지연
                                        }                                        
2760 7d6d1693 이지연
                                    
2761 48870200 LJIYEON
                                        status = !string.IsNullOrEmpty(status) ? status.Remove(0, 2) : string.Empty;
2762 7d6d1693 이지연
                                        string[] st = status.Split(new string[] { ", " }, StringSplitOptions.None);
2763
                                        if (st.Count() > 1)
2764 48870200 LJIYEON
                                        {
2765 7d6d1693 이지연
                                            status = string.Join(", ", st.Distinct());                                                                                     
2766 48870200 LJIYEON
                                        }
2767
                                        newRow["Status"] = status;
2768 23204ef6 이지연
                                        newRow["IsValid"] = PSNItem.IsValid;
2769
2770
                                        newRow["TopologySet_OID_Key"] = item.Topology.FullName;
2771
                                        newRow["PSNRevisionNumber"] = string.Format("V{0:D4}", Revision);                                                                           
2772 a5616391 LJIYEON
                                        newRow["PBS"] = PSNItem.GetPBSData();
2773 7106e181 LJIYEON
2774 a5616391 LJIYEON
                                        List<string> drawingNames = new List<string>();
2775
                                        foreach (Group _group in PSNItem.Groups)
2776
                                        {
2777
                                            if (!drawingNames.Contains(_group.Document.DrawingName))
2778 3210f690 LJIYEON
                                            {
2779 a5616391 LJIYEON
                                                if (drawingNames.Count == 0)
2780
                                                    newRow["Drawings"] = _group.Document.DrawingName;
2781
                                                else
2782
                                                    newRow["Drawings"] = newRow["Drawings"] + ", " + _group.Document.DrawingName;
2783
                                                drawingNames.Add(_group.Document.DrawingName);
2784 3210f690 LJIYEON
                                            }
2785 27d06aa8 LJIYEON
                                        }
2786 419055fa LJIYEON
2787
                                        // VentDrain의 경우 제외 요청 (데이터를 아예 제거하였을 경우 후 가공에서 문제가 생김 마지막에 지우는것으로 변경)
2788
                                        if (bVentDrain)
2789
                                            newRow["IncludingVirtualData"] = "Vent_Drain";
2790
                                        else
2791
                                            newRow["IncludingVirtualData"] = "No";
2792 23204ef6 이지연
                                       
2793 a5616391 LJIYEON
                                        newRow["PSNAccuracy"] = "100";
2794 08b33e44 gaqhf
2795
                                        string Pocket = "No";
2796
                                        string Condition = PSNFluidDT.Select(string.Format("Code = '{0}'", FluidCode)).FirstOrDefault().Field<string>("Condition");
2797
                                        if (Condition.Equals("Flare"))
2798
                                            Pocket = "Yes";
2799
2800 485040d4 esham21
                                        if (item.ID2DBType == "Nozzles" && PSNItem.StartType == PSNType.Equipment && From_item.Equipment != null) 
2801 08b33e44 gaqhf
                                        {
2802 23204ef6 이지연
                                            Equipment Equipment = From_item.Equipment;                                      
2803 91c75c0b 이지연
                                            EquipmentNoPocketItem nopocket = EquipmentNoPocket.EquipmentNoPocketItem.Where(x => x.Name == Equipment.Name && x.Type != "Pump").FirstOrDefault();
2804
                                          
2805
                                            if (nopocket != null)
2806 08b33e44 gaqhf
                                            {
2807 91c75c0b 이지연
                                                DataRow bNozzle = null;
2808
                                                if (nopocket.Type.Equals("Vertical Vessel"))
2809
                                                {
2810
                                                    DataRow drNozzle = Nozzle.Select(string.Format("Equipment_OID = '{0}' AND OID = '{1}'", Equipment.UID, From_item.UID)).FirstOrDefault();
2811
                                                    if (drNozzle != null)
2812
                                                    {
2813
                                                        if (drNozzle.Field<string>("Rotation").Length >= 4 && drNozzle.Field<string>("Rotation").Substring(0, 4) == "4.71")
2814
                                                        {
2815
                                                            bNozzle = drNozzle;
2816
                                                        }
2817
2818
                                                        if (bNozzle == null)
2819
                                                        {
2820
                                                            DataRow[] nozzleRows = Nozzle.Select(string.Format("Equipment_OID = '{0}'", Equipment.UID));
2821
2822
                                                            if (drNozzle != null)
2823
                                                            {
2824
                                                                bNozzle = drNozzle;
2825
                                                                foreach (DataRow it in nozzleRows)
2826
                                                                {
2827
                                                                    if (Convert.ToDecimal(drNozzle.Field<string>("Ycoords")) > Convert.ToDecimal(it.Field<string>("Ycoords")))
2828
                                                                    {
2829
                                                                        bNozzle = null;
2830
                                                                        break;
2831
                                                                    }
2832
                                                                }
2833
                                                            }
2834
                                                        }
2835
                                                    }
2836
2837
                                                    if (bNozzle != null)
2838
                                                        Pocket = "Yes";
2839
                                                }
2840
                                                else
2841
                                                    Pocket = "Yes";
2842 08b33e44 gaqhf
                                            }
2843
                                        }
2844 91c75c0b 이지연
                                        
2845 485040d4 esham21
                                        if (item.ID2DBType == "Nozzles" && PSNItem.EndType == PSNType.Equipment && To_item.Equipment != null) //To는 전체
2846 08b33e44 gaqhf
                                        {
2847
                                            Equipment Equipment = To_item.Equipment;
2848
                                            EquipmentNoPocketItem nopocket = EquipmentNoPocket.EquipmentNoPocketItem.Where(x => x.Name == Equipment.Name).FirstOrDefault();
2849
                                            if (nopocket != null)
2850
                                            {
2851 91c75c0b 이지연
                                                DataRow bNozzle = null;
2852
                                                if (nopocket.Type.Equals("Vertical Vessel"))
2853
                                                {
2854
                                                    DataRow drNozzle = Nozzle.Select(string.Format("Equipment_OID = '{0}' AND OID = '{1}'", Equipment.UID, To_item.UID)).FirstOrDefault();
2855
                                                    if(drNozzle != null)
2856
                                                    {
2857
                                                        if (drNozzle.Field<string>("Rotation").Length >= 4 && drNozzle.Field<string>("Rotation").Substring(0, 4) == "4.71")
2858
                                                        {
2859
                                                            bNozzle = drNozzle;
2860
                                                        }
2861
2862
                                                        if (bNozzle == null)
2863
                                                        {
2864
                                                            DataRow[] nozzleRows = Nozzle.Select(string.Format("Equipment_OID = '{0}'", Equipment.UID));
2865
2866
                                                            if (drNozzle != null)
2867
                                                            {
2868
                                                                bNozzle = drNozzle;
2869
                                                                foreach (DataRow it in nozzleRows)
2870
                                                                {
2871
                                                                    if (Convert.ToDecimal(drNozzle.Field<string>("Ycoords")) > Convert.ToDecimal(it.Field<string>("Ycoords")))
2872
                                                                    {
2873
                                                                        bNozzle = null;
2874
                                                                        break;
2875
                                                                    }
2876
                                                                }
2877
                                                            }
2878
                                                        }
2879
                                                    }                                                   
2880
2881
                                                    if (bNozzle != null)
2882
                                                        Pocket = "Yes";
2883
                                                }
2884
                                                else
2885
                                                    Pocket = "Yes";
2886 08b33e44 gaqhf
                                            }
2887
                                        }
2888 91c75c0b 이지연
                                        
2889 08b33e44 gaqhf
                                        newRow["Pocket"] = Pocket;
2890 0eefef3d 이지연
                                        string AFC = "P2";
2891 23204ef6 이지연
                                        if (PSNItem.StartType == PSNType.Equipment && From_item.Equipment != null)
2892 0eefef3d 이지연
                                        {
2893 d1afd412 이지연
                                            if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type != "Pump" && x.Name.Equals(From_item.Equipment.Name)).Count() > 0)
2894 284fa2c9 이지연
                                                AFC = "P1\\" + From_item.Equipment.Name;
2895 d1afd412 이지연
                                            else if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && x.Name.Equals(From_item.Equipment.Name)).Count() > 0)
2896
                                                newRow["PUMP"] = "PUMP";
2897 0eefef3d 이지연
                                        }
2898
2899
                                        if (PSNItem.EndType == PSNType.Equipment && To_item.Equipment != null)
2900
                                        {
2901 d1afd412 이지연
                                            if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type != "Pump" && x.Name.Equals(To_item.Equipment.Name)).Count() > 0)
2902 284fa2c9 이지연
                                                AFC = "P1\\" + To_item.Equipment.Name;
2903 d1afd412 이지연
                                            else if (EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Where(x => x.Type == "Pump" && x.Name.Equals(To_item.Equipment.Name)).Count() > 0)
2904
                                                newRow["PUMP"] = "PUMP";
2905 0eefef3d 이지연
                                        }
2906
2907
                                        newRow["AFC"] = AFC;
2908 d1afd412 이지연
2909
                                        newRow["EGTag"] = string.Empty;
2910
                                        newRow["HasMLTags"] = "False";
2911 4842b66a 이지연
                                        newRow["GroundLevel"] = GroundLevel;
2912 a5616391 LJIYEON
                                        pipeSystemNetworkDT.Rows.Add(newRow);
2913 2c46461b LJIYEON
                                    }
2914 27d06aa8 LJIYEON
                                }
2915 23204ef6 이지연
                            }                      
2916 a5616391 LJIYEON
                        }
2917
                        catch (Exception ex)
2918
                        {
2919
                            Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2920
                            MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
2921
                        }
2922 3210f690 LJIYEON
2923 a5616391 LJIYEON
                        //TopologySet 관련
2924
                        foreach (Topology topology in PSNItem.Topologies)
2925
                        {
2926
                            DataRow newRow = topologySetDT.NewRow();
2927
                            newRow["OID"] = topology.FullName;
2928
                            newRow["Type"] = topology.FullName.Split(new char[] { '-' }).Last().StartsWith("M") ? "Main" : "Branch";
2929
                            if (bVentDrain)
2930
                                newRow["SubType"] = "Vent_Drain";
2931
                            else
2932
                                newRow["SubType"] = null;
2933
                            newRow["HeadItemTag"] = GetItemTag(topology.Items.Last());
2934
                            newRow["TailItemTag"] = GetItemTag(topology.Items.First());
2935
                            newRow["HeadItemSPID"] = topology.Items.Last().UID;
2936
                            newRow["TailItemSPID"] = topology.Items.First().UID;
2937
                            topologySetDT.Rows.Add(newRow);
2938 94a117ca gaqhf
                        }
2939 7106e181 LJIYEON
2940 6b9e7a56 gaqhf
                    }
2941 7106e181 LJIYEON
                    catch (Exception ee)
2942 27d06aa8 LJIYEON
                    {
2943 879ce10b LJIYEON
2944 2c46461b LJIYEON
                    }
2945 6b9e7a56 gaqhf
                }
2946
2947 3210f690 LJIYEON
2948 2c46461b LJIYEON
                foreach (var item in startBranchDic)
2949 5c248ee3 gaqhf
                {
2950 2c46461b LJIYEON
                    string uid = item.Key.UID;
2951
                    string topologyName = item.Value.Topology.FullName;
2952
                    DataRow[] rows = pathItemsDT.Select(string.Format("OID LIKE '{0}%'", uid));
2953 7106e181 LJIYEON
2954 2c46461b LJIYEON
                    if (rows.Length == 1)
2955 9c151350 gaqhf
                    {
2956 2c46461b LJIYEON
                        rows.First()["BranchTopologySet_OID"] = topologyName;
2957 9c151350 gaqhf
                        rows.First()["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID();
2958
                    }
2959 2c46461b LJIYEON
                    else if (rows.Length > 1)
2960 5c248ee3 gaqhf
                    {
2961 2c46461b LJIYEON
                        DataRow targetRow = null;
2962
                        int index = int.MaxValue;
2963
                        foreach (DataRow row in rows)
2964 5c248ee3 gaqhf
                        {
2965 2c46461b LJIYEON
                            string split = row["OID"].ToString().Split(new char[] { '_' })[1];
2966
                            if (split.StartsWith("L"))
2967 5c248ee3 gaqhf
                            {
2968 2c46461b LJIYEON
                                int num = Convert.ToInt32(split.Remove(0, 1));
2969
                                if (index > num)
2970
                                {
2971
                                    index = num;
2972
                                    targetRow = row;
2973
                                }
2974 5c248ee3 gaqhf
                            }
2975
                        }
2976
2977 2c46461b LJIYEON
                        if (targetRow != null)
2978 9c151350 gaqhf
                        {
2979 2c46461b LJIYEON
                            targetRow["BranchTopologySet_OID"] = topologyName;
2980 9c151350 gaqhf
                            targetRow["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID();
2981
                        }
2982 2c46461b LJIYEON
                    }
2983 5c248ee3 gaqhf
                }
2984 f9f2787b LJIYEON
2985 2c46461b LJIYEON
                foreach (var item in endBranchDic)
2986 5c248ee3 gaqhf
                {
2987 2c46461b LJIYEON
                    string uid = item.Key.UID;
2988
                    string topologyName = item.Value.Topology.FullName;
2989
                    DataRow[] rows = pathItemsDT.Select(string.Format("OID LIKE '{0}%'", uid));
2990
                    if (rows.Length == 1)
2991 9c151350 gaqhf
                    {
2992 2c46461b LJIYEON
                        rows.First()["BranchTopologySet_OID"] = topologyName;
2993 9c151350 gaqhf
                        rows.First()["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID();
2994
                    }
2995 2c46461b LJIYEON
                    else if (rows.Length > 1)
2996 5c248ee3 gaqhf
                    {
2997 2c46461b LJIYEON
                        DataRow targetRow = null;
2998
                        int index = int.MinValue;
2999
                        foreach (DataRow row in rows)
3000 5c248ee3 gaqhf
                        {
3001 2c46461b LJIYEON
                            string split = row["OID"].ToString().Split(new char[] { '_' })[1];
3002
                            if (split.StartsWith("L"))
3003 5c248ee3 gaqhf
                            {
3004 2c46461b LJIYEON
                                int num = Convert.ToInt32(split.Remove(0, 1));
3005
                                if (index < num)
3006
                                {
3007
                                    index = num;
3008
                                    targetRow = row;
3009
                                }
3010 5c248ee3 gaqhf
                            }
3011
                        }
3012
3013 2c46461b LJIYEON
                        if (targetRow != null)
3014 9c151350 gaqhf
                        {
3015 2c46461b LJIYEON
                            targetRow["BranchTopologySet_OID"] = topologyName;
3016 9c151350 gaqhf
                            targetRow["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID();
3017
                        }
3018 2c46461b LJIYEON
                    }
3019 5c248ee3 gaqhf
                }
3020
3021 2c46461b LJIYEON
                PathItems = pathItemsDT;
3022
                SequenceData = sequenceDataDT;
3023
                PipeSystemNetwork = pipeSystemNetworkDT;
3024
                TopologySet = topologySetDT;
3025 f9f2787b LJIYEON
                PipeLine = pipelineDT;
3026 531fb158 LJIYEON
                PipeSystem = pipesystemDT;
3027 2c46461b LJIYEON
            }
3028
            catch (Exception ex)
3029
            {
3030
                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
3031
                MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
3032
            }
3033 36a45f13 gaqhf
        }
3034 2ada3be8 LJIYEON
3035 5e4c2ad1 LJIYEON
        private double AccuracyCalculation(List<double> lstAcc, double acc)
3036 2ada3be8 LJIYEON
        {
3037 7106e181 LJIYEON
            foreach (double lacc in lstAcc)
3038 2ada3be8 LJIYEON
            {
3039
                acc *= lacc;
3040
            }
3041
            return acc;
3042
        }
3043
3044 7881ec8f gaqhf
        private void UpdateSubType()
3045 36a45f13 gaqhf
        {
3046 27d06aa8 LJIYEON
            try
3047 36a45f13 gaqhf
            {
3048 27d06aa8 LJIYEON
                foreach (PSNItem PSNItem in PSNItems)
3049 36a45f13 gaqhf
                {
3050 27d06aa8 LJIYEON
                    if (PSNItem.IsBypass)
3051 36a45f13 gaqhf
                    {
3052 27d06aa8 LJIYEON
                        foreach (Topology topology in PSNItem.Topologies)
3053
                        {
3054
                            DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName));
3055
                            if (rows.Length.Equals(1))
3056
                                rows.First()["SubType"] = "Bypass";
3057
                        }
3058
                    }
3059
3060
                    if (PSNItem.StartType == PSNType.Header)
3061
                    {
3062
                        Topology topology = PSNItem.Topologies.First();
3063
                        DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName));
3064
                        if (rows.Length.Equals(1))
3065
                            rows.First()["SubType"] = "Header";
3066
                    }
3067
                    else if (PSNItem.EndType == PSNType.Header)
3068
                    {
3069
                        Topology topology = PSNItem.Topologies.Last();
3070 7881ec8f gaqhf
                        DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName));
3071
                        if (rows.Length.Equals(1))
3072 27d06aa8 LJIYEON
                            rows.First()["SubType"] = "Header";
3073 36a45f13 gaqhf
                    }
3074
                }
3075 7881ec8f gaqhf
3076 36a45f13 gaqhf
3077 27d06aa8 LJIYEON
                foreach (Topology topology in Topologies)
3078 7881ec8f gaqhf
                {
3079 27d06aa8 LJIYEON
                    try
3080
                    {
3081
                        DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName));
3082 7106e181 LJIYEON
3083
                        if (rows.Count() > 0)
3084 27d06aa8 LJIYEON
                        {
3085 3210f690 LJIYEON
                            if (rows.Length.Equals(1) && rows.First()["SubType"] == null || string.IsNullOrEmpty(rows.First()["SubType"].ToString()))
3086
                            {
3087
                                if (topology.Items == null)
3088
                                    continue;
3089 27d06aa8 LJIYEON
3090 3210f690 LJIYEON
                                Item firstItem = topology.Items.First();
3091
                                Item lastItem = topology.Items.Last();
3092 27d06aa8 LJIYEON
3093 3210f690 LJIYEON
                                List<Relation> relations = new List<Relation>();
3094 7881ec8f gaqhf
3095 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 )
3096
                                    relations.AddRange(firstItem.Relations.FindAll(x => x.Item != null && x.Item.Topology != null && x.Item.Topology.ID != topology.ID));
3097 7881ec8f gaqhf
3098 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)
3099
                                    relations.AddRange(lastItem.Relations.FindAll(x => x.Item != null && x.Item.Topology != null && x.Item.Topology.ID != topology.ID));
3100 3210f690 LJIYEON
3101
                                if (relations.Count > 0)
3102
                                    rows.First()["SubType"] = "OtherSystem";
3103
                            }
3104 27d06aa8 LJIYEON
                        }
3105
                    }
3106
                    catch (Exception ex)
3107
                    {
3108 7106e181 LJIYEON
3109 27d06aa8 LJIYEON
                        MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
3110
                    }
3111 7881ec8f gaqhf
                }
3112
3113 7106e181 LJIYEON
                foreach (DataRow row in TopologySet.Rows)
3114 27d06aa8 LJIYEON
                    if (row["SubType"] == null || string.IsNullOrEmpty(row["SubType"].ToString()))
3115
                        row["SubType"] = "Normal";
3116
            }
3117
            catch (Exception ex)
3118
            {
3119
                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
3120
                MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
3121
            }
3122 7881ec8f gaqhf
        }
3123 5e4c2ad1 LJIYEON
3124 7881ec8f gaqhf
        private bool IsBypass(PSNItem PSNItem)
3125
        {
3126
            bool bResult = false;
3127
3128
            if (PSNItem.GetPSNType() == "B2B")
3129
            {
3130
                Group firstGroup = PSNItem.Groups.First();
3131
                Group lastGroup = PSNItem.Groups.Last();
3132
                Item firstItem = firstGroup.Items.First();
3133
                Item lastItem = lastGroup.Items.Last();
3134
3135
                Item connectedFirstItem = GetConnectedItemByPSN(firstItem);
3136
                Item connectedLastItem = GetConnectedItemByPSN(lastItem);
3137 36a45f13 gaqhf
3138 7881ec8f gaqhf
                if (connectedFirstItem.LineNumber != null && connectedLastItem.LineNumber != null &&
3139
                    !string.IsNullOrEmpty(connectedFirstItem.LineNumber.Name) && !string.IsNullOrEmpty(connectedLastItem.LineNumber.Name) &&
3140
                    connectedFirstItem.LineNumber.Name == connectedLastItem.LineNumber.Name)
3141
                    bResult = true;
3142
                else if (connectedFirstItem.PSNItem == connectedLastItem.PSNItem)
3143
                    bResult = true;
3144
            }
3145 36a45f13 gaqhf
3146
            Item GetConnectedItemByPSN(Item item)
3147
            {
3148
                Item result = null;
3149
3150
                Relation relation = item.Relations.Find(x => x.Item != null && x.Item.PSNItem != item.PSNItem);
3151
                if (relation != null)
3152
                    result = relation.Item;
3153
3154 3210f690 LJIYEON
3155 36a45f13 gaqhf
                return result;
3156
            }
3157 7881ec8f gaqhf
3158
            return bResult;
3159
        }
3160 5e4c2ad1 LJIYEON
3161 419055fa LJIYEON
        private void DeleteVentDrain()
3162
        {
3163
            DataRow[] ventdrainRows = PipeSystemNetwork.Select(" IncludingVirtualData = 'Vent_Drain'");
3164 7106e181 LJIYEON
3165 419055fa LJIYEON
            foreach (DataRow dataRow in ventdrainRows)
3166
            {
3167 7106e181 LJIYEON
                dataRow.Delete();
3168
            }
3169 419055fa LJIYEON
        }
3170
3171 5e4c2ad1 LJIYEON
        private void UpdateAccuracy()
3172
        {
3173 54b6df95 LJIYEON
            //DataRow[] statusRows = PipeSystemNetwork.Select(" Type = 'Error' OR IsValid = 'Error'"); 
3174
            DataRow[] statusRows = PipeSystemNetwork.Select(" Type = 'Error' OR IsValid = 'Error'");
3175 5e4c2ad1 LJIYEON
            List<double> lstAcc = null;
3176
            string Status = string.Empty;
3177 f9f2787b LJIYEON
3178 5e4c2ad1 LJIYEON
            foreach (DataRow dataRow in statusRows)
3179
            {
3180
                lstAcc = new List<double>();
3181
                Status = dataRow.Field<string>("Status");
3182
                if (!string.IsNullOrEmpty(Status))
3183
                {
3184 51974d2b LJIYEON
                    string[] arrStatus = Status.Split(',');
3185 7106e181 LJIYEON
                    foreach (string arrstr in arrStatus)
3186 51974d2b LJIYEON
                    {
3187
                        if (arrstr.Contains(Rule1)) //Missing LineNumber_1
3188
                            lstAcc.Add(0.75);
3189 f9f2787b LJIYEON
3190 51974d2b LJIYEON
                        if (arrstr.Contains(Rule2)) //Missing LineNumber_2
3191
                            lstAcc.Add(0.7);
3192 f9f2787b LJIYEON
3193 51974d2b LJIYEON
                        if (arrstr.Contains(Rule3)) // OPC Disconnected
3194
                            lstAcc.Add(0.5);
3195 f9f2787b LJIYEON
3196 51974d2b LJIYEON
                        if (arrstr.Contains(Rule4)) //Missing ItemTag or Description
3197
                            lstAcc.Add(0.65);
3198
3199
                        if (arrstr.Contains(Rule5)) //Line Disconnected
3200
                            lstAcc.Add(0.6);
3201
                    }
3202 5e4c2ad1 LJIYEON
                }
3203
3204
                string PSNAccuracy = dataRow["PSNAccuracy"].ToString();
3205
                if (PSNAccuracy == "100")
3206
                    PSNAccuracy = "1";
3207
3208 51974d2b LJIYEON
                PSNAccuracy = Convert.ToString(Convert.ToDecimal(AccuracyCalculation(lstAcc, Convert.ToDouble(PSNAccuracy))));
3209
                //if (PSNAccuracy != "100")
3210
                //{
3211
                //    //dataRow["IncludingVirtualData"] = "No";
3212 7106e181 LJIYEON
                dataRow["PSNAccuracy"] = PSNAccuracy;
3213 51974d2b LJIYEON
                //}
3214 5e4c2ad1 LJIYEON
            }
3215 bfe278bb LJIYEON
            DataTable dt = PipeSystemNetwork.DefaultView.ToTable(true, new string[] { "OID" });
3216
            foreach (DataRow dr in dt.Rows)
3217
            {
3218
                string oid = dr.Field<string>("OID");
3219
                DataRow[] select = PipeSystemNetwork.Select(string.Format("OID = '{0}'", oid));
3220
                double totalDdr = 0;
3221
                foreach (DataRow ddr in select)
3222
                {
3223
                    double acc = Convert.ToDouble(ddr.Field<string>("PSNAccuracy"));
3224
                    if (acc == 100) acc = 1;
3225
                    if (totalDdr == 0) totalDdr = acc;
3226
                    else totalDdr *= acc;
3227
                }
3228
3229
                totalDdr *= 100;
3230
3231 7106e181 LJIYEON
                if (totalDdr != 100)
3232 bfe278bb LJIYEON
                {
3233 f9f2787b LJIYEON
                    foreach (DataRow ddr in select)
3234
                    {
3235
                        ddr["IncludingVirtualData"] = "Yes";
3236 51974d2b LJIYEON
                        ddr["PSNAccuracy"] = String.Format("{0:0.00}", Math.Round(totalDdr, 2));
3237 7d6d1693 이지연
                        ddr["IsValid"] = "Error";
3238 51974d2b LJIYEON
                    }
3239
                }
3240
                else
3241
                {
3242
                    foreach (DataRow ddr in select)
3243
                    {
3244
                        ddr["IncludingVirtualData"] = "No";
3245
                        ddr["PSNAccuracy"] = String.Format("{0:0.00}", Math.Round(totalDdr, 2));
3246 f9f2787b LJIYEON
                    }
3247 bfe278bb LJIYEON
                }
3248
            }
3249
3250 5e4c2ad1 LJIYEON
        }
3251
3252 a5616391 LJIYEON
        private void UpdateKeywordForPSN()
3253
        {
3254
            #region Keyword Info
3255
            KeywordInfo KeywordInfos = new KeywordInfo();
3256
            DataTable dtKeyword = DB.SelectKeywordsSetting();
3257
            foreach (DataRow row in dtKeyword.Rows)
3258
            {
3259
                int index = Convert.ToInt32(row["INDEX"]);
3260
                string name = row["NAME"].ToString();
3261
                string keyword = row["KEYWORD"].ToString();
3262
3263
                //KeywordInfo keywordInfo = new KeywordInfo();   
3264
                KeywordInfos.KeywordItems.Add(new KeywordItem()
3265
                {
3266
                    Index = index,
3267
                    Name = name,
3268
                    Keyword = keyword
3269
                });
3270
            }
3271
            #endregion
3272
3273 a2973aa3 LJIYEON
            DataRow[] endofHeaderRows = PipeSystemNetwork.Select(string.Format(" From_Data = '{0}' OR To_Data = '{0}'", "ENDOFHEADER"));
3274
            foreach (DataRow dataRow in endofHeaderRows)
3275
            {
3276
                PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString());
3277
3278
                if (dataRow.Field<string>("From_Data") == "ENDOFHEADER")
3279
                {
3280
                    DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
3281
                    DataRow dr = pathItemRows.First();
3282
                    dr["CLASS"] = PSNItem.Groups.First().Items.First().ID2DBName;
3283
                    dr["TYPE"] = "End";
3284
                    dr["ITEMTAG"] = "ENDOFHEADER";
3285
                    dr["DESCRIPTION"] = "ENDOFHEADER";
3286
                }
3287
3288
                if (dataRow.Field<string>("To_Data") == "ENDOFHEADER")
3289
                {
3290
                    DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
3291
                    DataRow dr = pathItemRows.Last();
3292
                    dr["CLASS"] = PSNItem.Groups.Last().Items.Last().ID2DBName;
3293
                    dr["TYPE"] = "End";
3294
                    dr["ITEMTAG"] = "ENDOFHEADER";
3295
                    dr["DESCRIPTION"] = "ENDOFHEADER";
3296
                }
3297
            }
3298
3299 a5616391 LJIYEON
            foreach (KeywordItem keyitem in KeywordInfos.KeywordItems)
3300
            {
3301 a2973aa3 LJIYEON
                DataRow[] keywordRows = PipeSystemNetwork.Select(string.Format(" From_Data = '{0}' OR To_Data = '{0}'", keyitem.Keyword));
3302 a5616391 LJIYEON
                foreach (DataRow dataRow in keywordRows)
3303 7106e181 LJIYEON
                {
3304
                    PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString());
3305 a5616391 LJIYEON
3306 7106e181 LJIYEON
                    if (dataRow.Field<string>("From_Data") == keyitem.Keyword)
3307
                    {
3308 a5616391 LJIYEON
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
3309 7106e181 LJIYEON
3310 a2973aa3 LJIYEON
                        //
3311
                        //if(.)
3312 7106e181 LJIYEON
                        if (PSNItem.Groups.First().Items.First().Name.Equals(keyitem.Name))
3313 a5616391 LJIYEON
                        {
3314
                            DataRow dr = pathItemRows.First();
3315
                            //dr["CLASS"] = ""; //Type
3316
                            dr["TYPE"] = "End";
3317
                            dr["ITEMTAG"] = keyitem.Keyword;
3318
                            dr["DESCRIPTION"] = keyitem.Keyword;
3319
                        }
3320 7106e181 LJIYEON
3321 a5616391 LJIYEON
                    }
3322
3323 a2973aa3 LJIYEON
                    if (dataRow.Field<string>("To_Data") == keyitem.Keyword)
3324 a5616391 LJIYEON
                    {
3325
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
3326
3327 a2973aa3 LJIYEON
                        if (PSNItem.Groups.Last().Items.Last().Name.Equals(keyitem.Name))
3328 a5616391 LJIYEON
                        {
3329
                            DataRow dr = pathItemRows.Last();
3330
                            //dr["CLASS"] = ""; //Type
3331
                            dr["TYPE"] = "End";
3332
                            dr["ITEMTAG"] = keyitem.Keyword;
3333
                            dr["DESCRIPTION"] = keyitem.Keyword;
3334
                            //dr.Field<string>("Type")
3335
                        }
3336
3337 7106e181 LJIYEON
                    }
3338 a5616391 LJIYEON
                }
3339 7106e181 LJIYEON
            }
3340 a5616391 LJIYEON
        }
3341
3342 7881ec8f gaqhf
        private void UpdateErrorForPSN()
3343
        {
3344 45529c16 LJIYEON
            DataRow[] errorRows = PipeSystemNetwork.Select(string.Format(" Type = '{0}'", ErrorType.Error));
3345 7881ec8f gaqhf
            foreach (DataRow dataRow in errorRows)
3346
            {
3347 eb44d82c LJIYEON
                try
3348 710a49f1 gaqhf
                {
3349 eb44d82c LJIYEON
                    PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString());
3350 dd27861e 이지연
                   
3351 eb44d82c LJIYEON
                    bool change = false;
3352 aa195a5b LJIYEON
                    bool bCheck = false;
3353 eb44d82c LJIYEON
                    if (!PSNItem.EnableType(PSNItem.StartType))
3354 710a49f1 gaqhf
                    {
3355 bd86dd48 이지연
                        //if(!PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"])).First().Field<string>("ItemTag").Contains("TIEINPOINT"))
3356
                        //{
3357
                            change = true;
3358
                            DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
3359
                            int insertIndex = PathItems.Rows.IndexOf(pathItemRows.First());
3360 7106e181 LJIYEON
3361 bd86dd48 이지연
                            Item item = PSNItem.Groups.First().Items.First();
3362
                            try
3363 eb44d82c LJIYEON
                            {
3364 bd86dd48 이지연
                                string FROM_DATA = string.Format("TIEINPOINT_{0:D5}V", tieInPointIndex);
3365
3366
                                foreach (DataRow loopRow in PipeSystemNetwork.Select(string.Format("OID = '{0}'", PSNItem.PSN_OID())))
3367 48870200 LJIYEON
                                {
3368 bd86dd48 이지연
                                    loopRow["FROM_DATA"] = FROM_DATA;
3369
                                    if (item.ItemType == ItemType.Line)
3370 48870200 LJIYEON
                                    {
3371 bd86dd48 이지연
                                        if (loopRow.Field<string>("OrderNumber") == "0")
3372
                                        {
3373
                                            string status = loopRow.Field<string>("Status");
3374
                                            //string isvali
3375
                                            if (string.IsNullOrEmpty(status))
3376
                                                status = "Line Disconnected";
3377
                                            else if (!status.Contains("Line Disconnected"))
3378
                                                status += ", Line Disconnected";
3379
                                            loopRow["Status"] = status;
3380
                                            if (!string.IsNullOrEmpty(status))
3381
                                                loopRow["IsValid"] = "Error";
3382
                                        }
3383 48870200 LJIYEON
                                    }
3384
                                }
3385 dd27861e 이지연
3386 bd86dd48 이지연
                                tieInPointIndex++;
3387 dd27861e 이지연
3388 bd86dd48 이지연
                                if (item.ItemType == ItemType.Line)
3389
                                {
3390
                                    PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.First(), FROM_DATA), insertIndex);
3391
                                }
3392
                                else
3393
                                {
3394
                                    PathItems.Rows.InsertAt(createLineRow(PathItems.Select(string.Format("PipeLine_OID = '{0}' AND PipeSystemNetwork_OID = '{1}'", item.PSNPipeLineID, dataRow["OID"])).First()), insertIndex);
3395
                                    PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.First(), FROM_DATA), insertIndex);
3396
3397
                                    bCheck = true;
3398
                                }
3399
3400
                                PSNItem.StartType = PSNType.Equipment;
3401 dd27861e 이지연
                            }
3402 bd86dd48 이지연
                            catch (Exception ex)
3403 eb44d82c LJIYEON
                            {
3404 bd86dd48 이지연
                                MessageBox.Show("Please check the item.\r\nDrawingName : " + item.Document.DrawingName + "\r\nUID : " + item.UID, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
3405
                                return;
3406 eb44d82c LJIYEON
                            }
3407 bd86dd48 이지연
                        //}                       
3408 eb44d82c LJIYEON
                    }
3409 710a49f1 gaqhf
3410 eb44d82c LJIYEON
                    if (!PSNItem.EnableType(PSNItem.EndType))
3411 bd86dd48 이지연
                    {
3412
                        //if (!PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"])).Last().Field<string>("ItemTag").Contains("TIEINPOINT"))
3413
                        //{
3414
                            DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
3415
                            //int insertIndex = PathItems.Rows.IndexOf(pathItemRows.First()) + pathItemRows.Count() - 1;
3416
                            DataRow dr = pathItemRows.Last();
3417
                            if (change)
3418 dd27861e 이지연
                            {
3419 bd86dd48 이지연
                                if (bCheck)
3420
                                    dr = pathItemRows[pathItemRows.Count() - 3];
3421
                                else
3422
                                {
3423
                                    dr = pathItemRows[pathItemRows.Count() - 2];
3424
                                }
3425 dd27861e 이지연
                            }
3426 f6c9db1a 이지연
3427 bd86dd48 이지연
                            change = true;
3428
                            int insertIndex = PathItems.Rows.IndexOf(dr) + 1;
3429 a36541fb LJIYEON
3430 bd86dd48 이지연
                            Item item = PSNItem.Groups.Last().Items.Last();
3431
                            try
3432 51974d2b LJIYEON
                            {
3433 bd86dd48 이지연
                                string TO_DATA = string.Format("TIEINPOINT_{0:D5}V", tieInPointIndex);
3434
3435
3436
                                foreach (DataRow loopRow in PipeSystemNetwork.Select(string.Format("OID = '{0}'", PSNItem.PSN_OID())))
3437 51974d2b LJIYEON
                                {
3438 bd86dd48 이지연
                                    loopRow["TO_DATA"] = TO_DATA;
3439
                                    if (item.ItemType == ItemType.Line)
3440 48870200 LJIYEON
                                    {
3441 bd86dd48 이지연
                                        if (loopRow.Field<string>("OrderNumber") == Convert.ToString(PipeSystemNetwork.Select(string.Format("OID = '{0}'", PSNItem.PSN_OID())).Count() - 1))
3442
                                        {
3443
                                            string status = loopRow.Field<string>("Status");
3444
                                            if (string.IsNullOrEmpty(status))
3445
                                                status = "Line Disconnected";
3446
                                            else if (!status.Contains("Line Disconnected"))
3447
                                                status += ", Line Disconnected";
3448
                                            loopRow["Status"] = status;
3449
                                            if (!string.IsNullOrEmpty(status))
3450
                                                loopRow["IsValid"] = "Error";
3451
                                        }
3452 48870200 LJIYEON
                                    }
3453 bd86dd48 이지연
3454 51974d2b LJIYEON
                                }
3455 7d6d1693 이지연
3456 bd86dd48 이지연
                                tieInPointIndex++;
3457 48870200 LJIYEON
3458 bd86dd48 이지연
                                if (item.ItemType == ItemType.Line)
3459
                                {
3460
                                    PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.Last(), TO_DATA), insertIndex);
3461
                                }
3462
                                else
3463
                                {
3464
                                    PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.Last(), TO_DATA), insertIndex);
3465
                                    PathItems.Rows.InsertAt(createLineRow(PathItems.Select(string.Format("PipeLine_OID = '{0}' AND PipeSystemNetwork_OID = '{1}'", item.PSNPipeLineID, dataRow["OID"])).Last()), insertIndex);
3466 7106e181 LJIYEON
3467 bd86dd48 이지연
                                }
3468
3469
                                PSNItem.EndType = PSNType.Equipment;
3470 eb44d82c LJIYEON
                            }
3471 bd86dd48 이지연
                            catch (Exception ex)
3472 eb44d82c LJIYEON
                            {
3473 bd86dd48 이지연
                                MessageBox.Show("Please check the item.\r\nDrawingName : " + item.Document.DrawingName + "\r\nUID : " + item.UID, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
3474
                                return;
3475 eb44d82c LJIYEON
                            }
3476 bd86dd48 이지연
                        //}      
3477 710a49f1 gaqhf
                    }
3478 eb44d82c LJIYEON
3479
                    dataRow["Type"] = PSNItem.GetPSNType();
3480
                    if (change)
3481 710a49f1 gaqhf
                    {
3482 eb44d82c LJIYEON
                        int rowIndex = 0;
3483
                        for (int i = 0; i < PathItems.Rows.Count; i++)
3484
                        {
3485
                            DataRow row = PathItems.Rows[i];
3486
                            if (row["PipeSystemNetwork_OID"].ToString() != dataRow["OID"].ToString())
3487
                                continue;
3488
                            string sequenceData = row["SequenceData_OID"].ToString();
3489
                            string[] split = sequenceData.Split(new char[] { '_' });
3490
3491
                            StringBuilder sb = new StringBuilder();
3492
                            for (int j = 0; j < split.Length - 1; j++)
3493
                                sb.Append(split[j] + "_");
3494
                            sb.Append(rowIndex++);
3495
                            row["SequenceData_OID"] = sb.ToString();
3496 a36541fb LJIYEON
3497 3210f690 LJIYEON
                            DataRow seqItemRows = SequenceData.Select(string.Format("PathItem_OID = '{0}'", row["OID"])).FirstOrDefault();
3498
                            int insertSeqIndex = SequenceData.Rows.IndexOf(seqItemRows);
3499
3500
                            string[] splitseq = sb.ToString().Split(new char[] { '_' });
3501
3502
                            if (seqItemRows == null)
3503
                            {
3504 7106e181 LJIYEON
                                DataRow newRow = SequenceData.NewRow();
3505 3210f690 LJIYEON
                                newRow["OID"] = sb.ToString();
3506
                                newRow["SERIALNUMBER"] = splitseq[splitseq.Length - 1];
3507
                                newRow["PathItem_OID"] = row["OID"];
3508
                                newRow["TopologySet_OID_Key"] = row["TopologySet_OID"];
3509
                                SequenceData.Rows.InsertAt(newRow, Convert.ToInt32(splitseq[splitseq.Length - 1]));
3510
                            }
3511
                            else
3512
                            {
3513
                                seqItemRows["OID"] = sb.ToString();
3514
                                seqItemRows["SERIALNUMBER"] = splitseq[splitseq.Length - 1];
3515
                                seqItemRows["PathItem_OID"] = row["OID"];
3516
                                seqItemRows["TopologySet_OID_Key"] = row["TopologySet_OID"];
3517 7106e181 LJIYEON
                            }
3518
                        }
3519 eb44d82c LJIYEON
                    }
3520 5e4c2ad1 LJIYEON
3521 a36541fb LJIYEON
                    DataRow createTerminatorRow(DataRow itemRow, string DATA)
3522 eb44d82c LJIYEON
                    {
3523
                        DataRow newRow = PathItems.NewRow();
3524
                        newRow["OID"] = Guid.NewGuid().ToString();
3525
                        newRow["SequenceData_OID"] = itemRow["SequenceData_OID"];
3526
                        newRow["TopologySet_OID"] = itemRow["TopologySet_OID"];
3527
                        newRow["BranchTopologySet_OID"] = itemRow["BranchTopologySet_OID"];
3528 7106e181 LJIYEON
                        newRow["PipeLine_OID"] = itemRow["PipeLine_OID"];
3529 a36541fb LJIYEON
                        newRow["ITEMNAME"] = "PipingComp"; //newRow["ITEMNAME"] = "End of line terminator";
3530
                        newRow["ITEMTAG"] = DATA; //itemRow["ITEMTAG"];
3531 7106e181 LJIYEON
                        newRow["DESCRIPTION"] = DATA;
3532 eb44d82c LJIYEON
                        newRow["Class"] = "End of line terminator";
3533
                        newRow["SubClass"] = "End of line terminator";
3534 a36541fb LJIYEON
                        newRow["TYPE"] = "End";
3535 eb44d82c LJIYEON
                        newRow["PIDNAME"] = itemRow["PIDNAME"];
3536
                        newRow["NPD"] = itemRow["NPD"];
3537
                        newRow["PipeSystemNetwork_OID"] = itemRow["PipeSystemNetwork_OID"];
3538
                        newRow["ViewPipeSystemNetwork_OID"] = itemRow["ViewPipeSystemNetwork_OID"];
3539 7106e181 LJIYEON
                        newRow["PipeRun_OID"] = itemRow["PipeRun_OID"];
3540 0d4b3dee 이지연
                        newRow["EGTConnectedPoint"] = "0";
3541 a36541fb LJIYEON
                        return newRow;
3542
                    }
3543
3544 eb44d82c LJIYEON
                    DataRow createLineRow(DataRow itemRow)
3545 710a49f1 gaqhf
                    {
3546 eb44d82c LJIYEON
                        DataRow newRow = PathItems.NewRow();
3547
                        newRow["OID"] = Guid.NewGuid().ToString();
3548
                        newRow["SequenceData_OID"] = itemRow["SequenceData_OID"];
3549
                        newRow["TopologySet_OID"] = itemRow["TopologySet_OID"];
3550 bd86dd48 이지연
                        newRow["BranchTopologySet_OID"] = "";
3551 eb44d82c LJIYEON
                        newRow["PipeLine_OID"] = itemRow["PipeLine_OID"];
3552 bd86dd48 이지연
                        newRow["ITEMNAME"] = "PipeRun";
3553
                        newRow["ITEMTAG"] = itemRow["PipeRun_OID"];
3554
                        newRow["Class"] = "Piping";
3555
                        newRow["SubClass"] = "";
3556
                        newRow["TYPE"] = "Secondary";
3557 eb44d82c LJIYEON
                        newRow["PIDNAME"] = itemRow["PIDNAME"];
3558
                        newRow["NPD"] = itemRow["NPD"];
3559
                        newRow["PipeSystemNetwork_OID"] = itemRow["PipeSystemNetwork_OID"];
3560
                        newRow["ViewPipeSystemNetwork_OID"] = itemRow["ViewPipeSystemNetwork_OID"];
3561
                        newRow["PipeRun_OID"] = itemRow["PipeRun_OID"];
3562 0d4b3dee 이지연
                        newRow["EGTConnectedPoint"] = "0";
3563 eb44d82c LJIYEON
                        return newRow;
3564 710a49f1 gaqhf
                    }
3565
                }
3566 7106e181 LJIYEON
                catch (Exception ex)
3567 5e4c2ad1 LJIYEON
                {
3568 710a49f1 gaqhf
3569
                }
3570 eb44d82c LJIYEON
            }
3571 6b9e7a56 gaqhf
        }
3572 4e2e0aa1 LJIYEON
3573
        private void InsertTeePSN()
3574
        {
3575 3f5cb4dc LJIYEON
            DataTable dt = PipeSystemNetwork.DefaultView.ToTable(true, new string[] { "OID", "Type" });
3576
            DataRow[] branchRows = dt.Select("Type Like '%B%'");
3577 820e283f LJIYEON
            bool change = false;
3578 4e2e0aa1 LJIYEON
            foreach (DataRow dataRow in branchRows)
3579
            {
3580
                try
3581 7106e181 LJIYEON
                {
3582 4e2e0aa1 LJIYEON
                    PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString());
3583 820e283f LJIYEON
                    change = false;
3584
3585 4e2e0aa1 LJIYEON
                    if (PSNItem.StartType == PSNType.Branch)
3586
                    {
3587 820e283f LJIYEON
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", PSNItem.PSN_OID()));
3588 4e2e0aa1 LJIYEON
                        int insertIndex = PathItems.Rows.IndexOf(pathItemRows.First());
3589 820e283f LJIYEON
                        Item Teeitem = PSNItem.Groups.First().Items.First();
3590 4e2e0aa1 LJIYEON
                        try
3591 820e283f LJIYEON
                        {
3592
                            if (Teeitem.ItemType == ItemType.Line)
3593 4e2e0aa1 LJIYEON
                            {
3594
                                if (pathItemRows.First().Field<string>("SubClass") != "Tee")
3595 7106e181 LJIYEON
                                {
3596 4e2e0aa1 LJIYEON
                                    PathItems.Rows.InsertAt(createTeeRow(pathItemRows.First()), insertIndex);
3597 0e9d868c LJIYEON
                                    pathItemRows.First().SetField("BranchTopologySet_OID", string.Empty);
3598
                                    pathItemRows.First().SetField("ViewPipeSystemNetwork_OID", dataRow["OID"].ToString());
3599 820e283f LJIYEON
                                    change = true;
3600 4e2e0aa1 LJIYEON
                                }
3601
3602 820e283f LJIYEON
                            }
3603 4e2e0aa1 LJIYEON
                        }
3604
                        catch (Exception ex)
3605
                        {
3606 820e283f LJIYEON
                            MessageBox.Show("Please check the item.\r\nDrawingName : " + Teeitem.Document.DrawingName + "\r\nUID : " + Teeitem.UID, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
3607 4e2e0aa1 LJIYEON
                            return;
3608
                        }
3609
                    }
3610
3611
                    if (PSNItem.EndType == PSNType.Branch)
3612
                    {
3613 820e283f LJIYEON
                        //change = true;
3614
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", PSNItem.PSN_OID()));
3615 7106e181 LJIYEON
3616 820e283f LJIYEON
                        Item Teeitem = PSNItem.Groups.Last().Items.Last();
3617 4e2e0aa1 LJIYEON
3618 820e283f LJIYEON
                        DataRow dr = pathItemRows.Last();
3619
                        if (change)
3620
                            dr = pathItemRows[pathItemRows.Count() - 2];
3621 e36ca22f LJIYEON
3622 b683578e LJIYEON
                        int insertIndex = PathItems.Rows.IndexOf(dr) + 1;
3623 e36ca22f LJIYEON
3624 4e2e0aa1 LJIYEON
                        try
3625
                        {
3626 820e283f LJIYEON
                            if (Teeitem.ItemType == ItemType.Line)
3627 4e2e0aa1 LJIYEON
                            {
3628 820e283f LJIYEON
                                if (dr.Field<string>("SubClass") != "Tee")
3629
                                {
3630
                                    PathItems.Rows.InsertAt(createTeeRow(dr), insertIndex);
3631
                                    change = true;
3632 0e9d868c LJIYEON
                                    dr.SetField("BranchTopologySet_OID", string.Empty);
3633
                                    dr.SetField("ViewPipeSystemNetwork_OID", dataRow["OID"].ToString());
3634 820e283f LJIYEON
                                }
3635
3636 4e2e0aa1 LJIYEON
                            }
3637
                        }
3638
                        catch (Exception ex)
3639
                        {
3640 820e283f LJIYEON
                            MessageBox.Show("Please check the item.\r\nDrawingName : " + Teeitem.Document.DrawingName + "\r\nUID : " + Teeitem.UID, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
3641 4e2e0aa1 LJIYEON
                            return;
3642
                        }
3643
                    }
3644
3645
                    if (change)
3646
                    {
3647 820e283f LJIYEON
                        //DataRow[] pathItemRows = pathItemsDT.Select(string.Format("PipeSystemNetwork_OID = '{0}'", PSNItem.PSN_OID()));
3648 4e2e0aa1 LJIYEON
                        int rowIndex = 0;
3649
                        for (int i = 0; i < PathItems.Rows.Count; i++)
3650
                        {
3651
                            DataRow row = PathItems.Rows[i];
3652 820e283f LJIYEON
                            if (row["PipeSystemNetwork_OID"].ToString() != PSNItem.PSN_OID())
3653 4e2e0aa1 LJIYEON
                                continue;
3654
                            string sequenceData = row["SequenceData_OID"].ToString();
3655
                            string[] split = sequenceData.Split(new char[] { '_' });
3656
3657
                            StringBuilder sb = new StringBuilder();
3658
                            for (int j = 0; j < split.Length - 1; j++)
3659
                                sb.Append(split[j] + "_");
3660
                            sb.Append(rowIndex++);
3661
                            row["SequenceData_OID"] = sb.ToString();
3662
3663
                            DataRow seqItemRows = SequenceData.Select(string.Format("PathItem_OID = '{0}'", row["OID"])).FirstOrDefault();
3664
                            int insertSeqIndex = SequenceData.Rows.IndexOf(seqItemRows);
3665
3666
                            string[] splitseq = sb.ToString().Split(new char[] { '_' });
3667
3668
                            if (seqItemRows == null)
3669
                            {
3670
                                DataRow newRow = SequenceData.NewRow();
3671
                                newRow["OID"] = sb.ToString();
3672
                                newRow["SERIALNUMBER"] = splitseq[splitseq.Length - 1];
3673
                                newRow["PathItem_OID"] = row["OID"];
3674
                                newRow["TopologySet_OID_Key"] = row["TopologySet_OID"];
3675
                                SequenceData.Rows.InsertAt(newRow, Convert.ToInt32(splitseq[splitseq.Length - 1]));
3676
                            }
3677
                            else
3678
                            {
3679
                                seqItemRows["OID"] = sb.ToString();
3680
                                seqItemRows["SERIALNUMBER"] = splitseq[splitseq.Length - 1];
3681
                                seqItemRows["PathItem_OID"] = row["OID"];
3682
                                seqItemRows["TopologySet_OID_Key"] = row["TopologySet_OID"];
3683
                            }
3684
                        }
3685 820e283f LJIYEON
                    }
3686 7106e181 LJIYEON
3687 4e2e0aa1 LJIYEON
                    DataRow createTeeRow(DataRow itemRow)
3688
                    {
3689
                        DataRow newRow = PathItems.NewRow();
3690
                        newRow["OID"] = Guid.NewGuid().ToString();
3691
                        newRow["SequenceData_OID"] = itemRow["SequenceData_OID"];
3692
                        newRow["TopologySet_OID"] = itemRow["TopologySet_OID"];
3693
                        newRow["BranchTopologySet_OID"] = itemRow["BranchTopologySet_OID"];
3694
                        newRow["PipeLine_OID"] = itemRow["PipeLine_OID"];
3695
                        newRow["ITEMNAME"] = "Branch"; //newRow["ITEMNAME"] = "End of line terminator";
3696
                        newRow["ITEMTAG"] = itemRow["ITEMTAG"];
3697
                        newRow["DESCRIPTION"] = "";
3698
                        newRow["Class"] = "Branch";
3699
                        newRow["SubClass"] = "Tee";
3700
                        newRow["TYPE"] = itemRow["TYPE"];
3701
                        newRow["PIDNAME"] = itemRow["PIDNAME"];
3702
                        newRow["NPD"] = itemRow["NPD"];
3703
                        newRow["PipeSystemNetwork_OID"] = itemRow["PipeSystemNetwork_OID"];
3704
                        newRow["ViewPipeSystemNetwork_OID"] = itemRow["ViewPipeSystemNetwork_OID"];
3705
                        newRow["PipeRun_OID"] = itemRow["PipeRun_OID"];
3706 0eefef3d 이지연
                      
3707
                        newRow["EGTConnectedPoint"] = 0;
3708 4e2e0aa1 LJIYEON
                        return newRow;
3709
                    }
3710
                }
3711
                catch (Exception ex)
3712
                {
3713
3714
                }
3715
            }
3716
        }
3717 6b9e7a56 gaqhf
    }
3718
3719
    public class PSNItem
3720
    {
3721 8f24b438 gaqhf
        public PSNItem(int count, int Revision)
3722 6b9e7a56 gaqhf
        {
3723
            Groups = new List<Group>();
3724
            Topologies = new List<Topology>();
3725 94a117ca gaqhf
3726
            Index = count + 1;
3727 8f24b438 gaqhf
            this.Revision = Revision;
3728 6b9e7a56 gaqhf
        }
3729 eb44d82c LJIYEON
3730 8f24b438 gaqhf
        private int Revision;
3731 6b9e7a56 gaqhf
        public string UID { get; set; }
3732
        public List<Group> Groups { get; set; }
3733
        public List<Topology> Topologies { get; set; }
3734
        public PSNType StartType { get; set; }
3735
        public PSNType EndType { get; set; }
3736 94a117ca gaqhf
        public int Index { get; set; }
3737 72775f2e LJIYEON
        public string IsValid { get; set; }
3738 a36541fb LJIYEON
        public bool IsKeyword { get; set; }
3739 36a45f13 gaqhf
        public string Status { get; set; }
3740 ddc1c369 LJIYEON
        public string IncludingVirtualData { get; set; }
3741
        public string PSNAccuracy { get; set; }
3742 eb44d82c LJIYEON
        public KeywordInfo KeywordInfos = new KeywordInfo();
3743 a36541fb LJIYEON
        public DataTable Nozzle = new DataTable();
3744 ddc1c369 LJIYEON
3745 94a117ca gaqhf
        public string PSN_OID()
3746
        {
3747 36a45f13 gaqhf
            return string.Format("V{0}-PSN-{1}", string.Format("{0:D4}", Revision), string.Format("{0:D5}", Index));
3748 94a117ca gaqhf
        }
3749 3610fd3f LJIYEON
3750 94a117ca gaqhf
        public string GetPSNType()
3751
        {
3752
            string result = string.Empty;
3753
3754
            if (EnableType(StartType) && EnableType(EndType))
3755
            {
3756
                if (StartType == PSNType.Equipment && EndType == PSNType.Equipment)
3757
                    result = "E2E";
3758
                else if (StartType == PSNType.Branch && EndType == PSNType.Branch)
3759
                    result = "B2B";
3760
                else if (StartType == PSNType.Header && EndType == PSNType.Header)
3761
                    result = "HD2";
3762
3763
                else if (StartType == PSNType.Equipment && EndType == PSNType.Branch)
3764
                    result = "E2B";
3765
                else if (StartType == PSNType.Branch && EndType == PSNType.Equipment)
3766
                    result = "B2E";
3767
3768
                else if (StartType == PSNType.Header && EndType == PSNType.Branch)
3769
                    result = "HDB";
3770
                else if (StartType == PSNType.Branch && EndType == PSNType.Header)
3771
                    result = "HDB";
3772
3773
                else if (StartType == PSNType.Header && EndType == PSNType.Equipment)
3774
                    result = "HDE";
3775
                else if (StartType == PSNType.Equipment && EndType == PSNType.Header)
3776
                    result = "HDE";
3777
                else
3778
                    result = "Error";
3779
            }
3780
            else
3781
                result = "Error";
3782
3783
            return result;
3784
3785 7106e181 LJIYEON
3786 94a117ca gaqhf
        }
3787 3610fd3f LJIYEON
3788 710a49f1 gaqhf
        public bool EnableType(PSNType type)
3789 94a117ca gaqhf
        {
3790
            bool result = false;
3791
3792
            if (type == PSNType.Branch ||
3793
                type == PSNType.Equipment ||
3794
                type == PSNType.Header)
3795
            {
3796
                result = true;
3797
            }
3798
3799
            return result;
3800
        }
3801 3610fd3f LJIYEON
3802 7881ec8f gaqhf
        public bool IsBypass { get; set; }
3803 94a117ca gaqhf
3804 23204ef6 이지연
        public string GetFromData(ref string Type, ref Item item, Item oItem, ref string OStatus)
3805 94a117ca gaqhf
        {
3806 51974d2b LJIYEON
            Status = string.Empty;
3807 94a117ca gaqhf
            string result = string.Empty;
3808 a36541fb LJIYEON
            if (IsKeyword)
3809
                IsKeyword = false;
3810 27d06aa8 LJIYEON
            try
3811 36a45f13 gaqhf
            {
3812 08b33e44 gaqhf
                item = Groups.First().Items.First();
3813
3814 27d06aa8 LJIYEON
                if (StartType == PSNType.Header)
3815
                    result = "ENDOFHEADER";
3816
                else if (StartType == PSNType.Branch)
3817
                {
3818 dd27861e 이지연
                    if (item.Relations.First().Item.LineNumber != null && !string.IsNullOrEmpty(item.Relations.First().Item.LineNumber.Name))
3819 27d06aa8 LJIYEON
                        result = item.Relations.First().Item.LineNumber.Name;
3820
                    else
3821
                    {
3822 7106e181 LJIYEON
                        IsValid = "Error";
3823 27d06aa8 LJIYEON
                        result = "Empty LineNumber";
3824
                    }
3825 23204ef6 이지연
3826
                        
3827
3828
                    //if (item.Relations.First().Item.LineNumber != null && !string.IsNullOrEmpty(item.Relations.First().Item.LineNumber.Name))
3829
                    //{
3830
                    //    result = item.Relations.First().Item.LineNumber.Name;
3831
                    //    if (item.Relations.First().Item.LineNumber.MissingLineNumber2)
3832
                    //    {
3833
                    //        Status += ", Missing LineNumber_2";
3834
                    //        IsValid = "Error";
3835
                    //    }
3836
                    //    if (item.Relations.First().Item.LineNumber.MissingLineNumber1)
3837
                    //    {
3838
                    //        Status += ", Missing LineNumber_1";
3839
                    //        IsValid = "Error";
3840
                    //    }
3841
                    //}
3842
                    //else
3843
                    //{
3844
                    //    IsValid = "Error";
3845
                    //    result = "Empty LineNumber";
3846
                    //}
3847 27d06aa8 LJIYEON
                }
3848
                else if (StartType == PSNType.Equipment)
3849 a36541fb LJIYEON
                {
3850 3210f690 LJIYEON
                    if (Groups.First().Items.First().Equipment != null)
3851
                        result = Groups.First().Items.First().Equipment.ItemTag;
3852 a36541fb LJIYEON
                    DataRow drNozzle = Nozzle.Select(string.Format("OID = '{0}'", Groups.First().Items.First().UID)).FirstOrDefault();
3853
3854
                    if (drNozzle != null)
3855 7106e181 LJIYEON
                        result += " [" + drNozzle.Field<string>("ITEMTAG") + "]";
3856
                }
3857 36a45f13 gaqhf
                else
3858
                {
3859 2f7c4151 이지연
                    
3860 a5616391 LJIYEON
                    item = Groups.First().Items.First();
3861 27d06aa8 LJIYEON
                    if (item.ItemType == ItemType.Symbol)
3862
                    {
3863 8ab98ea3 LJIYEON
                        string keyword = string.Empty;
3864 a5616391 LJIYEON
                        keyword = GetFromKeywordData(ref Type, item);
3865 8ab98ea3 LJIYEON
3866
                        if (string.IsNullOrEmpty(keyword))
3867
                        {
3868
                            if (item.ID2DBType.Contains("OPC's"))
3869 51974d2b LJIYEON
                                Status += ", OPC Disconnected";
3870 8ab98ea3 LJIYEON
                            else
3871
                                Status += ", Missing ItemTag or Description";
3872
3873
                            result = item.ID2DBName;
3874 2f7c4151 이지연
                            IsValid = "Error";
3875 8ab98ea3 LJIYEON
                        }
3876
                        else
3877 eb44d82c LJIYEON
                        {
3878 8ab98ea3 LJIYEON
                            result = keyword;
3879 a36541fb LJIYEON
                            IsKeyword = true;
3880 eb44d82c LJIYEON
                        }
3881 7106e181 LJIYEON
3882 27d06aa8 LJIYEON
                    }
3883
                    else if (item.ItemType == ItemType.Line)
3884
                    {
3885 85eeb2be 이지연
                        if (item.LineNumber != null && !string.IsNullOrEmpty(item.LineNumber.Name))
3886 48870200 LJIYEON
                        {
3887 85eeb2be 이지연
                            result = item.LineNumber.Name;
3888 48870200 LJIYEON
                        }
3889 f6c9db1a 이지연
                        else
3890 85eeb2be 이지연
                        {
3891
                            IsValid = "Error";
3892
                            result = "Empty LineNumber";
3893
                        }
3894 23204ef6 이지연
3895
                   
3896
                       
3897 27d06aa8 LJIYEON
                    }
3898
                    else
3899
                        result = "Unknown";
3900 36a45f13 gaqhf
                }
3901 23204ef6 이지연
3902
                if (oItem.LineNumber != null && !string.IsNullOrEmpty(oItem.LineNumber.Name))
3903
                {
3904
                    if (oItem.LineNumber.MissingLineNumber2)
3905
                    {
3906
                        OStatus += ", Missing LineNumber_2";
3907
                        IsValid = "Error";
3908
                    }
3909
                    if (oItem.LineNumber.MissingLineNumber1)
3910
                    {
3911
                        OStatus += ", Missing LineNumber_1";
3912
                        IsValid = "Error";
3913
                    }
3914
                }
3915 36a45f13 gaqhf
            }
3916 7106e181 LJIYEON
            catch (Exception ex)
3917 36a45f13 gaqhf
            {
3918
3919
            }
3920 94a117ca gaqhf
3921
            return result;
3922
        }
3923
3924 a5616391 LJIYEON
        public string GetFromKeywordData(ref string Type, Item item)
3925 879ce10b LJIYEON
        {
3926
            string result = string.Empty;
3927 7106e181 LJIYEON
3928
            foreach (KeywordItem keyitem in KeywordInfos.KeywordItems)
3929 879ce10b LJIYEON
            {
3930 7106e181 LJIYEON
                if (keyitem.Name.Equals(item.Name))
3931 a5616391 LJIYEON
                {
3932 eb44d82c LJIYEON
                    result = keyitem.Keyword;
3933 a5616391 LJIYEON
                    Type = item.ID2DBType;
3934 a2973aa3 LJIYEON
                    break;
3935 a5616391 LJIYEON
                }
3936 879ce10b LJIYEON
            }
3937 7106e181 LJIYEON
3938 879ce10b LJIYEON
            return result;
3939
        }
3940
3941 a5616391 LJIYEON
        public string GetToKeywordData(ref string Type, Item item)
3942 879ce10b LJIYEON
        {
3943
            string result = string.Empty;
3944
3945 eb44d82c LJIYEON
            foreach (KeywordItem keyitem in KeywordInfos.KeywordItems)
3946 879ce10b LJIYEON
            {
3947 eb44d82c LJIYEON
                if (keyitem.Name.Equals(item.Name))
3948 a5616391 LJIYEON
                {
3949 eb44d82c LJIYEON
                    result = keyitem.Keyword;
3950 a5616391 LJIYEON
                    Type = item.ID2DBType;
3951 a2973aa3 LJIYEON
                    break;
3952 a5616391 LJIYEON
                }
3953 879ce10b LJIYEON
            }
3954
            return result;
3955
        }
3956
3957 23204ef6 이지연
        public string GetToData(ref string ToType, ref Item item, Item oItem)
3958 94a117ca gaqhf
        {
3959
            string result = string.Empty;
3960 51974d2b LJIYEON
            Status = string.Empty;
3961 eb44d82c LJIYEON
3962 a2973aa3 LJIYEON
            if (IsKeyword)
3963
                IsKeyword = false;
3964 3210f690 LJIYEON
3965 08b33e44 gaqhf
            item = Groups.Last().Items.Last();
3966
3967 a2973aa3 LJIYEON
            if (EndType == PSNType.Header)
3968
                result = "ENDOFHEADER";
3969
            else if (EndType == PSNType.Branch)
3970
            {
3971 dd27861e 이지연
                if (item.Relations.Last().Item.LineNumber != null && !string.IsNullOrEmpty(item.Relations.Last().Item.LineNumber.Name))
3972 a2973aa3 LJIYEON
                    result = item.Relations.Last().Item.LineNumber.Name;
3973
                else
3974 36a45f13 gaqhf
                {
3975 85eeb2be 이지연
                    IsValid = "Error";
3976 a2973aa3 LJIYEON
                    result = "Empty LineNumber";
3977 23204ef6 이지연
                }
3978
3979
            
3980
              
3981
                //if (item.Relations.Last().Item.LineNumber != null && !string.IsNullOrEmpty(item.Relations.Last().Item.LineNumber.Name))
3982
                //{
3983
                //    result = item.Relations.Last().Item.LineNumber.Name;
3984
                //    if (item.Relations.Last().Item.LineNumber.MissingLineNumber2)
3985
                //    {
3986
                //        Status += ", Missing LineNumber_2";
3987
                //        IsValid = "Error";
3988
                //    }
3989
                //    if (item.Relations.Last().Item.LineNumber.MissingLineNumber1)
3990
                //    {
3991
                //        Status += ", Missing LineNumber_1";
3992
                //        IsValid = "Error";
3993
                //    }
3994
                //}
3995
                //else
3996
                //{
3997
                //    IsValid = "Error";
3998
                //    result = "Empty LineNumber";
3999
                //}                
4000 a2973aa3 LJIYEON
            }
4001
            else if (EndType == PSNType.Equipment)
4002
            {
4003 7106e181 LJIYEON
                if (Groups.Last().Items.Last().Equipment != null)
4004 a2973aa3 LJIYEON
                    result = Groups.Last().Items.Last().Equipment.ItemTag;
4005 8ab98ea3 LJIYEON
4006 a2973aa3 LJIYEON
                DataRow drNozzle = Nozzle.Select(string.Format("OID = '{0}'", Groups.Last().Items.Last().UID)).FirstOrDefault();
4007 3210f690 LJIYEON
4008 a2973aa3 LJIYEON
                if (drNozzle != null)
4009
                    result += " [" + drNozzle.Field<string>("ITEMTAG") + "]";
4010
            }
4011
            else
4012
            {
4013 2f7c4151 이지연
                
4014 a2973aa3 LJIYEON
                item = Groups.Last().Items.Last();
4015
                if (item.ItemType == ItemType.Symbol)
4016 3210f690 LJIYEON
                {
4017 a2973aa3 LJIYEON
                    string keyword = string.Empty;
4018
                    keyword = GetToKeywordData(ref ToType, item);
4019 3210f690 LJIYEON
4020 a2973aa3 LJIYEON
                    if (string.IsNullOrEmpty(keyword))
4021
                    {
4022
                        if (item.ID2DBType.Contains("OPC's"))
4023 51974d2b LJIYEON
                            Status += ", OPC Disconnected";
4024 8ab98ea3 LJIYEON
                        else
4025 a2973aa3 LJIYEON
                            Status += ", Missing ItemTag or Description";
4026 8ab98ea3 LJIYEON
4027 a2973aa3 LJIYEON
                        result = item.ID2DBName;
4028 2f7c4151 이지연
                        IsValid = "Error";
4029 8ab98ea3 LJIYEON
                    }
4030 a2973aa3 LJIYEON
                    else
4031 eb44d82c LJIYEON
                    {
4032 a2973aa3 LJIYEON
                        result = keyword;
4033
                        IsKeyword = true;
4034 eb44d82c LJIYEON
                    }
4035 a2973aa3 LJIYEON
4036
                }
4037
                else if (item.ItemType == ItemType.Line)
4038
                {
4039 85eeb2be 이지연
                    if (item.LineNumber != null && !string.IsNullOrEmpty(item.LineNumber.Name))
4040 48870200 LJIYEON
                    {
4041 85eeb2be 이지연
                        result = item.LineNumber.Name;
4042 48870200 LJIYEON
                    }
4043 f6c9db1a 이지연
                    else
4044 85eeb2be 이지연
                    {
4045
                        IsValid = "Error";
4046
                        result = "Empty LineNumber";
4047
                    }
4048 23204ef6 이지연
4049
                   
4050
                    
4051 36a45f13 gaqhf
                }
4052 a2973aa3 LJIYEON
                else
4053
                    result = "Unknown";
4054
            }
4055 23204ef6 이지연
4056 94a117ca gaqhf
            return result;
4057
        }
4058 7881ec8f gaqhf
4059
        public string GetPBSData()
4060
        {
4061
            string result = string.Empty;
4062
            List<string> PBSList = new List<string>();
4063
            if (Settings.Default.PBSSetting.Equals("Line Number"))
4064
            {
4065
                string attrValue = Settings.Default.PBSSettingValue;
4066
4067
                foreach (Group group in Groups)
4068
                {
4069 7106e181 LJIYEON
                    List<LineNumber> lineNumbers = group.Items.Select(x => x.LineNumber).Distinct().ToList();
4070 7881ec8f gaqhf
                    foreach (LineNumber lineNumber in lineNumbers)
4071
                    {
4072
                        Attribute attribute = lineNumber.Attributes.Find(x => x.Name == attrValue && !string.IsNullOrEmpty(x.Value));
4073
                        if (attribute != null)
4074
                        {
4075
                            string value = attribute.Value;
4076
                            if (!PBSList.Contains(value))
4077
                                PBSList.Add(value);
4078
                        }
4079
                    }
4080
                }
4081
            }
4082
            else if (Settings.Default.PBSSetting.Equals("Item Attribute"))
4083
            {
4084
                string attrValue = Settings.Default.PBSSettingValue;
4085
4086
                foreach (Group group in Groups)
4087
                {
4088
                    List<Item> items = group.Items.FindAll(x => x.Attributes.Find(y => y.Name == attrValue && !string.IsNullOrEmpty(y.Value)) != null);
4089
                    foreach (Item item in items)
4090
                    {
4091
                        string value = item.Attributes.Find(x => x.Name == attrValue).Value;
4092
                        if (!PBSList.Contains(value))
4093
                            PBSList.Add(value);
4094
                    }
4095
                }
4096
            }
4097
            else if (Settings.Default.PBSSetting.Equals("Drawing No"))
4098
            {
4099
                string attrValue = Settings.Default.PBSSettingValue;
4100
4101
                foreach (Group group in Groups)
4102
                {
4103
                    List<Document> documents = group.Items.Select(x => x.Document).Distinct().ToList();
4104
                    foreach (Document document in documents)
4105
                    {
4106
                        string name = document.DrawingName;
4107
4108
                        int startIndex = Settings.Default.PBSSettingStartValue;
4109
                        int endIndex = Settings.Default.PBSSettingEndValue;
4110
4111
                        string subStr = name.Substring(startIndex - 1, endIndex - startIndex + 1);
4112
                        if (!PBSList.Contains(subStr))
4113
                            PBSList.Add(subStr);
4114
                    }
4115
                }
4116
            }
4117
            else if (Settings.Default.PBSSetting.Equals("Unit Area"))
4118
            {
4119
                foreach (Group group in Groups)
4120
                {
4121
                    List<Document> documents = group.Items.Select(x => x.Document).Distinct().ToList();
4122
                    foreach (Document document in documents)
4123
                    {
4124
                        List<TextInfo> textInfos = document.TextInfos.FindAll(x => x.Area == "Unit");
4125
                        foreach (TextInfo textInfo in textInfos)
4126
                        {
4127
                            if (!PBSList.Contains(textInfo.Value))
4128
                                PBSList.Add(textInfo.Value);
4129
                        }
4130
                    }
4131
                }
4132
            }
4133
4134
            foreach (var item in PBSList)
4135
            {
4136
                if (string.IsNullOrEmpty(result))
4137
                    result = item;
4138
                else
4139
                    result += ", " + item;
4140
            }
4141
            return result;
4142
        }
4143 6b9e7a56 gaqhf
    }
4144
}
클립보드 이미지 추가 (최대 크기: 500 MB)