프로젝트

일반

사용자정보

개정판 3210f690

ID3210f6904c888a72967452a56bb11e2a27b9395d
상위 bb08c325
하위 6d50141d

이지연이(가) 3년 이상 전에 추가함

issue #000: PSN

Change-Id: I8feaf4df24a663e7ec10fe8249d0704a704808fb

차이점 보기:

DTI_PID/ID2PSN/DB.cs
28 28
        const string PSN_PIPELINE = "SPPIDPipeLine";
29 29
        //2021.11.26 추가
30 30
        const string PSN_INSULATIONPURPOSE = "SPPIDInsulationPurpose";
31
        //2021.12.01 추가
32
        const string PSN_REVISION_HISTORY = "T_PSN_REVISION_HISTORY";
31 33
        /// <summary>
32 34
        ///  ID2 Project.db 데이터를 가져온다. 
33 35
        ///  DB 접속 정보 및 DBType (Sqlite, Mssql) 정보를 가져옴
......
416 418

  
417 419
            return dt;
418 420
        }
419

  
420

  
421
        
421 422
        public static DataTable SelectInsulationPurpose()
422 423
        {
423 424
            DataTable dt = null;
......
1426 1427

  
1427 1428
            return result;
1428 1429
        }
1430

  
1429 1431
        public static PSN GetDBPSN()
1430 1432
        {
1431 1433
            PSN result = new PSN();
......
1435 1437
            {
1436 1438
                try
1437 1439
                {
1438
                    //var query = $"SELECT * FROM {PSN_PIPESYSTEMNETWORK} WHERE PSNRevisionNumber = '{string.Format("V{0:D4}", GetRevision())}'";
1440
                    //query = $"SELECT * FROM {PSN_PIPESYSTEMNETWORK}";
1439 1441
                    //using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1440 1442
                    //{
1441
                    //    result.PipeSystemNetwork = ds.Tables[0].Clone();
1442
                    //    result.PipeSystemNetwork.Columns["IsValid"].DataType = typeof(string);
1443

  
1444
                    //    foreach (DataRow row in ds.Tables[0].Rows)
1445
                    //    {
1446
                    //        DataRow newRow = result.PipeSystemNetwork.NewRow();
1447
                    //        newRow["OID"] = row["OID"].ToString();
1448
                    //        newRow["Type"] = row["Type"].ToString();
1449
                    //        newRow["OrderNumber"] = row["OrderNumber"].ToString();
1450
                    //        newRow["Pipeline_OID"] = row["Pipeline_OID"].ToString();
1451
                    //        newRow["FROM_DATA"] = row["FROM_DATA"].ToString();
1452
                    //        newRow["TO_DATA"] = row["TO_DATA"].ToString();
1453
                    //        newRow["TopologySet_OID_Key"] = row["TopologySet_OID_Key"].ToString();
1454
                    //        newRow["PSNRevisionNumber"] = row["PSNRevisionNumber"].ToString();
1455
                           
1456
                    //        string IsValid = string.Empty;
1457

  
1458
                    //        if (Convert.ToInt32(row["IsValid"].ToString()) == 0)
1459
                    //            IsValid = string.Empty;//"OK";
1460
                    //        else if (Convert.ToInt32(row["IsValid"].ToString()) == 1)
1461
                    //            IsValid = "InValid";
1462
                    //        else if (Convert.ToInt32(row["IsValid"].ToString()) == -1)
1463
                    //            IsValid = "Error";
1464

  
1465
                    //        newRow["IsValid"] = IsValid;
1466

  
1467
                    //        newRow["Status"] = row["Status"].ToString();
1468
                    //        newRow["PBS"] = row["PBS"].ToString();
1469
                    //        newRow["Drawings"] = row["Drawings"].ToString();
1470

  
1471
                    //        newRow["IncludingVirtualData"] = row["IncludingVirtualData"].ToString();
1472
                    //        newRow["PSNAccuracy"] = row["PSNAccuracy"].ToString();
1473

  
1474
                    //        result.PipeSystemNetwork.Rows.Add(newRow);
1475
                    //    }
1443
                    //    result.PipeSystemNetwork = ds.Tables[0].Copy();
1476 1444
                    //}
1477 1445

  
1478
                    var query = $"SELECT * FROM {PSN_EQUIPMENT}";
1446
                    var query = $"SELECT * FROM {PSN_PIPESYSTEMNETWORK} WHERE PSNRevisionNumber = '{string.Format("V{0:D4}", GetRevision())}'";
1447
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1448
                    {
1449
                        result.PipeSystemNetwork = ds.Tables[0].Clone();
1450
                        result.PipeSystemNetwork.Columns["IsValid"].DataType = typeof(string);
1451

  
1452
                        foreach (DataRow row in ds.Tables[0].Rows)
1453
                        {
1454
                            DataRow newRow = result.PipeSystemNetwork.NewRow();
1455
                            newRow["OID"] = row["OID"].ToString();
1456
                            newRow["Type"] = row["Type"].ToString();
1457
                            newRow["OrderNumber"] = row["OrderNumber"].ToString();
1458
                            newRow["Pipeline_OID"] = row["Pipeline_OID"].ToString();
1459
                            newRow["FROM_DATA"] = row["FROM_DATA"].ToString();
1460
                            newRow["TO_DATA"] = row["TO_DATA"].ToString();
1461
                            newRow["TopologySet_OID_Key"] = row["TopologySet_OID_Key"].ToString();
1462
                            newRow["PSNRevisionNumber"] = row["PSNRevisionNumber"].ToString();
1463

  
1464
                            string IsValid = string.Empty;
1465

  
1466
                            if (Convert.ToInt32(row["IsValid"].ToString()) == 0)
1467
                                IsValid = string.Empty;//"OK";
1468
                            else if (Convert.ToInt32(row["IsValid"].ToString()) == 1)
1469
                                IsValid = "InValid";
1470
                            else if (Convert.ToInt32(row["IsValid"].ToString()) == -1)
1471
                                IsValid = "Error";
1472

  
1473
                            newRow["IsValid"] = IsValid;
1474

  
1475
                            newRow["Status"] = row["Status"].ToString();
1476
                            newRow["PBS"] = row["PBS"].ToString();
1477
                            newRow["Drawings"] = row["Drawings"].ToString();
1478

  
1479
                            newRow["IncludingVirtualData"] = row["IncludingVirtualData"].ToString();
1480
                            newRow["PSNAccuracy"] = row["PSNAccuracy"].ToString();
1481

  
1482
                            result.PipeSystemNetwork.Rows.Add(newRow);
1483
                        }
1484
                    }
1485

  
1486
                    query = $"SELECT * FROM {PSN_EQUIPMENT}";
1479 1487
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1480 1488
                    {
1481 1489
                        result.Equipment = ds.Tables[0].Copy();
......
1505 1513
                        result.TopologySet = ds.Tables[0].Copy();
1506 1514
                    }
1507 1515

  
1516
                   
1517

  
1508 1518
                    query = $"SELECT * FROM {PSN_PIPELINE}";
1509 1519
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1510 1520
                    {
DTI_PID/ID2PSN/Form/MainForm.cs
259 259

  
260 260
        private void btnSave_Click(object sender, EventArgs e)
261 261
        {
262
            if (currentPSN == null)
262
            try
263 263
            {
264
                MessageBox.Show("There is no data to save.", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
265
                return;
266
            }
264
                if (currentPSN == null)
265
                {
266
                    MessageBox.Show("There is no data to save.", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
267
                    return;
268
                }
267 269

  
268
            CheckEquipment();
270
                splashScreenManager1.ShowWaitForm();
271
                splashScreenManager1.SetWaitFormCaption("Save PSN..");
272
                splashScreenManager1.SetWaitFormDescription("Wating...");
269 273

  
270
            if (DB.SavePSNData(currentPSN))
271
                MessageBox.Show("Save was successful.", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
272
            else
273
                MessageBox.Show("Failed to save.", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Error);
274
                CheckEquipment();
274 275

  
275
            void CheckEquipment()
276
                if (DB.SavePSNData(currentPSN))
277
                {
278
                    splashScreenManager1.CloseWaitForm();
279
                    MessageBox.Show("Save was successful.", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
280
                }
281
                else
282
                {
283
                    splashScreenManager1.CloseWaitForm();
284
                    MessageBox.Show("Failed to save.", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Error);
285
                }
286

  
287
                void CheckEquipment()
288
                {
289
                    DataTable psnDT = currentPSN.PipeSystemNetwork;
290
                }
291
            }
292
            catch (Exception ex)
276 293
            {
277
                DataTable psnDT = currentPSN.PipeSystemNetwork;
294
                splashScreenManager1.CloseWaitForm();
295
                MessageBox.Show(ex.Message, "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Error);
278 296
            }
279 297
        }
280 298

  
DTI_PID/ID2PSN/PSN.cs
326 326
                            }
327 327
                        }
328 328

  
329
                        Attribute insulAttr = item.LineNumber.Attributes.Find(x => x.Name == "InsulationPurpose");
330
                        if (insulAttr != null && !string.IsNullOrEmpty(insulAttr.Value))
331
                            pipeLineID.Add(insulAttr.Value); //item.PSNPipeLineID = item.TopologyData + "-" + insulAttr.Value;
332
                        //else
333
                        //    item.PSNPipeLineID = item.TopologyData;
329
                        if(topologyRuleDT.Select(string.Format("UID = '{0}'", "InsulationPurpose")) == null)
330
                        {
331
                            Attribute insulAttr = item.LineNumber.Attributes.Find(x => x.Name == "InsulationPurpose");
332
                            if (insulAttr != null && !string.IsNullOrEmpty(insulAttr.Value))
333
                                pipeLineID.Add(insulAttr.Value); //item.PSNPipeLineID = item.TopologyData + "-" + insulAttr.Value;
334
                                                                 //else
335
                                                                 //    item.PSNPipeLineID = item.TopologyData;
336
                        }
337

  
334 338
                        item.PSNPipeLineID = string.Join("-", pipeLineID);
335 339
                        item.TopologyData = string.Join("-", pipeLineID);
336 340
                    }
......
879 883
                    Equipment equipment = equipments.Find(x => x.UID == relation.UID);
880 884
                    equipment.Nozzles.Add(item);
881 885
                    row["ITEMTAG"] = string.Format("N{0}", string.Format("{0:D3}", equipment.Nozzles.Count + 100));
882
                    row["Equipment_OID"] = equipment.UID;
886
                    row["Equipment_OID"] = equipment.UID; 
883 887
                    item.Equipment = equipment;
884 888
                }
885 889
                row["XCOORDS"] = (item.POINT[0] / DrawingWidth).ToString();
......
1051 1055
                // key = 미입력 branch
1052 1056
                Dictionary<Item, Item> startBranchDic = new Dictionary<Item, Item>();
1053 1057
                Dictionary<Item, Item> endBranchDic = new Dictionary<Item, Item>();
1058
                List<Group> lstventdrainGroup = new List<Group>();
1054 1059

  
1055 1060
                foreach (PSNItem PSNItem in PSNItems)
1056 1061
                {
1057
                    int psnOrder = 0;
1058
                    int index = 0;
1059
                    bool bPSNStart = true;
1060
                    string sPSNData = string.Empty;
1061
                    bool bVentDrain = false;
1062

  
1063
                    //VentDrain 검사
1064
                    if (PSNItem.Groups.Count.Equals(1))
1062
                    try
1065 1063
                    {
1066
                        List<VentDrainInfo> endInfos = new List<VentDrainInfo>();
1067
                        Group group = PSNItem.Groups[0];
1068
                        for (int i = 0; i < group.Items.Count; i++)
1064
                        int psnOrder = 0;
1065
                        int index = 0;
1066
                        bool bPSNStart = true;
1067
                        string sPSNData = string.Empty;
1068
                        bool bVentDrain = false;
1069

  
1070
                        //VentDrain 검사
1071
                        if (PSNItem.Groups.Count.Equals(1))
1069 1072
                        {
1070
                            Item item = group.Items[i];
1071
                            foreach (VentDrainInfo ventDrainInfo in VentDrainInfos)
1072
                            {
1073
                                if (endInfos.Contains(ventDrainInfo) || ventDrainInfo.VentDrainItems.Count != group.Items.Count)
1074
                                    continue;
1075
                                if (!ventDrainInfo.VentDrainItems[i].Name.Equals(item.Name))
1076
                                {
1077
                                    endInfos.Add(ventDrainInfo);
1078
                                    continue;
1079
                                }
1080

  
1081
                                if (i + 1 == group.Items.Count && group.Items.Count.Equals(ventDrainInfo.VentDrainItems.Count))
1082
                                    bVentDrain = true;
1083
                            }
1084
                        }
1085

  
1086
                        if (!bVentDrain)
1087
                        {
1088
                            endInfos = new List<VentDrainInfo>();
1073
                            List<VentDrainInfo> endInfos = new List<VentDrainInfo>();
1074
                            Group group = PSNItem.Groups[0];
1089 1075
                            for (int i = 0; i < group.Items.Count; i++)
1090 1076
                            {
1091
                                Item item = group.Items[group.Items.Count - i - 1];
1077
                                Item item = group.Items[i];
1092 1078
                                foreach (VentDrainInfo ventDrainInfo in VentDrainInfos)
1093 1079
                                {
1094 1080
                                    if (endInfos.Contains(ventDrainInfo) || ventDrainInfo.VentDrainItems.Count != group.Items.Count)
......
1100 1086
                                    }
1101 1087

  
1102 1088
                                    if (i + 1 == group.Items.Count && group.Items.Count.Equals(ventDrainInfo.VentDrainItems.Count))
1089
                                    {
1103 1090
                                        bVentDrain = true;
1091
                                       
1092
                                        if (!lstventdrainGroup.Contains(group))
1093
                                            lstventdrainGroup.Add(group);
1094
                                    }
1104 1095
                                }
1105 1096
                            }
1106
                        }
1107
                    }
1108 1097

  
1109
                    //foreach (KeywordInfo keywordInfo in KeywordInfos)
1110
                    //    keywordInfo.KeywordItems = keywordInfo.KeywordItems.OrderBy(x => x.Index).ToList();
1111

  
1112
                    try
1113
                    {
1114
                        //PSN, PathItems, SequenceData 관련
1115
                        foreach (Group group in PSNItem.Groups)
1116
                        {
1117
                            foreach (Item item in group.Items)
1098
                            if (!bVentDrain)
1118 1099
                            {
1119
                                if (item.BranchItems.Count == 0)
1100
                                endInfos = new List<VentDrainInfo>();
1101
                                for (int i = 0; i < group.Items.Count; i++)
1120 1102
                                {
1121
                                    CreatePathItemsDataRow(item.UID, item.ID2DBType);
1122
                                    CreateSequenceDataDataRow(item.UID);
1123
                                    index++;
1124
                                }
1125
                                else
1126
                                {
1127
                                    CreatePathItemsDataRow(item.UID + "_L1", item.ID2DBType);
1128
                                    CreateSequenceDataDataRow(item.UID + "_L1");
1129
                                    index++;
1130
                                    for (int i = 0; i < item.BranchItems.Count; i++)
1103
                                    Item item = group.Items[group.Items.Count - i - 1];
1104
                                    foreach (VentDrainInfo ventDrainInfo in VentDrainInfos)
1131 1105
                                    {
1132
                                        CreatePathItemsDataRow(string.Format(item.UID + "_B{0}", i + 1), "Branch", item.BranchItems[i].Topology.FullName, item.BranchItems[i]);
1133
                                        CreateSequenceDataDataRow(string.Format(item.UID + "_B{0}", i + 1));
1134
                                        index++;
1135

  
1136
                                        CreatePathItemsDataRow(string.Format(item.UID + "_L{0}", i + 2), item.ID2DBType);
1137
                                        CreateSequenceDataDataRow(string.Format(item.UID + "_L{0}", i + 2));
1138
                                        index++;
1139

  
1140
                                        if (item.BranchItems[i].Relations[0].Item != null && item.BranchItems[i].Relations[0].Item == item)
1141
                                            startBranchDic.Add(item.BranchItems[i], item);
1142
                                        else if (item.BranchItems[i].Relations[1].Item != null && item.BranchItems[i].Relations[1].Item == item)
1143
                                            endBranchDic.Add(item.BranchItems[i], item);
1144
                                    }
1145
                                }
1106
                                        if (endInfos.Contains(ventDrainInfo) || ventDrainInfo.VentDrainItems.Count != group.Items.Count)
1107
                                            continue;
1108
                                        if (!ventDrainInfo.VentDrainItems[i].Name.Equals(item.Name))
1109
                                        {
1110
                                            endInfos.Add(ventDrainInfo);
1111
                                            continue;
1112
                                        }
1146 1113

  
1147
                                if (bPSNStart)
1148
                                {
1149
                                    CreatePipeSystemNetworkDataRow();
1150
                                    sPSNData = item.TopologyData;
1151
                                    psnOrder++;
1152
                                    bPSNStart = false;
1153
                                }
1154
                                else
1155
                                {
1156
                                    if (item.TopologyData != sPSNData)
1157
                                    {
1158
                                        CreatePipeSystemNetworkDataRow();
1159
                                        sPSNData = item.TopologyData;
1160
                                        psnOrder++;
1114
                                        if (i + 1 == group.Items.Count && group.Items.Count.Equals(ventDrainInfo.VentDrainItems.Count))
1115
                                        {
1116
                                            bVentDrain = true;
1117
                                           
1118
                                            if (!lstventdrainGroup.Contains(group))
1119
                                                lstventdrainGroup.Add(group);
1120
                                        }
1161 1121
                                    }
1162 1122
                                }
1163
                                void CreatePathItemsDataRow(string itemOID, string itemType, string branchTopologyName = "", Item branchItem = null)
1123
                            }
1124
                        }
1125

  
1126
                        //foreach (KeywordInfo keywordInfo in KeywordInfos)
1127
                        //    keywordInfo.KeywordItems = keywordInfo.KeywordItems.OrderBy(x => x.Index).ToList();
1128

  
1129
                        if (!bVentDrain)
1130
                        {
1131
                            try
1132
                            {
1133
                                //try
1134
                                //{ 
1135
                                //PSN, PathItems, SequenceData 관련
1136
                                foreach (Group group in PSNItem.Groups)
1164 1137
                                {
1165
                                    DataRow newRow = pathItemsDT.NewRow();
1166 1138

  
1167
                                    if(itemType == "Nozzles")
1139

  
1140
                                    foreach (Item item in group.Items)
1168 1141
                                    {
1169
                                        newRow["Equipment_OID"] = item.Equipment.UID;
1170
                                    }
1142
                                        if (item.BranchItems.Count == 0)
1143
                                        {
1144
                                            CreatePathItemsDataRow(item.UID, item.ID2DBType);
1145
                                            CreateSequenceDataDataRow(item.UID);
1146
                                            index++;
1147
                                        }
1148
                                        else
1149
                                        {
1150
                                            CreatePathItemsDataRow(item.UID + "_L1", item.ID2DBType);
1151
                                            CreateSequenceDataDataRow(item.UID + "_L1");
1152
                                            index++;
1153
                                            for (int i = 0; i < item.BranchItems.Count; i++)
1154
                                            {
1155
                                                CreatePathItemsDataRow(string.Format(item.UID + "_B{0}", i + 1), "Branch", item.BranchItems[i].Topology.FullName, item.BranchItems[i]);
1156
                                                CreateSequenceDataDataRow(string.Format(item.UID + "_B{0}", i + 1));
1157
                                                index++;
1158
                                                
1159
                                                CreatePathItemsDataRow(string.Format(item.UID + "_L{0}", i + 2), item.ID2DBType);
1160
                                                CreateSequenceDataDataRow(string.Format(item.UID + "_L{0}", i + 2));
1161
                                                index++;
1162

  
1163
                                                if (item.BranchItems[i].Relations[0].Item != null && item.BranchItems[i].Relations[0].Item == item)
1164
                                                    startBranchDic.Add(item.BranchItems[i], item);
1165
                                                else if (item.BranchItems[i].Relations[1].Item != null && item.BranchItems[i].Relations[1].Item == item)
1166
                                                    endBranchDic.Add(item.BranchItems[i], item);
1167
                                            }
1168
                                        }
1171 1169

  
1172
                                    newRow["OID"] = itemOID;
1170
                                        if (bPSNStart)
1171
                                        {
1172
                                            CreatePipeSystemNetworkDataRow();
1173
                                            sPSNData = item.TopologyData;
1174
                                            psnOrder++;
1175
                                            bPSNStart = false;
1176
                                        }
1177
                                        else
1178
                                        {
1179
                                            if (item.TopologyData != sPSNData)
1180
                                            {
1181
                                                CreatePipeSystemNetworkDataRow();
1182
                                                sPSNData = item.TopologyData;
1183
                                                psnOrder++;
1184
                                            }
1185
                                        }
1186
                                        void CreatePathItemsDataRow(string itemOID, string itemType, string branchTopologyName = "", Item branchItem = null)
1187
                                        {
1188
                                            DataRow newRow = pathItemsDT.NewRow();
1173 1189

  
1174
                                    newRow["SequenceData_OID"] = string.Format(item.Topology.FullName + "_{0}", index);
1190
                                            if (itemType == "Nozzles")
1191
                                            {
1192
                                                newRow["Equipment_OID"] = item.Equipment.UID;
1193
                                            }
1175 1194

  
1176
                                    newRow["TopologySet_OID"] = item.Topology.FullName;
1195
                                            newRow["OID"] = itemOID;
1177 1196

  
1178
                                    newRow["BranchTopologySet_OID"] = branchTopologyName;
1179
                                    newRow["PipeLine_OID"] = item.PSNPipeLineID;
1180
                                    newRow["ITEMNAME"] = GetItemName(item, itemOID);
1181
                                    newRow["ITEMTAG"] = GetItemTag(item);
1182
                                    newRow["Class"] = GetClass(item, itemOID);
1183
                                    newRow["SubClass"] = GetSubClass(item, itemOID);
1197
                                            newRow["SequenceData_OID"] = string.Format(item.Topology.FullName + "_{0}", index);
1184 1198

  
1185
                                    if (item.ItemType == ItemType.Symbol)
1186
                                        newRow["TYPE"] = item.ID2DBName;
1187
                                    else if (item.ItemType == ItemType.Line)
1188
                                        newRow["TYPE"] = item.ID2DBType;
1189
                                    newRow["PIDNAME"] = group.Document.DrawingName;
1199
                                            newRow["TopologySet_OID"] = item.Topology.FullName;
1190 1200

  
1191
                                    // NPD
1192
                                    if (item.LineNumber != null)
1193
                                    {
1194
                                        Attribute attribute = item.LineNumber.Attributes.Find(x => x.Name == "NominalDiameter");
1195
                                        if (attribute != null)
1196
                                            newRow["NPD"] = attribute.Value;
1197
                                    }
1198
                                    else
1199
                                        newRow["NPD"] = null;
1201
                                            newRow["BranchTopologySet_OID"] = branchTopologyName;
1202
                                            newRow["PipeLine_OID"] = item.PSNPipeLineID;
1203
                                            newRow["ITEMNAME"] = GetItemName(item, itemOID);
1204
                                            newRow["ITEMTAG"] = GetItemTag(item);
1205
                                            newRow["Class"] = GetClass(item, itemOID);
1206
                                            string subClass = GetSubClass(item, itemOID);
1207
                                           
1208
                                            newRow["SubClass"] = subClass;
1200 1209

  
1210
                                            if (item.ItemType == ItemType.Symbol)
1211
                                                newRow["TYPE"] = item.ID2DBName;
1212
                                            else if (item.ItemType == ItemType.Line)
1213
                                                newRow["TYPE"] = item.ID2DBType;
1214
                                            newRow["PIDNAME"] = group.Document.DrawingName;
1201 1215

  
1202
                                    newRow["PipeSystemNetwork_OID"] = PSNItem.PSN_OID();
1203
                                    if (branchItem == null)
1204
                                        newRow["ViewPipeSystemNetwork_OID"] = PSNItem.PSN_OID();
1205
                                    else
1206
                                        newRow["ViewPipeSystemNetwork_OID"] = branchItem.PSNItem.PSN_OID();
1216
                                            // NPD
1217
                                            if (item.LineNumber != null)
1218
                                            {
1219
                                                Attribute attribute = item.LineNumber.Attributes.Find(x => x.Name == "NominalDiameter");
1220
                                                if (attribute != null)
1221
                                                    newRow["NPD"] = attribute.Value;
1222
                                            }
1223
                                            else
1224
                                                newRow["NPD"] = null;
1207 1225

  
1208
                                    newRow["PipeRun_OID"] = item.LineNumber != null ? item.LineNumber.Name : string.Empty;
1209 1226

  
1210
                                    pathItemsDT.Rows.Add(newRow);
1211
                                }
1212
                                void UpdatePathItemsDataRow(string itemOID, string Type, string Text)
1213
                                {
1214
                                    if(pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault() != null)
1215
                                    {
1216
                                        //pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault()["TYPE"] = Type;
1217
                                        pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault()["ITEMTAG"] = Text;
1218
                                        pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault()["DESCRIPTION"] = Text;
1219
                                        pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault()["ITEMNAME"] = "PipingComp";
1220
                                    }
1221
                                }
1222
                                void UpdatePathItemsKeywordDataRow(string itemOID, string Text)
1223
                                {
1224
                                    if (pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault() != null)
1225
                                    {
1226
                                        pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault()["TYPE"] = "End";
1227
                                        pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault()["ITEMTAG"] = Text;
1228
                                        pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault()["DESCRIPTION"] = Text;
1229
                                    }
1230
                                }
1231
                                void CreateSequenceDataDataRow(string itemOID)
1232
                                {
1233
                                    DataRow newRow = sequenceDataDT.NewRow();
1234
                                    newRow["OID"] = string.Format(item.Topology.FullName + "_{0}", index);
1235
                                    newRow["SERIALNUMBER"] = string.Format("{0}", index);
1236
                                    newRow["PathItem_OID"] = itemOID;
1237
                                    newRow["TopologySet_OID_Key"] = item.Topology.FullName;
1227
                                            newRow["PipeSystemNetwork_OID"] = PSNItem.PSN_OID();
1228
                                            if (branchItem == null)
1229
                                                newRow["ViewPipeSystemNetwork_OID"] = PSNItem.PSN_OID();
1230
                                            else
1231
                                                newRow["ViewPipeSystemNetwork_OID"] = branchItem.PSNItem.PSN_OID();
1238 1232

  
1239
                                    sequenceDataDT.Rows.Add(newRow);
1240
                                }
1241
                                void CreatePipeSystemNetworkDataRow()
1242
                                {
1243
                                    // VentDrain의 경우 제외 요청
1244
                                    if (bVentDrain)
1245
                                        return;
1233
                                            newRow["PipeRun_OID"] = item.LineNumber != null ? item.LineNumber.Name : string.Empty;
1246 1234

  
1247
                                    LineNumber lineNumber = item.Document.LineNumbers.Find(x => x.UID == item.Owner);
1248
                                    if (lineNumber != null)
1249
                                    {
1250
                                        List<Attribute> att = lineNumber.Attributes;
1251
                                        if(att != null)
1235
                                            pathItemsDT.Rows.Add(newRow);
1236
                                        }
1237
                                        void UpdatePathItemsDataRow(string itemOID, string Type, string Text)
1238
                                        {
1239
                                            if (pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault() != null)
1240
                                            {
1241
                                                //pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault()["TYPE"] = Type;
1242
                                                pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault()["ITEMTAG"] = Text;
1243
                                                pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault()["DESCRIPTION"] = Text;
1244
                                                pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault()["ITEMNAME"] = "PipingComp";
1245
                                            }
1246
                                        }
1247
                                        void UpdatePathItemsKeywordDataRow(string itemOID, string Text)
1252 1248
                                        {
1253
                                            
1254
                                            List<string> oid = new List<string>();
1255
                                            string FluidCode = att.Where(x => x.Name.ToUpper().Equals("FLUIDCODE")).FirstOrDefault() != null ? att.Where(x => x.Name.ToUpper().Equals("FLUIDCODE")).FirstOrDefault().Value : string.Empty;
1256
                                            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;
1257
                                            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;
1258
                                            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;
1259
                                            //InsulationPurpose
1260
                                            if (!string.IsNullOrEmpty(FluidCode)) oid.Add(FluidCode);
1261
                                            if (!string.IsNullOrEmpty(PMC)) oid.Add(PMC);                                          
1249
                                            if (pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault() != null)
1250
                                            {
1251
                                                pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault()["TYPE"] = "End";
1252
                                                pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault()["ITEMTAG"] = Text;
1253
                                                pathItemsDT.Select(string.Format("OID = '{0}'", itemOID)).FirstOrDefault()["DESCRIPTION"] = Text;
1254
                                            }
1255
                                        }
1256
                                        void CreateSequenceDataDataRow(string itemOID)
1257
                                        {
1258
                                            DataRow newRow = sequenceDataDT.NewRow();
1259
                                            newRow["OID"] = string.Format(item.Topology.FullName + "_{0}", index);
1260
                                            newRow["SERIALNUMBER"] = string.Format("{0}", index);
1261
                                            newRow["PathItem_OID"] = itemOID;
1262
                                            newRow["TopologySet_OID_Key"] = item.Topology.FullName;
1262 1263

  
1263
                                            string PipeSystem_OID = string.Join("-", oid);
1264
                                            sequenceDataDT.Rows.Add(newRow);
1265
                                        }
1266
                                        void CreatePipeSystemNetworkDataRow()
1267
                                        {
1268
                                            // VentDrain의 경우 제외 요청
1269
                                            if (bVentDrain)
1270
                                                return;
1264 1271

  
1265
                                            if (!string.IsNullOrEmpty(SEQNUMBER)) oid.Add(SEQNUMBER);
1266
                                            if (!string.IsNullOrEmpty(INSULATION)) oid.Add(INSULATION);
1272
                                            LineNumber lineNumber = item.Document.LineNumbers.Find(x => x.UID == item.Owner);
1273
                                            if (lineNumber != null)
1274
                                            {
1275
                                                List<Attribute> att = lineNumber.Attributes;
1276
                                                if (att != null)
1277
                                                {
1278

  
1279
                                                    List<string> oid = new List<string>();
1280
                                                    string FluidCode = att.Where(x => x.Name.ToUpper().Equals("FLUIDCODE")).FirstOrDefault() != null ? att.Where(x => x.Name.ToUpper().Equals("FLUIDCODE")).FirstOrDefault().Value : string.Empty;
1281
                                                    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;
1282
                                                    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;
1283
                                                    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;
1284
                                                    //InsulationPurpose
1285
                                                    if (!string.IsNullOrEmpty(FluidCode)) oid.Add(FluidCode);
1286
                                                    if (!string.IsNullOrEmpty(PMC)) oid.Add(PMC);
1287

  
1288
                                                    string PipeSystem_OID = string.Join("-", oid);
1289

  
1290
                                                    if (!string.IsNullOrEmpty(SEQNUMBER)) oid.Add(SEQNUMBER);
1291
                                                    if (!string.IsNullOrEmpty(INSULATION)) oid.Add(INSULATION);
1292

  
1293
                                                    string OID = string.Join("-", oid);
1294

  
1295
                                                    if (pipelineDT.Select(string.Format("OID = '{0}'", OID)).Count() == 0)
1296
                                                    {
1297
                                                        DataRow newPipelineRow = pipelineDT.NewRow();
1298
                                                        newPipelineRow["OID"] = OID;
1299
                                                        newPipelineRow["PipeSystem_OID"] = PipeSystem_OID;
1300
                                                        newPipelineRow["FLUID"] = FluidCode;
1301
                                                        newPipelineRow["PMC"] = PMC;
1302
                                                        newPipelineRow["SEQNUMBER"] = SEQNUMBER;
1303
                                                        newPipelineRow["INSULATION"] = INSULATION;
1304
                                                        newPipelineRow["FROM_DATA"] = string.Empty;
1305
                                                        newPipelineRow["TO_DATA"] = string.Empty;
1306
                                                        newPipelineRow["Unit"] = PSNItem.GetPBSData();
1307
                                                        pipelineDT.Rows.Add(newPipelineRow);
1308
                                                    }
1309
                                                }
1310
                                            }
1311

  
1312
                                            DataRow newRow = pipeSystemNetworkDT.NewRow();
1313
                                            newRow["OID"] = PSNItem.PSN_OID();
1314

  
1315
                                            newRow["OrderNumber"] = psnOrder;
1316
                                            newRow["Pipeline_OID"] = item.PSNPipeLineID;
1317
                                            PSNItem.KeywordInfos = KeywordInfos;
1318
                                            PSNItem.Nozzle = Nozzle;
1319

  
1320
                                            string FROM_DATA = PSNItem.GetFromData();
1321
                                            newRow["FROM_DATA"] = FROM_DATA;
1322
                                            Item From_item = group.Items.First();
1323

  
1324
                                            if (PSNItem.IsKeyword)
1325
                                            {
1326
                                                PSNItem.StartType = PSNType.Equipment;
1327
                                                UpdatePathItemsKeywordDataRow(From_item.UID, FROM_DATA);
1328
                                            }
1329
                                            else if (FROM_DATA == "ENDOFHEADER")
1330
                                            {
1267 1331

  
1268
                                            string OID = string.Join("-", oid);
1332
                                                UpdatePathItemsDataRow(From_item.UID, From_item.ID2DBName, FROM_DATA);
1333
                                            }
1269 1334

  
1270
                                            if (pipelineDT.Select(string.Format("OID = '{0}'", OID)).Count() == 0)
1335
                                            string TO_DATA = PSNItem.GetToData();
1336
                                            newRow["TO_DATA"] = TO_DATA;
1337
                                            Item To_item = group.Items.Last();
1338
                                            if (PSNItem.IsKeyword)
1271 1339
                                            {
1272
                                                DataRow newPipelineRow = pipelineDT.NewRow();
1273
                                                newPipelineRow["OID"] = OID;
1274
                                                newPipelineRow["PipeSystem_OID"] = PipeSystem_OID;
1275
                                                newPipelineRow["FLUID"] = FluidCode;
1276
                                                newPipelineRow["PMC"] = PMC;
1277
                                                newPipelineRow["SEQNUMBER"] = SEQNUMBER;
1278
                                                newPipelineRow["INSULATION"] = INSULATION;
1279
                                                newPipelineRow["FROM_DATA"] = string.Empty;
1280
                                                newPipelineRow["TO_DATA"] = string.Empty;
1281
                                                newPipelineRow["Unit"] = PSNItem.GetPBSData();
1282
                                                pipelineDT.Rows.Add(newPipelineRow);
1283
                                            }                                            
1284
                                        }                                        
1285
                                    }
1340
                                                PSNItem.EndType = PSNType.Equipment;
1341
                                                UpdatePathItemsKeywordDataRow(To_item.UID, TO_DATA);
1342
                                            }
1343
                                            else if (TO_DATA == "ENDOFHEADER")
1344
                                            {
1345
                                                UpdatePathItemsDataRow(To_item.UID, To_item.ID2DBName, TO_DATA);
1346
                                            }
1286 1347

  
1287
                                    DataRow newRow = pipeSystemNetworkDT.NewRow();
1288
                                    newRow["OID"] = PSNItem.PSN_OID();
1289
                                    
1290
                                    newRow["OrderNumber"] = psnOrder;
1291
                                    newRow["Pipeline_OID"] = item.PSNPipeLineID;
1292
                                    PSNItem.KeywordInfos = KeywordInfos;
1293
                                    PSNItem.Nozzle = Nozzle;
1348
                                            newRow["Type"] = PSNItem.GetPSNType();
1294 1349

  
1295
                                    string FROM_DATA = PSNItem.GetFromData();
1296
                                    newRow["FROM_DATA"] = FROM_DATA;
1297
                                    Item From_item = group.Items.First();
1350
                                            newRow["TopologySet_OID_Key"] = item.Topology.FullName;
1351
                                            newRow["PSNRevisionNumber"] = string.Format("V{0:D4}", Revision);
1298 1352

  
1299
                                    if (PSNItem.IsKeyword)
1300
                                    {
1301
                                        PSNItem.StartType = PSNType.Equipment;
1302
                                        UpdatePathItemsKeywordDataRow(From_item.UID, FROM_DATA);                                     
1303
                                    }
1304
                                    else if(FROM_DATA == "ENDOFHEADER")
1305
                                    {
1306
                                        
1307
                                        UpdatePathItemsDataRow(From_item.UID, From_item.ID2DBName, FROM_DATA);
1308
                                    }
1353
                                            newRow["IsValid"] = PSNItem.IsValid;
1354
                                            newRow["Status"] = !string.IsNullOrEmpty(PSNItem.Status) ? PSNItem.Status.Remove(0, 2) : string.Empty;
1355
                                            newRow["PBS"] = PSNItem.GetPBSData();
1309 1356

  
1310
                                    string TO_DATA = PSNItem.GetToData();
1311
                                    newRow["TO_DATA"] = TO_DATA;
1312
                                    Item To_item = group.Items.First();
1313
                                    if (PSNItem.IsKeyword)
1314
                                    {
1315
                                        PSNItem.EndType = PSNType.Equipment;
1316
                                        UpdatePathItemsKeywordDataRow(To_item.UID, TO_DATA);
1317
                                    }
1318
                                    else if (TO_DATA == "ENDOFHEADER")
1319
                                    {
1320
                                        UpdatePathItemsDataRow(To_item.UID, From_item.ID2DBName, TO_DATA);
1321
                                    }
1357
                                            List<string> drawingNames = new List<string>();
1358
                                            foreach (Group _group in PSNItem.Groups)
1359
                                            {
1360
                                                if (!drawingNames.Contains(_group.Document.DrawingName))
1361
                                                {
1362
                                                    if (drawingNames.Count == 0)
1363
                                                        newRow["Drawings"] = _group.Document.DrawingName;
1364
                                                    else
1365
                                                        newRow["Drawings"] = newRow["Drawings"] + ", " + _group.Document.DrawingName;
1366
                                                    drawingNames.Add(_group.Document.DrawingName);
1367
                                                }
1368
                                            }
1369
                                            newRow["IncludingVirtualData"] = "No";
1370
                                            newRow["PSNAccuracy"] = "100";
1371
                                            pipeSystemNetworkDT.Rows.Add(newRow);
1322 1372

  
1323
                                    newRow["Type"] = PSNItem.GetPSNType();
1324

  
1325
                                    newRow["TopologySet_OID_Key"] = item.Topology.FullName;
1326
                                    newRow["PSNRevisionNumber"] = string.Format("V{0:D4}", Revision);
1327
                                    
1328
                                    newRow["IsValid"] = PSNItem.IsValid;
1329
                                    newRow["Status"] = !string.IsNullOrEmpty(PSNItem.Status) ? PSNItem.Status.Remove(0, 2) : string.Empty;
1330
                                    newRow["PBS"] = PSNItem.GetPBSData();
1331
                                  
1332
                                    List<string> drawingNames = new List<string>();
1333
                                    foreach (Group _group in PSNItem.Groups)
1334
                                    {
1335
                                        if (!drawingNames.Contains(_group.Document.DrawingName))
1336
                                        {
1337
                                            if (drawingNames.Count == 0)
1338
                                                newRow["Drawings"] = _group.Document.DrawingName;
1339
                                            else
1340
                                                newRow["Drawings"] = newRow["Drawings"] + ", " + _group.Document.DrawingName;
1341
                                            drawingNames.Add(_group.Document.DrawingName);
1342 1373
                                        }
1374

  
1343 1375
                                    }
1344
                                    newRow["IncludingVirtualData"] = "No";
1345
                                    newRow["PSNAccuracy"] = "100";
1346
                                    pipeSystemNetworkDT.Rows.Add(newRow);
1347 1376
                                }
1348 1377
                            }
1378
                            catch (Exception ex)
1379
                            {
1380
                                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1381
                                MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
1382
                            }
1383

  
1384
                            //TopologySet 관련
1385
                            foreach (Topology topology in PSNItem.Topologies)
1386
                            {
1387
                                DataRow newRow = topologySetDT.NewRow();
1388
                                newRow["OID"] = topology.FullName;
1389
                                newRow["Type"] = topology.FullName.Split(new char[] { '-' }).Last().StartsWith("M") ? "Main" : "Branch";
1390
                                if (bVentDrain)
1391
                                    newRow["SubType"] = "Vent_Drain";
1392
                                else
1393
                                    newRow["SubType"] = null;
1394
                                newRow["HeadItemTag"] = GetItemTag(topology.Items.Last());
1395
                                newRow["TailItemTag"] = GetItemTag(topology.Items.First());
1396
                                newRow["HeadItemSPID"] = topology.Items.Last().UID;
1397
                                newRow["TailItemSPID"] = topology.Items.First().UID;
1398
                                topologySetDT.Rows.Add(newRow);
1399
                            }
1349 1400
                        }
1350 1401
                    }
1351
                    catch(Exception ex)
1402
                    catch(Exception ee)
1352 1403
                    {
1353
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1354
                        MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
1355
                    }
1356 1404

  
1357
                    //TopologySet 관련
1358
                    foreach (Topology topology in PSNItem.Topologies)
1359
                    {
1360
                        DataRow newRow = topologySetDT.NewRow();
1361
                        newRow["OID"] = topology.FullName;
1362
                        newRow["Type"] = topology.FullName.Split(new char[] { '-' }).Last().StartsWith("M") ? "Main" : "Branch";
1363
                        if (bVentDrain)
1364
                            newRow["SubType"] = "Vent_Drain";
1365
                        else
1366
                            newRow["SubType"] = null;
1367
                        newRow["HeadItemTag"] = GetItemTag(topology.Items.Last());
1368
                        newRow["TailItemTag"] = GetItemTag(topology.Items.First());
1369
                        newRow["HeadItemSPID"] = topology.Items.Last().UID;
1370
                        newRow["TailItemSPID"] = topology.Items.First().UID;
1371
                        topologySetDT.Rows.Add(newRow);
1372 1405
                    }
1373 1406
                }
1374 1407

  
1408

  
1375 1409
                foreach (var item in startBranchDic)
1376 1410
                {
1377 1411
                    string uid = item.Key.UID;
1378 1412
                    string topologyName = item.Value.Topology.FullName;
1379 1413
                    DataRow[] rows = pathItemsDT.Select(string.Format("OID LIKE '{0}%'", uid));
1414
                   
1380 1415
                    if (rows.Length == 1)
1381 1416
                    {
1382 1417
                        rows.First()["BranchTopologySet_OID"] = topologyName;
......
1507 1542
                    try
1508 1543
                    {
1509 1544
                        DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName));
1510
                        if (rows.Length.Equals(1) && rows.First()["SubType"] == null || string.IsNullOrEmpty(rows.First()["SubType"].ToString()))
1545
                        
1546
                        if(rows.Count() > 0)
1511 1547
                        {
1512
                            if (topology.Items == null)
1513
                                continue;
1548
                            if (rows.Length.Equals(1) && rows.First()["SubType"] == null || string.IsNullOrEmpty(rows.First()["SubType"].ToString()))
1549
                            {
1550
                                if (topology.Items == null)
1551
                                    continue;
1514 1552

  
1515
                            Item firstItem = topology.Items.First();
1516
                            Item lastItem = topology.Items.Last();
1553
                                Item firstItem = topology.Items.First();
1554
                                Item lastItem = topology.Items.Last();
1517 1555

  
1518
                            List<Relation> relations = new List<Relation>();
1519
                            
1520
                            if (firstItem.Relations.FindAll(x => x.Item == null).Count() != 0)
1521
                                relations.AddRange(firstItem.Relations.FindAll(x => x.Item != null && x.Item.Topology.ID != topology.ID));
1556
                                List<Relation> relations = new List<Relation>();
1522 1557

  
1523
                            if (lastItem.Relations.FindAll(x => x.Item == null).Count() != 0)
1524
                                relations.AddRange(lastItem.Relations.FindAll(x => x.Item != null && x.Item.Topology.ID != topology.ID));
1558
                                if (firstItem.Relations.FindAll(x => x.Item == null).Count() != 0)
1559
                                    relations.AddRange(firstItem.Relations.FindAll(x => x.Item != null && x.Item.Topology.ID != topology.ID));
1525 1560

  
1526
                            if (relations.Count > 0)
1527
                                rows.First()["SubType"] = "OtherSystem";
1561
                                if (lastItem.Relations.FindAll(x => x.Item == null).Count() != 0)
1562
                                    relations.AddRange(lastItem.Relations.FindAll(x => x.Item != null && x.Item.Topology.ID != topology.ID));
1563

  
1564
                                if (relations.Count > 0)
1565
                                    rows.First()["SubType"] = "OtherSystem";
1566
                            }
1528 1567
                        }
1529 1568
                    }
1530 1569
                    catch (Exception ex)
......
1575 1614
                if (relation != null)
1576 1615
                    result = relation.Item;
1577 1616

  
1617

  
1578 1618
                return result;
1579 1619
            }
1580 1620

  
......
1642 1682
                    foreach (DataRow ddr in select)
1643 1683
                    {
1644 1684
                        ddr["IncludingVirtualData"] = "Yes";
1645
                        ddr["PSNAccuracy"] = totalDdr;
1685
                        ddr["PSNAccuracy"] = Math.Round(totalDdr, 2);
1646 1686
                    }
1647 1687
                }
1648 1688
            }
......
1684 1724
                            {
1685 1725
                                //createTerminatorRow - Rule 5번
1686 1726
                                PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.First(), FROM_DATA), insertIndex);
1687
                                SequenceData.Rows.InsertAt(createSequenceTerminatorRow(pathItemRows.First(), insertSeqIndex), insertSeqIndex);
1727
                                //SequenceData.Rows.InsertAt(createSequenceTerminatorRow(pathItemRows.First(), insertSeqIndex), insertSeqIndex);
1688 1728

  
1689 1729
                                bCheckRule5 = true;
1690 1730
                            }
1691 1731
                            else
1692 1732
                            {
1693 1733
                                PathItems.Rows.InsertAt(createLineRow(PathItems.Select(string.Format("PipeLine_OID = '{0}' AND ItemName = 'PipeRun' AND PipeSystemNetwork_OID = '{1}'", item.PSNPipeLineID, dataRow["OID"])).First()), insertIndex);
1694
                                SequenceData.Rows.InsertAt(createSequenceTerminatorRow(PathItems.Select(string.Format("PipeLine_OID = '{0}' AND ItemName = 'PipeRun' AND PipeSystemNetwork_OID = '{1}'", item.PSNPipeLineID, dataRow["OID"])).First(), insertSeqIndex), insertSeqIndex);
1734
                                //SequenceData.Rows.InsertAt(createSequenceTerminatorRow(PathItems.Select(string.Format("PipeLine_OID = '{0}' AND ItemName = 'PipeRun' AND PipeSystemNetwork_OID = '{1}'", item.PSNPipeLineID, dataRow["OID"])).First(), insertSeqIndex), insertSeqIndex);
1695 1735
                                //createTerminatorRow - Rule 5번
1696 1736
                                PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.First(), FROM_DATA), insertIndex);
1697
                                SequenceData.Rows.InsertAt(createSequenceTerminatorRow(pathItemRows.First(), insertSeqIndex), insertSeqIndex);
1737
                                //SequenceData.Rows.InsertAt(createSequenceTerminatorRow(pathItemRows.First(), insertSeqIndex), insertSeqIndex);
1698 1738

  
1699 1739
                                bCheckRule5 = true;
1700 1740
                            }
......
1715 1755
                        DataRow[] pathItemRows = PathItems.Select(string.Format("PipeSystemNetwork_OID = '{0}'", dataRow["OID"]));
1716 1756
                        int insertIndex = PathItems.Rows.IndexOf(pathItemRows.Last());
1717 1757

  
1718
                        DataRow[] seqItemRows = SequenceData.Select(string.Format("PathItem_OID = '{0}'", pathItemRows.Last()["OID"]));
1719
                        int insertSeqIndex = SequenceData.Rows.IndexOf(seqItemRows.Last());
1758
                       
1720 1759

  
1721 1760
                        Item item = PSNItem.Groups.Last().Items.Last();
1722 1761
                        try
......
1732 1771
                            {
1733 1772
                                //createTerminatorRow - Rule 5번
1734 1773
                                PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.Last(), TO_DATA), insertIndex + 1);
1735
                                SequenceData.Rows.InsertAt(createSequenceTerminatorRow(pathItemRows.Last(), insertSeqIndex + 1), insertSeqIndex + 1);
1774
                                //SequenceData.Rows.InsertAt(createSequenceTerminatorRow(pathItemRows.Last(), insertSeqIndex + 1), insertSeqIndex + 1);
1736 1775

  
1737 1776
                                bCheckRule5 = true;
1738 1777
                            }
......
1740 1779
                            {
1741 1780
                                //createTerminatorRow - Rule 5번
1742 1781
                                PathItems.Rows.InsertAt(createTerminatorRow(pathItemRows.Last(), TO_DATA), insertIndex + 1);
1743
                                SequenceData.Rows.InsertAt(createSequenceTerminatorRow(pathItemRows.Last(), insertSeqIndex + 1), insertSeqIndex + 1);
1782
                                //SequenceData.Rows.InsertAt(createSequenceTerminatorRow(pathItemRows.Last(), insertSeqIndex + 1), insertSeqIndex + 1);
1744 1783
                                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);
1745
                                SequenceData.Rows.InsertAt(createSequenceTerminatorRow(PathItems.Select(string.Format("PipeLine_OID = '{0}' AND ItemName = 'PipeRun' AND PipeSystemNetwork_OID = '{1}'", item.PSNPipeLineID, dataRow["OID"])).Last(), insertSeqIndex + 1), insertSeqIndex + 1);
1784
                                //SequenceData.Rows.InsertAt(createSequenceTerminatorRow(PathItems.Select(string.Format("PipeLine_OID = '{0}' AND ItemName = 'PipeRun' AND PipeSystemNetwork_OID = '{1}'", item.PSNPipeLineID, dataRow["OID"])).Last(), insertSeqIndex + 1), insertSeqIndex + 1);
1746 1785
                                bCheckRule5 = true;
1747 1786
                            }
1748 1787

  
......
1772 1811
                                sb.Append(split[j] + "_");
1773 1812
                            sb.Append(rowIndex++);
1774 1813
                            row["SequenceData_OID"] = sb.ToString();
1775
                        }
1776 1814

  
1777
                        rowIndex = 0;
1778
                        for (int i = 0; i < SequenceData.Rows.Count; i++)
1779
                        {
1780
                            DataRow row = SequenceData.Rows[i];
1781
                            if (row["PathItem_OID"].ToString() != dataRow["OID"].ToString())
1782
                                continue;
1783
                            string sequenceData = row["SequenceData_OID"].ToString();
1784
                            string[] split = sequenceData.Split(new char[] { '_' });
1815
                            DataRow seqItemRows = SequenceData.Select(string.Format("PathItem_OID = '{0}'", row["OID"])).FirstOrDefault();
1816
                            int insertSeqIndex = SequenceData.Rows.IndexOf(seqItemRows);
1817

  
1818
                            string[] splitseq = sb.ToString().Split(new char[] { '_' });
1819

  
1820
                            if (seqItemRows == null)
1821
                            {
1822
                                DataRow newRow = SequenceData.NewRow();    
1823
                                newRow["OID"] = sb.ToString();
1824
                                newRow["SERIALNUMBER"] = splitseq[splitseq.Length - 1];
1825
                                newRow["PathItem_OID"] = row["OID"];
1826
                                newRow["TopologySet_OID_Key"] = row["TopologySet_OID"];
1827
                                SequenceData.Rows.InsertAt(newRow, Convert.ToInt32(splitseq[splitseq.Length - 1]));
1828
                            }
1829
                            else
1830
                            {
1831
                                seqItemRows["OID"] = sb.ToString();
1832
                                seqItemRows["SERIALNUMBER"] = splitseq[splitseq.Length - 1];
1833
                                seqItemRows["PathItem_OID"] = row["OID"];
1834
                                seqItemRows["TopologySet_OID_Key"] = row["TopologySet_OID"];
1835

  
1836
                            }
1837
                           
1785 1838

  
1786
                            row["SERIALNUMBER"] = rowIndex++;
1787 1839
                        }
1840

  
1841
                        //rowIndex = 0;
1842
                        //for (int i = 0; i < SequenceData.Rows.Count; i++)
1843
                        //{
1844
                        //    DataRow row = SequenceData.Rows[i];
1845
                        //    if (row["PathItem_OID"].ToString() != dataRow["OID"].ToString())
1846
                        //        continue;
1847
                        //    string sequenceData = row["SequenceData_OID"].ToString();
1848
                        //    string[] split = sequenceData.Split(new char[] { '_' });
1849

  
1850
                        //    row["SERIALNUMBER"] = rowIndex++;
1851
                        //}
1788 1852
                    }
1789 1853

  
1790 1854
                    if (bCheckRule5)
......
1820 1884
                        return newRow;
1821 1885
                    }
1822 1886

  
1823
                    DataRow createSequenceTerminatorRow(DataRow itemRow, int insertIndex)
1824
                    {
1825
                        DataRow newRow = SequenceData.NewRow();
1826
                        newRow["OID"] = Guid.NewGuid().ToString(); 
1827
                        newRow["SERIALNUMBER"] = string.Format("{0}", insertIndex);
1828
                        newRow["PathItem_OID"] = itemRow["OID"];
1829
                        newRow["TopologySet_OID_Key"] = itemRow["TopologySet_OID"];
1887
                    //DataRow createSequenceTerminatorRow(DataRow itemRow, int insertIndex)
1888
                    //{
1889
                    //    DataRow newRow = SequenceData.NewRow();
1890
                    //    newRow["OID"] = itemRow["SequenceData_OID"]; 
1891
                    //    newRow["SERIALNUMBER"] = string.Format("{0}", insertIndex);
1892
                    //    newRow["PathItem_OID"] = itemRow["OID"];
1893
                    //    newRow["TopologySet_OID_Key"] = itemRow["TopologySet_OID"];
1830 1894

  
1831
                        return newRow;
1832
                    }
1895
                    //    return newRow;
1896
                    //}
1833 1897

  
1834 1898
                    DataRow createLineRow(DataRow itemRow)
1835 1899
                    {
......
1965 2029
                }
1966 2030
                else if (StartType == PSNType.Equipment)
1967 2031
                {
1968
                    result = Groups.First().Items.First().Equipment.ItemTag;
2032
                    if (Groups.First().Items.First().Equipment != null)
2033
                        result = Groups.First().Items.First().Equipment.ItemTag;
1969 2034
                    DataRow drNozzle = Nozzle.Select(string.Format("OID = '{0}'", Groups.First().Items.First().UID)).FirstOrDefault();
1970 2035

  
1971 2036
                    if (drNozzle != null)
......
2047 2112
        public string GetToData()
2048 2113
        {
2049 2114
            string result = string.Empty;
2050
            if (IsKeyword)
2051
                IsKeyword = false;
2115
          
2052 2116

  
2053
            if (EndType == PSNType.Header)
2054
                result = "ENDOFHEADER";
2055
            else if (EndType == PSNType.Branch)
2056
            {
2057
                Item item = Groups.Last().Items.Last();
2058
                if (item.Relations.Last().Item.LineNumber != null && !string.IsNullOrEmpty(item.Relations.Last().Item.LineNumber.Name))
2059
                    result = item.Relations.Last().Item.LineNumber.Name;
2060
                else
2117
                if (IsKeyword)
2118
                    IsKeyword = false;
2119

  
2120
                if (EndType == PSNType.Header)
2121
                    result = "ENDOFHEADER";
2122
                else if (EndType == PSNType.Branch)
2061 2123
                {
2062
                    Status += ", Missing LineNumber";
2063
                    result = "Empty LineNumber";
2124
                    Item item = Groups.Last().Items.Last();
2125
                    if (item.Relations.Last().Item.LineNumber != null && !string.IsNullOrEmpty(item.Relations.Last().Item.LineNumber.Name))
2126
                        result = item.Relations.Last().Item.LineNumber.Name;
2127
                    else
2128
                    {
2129
                        Status += ", Missing LineNumber";
2130
                        result = "Empty LineNumber";
2131
                    }
2064 2132
                }
2065
            }
2066
            else if (EndType == PSNType.Equipment)
2067
            {
2068
                result = Groups.Last().Items.Last().Equipment.ItemTag;
2069
                DataRow drNozzle = Nozzle.Select(string.Format("OID = '{0}'", Groups.First().Items.First().UID)).FirstOrDefault();
2070

  
2071
                if (drNozzle != null)
2072
                    result += " [" + drNozzle.Field<string>("ITEMTAG") + "]";
2073
            }
2074
            else
2075
            {
2076
                IsValid = "Error";
2077
                Item item = Groups.Last().Items.Last();
2078
                if (item.ItemType == ItemType.Symbol)
2133
                else if (EndType == PSNType.Equipment)
2079 2134
                {
2080
                    string keyword = string.Empty;
2081
                    keyword = GetToKeywordData();
2135
                    if(Groups.Last().Items.Last().Equipment != null)
2136
                        result = Groups.Last().Items.Last().Equipment.ItemTag;
2082 2137

  
2083
                    if (string.IsNullOrEmpty(keyword))
2138
                    DataRow drNozzle = Nozzle.Select(string.Format("OID = '{0}'", Groups.First().Items.First().UID)).FirstOrDefault();
2139

  
2140
                    if (drNozzle != null)
2141
                        result += " [" + drNozzle.Field<string>("ITEMTAG") + "]";
2142
                }
2143
                else
2144
                {
2145
                    IsValid = "Error";
2146
                    Item item = Groups.Last().Items.Last();
2147
                    if (item.ItemType == ItemType.Symbol)
2084 2148
                    {
2085
                        if (item.ID2DBType.Contains("OPC's"))
2086
                            Status += ", OPC Disconneted";
2149
                        string keyword = string.Empty;
2150
                        keyword = GetToKeywordData();
2151

  
2152
                        if (string.IsNullOrEmpty(keyword))
2153
                        {
2154
                            if (item.ID2DBType.Contains("OPC's"))
2155
                                Status += ", OPC Disconneted";
2156
                            else
2157
                                Status += ", Missing ItemTag or Description";
2158

  
2159
                            result = item.ID2DBName;
2160
                        }
2087 2161
                        else
2088
                            Status += ", Missing ItemTag or Description";
2162
                        {
2163
                            result = keyword;
2164
                            IsValid = string.Empty;
2165
                            IsKeyword = true;
2166
                        }
2089 2167

  
2090
                        result = item.ID2DBName;
2091 2168
                    }
2092
                    else
2169
                    else if (item.ItemType == ItemType.Line)
2093 2170
                    {
2094
                        result = keyword;
2095
                        IsValid = string.Empty;
2096
                        IsKeyword = true;
2171
                        Status += ", Line Disconnected";
2172
                        result = item.LineNumber != null && !string.IsNullOrEmpty(item.LineNumber.Name) ? item.LineNumber.Name : "Empty LineNumber";
2097 2173
                    }
2098
                    
2099
                }
2100
                else if (item.ItemType == ItemType.Line)
2101
                {
2102
                    Status += ", Line Disconnected";
2103
                    result = item.LineNumber != null && !string.IsNullOrEmpty(item.LineNumber.Name) ? item.LineNumber.Name : "Empty LineNumber";
2174
                    else
2175
                        result = "Unknown";
2104 2176
                }
2105
                else
2106
                    result = "Unknown";
2107
            }
2177
        
2178
         
2108 2179
            return result;
2109 2180
        }
2110 2181

  

내보내기 Unified diff