프로젝트

일반

사용자정보

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

hytos / DTI_PID / ID2PSN / PSN.cs @ bf9e8432

이력 | 보기 | 이력해설 | 다운로드 (137 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 6b9e7a56 gaqhf
12
namespace ID2PSN
13
{
14
    public enum PSNType
15
    {
16
        None,
17
        Branch,
18
        Equipment,
19
        Header,
20
        Symbol,
21
        OPC,
22
    }
23
24 45529c16 LJIYEON
    public enum ErrorType
25
    {
26
        Error = -1,
27
        OK,
28
        InValid //이값은 들어가는데가 없음..
29
    }
30
31 6b9e7a56 gaqhf
    public class PSN
32
    {
33 8f24b438 gaqhf
        private double[] DrawingSize = null;
34
        private double DrawingWidth = double.NaN;
35
        private double DrawingHeight = double.NaN;
36
        public int Revision;
37 c6503eaa gaqhf
        public string EquipTagNoAttributeName = string.Empty;
38 6b9e7a56 gaqhf
        public DataTable PathItems { get; set; }
39
        public DataTable SequenceData { get; set; }
40
        public DataTable PipeSystemNetwork { get; set; }
41 36a45f13 gaqhf
        public DataTable TopologySet { get; set; }
42 6b9e7a56 gaqhf
        public DataTable Equipment { get; set; }
43
        public DataTable Nozzle { get; set; }
44 a36541fb LJIYEON
        public DataTable PipeLine { get; set; }
45 531fb158 LJIYEON
        public DataTable PipeSystem { get; set; }
46 6b9e7a56 gaqhf
47 51974d2b LJIYEON
        public string Rule1 = "Missing LineNumber_1"; //Line Disconnected에서 변경
48
        public string Rule2 = "Missing LineNumber_2"; //Missing LineNumber에서 변경
49
        public string Rule3 = "OPC Disconnected";
50 5e4c2ad1 LJIYEON
        public string Rule4 = "Missing ItemTag or Description";
51 51974d2b LJIYEON
        public string Rule5 = "Line Disconnected";
52 2ada3be8 LJIYEON
53 710a49f1 gaqhf
        int tieInPointIndex = 1;
54
55 6b9e7a56 gaqhf
        List<Document> Documents;
56
        List<Group> groups = new List<Group>();
57
        List<PSNItem> PSNItems = new List<PSNItem>();
58
        List<Topology> Topologies = new List<Topology>();
59
60
        DataTable opcDT = null;
61
        DataTable topologyRuleDT = null;
62
63 5dfc785c LJIYEON
        ID2Info id2Info = ID2Info.GetInstance();
64
65 7106e181 LJIYEON
66 eb44d82c LJIYEON
67 a36541fb LJIYEON
        //const string FluidPriorityType = "FLUIDCODE";
68
        //const string PipingMaterialsPriorityType = "PIPINGMATERIALSCLASS";
69 6b9e7a56 gaqhf
70 5c248ee3 gaqhf
        public PSN()
71
        {
72 7106e181 LJIYEON
73 5c248ee3 gaqhf
        }
74
75 8f24b438 gaqhf
        public PSN(List<Document> documents, int Revision)
76 6b9e7a56 gaqhf
        {
77 5dfc785c LJIYEON
            try
78
            {
79
                Documents = documents;
80
                foreach (Document document in Documents)
81
                    groups.AddRange(document.Groups);
82
                opcDT = GetOPCInfo();
83
                topologyRuleDT = GetTopologyRule();
84
                this.Revision = Revision;
85
                DrawingSize = DB.GetDrawingSize();
86
                if (DrawingSize == null)
87
                {
88
                    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);
89
                    return;
90
                }
91
                DrawingWidth = DrawingSize[2] - DrawingSize[0];
92
                DrawingHeight = DrawingSize[3] - DrawingSize[1];
93
            }
94
            catch (Exception ex)
95
            {
96
                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
97
                MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
98
            }
99 6b9e7a56 gaqhf
        }
100
101 36a45f13 gaqhf
        private string GetItemTag(Item item)
102
        {
103
            string result = string.Empty;
104
            if (item.ItemType == ItemType.Line)
105
                result = item.LineNumber != null ? item.LineNumber.Name : string.Empty;
106
            else if (item.ItemType == ItemType.Symbol && item.SubItemType == SubItemType.Nozzle)
107
                result = Nozzle.Select(string.Format("OID = '{0}'", item.UID)).First()["ITEMTAG"].ToString();
108
109
            return result;
110
        }
111 7881ec8f gaqhf
        private string GetItemName(Item item, string itemOID)
112
        {
113
            string result = string.Empty;
114
            if (item.ItemType == ItemType.Line && (item.Name == "Secondary" || item.Name == "Primary"))
115
            {
116
                if (itemOID.Contains("_"))
117
                {
118
                    string split = itemOID.Split(new char[] { '_' })[1];
119
                    if (split.StartsWith("B"))
120
                        result = "Branch";
121
                    else
122
                        result = "PipeRun";
123
                }
124
                else
125
                    result = "PipeRun";
126
            }
127
            else if (item.ItemType == ItemType.Symbol)
128
            {
129
                if (item.ID2DBCategory == "Instrumentation")
130
                    result = "Instrument";
131
                else if (item.ID2DBType == "Nozzles")
132
                    result = "Nozzle";
133
                else if (item.ID2DBType == "Fittings" ||
134
                        item.ID2DBType == "Piping OPC's" ||
135
                        item.ID2DBType == "Specialty Components" ||
136
                        item.ID2DBType == "Valves" ||
137
                        item.ID2DBType == "Reducers")
138
                    result = "PipingComp";
139
            }
140
            return result;
141
        }
142
143
        private string GetClass(Item item, string itemOID)
144
        {
145
            string result = string.Empty;
146
            if (item.ItemType == ItemType.Line && (item.Name == "Secondary" || item.Name == "Primary"))
147
            {
148
                if (itemOID.Contains("_"))
149
                {
150
                    string split = itemOID.Split(new char[] { '_' })[1];
151
                    if (split.StartsWith("B"))
152
                        result = "Branch";
153
                    else
154
                        result = "Piping";
155
                }
156
                else
157
                    result = "Piping";
158
            }
159
            else if (item.ItemType == ItemType.Symbol)
160
            {
161
                if (item.ID2DBCategory == "Instrumentation")
162
                    result = item.ID2DBType;
163
                else if (item.ID2DBType == "Nozzles")
164
                    result = string.Empty;
165
                else if (item.ID2DBType == "Fittings" ||
166
                       item.ID2DBType == "Piping OPC's" ||
167
                       item.ID2DBType == "Specialty Components" ||
168
                       item.ID2DBType == "Valves" ||
169
                       item.ID2DBType == "Reducers")
170
                    result = item.ID2DBType;
171
            }
172
            return result;
173
        }
174
175
        private string GetSubClass(Item item, string itemOID)
176
        {
177
            string result = string.Empty;
178
            if (item.ItemType == ItemType.Line && (item.Name == "Secondary" || item.Name == "Primary"))
179
            {
180
                if (itemOID.Contains("_"))
181
                {
182
                    string split = itemOID.Split(new char[] { '_' })[1];
183
                    if (split.StartsWith("B"))
184
                        result = "Tee";
185
                    else
186
                        result = "";
187
                }
188
                else
189
                    result = "";
190
            }
191
            else if (item.ItemType == ItemType.Symbol)
192
            {
193
                if (item.ID2DBCategory == "Instrumentation")
194
                    result = string.Empty;
195
                else if (item.ID2DBType == "Nozzles")
196
                    result = string.Empty;
197
                else if (item.ID2DBType == "Fittings" ||
198
                       item.ID2DBType == "Piping OPC's" ||
199
                       item.ID2DBType == "Specialty Components" ||
200
                       item.ID2DBType == "Valves" ||
201
                       item.ID2DBType == "Reducers")
202
                    result = "In-line component";
203
            }
204
            return result;
205
        }
206 36a45f13 gaqhf
207 6b9e7a56 gaqhf
        public void SetPSNData()
208 7106e181 LJIYEON
        {
209 7881ec8f gaqhf
            // Item들의 속성으로 Topology Data를 생성한다.
210 3610fd3f LJIYEON
            // Topology Data는 Topology Rule Setting을 기준으로 생성한다.             
211 327a7a9c LJIYEON
            SetTopologyData();
212 7881ec8f gaqhf
            // ID2의 OPC연결 Data 기반으로 Group(도면단위 PSN)을 연결한다.
213 6b9e7a56 gaqhf
            ConnectByOPC();
214 7881ec8f gaqhf
            // 실제 PSN 생성 로직
215
            // 연결된 Group을 하나의 PSN으로 만든다.
216 6b9e7a56 gaqhf
            SetPSNItem();
217 7881ec8f gaqhf
            // 생성된 PSN의 Type을 설정한다.
218 6b9e7a56 gaqhf
            SetPSNType();
219 7881ec8f gaqhf
            // ID2에는 Branch 정보가 없어서 Branch 정보를 생성한다.
220 6b9e7a56 gaqhf
            SetBranchInfo();
221 7881ec8f gaqhf
            // 생성된 Topology Data들을 정리하며 Main, Branch를 판단한다.
222 6b9e7a56 gaqhf
            SetTopology();
223 7881ec8f gaqhf
            // PSN이 Bypass인지 검사 
224
            SetPSNBypass();
225
            // Topology들에게 Index를 부여한다
226 7106e181 LJIYEON
            SetTopologyIndex();
227 7881ec8f gaqhf
            // Nozzle, Equipment의 정보를 저장
228 6b9e7a56 gaqhf
            SaveNozzleAndEquipment();
229 7881ec8f gaqhf
            // PSN의 정보를 저장
230 6b9e7a56 gaqhf
            SavePSNData();
231 a2973aa3 LJIYEON
            // Update Keyword
232
            UpdateKeywordForPSN();
233
            // Vent/Drain PSN 데이터 제거
234
            DeleteVentDrain();
235 7881ec8f gaqhf
            // Topology의 subtype을 update(bypass, Header, 등등) 
236
            UpdateSubType();
237
            // Update Error
238 4e2e0aa1 LJIYEON
            UpdateErrorForPSN();
239
            // Insert Tee
240
            InsertTeePSN();
241 5e4c2ad1 LJIYEON
            // 확도 계산
242 811d7949 LJIYEON
            UpdateAccuracy();
243 7106e181 LJIYEON
            // ValveGrouping
244 811d7949 LJIYEON
            UpdateValveGrouping();
245 bf9e8432 이지연
            // AirFinCooler 
246
            UpdateAirFinCooler();
247 9ba9dcd2 LJIYEON
            // PathItem 정렬
248
            //PathItemSort();
249 811d7949 LJIYEON
        }
250
251 bf9e8432 이지연
        private void UpdateAirFinCooler()
252
        {
253
            try
254
            {
255
                #region EquipmentAirFinCooler Info
256
                EquipmentAirFinCoolerInfo EquipmentAirFinCooler = new EquipmentAirFinCoolerInfo();
257
                DataTable dtEquipmentAirFinCooler = DB.SelectAirFinCoolerSetting();
258
                foreach (DataRow row in dtEquipmentAirFinCooler.Rows)
259
                {
260
                    //pump type도 마찬가지?
261
                    EquipmentAirFinCooler.EquipmentAirFinCoolerItem.Add(new EquipmentAirFinCoolerItem()
262
                    {
263
                        Type = row["Type"].ToString(),
264
                        Name = row["Name"].ToString()
265
                    });
266
                }
267
                #endregion
268
269
                foreach(EquipmentAirFinCoolerItem item in EquipmentAirFinCooler.EquipmentAirFinCoolerItem)
270
                {
271
                    DataRow[] airFinCoolerRows = PipeSystemNetwork.Select(string.Format(" From_Data Like '{0}%' OR To_Data Like '{0}%'", item.Name));
272
                    foreach (DataRow dataRow in airFinCoolerRows)
273
                    {
274
                        PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString());
275
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"].ToString()));
276
                        foreach(DataRow dr in pathItemRows)
277
                        {
278
                            dr["EqpGroupTag"] = dataRow["Pipeline_OID"].ToString(); //ATG Sequence No Rule 여쭤봐야함.
279
                        }                       
280
                    }
281
                }
282
            }
283
            catch (Exception ex)
284
            {
285
                MessageBox.Show(ex.Message, "ID2 ", MessageBoxButtons.OK, MessageBoxIcon.Error);
286
            }
287
            //}
288
        }
289 9ba9dcd2 LJIYEON
290 811d7949 LJIYEON
        private void UpdateValveGrouping()
291
        {
292
            try
293
            {
294
                #region ValveGrouping Info
295
                ValveGroupInfo ValveGrouping = new ValveGroupInfo();
296
                DataTable dtValveGroupung = DB.SelectValveGroupItemsSetting();
297
                foreach (DataRow row in dtValveGroupung.Rows)
298
                {
299
                    ValveGrouping.ValveGroupItems.Add(new ValveGroupItem()
300
                    {
301
                        OID = row["OID"].ToString(),
302
                        GroupType = row["GroupType"].ToString(),
303
                        TagIdentifier = row["TagIdentifier"].ToString(),
304
                        AttributeName = row["AttributeName"].ToString(),
305
                        SppidSymbolName = row["SppidSymbolName"].ToString()
306
                    });
307
                }
308
                #endregion
309
310 7106e181 LJIYEON
311 811d7949 LJIYEON
                int vgTagNum = 1;
312
                DataRow[] tagpathItemRows = PathItems.Select(string.Format("GROUPTAG Like '%\\%'"));
313
                foreach (DataRow drPathitem in tagpathItemRows)
314
                {
315
                    string[] valvetag = drPathitem["GROUPTAG"].ToString().Split(new string[] { "\\" }, StringSplitOptions.None);
316
                    DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", drPathitem["PipeSystemNetwork_OID"].ToString()));
317
                    ValveGroupItem valveitem = ValveGrouping.ValveGroupItems.Where(x => x.SppidSymbolName == valvetag[0]).FirstOrDefault();
318 54b6df95 LJIYEON
                    if (valveitem == null || valveitem.GroupType == "Scope Break")
319 0a2fbe44 LJIYEON
                        continue;
320 811d7949 LJIYEON
                    Dictionary<int, List<DataRow>> keyValuePairs = new Dictionary<int, List<DataRow>>();
321
                    List<Item> valveGroupingItem = new List<Item>();
322
                    int bCnt = 0;
323
324 f2a63376 이지연
                    //bool bCheck = false;
325 811d7949 LJIYEON
                    List<DataRow> lstitem = new List<DataRow>();
326
                    foreach (DataRow dr in pathItemRows)
327
                    {
328 0a2fbe44 LJIYEON
                        //if (!string.IsNullOrEmpty(dr["GROUPTAG"].ToString()))
329
                        //    break;
330 9ba9dcd2 LJIYEON
331 f2a63376 이지연
                       if (!string.IsNullOrEmpty(dr["BranchTopologySet_OID"].ToString()))
332 811d7949 LJIYEON
                        {
333
                            DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", dr["BranchTopologySet_OID"].ToString()));
334 54b6df95 LJIYEON
                            if (dr["GROUPTAG"].ToString() == "Scope Break")
335
                            {
336
                                dr["GROUPTAG"] = string.Empty;
337
                                break;
338
                            }
339
340 f2a63376 이지연
                            if (rows.First()["SubType"].ToString() != "Bypass" && rows.First()["SubType"].ToString() != "Vent_Drain")
341 811d7949 LJIYEON
                            {
342 f2a63376 이지연
                               // bCheck = true;
343 54b6df95 LJIYEON
                                lstitem.Add(dr);
344 811d7949 LJIYEON
                                keyValuePairs.Add(bCnt, lstitem.ToList());
345
                                bCnt++;
346
                                lstitem.Clear();
347
                            }
348
                            else
349
                                lstitem.Add(dr);
350
                        }
351
                        else
352
                            lstitem.Add(dr);
353
                    }
354
355 54b6df95 LJIYEON
                    if (lstitem.Count > 0)
356 811d7949 LJIYEON
                    {
357
                        keyValuePairs.Add(bCnt, lstitem);
358 f2a63376 이지연
                        //bCnt++;
359 811d7949 LJIYEON
                    }
360 9ba9dcd2 LJIYEON
361
                    if (keyValuePairs.Count() == 0)
362
                        continue;
363
364 811d7949 LJIYEON
                    string VGTag = string.Empty;
365
                    if (valveitem.AttributeName == "NoSelection")
366
                    {
367
                        VGTag = valveitem.TagIdentifier + string.Format("-{0}", string.Format("{0:D5}", vgTagNum));
368
                        vgTagNum++;
369
                    }
370
                    else
371
                    {
372
                        VGTag = valveitem.TagIdentifier + "-" + valvetag[1];
373
                    }
374
375
                    foreach (KeyValuePair<int, List<DataRow>> keyValuePair in keyValuePairs)
376
                    {
377
                        if (keyValuePair.Value.Where(x => x.Field<string>("OID") == drPathitem.Field<string>("OID")).Count() > 0)
378
                        {
379
                            foreach (DataRow dr in keyValuePair.Value)
380
                            {
381
                                dr["GROUPTAG"] = VGTag;
382
                            }
383
                        }
384
                    }
385 08b33e44 gaqhf
386
                    if(valveitem.GroupType.Contains("PSV"))
387
                    {
388
                        DataRow[] psnRows = PipeSystemNetwork.Select(string.Format("OID = '{0}'", drPathitem["PipeSystemNetwork_OID"].ToString()));
389
                        foreach (DataRow row in psnRows)
390
                            row["Pocket"] = "Yes";
391 f2a63376 이지연
                    }                    
392 811d7949 LJIYEON
                }
393 bf9e8432 이지연
394
395 811d7949 LJIYEON
            }
396 7106e181 LJIYEON
            catch (Exception ex)
397 811d7949 LJIYEON
            {
398
                MessageBox.Show(ex.Message, "ID2 ", MessageBoxButtons.OK, MessageBoxIcon.Error);
399
            }
400
            //}
401 6b9e7a56 gaqhf
        }
402 7881ec8f gaqhf
403 6b9e7a56 gaqhf
        private void SetTopologyData()
404
        {
405 710a49f1 gaqhf
            // 13번 excel
406
            foreach (Group group in groups)
407
            {
408
                LineNumber prevLineNumber = null;
409
                for (int i = 0; i < group.Items.Count; i++)
410
                {
411
                    Item item = group.Items[i];
412
                    LineNumber lineNumber = item.Document.LineNumbers.Find(x => x.UID == item.Owner);
413
                    if (lineNumber == null)
414
                    {
415
                        if (prevLineNumber != null)
416
                        {
417
                            if (!prevLineNumber.IsCopy)
418
                            {
419
                                prevLineNumber = prevLineNumber.Copy();
420 48870200 LJIYEON
                                item.Document.LineNumbers.Add(prevLineNumber);
421
                                item.MissingLineNumber1 = true;
422 710a49f1 gaqhf
                            }
423
                            item.Owner = prevLineNumber.UID;
424
                        }
425
                    }
426
                    else
427
                        prevLineNumber = lineNumber;
428
                }
429
430
                prevLineNumber = null;
431
                for (int i = group.Items.Count - 1; i > -1; i--)
432
                {
433
                    Item item = group.Items[i];
434
                    LineNumber lineNumber = item.Document.LineNumbers.Find(x => x.UID == item.Owner);
435
                    if (lineNumber == null)
436
                    {
437
                        if (prevLineNumber != null)
438
                        {
439
                            if (!prevLineNumber.IsCopy)
440
                            {
441
                                prevLineNumber = prevLineNumber.Copy();
442
                                item.Document.LineNumbers.Add(prevLineNumber);
443 48870200 LJIYEON
                                item.MissingLineNumber1 = true;
444 710a49f1 gaqhf
                            }
445
446
                            item.Owner = prevLineNumber.UID;
447
                        }
448
                    }
449
                    else
450
                        prevLineNumber = lineNumber;
451
                }
452
453
                if (prevLineNumber == null)
454
                {
455
                    List<LineNumber> lineNumbers = group.Document.LineNumbers.FindAll(x => !x.IsCopy);
456
                    Random random = new Random();
457
                    int index = random.Next(lineNumbers.Count - 1);
458 a2973aa3 LJIYEON
459 710a49f1 gaqhf
                    // Copy
460
                    LineNumber cLineNumber = lineNumbers[index].Copy();
461
                    group.Document.LineNumbers.Add(cLineNumber);
462 7106e181 LJIYEON
463 710a49f1 gaqhf
                    foreach (Item item in group.Items)
464 a2973aa3 LJIYEON
                    {
465 710a49f1 gaqhf
                        item.Owner = cLineNumber.UID;
466 48870200 LJIYEON
                        item.MissingLineNumber2 = true;
467 7106e181 LJIYEON
                    }
468 710a49f1 gaqhf
                }
469
            }
470
471 6b9e7a56 gaqhf
            foreach (Document document in Documents)
472
            {
473
                foreach (Item item in document.Items)
474
                {
475
                    item.TopologyData = string.Empty;
476 8f24b438 gaqhf
                    item.PSNPipeLineID = string.Empty;
477 33cee849 LJIYEON
                    List<string> pipeLineID = new List<string>();
478 6b9e7a56 gaqhf
                    LineNumber lineNumber = document.LineNumbers.Find(x => x.UID == item.Owner);
479
                    if (lineNumber != null)
480
                    {
481
                        item.LineNumber = lineNumber;
482
483
                        foreach (DataRow row in topologyRuleDT.Rows)
484
                        {
485
                            string uid = row["UID"].ToString();
486 33cee849 LJIYEON
                            //if (uid == "-")
487
                            //    pipeLineID.Add(item.TopologyData);//item.TopologyData += "-"; 
488
                            if (uid != "-")
489 6b9e7a56 gaqhf
                            {
490 7106e181 LJIYEON
                                Attribute itemAttr = item.Attributes.Find(x => x.Name == uid);
491 f25b787a gaqhf
492
                                Attribute attribute = lineNumber.Attributes.Find(x => x.Name == uid);
493 33cee849 LJIYEON
                                if (attribute != null && !string.IsNullOrEmpty(attribute.Value))
494
                                    pipeLineID.Add(attribute.Value);//item.TopologyData += attribute.Value;
495 6b9e7a56 gaqhf
                            }
496
                        }
497 8f24b438 gaqhf
498 7106e181 LJIYEON
                        if (topologyRuleDT.Select(string.Format("UID = '{0}'", "InsulationPurpose")) == null)
499 3210f690 LJIYEON
                        {
500
                            Attribute insulAttr = item.LineNumber.Attributes.Find(x => x.Name == "InsulationPurpose");
501
                            if (insulAttr != null && !string.IsNullOrEmpty(insulAttr.Value))
502
                                pipeLineID.Add(insulAttr.Value); //item.PSNPipeLineID = item.TopologyData + "-" + insulAttr.Value;
503
                                                                 //else
504
                                                                 //    item.PSNPipeLineID = item.TopologyData;
505
                        }
506
507 33cee849 LJIYEON
                        item.PSNPipeLineID = string.Join("-", pipeLineID);
508
                        item.TopologyData = string.Join("-", pipeLineID);
509 7106e181 LJIYEON
510 6b9e7a56 gaqhf
                    }
511 0f07fa34 gaqhf
                    else
512
                    {
513
                        item.TopologyData = "Empty LineNumber";
514
                        item.LineNumber = new LineNumber();
515
                    }
516 6b9e7a56 gaqhf
                }
517
            }
518
519 0f07fa34 gaqhf
            int emptyIndex = 1;
520
            foreach (Group group in groups)
521
            {
522
                List<Item> groupItems = group.Items.FindAll(x => x.TopologyData == "Empty LineNumber");
523
                if (groupItems.Count > 0)
524
                {
525
                    foreach (var item in groupItems)
526
                        item.TopologyData += string.Format("-{0}", emptyIndex);
527
                    emptyIndex++;
528
                }
529
            }
530 6b9e7a56 gaqhf
531
        }
532 7106e181 LJIYEON
533 6b9e7a56 gaqhf
        private void ConnectByOPC()
534
        {
535 21edb7bc LJIYEON
            try
536 6b9e7a56 gaqhf
            {
537 21edb7bc LJIYEON
                foreach (Group group in groups.FindAll(x => x.Items.Last().SubItemType == SubItemType.OPC))
538 6b9e7a56 gaqhf
                {
539 21edb7bc LJIYEON
                    Item opcItem = group.Items.Last();
540
                    DataRow[] fromRows = opcDT.Select(string.Format("FromOPCUID = '{0}'", opcItem.UID));
541
                    if (fromRows.Length.Equals(1))
542
                    {
543
                        DataRow opcRow = fromRows.First();
544
                        string toDrawing = opcRow["ToDrawing"].ToString();
545
                        string toOPCUID = opcRow["ToOPCUID"].ToString();
546
547
                        Document toDocument = Documents.Find(x => x.DrawingName == toDrawing);
548
                        if (toDocument != null)
549 710a49f1 gaqhf
                        {
550 21edb7bc LJIYEON
                            Group toGroup = toDocument.Groups.Find(x => x.Items.Find(y => y.UID == toOPCUID) != null);
551
                            DataRow[] toRows = opcDT.Select(string.Format("ToOPCUID = '{0}'", toGroup.Items.First().UID));
552
                            //1대1 매칭이 아닐때 걸림 (2개 이상일 때) 2021.11.07 
553
                            if (toRows.Length > 1)
554
                            {
555
                                //throw new Exception("OPC error(multi connect)");
556
                                MessageBox.Show("OPC error(multi connect)", "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
557
                                return;
558
                            }
559
                            group.EndGroup = toGroup;
560
                            toGroup.StartGroup = group;
561 710a49f1 gaqhf
                        }
562 0fe04b33 LJIYEON
                    }
563 6b9e7a56 gaqhf
                }
564
            }
565 21edb7bc LJIYEON
            catch (Exception ex)
566
            {
567
                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
568
                //MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
569
            }
570 6b9e7a56 gaqhf
        }
571 5e4c2ad1 LJIYEON
572 6b9e7a56 gaqhf
        private void SetPSNItem()
573
        {
574 7106e181 LJIYEON
            Dictionary<Group, string> groupDic = new Dictionary<Group, string>();
575 6b9e7a56 gaqhf
            foreach (Group group in groups)
576
                groupDic.Add(group, Guid.NewGuid().ToString());
577
578
            foreach (Group group in groups)
579
            {
580
                string groupKey = groupDic[group];
581
                if (group.StartGroup != null)
582
                {
583
                    string otherKey = groupDic[group.StartGroup];
584
                    ChangeGroupID(otherKey, groupKey);
585
                }
586
            }
587
588
            // PSN 정리
589
            foreach (var item in groupDic)
590
            {
591
                Group group = item.Key;
592
                string uid = item.Value;
593
                PSNItem PSNItem = PSNItems.Find(x => x.UID == uid);
594
                if (PSNItem == null)
595
                {
596 8f24b438 gaqhf
                    PSNItem = new PSNItem(PSNItems.Count, Revision) { UID = uid };
597 6b9e7a56 gaqhf
                    PSNItems.Add(PSNItem);
598
                }
599
                PSNItem.Groups.Add(group);
600 36a45f13 gaqhf
                foreach (Item groupItem in group.Items)
601
                    groupItem.PSNItem = PSNItem;
602 6b9e7a56 gaqhf
            }
603
604
            // Sort PSN
605
            foreach (PSNItem PSNItem in PSNItems)
606
            {
607
                List<Group> _groups = new List<Group>();
608
609
                Stack<Group> stacks = new Stack<Group>();
610
                stacks.Push(PSNItem.Groups.First());
611
                while (stacks.Count > 0)
612
                {
613
                    Group stack = stacks.Pop();
614
                    if (_groups.Contains(stack))
615
                        continue;
616
617
                    if (_groups.Count == 0)
618
                        _groups.Add(stack);
619
                    else
620
                    {
621
                        if (stack.StartGroup != null && _groups.Contains(stack.StartGroup))
622
                        {
623
                            int index = _groups.IndexOf(stack.StartGroup);
624
                            _groups.Insert(index + 1, stack);
625
                        }
626
                        else if (stack.EndGroup != null && _groups.Contains(stack.EndGroup))
627
                        {
628
                            int index = _groups.IndexOf(stack.EndGroup);
629
                            _groups.Insert(index, stack);
630
                        }
631
                    }
632
633
                    if (stack.StartGroup != null)
634
                        stacks.Push(stack.StartGroup);
635
                    if (stack.EndGroup != null)
636
                        stacks.Push(stack.EndGroup);
637
                }
638
639
                PSNItem.Groups.Clear();
640
                PSNItem.Groups.AddRange(_groups);
641
            }
642
643
            void ChangeGroupID(string from, string to)
644
            {
645
                if (from.Equals(to))
646
                    return;
647
648
                List<Group> changeItems = new List<Group>();
649
                foreach (var _item in groupDic)
650
                    if (_item.Value.Equals(from))
651
                        changeItems.Add(_item.Key);
652
                foreach (var _item in changeItems)
653
                    groupDic[_item] = to;
654
            }
655
        }
656 5e4c2ad1 LJIYEON
657 6b9e7a56 gaqhf
        private void SetPSNType()
658
        {
659
            foreach (PSNItem PSNItem in PSNItems)
660
            {
661
                Group firstGroup = PSNItem.Groups.First();
662
                Group lastGroup = PSNItem.Groups.Last();
663
664
                Item firstItem = firstGroup.Items.First();
665
                Item lastItem = lastGroup.Items.Last();
666
667
                PSNItem.StartType = GetPSNType(firstItem, true);
668
                PSNItem.EndType = GetPSNType(lastItem, false);
669
            }
670
671
            PSNType GetPSNType(Item item, bool bFirst = true)
672
            {
673
                PSNType type = PSNType.None;
674
675
                if (item.ItemType == ItemType.Line)
676
                {
677
                    Group group = groups.Find(x => x.Items.Contains(item));
678
                    if (bFirst && item.Relations[0].Item != null && !group.Items.Contains(item.Relations[0].Item))
679
                    {
680
                        Item connItem = item.Relations[0].Item;
681
                        if (connItem.ItemType == ItemType.Line && !IsConnected(item, connItem))
682
                            type = PSNType.Branch;
683
                        else if (connItem.ItemType == ItemType.Symbol)
684
                            type = PSNType.Symbol;
685
                    }
686
                    else if (!bFirst && item.Relations[1].Item != null && !group.Items.Contains(item.Relations[1].Item))
687
                    {
688
                        Item connItem = item.Relations[1].Item;
689
                        if (connItem.ItemType == ItemType.Line && !IsConnected(item, connItem))
690
                            type = PSNType.Branch;
691
                        else if (connItem.ItemType == ItemType.Symbol)
692
                            type = PSNType.Symbol;
693
                    }
694
                }
695
                else if (item.ItemType == ItemType.Symbol)
696
                {
697
                    if (item.SubItemType == SubItemType.Nozzle)
698
                        type = PSNType.Equipment;
699
                    else if (item.SubItemType == SubItemType.Header)
700
                        type = PSNType.Header;
701
                    else if (item.SubItemType == SubItemType.OPC)
702
                        type = PSNType.OPC;
703
                }
704
705
                return type;
706
            }
707
        }
708 5e4c2ad1 LJIYEON
709 6b9e7a56 gaqhf
        private void SetBranchInfo()
710
        {
711
            foreach (Document document in Documents)
712
            {
713
                List<Item> lines = document.Items.FindAll(x => x.ItemType == ItemType.Line).ToList();
714
                foreach (Item line in lines)
715
                {
716
                    double[] point = line.Relations[0].Point;
717
                    List<Item> connLines = lines.FindAll(x => x.Relations.Find(y => y.UID == line.UID) != null && line.Relations.Find(y => y.UID == x.UID) == null);
718
                    connLines.Sort(SortBranchLine);
719
                    line.BranchItems.AddRange(connLines);
720
721
                    int SortBranchLine(Item a, Item b)
722
                    {
723
                        double[] pointA = a.Relations[0].UID == line.UID ? a.Relations[0].Point : a.Relations[1].Point;
724
                        double distanceA = CalcPointToPointdDistance(point[0], point[1], pointA[0], pointA[1]);
725
726
                        double[] pointB = b.Relations[0].UID == line.UID ? b.Relations[0].Point : b.Relations[1].Point;
727
                        double distanceB = CalcPointToPointdDistance(point[0], point[1], pointB[0], pointB[1]);
728
729
                        // 내림차순
730
                        return distanceA.CompareTo(distanceB);
731
                    }
732
                    double CalcPointToPointdDistance(double x1, double y1, double x2, double y2)
733
                    {
734
                        return Math.Pow(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2), 0.5);
735
                    }
736
                }
737
            }
738
        }
739 5e4c2ad1 LJIYEON
740 6b9e7a56 gaqhf
        private void SetTopology()
741
        {
742 27d06aa8 LJIYEON
            try
743 6b9e7a56 gaqhf
            {
744 27d06aa8 LJIYEON
                #region 기본 topology 정리
745
                foreach (PSNItem PSNItem in PSNItems)
746 6b9e7a56 gaqhf
                {
747 27d06aa8 LJIYEON
                    Topology topology = null;
748
                    foreach (Group group in PSNItem.Groups)
749 6b9e7a56 gaqhf
                    {
750 27d06aa8 LJIYEON
                        foreach (Item item in group.Items)
751 6b9e7a56 gaqhf
                        {
752 27d06aa8 LJIYEON
                            if (string.IsNullOrEmpty(item.TopologyData))
753
                                topology = null;
754 6b9e7a56 gaqhf
                            else
755
                            {
756 27d06aa8 LJIYEON
                                if (topology == null)
757 6b9e7a56 gaqhf
                                {
758
                                    topology = new Topology()
759
                                    {
760
                                        ID = item.TopologyData
761
                                    };
762
                                    Topologies.Add(topology);
763
764
                                    if (!PSNItem.Topologies.Contains(topology))
765
                                        PSNItem.Topologies.Add(topology);
766
                                }
767 27d06aa8 LJIYEON
                                else
768
                                {
769
                                    if (topology.ID != item.TopologyData)
770
                                    {
771
                                        topology = new Topology()
772
                                        {
773
                                            ID = item.TopologyData
774
                                        };
775
                                        Topologies.Add(topology);
776
777
                                        if (!PSNItem.Topologies.Contains(topology))
778
                                            PSNItem.Topologies.Add(topology);
779
                                    }
780
                                }
781 6b9e7a56 gaqhf
782 27d06aa8 LJIYEON
                                item.Topology = topology;
783
                                topology.Items.Add(item);
784
                            }
785 6b9e7a56 gaqhf
                        }
786
                    }
787
                }
788 27d06aa8 LJIYEON
                #endregion
789 6b9e7a56 gaqhf
790 27d06aa8 LJIYEON
                #region Type
791
                List<string> ids = Topologies.Select(x => x.ID).Distinct().ToList();
792
                foreach (string id in ids)
793
                {
794
                    try
795
                    {
796 678760c6 gaqhf
797 6b9e7a56 gaqhf
798 27d06aa8 LJIYEON
                        List<Topology> topologies = Topologies.FindAll(x => x.ID == id);
799
800
                        // Main
801
                        List<Topology> mainTopologies = FindMainTopology(topologies);
802
                        foreach (Topology topology in mainTopologies)
803
                            topology.Type = "M";
804
805
                        // Branch
806
                        List<Topology> branchToplogies = topologies.FindAll(x => string.IsNullOrEmpty(x.Type));
807
                        foreach (Topology topology in branchToplogies)
808
                            topology.Type = "B";
809
                    }
810
                    catch (Exception ex)
811
                    {
812
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
813
                        MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
814
                    }
815
                }
816
                #endregion
817
            }
818
            catch (Exception ex)
819
            {
820
                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
821
                MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
822 6b9e7a56 gaqhf
            }
823 27d06aa8 LJIYEON
824 6b9e7a56 gaqhf
        }
825 5e4c2ad1 LJIYEON
826 7881ec8f gaqhf
        private void SetTopologyIndex()
827
        {
828
            List<string> ids = Topologies.Select(x => x.ID).Distinct().ToList();
829
            foreach (string id in ids)
830
            {
831
                List<Topology> topologies = Topologies.FindAll(x => x.ID == id);
832
833
                // Main
834
                List<Topology> mainTopologies = topologies.FindAll(x => x.Type == "M");
835
                foreach (Topology topology in mainTopologies)
836
                    topology.Index = mainTopologies.IndexOf(topology).ToString();
837
838
                // Branch
839
                List<Topology> branchToplogies = topologies.FindAll(x => x.Type == "B");
840
                foreach (Topology topology in branchToplogies)
841
                    topology.Index = (branchToplogies.IndexOf(topology) + 1).ToString();
842
            }
843
        }
844 5e4c2ad1 LJIYEON
845 7881ec8f gaqhf
        private void SetPSNBypass()
846
        {
847
            foreach (PSNItem PSNItem in PSNItems)
848
                PSNItem.IsBypass = IsBypass(PSNItem);
849
        }
850 5e4c2ad1 LJIYEON
851 6b9e7a56 gaqhf
        private List<Topology> FindMainTopology(List<Topology> data)
852
        {
853 678760c6 gaqhf
            DataTable nominalDiameterDT = DB.SelectNominalDiameter();
854
            DataTable PMCDT = DB.SelectPSNPIPINGMATLCLASS();
855 a36541fb LJIYEON
            //2021.11.17 안쓰네 JY
856
            //DataTable fluidCodeDT = DB.SelectPSNFluidCode(); 
857 678760c6 gaqhf
858
            List<Topology> main = new List<Topology>();
859
            main.AddRange(data);
860 6b9e7a56 gaqhf
            //
861 678760c6 gaqhf
            main = GetNozzleTopology(data);
862
            if (main.Count == 1)
863
                return main;
864
            else
865
            {
866
                if (main.Count > 0)
867
                    main = GetPMCTopology(main);
868
                else
869
                    main = GetPMCTopology(data);
870
871
                if (main.Count == 1)
872
                    return main;
873
                else
874
                {
875
                    if (main.Count > 0)
876
                        main = GetDiaTopology(main);
877
                    else
878
                        main = GetDiaTopology(data);
879
880
881
                    if (main.Count == 1)
882
                        return main;
883
                    else
884
                    {
885
                        if (main.Count > 0)
886
                            main = GetItemTopology(main);
887
                        else
888
                            main = GetItemTopology(data);
889
                    }
890
                }
891
            }
892
893
            List<Topology> GetNozzleTopology(List<Topology> topologies)
894
            {
895
                return topologies.FindAll(x => x.Items.Find(y => y.SubItemType == SubItemType.Nozzle) != null);
896
            }
897 6b9e7a56 gaqhf
898 678760c6 gaqhf
            List<Topology> GetPMCTopology(List<Topology> topologies)
899
            {
900
                List<Topology> result = new List<Topology>();
901
                foreach (DataRow row in PMCDT.Rows)
902
                {
903
                    string value = row["CODE"].ToString();
904
                    foreach (Topology topology in topologies)
905
                    {
906
                        foreach (Item item in topology.Items)
907
                        {
908
                            if (item.LineNumber == null)
909
                                continue;
910 0f07fa34 gaqhf
                            Attribute attribute = item.LineNumber.Attributes.Find(x => x.Name == "PipingMaterialsClass");
911
                            if (attribute != null && value == attribute.Value)
912 678760c6 gaqhf
                            {
913
                                result.Add(topology);
914
                                break;
915
                            }
916
                        }
917
                    }
918
919
                    if (result.Count > 0)
920
                        break;
921
                }
922
923
                return result;
924
            }
925
926
            List<Topology> GetDiaTopology(List<Topology> topologies)
927
            {
928
                List<Topology> result = new List<Topology>();
929
                foreach (DataRow row in nominalDiameterDT.Rows)
930
                {
931
                    string inchValue = row["InchStr"].ToString();
932
                    string metricValue = row["MetricStr"].ToString();
933
                    foreach (Topology topology in topologies)
934
                    {
935
                        foreach (Item item in topology.Items)
936
                        {
937
                            if (item.LineNumber == null)
938
                                continue;
939 0f07fa34 gaqhf
                            Attribute attribute = item.LineNumber.Attributes.Find(x => x.Name == "NominalDiameter");
940
                            if (attribute != null && (inchValue == attribute.Value || metricValue == attribute.Value))
941 678760c6 gaqhf
                            {
942
                                result.Add(topology);
943
                                break;
944
                            }
945
                        }
946
                    }
947
948
                    if (result.Count > 0)
949
                        break;
950
                }
951
952
                return result;
953
            }
954
955
            List<Topology> GetItemTopology(List<Topology> topologies)
956
            {
957
                return new List<Topology>() { topologies.OrderByDescending(x => x.Items.Count).ToList().First() };
958
            }
959 6b9e7a56 gaqhf
960 678760c6 gaqhf
            return main;
961 6b9e7a56 gaqhf
        }
962
963
        private DataTable GetOPCInfo()
964
        {
965
            DataTable opc = DB.SelectOPCRelations();
966 ec1cc293 LJIYEON
            DataTable drawing = DB.AllDrawings();
967 6b9e7a56 gaqhf
968
            DataTable dt = new DataTable();
969
            dt.Columns.Add("FromDrawing", typeof(string));
970
            dt.Columns.Add("FromDrawingUID", typeof(string));
971
            dt.Columns.Add("FromOPCUID", typeof(string));
972
            dt.Columns.Add("ToDrawing", typeof(string));
973
            dt.Columns.Add("ToDrawingUID", typeof(string));
974
            dt.Columns.Add("ToOPCUID", typeof(string));
975
            foreach (DataRow row in opc.Rows)
976
            {
977
                string fromDrawingUID = row["From_Drawings_UID"] == null ? string.Empty : row["From_Drawings_UID"].ToString();
978 7106e181 LJIYEON
                string fromOPCUID = row["From_OPC_UID"] == null ? string.Empty : row["From_OPC_UID"].ToString();
979
                string toDrawingUID = row["To_Drawings_UID"] == null ? string.Empty : row["To_Drawings_UID"].ToString();
980 6b9e7a56 gaqhf
                string toOPCUID = row["To_OPC_UID"] == null ? string.Empty : row["To_OPC_UID"].ToString();
981
                if (!string.IsNullOrEmpty(toOPCUID))
982
                {
983
                    DataRow[] fromRows = drawing.Select(string.Format("UID = '{0}'", fromDrawingUID));
984
                    DataRow[] toRows = drawing.Select(string.Format("UID = '{0}'", toDrawingUID));
985
                    if (fromRows.Length.Equals(1) && toRows.Length.Equals(1))
986
                    {
987
                        string fromDrawingName = Path.GetFileNameWithoutExtension(fromRows.First()["NAME"].ToString());
988
                        string toDrawingName = Path.GetFileNameWithoutExtension(toRows.First()["NAME"].ToString());
989
990
                        DataRow newRow = dt.NewRow();
991
                        newRow["FromDrawing"] = fromDrawingName;
992
                        newRow["FromDrawingUID"] = fromDrawingUID;
993
                        newRow["FromOPCUID"] = fromOPCUID;
994
                        newRow["ToDrawing"] = toDrawingName;
995
                        newRow["ToDrawingUID"] = toDrawingUID;
996
                        newRow["ToOPCUID"] = toOPCUID;
997
998
                        dt.Rows.Add(newRow);
999
                    }
1000
                }
1001
            }
1002
1003
            return dt;
1004
        }
1005 5e4c2ad1 LJIYEON
1006 6b9e7a56 gaqhf
        private DataTable GetTopologyRule()
1007
        {
1008
            DataTable dt = DB.SelectTopologyRule();
1009
1010
            return dt;
1011
        }
1012 5e4c2ad1 LJIYEON
1013 6b9e7a56 gaqhf
        private bool IsConnected(Item item1, Item item2)
1014
        {
1015
            if (item1.Relations.Find(x => x.UID.Equals(item2.UID)) != null &&
1016
                item2.Relations.Find(x => x.UID.Equals(item1.UID)) != null)
1017
                return true;
1018
            else
1019
                return false;
1020
        }
1021
1022
        private void SaveNozzleAndEquipment()
1023
        {
1024
            List<Item> nozzles = new List<Item>();
1025
            List<Equipment> equipments = new List<Equipment>();
1026
            foreach (Document document in Documents)
1027
            {
1028
                nozzles.AddRange(document.Items.FindAll(x => x.SubItemType == SubItemType.Nozzle));
1029
                equipments.AddRange(document.Equipments);
1030
            }
1031 7106e181 LJIYEON
1032 6b9e7a56 gaqhf
1033
            DataTable nozzleDT = new DataTable();
1034
            nozzleDT.Columns.Add("OID", typeof(string));
1035
            nozzleDT.Columns.Add("ITEMTAG", typeof(string));
1036
            nozzleDT.Columns.Add("XCOORDS", typeof(string));
1037
            nozzleDT.Columns.Add("YCOORDS", typeof(string));
1038
            nozzleDT.Columns.Add("Equipment_OID", typeof(string));
1039
            nozzleDT.Columns.Add("FLUID", typeof(string));
1040
            nozzleDT.Columns.Add("NPD", typeof(string));
1041 33cee849 LJIYEON
            nozzleDT.Columns.Add("PMC", typeof(string));
1042 6b9e7a56 gaqhf
            nozzleDT.Columns.Add("ROTATION", typeof(string));
1043
            nozzleDT.Columns.Add("FlowDirection", typeof(string));
1044
1045
            foreach (Item item in nozzles)
1046
            {
1047
                DataRow row = nozzleDT.NewRow();
1048
                row["OID"] = item.UID;
1049
1050
                Relation relation = item.Relations.Find(x => equipments.Find(y => y.UID == x.UID) != null);
1051
                if (relation != null)
1052
                {
1053
                    Equipment equipment = equipments.Find(x => x.UID == relation.UID);
1054
                    equipment.Nozzles.Add(item);
1055 a36541fb LJIYEON
                    row["ITEMTAG"] = string.Format("N{0}", string.Format("{0:D3}", equipment.Nozzles.Count + 100));
1056 7106e181 LJIYEON
                    row["Equipment_OID"] = equipment.UID;
1057 4c76a67a gaqhf
                    item.Equipment = equipment;
1058 6b9e7a56 gaqhf
                }
1059 8f24b438 gaqhf
                row["XCOORDS"] = (item.POINT[0] / DrawingWidth).ToString();
1060
                row["YCOORDS"] = (item.POINT[1] / DrawingHeight).ToString();
1061 6b9e7a56 gaqhf
                Attribute fluidAttr = item.LineNumber.Attributes.Find(x => x.Name == "FluidCode");
1062
                row["FLUID"] = fluidAttr != null ? fluidAttr.Value : string.Empty;
1063
                Attribute npdAttr = item.LineNumber.Attributes.Find(x => x.Name == "NominalDiameter");
1064
                row["NPD"] = npdAttr != null ? npdAttr.Value : string.Empty;
1065 33cee849 LJIYEON
                Attribute pmcAttr = item.LineNumber.Attributes.Find(x => x.Name == "PipingMaterialsClass");
1066
                row["PMC"] = pmcAttr != null ? pmcAttr.Value : string.Empty;
1067 f25b787a gaqhf
1068
                double angle = Math.PI * 2 - Convert.ToDouble(item.ANGLE);
1069
                if (angle >= Math.PI * 2)
1070
                    angle = angle - Math.PI * 2;
1071
                row["ROTATION"] = angle.ToString();
1072 6b9e7a56 gaqhf
1073
                if (item.Topology.Items.First().Equals(item))
1074
                    row["FlowDirection"] = "Outlet";
1075
                else if (item.Topology.Items.Last().Equals(item))
1076
                    row["FlowDirection"] = "Inlet";
1077
                else
1078
                    row["FlowDirection"] = string.Empty;
1079
1080
                nozzleDT.Rows.Add(row);
1081
            }
1082
1083
            DataTable equipDT = new DataTable();
1084
            equipDT.Columns.Add("OID", typeof(string));
1085
            equipDT.Columns.Add("ITEMTAG", typeof(string));
1086
            equipDT.Columns.Add("XCOORDS", typeof(string));
1087
            equipDT.Columns.Add("YCOORDS", typeof(string));
1088
1089
            foreach (Equipment equipment in equipments)
1090
            {
1091
                DataRow row = equipDT.NewRow();
1092
                row["OID"] = equipment.UID;
1093 c6503eaa gaqhf
                if (!string.IsNullOrEmpty(EquipTagNoAttributeName))
1094
                {
1095
                    Attribute attribute = equipment.Attributes.Find(x => x.Name == EquipTagNoAttributeName);
1096
                    if (attribute != null)
1097
                        equipment.ItemTag = attribute.Value;
1098
                }
1099
                else
1100
                    equipment.ItemTag = equipment.Name;
1101 6b9e7a56 gaqhf
1102 c6503eaa gaqhf
                row["ITEMTAG"] = equipment.ItemTag;
1103 6b9e7a56 gaqhf
                List<double> xList = equipment.POINT.Select(x => x[0]).ToList();
1104 8f24b438 gaqhf
                row["XCOORDS"] = (xList.Sum() / (double)xList.Count) / DrawingWidth;
1105 6b9e7a56 gaqhf
1106
                List<double> yList = equipment.POINT.Select(x => x[1]).ToList();
1107 8f24b438 gaqhf
                row["YCOORDS"] = (yList.Sum() / (double)yList.Count) / DrawingHeight;
1108 6b9e7a56 gaqhf
1109
                equipDT.Rows.Add(row);
1110
            }
1111
1112
            Equipment = equipDT;
1113
            Nozzle = nozzleDT;
1114
        }
1115 5e4c2ad1 LJIYEON
1116 6b9e7a56 gaqhf
        private void SavePSNData()
1117
        {
1118 2c46461b LJIYEON
            try
1119 36a45f13 gaqhf
            {
1120 2c46461b LJIYEON
                DataTable pathItemsDT = new DataTable();
1121
                pathItemsDT.Columns.Add("OID", typeof(string));
1122
                pathItemsDT.Columns.Add("SequenceData_OID", typeof(string));
1123
                pathItemsDT.Columns.Add("TopologySet_OID", typeof(string));
1124
                pathItemsDT.Columns.Add("BranchTopologySet_OID", typeof(string));
1125
                pathItemsDT.Columns.Add("PipeLine_OID", typeof(string));
1126
                pathItemsDT.Columns.Add("ITEMNAME", typeof(string));
1127
                pathItemsDT.Columns.Add("ITEMTAG", typeof(string));
1128 7106e181 LJIYEON
                pathItemsDT.Columns.Add("DESCRIPTION", typeof(string));
1129 2c46461b LJIYEON
                pathItemsDT.Columns.Add("Class", typeof(string));
1130
                pathItemsDT.Columns.Add("SubClass", typeof(string));
1131
                pathItemsDT.Columns.Add("TYPE", typeof(string));
1132
                pathItemsDT.Columns.Add("PIDNAME", typeof(string));
1133 a36541fb LJIYEON
                pathItemsDT.Columns.Add("Equipment_OID", typeof(string));
1134 2c46461b LJIYEON
                pathItemsDT.Columns.Add("NPD", typeof(string));
1135 811d7949 LJIYEON
                pathItemsDT.Columns.Add("GROUPTAG", typeof(string));
1136 2c46461b LJIYEON
                pathItemsDT.Columns.Add("PipeSystemNetwork_OID", typeof(string));
1137
                pathItemsDT.Columns.Add("ViewPipeSystemNetwork_OID", typeof(string));
1138
                pathItemsDT.Columns.Add("PipeRun_OID", typeof(string));
1139 bf9e8432 이지연
                pathItemsDT.Columns.Add("EqpGroupTag", typeof(string));
1140
                pathItemsDT.Columns.Add("MainLineTag", typeof(string));
1141
                pathItemsDT.Columns.Add("EGTConnectedPoint", typeof(string));
1142
                pathItemsDT.Columns.Add("EGFlowDirection", typeof(string));
1143 2c46461b LJIYEON
1144
                DataTable sequenceDataDT = new DataTable();
1145
                sequenceDataDT.Columns.Add("OID", typeof(string));
1146
                sequenceDataDT.Columns.Add("SERIALNUMBER", typeof(string));
1147
                sequenceDataDT.Columns.Add("PathItem_OID", typeof(string));
1148
                sequenceDataDT.Columns.Add("TopologySet_OID_Key", typeof(string));
1149
1150
                DataTable pipeSystemNetworkDT = new DataTable();
1151
                pipeSystemNetworkDT.Columns.Add("OID", typeof(string));
1152
                pipeSystemNetworkDT.Columns.Add("Type", typeof(string));
1153
                pipeSystemNetworkDT.Columns.Add("OrderNumber", typeof(string));
1154
                pipeSystemNetworkDT.Columns.Add("Pipeline_OID", typeof(string));
1155
                pipeSystemNetworkDT.Columns.Add("FROM_DATA", typeof(string));
1156
                pipeSystemNetworkDT.Columns.Add("TO_DATA", typeof(string));
1157
                pipeSystemNetworkDT.Columns.Add("TopologySet_OID_Key", typeof(string));
1158
                pipeSystemNetworkDT.Columns.Add("PSNRevisionNumber", typeof(string));
1159
                pipeSystemNetworkDT.Columns.Add("PBS", typeof(string));
1160 72775f2e LJIYEON
                pipeSystemNetworkDT.Columns.Add("Drawings", typeof(string));
1161
                pipeSystemNetworkDT.Columns.Add("IsValid", typeof(string));
1162 2c46461b LJIYEON
                pipeSystemNetworkDT.Columns.Add("Status", typeof(string));
1163 ddc1c369 LJIYEON
                pipeSystemNetworkDT.Columns.Add("IncludingVirtualData", typeof(string));
1164
                pipeSystemNetworkDT.Columns.Add("PSNAccuracy", typeof(string));
1165 08b33e44 gaqhf
                pipeSystemNetworkDT.Columns.Add("Pocket", typeof(string));
1166 2c46461b LJIYEON
1167
                DataTable topologySetDT = new DataTable();
1168
                topologySetDT.Columns.Add("OID", typeof(string));
1169
                topologySetDT.Columns.Add("Type", typeof(string));
1170
                topologySetDT.Columns.Add("SubType", typeof(string));
1171
                topologySetDT.Columns.Add("HeadItemTag", typeof(string));
1172
                topologySetDT.Columns.Add("TailItemTag", typeof(string));
1173 72775f2e LJIYEON
                topologySetDT.Columns.Add("HeadItemSPID", typeof(string));
1174
                topologySetDT.Columns.Add("TailItemSPID", typeof(string));
1175 2c46461b LJIYEON
1176 f9f2787b LJIYEON
                DataTable pipelineDT = new DataTable();
1177
                pipelineDT.Columns.Add("OID", typeof(string));
1178
                pipelineDT.Columns.Add("PipeSystem_OID", typeof(string));
1179
                pipelineDT.Columns.Add("FLUID", typeof(string));
1180
                pipelineDT.Columns.Add("PMC", typeof(string));
1181
                pipelineDT.Columns.Add("SEQNUMBER", typeof(string));
1182
                pipelineDT.Columns.Add("INSULATION", typeof(string));
1183
                pipelineDT.Columns.Add("FROM_DATA", typeof(string));
1184
                pipelineDT.Columns.Add("TO_DATA", typeof(string));
1185
                pipelineDT.Columns.Add("Unit", typeof(string));
1186
1187 531fb158 LJIYEON
                DataTable pipesystemDT = new DataTable();
1188
                pipesystemDT.Columns.Add("OID", typeof(string));
1189
                pipesystemDT.Columns.Add("DESCRIPTION", typeof(string));
1190
                pipesystemDT.Columns.Add("FLUID", typeof(string));
1191
                pipesystemDT.Columns.Add("PMC", typeof(string));
1192
                pipesystemDT.Columns.Add("PipeLineQty", typeof(string));
1193
                pipesystemDT.Columns.Add("GroundLevel", typeof(string));
1194
1195 879ce10b LJIYEON
                // Set Vent/Drain Info
1196 2c46461b LJIYEON
                List<VentDrainInfo> VentDrainInfos = new List<VentDrainInfo>();
1197
                DataTable dt = DB.SelectVentDrainSetting();
1198
                foreach (DataRow row in dt.Rows)
1199 36a45f13 gaqhf
                {
1200 2c46461b LJIYEON
                    string groupID = row["GROUP_ID"].ToString();
1201
                    string desc = row["DESCRIPTION"].ToString();
1202
                    int index = Convert.ToInt32(row["INDEX"]);
1203
                    string name = row["NAME"].ToString();
1204 36a45f13 gaqhf
1205 2c46461b LJIYEON
                    VentDrainInfo ventDrainInfo = VentDrainInfos.Find(x => x.UID.Equals(groupID));
1206
                    if (ventDrainInfo == null)
1207 36a45f13 gaqhf
                    {
1208 2c46461b LJIYEON
                        ventDrainInfo = new VentDrainInfo(groupID);
1209
                        ventDrainInfo.Description = desc;
1210
                        VentDrainInfos.Add(ventDrainInfo);
1211 36a45f13 gaqhf
                    }
1212
1213 2c46461b LJIYEON
                    ventDrainInfo.VentDrainItems.Add(new VentDrainItem()
1214
                    {
1215
                        Index = index,
1216
                        Name = name
1217
                    });
1218
                }
1219 51974d2b LJIYEON
                foreach (VentDrainInfo ventDrainInfo in VentDrainInfos)
1220
                    ventDrainInfo.VentDrainItems = ventDrainInfo.VentDrainItems.OrderBy(x => x.Index).ToList();
1221 2c46461b LJIYEON
1222 879ce10b LJIYEON
                #region Keyword Info
1223 eb44d82c LJIYEON
                KeywordInfo KeywordInfos = new KeywordInfo();
1224 879ce10b LJIYEON
                DataTable dtKeyword = DB.SelectKeywordsSetting();
1225
                foreach (DataRow row in dtKeyword.Rows)
1226
                {
1227
                    int index = Convert.ToInt32(row["INDEX"]);
1228
                    string name = row["NAME"].ToString();
1229
                    string keyword = row["KEYWORD"].ToString();
1230
1231 eb44d82c LJIYEON
                    //KeywordInfo keywordInfo = new KeywordInfo();   
1232
                    KeywordInfos.KeywordItems.Add(new KeywordItem()
1233 879ce10b LJIYEON
                    {
1234
                        Index = index,
1235
                        Name = name,
1236
                        Keyword = keyword
1237
                    });
1238 811d7949 LJIYEON
                }
1239
                #endregion
1240
1241
                #region ValveGrouping Info
1242
                ValveGroupInfo ValveGrouping = new ValveGroupInfo();
1243
                DataTable dtValveGroupung = DB.SelectValveGroupItemsSetting();
1244
                foreach (DataRow row in dtValveGroupung.Rows)
1245
                {
1246
                    ValveGrouping.ValveGroupItems.Add(new ValveGroupItem()
1247
                    {
1248
                        OID = row["OID"].ToString(),
1249
                        GroupType = row["GroupType"].ToString(),
1250
                        TagIdentifier = row["TagIdentifier"].ToString(),
1251
                        AttributeName = row["AttributeName"].ToString(),
1252
                        SppidSymbolName = row["SppidSymbolName"].ToString()
1253
                    });
1254
                }
1255 879ce10b LJIYEON
                #endregion
1256
1257 08b33e44 gaqhf
                #region EquipmentNoPocket Info
1258
                EquipmentNoPocketInfo EquipmentNoPocket = new EquipmentNoPocketInfo();
1259
                DataTable dtEquipmentNoPocket = DB.SelectEquipmentNoPocketSetting();
1260
                foreach (DataRow row in dtEquipmentNoPocket.Rows)
1261
                {
1262
                    EquipmentNoPocket.EquipmentNoPocketItem.Add(new EquipmentNoPocketItem()
1263
                    {
1264
                        Index = Convert.ToInt32(row["INDEX"]),
1265
                        Type = row["TYPE"].ToString(),
1266
                        Name = row["NAME"].ToString()
1267
                    });
1268
                }
1269
                #endregion
1270
1271 2c46461b LJIYEON
                // key = 미입력 branch
1272
                Dictionary<Item, Item> startBranchDic = new Dictionary<Item, Item>();
1273
                Dictionary<Item, Item> endBranchDic = new Dictionary<Item, Item>();
1274 531fb158 LJIYEON
                DataTable PSNFluidDT = DB.SelectPSNFluidCode();
1275
                DataTable PSNPMCDT = DB.SelectPSNPIPINGMATLCLASS();
1276 2c46461b LJIYEON
                foreach (PSNItem PSNItem in PSNItems)
1277
                {
1278 3210f690 LJIYEON
                    try
1279 36a45f13 gaqhf
                    {
1280 3210f690 LJIYEON
                        int psnOrder = 0;
1281
                        int index = 0;
1282
                        bool bPSNStart = true;
1283
                        string sPSNData = string.Empty;
1284
                        bool bVentDrain = false;
1285 7106e181 LJIYEON
1286 51974d2b LJIYEON
                        List<Group> Groups = PSNItem.Groups;
1287 811d7949 LJIYEON
                        Dictionary<string, List<Item>> keyValuePairs = new Dictionary<string, List<Item>>();
1288 7106e181 LJIYEON
                        List<Item> valveGroupingItem = new List<Item>();
1289
1290 3210f690 LJIYEON
                        //VentDrain 검사
1291
                        if (PSNItem.Groups.Count.Equals(1))
1292 36a45f13 gaqhf
                        {
1293 7106e181 LJIYEON
                            List<VentDrainInfo> endInfos = new List<VentDrainInfo>();
1294
                            for (int g = 0; g < Groups.Count; g++)
1295 2c46461b LJIYEON
                            {
1296 51974d2b LJIYEON
                                Group group = Groups[g];
1297
                                for (int i = 0; i < group.Items.Count; i++)
1298 2c46461b LJIYEON
                                {
1299 51974d2b LJIYEON
                                    Item item = group.Items[i];
1300 3210f690 LJIYEON
                                    foreach (VentDrainInfo ventDrainInfo in VentDrainInfos)
1301 27d06aa8 LJIYEON
                                    {
1302 51974d2b LJIYEON
                                        if (endInfos.Contains(ventDrainInfo))
1303 3210f690 LJIYEON
                                            continue;
1304 51974d2b LJIYEON
1305 3210f690 LJIYEON
                                        if (!ventDrainInfo.VentDrainItems[i].Name.Equals(item.Name))
1306
                                        {
1307
                                            endInfos.Add(ventDrainInfo);
1308
                                            continue;
1309
                                        }
1310 6b9e7a56 gaqhf
1311 51974d2b LJIYEON
                                        if (ventDrainInfo.VentDrainItems.Count.Equals(i + 1))
1312 3210f690 LJIYEON
                                        {
1313
                                            bVentDrain = true;
1314 51974d2b LJIYEON
                                            break;
1315 3210f690 LJIYEON
                                        }
1316 27d06aa8 LJIYEON
                                    }
1317 51974d2b LJIYEON
1318
                                    if (bVentDrain || endInfos.Count.Equals(VentDrainInfos.Count))
1319
                                        break;
1320
                                }
1321
1322
                                if (!bVentDrain)
1323
                                {
1324
                                    endInfos = new List<VentDrainInfo>();
1325
                                    for (int i = 0; i < group.Items.Count; i++)
1326
                                    {
1327
                                        Item item = group.Items[group.Items.Count - i - 1];
1328
                                        foreach (VentDrainInfo ventDrainInfo in VentDrainInfos)
1329
                                        {
1330
                                            if (endInfos.Contains(ventDrainInfo))
1331
                                                continue;
1332
1333
                                            if (!ventDrainInfo.VentDrainItems[i].Name.Equals(item.Name))
1334
                                            {
1335
                                                endInfos.Add(ventDrainInfo);
1336
                                                continue;
1337
                                            }
1338
1339
                                            if (ventDrainInfo.VentDrainItems.Count.Equals(i + 1))
1340
                                            {
1341
                                                bVentDrain = true;
1342
                                                break;
1343
                                            }
1344
                                        }
1345
1346
                                        if (bVentDrain || endInfos.Count.Equals(VentDrainInfos.Count))
1347
                                            break;
1348
                                    }
1349 27d06aa8 LJIYEON
                                }
1350 3210f690 LJIYEON
                            }
1351
                        }
1352 7106e181 LJIYEON
1353 a5616391 LJIYEON
                        try
1354 7106e181 LJIYEON
                        {
1355 a5616391 LJIYEON
                            foreach (Group group in PSNItem.Groups)
1356 7106e181 LJIYEON
                            {
1357 a5616391 LJIYEON
                                foreach (Item item in group.Items)
1358 7106e181 LJIYEON
                                {
1359 811d7949 LJIYEON
                                    string VgTag = string.Empty;
1360 7106e181 LJIYEON
                                    if (ValveGrouping.ValveGroupItems.Where(x => x.SppidSymbolName == item.Name).Count() > 0)
1361 811d7949 LJIYEON
                                    {
1362
                                        ValveGroupItem valveitem = ValveGrouping.ValveGroupItems.Where(x => x.SppidSymbolName == item.Name).First();
1363 7106e181 LJIYEON
                                        string value = string.Empty;
1364
1365
                                        if (valveitem.GroupType == "Scope Break" || valveitem.AttributeName == "NoSelection")
1366 54b6df95 LJIYEON
                                            value = "NoSelection";
1367
                                        else
1368
                                            value = item.Attributes.Find(x => x.Name == valveitem.AttributeName).Value;
1369
1370
                                        if (valveitem.GroupType == "Scope Break")
1371
                                            VgTag = "Scope Break";
1372
                                        else
1373
                                            VgTag = valveitem.SppidSymbolName + "\\" + value;
1374 7106e181 LJIYEON
1375 811d7949 LJIYEON
                                    }
1376
1377 a5616391 LJIYEON
                                    string PathitemUID = string.Empty;
1378
                                    if (item.BranchItems.Count == 0)
1379 a36541fb LJIYEON
                                    {
1380 a5616391 LJIYEON
                                        PathitemUID = item.UID;
1381 811d7949 LJIYEON
                                        CreatePathItemsDataRow(PathitemUID, item.ID2DBType, VgTag);
1382 a5616391 LJIYEON
                                        CreateSequenceDataDataRow(PathitemUID);
1383
                                        index++;
1384
                                    }
1385
                                    else
1386
                                    {
1387
                                        PathitemUID = item.UID + "_L1";
1388 811d7949 LJIYEON
                                        CreatePathItemsDataRow(PathitemUID, item.ID2DBType, VgTag);
1389 a5616391 LJIYEON
                                        CreateSequenceDataDataRow(PathitemUID);
1390
                                        index++;
1391
                                        for (int i = 0; i < item.BranchItems.Count; i++)
1392 3210f690 LJIYEON
                                        {
1393 811d7949 LJIYEON
                                            CreatePathItemsDataRow(string.Format(item.UID + "_B{0}", i + 1), "Branch", string.Empty, item.BranchItems[i].Topology.FullName, item.BranchItems[i]);
1394 a5616391 LJIYEON
                                            CreateSequenceDataDataRow(string.Format(item.UID + "_B{0}", i + 1));
1395 3210f690 LJIYEON
                                            index++;
1396 7106e181 LJIYEON
1397 a5616391 LJIYEON
                                            CreatePathItemsDataRow(string.Format(item.UID + "_L{0}", i + 2), item.ID2DBType);
1398
                                            CreateSequenceDataDataRow(string.Format(item.UID + "_L{0}", i + 2));
1399
                                            index++;
1400 a36541fb LJIYEON
1401 a5616391 LJIYEON
                                            if (item.BranchItems[i].Relations[0].Item != null && item.BranchItems[i].Relations[0].Item == item)
1402
                                                startBranchDic.Add(item.BranchItems[i], item);
1403
                                            else if (item.BranchItems[i].Relations[1].Item != null && item.BranchItems[i].Relations[1].Item == item)
1404
                                                endBranchDic.Add(item.BranchItems[i], item);
1405
                                        }
1406
                                    }
1407 7106e181 LJIYEON
1408 a5616391 LJIYEON
                                    if (bPSNStart)
1409 7106e181 LJIYEON
                                    {
1410 a5616391 LJIYEON
                                        CreatePipeSystemNetworkDataRow();
1411 7106e181 LJIYEON
                                        sPSNData = item.TopologyData;
1412 a5616391 LJIYEON
                                        psnOrder++;
1413
                                        bPSNStart = false;
1414
                                    }
1415
                                    else
1416
                                    {
1417
                                        if (item.TopologyData != sPSNData)
1418 3210f690 LJIYEON
                                        {
1419
                                            CreatePipeSystemNetworkDataRow();
1420
                                            sPSNData = item.TopologyData;
1421
                                            psnOrder++;
1422
                                        }
1423 a5616391 LJIYEON
                                    }
1424 7106e181 LJIYEON
1425 811d7949 LJIYEON
                                    void CreatePathItemsDataRow(string itemOID, string itemType, string GROUPTAG = "", string branchTopologyName = "", Item branchItem = null)
1426 a5616391 LJIYEON
                                    {
1427
                                        DataRow newRow = pathItemsDT.NewRow();
1428
1429
                                        if (itemType == "Nozzles")
1430 3210f690 LJIYEON
                                        {
1431 a5616391 LJIYEON
                                            newRow["Equipment_OID"] = item.Equipment.UID;
1432 3210f690 LJIYEON
                                        }
1433 7106e181 LJIYEON
1434 a5616391 LJIYEON
                                        newRow["OID"] = itemOID;
1435
                                        newRow["SequenceData_OID"] = string.Format(item.Topology.FullName + "_{0}", index);
1436
                                        newRow["TopologySet_OID"] = item.Topology.FullName;
1437
                                        newRow["BranchTopologySet_OID"] = branchTopologyName;
1438
                                        newRow["PipeLine_OID"] = item.PSNPipeLineID;
1439
                                        newRow["ITEMNAME"] = GetItemName(item, itemOID);
1440
                                        newRow["ITEMTAG"] = GetItemTag(item);
1441
                                        newRow["Class"] = GetClass(item, itemOID);
1442 7106e181 LJIYEON
                                        string subClass = GetSubClass(item, itemOID);
1443 a5616391 LJIYEON
                                        newRow["SubClass"] = subClass;
1444 7106e181 LJIYEON
1445 a5616391 LJIYEON
                                        if (item.ItemType == ItemType.Symbol)
1446
                                            newRow["TYPE"] = item.ID2DBName;
1447
                                        else if (item.ItemType == ItemType.Line)
1448
                                            newRow["TYPE"] = item.ID2DBType;
1449
                                        newRow["PIDNAME"] = group.Document.DrawingName;
1450
1451
                                        // NPD
1452
                                        if (item.LineNumber != null)
1453
                                        {
1454
                                            Attribute attribute = item.LineNumber.Attributes.Find(x => x.Name == "NominalDiameter");
1455
                                            if (attribute != null)
1456
                                                newRow["NPD"] = attribute.Value;
1457
                                        }
1458
                                        else
1459
                                            newRow["NPD"] = null;
1460 7881ec8f gaqhf
1461 811d7949 LJIYEON
                                        newRow["GROUPTAG"] = GROUPTAG;
1462 a5616391 LJIYEON
                                        newRow["PipeSystemNetwork_OID"] = PSNItem.PSN_OID();
1463
                                        if (branchItem == null)
1464
                                            newRow["ViewPipeSystemNetwork_OID"] = PSNItem.PSN_OID();
1465
                                        else
1466
                                            newRow["ViewPipeSystemNetwork_OID"] = branchItem.PSNItem.PSN_OID();
1467 27d06aa8 LJIYEON
1468 a5616391 LJIYEON
                                        newRow["PipeRun_OID"] = item.LineNumber != null ? item.LineNumber.Name : string.Empty;
1469 6b9e7a56 gaqhf
1470 a5616391 LJIYEON
                                        pathItemsDT.Rows.Add(newRow);
1471 7106e181 LJIYEON
                                    }
1472 a5616391 LJIYEON
                                    void CreateSequenceDataDataRow(string itemOID)
1473
                                    {
1474
                                        DataRow newRow = sequenceDataDT.NewRow();
1475
                                        newRow["OID"] = string.Format(item.Topology.FullName + "_{0}", index);
1476
                                        newRow["SERIALNUMBER"] = string.Format("{0}", index);
1477
                                        newRow["PathItem_OID"] = itemOID;
1478
                                        newRow["TopologySet_OID_Key"] = item.Topology.FullName;
1479 839708c6 LJIYEON
1480 a5616391 LJIYEON
                                        sequenceDataDT.Rows.Add(newRow);
1481
                                    }
1482
                                    void CreatePipeSystemNetworkDataRow()
1483 7106e181 LJIYEON
                                    {
1484 a5616391 LJIYEON
                                        LineNumber lineNumber = item.Document.LineNumbers.Find(x => x.UID == item.Owner);
1485 08b33e44 gaqhf
                                        string FluidCode = string.Empty;
1486 a5616391 LJIYEON
                                        if (lineNumber != null)
1487 3210f690 LJIYEON
                                        {
1488 a5616391 LJIYEON
                                            List<Attribute> att = lineNumber.Attributes;
1489
                                            if (att != null)
1490 3210f690 LJIYEON
                                            {
1491 a5616391 LJIYEON
                                                List<string> oid = new List<string>();
1492 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;
1493 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;
1494
                                                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;
1495
                                                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;
1496
                                                //InsulationPurpose
1497
                                                if (!string.IsNullOrEmpty(FluidCode)) oid.Add(FluidCode);
1498
                                                if (!string.IsNullOrEmpty(PMC)) oid.Add(PMC);
1499
1500
                                                string PipeSystem_OID = string.Join("-", oid);
1501
1502
                                                if (!string.IsNullOrEmpty(SEQNUMBER)) oid.Add(SEQNUMBER);
1503
                                                if (!string.IsNullOrEmpty(INSULATION)) oid.Add(INSULATION);
1504
1505
                                                string OID = string.Join("-", oid);
1506 531fb158 LJIYEON
                                                string FluidCodeGL = string.Empty;
1507
                                                string PMCGL = string.Empty;
1508 7106e181 LJIYEON
1509 3210f690 LJIYEON
1510 a5616391 LJIYEON
                                                if (pipelineDT.Select(string.Format("OID = '{0}'", OID)).Count() == 0)
1511
                                                {
1512
                                                    DataRow newPipelineRow = pipelineDT.NewRow();
1513
                                                    newPipelineRow["OID"] = OID;
1514
                                                    newPipelineRow["PipeSystem_OID"] = PipeSystem_OID;
1515
                                                    newPipelineRow["FLUID"] = FluidCode;
1516
                                                    newPipelineRow["PMC"] = PMC;
1517
                                                    newPipelineRow["SEQNUMBER"] = SEQNUMBER;
1518
                                                    newPipelineRow["INSULATION"] = INSULATION;
1519
                                                    newPipelineRow["FROM_DATA"] = string.Empty;
1520
                                                    newPipelineRow["TO_DATA"] = string.Empty;
1521
                                                    newPipelineRow["Unit"] = PSNItem.GetPBSData();
1522 7106e181 LJIYEON
                                                    pipelineDT.Rows.Add(newPipelineRow);
1523 531fb158 LJIYEON
                                                }
1524
1525
                                                if (pipesystemDT.Select(string.Format("OID = '{0}'", PipeSystem_OID)).Count() == 0)
1526
                                                {
1527 54b6df95 LJIYEON
                                                    DataRow newPipesystemRow = pipesystemDT.NewRow();
1528
                                                    newPipesystemRow["OID"] = PipeSystem_OID;
1529
                                                    newPipesystemRow["DESCRIPTION"] = string.Empty;
1530
                                                    newPipesystemRow["FLUID"] = FluidCode;
1531
                                                    newPipesystemRow["PMC"] = PMC;
1532
                                                    newPipesystemRow["PipeLineQty"] = string.Empty;
1533
                                                    string GroundLevel = string.Empty;
1534
                                                    if (!string.IsNullOrEmpty(FluidCode) && !string.IsNullOrEmpty(PMC))
1535
                                                    {
1536
                                                        FluidCodeGL = PSNFluidDT.Select(string.Format("Code = '{0}'", FluidCode)).FirstOrDefault().Field<string>("GroundLevel");
1537
                                                        PMCGL = PSNPMCDT.Select(string.Format("Code= '{0}'", PMC)).FirstOrDefault().Field<string>("GroundLevel");
1538
                                                        if (FluidCodeGL == "AG" && PMCGL == "AG")
1539
                                                            GroundLevel = "AG";
1540
                                                        else if (FluidCodeGL == "UG" && PMCGL == "UG")
1541
                                                            GroundLevel = "UG";
1542
                                                        else
1543
                                                            GroundLevel = "AG_UG";
1544
                                                    }
1545
                                                    newPipesystemRow["GroundLevel"] = GroundLevel;
1546
1547
                                                    pipesystemDT.Rows.Add(newPipesystemRow);
1548 3210f690 LJIYEON
                                                }
1549
                                            }
1550 a5616391 LJIYEON
                                        }
1551 3210f690 LJIYEON
1552 a5616391 LJIYEON
                                        DataRow newRow = pipeSystemNetworkDT.NewRow();
1553
                                        newRow["OID"] = PSNItem.PSN_OID();
1554 7106e181 LJIYEON
1555 a5616391 LJIYEON
                                        newRow["OrderNumber"] = psnOrder;
1556
                                        newRow["Pipeline_OID"] = item.PSNPipeLineID;
1557
                                        PSNItem.KeywordInfos = KeywordInfos;
1558
                                        PSNItem.Nozzle = Nozzle;
1559 7106e181 LJIYEON
1560 a5616391 LJIYEON
                                        string FromType = string.Empty;
1561
                                        Item From_item = new Item();
1562 7106e181 LJIYEON
1563 a5616391 LJIYEON
                                        string FROM_DATA = PSNItem.GetFromData(ref FromType, ref From_item);
1564 51974d2b LJIYEON
                                        string status = string.Empty;
1565
                                        if (psnOrder == 0)
1566
                                        {
1567
                                            status = PSNItem.Status;
1568
                                        }
1569
1570 a5616391 LJIYEON
                                        if (PSNItem.IsKeyword)
1571
                                        {
1572 e552da48 LJIYEON
                                            PSNItem.StartType = PSNType.Equipment;
1573 a5616391 LJIYEON
                                        }
1574
                                        string ToType = string.Empty;
1575
                                        Item To_item = new Item();
1576
                                        string TO_DATA = PSNItem.GetToData(ref ToType, ref To_item);
1577
                                        if (PSNItem.IsKeyword)
1578
                                        {
1579 e552da48 LJIYEON
                                            PSNItem.EndType = PSNType.Equipment;
1580 a5616391 LJIYEON
                                        }
1581 54b6df95 LJIYEON
1582 7106e181 LJIYEON
                                        //if (Groups.Count == psnOrder + 1 && !string.IsNullOrEmpty(PSNItem.Status))
1583
                                        //{
1584
                                        if (!string.IsNullOrEmpty(PSNItem.Status))
1585 51974d2b LJIYEON
                                            status += PSNItem.Status;
1586 7106e181 LJIYEON
                                        //}
1587 33cee849 LJIYEON
1588 e552da48 LJIYEON
                                        newRow["FROM_DATA"] = FROM_DATA;
1589 7106e181 LJIYEON
                                        newRow["TO_DATA"] = TO_DATA;
1590 a5616391 LJIYEON
                                        newRow["Type"] = PSNItem.GetPSNType();
1591 e552da48 LJIYEON
1592
                                        if (psnOrder > 0)
1593
                                        {
1594 7106e181 LJIYEON
                                            DataRow dr = pipeSystemNetworkDT.Select(string.Format("OID = '{0}' AND OrderNumber = {1}", PSNItem.PSN_OID(), psnOrder - 1)).FirstOrDefault();
1595
                                            if (!string.IsNullOrEmpty(PSNItem.Status))
1596
                                            {//status = !string.IsNullOrEmpty(status) ? status.Remove(0, 2) : string.Empty;
1597
                                                if (dr["Status"].ToString().Contains(PSNItem.Status))
1598
                                                    dr["Status"] = dr["Status"].ToString().Replace(PSNItem.Status, string.Empty);
1599
                                                else if (dr["Status"].ToString().Contains(PSNItem.Status.Remove(0, 2)))
1600
                                                    dr["Status"] = dr["Status"].ToString().Replace(PSNItem.Status.Remove(0, 2), string.Empty);
1601
1602
                                            }
1603
1604
                                            if (dr != null)
1605 e552da48 LJIYEON
                                            {
1606
                                                newRow["FROM_DATA"] = dr.Field<string>("FROM_DATA");
1607
                                                newRow["TO_DATA"] = dr.Field<string>("TO_DATA");
1608
                                                newRow["Type"] = dr.Field<string>("Type");
1609
                                            }
1610 7106e181 LJIYEON
                                        }
1611 eb44d82c LJIYEON
1612 48870200 LJIYEON
                                        status = !string.IsNullOrEmpty(status) ? status.Remove(0, 2) : string.Empty;
1613
                                        if (group.Items.Count == 1 && !string.IsNullOrEmpty(status))
1614
                                        {
1615
                                            MatchCollection matches = Regex.Matches(status, "Missing LineNumber_1");
1616
                                            int cnt = matches.Count;
1617
                                            if (cnt > 1)
1618
                                                status.Replace(", Missing LineNumber_1", string.Empty);
1619
                                        }
1620 a5616391 LJIYEON
                                        newRow["TopologySet_OID_Key"] = item.Topology.FullName;
1621
                                        newRow["PSNRevisionNumber"] = string.Format("V{0:D4}", Revision);
1622 5e4c2ad1 LJIYEON
1623 7106e181 LJIYEON
1624 a5616391 LJIYEON
                                        newRow["IsValid"] = PSNItem.IsValid;
1625 48870200 LJIYEON
                                        newRow["Status"] = status;
1626 a5616391 LJIYEON
                                        newRow["PBS"] = PSNItem.GetPBSData();
1627 7106e181 LJIYEON
1628 a5616391 LJIYEON
                                        List<string> drawingNames = new List<string>();
1629
                                        foreach (Group _group in PSNItem.Groups)
1630
                                        {
1631
                                            if (!drawingNames.Contains(_group.Document.DrawingName))
1632 3210f690 LJIYEON
                                            {
1633 a5616391 LJIYEON
                                                if (drawingNames.Count == 0)
1634
                                                    newRow["Drawings"] = _group.Document.DrawingName;
1635
                                                else
1636
                                                    newRow["Drawings"] = newRow["Drawings"] + ", " + _group.Document.DrawingName;
1637
                                                drawingNames.Add(_group.Document.DrawingName);
1638 3210f690 LJIYEON
                                            }
1639 27d06aa8 LJIYEON
                                        }
1640 419055fa LJIYEON
1641
                                        // VentDrain의 경우 제외 요청 (데이터를 아예 제거하였을 경우 후 가공에서 문제가 생김 마지막에 지우는것으로 변경)
1642
                                        if (bVentDrain)
1643
                                            newRow["IncludingVirtualData"] = "Vent_Drain";
1644
                                        else
1645
                                            newRow["IncludingVirtualData"] = "No";
1646
                                        //    return;
1647 a2973aa3 LJIYEON
                                        //newRow["IncludingVirtualData"] = "No";
1648 a5616391 LJIYEON
                                        newRow["PSNAccuracy"] = "100";
1649 08b33e44 gaqhf
1650
                                        string Pocket = "No";
1651
                                        string Condition = PSNFluidDT.Select(string.Format("Code = '{0}'", FluidCode)).FirstOrDefault().Field<string>("Condition");
1652
                                        if (Condition.Equals("Flare"))
1653
                                            Pocket = "Yes";
1654
1655 91c75c0b 이지연
                                        if (item.ID2DBType == "Nozzles" && PSNItem.StartType == PSNType.Equipment) 
1656 08b33e44 gaqhf
                                        {
1657
                                          //  string itemName = From_item.Name;
1658
                                            Equipment Equipment = From_item.Equipment;
1659 91c75c0b 이지연
                                      
1660
                                            EquipmentNoPocketItem nopocket = EquipmentNoPocket.EquipmentNoPocketItem.Where(x => x.Name == Equipment.Name && x.Type != "Pump").FirstOrDefault();
1661
                                          
1662
1663
                                            if (nopocket != null)
1664 08b33e44 gaqhf
                                            {
1665 91c75c0b 이지연
                                                DataRow bNozzle = null;
1666
                                                if (nopocket.Type.Equals("Vertical Vessel"))
1667
                                                {
1668
                                                    DataRow drNozzle = Nozzle.Select(string.Format("Equipment_OID = '{0}' AND OID = '{1}'", Equipment.UID, From_item.UID)).FirstOrDefault();
1669
                                                    if (drNozzle != null)
1670
                                                    {
1671
                                                        if (drNozzle.Field<string>("Rotation").Length >= 4 && drNozzle.Field<string>("Rotation").Substring(0, 4) == "4.71")
1672
                                                        {
1673
                                                            bNozzle = drNozzle;
1674
                                                        }
1675
1676
                                                        if (bNozzle == null)
1677
                                                        {
1678
                                                            DataRow[] nozzleRows = Nozzle.Select(string.Format("Equipment_OID = '{0}'", Equipment.UID));
1679
1680
                                                            if (drNozzle != null)
1681
                                                            {
1682
                                                                bNozzle = drNozzle;
1683
                                                                foreach (DataRow it in nozzleRows)
1684
                                                                {
1685
                                                                    if (Convert.ToDecimal(drNozzle.Field<string>("Ycoords")) > Convert.ToDecimal(it.Field<string>("Ycoords")))
1686
                                                                    {
1687
                                                                        bNozzle = null;
1688
                                                                        break;
1689
                                                                    }
1690
                                                                }
1691
                                                            }
1692
                                                        }
1693
                                                    }
1694
1695
                                                    if (bNozzle != null)
1696
                                                        Pocket = "Yes";
1697
                                                }
1698
                                                else
1699
                                                    Pocket = "Yes";
1700 08b33e44 gaqhf
                                            }
1701
                                        }
1702 91c75c0b 이지연
                                        
1703
                                        if (item.ID2DBType == "Nozzles" && PSNItem.EndType == PSNType.Equipment) //To는 전체
1704 08b33e44 gaqhf
                                        {
1705
                                           // string itemName = To_item.Name;
1706
                                            Equipment Equipment = To_item.Equipment;
1707
                                            EquipmentNoPocketItem nopocket = EquipmentNoPocket.EquipmentNoPocketItem.Where(x => x.Name == Equipment.Name).FirstOrDefault();
1708
                                            if (nopocket != null)
1709
                                            {
1710 91c75c0b 이지연
                                                DataRow bNozzle = null;
1711
                                                if (nopocket.Type.Equals("Vertical Vessel"))
1712
                                                {
1713
                                                    DataRow drNozzle = Nozzle.Select(string.Format("Equipment_OID = '{0}' AND OID = '{1}'", Equipment.UID, To_item.UID)).FirstOrDefault();
1714
                                                    if(drNozzle != null)
1715
                                                    {
1716
                                                        if (drNozzle.Field<string>("Rotation").Length >= 4 && drNozzle.Field<string>("Rotation").Substring(0, 4) == "4.71")
1717
                                                        {
1718
                                                            bNozzle = drNozzle;
1719
                                                        }
1720
1721
                                                        if (bNozzle == null)
1722
                                                        {
1723
                                                            DataRow[] nozzleRows = Nozzle.Select(string.Format("Equipment_OID = '{0}'", Equipment.UID));
1724
1725
                                                            if (drNozzle != null)
1726
                                                            {
1727
                                                                bNozzle = drNozzle;
1728
                                                                foreach (DataRow it in nozzleRows)
1729
                                                                {
1730
                                                                    if (Convert.ToDecimal(drNozzle.Field<string>("Ycoords")) > Convert.ToDecimal(it.Field<string>("Ycoords")))
1731
                                                                    {
1732
                                                                        bNozzle = null;
1733
                                                                        break;
1734
                                                                    }
1735
                                                                }
1736
                                                            }
1737
                                                        }
1738
                                                    }                                                   
1739
1740
                                                    if (bNozzle != null)
1741
                                                        Pocket = "Yes";
1742
                                                }
1743
                                                else
1744
                                                    Pocket = "Yes";
1745 08b33e44 gaqhf
                                            }
1746
                                        }
1747 91c75c0b 이지연
                                        
1748 08b33e44 gaqhf
                                        newRow["Pocket"] = Pocket;
1749
                                        
1750 a5616391 LJIYEON
                                        pipeSystemNetworkDT.Rows.Add(newRow);
1751 2c46461b LJIYEON
                                    }
1752 27d06aa8 LJIYEON
                                }
1753 7106e181 LJIYEON
1754 820e283f LJIYEON
                            }
1755 91c75c0b 이지연
                        
1756 7106e181 LJIYEON
1757 a5616391 LJIYEON
                        }
1758
                        catch (Exception ex)
1759
                        {
1760
                            Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1761
                            MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
1762
                        }
1763 3210f690 LJIYEON
1764 a5616391 LJIYEON
                        //TopologySet 관련
1765
                        foreach (Topology topology in PSNItem.Topologies)
1766
                        {
1767
                            DataRow newRow = topologySetDT.NewRow();
1768
                            newRow["OID"] = topology.FullName;
1769
                            newRow["Type"] = topology.FullName.Split(new char[] { '-' }).Last().StartsWith("M") ? "Main" : "Branch";
1770
                            if (bVentDrain)
1771
                                newRow["SubType"] = "Vent_Drain";
1772
                            else
1773
                                newRow["SubType"] = null;
1774
                            newRow["HeadItemTag"] = GetItemTag(topology.Items.Last());
1775
                            newRow["TailItemTag"] = GetItemTag(topology.Items.First());
1776
                            newRow["HeadItemSPID"] = topology.Items.Last().UID;
1777
                            newRow["TailItemSPID"] = topology.Items.First().UID;
1778
                            topologySetDT.Rows.Add(newRow);
1779 94a117ca gaqhf
                        }
1780 7106e181 LJIYEON
1781 6b9e7a56 gaqhf
                    }
1782 7106e181 LJIYEON
                    catch (Exception ee)
1783 27d06aa8 LJIYEON
                    {
1784 879ce10b LJIYEON
1785 2c46461b LJIYEON
                    }
1786 6b9e7a56 gaqhf
                }
1787
1788 3210f690 LJIYEON
1789 2c46461b LJIYEON
                foreach (var item in startBranchDic)
1790 5c248ee3 gaqhf
                {
1791 2c46461b LJIYEON
                    string uid = item.Key.UID;
1792
                    string topologyName = item.Value.Topology.FullName;
1793
                    DataRow[] rows = pathItemsDT.Select(string.Format("OID LIKE '{0}%'", uid));
1794 7106e181 LJIYEON
1795 2c46461b LJIYEON
                    if (rows.Length == 1)
1796 9c151350 gaqhf
                    {
1797 2c46461b LJIYEON
                        rows.First()["BranchTopologySet_OID"] = topologyName;
1798 9c151350 gaqhf
                        rows.First()["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID();
1799
                    }
1800 2c46461b LJIYEON
                    else if (rows.Length > 1)
1801 5c248ee3 gaqhf
                    {
1802 2c46461b LJIYEON
                        DataRow targetRow = null;
1803
                        int index = int.MaxValue;
1804
                        foreach (DataRow row in rows)
1805 5c248ee3 gaqhf
                        {
1806 2c46461b LJIYEON
                            string split = row["OID"].ToString().Split(new char[] { '_' })[1];
1807
                            if (split.StartsWith("L"))
1808 5c248ee3 gaqhf
                            {
1809 2c46461b LJIYEON
                                int num = Convert.ToInt32(split.Remove(0, 1));
1810
                                if (index > num)
1811
                                {
1812
                                    index = num;
1813
                                    targetRow = row;
1814
                                }
1815 5c248ee3 gaqhf
                            }
1816
                        }
1817
1818 2c46461b LJIYEON
                        if (targetRow != null)
1819 9c151350 gaqhf
                        {
1820 2c46461b LJIYEON
                            targetRow["BranchTopologySet_OID"] = topologyName;
1821 9c151350 gaqhf
                            targetRow["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID();
1822
                        }
1823 2c46461b LJIYEON
                    }
1824 5c248ee3 gaqhf
                }
1825 f9f2787b LJIYEON
1826 2c46461b LJIYEON
                foreach (var item in endBranchDic)
1827 5c248ee3 gaqhf
                {
1828 2c46461b LJIYEON
                    string uid = item.Key.UID;
1829
                    string topologyName = item.Value.Topology.FullName;
1830
                    DataRow[] rows = pathItemsDT.Select(string.Format("OID LIKE '{0}%'", uid));
1831
                    if (rows.Length == 1)
1832 9c151350 gaqhf
                    {
1833 2c46461b LJIYEON
                        rows.First()["BranchTopologySet_OID"] = topologyName;
1834 9c151350 gaqhf
                        rows.First()["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID();
1835
                    }
1836 2c46461b LJIYEON
                    else if (rows.Length > 1)
1837 5c248ee3 gaqhf
                    {
1838 2c46461b LJIYEON
                        DataRow targetRow = null;
1839
                        int index = int.MinValue;
1840
                        foreach (DataRow row in rows)
1841 5c248ee3 gaqhf
                        {
1842 2c46461b LJIYEON
                            string split = row["OID"].ToString().Split(new char[] { '_' })[1];
1843
                            if (split.StartsWith("L"))
1844 5c248ee3 gaqhf
                            {
1845 2c46461b LJIYEON
                                int num = Convert.ToInt32(split.Remove(0, 1));
1846
                                if (index < num)
1847
                                {
1848
                                    index = num;
1849
                                    targetRow = row;
1850
                                }
1851 5c248ee3 gaqhf
                            }
1852
                        }
1853
1854 2c46461b LJIYEON
                        if (targetRow != null)
1855 9c151350 gaqhf
                        {
1856 2c46461b LJIYEON
                            targetRow["BranchTopologySet_OID"] = topologyName;
1857 9c151350 gaqhf
                            targetRow["ViewPipeSystemNetwork_OID"] = item.Value.PSNItem.PSN_OID();
1858
                        }
1859 2c46461b LJIYEON
                    }
1860 5c248ee3 gaqhf
                }
1861
1862 2c46461b LJIYEON
                PathItems = pathItemsDT;
1863
                SequenceData = sequenceDataDT;
1864
                PipeSystemNetwork = pipeSystemNetworkDT;
1865
                TopologySet = topologySetDT;
1866 f9f2787b LJIYEON
                PipeLine = pipelineDT;
1867 531fb158 LJIYEON
                PipeSystem = pipesystemDT;
1868 2c46461b LJIYEON
            }
1869
            catch (Exception ex)
1870
            {
1871
                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1872
                MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
1873
            }
1874 36a45f13 gaqhf
        }
1875 2ada3be8 LJIYEON
1876 5e4c2ad1 LJIYEON
        private double AccuracyCalculation(List<double> lstAcc, double acc)
1877 2ada3be8 LJIYEON
        {
1878 7106e181 LJIYEON
            foreach (double lacc in lstAcc)
1879 2ada3be8 LJIYEON
            {
1880
                acc *= lacc;
1881
            }
1882
            return acc;
1883
        }
1884
1885 7881ec8f gaqhf
        private void UpdateSubType()
1886 36a45f13 gaqhf
        {
1887 27d06aa8 LJIYEON
            try
1888 36a45f13 gaqhf
            {
1889 27d06aa8 LJIYEON
                foreach (PSNItem PSNItem in PSNItems)
1890 36a45f13 gaqhf
                {
1891 27d06aa8 LJIYEON
                    if (PSNItem.IsBypass)
1892 36a45f13 gaqhf
                    {
1893 27d06aa8 LJIYEON
                        foreach (Topology topology in PSNItem.Topologies)
1894
                        {
1895
                            DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName));
1896
                            if (rows.Length.Equals(1))
1897
                                rows.First()["SubType"] = "Bypass";
1898
                        }
1899
                    }
1900
1901
                    if (PSNItem.StartType == PSNType.Header)
1902
                    {
1903
                        Topology topology = PSNItem.Topologies.First();
1904
                        DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName));
1905
                        if (rows.Length.Equals(1))
1906
                            rows.First()["SubType"] = "Header";
1907
                    }
1908
                    else if (PSNItem.EndType == PSNType.Header)
1909
                    {
1910
                        Topology topology = PSNItem.Topologies.Last();
1911 7881ec8f gaqhf
                        DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName));
1912
                        if (rows.Length.Equals(1))
1913 27d06aa8 LJIYEON
                            rows.First()["SubType"] = "Header";
1914 36a45f13 gaqhf
                    }
1915
                }
1916 7881ec8f gaqhf
1917 36a45f13 gaqhf
1918 27d06aa8 LJIYEON
                foreach (Topology topology in Topologies)
1919 7881ec8f gaqhf
                {
1920 27d06aa8 LJIYEON
                    try
1921
                    {
1922
                        DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName));
1923 7106e181 LJIYEON
1924
                        if (rows.Count() > 0)
1925 27d06aa8 LJIYEON
                        {
1926 3210f690 LJIYEON
                            if (rows.Length.Equals(1) && rows.First()["SubType"] == null || string.IsNullOrEmpty(rows.First()["SubType"].ToString()))
1927
                            {
1928
                                if (topology.Items == null)
1929
                                    continue;
1930 27d06aa8 LJIYEON
1931 3210f690 LJIYEON
                                Item firstItem = topology.Items.First();
1932
                                Item lastItem = topology.Items.Last();
1933 27d06aa8 LJIYEON
1934 3210f690 LJIYEON
                                List<Relation> relations = new List<Relation>();
1935 7881ec8f gaqhf
1936 3210f690 LJIYEON
                                if (firstItem.Relations.FindAll(x => x.Item == null).Count() != 0)
1937
                                    relations.AddRange(firstItem.Relations.FindAll(x => x.Item != null && x.Item.Topology.ID != topology.ID));
1938 7881ec8f gaqhf
1939 3210f690 LJIYEON
                                if (lastItem.Relations.FindAll(x => x.Item == null).Count() != 0)
1940
                                    relations.AddRange(lastItem.Relations.FindAll(x => x.Item != null && x.Item.Topology.ID != topology.ID));
1941
1942
                                if (relations.Count > 0)
1943
                                    rows.First()["SubType"] = "OtherSystem";
1944
                            }
1945 27d06aa8 LJIYEON
                        }
1946
                    }
1947
                    catch (Exception ex)
1948
                    {
1949 7106e181 LJIYEON
1950 27d06aa8 LJIYEON
                        MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
1951
                    }
1952 7881ec8f gaqhf
                }
1953
1954 7106e181 LJIYEON
                foreach (DataRow row in TopologySet.Rows)
1955 27d06aa8 LJIYEON
                    if (row["SubType"] == null || string.IsNullOrEmpty(row["SubType"].ToString()))
1956
                        row["SubType"] = "Normal";
1957
            }
1958
            catch (Exception ex)
1959
            {
1960
                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1961
                MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
1962
            }
1963 7881ec8f gaqhf
        }
1964 5e4c2ad1 LJIYEON
1965 7881ec8f gaqhf
        private bool IsBypass(PSNItem PSNItem)
1966
        {
1967
            bool bResult = false;
1968
1969
            if (PSNItem.GetPSNType() == "B2B")
1970
            {
1971
                Group firstGroup = PSNItem.Groups.First();
1972
                Group lastGroup = PSNItem.Groups.Last();
1973
                Item firstItem = firstGroup.Items.First();
1974
                Item lastItem = lastGroup.Items.Last();
1975
1976
                Item connectedFirstItem = GetConnectedItemByPSN(firstItem);
1977
                Item connectedLastItem = GetConnectedItemByPSN(lastItem);
1978 36a45f13 gaqhf
1979 7881ec8f gaqhf
                if (connectedFirstItem.LineNumber != null && connectedLastItem.LineNumber != null &&
1980
                    !string.IsNullOrEmpty(connectedFirstItem.LineNumber.Name) && !string.IsNullOrEmpty(connectedLastItem.LineNumber.Name) &&
1981
                    connectedFirstItem.LineNumber.Name == connectedLastItem.LineNumber.Name)
1982
                    bResult = true;
1983
                else if (connectedFirstItem.PSNItem == connectedLastItem.PSNItem)
1984
                    bResult = true;
1985
            }
1986 36a45f13 gaqhf
1987
            Item GetConnectedItemByPSN(Item item)
1988
            {
1989
                Item result = null;
1990
1991
                Relation relation = item.Relations.Find(x => x.Item != null && x.Item.PSNItem != item.PSNItem);
1992
                if (relation != null)
1993
                    result = relation.Item;
1994
1995 3210f690 LJIYEON
1996 36a45f13 gaqhf
                return result;
1997
            }
1998 7881ec8f gaqhf
1999
            return bResult;
2000
        }
2001 5e4c2ad1 LJIYEON
2002 419055fa LJIYEON
        private void DeleteVentDrain()
2003
        {
2004
            DataRow[] ventdrainRows = PipeSystemNetwork.Select(" IncludingVirtualData = 'Vent_Drain'");
2005 7106e181 LJIYEON
2006 419055fa LJIYEON
            foreach (DataRow dataRow in ventdrainRows)
2007
            {
2008 7106e181 LJIYEON
                dataRow.Delete();
2009
            }
2010 419055fa LJIYEON
        }
2011
2012 5e4c2ad1 LJIYEON
        private void UpdateAccuracy()
2013
        {
2014 54b6df95 LJIYEON
            //DataRow[] statusRows = PipeSystemNetwork.Select(" Type = 'Error' OR IsValid = 'Error'"); 
2015
            DataRow[] statusRows = PipeSystemNetwork.Select(" Type = 'Error' OR IsValid = 'Error'");
2016 5e4c2ad1 LJIYEON
            List<double> lstAcc = null;
2017
            string Status = string.Empty;
2018 f9f2787b LJIYEON
2019 5e4c2ad1 LJIYEON
            foreach (DataRow dataRow in statusRows)
2020
            {
2021
                lstAcc = new List<double>();
2022
                Status = dataRow.Field<string>("Status");
2023
                if (!string.IsNullOrEmpty(Status))
2024
                {
2025 51974d2b LJIYEON
                    string[] arrStatus = Status.Split(',');
2026 7106e181 LJIYEON
                    foreach (string arrstr in arrStatus)
2027 51974d2b LJIYEON
                    {
2028
                        if (arrstr.Contains(Rule1)) //Missing LineNumber_1
2029
                            lstAcc.Add(0.75);
2030 f9f2787b LJIYEON
2031 51974d2b LJIYEON
                        if (arrstr.Contains(Rule2)) //Missing LineNumber_2
2032
                            lstAcc.Add(0.7);
2033 f9f2787b LJIYEON
2034 51974d2b LJIYEON
                        if (arrstr.Contains(Rule3)) // OPC Disconnected
2035
                            lstAcc.Add(0.5);
2036 f9f2787b LJIYEON
2037 51974d2b LJIYEON
                        if (arrstr.Contains(Rule4)) //Missing ItemTag or Description
2038
                            lstAcc.Add(0.65);
2039
2040
                        if (arrstr.Contains(Rule5)) //Line Disconnected
2041
                            lstAcc.Add(0.6);
2042
                    }
2043 5e4c2ad1 LJIYEON
                }
2044
2045
                string PSNAccuracy = dataRow["PSNAccuracy"].ToString();
2046
                if (PSNAccuracy == "100")
2047
                    PSNAccuracy = "1";
2048
2049 51974d2b LJIYEON
                PSNAccuracy = Convert.ToString(Convert.ToDecimal(AccuracyCalculation(lstAcc, Convert.ToDouble(PSNAccuracy))));
2050
                //if (PSNAccuracy != "100")
2051
                //{
2052
                //    //dataRow["IncludingVirtualData"] = "No";
2053 7106e181 LJIYEON
                dataRow["PSNAccuracy"] = PSNAccuracy;
2054 51974d2b LJIYEON
                //}
2055 5e4c2ad1 LJIYEON
            }
2056 bfe278bb LJIYEON
            DataTable dt = PipeSystemNetwork.DefaultView.ToTable(true, new string[] { "OID" });
2057
            foreach (DataRow dr in dt.Rows)
2058
            {
2059
                string oid = dr.Field<string>("OID");
2060
                DataRow[] select = PipeSystemNetwork.Select(string.Format("OID = '{0}'", oid));
2061
                double totalDdr = 0;
2062
                foreach (DataRow ddr in select)
2063
                {
2064
                    double acc = Convert.ToDouble(ddr.Field<string>("PSNAccuracy"));
2065
                    if (acc == 100) acc = 1;
2066
                    if (totalDdr == 0) totalDdr = acc;
2067
                    else totalDdr *= acc;
2068
                }
2069
2070
                totalDdr *= 100;
2071
2072 7106e181 LJIYEON
                if (totalDdr != 100)
2073 bfe278bb LJIYEON
                {
2074 f9f2787b LJIYEON
                    foreach (DataRow ddr in select)
2075
                    {
2076
                        ddr["IncludingVirtualData"] = "Yes";
2077 51974d2b LJIYEON
                        ddr["PSNAccuracy"] = String.Format("{0:0.00}", Math.Round(totalDdr, 2));
2078
                    }
2079
                }
2080
                else
2081
                {
2082
                    foreach (DataRow ddr in select)
2083
                    {
2084
                        ddr["IncludingVirtualData"] = "No";
2085
                        ddr["PSNAccuracy"] = String.Format("{0:0.00}", Math.Round(totalDdr, 2));
2086 f9f2787b LJIYEON
                    }
2087 bfe278bb LJIYEON
                }
2088
            }
2089
2090 5e4c2ad1 LJIYEON
        }
2091
2092 a5616391 LJIYEON
        private void UpdateKeywordForPSN()
2093
        {
2094
            #region Keyword Info
2095
            KeywordInfo KeywordInfos = new KeywordInfo();
2096
            DataTable dtKeyword = DB.SelectKeywordsSetting();
2097
            foreach (DataRow row in dtKeyword.Rows)
2098
            {
2099
                int index = Convert.ToInt32(row["INDEX"]);
2100
                string name = row["NAME"].ToString();
2101
                string keyword = row["KEYWORD"].ToString();
2102
2103
                //KeywordInfo keywordInfo = new KeywordInfo();   
2104
                KeywordInfos.KeywordItems.Add(new KeywordItem()
2105
                {
2106
                    Index = index,
2107
                    Name = name,
2108
                    Keyword = keyword
2109
                });
2110
            }
2111
            #endregion
2112
2113 a2973aa3 LJIYEON
            DataRow[] endofHeaderRows = PipeSystemNetwork.Select(string.Format(" From_Data = '{0}' OR To_Data = '{0}'", "ENDOFHEADER"));
2114
            foreach (DataRow dataRow in endofHeaderRows)
2115
            {
2116
                PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString());
2117
2118
                if (dataRow.Field<string>("From_Data") == "ENDOFHEADER")
2119
                {
2120
                    DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
2121
                    DataRow dr = pathItemRows.First();
2122
                    dr["CLASS"] = PSNItem.Groups.First().Items.First().ID2DBName;
2123
                    dr["TYPE"] = "End";
2124
                    dr["ITEMTAG"] = "ENDOFHEADER";
2125
                    dr["DESCRIPTION"] = "ENDOFHEADER";
2126
                }
2127
2128
                if (dataRow.Field<string>("To_Data") == "ENDOFHEADER")
2129
                {
2130
                    DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
2131
                    DataRow dr = pathItemRows.Last();
2132
                    dr["CLASS"] = PSNItem.Groups.Last().Items.Last().ID2DBName;
2133
                    dr["TYPE"] = "End";
2134
                    dr["ITEMTAG"] = "ENDOFHEADER";
2135
                    dr["DESCRIPTION"] = "ENDOFHEADER";
2136
                }
2137
            }
2138
2139 a5616391 LJIYEON
            foreach (KeywordItem keyitem in KeywordInfos.KeywordItems)
2140
            {
2141 a2973aa3 LJIYEON
                DataRow[] keywordRows = PipeSystemNetwork.Select(string.Format(" From_Data = '{0}' OR To_Data = '{0}'", keyitem.Keyword));
2142 a5616391 LJIYEON
                foreach (DataRow dataRow in keywordRows)
2143 7106e181 LJIYEON
                {
2144
                    PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString());
2145 a5616391 LJIYEON
2146 7106e181 LJIYEON
                    if (dataRow.Field<string>("From_Data") == keyitem.Keyword)
2147
                    {
2148 a5616391 LJIYEON
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
2149 7106e181 LJIYEON
2150 a2973aa3 LJIYEON
                        //
2151
                        //if(.)
2152 7106e181 LJIYEON
                        if (PSNItem.Groups.First().Items.First().Name.Equals(keyitem.Name))
2153 a5616391 LJIYEON
                        {
2154
                            DataRow dr = pathItemRows.First();
2155
                            //dr["CLASS"] = ""; //Type
2156
                            dr["TYPE"] = "End";
2157
                            dr["ITEMTAG"] = keyitem.Keyword;
2158
                            dr["DESCRIPTION"] = keyitem.Keyword;
2159
                        }
2160 7106e181 LJIYEON
2161 a5616391 LJIYEON
                    }
2162
2163 a2973aa3 LJIYEON
                    if (dataRow.Field<string>("To_Data") == keyitem.Keyword)
2164 a5616391 LJIYEON
                    {
2165
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
2166
2167 a2973aa3 LJIYEON
                        if (PSNItem.Groups.Last().Items.Last().Name.Equals(keyitem.Name))
2168 a5616391 LJIYEON
                        {
2169
                            DataRow dr = pathItemRows.Last();
2170
                            //dr["CLASS"] = ""; //Type
2171
                            dr["TYPE"] = "End";
2172
                            dr["ITEMTAG"] = keyitem.Keyword;
2173
                            dr["DESCRIPTION"] = keyitem.Keyword;
2174
                            //dr.Field<string>("Type")
2175
                        }
2176
2177 7106e181 LJIYEON
                    }
2178 a5616391 LJIYEON
                }
2179 7106e181 LJIYEON
            }
2180 a5616391 LJIYEON
        }
2181
2182 7881ec8f gaqhf
        private void UpdateErrorForPSN()
2183
        {
2184 45529c16 LJIYEON
            DataRow[] errorRows = PipeSystemNetwork.Select(string.Format(" Type = '{0}'", ErrorType.Error));
2185 7881ec8f gaqhf
            foreach (DataRow dataRow in errorRows)
2186
            {
2187 eb44d82c LJIYEON
                try
2188 710a49f1 gaqhf
                {
2189 eb44d82c LJIYEON
                    PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString());
2190
                    bool change = false;
2191 aa195a5b LJIYEON
                    bool bCheck = false;
2192
                    int bCount = 0;
2193 eb44d82c LJIYEON
                    if (!PSNItem.EnableType(PSNItem.StartType))
2194 710a49f1 gaqhf
                    {
2195 eb44d82c LJIYEON
                        change = true;
2196 aa195a5b LJIYEON
                        bCheck = change;
2197 7106e181 LJIYEON
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
2198 eb44d82c LJIYEON
                        int insertIndex = PathItems.Rows.IndexOf(pathItemRows.First());
2199 7106e181 LJIYEON
2200 eb44d82c LJIYEON
                        Item item = PSNItem.Groups.First().Items.First();
2201
                        try
2202 a36541fb LJIYEON
                        {
2203
                            string FROM_DATA = string.Format("TIEINPOINT_{0:D5}V", tieInPointIndex);
2204 7106e181 LJIYEON
2205 eb44d82c LJIYEON
                            tieInPointIndex++;
2206 5e4c2ad1 LJIYEON
2207 7881ec8f gaqhf
2208 eb44d82c LJIYEON
                            if (item.ItemType == ItemType.Line)
2209
                            {
2210 a36541fb LJIYEON
                                PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.First(), FROM_DATA), insertIndex);
2211 aa195a5b LJIYEON
                                bCount = 2;
2212 48870200 LJIYEON
2213
                                foreach (DataRow loopRow in PipeSystemNetwork.Select(string.Format("OID = '{0}'", PSNItem.PSN_OID())))
2214
                                {
2215
                                    loopRow["FROM_DATA"] = FROM_DATA;
2216
                                    if (loopRow.Field<string>("OrderNumber") == "0")
2217
                                    {
2218
                                        string status = loopRow.Field<string>("Status");
2219 7106e181 LJIYEON
                                        //string isvali
2220 48870200 LJIYEON
                                        if (string.IsNullOrEmpty(status))
2221
                                            status = "Line Disconnected";
2222
                                        else if (!status.Contains("Line Disconnected"))
2223
                                            status += ", Line Disconnected";
2224
                                        loopRow["Status"] = status;
2225 7106e181 LJIYEON
                                        if (!string.IsNullOrEmpty(status))
2226
                                            loopRow["IsValid"] = "Error";
2227 48870200 LJIYEON
                                    }
2228
                                }
2229 eb44d82c LJIYEON
                            }
2230
                            else
2231
                            {
2232
                                PathItems.Rows.InsertAt(createLineRow(PathItems.Select(string.Format("PipeLine_OID = '{0}' AND ItemName = 'PipeRun' AND PipeSystemNetwork_OID = '{1}'", item.PSNPipeLineID, dataRow["OID"])).First()), insertIndex);
2233 7106e181 LJIYEON
2234 a36541fb LJIYEON
                                PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.First(), FROM_DATA), insertIndex);
2235 aa195a5b LJIYEON
                                bCount = 3;
2236 eb44d82c LJIYEON
                            }
2237 710a49f1 gaqhf
2238 eb44d82c LJIYEON
                            PSNItem.StartType = PSNType.Equipment;
2239
                        }
2240
                        catch (Exception ex)
2241
                        {
2242
                            MessageBox.Show("Please check the item.\r\nDrawingName : " + item.Document.DrawingName + "\r\nUID : " + item.UID, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
2243
                            return;
2244
                        }
2245
                    }
2246 710a49f1 gaqhf
2247 eb44d82c LJIYEON
                    if (!PSNItem.EnableType(PSNItem.EndType))
2248 710a49f1 gaqhf
                    {
2249 eb44d82c LJIYEON
                        change = true;
2250
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
2251 a2973aa3 LJIYEON
                        int insertIndex = PathItems.Rows.IndexOf(pathItemRows.First()) + pathItemRows.Count() - 1;
2252 a36541fb LJIYEON
2253 eb44d82c LJIYEON
                        Item item = PSNItem.Groups.Last().Items.Last();
2254
                        try
2255 a36541fb LJIYEON
                        {
2256
                            string TO_DATA = string.Format("TIEINPOINT_{0:D5}V", tieInPointIndex);
2257
2258 48870200 LJIYEON
                            if (item.ItemType == ItemType.Line)
2259 51974d2b LJIYEON
                            {
2260 48870200 LJIYEON
                                foreach (DataRow loopRow in PipeSystemNetwork.Select(string.Format("OID = '{0}'", PSNItem.PSN_OID())))
2261 51974d2b LJIYEON
                                {
2262 48870200 LJIYEON
                                    loopRow["TO_DATA"] = TO_DATA;
2263
                                    if (loopRow.Field<string>("OrderNumber") == Convert.ToString(PipeSystemNetwork.Select(string.Format("OID = '{0}'", PSNItem.PSN_OID())).Count() - 1))
2264
                                    {
2265
                                        string status = loopRow.Field<string>("Status");
2266
                                        if (string.IsNullOrEmpty(status))
2267
                                            status = "Line Disconnected";
2268
                                        else if (!status.Contains("Line Disconnected"))
2269
                                            status += ", Line Disconnected";
2270
                                        loopRow["Status"] = status;
2271 7106e181 LJIYEON
                                        if (!string.IsNullOrEmpty(status))
2272
                                            loopRow["IsValid"] = "Error";
2273 48870200 LJIYEON
                                    }
2274 51974d2b LJIYEON
                                }
2275
                            }
2276 48870200 LJIYEON
2277 eb44d82c LJIYEON
                            tieInPointIndex++;
2278 7106e181 LJIYEON
2279
                            if (!bCheck)
2280 eb44d82c LJIYEON
                            {
2281 aa195a5b LJIYEON
                                if (item.ItemType == ItemType.Line)
2282
                                {
2283
                                    PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.Last(), TO_DATA), insertIndex + 1);
2284
                                }
2285
                                else
2286
                                {
2287
                                    PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.Last(), TO_DATA), insertIndex + 1);
2288
                                    PathItems.Rows.InsertAt(createLineRow(PathItems.Select(string.Format("PipeLine_OID = '{0}' AND ItemName = 'PipeRun' AND PipeSystemNetwork_OID = '{1}'", item.PSNPipeLineID, dataRow["OID"])).Last()), insertIndex + 1);
2289
                                }
2290 eb44d82c LJIYEON
                            }
2291
                            else
2292
                            {
2293 aa195a5b LJIYEON
                                if (item.ItemType == ItemType.Line)
2294
                                {
2295
                                    PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows[pathItemRows.Count() - bCount], TO_DATA), insertIndex + 1);
2296
                                }
2297
                                else
2298
                                {
2299
                                    PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows[pathItemRows.Count() - bCount], TO_DATA), insertIndex + 1);
2300
                                    PathItems.Rows.InsertAt(createLineRow(PathItems.Select(string.Format("PipeLine_OID = '{0}' AND ItemName = 'PipeRun' AND PipeSystemNetwork_OID = '{1}'", item.PSNPipeLineID, dataRow["OID"])).Last()), insertIndex + 1);
2301
                                }
2302 eb44d82c LJIYEON
                            }
2303 7106e181 LJIYEON
2304 5e4c2ad1 LJIYEON
2305 eb44d82c LJIYEON
                            PSNItem.EndType = PSNType.Equipment;
2306
                        }
2307 7106e181 LJIYEON
                        catch (Exception ex)
2308 eb44d82c LJIYEON
                        {
2309
                            MessageBox.Show("Please check the item.\r\nDrawingName : " + item.Document.DrawingName + "\r\nUID : " + item.UID, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
2310
                            return;
2311
                        }
2312 710a49f1 gaqhf
                    }
2313 eb44d82c LJIYEON
2314
                    dataRow["Type"] = PSNItem.GetPSNType();
2315
                    if (change)
2316 710a49f1 gaqhf
                    {
2317 eb44d82c LJIYEON
                        int rowIndex = 0;
2318
                        for (int i = 0; i < PathItems.Rows.Count; i++)
2319
                        {
2320
                            DataRow row = PathItems.Rows[i];
2321
                            if (row["PipeSystemNetwork_OID"].ToString() != dataRow["OID"].ToString())
2322
                                continue;
2323
                            string sequenceData = row["SequenceData_OID"].ToString();
2324
                            string[] split = sequenceData.Split(new char[] { '_' });
2325
2326
                            StringBuilder sb = new StringBuilder();
2327
                            for (int j = 0; j < split.Length - 1; j++)
2328
                                sb.Append(split[j] + "_");
2329
                            sb.Append(rowIndex++);
2330
                            row["SequenceData_OID"] = sb.ToString();
2331 a36541fb LJIYEON
2332 3210f690 LJIYEON
                            DataRow seqItemRows = SequenceData.Select(string.Format("PathItem_OID = '{0}'", row["OID"])).FirstOrDefault();
2333
                            int insertSeqIndex = SequenceData.Rows.IndexOf(seqItemRows);
2334
2335
                            string[] splitseq = sb.ToString().Split(new char[] { '_' });
2336
2337
                            if (seqItemRows == null)
2338
                            {
2339 7106e181 LJIYEON
                                DataRow newRow = SequenceData.NewRow();
2340 3210f690 LJIYEON
                                newRow["OID"] = sb.ToString();
2341
                                newRow["SERIALNUMBER"] = splitseq[splitseq.Length - 1];
2342
                                newRow["PathItem_OID"] = row["OID"];
2343
                                newRow["TopologySet_OID_Key"] = row["TopologySet_OID"];
2344
                                SequenceData.Rows.InsertAt(newRow, Convert.ToInt32(splitseq[splitseq.Length - 1]));
2345
                            }
2346
                            else
2347
                            {
2348
                                seqItemRows["OID"] = sb.ToString();
2349
                                seqItemRows["SERIALNUMBER"] = splitseq[splitseq.Length - 1];
2350
                                seqItemRows["PathItem_OID"] = row["OID"];
2351
                                seqItemRows["TopologySet_OID_Key"] = row["TopologySet_OID"];
2352 7106e181 LJIYEON
                            }
2353
                        }
2354 eb44d82c LJIYEON
                    }
2355 5e4c2ad1 LJIYEON
2356 a36541fb LJIYEON
                    DataRow createTerminatorRow(DataRow itemRow, string DATA)
2357 eb44d82c LJIYEON
                    {
2358
                        DataRow newRow = PathItems.NewRow();
2359
                        newRow["OID"] = Guid.NewGuid().ToString();
2360
                        newRow["SequenceData_OID"] = itemRow["SequenceData_OID"];
2361
                        newRow["TopologySet_OID"] = itemRow["TopologySet_OID"];
2362
                        newRow["BranchTopologySet_OID"] = itemRow["BranchTopologySet_OID"];
2363 7106e181 LJIYEON
                        newRow["PipeLine_OID"] = itemRow["PipeLine_OID"];
2364 a36541fb LJIYEON
                        newRow["ITEMNAME"] = "PipingComp"; //newRow["ITEMNAME"] = "End of line terminator";
2365
                        newRow["ITEMTAG"] = DATA; //itemRow["ITEMTAG"];
2366 7106e181 LJIYEON
                        newRow["DESCRIPTION"] = DATA;
2367 eb44d82c LJIYEON
                        newRow["Class"] = "End of line terminator";
2368
                        newRow["SubClass"] = "End of line terminator";
2369 a36541fb LJIYEON
                        newRow["TYPE"] = "End";
2370 eb44d82c LJIYEON
                        newRow["PIDNAME"] = itemRow["PIDNAME"];
2371
                        newRow["NPD"] = itemRow["NPD"];
2372
                        newRow["PipeSystemNetwork_OID"] = itemRow["PipeSystemNetwork_OID"];
2373
                        newRow["ViewPipeSystemNetwork_OID"] = itemRow["ViewPipeSystemNetwork_OID"];
2374 7106e181 LJIYEON
                        newRow["PipeRun_OID"] = itemRow["PipeRun_OID"];
2375 a36541fb LJIYEON
2376
                        return newRow;
2377
                    }
2378
2379 eb44d82c LJIYEON
                    DataRow createLineRow(DataRow itemRow)
2380 710a49f1 gaqhf
                    {
2381 eb44d82c LJIYEON
                        DataRow newRow = PathItems.NewRow();
2382
                        newRow["OID"] = Guid.NewGuid().ToString();
2383
                        newRow["SequenceData_OID"] = itemRow["SequenceData_OID"];
2384
                        newRow["TopologySet_OID"] = itemRow["TopologySet_OID"];
2385
                        newRow["BranchTopologySet_OID"] = itemRow["BranchTopologySet_OID"];
2386
                        newRow["PipeLine_OID"] = itemRow["PipeLine_OID"];
2387
                        newRow["ITEMNAME"] = itemRow["ITEMNAME"];
2388
                        newRow["ITEMTAG"] = itemRow["ITEMTAG"];
2389
                        newRow["Class"] = itemRow["Class"];
2390
                        newRow["SubClass"] = itemRow["SubClass"];
2391
                        newRow["TYPE"] = itemRow["TYPE"];
2392
                        newRow["PIDNAME"] = itemRow["PIDNAME"];
2393
                        newRow["NPD"] = itemRow["NPD"];
2394
                        newRow["PipeSystemNetwork_OID"] = itemRow["PipeSystemNetwork_OID"];
2395
                        newRow["ViewPipeSystemNetwork_OID"] = itemRow["ViewPipeSystemNetwork_OID"];
2396
                        newRow["PipeRun_OID"] = itemRow["PipeRun_OID"];
2397
2398
                        return newRow;
2399 710a49f1 gaqhf
                    }
2400
                }
2401 7106e181 LJIYEON
                catch (Exception ex)
2402 5e4c2ad1 LJIYEON
                {
2403 710a49f1 gaqhf
2404
                }
2405 eb44d82c LJIYEON
            }
2406 6b9e7a56 gaqhf
        }
2407 4e2e0aa1 LJIYEON
2408
        private void InsertTeePSN()
2409
        {
2410 3f5cb4dc LJIYEON
            DataTable dt = PipeSystemNetwork.DefaultView.ToTable(true, new string[] { "OID", "Type" });
2411
            DataRow[] branchRows = dt.Select("Type Like '%B%'");
2412 820e283f LJIYEON
            bool change = false;
2413 4e2e0aa1 LJIYEON
            foreach (DataRow dataRow in branchRows)
2414
            {
2415
                try
2416 7106e181 LJIYEON
                {
2417 4e2e0aa1 LJIYEON
                    PSNItem PSNItem = PSNItems.Find(x => x.PSN_OID() == dataRow["OID"].ToString());
2418 820e283f LJIYEON
                    change = false;
2419
2420 4e2e0aa1 LJIYEON
                    if (PSNItem.StartType == PSNType.Branch)
2421
                    {
2422 820e283f LJIYEON
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", PSNItem.PSN_OID()));
2423 4e2e0aa1 LJIYEON
                        int insertIndex = PathItems.Rows.IndexOf(pathItemRows.First());
2424 820e283f LJIYEON
                        Item Teeitem = PSNItem.Groups.First().Items.First();
2425 4e2e0aa1 LJIYEON
                        try
2426 820e283f LJIYEON
                        {
2427
                            if (Teeitem.ItemType == ItemType.Line)
2428 4e2e0aa1 LJIYEON
                            {
2429
                                if (pathItemRows.First().Field<string>("SubClass") != "Tee")
2430 7106e181 LJIYEON
                                {
2431 4e2e0aa1 LJIYEON
                                    PathItems.Rows.InsertAt(createTeeRow(pathItemRows.First()), insertIndex);
2432 0e9d868c LJIYEON
                                    pathItemRows.First().SetField("BranchTopologySet_OID", string.Empty);
2433
                                    pathItemRows.First().SetField("ViewPipeSystemNetwork_OID", dataRow["OID"].ToString());
2434 820e283f LJIYEON
                                    change = true;
2435 4e2e0aa1 LJIYEON
                                }
2436
2437 820e283f LJIYEON
                            }
2438 4e2e0aa1 LJIYEON
                        }
2439
                        catch (Exception ex)
2440
                        {
2441 820e283f LJIYEON
                            MessageBox.Show("Please check the item.\r\nDrawingName : " + Teeitem.Document.DrawingName + "\r\nUID : " + Teeitem.UID, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
2442 4e2e0aa1 LJIYEON
                            return;
2443
                        }
2444
                    }
2445
2446
                    if (PSNItem.EndType == PSNType.Branch)
2447
                    {
2448 820e283f LJIYEON
                        //change = true;
2449
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", PSNItem.PSN_OID()));
2450 7106e181 LJIYEON
2451 820e283f LJIYEON
                        Item Teeitem = PSNItem.Groups.Last().Items.Last();
2452 4e2e0aa1 LJIYEON
2453 820e283f LJIYEON
                        DataRow dr = pathItemRows.Last();
2454
                        if (change)
2455
                            dr = pathItemRows[pathItemRows.Count() - 2];
2456 e36ca22f LJIYEON
2457 b683578e LJIYEON
                        int insertIndex = PathItems.Rows.IndexOf(dr) + 1;
2458 e36ca22f LJIYEON
2459 4e2e0aa1 LJIYEON
                        try
2460
                        {
2461 820e283f LJIYEON
                            if (Teeitem.ItemType == ItemType.Line)
2462 4e2e0aa1 LJIYEON
                            {
2463 820e283f LJIYEON
                                if (dr.Field<string>("SubClass") != "Tee")
2464
                                {
2465
                                    PathItems.Rows.InsertAt(createTeeRow(dr), insertIndex);
2466
                                    change = true;
2467 0e9d868c LJIYEON
                                    dr.SetField("BranchTopologySet_OID", string.Empty);
2468
                                    dr.SetField("ViewPipeSystemNetwork_OID", dataRow["OID"].ToString());
2469 820e283f LJIYEON
                                }
2470
2471 4e2e0aa1 LJIYEON
                            }
2472
                        }
2473
                        catch (Exception ex)
2474
                        {
2475 820e283f LJIYEON
                            MessageBox.Show("Please check the item.\r\nDrawingName : " + Teeitem.Document.DrawingName + "\r\nUID : " + Teeitem.UID, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
2476 4e2e0aa1 LJIYEON
                            return;
2477
                        }
2478
                    }
2479
2480
                    if (change)
2481
                    {
2482 820e283f LJIYEON
                        //DataRow[] pathItemRows = pathItemsDT.Select(string.Format("PipeSystemNetwork_OID = '{0}'", PSNItem.PSN_OID()));
2483 4e2e0aa1 LJIYEON
                        int rowIndex = 0;
2484
                        for (int i = 0; i < PathItems.Rows.Count; i++)
2485
                        {
2486
                            DataRow row = PathItems.Rows[i];
2487 820e283f LJIYEON
                            if (row["PipeSystemNetwork_OID"].ToString() != PSNItem.PSN_OID())
2488 4e2e0aa1 LJIYEON
                                continue;
2489
                            string sequenceData = row["SequenceData_OID"].ToString();
2490
                            string[] split = sequenceData.Split(new char[] { '_' });
2491
2492
                            StringBuilder sb = new StringBuilder();
2493
                            for (int j = 0; j < split.Length - 1; j++)
2494
                                sb.Append(split[j] + "_");
2495
                            sb.Append(rowIndex++);
2496
                            row["SequenceData_OID"] = sb.ToString();
2497
2498
                            DataRow seqItemRows = SequenceData.Select(string.Format("PathItem_OID = '{0}'", row["OID"])).FirstOrDefault();
2499
                            int insertSeqIndex = SequenceData.Rows.IndexOf(seqItemRows);
2500
2501
                            string[] splitseq = sb.ToString().Split(new char[] { '_' });
2502
2503
                            if (seqItemRows == null)
2504
                            {
2505
                                DataRow newRow = SequenceData.NewRow();
2506
                                newRow["OID"] = sb.ToString();
2507
                                newRow["SERIALNUMBER"] = splitseq[splitseq.Length - 1];
2508
                                newRow["PathItem_OID"] = row["OID"];
2509
                                newRow["TopologySet_OID_Key"] = row["TopologySet_OID"];
2510
                                SequenceData.Rows.InsertAt(newRow, Convert.ToInt32(splitseq[splitseq.Length - 1]));
2511
                            }
2512
                            else
2513
                            {
2514
                                seqItemRows["OID"] = sb.ToString();
2515
                                seqItemRows["SERIALNUMBER"] = splitseq[splitseq.Length - 1];
2516
                                seqItemRows["PathItem_OID"] = row["OID"];
2517
                                seqItemRows["TopologySet_OID_Key"] = row["TopologySet_OID"];
2518
                            }
2519
                        }
2520 820e283f LJIYEON
                    }
2521 7106e181 LJIYEON
2522 4e2e0aa1 LJIYEON
                    DataRow createTeeRow(DataRow itemRow)
2523
                    {
2524
                        DataRow newRow = PathItems.NewRow();
2525
                        newRow["OID"] = Guid.NewGuid().ToString();
2526
                        newRow["SequenceData_OID"] = itemRow["SequenceData_OID"];
2527
                        newRow["TopologySet_OID"] = itemRow["TopologySet_OID"];
2528
                        newRow["BranchTopologySet_OID"] = itemRow["BranchTopologySet_OID"];
2529
                        newRow["PipeLine_OID"] = itemRow["PipeLine_OID"];
2530
                        newRow["ITEMNAME"] = "Branch"; //newRow["ITEMNAME"] = "End of line terminator";
2531
                        newRow["ITEMTAG"] = itemRow["ITEMTAG"];
2532
                        newRow["DESCRIPTION"] = "";
2533
                        newRow["Class"] = "Branch";
2534
                        newRow["SubClass"] = "Tee";
2535
                        newRow["TYPE"] = itemRow["TYPE"];
2536
                        newRow["PIDNAME"] = itemRow["PIDNAME"];
2537
                        newRow["NPD"] = itemRow["NPD"];
2538
                        newRow["PipeSystemNetwork_OID"] = itemRow["PipeSystemNetwork_OID"];
2539
                        newRow["ViewPipeSystemNetwork_OID"] = itemRow["ViewPipeSystemNetwork_OID"];
2540
                        newRow["PipeRun_OID"] = itemRow["PipeRun_OID"];
2541
2542
                        return newRow;
2543
                    }
2544
                }
2545
                catch (Exception ex)
2546
                {
2547
2548
                }
2549
            }
2550
        }
2551 6b9e7a56 gaqhf
    }
2552
2553
    public class PSNItem
2554
    {
2555 8f24b438 gaqhf
        public PSNItem(int count, int Revision)
2556 6b9e7a56 gaqhf
        {
2557
            Groups = new List<Group>();
2558
            Topologies = new List<Topology>();
2559 94a117ca gaqhf
2560
            Index = count + 1;
2561 8f24b438 gaqhf
            this.Revision = Revision;
2562 6b9e7a56 gaqhf
        }
2563 eb44d82c LJIYEON
2564 8f24b438 gaqhf
        private int Revision;
2565 6b9e7a56 gaqhf
        public string UID { get; set; }
2566
        public List<Group> Groups { get; set; }
2567
        public List<Topology> Topologies { get; set; }
2568
        public PSNType StartType { get; set; }
2569
        public PSNType EndType { get; set; }
2570 94a117ca gaqhf
        public int Index { get; set; }
2571 72775f2e LJIYEON
        public string IsValid { get; set; }
2572 a36541fb LJIYEON
        public bool IsKeyword { get; set; }
2573 36a45f13 gaqhf
        public string Status { get; set; }
2574 ddc1c369 LJIYEON
        public string IncludingVirtualData { get; set; }
2575
        public string PSNAccuracy { get; set; }
2576 eb44d82c LJIYEON
        public KeywordInfo KeywordInfos = new KeywordInfo();
2577 a36541fb LJIYEON
        public DataTable Nozzle = new DataTable();
2578 ddc1c369 LJIYEON
2579 94a117ca gaqhf
        public string PSN_OID()
2580
        {
2581 36a45f13 gaqhf
            return string.Format("V{0}-PSN-{1}", string.Format("{0:D4}", Revision), string.Format("{0:D5}", Index));
2582 94a117ca gaqhf
        }
2583 3610fd3f LJIYEON
2584 94a117ca gaqhf
        public string GetPSNType()
2585
        {
2586
            string result = string.Empty;
2587
2588
            if (EnableType(StartType) && EnableType(EndType))
2589
            {
2590
                if (StartType == PSNType.Equipment && EndType == PSNType.Equipment)
2591
                    result = "E2E";
2592
                else if (StartType == PSNType.Branch && EndType == PSNType.Branch)
2593
                    result = "B2B";
2594
                else if (StartType == PSNType.Header && EndType == PSNType.Header)
2595
                    result = "HD2";
2596
2597
                else if (StartType == PSNType.Equipment && EndType == PSNType.Branch)
2598
                    result = "E2B";
2599
                else if (StartType == PSNType.Branch && EndType == PSNType.Equipment)
2600
                    result = "B2E";
2601
2602
                else if (StartType == PSNType.Header && EndType == PSNType.Branch)
2603
                    result = "HDB";
2604
                else if (StartType == PSNType.Branch && EndType == PSNType.Header)
2605
                    result = "HDB";
2606
2607
                else if (StartType == PSNType.Header && EndType == PSNType.Equipment)
2608
                    result = "HDE";
2609
                else if (StartType == PSNType.Equipment && EndType == PSNType.Header)
2610
                    result = "HDE";
2611
                else
2612
                    result = "Error";
2613
            }
2614
            else
2615
                result = "Error";
2616
2617
            return result;
2618
2619 7106e181 LJIYEON
2620 94a117ca gaqhf
        }
2621 3610fd3f LJIYEON
2622 710a49f1 gaqhf
        public bool EnableType(PSNType type)
2623 94a117ca gaqhf
        {
2624
            bool result = false;
2625
2626
            if (type == PSNType.Branch ||
2627
                type == PSNType.Equipment ||
2628
                type == PSNType.Header)
2629
            {
2630
                result = true;
2631
            }
2632
2633
            return result;
2634
        }
2635 3610fd3f LJIYEON
2636 7881ec8f gaqhf
        public bool IsBypass { get; set; }
2637 94a117ca gaqhf
2638 a5616391 LJIYEON
        public string GetFromData(ref string Type, ref Item item)
2639 94a117ca gaqhf
        {
2640 51974d2b LJIYEON
            Status = string.Empty;
2641 94a117ca gaqhf
            string result = string.Empty;
2642 a36541fb LJIYEON
            if (IsKeyword)
2643
                IsKeyword = false;
2644 27d06aa8 LJIYEON
            try
2645 36a45f13 gaqhf
            {
2646 08b33e44 gaqhf
                item = Groups.First().Items.First();
2647
2648 27d06aa8 LJIYEON
                if (StartType == PSNType.Header)
2649
                    result = "ENDOFHEADER";
2650
                else if (StartType == PSNType.Branch)
2651
                {
2652 48870200 LJIYEON
                    //if (!item.MissingLineNumber && item.Relations.First().Item.LineNumber != null && !string.IsNullOrEmpty(item.Relations.First().Item.LineNumber.Name))
2653 f2a63376 이지연
                    if (!item.MissingLineNumber2 && item.Relations.First().Item.LineNumber != null && !string.IsNullOrEmpty(item.Relations.First().Item.LineNumber.Name))
2654 27d06aa8 LJIYEON
                        result = item.Relations.First().Item.LineNumber.Name;
2655
                    else
2656
                    {
2657 7106e181 LJIYEON
                        IsValid = "Error";
2658 51974d2b LJIYEON
                        Status += ", Missing LineNumber_2";
2659 27d06aa8 LJIYEON
                        result = "Empty LineNumber";
2660
                    }
2661 48870200 LJIYEON
2662
                    //if (item.MissingLineNumber1)
2663
                    //{
2664
                    //    Status += ", Missing LineNumber_1";
2665
                    //    result = item.MissingLineNumber1 && item.LineNumber != null && !string.IsNullOrEmpty(item.LineNumber.Name) ? item.LineNumber.Name : "Empty LineNumber";
2666
2667
                    //}
2668 27d06aa8 LJIYEON
                }
2669
                else if (StartType == PSNType.Equipment)
2670 a36541fb LJIYEON
                {
2671 3210f690 LJIYEON
                    if (Groups.First().Items.First().Equipment != null)
2672
                        result = Groups.First().Items.First().Equipment.ItemTag;
2673 a36541fb LJIYEON
                    DataRow drNozzle = Nozzle.Select(string.Format("OID = '{0}'", Groups.First().Items.First().UID)).FirstOrDefault();
2674
2675
                    if (drNozzle != null)
2676 7106e181 LJIYEON
                        result += " [" + drNozzle.Field<string>("ITEMTAG") + "]";
2677
                }
2678 36a45f13 gaqhf
                else
2679
                {
2680 72775f2e LJIYEON
                    IsValid = "Error";
2681 a5616391 LJIYEON
                    item = Groups.First().Items.First();
2682 27d06aa8 LJIYEON
                    if (item.ItemType == ItemType.Symbol)
2683
                    {
2684 7106e181 LJIYEON
2685 8ab98ea3 LJIYEON
                        string keyword = string.Empty;
2686 a5616391 LJIYEON
                        keyword = GetFromKeywordData(ref Type, item);
2687 8ab98ea3 LJIYEON
2688
                        if (string.IsNullOrEmpty(keyword))
2689
                        {
2690
                            if (item.ID2DBType.Contains("OPC's"))
2691 51974d2b LJIYEON
                                Status += ", OPC Disconnected";
2692 8ab98ea3 LJIYEON
                            else
2693
                                Status += ", Missing ItemTag or Description";
2694
2695
                            result = item.ID2DBName;
2696
                        }
2697
                        else
2698 eb44d82c LJIYEON
                        {
2699 8ab98ea3 LJIYEON
                            result = keyword;
2700 a36541fb LJIYEON
                            IsKeyword = true;
2701
                            IsValid = string.Empty;
2702 eb44d82c LJIYEON
                        }
2703 7106e181 LJIYEON
2704 27d06aa8 LJIYEON
                    }
2705
                    else if (item.ItemType == ItemType.Line)
2706
                    {
2707 7106e181 LJIYEON
2708 48870200 LJIYEON
                        if (item.MissingLineNumber1)
2709
                        {
2710 7106e181 LJIYEON
                            IsValid = "Error";
2711 48870200 LJIYEON
                            Status += ", Missing LineNumber_1";
2712
                            result = item.MissingLineNumber1 && item.LineNumber != null && !string.IsNullOrEmpty(item.LineNumber.Name) ? item.LineNumber.Name : "Empty LineNumber";
2713
                        }
2714 27d06aa8 LJIYEON
                    }
2715
                    else
2716
                        result = "Unknown";
2717 48870200 LJIYEON
2718 36a45f13 gaqhf
                }
2719
            }
2720 7106e181 LJIYEON
            catch (Exception ex)
2721 36a45f13 gaqhf
            {
2722
2723
            }
2724 94a117ca gaqhf
2725
            return result;
2726
        }
2727
2728 a5616391 LJIYEON
        public string GetFromKeywordData(ref string Type, Item item)
2729 879ce10b LJIYEON
        {
2730
            string result = string.Empty;
2731 7106e181 LJIYEON
2732
            foreach (KeywordItem keyitem in KeywordInfos.KeywordItems)
2733 879ce10b LJIYEON
            {
2734 7106e181 LJIYEON
                if (keyitem.Name.Equals(item.Name))
2735 a5616391 LJIYEON
                {
2736 eb44d82c LJIYEON
                    result = keyitem.Keyword;
2737 a5616391 LJIYEON
                    Type = item.ID2DBType;
2738 a2973aa3 LJIYEON
                    break;
2739 a5616391 LJIYEON
                }
2740 879ce10b LJIYEON
            }
2741 7106e181 LJIYEON
2742 879ce10b LJIYEON
            return result;
2743
        }
2744
2745 a5616391 LJIYEON
        public string GetToKeywordData(ref string Type, Item item)
2746 879ce10b LJIYEON
        {
2747
            string result = string.Empty;
2748
2749 eb44d82c LJIYEON
            foreach (KeywordItem keyitem in KeywordInfos.KeywordItems)
2750 879ce10b LJIYEON
            {
2751 eb44d82c LJIYEON
                if (keyitem.Name.Equals(item.Name))
2752 a5616391 LJIYEON
                {
2753 eb44d82c LJIYEON
                    result = keyitem.Keyword;
2754 a5616391 LJIYEON
                    Type = item.ID2DBType;
2755 a2973aa3 LJIYEON
                    break;
2756 a5616391 LJIYEON
                }
2757 879ce10b LJIYEON
            }
2758
            return result;
2759
        }
2760
2761 a5616391 LJIYEON
        public string GetToData(ref string ToType, ref Item item)
2762 94a117ca gaqhf
        {
2763
            string result = string.Empty;
2764 51974d2b LJIYEON
            Status = string.Empty;
2765 eb44d82c LJIYEON
2766 a2973aa3 LJIYEON
            if (IsKeyword)
2767
                IsKeyword = false;
2768 3210f690 LJIYEON
2769 08b33e44 gaqhf
            item = Groups.Last().Items.Last();
2770
2771 a2973aa3 LJIYEON
            if (EndType == PSNType.Header)
2772
                result = "ENDOFHEADER";
2773
            else if (EndType == PSNType.Branch)
2774
            {
2775 7106e181 LJIYEON
2776 08b33e44 gaqhf
                
2777 48870200 LJIYEON
                //if (!item.MissingLineNumber && item.Relations.Last().Item.LineNumber != null && !string.IsNullOrEmpty(item.Relations.Last().Item.LineNumber.Name))
2778 f2a63376 이지연
                if (!item.MissingLineNumber2 && item.Relations.Last().Item.LineNumber != null && !string.IsNullOrEmpty(item.Relations.Last().Item.LineNumber.Name))
2779 a2973aa3 LJIYEON
                    result = item.Relations.Last().Item.LineNumber.Name;
2780
                else
2781 36a45f13 gaqhf
                {
2782 7106e181 LJIYEON
                    IsValid = "Error";
2783 51974d2b LJIYEON
                    Status += ", Missing LineNumber_2";
2784 a2973aa3 LJIYEON
                    result = "Empty LineNumber";
2785 36a45f13 gaqhf
                }
2786 48870200 LJIYEON
2787
                //if (item.MissingLineNumber1)
2788
                //{
2789
                //    Status += ", Missing LineNumber_1";
2790
                //    result = item.MissingLineNumber1 && item.LineNumber != null && !string.IsNullOrEmpty(item.LineNumber.Name) ? item.LineNumber.Name : "Empty LineNumber";
2791
2792
                //}
2793 a2973aa3 LJIYEON
            }
2794
            else if (EndType == PSNType.Equipment)
2795
            {
2796 7106e181 LJIYEON
                if (Groups.Last().Items.Last().Equipment != null)
2797 a2973aa3 LJIYEON
                    result = Groups.Last().Items.Last().Equipment.ItemTag;
2798 8ab98ea3 LJIYEON
2799 a2973aa3 LJIYEON
                DataRow drNozzle = Nozzle.Select(string.Format("OID = '{0}'", Groups.Last().Items.Last().UID)).FirstOrDefault();
2800 3210f690 LJIYEON
2801 a2973aa3 LJIYEON
                if (drNozzle != null)
2802
                    result += " [" + drNozzle.Field<string>("ITEMTAG") + "]";
2803
            }
2804
            else
2805
            {
2806
                IsValid = "Error";
2807
                item = Groups.Last().Items.Last();
2808
                if (item.ItemType == ItemType.Symbol)
2809 3210f690 LJIYEON
                {
2810 a2973aa3 LJIYEON
                    string keyword = string.Empty;
2811
                    keyword = GetToKeywordData(ref ToType, item);
2812 3210f690 LJIYEON
2813 a2973aa3 LJIYEON
                    if (string.IsNullOrEmpty(keyword))
2814
                    {
2815
                        if (item.ID2DBType.Contains("OPC's"))
2816 51974d2b LJIYEON
                            Status += ", OPC Disconnected";
2817 8ab98ea3 LJIYEON
                        else
2818 a2973aa3 LJIYEON
                            Status += ", Missing ItemTag or Description";
2819 8ab98ea3 LJIYEON
2820 a2973aa3 LJIYEON
                        result = item.ID2DBName;
2821 8ab98ea3 LJIYEON
                    }
2822 a2973aa3 LJIYEON
                    else
2823 eb44d82c LJIYEON
                    {
2824 a2973aa3 LJIYEON
                        result = keyword;
2825
                        IsValid = string.Empty;
2826
                        IsKeyword = true;
2827 eb44d82c LJIYEON
                    }
2828 a2973aa3 LJIYEON
2829
                }
2830
                else if (item.ItemType == ItemType.Line)
2831
                {
2832 48870200 LJIYEON
                    if (item.MissingLineNumber1)
2833
                    {
2834 7106e181 LJIYEON
                        IsValid = "Error";
2835 48870200 LJIYEON
                        Status += ", Missing LineNumber_1";
2836
                        result = item.MissingLineNumber1 && item.LineNumber != null && !string.IsNullOrEmpty(item.LineNumber.Name) ? item.LineNumber.Name : "Empty LineNumber";
2837
                    }
2838 36a45f13 gaqhf
                }
2839 a2973aa3 LJIYEON
                else
2840
                    result = "Unknown";
2841 7106e181 LJIYEON
2842
2843 a2973aa3 LJIYEON
            }
2844 7106e181 LJIYEON
2845
2846
2847 94a117ca gaqhf
            return result;
2848
        }
2849 7881ec8f gaqhf
2850
        public string GetPBSData()
2851
        {
2852
            string result = string.Empty;
2853
            List<string> PBSList = new List<string>();
2854
            if (Settings.Default.PBSSetting.Equals("Line Number"))
2855
            {
2856
                string attrValue = Settings.Default.PBSSettingValue;
2857
2858
                foreach (Group group in Groups)
2859
                {
2860 7106e181 LJIYEON
                    List<LineNumber> lineNumbers = group.Items.Select(x => x.LineNumber).Distinct().ToList();
2861 7881ec8f gaqhf
                    foreach (LineNumber lineNumber in lineNumbers)
2862
                    {
2863
                        Attribute attribute = lineNumber.Attributes.Find(x => x.Name == attrValue && !string.IsNullOrEmpty(x.Value));
2864
                        if (attribute != null)
2865
                        {
2866
                            string value = attribute.Value;
2867
                            if (!PBSList.Contains(value))
2868
                                PBSList.Add(value);
2869
                        }
2870
                    }
2871
                }
2872
            }
2873
            else if (Settings.Default.PBSSetting.Equals("Item Attribute"))
2874
            {
2875
                string attrValue = Settings.Default.PBSSettingValue;
2876
2877
                foreach (Group group in Groups)
2878
                {
2879
                    List<Item> items = group.Items.FindAll(x => x.Attributes.Find(y => y.Name == attrValue && !string.IsNullOrEmpty(y.Value)) != null);
2880
                    foreach (Item item in items)
2881
                    {
2882
                        string value = item.Attributes.Find(x => x.Name == attrValue).Value;
2883
                        if (!PBSList.Contains(value))
2884
                            PBSList.Add(value);
2885
                    }
2886
                }
2887
            }
2888
            else if (Settings.Default.PBSSetting.Equals("Drawing No"))
2889
            {
2890
                string attrValue = Settings.Default.PBSSettingValue;
2891
2892
                foreach (Group group in Groups)
2893
                {
2894
                    List<Document> documents = group.Items.Select(x => x.Document).Distinct().ToList();
2895
                    foreach (Document document in documents)
2896
                    {
2897
                        string name = document.DrawingName;
2898
2899
                        int startIndex = Settings.Default.PBSSettingStartValue;
2900
                        int endIndex = Settings.Default.PBSSettingEndValue;
2901
2902
                        string subStr = name.Substring(startIndex - 1, endIndex - startIndex + 1);
2903
                        if (!PBSList.Contains(subStr))
2904
                            PBSList.Add(subStr);
2905
                    }
2906
                }
2907
            }
2908
            else if (Settings.Default.PBSSetting.Equals("Unit Area"))
2909
            {
2910
                foreach (Group group in Groups)
2911
                {
2912
                    List<Document> documents = group.Items.Select(x => x.Document).Distinct().ToList();
2913
                    foreach (Document document in documents)
2914
                    {
2915
                        List<TextInfo> textInfos = document.TextInfos.FindAll(x => x.Area == "Unit");
2916
                        foreach (TextInfo textInfo in textInfos)
2917
                        {
2918
                            if (!PBSList.Contains(textInfo.Value))
2919
                                PBSList.Add(textInfo.Value);
2920
                        }
2921
                    }
2922
                }
2923
            }
2924
2925
            foreach (var item in PBSList)
2926
            {
2927
                if (string.IsNullOrEmpty(result))
2928
                    result = item;
2929
                else
2930
                    result += ", " + item;
2931
            }
2932
            return result;
2933
        }
2934 6b9e7a56 gaqhf
    }
2935
}
클립보드 이미지 추가 (최대 크기: 500 MB)