프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / ID2PSN / PSN.cs @ d2cffa33

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

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