프로젝트

일반

사용자정보

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

hytos / DTI_PID / ID2PSN / PSN.cs @ 85eeb2be

이력 | 보기 | 이력해설 | 다운로드 (185 KB)

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