프로젝트

일반

사용자정보

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

hytos / DTI_PID / ID2PSN / DB.cs @ c3b48db0

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

1
using System;
2
using System.Collections.Generic;
3
using System.Data;
4
using System.Data.Common;
5
using System.Data.SqlClient;
6
using System.Data.SQLite;
7
using System.Linq;
8
using System.Text.RegularExpressions;
9

    
10
namespace ID2PSN
11
{
12
    public class DB
13
    {
14
        const string PSN_TOPOLOGY_RULE = "T_PSN_TOPOLOGY_RULE";
15
        const string PSN_HEADER_SETTING = "T_PSN_HEADER_SETTING";
16
        const string PSN_VENTDRAIN_SETTING = "T_PSN_VENTDRAIN_SETTING";
17
        const string PSN_VIEW = "T_PSN_VIEW";
18
        const string PSN_TRANSFORMKEYWORD_SETTING = "T_PSN_TRANSFORMKEYWORD_SETTING";
19
        const string PSN_VALVEGROUP_SETTING = "SPPIDValveGroup";
20

    
21
        const string PSN_PATHITEMS = "SPPIDPathItem";
22
        const string PSN_SEQUENCEDATA = "SPPIDSequenceData";
23
        const string PSN_PIPESYSTEMNETWORK = "SPPIDPipeSystemNetwork";
24
        const string PSN_EQUIPMENT = "SPPIDEquipment";
25
        const string PSN_NOZZLE = "SPPIDNozzle";
26
        const string PSN_FLUIDCODE = "SPPIDFluidCode";
27
        const string PSN_PIPINGMATLCLASS = "SPPIDPipingMatlClass";
28
        const string PSN_TOPOLOGYSET = "SPPIDTopologySet";
29
        //2021.11.17 추가 
30
        const string PSN_PIPELINE = "SPPIDPipeLine";
31
        //2021.11.26 추가
32
        const string PSN_INSULATIONPURPOSE = "SPPIDInsulationPurpose";
33
        //2022.01.12 추가 //ARS_COMMON DB
34
        const string PSN_REVISION = "PSNRevision";
35
        const string PSN_COMMON = "ARS_COMMON";
36
        //2022.01.19 추가
37
        const string PSN_PIPESYSTEM = "SPPIDPipeSystem";
38

    
39
        //2022.02.03 추가
40
        const string PSN_NOPOCKETSETTING = "T_PSN_NOPOCKET_SETTING";
41
        const string PSN_AIRFINCOOLERSETTING = "T_PSN_AIRFINCOOLER_SETTING";
42
        /// <summary>
43
        ///  ID2 Project.db 데이터를 가져온다. 
44
        ///  DB 접속 정보 및 DBType (Sqlite, Mssql) 정보를 가져옴
45
        ///  - JY
46
        /// </summary>
47
        /// <returns></returns>
48
        public static DataTable GetProject()
49
        {
50
            DataTable dt = new DataTable();
51
            ID2Info id2Info = ID2Info.GetInstance();
52
            try
53
            {
54
                using (SQLiteConnection connection = new SQLiteConnection(@"Data Source = C:\ProgramData\Digital PID\Project.db", true))
55
                {
56
                    connection.Open();
57
                    if (connection.State.Equals(ConnectionState.Open))
58
                    {
59
                        using (SQLiteCommand cmd = connection.CreateCommand())
60
                        {
61
                            cmd.CommandText = "SELECT p.[Id], p.Name, p.Path, s.DBTypes_UID, s.Host, s.[User], s.[Password], s.FilePath FROM DBSettings s, Projects p WHERE s.Projects_UID = p.[Id]";
62
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
63
                                dt.Load(dr);
64
                        }
65

    
66
                    }
67
                    connection.Close();
68
                }
69
            }
70
            catch (Exception ex)
71
            {
72
                System.Windows.Forms.MessageBox.Show(ex.Message);
73
            }
74

    
75
            dt.AcceptChanges();
76
            dt.DefaultView.Sort = "Name";
77
            dt = dt.DefaultView.ToTable();
78

    
79
            return dt;
80
        }
81

    
82
        /// <summary>
83
        ///  SQLite에 초기 DB 생성
84
        ///  - JY
85
        /// </summary>
86
        /// <returns></returns>
87
        public static bool ConnTestAndCreateTable()
88
        {
89
            bool result = false;
90
            ID2Info id2Info = ID2Info.GetInstance();
91

    
92
            using (IAbstractDatabase connection = id2Info.CreateConnection())
93
            {
94
                try
95
                {
96
                    var names = connection.GetTableNames();
97
                    var matched = names.FirstOrDefault(param => param == PSN_HEADER_SETTING);
98
                    Dictionary<string, string> dicColCheck = new Dictionary<string, string>();
99
                    dicColCheck.Add("GROUP_ID", "TEXT");
100
                    dicColCheck.Add("DESCRIPTION", "TEXT");
101
                    dicColCheck.Add("INDEX", "INTEGER");
102
                    dicColCheck.Add("NAME", "TEXT");
103

    
104
                    if (matched == null)
105
                    {
106
                        var query = $"CREATE TABLE {PSN_HEADER_SETTING} (GROUP_ID TEXT, DESCRIPTION TEXT, [INDEX] INTEGER, NAME TEXT)";
107
                        using (var cmd = connection.GetSqlStringCommand(query))
108
                        {
109
                            cmd.ExecuteNonQuery();
110
                        }
111
                    }
112
                    else
113
                    {
114
                        AddColumn(PSN_HEADER_SETTING, dicColCheck);
115
                    }
116

    
117
                    matched = names.FirstOrDefault(param => param == PSN_VENTDRAIN_SETTING);
118
                    dicColCheck.Clear();
119
                    dicColCheck.Add("GROUP_ID", "TEXT");
120
                    dicColCheck.Add("DESCRIPTION", "TEXT");
121
                    dicColCheck.Add("INDEX", "INTEGER");
122
                    dicColCheck.Add("NAME", "TEXT");
123
                    if (matched == null)
124
                    {
125
                        var query = $"CREATE TABLE {PSN_VENTDRAIN_SETTING} (GROUP_ID TEXT, DESCRIPTION TEXT, [INDEX] INTEGER, NAME TEXT)";
126
                        using (var cmd = connection.GetSqlStringCommand(query))
127
                        {
128
                            cmd.ExecuteNonQuery();
129
                        }
130
                    }
131
                    else
132
                    {
133
                        AddColumn(PSN_VENTDRAIN_SETTING, dicColCheck);
134
                    }
135

    
136
                    matched = names.FirstOrDefault(param => param == PSN_TOPOLOGY_RULE);
137
                    dicColCheck.Clear();
138
                    dicColCheck.Add("UID", "TEXT");
139
                    if (matched == null)
140
                    {
141
                        var query = $"CREATE TABLE {PSN_TOPOLOGY_RULE} (UID TEXT)";
142
                        using (var cmd = connection.GetSqlStringCommand(query))
143
                        {
144
                            cmd.ExecuteNonQuery();
145
                        }
146

    
147
                        DataTable topologyRule = new DataTable();
148
                        topologyRule.Columns.Add("NAME", typeof(string));
149

    
150
                        topologyRule.Rows.Add("FluidCode");
151
                        topologyRule.Rows.Add("-");
152
                        topologyRule.Rows.Add("PipingMaterialsClass");
153
                        topologyRule.Rows.Add("-");
154
                        topologyRule.Rows.Add("Tag Seq No");
155

    
156
                        SaveTopologyRule(topologyRule);
157
                    }
158
                    //else
159
                    //{
160
                    //    AddColumn(PSN_TOPOLOGY_RULE, dicColCheck);
161
                    //}
162

    
163
                    matched = names.FirstOrDefault(param => param == PSN_PIPESYSTEMNETWORK);
164
                    dicColCheck.Clear();
165
                    dicColCheck.Add("OID",                      "NVARCHAR(255)");
166
                    dicColCheck.Add("Type",                     "NVARCHAR(255)");
167
                    dicColCheck.Add("OrderNumber",              "NVARCHAR(255)");
168
                    dicColCheck.Add("Pipeline_OID",             "NVARCHAR(255)");
169
                    dicColCheck.Add("From_Data",                "NVARCHAR(255)");
170
                    dicColCheck.Add("To_Data", "NVARCHAR(255)");
171
                    dicColCheck.Add("TopologySet_OID_Key", "NVARCHAR(125)");
172
                    dicColCheck.Add("PSNRevisionNumber", "NVARCHAR(255)");
173
                    dicColCheck.Add("IsValid", "INT");
174
                    dicColCheck.Add("Status", "NVARCHAR(255)");
175
                    dicColCheck.Add("PBS", "NVARCHAR(255)");
176
                    dicColCheck.Add("Drawings", "NVARCHAR(255)");
177
                    dicColCheck.Add("IncludingVirtualData", "NVARCHAR(10)");
178
                    dicColCheck.Add("PSNAccuracy", "REAL");
179
                    dicColCheck.Add("Pocket", "NVARCHAR(10)");
180
                    
181
                    if (matched == null)
182
                    {
183
                        var query = $"CREATE TABLE {PSN_PIPESYSTEMNETWORK} (OID NVARCHAR(255), Type NVARCHAR(255), OrderNumber NVARCHAR(255), Pipeline_OID NVARCHAR(255), From_Data NVARCHAR(255), " +
184
                            "To_Data NVARCHAR(255), TopologySet_OID_Key NVARCHAR(125), PSNRevisionNumber NVARCHAR(255), IsValid INTEGER, Status NVARCHAR(255), PBS NVARCHAR(255), Drawings NVARCHAR(255), " +
185
                            "IncludingVirtualData NVARCHAR(10), PSNAccuracy REAL, Pocket NVARCHAR(10))";
186
                        using (var cmd = connection.GetSqlStringCommand(query))
187
                        {
188
                            cmd.ExecuteNonQuery();
189
                        }
190
                    }
191
                    else
192
                    {
193
                        AddColumn(PSN_PIPESYSTEMNETWORK, dicColCheck);
194
                    }
195

    
196
                    matched = names.FirstOrDefault(param => param == PSN_EQUIPMENT);
197
                    dicColCheck.Clear();
198
                    dicColCheck.Add("OID", "NVARCHAR(255)");
199
                    dicColCheck.Add("ItemTag", "NVARCHAR(255)");
200
                    dicColCheck.Add("Xcoords", "REAL");
201
                    dicColCheck.Add("Ycoords", "REAL");
202
                    if (matched == null)
203
                    {
204
                        var query = $"CREATE TABLE {PSN_EQUIPMENT} (OID NVARCHAR(255), ItemTag NVARCHAR(255), Xcoords REAL, Ycoords REAL)";
205
                        using (var cmd = connection.GetSqlStringCommand(query))
206
                        {
207
                            cmd.ExecuteNonQuery();
208
                        }
209
                    }
210
                    else
211
                    {
212
                        AddColumn(PSN_EQUIPMENT, dicColCheck);
213
                    }
214

    
215
                    dicColCheck.Clear();
216
                    dicColCheck.Add("OID", "NVARCHAR(255)");
217
                    dicColCheck.Add("ItemTag", "NVARCHAR(255)");
218
                    dicColCheck.Add("Xcoords", "REAL");
219
                    dicColCheck.Add("Ycoords", "REAL");
220
                    dicColCheck.Add("Equipment_OID", "NVARCHAR(255)");
221
                    dicColCheck.Add("Fluid", "NVARCHAR(255)");
222
                    dicColCheck.Add("NPD", "NVARCHAR(255)");
223
                    dicColCheck.Add("PMC", "NVARCHAR(255)");
224
                    dicColCheck.Add("Rotation", "REAL");
225
                    dicColCheck.Add("FlowDirection", "NVARCHAR(255)");
226

    
227
                    matched = names.FirstOrDefault(param => param == PSN_NOZZLE);
228
                    if (matched == null)
229
                    {
230
                        var query = $"CREATE TABLE {PSN_NOZZLE} (OID NVARCHAR(255), ItemTag NVARCHAR(255), Xcoords REAL, Ycoords REAL, Equipment_OID NVARCHAR(255), " +
231
                            "Fluid NVARCHAR(255), NPD NVARCHAR(255), PMC NVARCHAR(255), Rotation REAL, FlowDirection NVARCHAR(255))";
232
                        using (var cmd = connection.GetSqlStringCommand(query))
233
                        {
234
                            cmd.ExecuteNonQuery();
235
                        }
236
                    }
237
                    else
238
                    {
239
                        AddColumn(PSN_NOZZLE, dicColCheck);
240
                    }
241

    
242
                    matched = names.FirstOrDefault(param => param == PSN_FLUIDCODE);
243
                    dicColCheck.Clear();
244
                    dicColCheck.Add("UID", "NVARCHAR(50)");
245
                    dicColCheck.Add("Code", "NVARCHAR(255)");
246
                    dicColCheck.Add("Description", "NVARCHAR(255)");
247
                    dicColCheck.Add("Condition", "NVARCHAR(255)");
248
                    dicColCheck.Add("Remarks", "NVARCHAR(255)");
249
                    dicColCheck.Add("GroundLevel", "NVARCHAR(20)");
250
                    if (matched == null)
251
                    {
252
                        var query = $"CREATE TABLE {PSN_FLUIDCODE} (UID NVARCHAR(50), Code NVARCHAR(255), Description NVARCHAR(255), Condition NVARCHAR(255), Remarks NVARCHAR(255), GroundLevel NVARCHAR(20))";
253
                        using (var cmd = connection.GetSqlStringCommand(query))
254
                        {
255
                            cmd.ExecuteNonQuery();
256
                        }
257
                    }
258
                    else
259
                    {
260
                        AddColumn(PSN_FLUIDCODE, dicColCheck);
261
                    }
262

    
263
                    matched = names.FirstOrDefault(param => param == PSN_PIPINGMATLCLASS);
264
                    dicColCheck.Clear();
265
                    dicColCheck.Add("UID", "NVARCHAR(50)");
266
                    dicColCheck.Add("Priority", "INTEGER");
267
                    dicColCheck.Add("Code", "NVARCHAR(255)");
268
                    dicColCheck.Add("Description", "NVARCHAR(255)");
269
                    dicColCheck.Add("Condition", "NVARCHAR(255)");
270
                    dicColCheck.Add("Remarks", "NVARCHAR(255)");
271
                    dicColCheck.Add("GroundLevel", "NVARCHAR(20)");
272
                    if (matched == null)
273
                    {
274
                        var query = $"CREATE TABLE {PSN_PIPINGMATLCLASS} (UID NVARCHAR(50), Priority INTEGER, Code NVARCHAR(255), Description NVARCHAR(255), Condition NVARCHAR(255), Remarks NVARCHAR(255), GroundLevel NVARCHAR(20))";
275
                        using (var cmd = connection.GetSqlStringCommand(query))
276
                        {
277
                            cmd.ExecuteNonQuery();
278
                        }
279
                    }
280
                    else
281
                    {
282
                        AddColumn(PSN_PIPINGMATLCLASS, dicColCheck);
283
                    }
284

    
285
                    matched = names.FirstOrDefault(param => param == PSN_SEQUENCEDATA);
286
                    dicColCheck.Clear();
287
                    dicColCheck.Add("OID", "NVARCHAR(255)");
288
                    dicColCheck.Add("SERIALNUMBER", "NVARCHAR(255)");
289
                    dicColCheck.Add("PathItem_OID", "NVARCHAR(255)");
290
                    dicColCheck.Add("TopologySet_OID_Key", "NVARCHAR(255)");
291
                    if (matched == null)
292
                    {
293
                        var query = $"CREATE TABLE {PSN_SEQUENCEDATA} (OID NVARCHAR(255), SERIALNUMBER NVARCHAR(255), PathItem_OID NVARCHAR(255), TopologySet_OID_Key NVARCHAR(255))";
294
                        using (var cmd = connection.GetSqlStringCommand(query))
295
                        {
296
                            cmd.ExecuteNonQuery();
297
                        }
298
                    }
299
                    else
300
                    {
301
                        AddColumn(PSN_SEQUENCEDATA, dicColCheck);
302
                    }
303

    
304
                    matched = names.FirstOrDefault(param => param == PSN_PATHITEMS);
305
                    dicColCheck.Clear();
306
                    dicColCheck.Add("OID", "NVARCHAR(255)");
307
                    dicColCheck.Add("SequenceData_OID", "NVARCHAR(255)");
308
                    dicColCheck.Add("TopologySet_OID", "NVARCHAR(255)");
309
                    dicColCheck.Add("BranchTopologySet_OID", "NVARCHAR(255)");
310
                    dicColCheck.Add("PipeLine_OID", "NVARCHAR(255)");
311
                    dicColCheck.Add("ItemName", "NVARCHAR(255)");
312
                    dicColCheck.Add("ItemTag", "NVARCHAR(255)");
313
                    dicColCheck.Add("DESCRIPTION", "NVARCHAR(255)");
314
                    dicColCheck.Add("CLASS", "NVARCHAR(255)");
315
                    dicColCheck.Add("SUBCLASS", "NVARCHAR(255)");
316
                    dicColCheck.Add("TYPE", "NVARCHAR(255)");
317
                    dicColCheck.Add("PIDNAME", "NVARCHAR(255)");
318
                    dicColCheck.Add("Equipment_OID", "NVARCHAR(255)");
319
                    dicColCheck.Add("NPD", "NVARCHAR(255)");
320
                    dicColCheck.Add("GROUPTAG", "NVARCHAR(255)");
321
                    dicColCheck.Add("PipeSystemNetwork_OID", "NVARCHAR(255)");
322
                    dicColCheck.Add("PipeRun_OID", "NVARCHAR(255)");
323
                    dicColCheck.Add("ViewPipeSystemNetwork_OID", "NVARCHAR(255)");
324

    
325
                    dicColCheck.Add("EqpGroupTag", "NVARCHAR(255)");
326
                    dicColCheck.Add("MainLineTag", "NVARCHAR(255)");
327

    
328
                    dicColCheck.Add("EGTConnectedPoint", "INT");
329
                    dicColCheck.Add("EGFlowDirection", "NVARCHAR(10)");
330

    
331
                    if (matched == null)
332
                    {
333
                        var query = $"CREATE TABLE {PSN_PATHITEMS} (OID NVARCHAR(255), SequenceData_OID NVARCHAR(255), " +
334
                            "TopologySet_OID NVARCHAR(255), BranchTopologySet_OID NVARCHAR(255), PipeLine_OID NVARCHAR(255), ItemName NVARCHAR(255), ItemTag NVARCHAR(255), DESCRIPTION NVARCHAR(255), " +
335
                            "CLASS NVARCHAR(255), SUBCLASS NVARCHAR(255), TYPE NVARCHAR(255), PIDNAME NVARCHAR(255), Equipment_OID NVARCHAR(255), NPD NVARCHAR(255), GROUPTAG NVARCHAR(255), PipeSystemNetwork_OID NVARCHAR(255), PipeRun_OID NVARCHAR(255), " +
336
                            "ViewPipeSystemNetwork_OID NVARCHAR(255), EqpGroupTag NVARCHAR(255), MainLineTag NVARCHAR(255), EGTConnectedPoint INT, EGFlowDirection NVARCHAR(10))";
337
                        using (var cmd = connection.GetSqlStringCommand(query))
338
                        {
339
                            cmd.ExecuteNonQuery();
340
                        }
341
                    }
342
                    else
343
                    {
344
                        AddColumn(PSN_PATHITEMS, dicColCheck);
345
                    }
346

    
347
                    matched = names.FirstOrDefault(param => param == PSN_VIEW);
348
                    dicColCheck.Clear();
349
                    dicColCheck.Add("OID", "TEXT");
350
                    if (matched == null)
351
                    {
352
                        var query = $"CREATE TABLE {PSN_VIEW} (OID TEXT)";
353
                        using (var cmd = connection.GetSqlStringCommand(query))
354
                        {
355
                            cmd.ExecuteNonQuery();
356
                        }
357
                    }
358

    
359
                    matched = names.FirstOrDefault(param => param == PSN_TOPOLOGYSET);
360
                    dicColCheck.Clear();
361
                    dicColCheck.Add("OID", "NVARCHAR(255)");
362
                    dicColCheck.Add("Type", "NVARCHAR(255)");
363
                    dicColCheck.Add("SubType", "NVARCHAR(255)");
364
                    dicColCheck.Add("HeadItemTag", "NVARCHAR(255)");
365
                    dicColCheck.Add("TailItemTag", "NVARCHAR(255)");
366
                    dicColCheck.Add("HeadItemSPID", "NVARCHAR(255)");
367
                    dicColCheck.Add("TailItemSPID", "NVARCHAR(255)");
368

    
369
                    if (matched == null)
370
                    {
371
                        var query = $"CREATE TABLE {PSN_TOPOLOGYSET} (OID NVARCHAR(255), Type NVARCHAR(255), SubType NVARCHAR(255), HeadItemTag NVARCHAR(255), TailItemTag NVARCHAR(255), HeadItemSPID NVARCHAR(255), TailItemSPID NVARCHAR(255))";
372
                        using (var cmd = connection.GetSqlStringCommand(query))
373
                        {
374
                            cmd.ExecuteNonQuery();
375
                        }
376
                    }
377
                    else
378
                    {
379
                        AddColumn(PSN_TOPOLOGYSET, dicColCheck);
380
                    }
381

    
382
                    matched = names.FirstOrDefault(param => param == PSN_TRANSFORMKEYWORD_SETTING);
383
                    dicColCheck.Clear();
384
                    dicColCheck.Add("[INDEX]", "INTEGER");
385
                    dicColCheck.Add("[NAME]", "TEXT");
386
                    dicColCheck.Add("[KEYWORD]", "TEXT");
387
                    if (matched == null)
388
                    {
389
                        var query = $"CREATE TABLE {PSN_TRANSFORMKEYWORD_SETTING} ([INDEX] INTEGER, [NAME] TEXT, [KEYWORD] TEXT)";
390
                        using (var cmd = connection.GetSqlStringCommand(query))
391
                        {
392
                            cmd.ExecuteNonQuery();
393
                        }
394
                    }
395
                    else
396
                    {
397
                        AddColumn(PSN_TRANSFORMKEYWORD_SETTING, dicColCheck);
398
                    }
399

    
400
                    matched = names.FirstOrDefault(param => param == PSN_PIPELINE);
401
                    dicColCheck.Clear();
402
                    dicColCheck.Add("OID", "NVARCHAR(255)");
403
                    dicColCheck.Add("PipeSystem_OID", "NVARCHAR(255)");
404
                    dicColCheck.Add("FLUID", "NVARCHAR(255)");
405
                    dicColCheck.Add("PMC", "NVARCHAR(255)");
406
                    dicColCheck.Add("SEQNUMBER", "NVARCHAR(255)");
407
                    dicColCheck.Add("INSULATION", "NVARCHAR(255)");
408
                    dicColCheck.Add("FROM_DATA", "NVARCHAR(255)");
409
                    dicColCheck.Add("TO_DATA", "NVARCHAR(255)");
410
                    dicColCheck.Add("Unit", "NVARCHAR(100)");
411
                    if (matched == null)
412
                    {
413
                        var query = $"CREATE TABLE {PSN_PIPELINE} (OID NVARCHAR(255), PipeSystem_OID NVARCHAR(255), FLUID NVARCHAR(255), PMC NVARCHAR(255), SEQNUMBER NVARCHAR(255), INSULATION NVARCHAR(255), " +
414
                            $"FROM_DATA NVARCHAR(255), TO_DATA NVARCHAR(255), Unit NVARCHAR(100))";
415
                        using (var cmd = connection.GetSqlStringCommand(query))
416
                        {
417
                            cmd.ExecuteNonQuery();
418
                        }
419
                    }
420
                    else
421
                    {
422
                        AddColumn(PSN_PIPELINE, dicColCheck);
423
                    }
424

    
425
                    matched = names.FirstOrDefault(param => param == PSN_INSULATIONPURPOSE);
426
                    dicColCheck.Clear();
427
                    dicColCheck.Add("UID", "NVARCHAR(50)");
428
                    dicColCheck.Add("Code", "NVARCHAR(255)");
429
                    dicColCheck.Add("Description", "NVARCHAR(255)");
430
                    dicColCheck.Add("Remarks", "NVARCHAR(255)");
431
                    if (matched == null)
432
                    {
433
                        var query = $"CREATE TABLE {PSN_INSULATIONPURPOSE} (UID NVARCHAR(50), Code NVARCHAR(255), Description NVARCHAR(255), Remarks NVARCHAR(255))";
434
                        using (var cmd = connection.GetSqlStringCommand(query))
435
                        {
436
                            cmd.ExecuteNonQuery();
437
                        }
438
                    }
439
                    else
440
                    {
441
                        AddColumn(PSN_INSULATIONPURPOSE, dicColCheck);
442
                    }
443

    
444
                    matched = names.FirstOrDefault(param => param == PSN_VALVEGROUP_SETTING);
445
                    dicColCheck.Clear();
446
                    dicColCheck.Add("OID", "NVARCHAR(255)");
447
                    dicColCheck.Add("GroupType", "NVARCHAR(255)");
448
                    dicColCheck.Add("TagIdentifier", "NVARCHAR(50)");
449
                    dicColCheck.Add("AttributeName", "NVARCHAR(255)");
450
                    dicColCheck.Add("SppidSymbolName", "NVARCHAR(255)");
451
                    if (matched == null)
452
                    {
453
                        var query = $"CREATE TABLE {PSN_VALVEGROUP_SETTING} (OID NVARCHAR(255), GroupType NVARCHAR(255), TagIdentifier NVARCHAR(50), AttributeName NVARCHAR(255), SppidSymbolName NVARCHAR(255))";
454
                        using (var cmd = connection.GetSqlStringCommand(query))
455
                        {
456
                            cmd.ExecuteNonQuery();
457
                        }
458
                    }
459
                    else
460
                    {
461
                        AddColumn(PSN_VALVEGROUP_SETTING, dicColCheck);
462
                    }
463

    
464
                    matched = names.FirstOrDefault(param => param == PSN_PIPESYSTEM);
465
                    dicColCheck.Clear();
466
                    dicColCheck.Add("OID", "NVARCHAR(255)");
467
                    dicColCheck.Add("DESCRIPTION", "NVARCHAR(255)");
468
                    dicColCheck.Add("FLUID", "NVARCHAR(255)");
469
                    dicColCheck.Add("PMC", "NVARCHAR(255)");
470
                    dicColCheck.Add("PipeLineQty", "NVARCHAR(255)");
471
                    dicColCheck.Add("GroundLevel", "NVARCHAR(20)");
472
                    if (matched == null)
473
                    {
474
                        var query = $"CREATE TABLE {PSN_PIPESYSTEM} (OID NVARCHAR(255), DESCRIPTION NVARCHAR(255), FLUID NVARCHAR(255), PMC NVARCHAR(255), PipeLineQty NVARCHAR(255), GroundLevel NVARCHAR(20))";
475
                        using (var cmd = connection.GetSqlStringCommand(query))
476
                        {
477
                            cmd.ExecuteNonQuery();
478
                        }
479
                    }
480
                    else
481
                    {
482
                        AddColumn(PSN_PIPESYSTEM, dicColCheck);
483
                    }
484

    
485
                    matched = names.FirstOrDefault(param => param == PSN_NOPOCKETSETTING);
486
                    dicColCheck.Clear();
487
                    dicColCheck.Add("[INDEX]", "INTEGER");
488
                    dicColCheck.Add("[TYPE]", "TEXT");
489
                    dicColCheck.Add("[NAME]", "TEXT");
490
                    if (matched == null)
491
                    {
492
                        var query = $"CREATE TABLE {PSN_NOPOCKETSETTING} ([INDEX] INTEGER, [TYPE] TEXT, [NAME] TEXT)";
493
                        using (var cmd = connection.GetSqlStringCommand(query))
494
                        {
495
                            cmd.ExecuteNonQuery();
496
                        }
497
                    }
498
                    else
499
                    {
500
                        AddColumn(PSN_NOPOCKETSETTING, dicColCheck);
501
                    }
502

    
503
                    matched = names.FirstOrDefault(param => param == PSN_AIRFINCOOLERSETTING);
504
                    dicColCheck.Clear();
505
                    dicColCheck.Add("[INDEX]", "INTEGER");
506
                    dicColCheck.Add("[TYPE]", "TEXT");
507
                    dicColCheck.Add("[NAME]", "TEXT");
508
                    if (matched == null)
509
                    {
510
                        var query = $"CREATE TABLE {PSN_AIRFINCOOLERSETTING} ([INDEX] INTEGER, [TYPE] TEXT, [NAME] TEXT)";
511
                        using (var cmd = connection.GetSqlStringCommand(query))
512
                        {
513
                            cmd.ExecuteNonQuery();
514
                        }
515
                    }
516
                    else
517
                    {
518
                        AddColumn(PSN_AIRFINCOOLERSETTING, dicColCheck);
519
                    }
520

    
521

    
522
                    void AddColumn(string TableName, Dictionary<string, string> dicCol)
523
                    {
524
                        var colnames = connection.GetColumnNames(TableName);
525
                        bool check = false;
526
                        if (colnames != null)
527
                        {
528
                            foreach (KeyValuePair<string, string> col in dicCol)
529
                            {
530
                                check = false;
531
                                foreach (string c in colnames)
532
                                {
533
                                    if (col.Key.Contains(c))
534
                                    {
535
                                        check = true;
536
                                        break;
537
                                    }
538
                                }
539

    
540
                                if (!check) //없으면 추가
541
                                {
542
                                    string i = string.Empty;
543
                                    if (col.Value.ToString().ToUpper().Contains("INT") || col.Value.ToString().ToUpper().Contains("REAL"))
544
                                        i = "DEFAULT 0";
545

    
546
                                    var query = $"ALTER TABLE " + TableName + " ADD [" + col.Key + "] " + col.Value + " " + i + ";";
547
                                    using (var cmd = connection.GetSqlStringCommand(query))
548
                                    {
549
                                        cmd.ExecuteNonQuery();
550
                                    }
551
                                }
552
                            }
553
                        }
554
                    }
555

    
556
                    result = true;
557
                }
558
                catch (Exception ex)
559
                {
560
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
561
                }
562
            }
563

    
564
            return result;
565
        }
566

    
567
        // ID2 DB 데이터
568
        /// <summary>
569
        /// ID2 데이타베이스에서 OPC 데이터를 조회
570
        /// </summary>
571
        /// <returns></returns>
572
        public static DataTable SelectOPCRelations()
573
        {
574
            DataTable dt = null;
575
            ID2Info id2Info = ID2Info.GetInstance();
576

    
577
            using (IAbstractDatabase connection = id2Info.CreateConnection())
578
            {
579
                try
580
                {
581
                    var query = "SELECT * FROM OPCRelations;";
582
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
583
                    {
584
                        dt = ds.Tables[0].Copy();
585
                    }
586
                }
587
                catch (Exception ex)
588
                {
589
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
590
                }
591
            }
592

    
593
            return dt;
594
        }
595

    
596
        /// <summary>
597
        /// ID2 데이타베이스에서 도면 데이터를 조회
598
        /// </summary>
599
        /// <returns></returns>
600
        public static DataTable SelectDrawings()
601
        {
602
            DataTable dt = null;
603
            ID2Info id2Info = ID2Info.GetInstance();
604

    
605
            using (IAbstractDatabase connection = id2Info.CreateConnection())
606
            {
607
                try
608
                {
609
                    var query = "SELECT DISTINCT NAME FROM [Drawings] order by Name";
610
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
611
                    {
612
                        dt = ds.Tables[0].Copy();
613
                    }
614
                }
615
                catch (Exception ex)
616
                {
617
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
618
                }
619
            }
620

    
621
            return dt;
622
        }
623

    
624
        public static DataTable AllDrawings()
625
        {
626
            DataTable dt = null;
627
            ID2Info id2Info = ID2Info.GetInstance();
628

    
629
            using (IAbstractDatabase connection = id2Info.CreateConnection())
630
            {
631
                try
632
                {
633
                    var query = "SELECT * FROM [Drawings]";
634
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
635
                    {
636
                        dt = ds.Tables[0].Copy();
637
                    }
638
                }
639
                catch (Exception ex)
640
                {
641
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
642
                }
643
            }
644

    
645
            return dt;
646
        }
647

    
648
        public static DataTable SelectLineProperties()
649
        {
650
            DataTable dt = null;
651
            ID2Info id2Info = ID2Info.GetInstance();
652

    
653
            using (IAbstractDatabase connection = id2Info.CreateConnection())
654
            {
655
                try
656
                {
657
                    var query = "SELECT * FROM LineProperties";
658
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
659
                    {
660
                        dt = ds.Tables[0].Copy();
661
                    }
662
                }
663
                catch (Exception ex)
664
                {
665
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
666
                }
667
            }
668

    
669
            return dt;
670
        }
671

    
672
        public static DataTable SelectFluidCode()
673
        {
674
            DataTable dt = null;
675
            ID2Info id2Info = ID2Info.GetInstance();
676

    
677
            using (IAbstractDatabase connection = id2Info.CreateConnection())
678
            {
679
                try
680
                {
681
                    var query = "SELECT * FROM FluidCode";
682
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
683
                    {
684
                        dt = ds.Tables[0].Copy();
685
                    }
686
                }
687
                catch (Exception ex)
688
                {
689
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
690
                }
691
            }
692

    
693
            return dt;
694
        }
695

    
696
        public static DataTable SelectPipingMaterialsClass()
697
        {
698
            DataTable dt = null;
699
            ID2Info id2Info = ID2Info.GetInstance();
700

    
701
            using (IAbstractDatabase connection = id2Info.CreateConnection())
702
            {
703
                try
704
                {
705
                    var query = "SELECT * FROM PipingMaterialsClass";
706
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
707
                    {
708
                        dt = ds.Tables[0].Copy();
709
                    }
710
                }
711
                catch (Exception ex)
712
                {
713
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
714
                }
715
            }
716

    
717
            return dt;
718
        }
719

    
720
        public static DataTable SelectPSNPIPINGMATLCLASS()
721
        {
722
            DataTable dt = null;
723
            ID2Info id2Info = ID2Info.GetInstance();
724

    
725
            using (IAbstractDatabase connection = id2Info.CreateConnection())
726
            {
727
                try
728
                {
729
                    var query = $"SELECT * FROM {PSN_PIPINGMATLCLASS}";
730
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
731
                    {
732
                        dt = ds.Tables[0].Copy();
733
                    }
734
                }
735
                catch (Exception ex)
736
                {
737
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
738
                }
739
            }
740

    
741
            return dt;
742
        }
743
        
744
        public static DataTable SelectInsulationPurpose()
745
        {
746
            DataTable dt = null;
747
            ID2Info id2Info = ID2Info.GetInstance();
748

    
749
            using (IAbstractDatabase connection = id2Info.CreateConnection())
750
            {
751
                try
752
                {
753
                    var query = "SELECT * FROM InsulationPurpose";
754
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
755
                    {
756
                        dt = ds.Tables[0].Copy();
757
                    }
758
                }
759
                catch (Exception ex)
760
                {
761
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
762
                }
763
            }
764

    
765
            return dt;
766
        }
767

    
768
        public static DataTable SelectPSNINSULATIONPURPOSE()
769
        {
770
            DataTable dt = null;
771
            ID2Info id2Info = ID2Info.GetInstance();
772

    
773
            using (IAbstractDatabase connection = id2Info.CreateConnection())
774
            {
775
                try
776
                {
777
                    var query = $"SELECT * FROM {PSN_INSULATIONPURPOSE}";
778
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
779
                    {
780
                        dt = ds.Tables[0].Copy();
781
                    }
782
                }
783
                catch (Exception ex)
784
                {
785
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
786
                }
787
            }
788

    
789
            return dt;
790
        }
791

    
792
        public static DataTable SelectNominalDiameter()
793
        {
794
            DataTable dt = null;
795
            ID2Info id2Info = ID2Info.GetInstance();
796

    
797
            using (IAbstractDatabase connection = id2Info.CreateConnection())
798
            {
799
                try
800
                {
801
                    var query = "SELECT * FROM NominalDiameter ORDER BY Metric DESC";
802
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
803
                    {
804
                        dt = ds.Tables[0].Copy();
805
                    }
806
                }
807
                catch (Exception ex)
808
                {
809
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
810
                }
811
            }
812

    
813
            ///TODO: need to check below code
814
            dt.Rows.RemoveAt(0);
815
            dt.Rows.RemoveAt(0);
816
            dt.Rows.RemoveAt(0);
817
            dt.Rows.RemoveAt(0);
818

    
819
            return dt;
820
        }
821

    
822
        public static DataTable SelectAllSymbolAttribute()
823
        {
824
            DataTable dt = null;
825
            ID2Info id2Info = ID2Info.GetInstance();
826

    
827
            using (IAbstractDatabase connection = id2Info.CreateConnection())
828
            {
829
                try
830
                {
831
                    var query = "SELECT B.Name AS SymbolName, Attribute AS SymbolAttribute, A.SymbolType_UID ,Attribute ,DisplayAttribute ,AttributeType, Expression FROM SymbolAttribute A INNER JOIN Symbol B ON A.SymbolType_UID = B.SymbolType_UID; ";
832
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
833
                    {
834
                        dt = ds.Tables[0].Copy();
835
                    }
836
                }
837
                catch (Exception ex)
838
                {
839
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
840
                }
841
            }
842

    
843
            return dt;
844
        }
845

    
846
        public static DataTable SelectSymbolAttribute()
847
        {
848
            DataTable dt = null;
849
            ID2Info id2Info = ID2Info.GetInstance();
850

    
851
            using (IAbstractDatabase connection = id2Info.CreateConnection())
852
            {
853
                try
854
                {
855
                   // var query = "SELECT DISTINCT Attribute, DisplayAttribute FROM SymbolAttribute;";
856
                    var query = "SELECT DISTINCT Attribute FROM SymbolAttribute;";
857
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
858
                    {
859
                        dt = ds.Tables[0].Copy();
860
                    }
861
                }
862
                catch (Exception ex)
863
                {
864
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
865
                }
866
            }
867

    
868
            return dt;
869
        }
870

    
871
        public static DataTable SelectSymbolName()
872
        {
873
            DataTable dt = null;
874
            ID2Info id2Info = ID2Info.GetInstance();
875

    
876
            using (IAbstractDatabase connection = id2Info.CreateConnection())
877
            {
878
                try
879
                {
880
                    var query = "SELECT * FROM SymbolName;";
881
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
882
                    {
883
                        dt = ds.Tables[0].Copy();
884
                    }
885
                }
886
                catch (Exception ex)
887
                {
888
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
889
                }
890
            }
891

    
892
            return dt;
893
        }
894

    
895
        public static double[] GetDrawingSize()
896
        {
897
            double[] result = null;
898

    
899
            ID2Info id2Info = ID2Info.GetInstance();
900
            using (IAbstractDatabase connection = id2Info.CreateConnection())
901
            {
902
                try
903
                {
904
                    var query = "SELECT value FROM Configuration WHERE Section = 'Area' AND [Key] = 'Drawing';";
905
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
906
                    {
907
                        if (ds.Tables[0].Rows.Count == 1)
908
                        {
909
                            string value = ds.Tables[0].Rows[0][0].ToString();
910
                            string[] split = value.Split(new char[] { ',' });
911
                            result = new double[] {
912
                                Convert.ToDouble(Regex.Replace(split[0], @"[^0-9]", string.Empty)),
913
                                Convert.ToDouble(Regex.Replace(split[1], @"[^0-9]", string.Empty)),
914
                                Convert.ToDouble(Regex.Replace(split[2], @"[^0-9]", string.Empty)),
915
                                Convert.ToDouble(Regex.Replace(split[3], @"[^0-9]", string.Empty))
916
                                };
917
                            result = new double[] {
918
                                Math.Min(result[0], result[2]),
919
                                Math.Min(result[1], result[3]),
920
                                Math.Max(result[0], result[2]),
921
                                Math.Max(result[1], result[3])
922
                                };
923
                        }
924
                    }
925
                }
926
                catch (Exception ex)
927
                {
928
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
929
                }
930
            }
931

    
932
            return result;
933
        }
934

    
935
        public static DataTable GetEquipmentType()
936
        {
937
            DataTable dt = null;
938
            ID2Info id2Info = ID2Info.GetInstance();
939

    
940
            using (IAbstractDatabase connection = id2Info.CreateConnection())
941
            {
942
                try
943
                {
944
                    var query = "SELECT Type FROM SymbolType WHERE Category = 'Equipment';";
945
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
946
                    {
947
                        dt = ds.Tables[0].Copy();
948
                    }
949
                }
950
                catch (Exception ex)
951
                {
952
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
953
                }
954
            }
955

    
956
            return dt;
957
        }
958

    
959
        /// <summary>
960
        ///  Zoom 을 위하여 저장 T_PSN_VIEW 데이터로 PSN 데이터지만 Msqql 과 Sqlite 둘다 저장되어 있음
961
        ///  => ID2 가 DB 타입에 따라서 바라보는 DB가 mssql이냐 sqlite냐로 지정되기 때문에 zoom 기능을 그대로 사용하려면 해당 데이터는 psn도 id2 dbtype에 맞춰서 저장 및 로드해야함
962
        ///  => 더 이상 사용하지 않음
963
        /// </summary>
964
        /// <param name="values"></param>
965
        /// <returns></returns>
966
        public static bool SaveView(List<string> values)
967
        {
968
            ID2Info id2Info = ID2Info.GetInstance();
969

    
970
            bool result = true;
971

    
972
            using (IAbstractDatabase connection = id2Info.CreateConnection())
973
            {
974
                try
975
                {
976
                    using (var txn = connection.BeginTransaction())
977
                    {
978
                        try
979
                        {
980
                            var query = $"DELETE FROM {PSN_VIEW}";
981
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
982

    
983
                            foreach (string value in values)
984
                            {
985
                                query = $"INSERT INTO {PSN_VIEW} (OID) VALUES (@OID)";
986
                                var cmd = connection.GetSqlStringCommand(query);
987
                                AddWithValue(cmd, "@OID", value);
988
                                connection.ExecuteNonQuery(cmd, txn);
989
                            }
990
                            txn.Commit();
991
                        }
992
                        catch (Exception ex)
993
                        {
994
                            txn.Rollback();
995
                            result = false;
996
                        }
997
                    }
998
                }
999
                catch (Exception ex)
1000
                {
1001
                    System.Windows.Forms.MessageBox.Show(ex.Message);
1002
                    result = false;
1003
                }
1004
            }
1005

    
1006
            return result;
1007
        }
1008

    
1009
        public static bool DeleteView()
1010
        {
1011
            ID2Info id2Info = ID2Info.GetInstance();
1012

    
1013
            bool result = true;
1014
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1015
            {
1016
                try
1017
                {
1018
                    using (var txn = connection.BeginTransaction())
1019
                    {
1020
                        try
1021
                        {
1022
                            var query = $"DELETE FROM {PSN_VIEW}";
1023
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1024
                            txn.Commit();
1025
                        }
1026
                        catch (Exception ex)
1027
                        {
1028
                            txn.Rollback();
1029
                            result = false;
1030
                        }
1031
                    }
1032
                }
1033
                catch (Exception ex)
1034
                {
1035
                    System.Windows.Forms.MessageBox.Show(ex.Message);
1036
                    result = false;
1037
                }
1038
            }
1039

    
1040
            return result;
1041
        }
1042

    
1043
        //PSN Sqlite 
1044
        public static DataTable SelectHeaderSetting()
1045
        {
1046
            DataTable dt = null;
1047
            ID2Info id2Info = ID2Info.GetInstance();
1048

    
1049
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1050
            {
1051
                try
1052
                {
1053
                    var query = $@"SELECT GROUP_ID, DESCRIPTION, [INDEX], NAME FROM {PSN_HEADER_SETTING};";
1054
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1055
                    {
1056
                        dt = ds.Tables[0].Copy();
1057
                    }
1058
                }
1059
                catch (Exception ex)
1060
                {
1061
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1062
                }
1063
            }
1064

    
1065
            return dt;
1066
        }
1067

    
1068
        public static DataTable SelectVentDrainSetting()
1069
        {
1070
            DataTable dt = null;
1071
            ID2Info id2Info = ID2Info.GetInstance();
1072

    
1073
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1074
            {
1075
                try
1076
                {
1077
                    var query = $@"SELECT GROUP_ID, DESCRIPTION, [INDEX], NAME FROM {PSN_VENTDRAIN_SETTING};";
1078
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1079
                    {
1080
                        dt = ds.Tables[0].Copy();
1081
                    }
1082
                }
1083
                catch (Exception ex)
1084
                {
1085
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1086
                }
1087
            }
1088

    
1089
            return dt;
1090
        }
1091

    
1092
        public static DataTable SelectKeywordsSetting()
1093
        {
1094
            DataTable dt = null;
1095
            ID2Info id2Info = ID2Info.GetInstance();
1096

    
1097
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1098
            {
1099
                try
1100
                {
1101
                    var query = $@"SELECT [KEYWORD], [INDEX], [NAME] FROM {PSN_TRANSFORMKEYWORD_SETTING};";
1102
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1103
                    {
1104
                        dt = ds.Tables[0].Copy();
1105
                    }
1106
                }
1107
                catch (Exception ex)
1108
                {
1109
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1110
                }
1111
            }
1112

    
1113
            return dt;
1114
        }
1115

    
1116
        public static DataTable SelectValveGroupItemsSetting()
1117
        {
1118
            DataTable dt = null;
1119
            ID2Info id2Info = ID2Info.GetInstance();
1120

    
1121
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1122
            {
1123
                try
1124
                {
1125
                    var query = $@"SELECT OID, GroupType, TagIdentifier, AttributeName, SppidSymbolName FROM {PSN_VALVEGROUP_SETTING};";
1126
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1127
                    {
1128
                        dt = ds.Tables[0].Copy();
1129
                    }
1130
                }
1131
                catch (Exception ex)
1132
                {
1133
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1134
                }
1135
            }
1136

    
1137
            return dt;
1138
        }
1139

    
1140
  
1141
        public static DataTable SelectEquipmentNoPocketSetting()
1142
        {
1143
            DataTable dt = null;
1144
            ID2Info id2Info = ID2Info.GetInstance();
1145

    
1146
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1147
            {
1148
                try
1149
                {
1150
                    var query = $@"SELECT [INDEX], [TYPE], [NAME] FROM {PSN_NOPOCKETSETTING};";
1151
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1152
                    {
1153
                        dt = ds.Tables[0].Copy();
1154
                    }
1155
                }
1156
                catch (Exception ex)
1157
                {
1158
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1159
                }
1160
            }
1161

    
1162
            return dt;
1163
        }
1164

    
1165
        public static DataTable SelectAirFinCoolerSetting()
1166
        {
1167
            DataTable dt = null;
1168
            ID2Info id2Info = ID2Info.GetInstance();
1169

    
1170
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1171
            {
1172
                try
1173
                {
1174
                    var query = $@"SELECT [INDEX], [TYPE], [NAME] FROM {PSN_AIRFINCOOLERSETTING};";
1175
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1176
                    {
1177
                        dt = ds.Tables[0].Copy();
1178
                    }
1179
                }
1180
                catch (Exception ex)
1181
                {
1182
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1183
                }
1184
            }
1185

    
1186
            return dt;            
1187
        }
1188

    
1189
        public static bool SaveHeaderSetting(List<HeaderInfo> headerInfos)
1190
        {
1191
            ID2Info id2Info = ID2Info.GetInstance();
1192
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1193
            {
1194
                try
1195
                {
1196
                    using (var txn = connection.BeginTransaction())
1197
                    {
1198
                        var query = $"DELETE FROM {PSN_HEADER_SETTING}";
1199
                        connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1200

    
1201
                        foreach (HeaderInfo headerInfo in headerInfos)
1202
                        {
1203
                            foreach (HeaderItem item in headerInfo.HeaderItems)
1204
                            {
1205
                                query = $"INSERT INTO {PSN_HEADER_SETTING} (GROUP_ID, DESCRIPTION, [INDEX], NAME) VALUES (@GROUP_ID, @DESCRIPTION, @INDEX, @NAME)";
1206
                                var cmd = connection.GetSqlStringCommand(query);
1207
                                AddWithValue(cmd, "@GROUP_ID", headerInfo.UID);
1208
                                AddWithValue(cmd, "@DESCRIPTION", headerInfo.Description);
1209
                                AddWithValue(cmd, "@INDEX", item.Index);
1210
                                AddWithValue(cmd, "@NAME", item.Name);
1211
                                connection.ExecuteNonQuery(cmd, txn);
1212
                            }
1213
                        }
1214
                        txn.Commit();
1215
                    }
1216
                    
1217
                }
1218
                catch (Exception ex)
1219
                {
1220
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1221
                    return false;
1222
                }
1223
            }
1224
            return true;
1225
        }
1226

    
1227
        public static bool SaveVentDrainSetting(List<VentDrainInfo> ventDrainInfos)
1228
        {
1229
            ID2Info id2Info = ID2Info.GetInstance();
1230
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1231
            {
1232
                using (var txn = connection.BeginTransaction())
1233
                {
1234
                    try
1235
                    {
1236
                        var query = $"DELETE FROM {PSN_VENTDRAIN_SETTING}";
1237
                        connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1238

    
1239
                        foreach (VentDrainInfo ventDrainInfo in ventDrainInfos)
1240
                        {
1241
                            foreach (VentDrainItem item in ventDrainInfo.VentDrainItems)
1242
                            {
1243
                                query = $"INSERT INTO {PSN_VENTDRAIN_SETTING} (GROUP_ID, DESCRIPTION, [INDEX], NAME) VALUES (@GROUP_ID, @DESCRIPTION, @INDEX, @NAME)";
1244
                                var cmd = connection.GetSqlStringCommand(query);
1245
                                AddWithValue(cmd, "@GROUP_ID", ventDrainInfo.UID);
1246
                                AddWithValue(cmd, "@DESCRIPTION", ventDrainInfo.Description);
1247
                                AddWithValue(cmd, "@INDEX", item.Index);
1248
                                AddWithValue(cmd, "@NAME", item.Name);
1249
                                connection.ExecuteNonQuery(cmd, txn);
1250
                            }
1251
                        }
1252

    
1253
                        txn.Commit();
1254
                    }
1255
                    catch (Exception ex)
1256
                    {
1257
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1258
                        return false;
1259
                    }
1260
                }
1261
            }
1262

    
1263
            return true;
1264
        }
1265

    
1266
        public static bool SaveValveGroupItemsSetting(List<ValveGroupItem> valveGroupItems)
1267
        {
1268
            ID2Info id2Info = ID2Info.GetInstance();
1269
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1270
            {
1271
                using (var txn = connection.BeginTransaction())
1272
                {
1273
                    try
1274
                    {
1275
                        var query = $"DELETE FROM {PSN_VALVEGROUP_SETTING}";
1276
                        connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1277

    
1278
                        foreach (ValveGroupItem item in valveGroupItems)
1279
                        {
1280
                            query = $"INSERT INTO {PSN_VALVEGROUP_SETTING} (OID, GroupType, TagIdentifier, AttributeName, SppidSymbolName) " +
1281
                                $"VALUES (@OID, @GroupType, @TagIdentifier, @AttributeName, @SppidSymbolName)";
1282
                            var cmd = connection.GetSqlStringCommand(query);
1283
                            AddWithValue(cmd, "@OID", item.OID);
1284
                            AddWithValue(cmd, "@GroupType", item.GroupType);
1285
                            AddWithValue(cmd, "@TagIdentifier", item.TagIdentifier);
1286
                            AddWithValue(cmd, "@AttributeName", item.AttributeName);
1287
                            AddWithValue(cmd, "@SppidSymbolName", item.SppidSymbolName);
1288
                            connection.ExecuteNonQuery(cmd, txn);
1289
                        }
1290

    
1291
                        txn.Commit();
1292
                    }
1293
                    catch (Exception ex)
1294
                    {
1295
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1296
                        return false;
1297
                    }
1298
                }
1299
            }
1300

    
1301
            return true;
1302
        }
1303

    
1304
        public static bool SaveKeywordsSetting(List<KeywordItem> keywordItems)
1305
        {
1306
            ID2Info id2Info = ID2Info.GetInstance();
1307
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1308
            {
1309
                using (var txn = connection.BeginTransaction())
1310
                {
1311
                    try
1312
                    {
1313
                        var query = $"DELETE FROM {PSN_TRANSFORMKEYWORD_SETTING}";
1314
                        connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1315
                        
1316
                        foreach (KeywordItem item in keywordItems)
1317
                        {
1318
                            query = $"INSERT INTO {PSN_TRANSFORMKEYWORD_SETTING} ([INDEX], NAME, KEYWORD) VALUES (@INDEX, @NAME, @KEYWORD)";
1319
                            var cmd = connection.GetSqlStringCommand(query);
1320
                            AddWithValue(cmd, "@INDEX", item.Index);
1321
                            AddWithValue(cmd, "@NAME", item.Name);
1322
                            AddWithValue(cmd, "@KEYWORD", item.Keyword);                            
1323
                            connection.ExecuteNonQuery(cmd, txn);
1324
                        }
1325
                        
1326
                        txn.Commit();
1327
                    }
1328
                    catch (Exception ex)
1329
                    {
1330
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1331
                        return false;
1332
                    }
1333
                }
1334
            }
1335

    
1336
            return true;
1337
        }
1338

    
1339
        public static bool SaveEquipmentNopocketSetting(List<EquipmentNoPocketItem> keywordItems)
1340
        {
1341
            ID2Info id2Info = ID2Info.GetInstance();
1342
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1343
            {
1344
                using (var txn = connection.BeginTransaction())
1345
                {
1346
                    try
1347
                    {
1348
                        var query = $"DELETE FROM {PSN_NOPOCKETSETTING}";
1349
                        connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1350

    
1351
                        foreach (EquipmentNoPocketItem item in keywordItems)
1352
                        {
1353
                            query = $"INSERT INTO {PSN_NOPOCKETSETTING} ([INDEX], [TYPE], [NAME]) VALUES (@INDEX, @TYPE, @NAME)";
1354
                            var cmd = connection.GetSqlStringCommand(query);
1355
                            AddWithValue(cmd, "@INDEX", item.Index);
1356
                            AddWithValue(cmd, "@TYPE", item.Type);
1357
                            AddWithValue(cmd, "@NAME", item.Name);
1358
                            connection.ExecuteNonQuery(cmd, txn);
1359
                        }
1360

    
1361
                        txn.Commit();
1362
                    }
1363
                    catch (Exception ex)
1364
                    {
1365
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1366
                        return false;
1367
                    }
1368
                }
1369
            }
1370

    
1371
            return true;
1372
        }
1373

    
1374
        public static bool SaveAirFinCoolerSetting(List<EquipmentAirFinCoolerItem> keywordItems)
1375
        {
1376
            ID2Info id2Info = ID2Info.GetInstance();
1377
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1378
            {
1379
                using (var txn = connection.BeginTransaction())
1380
                {
1381
                    try
1382
                    {
1383
                        var query = $"DELETE FROM {PSN_AIRFINCOOLERSETTING}";
1384
                        connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1385

    
1386
                        foreach (EquipmentAirFinCoolerItem item in keywordItems)
1387
                        {
1388
                            query = $"INSERT INTO {PSN_AIRFINCOOLERSETTING} ([INDEX], [TYPE], [NAME]) VALUES (@INDEX, @TYPE, @NAME)";
1389
                            var cmd = connection.GetSqlStringCommand(query);
1390
                            AddWithValue(cmd, "@INDEX", item.Index);
1391
                            AddWithValue(cmd, "@TYPE", item.Type);
1392
                            AddWithValue(cmd, "@NAME", item.Name);
1393
                            connection.ExecuteNonQuery(cmd, txn);
1394
                        }
1395

    
1396
                        txn.Commit();
1397
                    }
1398
                    catch (Exception ex)
1399
                    {
1400
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1401
                        return false;
1402
                    }
1403
                }
1404
            }
1405

    
1406
            return true;
1407
        }
1408

    
1409
        public static bool SaveTopologyRule(DataTable dt)
1410
        {
1411
            ID2Info id2Info = ID2Info.GetInstance();
1412
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1413
            {
1414
                using (var txn = connection.BeginTransaction())
1415
                {
1416
                    try
1417
                    {
1418
                        var query = $"DELETE FROM {PSN_TOPOLOGY_RULE}";
1419
                        var cmd = connection.GetSqlStringCommand(query);
1420
                        //connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1421
                        connection.ExecuteNonQuery(cmd, txn);
1422

    
1423
                        foreach (DataRow row in dt.Rows)
1424
                        {
1425
                            query = $"INSERT INTO {PSN_TOPOLOGY_RULE} (UID) VALUES (@UID)";
1426
                            cmd = connection.GetSqlStringCommand(query);
1427
                            AddWithValue(cmd, "@UID", row["NAME"].ToString());
1428
                            connection.ExecuteNonQuery(cmd, txn);
1429
                        }
1430

    
1431
                        txn.Commit();
1432
                    }
1433
                    catch (Exception ex)
1434
                    {
1435
                        txn.Rollback();
1436
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1437
                        return false;
1438
                    }
1439
                }
1440
            }
1441

    
1442
            return true;
1443
        }
1444

    
1445
        public static DataTable SelectTopologyRule()
1446
        {
1447
            DataTable dt = null;
1448

    
1449
            ID2Info id2Info = ID2Info.GetInstance();
1450
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1451
            {
1452
                try
1453
                {
1454
                    var query = $"SELECT * FROM {PSN_TOPOLOGY_RULE}";
1455
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1456
                    {
1457
                        dt = ds.Tables[0].Copy();
1458
                    }
1459
                }
1460
                catch (Exception ex)
1461
                {
1462
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1463
                }
1464
            }
1465

    
1466
            return dt;
1467
        }
1468

    
1469
        private static void AddWithValue(DbCommand cmd, string PropName, object Value)
1470
        {
1471
            var param = cmd.CreateParameter();
1472
            param.ParameterName = PropName;
1473
            param.Value = Value;
1474
            cmd.Parameters.Add(param);
1475
        }
1476

    
1477
        public static DataTable SelectRevisionTable()
1478
        {
1479
            DataTable dt = null;
1480
            ID2Info id2Info = ID2Info.GetInstance();
1481

    
1482
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1483
            {
1484
                try
1485
                {
1486
                    var query = $"SELECT T.name AS table_name, C.name AS column_name FROM ARS_COMMON.sys.tables AS T INNER JOIN ARS_COMMON.sys.columns AS C ON T.object_id = C.object_id WHERE T.name = 'PSNREVISION'";
1487
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1488
                    {
1489
                        dt = ds.Tables[0].Copy();
1490
                    }
1491
                }
1492
                catch (Exception ex)
1493
                {
1494
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1495
                }
1496
            }
1497

    
1498
            return dt;
1499
        }
1500

    
1501
        public static DataTable SelectRevision()
1502
        {
1503
            DataTable dt = null;
1504
            ID2Info id2Info = ID2Info.GetInstance();
1505

    
1506
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1507
            {
1508
                try
1509
                {
1510
                    var query = $"SELECT * FROM ARS_COMMON.dbo.PSNREVISION";
1511

    
1512
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1513
                    {
1514
                        dt = ds.Tables[0].Copy();
1515
                    }
1516
                }
1517
                catch (Exception ex)
1518
                {
1519
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1520
                }
1521
            }
1522

    
1523
            return dt;
1524
        }
1525

    
1526
        public static bool ConnCreateRevisionTable(Dictionary<string, string> dicColCheck, List<string> names)
1527
        {
1528
            bool result = false;
1529
            ID2Info id2Info = ID2Info.GetInstance();
1530

    
1531
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1532
            {
1533
                try
1534
                {
1535
                    if (names.Count == 0)
1536
                    {
1537
                        
1538
                        var query = $"CREATE TABLE ARS_COMMON.dbo.PSNRevision ([OID] [uniqueidentifier] ,[Project_OID] [uniqueidentifier] ," +
1539
                            $"[ProjectCode] nvarchar(255), [RevNumber] int ,[UserName] nvarchar(255) ,[TimeData] nvarchar(255) ," +
1540
                            $"[PSNDatabasePath] nvarchar(255) ,	[PsnByPBSFilter] varchar(20) ,[PsnByNPDFilter] varchar(20) ,[PidDrawings] int ,	" +
1541
                            $"[PipeSystems] int ,[PipeLines] int ,[Topologies] int ,[PipeSystemNetworks] int ,[InValidPSNs] int ,[E2E] int ," +
1542
                            $"[E2B] int ,[B2E] int ,[HDE] int ,[HD2] int ,[HDB] int ,[B2B] int, [LastModificationdate] nvarchar(255), [ID2_PSN] nvarchar(10))";
1543
                        using (var cmd = connection.GetSqlStringCommand(query))
1544
                        {
1545
                            cmd.ExecuteNonQuery();
1546
                        }
1547
                    }
1548
                    else
1549
                    {
1550
                        AddColumn(PSN_REVISION, dicColCheck, names);
1551
                    }
1552

    
1553
                    void AddColumn(string TableName, Dictionary<string, string> dicCol, List<string> colnames)
1554
                    {
1555
                        bool check = false;
1556
                        if (colnames != null)
1557
                        {
1558
                            foreach (KeyValuePair<string, string> col in dicCol)
1559
                            {
1560
                                check = false;
1561
                                foreach (string c in colnames)
1562
                                {
1563
                                    if (col.Key.Contains(c))
1564
                                    {
1565
                                        check = true;
1566
                                        break;
1567
                                    }
1568
                                }
1569

    
1570
                                if (!check) //없으면 추가
1571
                                {
1572
                                    string i = string.Empty;
1573
                                    if (col.Value.ToString().ToUpper().Contains("INT") || col.Value.ToString().ToUpper().Contains("REAL"))
1574
                                        i = "DEFAULT 0";
1575

    
1576
                                    var queryalter = $"ALTER TABLE ARS_COMMON.dbo.PSNRevision ADD [" + col.Key + "] " + col.Value + " " + i + ";";
1577
                                    using (var cmd = connection.GetSqlStringCommand(queryalter))
1578
                                    {
1579
                                        cmd.ExecuteNonQuery();
1580
                                    }
1581
                                }
1582
                            }
1583
                        }
1584
                    }
1585

    
1586
                    result = true;
1587
                }
1588
                catch (Exception ex)
1589
                {
1590
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1591
                }
1592
            }
1593

    
1594
            return result;
1595
        }
1596

    
1597
        public static bool UpdateRevision(string TimeData, string ProjectCode, int RevNumber, string UserName, string PSNDatabasePath, string PsnByPBSFilter, string PsnByNPDFilter,
1598
           int PidDrawings, int PipeSystems, int PipeLines, int Topologies, int PipeSystemNetworks, int InValidPSNs, int E2E, int E2B, int B2E, int HDE, int HD2, int HDB, int B2B)
1599
        {
1600
            ID2Info id2Info = ID2Info.GetInstance();
1601
            bool result = true;
1602

    
1603
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1604
            {
1605
                try
1606
                {
1607
                    using (var txn = connection.BeginTransaction())
1608
                    {
1609
                        try
1610
                        {
1611
                            string where = string.Format("DELETE FROM ARS_COMMON.dbo.PSNRevision WHERE ProjectCode = '{0}' AND PSNDatabasePath = '{1}' AND RevNumber = {2}", ProjectCode, PSNDatabasePath, RevNumber);
1612
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(where), txn);
1613
                            var query = $"INSERT INTO ARS_COMMON.dbo.PSNRevision (OID, Project_OID, ProjectCode, RevNumber, UserName, TimeData, PSNDatabasePath, " +
1614
                                $"PsnByPBSFilter, PsnByNPDFilter, PidDrawings, PipeSystems, PipeLines, Topologies, PipeSystemNetworks, InValidPSNs, E2E, E2B, B2E, HDE, " +
1615
                                $"HD2, HDB, B2B, LastModificationdate, ID2_PSN) VALUES (NEWID(), NEWID(), @ProjectCode, @RevNumber, @UserName, @TimeData, @PSNDatabasePath" +
1616
                                $", @PsnByPBSFilter, @PsnByNPDFilter, @PidDrawings, @PipeSystems, @PipeLines, @Topologies, @PipeSystemNetworks, @InValidPSNs, " +
1617
                                $"@E2E, @E2B, @B2E, @HDE, @HD2, @HDB, @B2B, @LastModificationdate, @ID2_PSN)";
1618
                            var cmd = connection.GetSqlStringCommand(query);
1619
                      
1620
                            AddWithValue(cmd, "@ProjectCode", ProjectCode);
1621
                            AddWithValue(cmd, "@RevNumber", RevNumber);
1622
                            AddWithValue(cmd, "@UserName", UserName);
1623
                            AddWithValue(cmd, "@TimeData", TimeData); //String.Format("{0:G}", dt) // DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
1624

    
1625
                            AddWithValue(cmd, "@PSNDatabasePath", PSNDatabasePath);
1626

    
1627
                            AddWithValue(cmd, "@PsnByPBSFilter", PsnByPBSFilter);
1628
                            AddWithValue(cmd, "@PsnByNPDFilter", PsnByNPDFilter);
1629
                            AddWithValue(cmd, "@PidDrawings", PidDrawings);
1630
                            AddWithValue(cmd, "@PipeSystems", PipeSystems);
1631
                            AddWithValue(cmd, "@PipeLines", PipeLines);
1632

    
1633
                            AddWithValue(cmd, "@Topologies", Topologies);
1634
                            AddWithValue(cmd, "@PipeSystemNetworks", PipeSystemNetworks);
1635
                            AddWithValue(cmd, "@InValidPSNs", InValidPSNs);
1636
                            AddWithValue(cmd, "@E2E", E2E);
1637
                            AddWithValue(cmd, "@E2B", E2B);
1638
                            AddWithValue(cmd, "@B2E", B2E);
1639
                            AddWithValue(cmd, "@HDE", HDE);
1640
                            AddWithValue(cmd, "@HD2", HD2);
1641
                            AddWithValue(cmd, "@HDB", HDB);
1642
                            AddWithValue(cmd, "@B2B", B2B);
1643
                            System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US");
1644
                            DateTime oDateTime = DateTime.Now;
1645
                            AddWithValue(cmd, "@LastModificationdate", oDateTime.ToString(ci));
1646
                            AddWithValue(cmd, "@ID2_PSN", "Y");
1647
                            connection.ExecuteNonQuery(cmd, txn);
1648

    
1649
                            txn.Commit();
1650
                        }
1651
                        catch (Exception ex)
1652
                        {
1653
                            txn.Rollback();
1654
                            result = false;
1655
                        }
1656
                    }
1657
                }
1658
                catch (Exception ex)
1659
                {
1660
                    System.Windows.Forms.MessageBox.Show(ex.Message);
1661
                    result = false;
1662
                }
1663
            }
1664

    
1665
            return result;
1666
        }
1667

    
1668

    
1669
        public static bool SaveRevision(string ProjectCode, int RevNumber, string UserName, string PSNDatabasePath, string PsnByPBSFilter, string PsnByNPDFilter,
1670
            int PidDrawings, int PipeSystems, int PipeLines, int Topologies, int PipeSystemNetworks, int InValidPSNs, int E2E, int E2B, int B2E, int HDE, int HD2, int HDB, int B2B)
1671
        {
1672
            ID2Info id2Info = ID2Info.GetInstance();
1673

    
1674
            bool result = true;
1675

    
1676
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1677
            {
1678
                try
1679
                {
1680
                    using (var txn = connection.BeginTransaction())
1681
                    {
1682
                        try
1683
                        {                           
1684
                         
1685
                            var query = $"INSERT INTO ARS_COMMON.dbo.PSNRevision (OID, Project_OID, ProjectCode, RevNumber, UserName, TimeData, PSNDatabasePath, " +
1686
                                $"PsnByPBSFilter, PsnByNPDFilter, PidDrawings, PipeSystems, PipeLines, Topologies, PipeSystemNetworks, InValidPSNs, E2E, E2B, B2E, HDE, " +
1687
                                $"HD2, HDB, B2B, LastModificationdate, ID2_PSN) VALUES (NEWID(), NEWID(), @ProjectCode, @RevNumber, @UserName, @TimeData, @PSNDatabasePath" +
1688
                                $", @PsnByPBSFilter, @PsnByNPDFilter, @PidDrawings, @PipeSystems, @PipeLines, @Topologies, @PipeSystemNetworks, @InValidPSNs, " +
1689
                                $"@E2E, @E2B, @B2E, @HDE, @HD2, @HDB, @B2B, @LastModificationdate, @ID2_PSN)";
1690
                            var cmd = connection.GetSqlStringCommand(query);
1691
                            AddWithValue(cmd, "@OID", Guid.NewGuid().ToString());
1692
                            AddWithValue(cmd, "@Project_OID", Guid.NewGuid().ToString());
1693
                            AddWithValue(cmd, "@ProjectCode", ProjectCode);
1694
                            AddWithValue(cmd, "@RevNumber", RevNumber);
1695
                            AddWithValue(cmd, "@UserName", UserName);
1696

    
1697
                            System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US");
1698
                            DateTime oDateTime = DateTime.Now;
1699

    
1700
                            AddWithValue(cmd, "@TimeData", oDateTime.ToString(ci)); //String.Format("{0:G}", dt) // DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
1701

    
1702
                            AddWithValue(cmd, "@PSNDatabasePath", PSNDatabasePath);
1703

    
1704
                            AddWithValue(cmd, "@PsnByPBSFilter", PsnByPBSFilter);
1705
                            AddWithValue(cmd, "@PsnByNPDFilter", PsnByNPDFilter);
1706
                            AddWithValue(cmd, "@PidDrawings", PidDrawings);
1707
                            AddWithValue(cmd, "@PipeSystems", PipeSystems);
1708
                            AddWithValue(cmd, "@PipeLines", PipeLines);
1709

    
1710
                            AddWithValue(cmd, "@Topologies", Topologies);
1711
                            AddWithValue(cmd, "@PipeSystemNetworks", PipeSystemNetworks);
1712
                            AddWithValue(cmd, "@InValidPSNs", InValidPSNs);
1713
                            AddWithValue(cmd, "@E2E", E2E);
1714
                            AddWithValue(cmd, "@E2B", E2B);
1715
                            AddWithValue(cmd, "@B2E", B2E);
1716
                            AddWithValue(cmd, "@HDE", HDE);
1717
                            AddWithValue(cmd, "@HD2", HD2);
1718
                            AddWithValue(cmd, "@HDB", HDB);
1719
                            AddWithValue(cmd, "@B2B", B2B);
1720
                            // AddWithValue(cmd, "@LastModificationdate", oDateTime.ToString(ci));
1721
                            AddWithValue(cmd, "@LastModificationdate", "");
1722
                            AddWithValue(cmd, "@ID2_PSN", "Y");
1723
                            
1724
                            connection.ExecuteNonQuery(cmd, txn);
1725
                            
1726
                            txn.Commit();
1727
                        }
1728
                        catch (Exception ex)
1729
                        {
1730
                            txn.Rollback();
1731
                            result = false;
1732
                        }
1733
                    }
1734
                }
1735
                catch (Exception ex)
1736
                {
1737
                    System.Windows.Forms.MessageBox.Show(ex.Message);
1738
                    result = false;
1739
                }
1740
            }
1741

    
1742
            return result;
1743
        }
1744

    
1745
        public static bool SavePSNData(PSN item)
1746
        {
1747
            ID2Info id2Info = ID2Info.GetInstance();
1748

    
1749
            bool result = true;            
1750

    
1751
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1752
            {
1753
                try
1754
                {
1755
                    using (var txn = connection.BeginTransaction())
1756
                    {
1757
                        try
1758
                        {
1759
                            // Path Items
1760
                            var query = $"DELETE FROM {PSN_PATHITEMS}";
1761
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1762
                            for (int i = 0; i < item.PathItems.Rows.Count; i++)
1763
                            {
1764
                                DataRow row = item.PathItems.Rows[i];
1765
                                query = $"INSERT INTO {PSN_PATHITEMS} " +
1766
                                    $"(OID, SequenceData_OID, TopologySet_OID, BranchTopologySet_OID, PipeLine_OID, ItemName, ItemTag, DESCRIPTION, CLASS, SUBCLASS, TYPE, " +
1767
                                    $"PIDNAME, Equipment_OID, NPD, GROUPTAG, PipeSystemNetwork_OID, PipeRun_OID, ViewPipeSystemNetwork_OID, EqpGroupTag, MainLineTag, EGTConnectedPoint, EGFlowDirection) VALUES " +
1768
                                    $"(@OID, @SequenceData_OID, @TopologySet_OID, @BranchTopologySet_OID, @PipeLine_OID, @ITEMNAME, @ITEMTAG, @DESCRIPTION, @Class, @SubClass, @TYPE, @PIDNAME, " +
1769
                                    $"@Equipment_OID, @NPD, @GROUPTAG, @PipeSystemNetwork_OID,@PipeRun_OID, @ViewPipeSystemNetwork_OID, @EqpGroupTag , @MainLineTag, @EGTConnectedPoint, @EGFlowDirection)";
1770
                                var cmd = connection.GetSqlStringCommand(query);
1771
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
1772
                                AddWithValue(cmd, "@SequenceData_OID", string.IsNullOrEmpty(row["SequenceData_OID"].ToString()) ? "" : row["SequenceData_OID"].ToString());
1773
                                AddWithValue(cmd, "@TopologySet_OID", string.IsNullOrEmpty(row["TopologySet_OID"].ToString()) ? "" : row["TopologySet_OID"].ToString());
1774
                                AddWithValue(cmd, "@BranchTopologySet_OID", string.IsNullOrEmpty(row["BranchTopologySet_OID"].ToString()) ? "" : row["BranchTopologySet_OID"].ToString());
1775
                                AddWithValue(cmd, "@PipeLine_OID", string.IsNullOrEmpty(row["PipeLine_OID"].ToString()) ? "" : row["PipeLine_OID"].ToString());
1776
                                AddWithValue(cmd, "@ITEMNAME", string.IsNullOrEmpty(row["ITEMNAME"].ToString()) ? "" : row["ITEMNAME"].ToString());
1777
                                AddWithValue(cmd, "@ITEMTAG", string.IsNullOrEmpty(row["ITEMTAG"].ToString()) ? "" : row["ITEMTAG"].ToString());
1778
                                AddWithValue(cmd, "@DESCRIPTION", string.IsNullOrEmpty(row["DESCRIPTION"].ToString()) ? "" : row["DESCRIPTION"].ToString());
1779
                                AddWithValue(cmd, "@Class", string.IsNullOrEmpty(row["Class"].ToString()) ? "" : row["Class"].ToString());
1780
                                AddWithValue(cmd, "@SubClass", string.IsNullOrEmpty(row["SubClass"].ToString()) ? "" : row["SubClass"].ToString());
1781
                                AddWithValue(cmd, "@TYPE", string.IsNullOrEmpty(row["TYPE"].ToString()) ? "" : row["TYPE"].ToString());
1782
                                AddWithValue(cmd, "@PIDNAME", string.IsNullOrEmpty(row["PIDNAME"].ToString()) ? "" : row["PIDNAME"].ToString());
1783
                                AddWithValue(cmd, "@Equipment_OID", string.IsNullOrEmpty(row["Equipment_OID"].ToString()) ? "" : row["Equipment_OID"].ToString());
1784
                                AddWithValue(cmd, "@NPD", string.IsNullOrEmpty(row["NPD"].ToString()) ? "" : row["NPD"].ToString());
1785
                                AddWithValue(cmd, "@GROUPTAG", string.IsNullOrEmpty(row["GROUPTAG"].ToString()) ? "" : row["GROUPTAG"].ToString());
1786
                                AddWithValue(cmd, "@PipeSystemNetwork_OID", string.IsNullOrEmpty(row["PipeSystemNetwork_OID"].ToString()) ? "" : row["PipeSystemNetwork_OID"].ToString());
1787
                                AddWithValue(cmd, "@ViewPipeSystemNetwork_OID", string.IsNullOrEmpty(row["ViewPipeSystemNetwork_OID"].ToString()) ? "" : row["ViewPipeSystemNetwork_OID"].ToString());
1788
                                AddWithValue(cmd, "@PipeRun_OID", string.IsNullOrEmpty(row["PipeRun_OID"].ToString()) ? "" : row["PipeRun_OID"].ToString());
1789
                                AddWithValue(cmd, "@EqpGroupTag", string.IsNullOrEmpty(row["EqpGroupTag"].ToString()) ? "" : row["EqpGroupTag"].ToString());
1790
                                AddWithValue(cmd, "@MainLineTag", string.IsNullOrEmpty(row["MainLineTag"].ToString()) ? "" : row["MainLineTag"].ToString());
1791

    
1792
                                AddWithValue(cmd, "@EGTConnectedPoint", string.IsNullOrEmpty(row["EGTConnectedPoint"].ToString()) ? "0" : row["EGTConnectedPoint"].ToString());
1793
                                AddWithValue(cmd, "@EGFlowDirection", string.IsNullOrEmpty(row["EGFlowDirection"].ToString()) ? "" : row["EGFlowDirection"].ToString());
1794
                                connection.ExecuteNonQuery(cmd, txn);
1795
                            }
1796

    
1797
                            // Sequence
1798
                            query = $"DELETE FROM {PSN_SEQUENCEDATA}";
1799
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1800
                            foreach (DataRow row in item.SequenceData.Rows)
1801
                            {
1802
                                query = $"INSERT INTO {PSN_SEQUENCEDATA} (OID, SERIALNUMBER, PathItem_OID, TopologySet_OID_Key) VALUES (@OID, @SERIALNUMBER, @PathItem_OID, @TopologySet_OID_Key)";
1803
                                var cmd = connection.GetSqlStringCommand(query);
1804
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
1805
                                AddWithValue(cmd, "@SERIALNUMBER", string.IsNullOrEmpty(row["SERIALNUMBER"].ToString()) ? "" : row["SERIALNUMBER"].ToString());
1806
                                AddWithValue(cmd, "@PathItem_OID", string.IsNullOrEmpty(row["PathItem_OID"].ToString()) ? "" : row["PathItem_OID"].ToString());
1807
                                AddWithValue(cmd, "@TopologySet_OID_Key", string.IsNullOrEmpty(row["TopologySet_OID_Key"].ToString()) ? "" : row["TopologySet_OID_Key"].ToString());
1808
                                connection.ExecuteNonQuery(cmd, txn);
1809
                            }
1810

    
1811
                            // Nozzle
1812
                            query = $"DELETE FROM {PSN_NOZZLE}";
1813
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1814
                            foreach (DataRow row in item.Nozzle.Rows)
1815
                            {
1816
                                query = $"INSERT INTO {PSN_NOZZLE} (OID, ItemTag, Xcoords, Ycoords, Equipment_OID, Fluid, NPD, PMC, Rotation, FlowDirection) VALUES (@OID, @ITEMTAG, @XCOORDS, @YCOORDS, @Equipment_OID, @FLUID, @NPD, @PMC, @ROTATION, @FlowDirection)";
1817
                                var cmd = connection.GetSqlStringCommand(query);
1818
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
1819
                                AddWithValue(cmd, "@ITEMTAG", string.IsNullOrEmpty(row["ITEMTAG"].ToString()) ? "" : row["ITEMTAG"].ToString());
1820

    
1821
                                if (string.IsNullOrEmpty(row["XCOORDS"].ToString()))
1822
                                    AddWithValue(cmd, "@XCOORDS", DBNull.Value);
1823
                                else
1824
                                    AddWithValue(cmd, "@XCOORDS", row["XCOORDS"].ToString());
1825

    
1826
                                if (string.IsNullOrEmpty(row["YCOORDS"].ToString()))
1827
                                    AddWithValue(cmd, "@YCOORDS", DBNull.Value);
1828
                                else
1829
                                    AddWithValue(cmd, "@YCOORDS", row["YCOORDS"].ToString());
1830

    
1831
                                AddWithValue(cmd, "@Equipment_OID", string.IsNullOrEmpty(row["Equipment_OID"].ToString()) ? "" : row["Equipment_OID"].ToString());
1832
                                AddWithValue(cmd, "@FLUID", string.IsNullOrEmpty(row["FLUID"].ToString()) ? "" : row["FLUID"].ToString());
1833
                                AddWithValue(cmd, "@NPD", string.IsNullOrEmpty(row["NPD"].ToString()) ? "" : row["NPD"].ToString());
1834
                                AddWithValue(cmd, "@PMC", string.IsNullOrEmpty(row["PMC"].ToString()) ? "" : row["PMC"].ToString());
1835

    
1836
                                if (string.IsNullOrEmpty(row["ROTATION"].ToString()))
1837
                                    AddWithValue(cmd, "@ROTATION", DBNull.Value);
1838
                                else
1839
                                    AddWithValue(cmd, "@ROTATION", row["ROTATION"].ToString());
1840

    
1841
                                AddWithValue(cmd, "@FlowDirection", string.IsNullOrEmpty(row["FlowDirection"].ToString()) ? "" : row["FlowDirection"].ToString());
1842
                                connection.ExecuteNonQuery(cmd, txn);
1843
                            }
1844

    
1845
                            //Equipment
1846
                            query = $"DELETE FROM {PSN_EQUIPMENT}";
1847
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1848
                            foreach (DataRow row in item.Equipment.Rows)
1849
                            {
1850
                                query = $"INSERT INTO {PSN_EQUIPMENT} (OID, ItemTag, Xcoords, Ycoords) VALUES (@OID, @ITEMTAG, @XCOORDS, @YCOORDS)";
1851
                                var cmd = connection.GetSqlStringCommand(query);
1852
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
1853
                                AddWithValue(cmd, "@ITEMTAG", string.IsNullOrEmpty(row["ITEMTAG"].ToString()) ? "" : row["ITEMTAG"].ToString());
1854

    
1855
                                if (string.IsNullOrEmpty(row["XCOORDS"].ToString()))
1856
                                    AddWithValue(cmd, "@XCOORDS", DBNull.Value);
1857
                                else
1858
                                    AddWithValue(cmd, "@XCOORDS", row["XCOORDS"].ToString());
1859

    
1860
                                if (string.IsNullOrEmpty(row["YCOORDS"].ToString()))
1861
                                    AddWithValue(cmd, "@YCOORDS", DBNull.Value);
1862
                                else
1863
                                    AddWithValue(cmd, "@YCOORDS", row["YCOORDS"].ToString());
1864

    
1865
                                connection.ExecuteNonQuery(cmd, txn);
1866
                            }
1867

    
1868
                            // TopologySet
1869
                            query = $"DELETE FROM {PSN_TOPOLOGYSET}";
1870
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1871
                            foreach (DataRow row in item.TopologySet.Rows)
1872
                            {
1873
                                query = $"INSERT INTO {PSN_TOPOLOGYSET} (OID, Type, SubType, HeadItemTag, TailItemTag, HeadItemSPID, TailItemSPID) VALUES (@OID, @Type, @SubType, @HeadItemTag, @TailItemTag, @HeadItemSPID, @TailItemSPID)";
1874
                                var cmd = connection.GetSqlStringCommand(query);
1875
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
1876
                                AddWithValue(cmd, "@Type", string.IsNullOrEmpty(row["Type"].ToString()) ? "" : row["Type"].ToString());
1877
                                AddWithValue(cmd, "@SubType", string.IsNullOrEmpty(row["SubType"].ToString()) ? "" : row["SubType"].ToString());
1878
                                AddWithValue(cmd, "@HeadItemTag", string.IsNullOrEmpty(row["HeadItemTag"].ToString()) ? "" : row["HeadItemTag"].ToString());
1879
                                AddWithValue(cmd, "@TailItemTag", string.IsNullOrEmpty(row["TailItemTag"].ToString()) ? "" : row["TailItemTag"].ToString());
1880
                                AddWithValue(cmd, "@HeadItemSPID", string.IsNullOrEmpty(row["HeadItemSPID"].ToString()) ? "" : row["HeadItemSPID"].ToString());
1881
                                AddWithValue(cmd, "@TailItemSPID", string.IsNullOrEmpty(row["TailItemSPID"].ToString()) ? "" : row["TailItemSPID"].ToString());
1882
                                connection.ExecuteNonQuery(cmd, txn);
1883
                            }
1884

    
1885
                            // PSN
1886
                            query = $"DELETE FROM {PSN_PIPESYSTEMNETWORK} WHERE PSNRevisionNumber = '{string.Format("V{0:D4}", item.Revision)}'";
1887
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1888
                            foreach (DataRow row in item.PipeSystemNetwork.Rows)
1889
                            {
1890
                                query = $"INSERT INTO {PSN_PIPESYSTEMNETWORK} " +
1891
                                    $"(OID, Type, OrderNumber, Pipeline_OID, FROM_DATA, TO_DATA, TopologySet_OID_Key, PSNRevisionNumber, PBS, Drawings, IsValid, Status, IncludingVirtualData, PSNAccuracy, Pocket) VALUES " +
1892
                                    $"(@OID, @Type, @OrderNumber, @Pipeline_OID, @FROM_DATA, @TO_DATA, @TopologySet_OID_Key, @PSNRevisionNumber,  @PBS, @Drawings, @IsValid, @Status, @IncludingVirtualData, @PSNAccuracy, @Pocket)";
1893
                                var cmd = connection.GetSqlStringCommand(query);
1894
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
1895
                                AddWithValue(cmd, "@Type", string.IsNullOrEmpty(row["Type"].ToString()) ? "" : row["Type"].ToString());
1896
                                AddWithValue(cmd, "@OrderNumber", string.IsNullOrEmpty(row["OrderNumber"].ToString()) ? "" : row["OrderNumber"].ToString());
1897
                                AddWithValue(cmd, "@Pipeline_OID", string.IsNullOrEmpty(row["Pipeline_OID"].ToString()) ? "" : row["Pipeline_OID"].ToString());
1898
                                AddWithValue(cmd, "@FROM_DATA", string.IsNullOrEmpty(row["FROM_DATA"].ToString()) ? "" : row["FROM_DATA"].ToString());
1899
                                AddWithValue(cmd, "@TO_DATA", string.IsNullOrEmpty(row["TO_DATA"].ToString()) ? "" : row["TO_DATA"].ToString());
1900
                                AddWithValue(cmd, "@TopologySet_OID_Key", string.IsNullOrEmpty(row["TopologySet_OID_Key"].ToString()) ? "" : row["TopologySet_OID_Key"].ToString());
1901
                                AddWithValue(cmd, "@PSNRevisionNumber", string.IsNullOrEmpty(row["PSNRevisionNumber"].ToString()) ? "" : row["PSNRevisionNumber"].ToString());
1902

    
1903
                                int IsValid = 0;
1904
                                if (row["IsValid"].ToString() == string.Empty || row["IsValid"].ToString() == "OK")
1905
                                    IsValid = 0;
1906
                                else if (row["IsValid"].ToString() == "InValid")
1907
                                    IsValid = 1;
1908
                                else if (row["IsValid"].ToString() == "Error")
1909
                                    IsValid = -1;
1910

    
1911
                                AddWithValue(cmd, "@IsValid", IsValid);
1912
                                AddWithValue(cmd, "@Status", string.IsNullOrEmpty(row["Status"].ToString()) ? "" : row["Status"].ToString());
1913

    
1914
                                AddWithValue(cmd, "@PBS", string.IsNullOrEmpty(row["PBS"].ToString()) ? "" : row["PBS"].ToString());
1915
                                AddWithValue(cmd, "@Drawings", string.IsNullOrEmpty(row["Drawings"].ToString()) ? "" : row["Drawings"].ToString());
1916

    
1917
                                AddWithValue(cmd, "@IncludingVirtualData", string.IsNullOrEmpty(row["IncludingVirtualData"].ToString()) ? "" : row["IncludingVirtualData"].ToString());
1918
                                if (string.IsNullOrEmpty(row["PSNAccuracy"].ToString()))
1919
                                    AddWithValue(cmd, "@PSNAccuracy", DBNull.Value);
1920
                                else
1921
                                    AddWithValue(cmd, "@PSNAccuracy", row["PSNAccuracy"].ToString().Replace("%", ""));
1922

    
1923
                                AddWithValue(cmd, "@Pocket", string.IsNullOrEmpty(row["Pocket"].ToString()) ? "Yes" : row["Pocket"].ToString());
1924

    
1925
                                connection.ExecuteNonQuery(cmd, txn);
1926
                            }
1927

    
1928
                            //Pipeline
1929
                            query = $"DELETE FROM {PSN_PIPELINE}";
1930
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1931
                            foreach (DataRow row in item.PipeLine.Rows)
1932
                            {
1933
                                query = $"INSERT INTO {PSN_PIPELINE} (OID, PipeSystem_OID, FLUID, PMC, SEQNUMBER, INSULATION, FROM_DATA, TO_DATA, Unit) VALUES (@OID, @PipeSystem_OID, @FLUID, @PMC, @SEQNUMBER, @INSULATION, @FROM_DATA, @TO_DATA, @Unit)";
1934
                                var cmd = connection.GetSqlStringCommand(query);
1935
                                AddWithValue(cmd, "@OID", row["OID"].ToString());
1936
                                AddWithValue(cmd, "@PipeSystem_OID", row["PipeSystem_OID"].ToString());
1937
                                AddWithValue(cmd, "@FLUID", row["FLUID"].ToString());
1938
                                AddWithValue(cmd, "@PMC", row["PMC"].ToString());
1939
                                AddWithValue(cmd, "@SEQNUMBER", row["SEQNUMBER"].ToString());
1940
                                AddWithValue(cmd, "@INSULATION", row["INSULATION"].ToString());
1941
                                AddWithValue(cmd, "@FROM_DATA", row["FROM_DATA"].ToString());
1942
                                AddWithValue(cmd, "@TO_DATA", row["TO_DATA"].ToString());
1943
                                AddWithValue(cmd, "@Unit", row["Unit"].ToString());
1944
                                connection.ExecuteNonQuery(cmd, txn);
1945
                            }
1946

    
1947
                            //PipeSystem
1948
                            query = $"DELETE FROM {PSN_PIPESYSTEM}";
1949
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1950
                            foreach (DataRow row in item.PipeSystem.Rows)
1951
                            {
1952
                                query = $"INSERT INTO {PSN_PIPESYSTEM} (OID, DESCRIPTION, FLUID, PMC, PipeLineQty, GroundLevel) VALUES (@OID, @DESCRIPTION, @FLUID, @PMC, @PipeLineQty, @GroundLevel)";
1953
                                var cmd = connection.GetSqlStringCommand(query);
1954
                                AddWithValue(cmd, "@OID", row["OID"].ToString());
1955
                                AddWithValue(cmd, "@DESCRIPTION", row["DESCRIPTION"].ToString());
1956
                                AddWithValue(cmd, "@FLUID", row["FLUID"].ToString());
1957
                                AddWithValue(cmd, "@PMC", row["PMC"].ToString());
1958
                                AddWithValue(cmd, "@PipeLineQty", row["PipeLineQty"].ToString());
1959
                                AddWithValue(cmd, "@GroundLevel", row["GroundLevel"].ToString());
1960
                                connection.ExecuteNonQuery(cmd, txn);
1961
                            }
1962

    
1963
                            if(id2Info.ID2DBType == ID2DB_Type.MSSQL)
1964
                            {
1965
                                query = $"If(db_id(N'" + PSN_COMMON + "') IS NULL) CREATE DATABASE [" + PSN_COMMON + "]";
1966
                                connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1967
                            }
1968
                          
1969

    
1970
                            txn.Commit();
1971
                        }
1972
                        catch (Exception ex)
1973
                        {
1974
                            txn.Rollback();
1975
                            result = false;
1976
                        }
1977

    
1978
                    }
1979
                    void AddColumn(string TableName, Dictionary<string, string> dicCol, List<string> colnames)
1980
                    {                        
1981
                        bool check = false;
1982
                        if (colnames != null)
1983
                        {
1984
                            foreach (KeyValuePair<string, string> col in dicCol)
1985
                            {
1986
                                check = false;
1987
                                foreach (string c in colnames)
1988
                                {
1989
                                    if (col.Key.Contains(c))
1990
                                    {
1991
                                        check = true;
1992
                                        break;
1993
                                    }
1994
                                }
1995

    
1996
                                if (!check) //없으면 추가
1997
                                {
1998
                                    string i = string.Empty;
1999
                                    if (col.Value.ToString().ToUpper().Contains("INT") || col.Value.ToString().ToUpper().Contains("REAL"))
2000
                                        i = "DEFAULT 0";
2001

    
2002
                                    var queryalter = $"ALTER TABLE " + TableName + " ADD [" + col.Key + "] " + col.Value + " " + i + ";";
2003
                                    using (var cmd = connection.GetSqlStringCommand(queryalter))
2004
                                    {
2005
                                        cmd.ExecuteNonQuery();
2006
                                    }
2007
                                }
2008
                            }
2009
                        }
2010
                    }
2011
                }
2012
                catch (Exception ex)
2013
                {
2014
                    System.Windows.Forms.MessageBox.Show(ex.Message);
2015
                    result = false;
2016
                }
2017
            }
2018

    
2019
            return result;
2020
        }
2021

    
2022
        public static bool SavePSNFluidCode(DataTable dt)
2023
        {
2024
            ID2Info id2Info = ID2Info.GetInstance();
2025

    
2026
            bool result = true;
2027
            using (IAbstractDatabase connection = id2Info.CreateConnection())
2028
            {
2029
                try
2030
                {
2031
                    using (var txn = connection.BeginTransaction())
2032
                    {
2033
                        try
2034
                        {
2035
                            var query = $"DELETE FROM {PSN_FLUIDCODE}";
2036
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
2037

    
2038
                            foreach (DataRow row in dt.Rows)
2039
                            {
2040
                                query = $"INSERT INTO {PSN_FLUIDCODE} (UID, Code, Description, Condition, Remarks, GroundLevel) VALUES (@UID, @Code, @Description, @Condition, @Remarks, @GroundLevel)";
2041
                                var cmd = connection.GetSqlStringCommand(query);
2042
                                cmd.Parameters.Clear();
2043

    
2044
                                {
2045
                                    var param = cmd.CreateParameter();
2046
                                    param.ParameterName = "@UID";
2047
                                    param.Value = row["UID"].ToString();
2048
                                    cmd.Parameters.Add(param);
2049
                                }
2050

    
2051
                                {
2052
                                    var param = cmd.CreateParameter();
2053
                                    param.ParameterName = "@Code";
2054
                                    param.Value = row["Code"].ToString();
2055
                                    cmd.Parameters.Add(param);
2056
                                }
2057

    
2058
                                {
2059
                                    var param = cmd.CreateParameter();
2060
                                    param.ParameterName = "@Description";
2061
                                    param.Value = row["Description"].ToString();
2062
                                    cmd.Parameters.Add(param);
2063
                                }
2064

    
2065
                                {
2066
                                    var param = cmd.CreateParameter();
2067
                                    param.ParameterName = "@Condition";
2068
                                    param.Value = row["Condition"].ToString();
2069
                                    cmd.Parameters.Add(param);
2070
                                }
2071

    
2072
                                {
2073
                                    var param = cmd.CreateParameter();
2074
                                    param.ParameterName = "@Remarks";
2075
                                    param.Value = row["Remarks"].ToString();
2076
                                    cmd.Parameters.Add(param);
2077
                                }
2078

    
2079
                                {
2080
                                    var param = cmd.CreateParameter();
2081
                                    param.ParameterName = "@GroundLevel";
2082
                                    param.Value = row["GroundLevel"].ToString();
2083
                                    cmd.Parameters.Add(param);
2084
                                }
2085

    
2086
                                connection.ExecuteNonQuery(cmd, txn);
2087
                            }
2088
                            txn.Commit();
2089
                        }
2090
                        catch (Exception ex)
2091
                        {
2092
                            txn.Rollback();
2093
                            result = false;
2094
                        }
2095
                    }
2096
                }
2097
                catch (Exception ex)
2098
                {
2099
                    System.Windows.Forms.MessageBox.Show(ex.Message);
2100
                    result = false;
2101
                }
2102
            }
2103

    
2104
            return result;
2105
        }
2106

    
2107
        public static DataTable SelectPSNFluidCode()
2108
        {
2109
            DataTable dt = null;
2110
            ID2Info id2Info = ID2Info.GetInstance();
2111

    
2112
            using (IAbstractDatabase connection = id2Info.CreateConnection())
2113
            {
2114
                try
2115
                {
2116
                    var query = $"SELECT * FROM {PSN_FLUIDCODE}";
2117
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2118
                    {
2119
                        dt = ds.Tables[0].Copy();
2120
                    }
2121
                }
2122
                catch (Exception ex)
2123
                {
2124
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2125
                }
2126
            }
2127

    
2128
            return dt;
2129
        }
2130

    
2131
        public static bool SavePSNPMC(DataTable dt)
2132
        {
2133
            ID2Info id2Info = ID2Info.GetInstance();
2134

    
2135
            bool result = true;
2136
            using (IAbstractDatabase connection = id2Info.CreateConnection())
2137
            {
2138
                try
2139
                {
2140
                    using (var txn = connection.BeginTransaction())
2141
                    {
2142
                        try
2143
                        {
2144
                            var query = $"DELETE FROM {PSN_PIPINGMATLCLASS}";
2145
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
2146

    
2147
                            foreach (DataRow row in dt.Rows)
2148
                            {
2149
                                query = $"INSERT INTO {PSN_PIPINGMATLCLASS} ( UID, Priority, Code, Description, Condition, Remarks, GroundLevel) VALUES (@UID, @Priority, @Code, @Description, @Condition, @Remarks, @GroundLevel)";
2150
                                var cmd = connection.GetSqlStringCommand(query);
2151
                                cmd.Parameters.Clear();
2152

    
2153
                                {
2154
                                    var param = cmd.CreateParameter();
2155
                                    param.ParameterName = "@UID";
2156
                                    param.Value = row["UID"].ToString();
2157
                                    cmd.Parameters.Add(param);
2158
                                }
2159

    
2160
                                {
2161
                                    var param = cmd.CreateParameter();
2162
                                    param.ParameterName = "@Priority";
2163
                                    param.Value = row["Priority"].ToString();
2164
                                    cmd.Parameters.Add(param);
2165
                                }
2166

    
2167
                                {
2168
                                    var param = cmd.CreateParameter();
2169
                                    param.ParameterName = "@Code";
2170
                                    param.Value = row["Code"].ToString();
2171
                                    cmd.Parameters.Add(param);
2172
                                }
2173

    
2174
                                {
2175
                                    var param = cmd.CreateParameter();
2176
                                    param.ParameterName = "@Description";
2177
                                    param.Value = row["Description"].ToString();
2178
                                    cmd.Parameters.Add(param);
2179
                                }
2180

    
2181
                                {
2182
                                    var param = cmd.CreateParameter();
2183
                                    param.ParameterName = "@Condition";
2184
                                    param.Value = row["Condition"].ToString();
2185
                                    cmd.Parameters.Add(param);
2186
                                }
2187

    
2188
                                {
2189
                                    var param = cmd.CreateParameter();
2190
                                    param.ParameterName = "@Remarks";
2191
                                    param.Value = row["Remarks"].ToString();
2192
                                    cmd.Parameters.Add(param);
2193
                                }
2194

    
2195
                                {
2196
                                    var param = cmd.CreateParameter();
2197
                                    param.ParameterName = "@GroundLevel";
2198
                                    param.Value = row["GroundLevel"].ToString();
2199
                                    cmd.Parameters.Add(param);
2200
                                }
2201

    
2202
                                connection.ExecuteNonQuery(cmd, txn);
2203
                            }
2204

    
2205
                            txn.Commit();
2206
                        }
2207
                        catch (Exception ex)
2208
                        {
2209
                            txn.Rollback();
2210
                            result = false;
2211
                        }
2212
                    }
2213
                }
2214
                catch (Exception ex)
2215
                {
2216
                    System.Windows.Forms.MessageBox.Show(ex.Message);
2217
                    result = false;
2218
                }
2219
            }
2220

    
2221
            return result;
2222
        }
2223

    
2224
        public static bool SavePSNInsulation(DataTable dt)
2225
        {
2226
            ID2Info id2Info = ID2Info.GetInstance();
2227

    
2228
            bool result = true;
2229
            using (IAbstractDatabase connection = id2Info.CreateConnection())
2230
            {
2231
                try
2232
                {
2233
                    using (var txn = connection.BeginTransaction())
2234
                    {
2235
                        try
2236
                        {
2237
                            var query = $"DELETE FROM {PSN_INSULATIONPURPOSE}";
2238
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
2239

    
2240
                            foreach (DataRow row in dt.Rows)
2241
                            {
2242
                                query = $"INSERT INTO {PSN_INSULATIONPURPOSE} (UID, Code, Description, Remarks) VALUES (@UID, @Code, @Description, @Remarks)";
2243
                                var cmd = connection.GetSqlStringCommand(query);
2244
                                cmd.Parameters.Clear();
2245

    
2246
                                {
2247
                                    var param = cmd.CreateParameter();
2248
                                    param.ParameterName = "@UID";
2249
                                    param.Value = row["UID"].ToString();
2250
                                    cmd.Parameters.Add(param);
2251
                                }
2252
                                
2253
                                {
2254
                                    var param = cmd.CreateParameter();
2255
                                    param.ParameterName = "@Code";
2256
                                    param.Value = row["Code"].ToString();
2257
                                    cmd.Parameters.Add(param);
2258
                                }
2259

    
2260
                                {
2261
                                    var param = cmd.CreateParameter();
2262
                                    param.ParameterName = "@Description";
2263
                                    param.Value = row["Description"].ToString();
2264
                                    cmd.Parameters.Add(param);
2265
                                }
2266
                                
2267
                                {
2268
                                    var param = cmd.CreateParameter();
2269
                                    param.ParameterName = "@Remarks";
2270
                                    param.Value = row["Remarks"].ToString();
2271
                                    cmd.Parameters.Add(param);
2272
                                }
2273

    
2274
                                connection.ExecuteNonQuery(cmd, txn);
2275
                            }
2276

    
2277
                            txn.Commit();
2278
                        }
2279
                        catch (Exception ex)
2280
                        {
2281
                            txn.Rollback();
2282
                            result = false;
2283
                        }
2284
                    }
2285
                }
2286
                catch (Exception ex)
2287
                {
2288
                    System.Windows.Forms.MessageBox.Show(ex.Message);
2289
                    result = false;
2290
                }
2291
            }
2292

    
2293
            return result;
2294
        }
2295

    
2296
        public static PSN GetDBPSN()
2297
        {
2298
            PSN result = new PSN();
2299
            ID2Info id2Info = ID2Info.GetInstance();
2300

    
2301
            using (IAbstractDatabase connection = id2Info.CreateConnection())
2302
            {
2303
                try
2304
                {
2305
                    //query = $"SELECT * FROM {PSN_PIPESYSTEMNETWORK}";
2306
                    //using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2307
                    //{
2308
                    //    result.PipeSystemNetwork = ds.Tables[0].Copy();
2309
                    //}
2310

    
2311
                    var query = $"SELECT * FROM {PSN_PIPESYSTEMNETWORK} WHERE PSNRevisionNumber = '{string.Format("V{0:D4}", GetRevision())}'";
2312
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2313
                    {
2314
                        result.PipeSystemNetwork = ds.Tables[0].Clone();
2315
                        result.PipeSystemNetwork.Columns["IsValid"].DataType = typeof(string);
2316

    
2317
                        foreach (DataRow row in ds.Tables[0].Rows)
2318
                        {
2319
                            DataRow newRow = result.PipeSystemNetwork.NewRow();
2320
                            newRow["OID"] = row["OID"].ToString();
2321
                            newRow["Type"] = row["Type"].ToString();
2322
                            newRow["OrderNumber"] = row["OrderNumber"].ToString();
2323
                            newRow["Pipeline_OID"] = row["Pipeline_OID"].ToString();
2324
                            newRow["FROM_DATA"] = row["FROM_DATA"].ToString();
2325
                            newRow["TO_DATA"] = row["TO_DATA"].ToString();
2326
                            newRow["TopologySet_OID_Key"] = row["TopologySet_OID_Key"].ToString();
2327
                            newRow["PSNRevisionNumber"] = row["PSNRevisionNumber"].ToString();
2328

    
2329
                            string IsValid = string.Empty;
2330

    
2331
                            if (Convert.ToInt32(row["IsValid"].ToString()) == 0)
2332
                                IsValid = string.Empty;//"OK";
2333
                            else if (Convert.ToInt32(row["IsValid"].ToString()) == 1)
2334
                                IsValid = "InValid";
2335
                            else if (Convert.ToInt32(row["IsValid"].ToString()) == -1)
2336
                                IsValid = "Error";
2337

    
2338
                            newRow["IsValid"] = IsValid;
2339

    
2340
                            newRow["Status"] = row["Status"].ToString();
2341
                            newRow["PBS"] = row["PBS"].ToString();
2342
                            newRow["Drawings"] = row["Drawings"].ToString();
2343

    
2344
                            newRow["IncludingVirtualData"] = row["IncludingVirtualData"].ToString();
2345
                            newRow["PSNAccuracy"] = row["PSNAccuracy"].ToString();
2346

    
2347
                            newRow["Pocket"] = row["Pocket"].ToString();
2348
                            
2349
                            result.PipeSystemNetwork.Rows.Add(newRow);
2350
                        }
2351
                    }
2352

    
2353
                    query = $"SELECT * FROM {PSN_EQUIPMENT}";
2354
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2355
                    {
2356
                        result.Equipment = ds.Tables[0].Copy();
2357
                    }
2358

    
2359
                    query = $"SELECT * FROM {PSN_NOZZLE}";
2360
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2361
                    {
2362
                        result.Nozzle = ds.Tables[0].Copy();
2363
                    }
2364

    
2365
                    query = $"SELECT * FROM {PSN_PATHITEMS}";
2366
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2367
                    {
2368
                        result.PathItems = ds.Tables[0].Copy();
2369
                    }
2370

    
2371
                    query = $"SELECT * FROM {PSN_SEQUENCEDATA}";
2372
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2373
                    {
2374
                        result.SequenceData = ds.Tables[0].Copy();
2375
                    }
2376

    
2377
                    query = $"SELECT * FROM {PSN_TOPOLOGYSET}";
2378
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2379
                    {
2380
                        result.TopologySet = ds.Tables[0].Copy();
2381
                    }
2382

    
2383
                    query = $"SELECT * FROM {PSN_PIPELINE}";
2384
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2385
                    {
2386
                        result.PipeLine = ds.Tables[0].Copy();
2387
                    }
2388

    
2389
                    query = $"SELECT * FROM {PSN_PIPESYSTEM}";
2390
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2391
                    {
2392
                        result.PipeSystem = ds.Tables[0].Copy();
2393
                    }
2394

    
2395
                    result.Revision = GetRevision();
2396
                }
2397
                catch (Exception ex)
2398
                {
2399
                    System.Windows.Forms.MessageBox.Show(ex.Message);
2400
                    result = null;
2401
                }
2402
            }
2403

    
2404
            return result;
2405
        }
2406

    
2407
        public static int GetRevision()
2408
        {
2409
            int result = 0;
2410
            ID2Info id2Info = ID2Info.GetInstance();
2411

    
2412
            using (IAbstractDatabase connection = id2Info.CreateConnection())
2413
            {
2414
                try
2415
                {
2416
                    var query = $"SELECT DISTINCT PSNRevisionNumber FROM {PSN_PIPESYSTEMNETWORK};";
2417
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2418
                    {
2419
                        foreach (DataRow row in ds.Tables[0].Rows)
2420
                        {
2421
                            string value = row["PSNRevisionNumber"].ToString();
2422
                            if (value.StartsWith("V"))
2423
                                value = value.Remove(0, 1);
2424
                            int revisionNumber = Convert.ToInt32(value);
2425
                            if (result < revisionNumber)
2426
                                result = revisionNumber;
2427
                        }
2428
                    }
2429
                }
2430
                catch (Exception ex)
2431
                {
2432
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2433
                    result = -1;
2434
                }
2435
            }
2436

    
2437
            return result;
2438
        }
2439

    
2440
        public static DataTable GetPathItem()
2441
        {
2442
            DataTable dt = null;
2443

    
2444
            ID2Info id2Info = ID2Info.GetInstance();
2445
            using (IAbstractDatabase connection = id2Info.CreateConnection())
2446
            {
2447
                try
2448
                {
2449
                    var query = $"SELECT * FROM {PSN_PATHITEMS}";
2450
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2451
                    {
2452
                        dt = ds.Tables[0].Copy();
2453
                    }
2454
                }
2455
                catch (Exception ex)
2456
                {
2457
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2458
                }
2459
            }
2460

    
2461
            return dt;
2462
        }
2463

    
2464
        public static DataTable GetTopologySet()
2465
        {
2466
            DataTable dt = null;
2467

    
2468
            ID2Info id2Info = ID2Info.GetInstance();
2469
            using (IAbstractDatabase connection = id2Info.CreateConnection())
2470
            {
2471
                try
2472
                {
2473
                    var query = $"SELECT * FROM {PSN_TOPOLOGYSET}";
2474
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2475
                    {
2476
                        dt = ds.Tables[0].Clone();
2477
                        foreach (DataRow row in ds.Tables[0].Rows)
2478
                        {
2479
                            DataRow newRow = dt.NewRow();
2480
                            newRow["OID"] = row["OID"].ToString();
2481
                            newRow["Type"] = row["Type"].ToString();
2482
                            newRow["SubType"] = row["SubType"].ToString();
2483
                            newRow["HeadItemTag"] = row["HeadItemTag"].ToString();
2484
                            newRow["TailItemTag"] = row["TailItemTag"].ToString();
2485
                            newRow["HeadItemSPID"] = row["HeadItemSPID"].ToString();
2486
                            newRow["TailItemSPID"] = row["TailItemSPID"].ToString();
2487
                            dt.Rows.Add(newRow);
2488
                        }
2489
                    }
2490
                }
2491
                catch (Exception ex)
2492
                {
2493
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2494
                }
2495
            }
2496

    
2497
            return dt;
2498
        }
2499

    
2500
        public static DataTable GetPipeSystemNetwork()
2501
        {
2502
            DataTable dt = null;
2503

    
2504
            ID2Info id2Info = ID2Info.GetInstance();
2505
            using (IAbstractDatabase connection = id2Info.CreateConnection())
2506
            {
2507
                try
2508
                {
2509
                    var query = $"SELECT * FROM {PSN_PIPESYSTEMNETWORK} WHERE PSNRevisionNumber = '{string.Format("V{0:D4}", GetRevision())}' ORDER BY OID, OrderNumber";
2510
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2511
                    {
2512
                        dt = ds.Tables[0].Clone();
2513
                        dt.Columns["IsValid"].DataType = typeof(string);
2514
                        foreach (DataRow row in ds.Tables[0].Rows)
2515
                        {
2516
                            DataRow newRow = dt.NewRow();
2517
                            newRow["OID"] = row["OID"].ToString();
2518
                            newRow["Type"] = row["Type"].ToString();
2519
                            newRow["OrderNumber"] = row["OrderNumber"].ToString();
2520
                            newRow["Pipeline_OID"] = row["Pipeline_OID"].ToString();
2521
                            newRow["FROM_DATA"] = row["FROM_DATA"].ToString();
2522
                            newRow["TO_DATA"] = row["TO_DATA"].ToString();
2523
                            newRow["TopologySet_OID_Key"] = row["TopologySet_OID_Key"].ToString();
2524
                            newRow["PSNRevisionNumber"] = row["PSNRevisionNumber"].ToString();
2525

    
2526
                            string IsValid = string.Empty;
2527

    
2528
                            if (Convert.ToInt32(row["IsValid"].ToString()) == 0)
2529
                                IsValid = string.Empty;//"OK";
2530
                            else if (Convert.ToInt32(row["IsValid"].ToString()) == 1)
2531
                                IsValid = "InValid";
2532
                            else if (Convert.ToInt32(row["IsValid"].ToString()) == -1)
2533
                                IsValid = "Error";
2534

    
2535
                            newRow["IsValid"] = IsValid;
2536
                            newRow["Status"] = row["Status"].ToString();
2537

    
2538
                            newRow["PBS"] = row["PBS"].ToString();
2539
                            newRow["Drawings"] = row["Drawings"].ToString();
2540
                            
2541
                            newRow["IncludingVirtualData"] = row["IncludingVirtualData"].ToString();
2542
                            newRow["PSNAccuracy"] = row["PSNAccuracy"].ToString();
2543

    
2544
                            newRow["Pocket"] = row["Pocket"].ToString();
2545
                            
2546
                            dt.Rows.Add(newRow);
2547
                        }
2548
                    }
2549
                }
2550
                catch (Exception ex)
2551
                {
2552
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2553
                }
2554
            }
2555

    
2556
            return dt;
2557
        }
2558

    
2559
        public static DataTable GetSequenceData()
2560
        {
2561
            DataTable dt = null;
2562

    
2563
            ID2Info id2Info = ID2Info.GetInstance();
2564
            using (IAbstractDatabase connection = id2Info.CreateConnection())
2565
            {
2566
                try
2567
                {
2568
                    var query = $"SELECT * FROM {PSN_SEQUENCEDATA}";
2569
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2570
                    {
2571
                        dt = ds.Tables[0].Copy();
2572
                    }
2573
                }
2574
                catch (Exception ex)
2575
                {
2576
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2577
                }
2578
            }
2579

    
2580
            return dt;
2581
        }
2582

    
2583
       
2584
        //Anohter DB
2585
        public static bool ConnTestAndCreateAnotherTable()
2586
        {
2587
            bool result = false;
2588
            AnotherID2Info id2Info = AnotherID2Info.GetInstance();
2589

    
2590
            using (IAbstractDatabase connection = id2Info.CreateConnection())
2591
            {
2592
                try
2593
                {
2594
                    var names = connection.GetTableNames();
2595
                    var matched = names.FirstOrDefault(param => param == PSN_HEADER_SETTING);
2596
                    Dictionary<string, string> dicColCheck = new Dictionary<string, string>();
2597
                    dicColCheck.Add("GROUP_ID", "TEXT");
2598
                    dicColCheck.Add("DESCRIPTION", "TEXT");
2599
                    dicColCheck.Add("INDEX", "INTEGER");
2600
                    dicColCheck.Add("NAME", "TEXT");
2601

    
2602
                    if (matched == null)
2603
                    {
2604
                        var query = $"CREATE TABLE {PSN_HEADER_SETTING} (GROUP_ID TEXT, DESCRIPTION TEXT, [INDEX] INTEGER, NAME TEXT)";
2605
                        using (var cmd = connection.GetSqlStringCommand(query))
2606
                        {
2607
                            cmd.ExecuteNonQuery();
2608
                        }
2609
                    }
2610
                    else
2611
                    {
2612
                        AddColumn(PSN_HEADER_SETTING, dicColCheck);
2613
                    }
2614

    
2615
                    matched = names.FirstOrDefault(param => param == PSN_VENTDRAIN_SETTING);
2616
                    dicColCheck.Clear();
2617
                    dicColCheck.Add("GROUP_ID", "TEXT");
2618
                    dicColCheck.Add("DESCRIPTION", "TEXT");
2619
                    dicColCheck.Add("INDEX", "INTEGER");
2620
                    dicColCheck.Add("NAME", "TEXT");
2621
                    if (matched == null)
2622
                    {
2623
                        var query = $"CREATE TABLE {PSN_VENTDRAIN_SETTING} (GROUP_ID TEXT, DESCRIPTION TEXT, [INDEX] INTEGER, NAME TEXT)";
2624
                        using (var cmd = connection.GetSqlStringCommand(query))
2625
                        {
2626
                            cmd.ExecuteNonQuery();
2627
                        }
2628
                    }
2629
                    else
2630
                    {
2631
                        AddColumn(PSN_VENTDRAIN_SETTING, dicColCheck);
2632
                    }
2633

    
2634
                    matched = names.FirstOrDefault(param => param == PSN_TOPOLOGY_RULE);
2635
                    dicColCheck.Clear();
2636
                    dicColCheck.Add("UID", "TEXT");
2637
                    if (matched == null)
2638
                    {
2639
                        var query = $"CREATE TABLE {PSN_TOPOLOGY_RULE} (UID TEXT)";
2640
                        using (var cmd = connection.GetSqlStringCommand(query))
2641
                        {
2642
                            cmd.ExecuteNonQuery();
2643
                        }
2644

    
2645
                        DataTable topologyRule = new DataTable();
2646
                        topologyRule.Columns.Add("NAME", typeof(string));
2647

    
2648
                        topologyRule.Rows.Add("FluidCode");
2649
                        topologyRule.Rows.Add("-");
2650
                        topologyRule.Rows.Add("PipingMaterialsClass");
2651
                        topologyRule.Rows.Add("-");
2652
                        topologyRule.Rows.Add("Tag Seq No");
2653

    
2654
                        SaveTopologyRule(topologyRule);
2655
                    }
2656
                    //else
2657
                    //{
2658
                    //    AddColumn(PSN_TOPOLOGY_RULE, dicColCheck);
2659
                    //}
2660

    
2661
                    matched = names.FirstOrDefault(param => param == PSN_PIPESYSTEMNETWORK);
2662
                    dicColCheck.Clear();
2663
                    dicColCheck.Add("OID", "NVARCHAR(255)");
2664
                    dicColCheck.Add("Type", "NVARCHAR(255)");
2665
                    dicColCheck.Add("OrderNumber", "NVARCHAR(255)");
2666
                    dicColCheck.Add("Pipeline_OID", "NVARCHAR(255)");
2667
                    dicColCheck.Add("From_Data", "NVARCHAR(255)");
2668
                    dicColCheck.Add("To_Data", "NVARCHAR(255)");
2669
                    dicColCheck.Add("TopologySet_OID_Key", "NVARCHAR(125)");
2670
                    dicColCheck.Add("PSNRevisionNumber", "NVARCHAR(255)");
2671
                    dicColCheck.Add("IsValid", "INT");
2672
                    dicColCheck.Add("Status", "NVARCHAR(255)");
2673
                    dicColCheck.Add("PBS", "NVARCHAR(255)");
2674
                    dicColCheck.Add("Drawings", "NVARCHAR(255)");
2675
                    dicColCheck.Add("IncludingVirtualData", "NVARCHAR(10)");
2676
                    dicColCheck.Add("PSNAccuracy", "REAL");
2677
                    dicColCheck.Add("Pocket", "NVARCHAR(10)");
2678
                    
2679
                    if (matched == null)
2680
                    {
2681
                        var query = $"CREATE TABLE {PSN_PIPESYSTEMNETWORK} (OID NVARCHAR(255), Type NVARCHAR(255), OrderNumber NVARCHAR(255), Pipeline_OID NVARCHAR(255), From_Data NVARCHAR(255), " +
2682
                            "To_Data NVARCHAR(255), TopologySet_OID_Key NVARCHAR(125), PSNRevisionNumber NVARCHAR(255), IsValid INTEGER, Status NVARCHAR(255), PBS NVARCHAR(255), Drawings NVARCHAR(255), " +
2683
                            "IncludingVirtualData NVARCHAR(10),  PSNAccuracy REAL, Pocket NVARCHAR(10))";
2684
                        using (var cmd = connection.GetSqlStringCommand(query))
2685
                        {
2686
                            cmd.ExecuteNonQuery();
2687
                        }
2688
                    }
2689
                    else
2690
                    {
2691
                        AddColumn(PSN_PIPESYSTEMNETWORK, dicColCheck);
2692
                    }
2693

    
2694
                    matched = names.FirstOrDefault(param => param == PSN_EQUIPMENT);
2695
                    dicColCheck.Clear();
2696
                    dicColCheck.Add("OID", "NVARCHAR(255)");
2697
                    dicColCheck.Add("ItemTag", "NVARCHAR(255)");
2698
                    dicColCheck.Add("Xcoords", "REAL");
2699
                    dicColCheck.Add("Ycoords", "REAL");
2700
                    if (matched == null)
2701
                    {
2702
                        var query = $"CREATE TABLE {PSN_EQUIPMENT} (OID NVARCHAR(255), ItemTag NVARCHAR(255), Xcoords REAL, Ycoords REAL)";
2703
                        using (var cmd = connection.GetSqlStringCommand(query))
2704
                        {
2705
                            cmd.ExecuteNonQuery();
2706
                        }
2707
                    }
2708
                    else
2709
                    {
2710
                        AddColumn(PSN_EQUIPMENT, dicColCheck);
2711
                    }
2712

    
2713
                    dicColCheck.Clear();
2714
                    dicColCheck.Add("OID", "NVARCHAR(255)");
2715
                    dicColCheck.Add("ItemTag", "NVARCHAR(255)");
2716
                    dicColCheck.Add("Xcoords", "REAL");
2717
                    dicColCheck.Add("Ycoords", "REAL");
2718
                    dicColCheck.Add("Equipment_OID", "NVARCHAR(255)");
2719
                    dicColCheck.Add("Fluid", "NVARCHAR(255)");
2720
                    dicColCheck.Add("NPD", "NVARCHAR(255)");
2721
                    dicColCheck.Add("PMC", "NVARCHAR(255)");
2722
                    dicColCheck.Add("Rotation", "REAL");
2723
                    dicColCheck.Add("FlowDirection", "NVARCHAR(255)");
2724

    
2725
                    matched = names.FirstOrDefault(param => param == PSN_NOZZLE);
2726
                    if (matched == null)
2727
                    {
2728
                        var query = $"CREATE TABLE {PSN_NOZZLE} (OID NVARCHAR(255), ItemTag NVARCHAR(255), Xcoords REAL, Ycoords REAL, Equipment_OID NVARCHAR(255), " +
2729
                            "Fluid NVARCHAR(255), NPD NVARCHAR(255), PMC NVARCHAR(255), Rotation REAL, FlowDirection NVARCHAR(255))";
2730
                        using (var cmd = connection.GetSqlStringCommand(query))
2731
                        {
2732
                            cmd.ExecuteNonQuery();
2733
                        }
2734
                    }
2735
                    else
2736
                    {
2737
                        AddColumn(PSN_NOZZLE, dicColCheck);
2738
                    }
2739

    
2740
                    matched = names.FirstOrDefault(param => param == PSN_FLUIDCODE);
2741
                    dicColCheck.Clear();
2742
                    dicColCheck.Add("UID", "NVARCHAR(50)");
2743
                    dicColCheck.Add("Code", "NVARCHAR(255)");
2744
                    dicColCheck.Add("Description", "NVARCHAR(255)");
2745
                    dicColCheck.Add("Condition", "NVARCHAR(255)");
2746
                    dicColCheck.Add("Remarks", "NVARCHAR(255)");
2747
                    dicColCheck.Add("GroundLevel", "NVARCHAR(20)");
2748
                    if (matched == null)
2749
                    {
2750
                        var query = $"CREATE TABLE {PSN_FLUIDCODE} (UID NVARCHAR(50), Code NVARCHAR(255), Description NVARCHAR(255), Condition NVARCHAR(255), Remarks NVARCHAR(255), GroundLevel NVARCHAR(20))";
2751
                        using (var cmd = connection.GetSqlStringCommand(query))
2752
                        {
2753
                            cmd.ExecuteNonQuery();
2754
                        }
2755
                    }
2756
                    else
2757
                    {
2758
                        AddColumn(PSN_FLUIDCODE, dicColCheck);
2759
                    }
2760

    
2761
                    matched = names.FirstOrDefault(param => param == PSN_PIPINGMATLCLASS);
2762
                    dicColCheck.Clear();
2763
                    dicColCheck.Add("UID", "NVARCHAR(50)");
2764
                    dicColCheck.Add("Priority", "INTEGER");
2765
                    dicColCheck.Add("Code", "NVARCHAR(255)");
2766
                    dicColCheck.Add("Description", "NVARCHAR(255)");
2767
                    dicColCheck.Add("Condition", "NVARCHAR(255)");
2768
                    dicColCheck.Add("Remarks", "NVARCHAR(255)");
2769
                    dicColCheck.Add("GroundLevel", "NVARCHAR(20)");
2770
                    if (matched == null)
2771
                    {
2772
                        var query = $"CREATE TABLE {PSN_PIPINGMATLCLASS} (UID NVARCHAR(50), Priority INTEGER, Code NVARCHAR(255), Description NVARCHAR(255), Condition NVARCHAR(255), Remarks NVARCHAR(255), GroundLevel NVARCHAR(20))";
2773
                        using (var cmd = connection.GetSqlStringCommand(query))
2774
                        {
2775
                            cmd.ExecuteNonQuery();
2776
                        }
2777
                    }
2778
                    else
2779
                    {
2780
                        AddColumn(PSN_PIPINGMATLCLASS, dicColCheck);
2781
                    }
2782

    
2783
                    matched = names.FirstOrDefault(param => param == PSN_SEQUENCEDATA);
2784
                    dicColCheck.Clear();
2785
                    dicColCheck.Add("OID", "NVARCHAR(255)");
2786
                    dicColCheck.Add("SERIALNUMBER", "NVARCHAR(255)");
2787
                    dicColCheck.Add("PathItem_OID", "NVARCHAR(255)");
2788
                    dicColCheck.Add("TopologySet_OID_Key", "NVARCHAR(255)");
2789
                    if (matched == null)
2790
                    {
2791
                        var query = $"CREATE TABLE {PSN_SEQUENCEDATA} (OID NVARCHAR(255), SERIALNUMBER NVARCHAR(255), PathItem_OID NVARCHAR(255), TopologySet_OID_Key NVARCHAR(255))";
2792
                        using (var cmd = connection.GetSqlStringCommand(query))
2793
                        {
2794
                            cmd.ExecuteNonQuery();
2795
                        }
2796
                    }
2797
                    else
2798
                    {
2799
                        AddColumn(PSN_SEQUENCEDATA, dicColCheck);
2800
                    }
2801

    
2802
                    matched = names.FirstOrDefault(param => param == PSN_PATHITEMS);
2803
                    dicColCheck.Clear();
2804
                    dicColCheck.Add("OID", "NVARCHAR(255)");
2805
                    dicColCheck.Add("SequenceData_OID", "NVARCHAR(255)");
2806
                    dicColCheck.Add("TopologySet_OID", "NVARCHAR(255)");
2807
                    dicColCheck.Add("BranchTopologySet_OID", "NVARCHAR(255)");
2808
                    dicColCheck.Add("PipeLine_OID", "NVARCHAR(255)");
2809
                    dicColCheck.Add("ItemName", "NVARCHAR(255)");
2810
                    dicColCheck.Add("ItemTag", "NVARCHAR(255)");
2811
                    dicColCheck.Add("DESCRIPTION", "NVARCHAR(255)");
2812
                    dicColCheck.Add("CLASS", "NVARCHAR(255)");
2813
                    dicColCheck.Add("SUBCLASS", "NVARCHAR(255)");
2814
                    dicColCheck.Add("TYPE", "NVARCHAR(255)");
2815
                    dicColCheck.Add("PIDNAME", "NVARCHAR(255)");
2816
                    dicColCheck.Add("Equipment_OID", "NVARCHAR(255)");
2817
                    dicColCheck.Add("NPD", "NVARCHAR(255)");
2818
                    dicColCheck.Add("GROUPTAG", "NVARCHAR(255)");
2819
                    dicColCheck.Add("PipeSystemNetwork_OID", "NVARCHAR(255)");
2820
                    dicColCheck.Add("PipeRun_OID", "NVARCHAR(255)");
2821
                    dicColCheck.Add("ViewPipeSystemNetwork_OID", "NVARCHAR(255)");
2822
                    dicColCheck.Add("EqpGroupTag", "NVARCHAR(255)");
2823
                    dicColCheck.Add("MainLineTag", "NVARCHAR(255)");
2824
                    dicColCheck.Add("EGTConnectedPoint", "INT");
2825
                    dicColCheck.Add("EGFlowDirection", "NVARCHAR(10)");
2826
                    if (matched == null)
2827
                    {
2828
                        var query = $"CREATE TABLE {PSN_PATHITEMS} (OID NVARCHAR(255), SequenceData_OID NVARCHAR(255), " +
2829
                            "TopologySet_OID NVARCHAR(255), BranchTopologySet_OID NVARCHAR(255), PipeLine_OID NVARCHAR(255), ItemName NVARCHAR(255), ItemTag NVARCHAR(255), DESCRIPTION NVARCHAR(255), " +
2830
                            "CLASS NVARCHAR(255), SUBCLASS NVARCHAR(255), TYPE NVARCHAR(255), PIDNAME NVARCHAR(255), Equipment_OID NVARCHAR(255), NPD NVARCHAR(255), GROUPTAG NVARCHAR(255), PipeSystemNetwork_OID NVARCHAR(255), PipeRun_OID NVARCHAR(255), " +
2831
                            "ViewPipeSystemNetwork_OID NVARCHAR(255), EqpGroupTag NVARCHAR(255), MainLineTag NVARCHAR(255), EGTConnectedPoint INT, EGFlowDirection NVARCHAR(10))";
2832
                        using (var cmd = connection.GetSqlStringCommand(query))
2833
                        {
2834
                            cmd.ExecuteNonQuery();
2835
                        }
2836
                    }
2837
                    else
2838
                    {
2839
                        AddColumn(PSN_PATHITEMS, dicColCheck);
2840
                    }
2841

    
2842
                    matched = names.FirstOrDefault(param => param == PSN_VIEW);
2843
                    dicColCheck.Clear();
2844
                    dicColCheck.Add("OID", "TEXT");
2845
                    if (matched == null)
2846
                    {
2847
                        var query = $"CREATE TABLE {PSN_VIEW} (OID TEXT)";
2848
                        using (var cmd = connection.GetSqlStringCommand(query))
2849
                        {
2850
                            cmd.ExecuteNonQuery();
2851
                        }
2852
                    }
2853

    
2854
                    matched = names.FirstOrDefault(param => param == PSN_TOPOLOGYSET);
2855
                    dicColCheck.Clear();
2856
                    dicColCheck.Add("OID", "NVARCHAR(255)");
2857
                    dicColCheck.Add("Type", "NVARCHAR(255)");
2858
                    dicColCheck.Add("SubType", "NVARCHAR(255)");
2859
                    dicColCheck.Add("HeadItemTag", "NVARCHAR(255)");
2860
                    dicColCheck.Add("TailItemTag", "NVARCHAR(255)");
2861
                    dicColCheck.Add("HeadItemSPID", "NVARCHAR(255)");
2862
                    dicColCheck.Add("TailItemSPID", "NVARCHAR(255)");
2863

    
2864
                    if (matched == null)
2865
                    {
2866
                        var query = $"CREATE TABLE { PSN_TOPOLOGYSET} (OID NVARCHAR(255), Type NVARCHAR(255), SubType NVARCHAR(255), HeadItemTag NVARCHAR(255), TailItemTag NVARCHAR(255), HeadItemSPID NVARCHAR(255), TailItemSPID NVARCHAR(255))";
2867
                        using (var cmd = connection.GetSqlStringCommand(query))
2868
                        {
2869
                            cmd.ExecuteNonQuery();
2870
                        }
2871
                    }
2872
                    else
2873
                    {
2874
                        AddColumn(PSN_TOPOLOGYSET, dicColCheck);
2875
                    }
2876

    
2877
                    matched = names.FirstOrDefault(param => param == PSN_TRANSFORMKEYWORD_SETTING);
2878
                    dicColCheck.Clear();
2879
                    dicColCheck.Add("INDEX", "INTEGER");
2880
                    dicColCheck.Add("NAME", "TEXT");
2881
                    dicColCheck.Add("KEYWORD", "TEXT");
2882
                    if (matched == null)
2883
                    {
2884
                        var query = $"CREATE TABLE {PSN_TRANSFORMKEYWORD_SETTING} ([INDEX] INTEGER, [NAME] TEXT, [KEYWORD] TEXT)";
2885
                        using (var cmd = connection.GetSqlStringCommand(query))
2886
                        {
2887
                            cmd.ExecuteNonQuery();
2888
                        }
2889
                    }
2890
                    else
2891
                    {
2892
                        AddColumn(PSN_TRANSFORMKEYWORD_SETTING, dicColCheck);
2893
                    }
2894

    
2895
                    matched = names.FirstOrDefault(param => param == PSN_PIPELINE);
2896
                    dicColCheck.Clear();
2897
                    dicColCheck.Add("OID", "NVARCHAR(255)");
2898
                    dicColCheck.Add("PipeSystem_OID", "NVARCHAR(255)");
2899
                    dicColCheck.Add("FLUID", "NVARCHAR(255)");
2900
                    dicColCheck.Add("PMC", "NVARCHAR(255)");
2901
                    dicColCheck.Add("SEQNUMBER", "NVARCHAR(255)");
2902
                    dicColCheck.Add("INSULATION", "NVARCHAR(255)");
2903
                    dicColCheck.Add("FROM_DATA", "NVARCHAR(255)");
2904
                    dicColCheck.Add("TO_DATA", "NVARCHAR(255)");
2905
                    dicColCheck.Add("Unit", "NVARCHAR(100)");
2906
                    if (matched == null)
2907
                    {
2908
                        var query = $"CREATE TABLE {PSN_PIPELINE} (OID NVARCHAR(255), PipeSystem_OID NVARCHAR(255), FLUID NVARCHAR(255), PMC NVARCHAR(255), SEQNUMBER NVARCHAR(255), INSULATION NVARCHAR(255), " +
2909
                            $"FROM_DATA NVARCHAR(255), TO_DATA NVARCHAR(255), Unit NVARCHAR(100))";
2910
                        using (var cmd = connection.GetSqlStringCommand(query))
2911
                        {
2912
                            cmd.ExecuteNonQuery();
2913
                        }
2914
                    }
2915
                    else
2916
                    {
2917
                        AddColumn(PSN_PIPELINE, dicColCheck);
2918
                    }
2919

    
2920
                    matched = names.FirstOrDefault(param => param == PSN_INSULATIONPURPOSE);
2921
                    dicColCheck.Clear();
2922
                    dicColCheck.Add("UID", "NVARCHAR(50)");
2923
                    dicColCheck.Add("Code", "NVARCHAR(255)");
2924
                    dicColCheck.Add("Description", "NVARCHAR(255)");
2925
                    dicColCheck.Add("Remarks", "NVARCHAR(255)");
2926
                    if (matched == null)
2927
                    {
2928
                        var query = $"CREATE TABLE {PSN_INSULATIONPURPOSE} (UID NVARCHAR(50), Code NVARCHAR(255), Description NVARCHAR(255), Remarks NVARCHAR(255))";
2929
                        using (var cmd = connection.GetSqlStringCommand(query))
2930
                        {
2931
                            cmd.ExecuteNonQuery();
2932
                        }
2933
                    }
2934
                    else
2935
                    {
2936
                        AddColumn(PSN_INSULATIONPURPOSE, dicColCheck);
2937
                    }
2938

    
2939
                    matched = names.FirstOrDefault(param => param == PSN_VALVEGROUP_SETTING);
2940
                    dicColCheck.Clear();
2941
                    dicColCheck.Add("OID", "NVARCHAR(255)");
2942
                    dicColCheck.Add("GroupType", "NVARCHAR(255)");
2943
                    dicColCheck.Add("TagIdentifier", "NVARCHAR(50)");
2944
                    dicColCheck.Add("AttributeName", "NVARCHAR(255)");
2945
                    dicColCheck.Add("SppidSymbolName", "NVARCHAR(255)");
2946
                    if (matched == null)
2947
                    {
2948
                        var query = $"CREATE TABLE {PSN_VALVEGROUP_SETTING} (OID NVARCHAR(50), GroupType NVARCHAR(255), TagIdentifier NVARCHAR(50), AttributeName NVARCHAR(255), SppidSymbolName NVARCHAR(255))";
2949
                        using (var cmd = connection.GetSqlStringCommand(query))
2950
                        {
2951
                            cmd.ExecuteNonQuery();
2952
                        }
2953
                    }
2954
                    else
2955
                    {
2956
                        AddColumn(PSN_VALVEGROUP_SETTING, dicColCheck);
2957
                    }
2958

    
2959
                    matched = names.FirstOrDefault(param => param == PSN_PIPESYSTEM);
2960
                    dicColCheck.Clear();
2961
                    dicColCheck.Add("OID", "NVARCHAR(255)");
2962
                    dicColCheck.Add("DESCRIPTION", "NVARCHAR(255)");
2963
                    dicColCheck.Add("FLUID", "NVARCHAR(255)");
2964
                    dicColCheck.Add("PMC", "NVARCHAR(255)");
2965
                    dicColCheck.Add("PipeLineQty", "NVARCHAR(255)");
2966
                    dicColCheck.Add("GroundLevel", "NVARCHAR(20)");
2967
                    if (matched == null)
2968
                    {
2969
                        var query = $"CREATE TABLE {PSN_PIPESYSTEM} (OID NVARCHAR(255), DESCRIPTION NVARCHAR(255), FLUID NVARCHAR(255), PMC NVARCHAR(255), PipeLineQty NVARCHAR(255), GroundLevel NVARCHAR(20))";
2970
                        using (var cmd = connection.GetSqlStringCommand(query))
2971
                        {
2972
                            cmd.ExecuteNonQuery();
2973
                        }
2974
                    }
2975
                    else
2976
                    {
2977
                        AddColumn(PSN_PIPESYSTEM, dicColCheck);
2978
                    }
2979

    
2980
                    matched = names.FirstOrDefault(param => param == PSN_NOPOCKETSETTING);
2981
                    dicColCheck.Clear();
2982
                    dicColCheck.Add("[INDEX]", "INTEGER");
2983
                    dicColCheck.Add("[TYPE]", "TEXT");
2984
                    dicColCheck.Add("[NAME]", "TEXT");
2985
                    if (matched == null)
2986
                    {
2987
                        var query = $"CREATE TABLE {PSN_NOPOCKETSETTING} ([INDEX] INTEGER, [TYPE] TEXT, [NAME] TEXT)";
2988
                        using (var cmd = connection.GetSqlStringCommand(query))
2989
                        {
2990
                            cmd.ExecuteNonQuery();
2991
                        }
2992
                    }
2993
                    else
2994
                    {
2995
                        AddColumn(PSN_NOPOCKETSETTING, dicColCheck);
2996
                    }
2997

    
2998
                    matched = names.FirstOrDefault(param => param == PSN_AIRFINCOOLERSETTING);
2999
                    dicColCheck.Clear();
3000
                    dicColCheck.Add("[INDEX]", "INTEGER");
3001
                    dicColCheck.Add("[TYPE]", "TEXT");
3002
                    dicColCheck.Add("[NAME]", "TEXT");
3003
                    if (matched == null)
3004
                    {
3005
                        var query = $"CREATE TABLE {PSN_AIRFINCOOLERSETTING}  ([INDEX] INTEGER, [TYPE] TEXT, [NAME] TEXT)";
3006
                        using (var cmd = connection.GetSqlStringCommand(query))
3007
                        {
3008
                            cmd.ExecuteNonQuery();
3009
                        }
3010
                    }
3011
                    else
3012
                    {
3013
                        AddColumn(PSN_AIRFINCOOLERSETTING, dicColCheck);
3014
                    }
3015
                    
3016

    
3017
                    var query2 = $"If(db_id(N'" + PSN_COMMON + "') IS NULL) CREATE DATABASE [" + PSN_COMMON + "]";
3018
                    if (id2Info.ID2DBType == AnotherID2DB_Type.MSSQL)
3019
                    {
3020
                        //connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3021
                        using (var cmd = connection.GetSqlStringCommand(query2))
3022
                        {
3023
                            cmd.ExecuteNonQuery();
3024
                        }
3025
                    }
3026

    
3027
                    void AddColumn(string TableName, Dictionary<string, string> dicCol)
3028
                    {
3029
                        var colnames = connection.GetColumnNames(TableName);
3030
                        bool check = false;
3031
                        if (colnames != null)
3032
                        {
3033
                            foreach (KeyValuePair<string, string> col in dicCol)
3034
                            {
3035
                                check = false;
3036
                                foreach (string c in colnames)
3037
                                {
3038
                                    if (col.Key.ToUpper().Equals(c.ToUpper()))
3039
                                    {
3040
                                        check = true;
3041
                                        break;
3042
                                    }
3043
                                }
3044

    
3045
                                if (!check) //없으면 추가
3046
                                {
3047
                                    string i = string.Empty;
3048
                                    if (col.Value.ToString().ToUpper().Contains("INT") || col.Value.ToString().ToUpper().Contains("REAL"))
3049
                                        i = "DEFAULT 0";
3050

    
3051
                                    var query = $"ALTER TABLE " + TableName + " ADD [" + col.Key + "] " + col.Value + " " + i + ";";
3052
                                    using (var cmd = connection.GetSqlStringCommand(query))
3053
                                    {
3054
                                        cmd.ExecuteNonQuery();
3055
                                    }
3056
                                }
3057
                            }
3058
                        }
3059
                    }
3060

    
3061
                    result = true;
3062
                }
3063
                catch (Exception ex)
3064
                {
3065
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
3066
                }
3067
            }
3068

    
3069
            return result;
3070
        }
3071

    
3072
        public static bool SaveAnotherRevision(string ProjectCode, int RevNumber, string UserName, string PSNDatabasePath, string PsnByPBSFilter, string PsnByNPDFilter,
3073
         int PidDrawings, int PipeSystems, int PipeLines, int Topologies, int PipeSystemNetworks, int InValidPSNs, int E2E, int E2B, int B2E, int HDE, int HD2, int HDB, int B2B)
3074
        {
3075
            AnotherID2Info id2Info = AnotherID2Info.GetInstance();
3076

    
3077
            bool result = true;
3078

    
3079
            using (IAbstractDatabase connection = id2Info.CreateConnection())
3080
            {
3081
                try
3082
                {
3083
                    using (var txn = connection.BeginTransaction())
3084
                    {
3085
                        try
3086
                        {
3087

    
3088
                            var query = $"INSERT INTO ARS_COMMON.dbo.PSNRevision (OID, Project_OID, ProjectCode, RevNumber, UserName, TimeData, PSNDatabasePath, " +
3089
                                $"PsnByPBSFilter, PsnByNPDFilter, PidDrawings, PipeSystems, PipeLines, Topologies, PipeSystemNetworks, InValidPSNs, E2E, E2B, B2E, HDE, " +
3090
                                $"HD2, HDB, B2B, LastModificationdate, ID2_PSN) VALUES (NEWID(), NEWID(), @ProjectCode, @RevNumber, @UserName, @TimeData, @PSNDatabasePath" +
3091
                                $", @PsnByPBSFilter, @PsnByNPDFilter, @PidDrawings, @PipeSystems, @PipeLines, @Topologies, @PipeSystemNetworks, @InValidPSNs, " +
3092
                                $"@E2E, @E2B, @B2E, @HDE, @HD2, @HDB, @B2B, @LastModificationdate, @ID2_PSN)";
3093
                            var cmd = connection.GetSqlStringCommand(query);
3094
                            AddWithValue(cmd, "@OID", Guid.NewGuid().ToString());
3095
                            AddWithValue(cmd, "@Project_OID", Guid.NewGuid().ToString());
3096
                            AddWithValue(cmd, "@ProjectCode", ProjectCode);
3097
                            AddWithValue(cmd, "@RevNumber", RevNumber);
3098
                            AddWithValue(cmd, "@UserName", UserName);
3099

    
3100
                            System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US");
3101
                            DateTime oDateTime = DateTime.Now;                            
3102

    
3103
                            AddWithValue(cmd, "@TimeData", oDateTime.ToString(ci)); //String.Format("{0:G}", dt) // DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
3104
                            
3105
                            AddWithValue(cmd, "@PSNDatabasePath", PSNDatabasePath);
3106

    
3107
                            AddWithValue(cmd, "@PsnByPBSFilter", PsnByPBSFilter);
3108
                            AddWithValue(cmd, "@PsnByNPDFilter", PsnByNPDFilter);
3109
                            AddWithValue(cmd, "@PidDrawings", PidDrawings);
3110
                            AddWithValue(cmd, "@PipeSystems", PipeSystems);
3111
                            AddWithValue(cmd, "@PipeLines", PipeLines);
3112

    
3113
                            AddWithValue(cmd, "@Topologies", Topologies);
3114
                            AddWithValue(cmd, "@PipeSystemNetworks", PipeSystemNetworks);
3115
                            AddWithValue(cmd, "@InValidPSNs", InValidPSNs);
3116
                            AddWithValue(cmd, "@E2E", E2E);
3117
                            AddWithValue(cmd, "@E2B", E2B);
3118
                            AddWithValue(cmd, "@B2E", B2E);
3119
                            AddWithValue(cmd, "@HDE", HDE);
3120
                            AddWithValue(cmd, "@HD2", HD2);
3121
                            AddWithValue(cmd, "@HDB", HDB);
3122
                            AddWithValue(cmd, "@B2B", B2B);
3123

    
3124
                            AddWithValue(cmd, "@LastModificationdate", oDateTime.ToString(ci));
3125
                            AddWithValue(cmd, "@ID2_PSN", "Y");
3126
                            
3127
                            connection.ExecuteNonQuery(cmd, txn);
3128

    
3129
                            txn.Commit();
3130
                        }
3131
                        catch (Exception ex)
3132
                        {
3133
                            txn.Rollback();
3134
                            result = false;
3135
                        }
3136
                    }
3137
                }
3138
                catch (Exception ex)
3139
                {
3140
                    System.Windows.Forms.MessageBox.Show(ex.Message);
3141
                    result = false;
3142
                }
3143
            }
3144

    
3145
            return result;
3146
        }
3147

    
3148
        public static bool ConnAnotherCreateRevisionTable(Dictionary<string, string> dicColCheck, List<string> names)
3149
        {
3150
            bool result = false;
3151
            AnotherID2Info id2Info = AnotherID2Info.GetInstance();
3152

    
3153
            using (IAbstractDatabase connection = id2Info.CreateConnection())
3154
            {
3155
                try
3156
                {
3157
                    if (names.Count == 0)
3158
                    {
3159

    
3160
                        var query = $"CREATE TABLE ARS_COMMON.dbo.PSNRevision ([OID] [uniqueidentifier] ,[Project_OID] [uniqueidentifier] ," +
3161
                            $"[ProjectCode] nvarchar(255), [RevNumber] int ,[UserName] nvarchar(255) ,[TimeData] nvarchar(255) ," +
3162
                            $"[PSNDatabasePath] nvarchar(255) ,	[PsnByPBSFilter] varchar(20) ,[PsnByNPDFilter] varchar(20) ,[PidDrawings] int ,	" +
3163
                            $"[PipeSystems] int ,[PipeLines] int ,[Topologies] int ,[PipeSystemNetworks] int ,[InValidPSNs] int ,[E2E] int ," +
3164
                            $"[E2B] int ,[B2E] int ,[HDE] int ,[HD2] int ,[HDB] int ,[B2B] int , [LastModificationdate] nvarchar(255), [ID2_PSN] nvarchar(10))";
3165
                        using (var cmd = connection.GetSqlStringCommand(query))
3166
                        {
3167
                            cmd.ExecuteNonQuery();
3168
                        }
3169
                    }
3170
                    else
3171
                    {
3172
                        AddColumn(PSN_REVISION, dicColCheck, names);
3173
                    }
3174

    
3175
                    void AddColumn(string TableName, Dictionary<string, string> dicCol, List<string> colnames)
3176
                    {
3177
                        bool check = false;
3178
                        if (colnames != null)
3179
                        {
3180
                            foreach (KeyValuePair<string, string> col in dicCol)
3181
                            {
3182
                                check = false;
3183
                                foreach (string c in colnames)
3184
                                {
3185
                                    if (col.Key.Contains(c))
3186
                                    {
3187
                                        check = true;
3188
                                        break;
3189
                                    }
3190
                                }
3191

    
3192
                                if (!check) //없으면 추가
3193
                                {
3194
                                    string i = string.Empty;
3195
                                    if (col.Value.ToString().ToUpper().Contains("INT") || col.Value.ToString().ToUpper().Contains("REAL"))
3196
                                        i = "DEFAULT 0";
3197

    
3198
                                    var queryalter = $"ALTER TABLE ARS_COMMON.dbo.PSNRevision ADD [" + col.Key + "] " + col.Value + " " + i + ";";
3199
                                    using (var cmd = connection.GetSqlStringCommand(queryalter))
3200
                                    {
3201
                                        cmd.ExecuteNonQuery();
3202
                                    }
3203
                                }
3204
                            }
3205
                        }
3206
                    }
3207

    
3208
                    result = true;
3209
                }
3210
                catch (Exception ex)
3211
                {
3212
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
3213
                }
3214
            }
3215

    
3216
            return result;
3217
        }
3218

    
3219
        public static DataTable SelectAnotherRevision()
3220
        {
3221
            DataTable dt = null;
3222
            AnotherID2Info id2Info = AnotherID2Info.GetInstance();
3223

    
3224
            using (IAbstractDatabase connection = id2Info.CreateConnection())
3225
            {
3226
                try
3227
                {
3228
                    var query = $"SELECT * FROM ARS_COMMON.dbo.PSNREVISION";
3229

    
3230
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
3231
                    {
3232
                        dt = ds.Tables[0].Copy();
3233
                    }
3234
                }
3235
                catch (Exception ex)
3236
                {
3237
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
3238
                }
3239
            }
3240

    
3241
            return dt;
3242
        }
3243

    
3244
        public static DataTable SelectAnotherRevisionTable()
3245
        {
3246
            DataTable dt = null;
3247
            AnotherID2Info id2Info = AnotherID2Info.GetInstance();
3248

    
3249
            using (IAbstractDatabase connection = id2Info.CreateConnection())
3250
            {
3251
                try
3252
                {
3253
                    var query = $"SELECT T.name AS table_name, C.name AS column_name FROM ARS_COMMON.sys.tables AS T INNER JOIN ARS_COMMON.sys.columns AS C ON T.object_id = C.object_id WHERE T.name = 'PSNREVISION'";
3254
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
3255
                    {
3256
                        dt = ds.Tables[0].Copy();
3257
                    }
3258
                }
3259
                catch (Exception ex)
3260
                {
3261
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
3262
                }
3263
            }
3264

    
3265
            return dt;
3266
        }
3267

    
3268
        public static bool SaveAnotherPSNData(PSN item, List<HeaderInfo> headerInfos, List<VentDrainInfo> ventDrainInfos,
3269
          List<KeywordItem> keywordItems, DataTable dtTopologyRule, DataTable dtFluidCode, DataTable dtPMC, DataTable dtInsulation, DataTable dtvalvegrouping, DataTable dtnopocket)
3270
        {
3271
            AnotherID2Info id2Info = AnotherID2Info.GetInstance();
3272

    
3273
            bool result = true;
3274
            using (IAbstractDatabase connection = id2Info.CreateConnection())
3275
            {
3276
                try
3277
                {
3278
                    using (var txn = connection.BeginTransaction())
3279
                    {
3280
                        try
3281
                        {
3282
                            // Path Items
3283
                            var query = $"DELETE FROM {PSN_PATHITEMS}";
3284
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3285
                            for (int i = 0; i < item.PathItems.Rows.Count; i++)
3286
                            {
3287
                                DataRow row = item.PathItems.Rows[i];
3288
                                query = $"INSERT INTO {PSN_PATHITEMS} " +
3289
                                    $"(OID, SequenceData_OID, TopologySet_OID, BranchTopologySet_OID, PipeLine_OID, ItemName, ItemTag, DESCRIPTION, CLASS, SUBCLASS, TYPE, " +
3290
                                    $"PIDNAME, Equipment_OID, NPD, GROUPTAG, PipeSystemNetwork_OID, PipeRun_OID, ViewPipeSystemNetwork_OID, EqpGroupTag , MainLineTag, EGTConnectedPoint, EGFlowDirection ) VALUES " +
3291
                                    $"(@OID, @SequenceData_OID, @TopologySet_OID, @BranchTopologySet_OID, @PipeLine_OID, @ITEMNAME, @ITEMTAG, @DESCRIPTION, @Class, @SubClass, @TYPE, @PIDNAME," +
3292
                                    $" @Equipment_OID, @NPD, @GROUPTAG, @PipeSystemNetwork_OID,@PipeRun_OID, @ViewPipeSystemNetwork_OID, @EqpGroupTag , @MainLineTag, @EGTConnectedPoint, @EGFlowDirection )";
3293
                                var cmd = connection.GetSqlStringCommand(query);
3294
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
3295
                                AddWithValue(cmd, "@SequenceData_OID", string.IsNullOrEmpty(row["SequenceData_OID"].ToString()) ? "" : row["SequenceData_OID"].ToString());
3296
                                AddWithValue(cmd, "@TopologySet_OID", string.IsNullOrEmpty(row["TopologySet_OID"].ToString()) ? "" : row["TopologySet_OID"].ToString());
3297
                                AddWithValue(cmd, "@BranchTopologySet_OID", string.IsNullOrEmpty(row["BranchTopologySet_OID"].ToString()) ? "" : row["BranchTopologySet_OID"].ToString());
3298
                                AddWithValue(cmd, "@PipeLine_OID", string.IsNullOrEmpty(row["PipeLine_OID"].ToString()) ? "" : row["PipeLine_OID"].ToString());
3299
                                AddWithValue(cmd, "@ITEMNAME", string.IsNullOrEmpty(row["ITEMNAME"].ToString()) ? "" : row["ITEMNAME"].ToString());
3300
                                AddWithValue(cmd, "@ITEMTAG", string.IsNullOrEmpty(row["ITEMTAG"].ToString()) ? "" : row["ITEMTAG"].ToString());
3301
                                AddWithValue(cmd, "@DESCRIPTION", string.IsNullOrEmpty(row["DESCRIPTION"].ToString()) ? "" : row["DESCRIPTION"].ToString());
3302
                                AddWithValue(cmd, "@Class", string.IsNullOrEmpty(row["Class"].ToString()) ? "" : row["Class"].ToString());
3303
                                AddWithValue(cmd, "@SubClass", string.IsNullOrEmpty(row["SubClass"].ToString()) ? "" : row["SubClass"].ToString());
3304
                                AddWithValue(cmd, "@TYPE", string.IsNullOrEmpty(row["TYPE"].ToString()) ? "" : row["TYPE"].ToString());
3305
                                AddWithValue(cmd, "@PIDNAME", string.IsNullOrEmpty(row["PIDNAME"].ToString()) ? "" : row["PIDNAME"].ToString());
3306
                                AddWithValue(cmd, "@Equipment_OID", string.IsNullOrEmpty(row["Equipment_OID"].ToString()) ? "" : row["Equipment_OID"].ToString());
3307
                                AddWithValue(cmd, "@NPD", string.IsNullOrEmpty(row["NPD"].ToString()) ? "" : row["NPD"].ToString());
3308
                                AddWithValue(cmd, "@GROUPTAG", string.IsNullOrEmpty(row["GROUPTAG"].ToString()) ? "" : row["GROUPTAG"].ToString());
3309
                                AddWithValue(cmd, "@PipeSystemNetwork_OID", string.IsNullOrEmpty(row["PipeSystemNetwork_OID"].ToString()) ? "" : row["PipeSystemNetwork_OID"].ToString());
3310
                                AddWithValue(cmd, "@ViewPipeSystemNetwork_OID", string.IsNullOrEmpty(row["ViewPipeSystemNetwork_OID"].ToString()) ? "" : row["ViewPipeSystemNetwork_OID"].ToString());
3311
                                AddWithValue(cmd, "@PipeRun_OID", string.IsNullOrEmpty(row["PipeRun_OID"].ToString()) ? "" : row["PipeRun_OID"].ToString());
3312
                                AddWithValue(cmd, "@EqpGroupTag", string.IsNullOrEmpty(row["EqpGroupTag"].ToString()) ? "" : row["EqpGroupTag"].ToString());
3313
                                AddWithValue(cmd, "@MainLineTag", string.IsNullOrEmpty(row["MainLineTag"].ToString()) ? "" : row["MainLineTag"].ToString());
3314
                                AddWithValue(cmd, "@EGTConnectedPoint", string.IsNullOrEmpty(row["EGTConnectedPoint"].ToString()) ? "0" : row["EGTConnectedPoint"].ToString());
3315
                                AddWithValue(cmd, "@EGFlowDirection", string.IsNullOrEmpty(row["EGFlowDirection"].ToString()) ? "" : row["EGFlowDirection"].ToString());
3316

    
3317
                                connection.ExecuteNonQuery(cmd, txn);
3318
                            }
3319

    
3320
                            // Sequence
3321
                            query = $"DELETE FROM {PSN_SEQUENCEDATA}";
3322
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3323
                            foreach (DataRow row in item.SequenceData.Rows)
3324
                            {
3325
                                query = $"INSERT INTO {PSN_SEQUENCEDATA} (OID, SERIALNUMBER, PathItem_OID, TopologySet_OID_Key) VALUES (@OID, @SERIALNUMBER, @PathItem_OID, @TopologySet_OID_Key)";
3326
                                var cmd = connection.GetSqlStringCommand(query);
3327
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
3328
                                AddWithValue(cmd, "@SERIALNUMBER", string.IsNullOrEmpty(row["SERIALNUMBER"].ToString()) ? "" : row["SERIALNUMBER"].ToString());
3329
                                AddWithValue(cmd, "@PathItem_OID", string.IsNullOrEmpty(row["PathItem_OID"].ToString()) ? "" : row["PathItem_OID"].ToString());
3330
                                AddWithValue(cmd, "@TopologySet_OID_Key", string.IsNullOrEmpty(row["TopologySet_OID_Key"].ToString()) ? "" : row["TopologySet_OID_Key"].ToString());
3331
                                connection.ExecuteNonQuery(cmd, txn);
3332
                            }
3333

    
3334
                            // Nozzle
3335
                            query = $"DELETE FROM {PSN_NOZZLE}";
3336
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3337
                            foreach (DataRow row in item.Nozzle.Rows)
3338
                            {
3339
                                query = $"INSERT INTO {PSN_NOZZLE} (OID, ItemTag, Xcoords, Ycoords, Equipment_OID, Fluid, NPD, PMC, Rotation, FlowDirection) VALUES (@OID, @ITEMTAG, @XCOORDS, @YCOORDS, @Equipment_OID, @FLUID, @NPD, @PMC, @ROTATION, @FlowDirection)";
3340
                                var cmd = connection.GetSqlStringCommand(query);
3341
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
3342
                                AddWithValue(cmd, "@ITEMTAG", string.IsNullOrEmpty(row["ITEMTAG"].ToString()) ? "" : row["ITEMTAG"].ToString());
3343

    
3344
                                if (string.IsNullOrEmpty(row["XCOORDS"].ToString()))
3345
                                    AddWithValue(cmd, "@XCOORDS", DBNull.Value);
3346
                                else
3347
                                    AddWithValue(cmd, "@XCOORDS", row["XCOORDS"].ToString());
3348

    
3349
                                if (string.IsNullOrEmpty(row["YCOORDS"].ToString()))
3350
                                    AddWithValue(cmd, "@YCOORDS", DBNull.Value);
3351
                                else
3352
                                    AddWithValue(cmd, "@YCOORDS", row["YCOORDS"].ToString());
3353

    
3354
                                AddWithValue(cmd, "@Equipment_OID", string.IsNullOrEmpty(row["Equipment_OID"].ToString()) ? "" : row["Equipment_OID"].ToString());
3355
                                AddWithValue(cmd, "@FLUID", string.IsNullOrEmpty(row["FLUID"].ToString()) ? "" : row["FLUID"].ToString());
3356
                                AddWithValue(cmd, "@NPD", string.IsNullOrEmpty(row["NPD"].ToString()) ? "" : row["NPD"].ToString());
3357
                                AddWithValue(cmd, "@PMC", string.IsNullOrEmpty(row["PMC"].ToString()) ? "" : row["PMC"].ToString());
3358

    
3359
                                if (string.IsNullOrEmpty(row["ROTATION"].ToString()))
3360
                                    AddWithValue(cmd, "@ROTATION", DBNull.Value);
3361
                                else
3362
                                    AddWithValue(cmd, "@ROTATION", row["ROTATION"].ToString());
3363

    
3364
                                AddWithValue(cmd, "@FlowDirection", string.IsNullOrEmpty(row["FlowDirection"].ToString()) ? "" : row["FlowDirection"].ToString());
3365
                                connection.ExecuteNonQuery(cmd, txn);
3366
                            }
3367

    
3368
                            //Equipment
3369
                            query = $"DELETE FROM {PSN_EQUIPMENT}";
3370
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3371
                            foreach (DataRow row in item.Equipment.Rows)
3372
                            {
3373
                                query = $"INSERT INTO {PSN_EQUIPMENT} (OID, ItemTag, Xcoords, Ycoords) VALUES (@OID, @ITEMTAG, @XCOORDS, @YCOORDS)";
3374
                                var cmd = connection.GetSqlStringCommand(query);
3375
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
3376
                                AddWithValue(cmd, "@ITEMTAG", string.IsNullOrEmpty(row["ITEMTAG"].ToString()) ? "" : row["ITEMTAG"].ToString());
3377

    
3378
                                if (string.IsNullOrEmpty(row["XCOORDS"].ToString()))
3379
                                    AddWithValue(cmd, "@XCOORDS", DBNull.Value);
3380
                                else
3381
                                    AddWithValue(cmd, "@XCOORDS", row["XCOORDS"].ToString());
3382

    
3383
                                if (string.IsNullOrEmpty(row["YCOORDS"].ToString()))
3384
                                    AddWithValue(cmd, "@YCOORDS", DBNull.Value);
3385
                                else
3386
                                    AddWithValue(cmd, "@YCOORDS", row["YCOORDS"].ToString());
3387

    
3388
                                connection.ExecuteNonQuery(cmd, txn);
3389
                            }
3390

    
3391
                            // TopologySet
3392
                            query = $"DELETE FROM {PSN_TOPOLOGYSET}";
3393
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3394
                            foreach (DataRow row in item.TopologySet.Rows)
3395
                            {
3396
                                query = $"INSERT INTO {PSN_TOPOLOGYSET} (OID, Type, SubType, HeadItemTag, TailItemTag, HeadItemSPID, TailItemSPID) VALUES (@OID, @Type, @SubType, @HeadItemTag, @TailItemTag, @HeadItemSPID, @TailItemSPID)";
3397
                                var cmd = connection.GetSqlStringCommand(query);
3398
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
3399
                                AddWithValue(cmd, "@Type", string.IsNullOrEmpty(row["Type"].ToString()) ? "" : row["Type"].ToString());
3400
                                AddWithValue(cmd, "@SubType", string.IsNullOrEmpty(row["SubType"].ToString()) ? "" : row["SubType"].ToString());
3401
                                AddWithValue(cmd, "@HeadItemTag", string.IsNullOrEmpty(row["HeadItemTag"].ToString()) ? "" : row["HeadItemTag"].ToString());
3402
                                AddWithValue(cmd, "@TailItemTag", string.IsNullOrEmpty(row["TailItemTag"].ToString()) ? "" : row["TailItemTag"].ToString());
3403
                                AddWithValue(cmd, "@HeadItemSPID", string.IsNullOrEmpty(row["HeadItemSPID"].ToString()) ? "" : row["HeadItemSPID"].ToString());
3404
                                AddWithValue(cmd, "@TailItemSPID", string.IsNullOrEmpty(row["TailItemSPID"].ToString()) ? "" : row["TailItemSPID"].ToString());
3405
                                connection.ExecuteNonQuery(cmd, txn);
3406
                            }
3407

    
3408
                            // PSN
3409
                            query = $"DELETE FROM {PSN_PIPESYSTEMNETWORK} WHERE PSNRevisionNumber = '{string.Format("V{0:D4}", item.Revision)}'";
3410
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3411
                            foreach (DataRow row in item.PipeSystemNetwork.Rows)
3412
                            {
3413
                                query = $"INSERT INTO {PSN_PIPESYSTEMNETWORK} " +
3414
                                    $"(OID, Type, OrderNumber, Pipeline_OID, FROM_DATA, TO_DATA, TopologySet_OID_Key, PSNRevisionNumber, PBS, Drawings, IsValid, Status, IncludingVirtualData, PSNAccuracy, Pocket) VALUES " +
3415
                                    $"(@OID, @Type, @OrderNumber, @Pipeline_OID, @FROM_DATA, @TO_DATA, @TopologySet_OID_Key, @PSNRevisionNumber,  @PBS, @Drawings, @IsValid, @Status, @IncludingVirtualData, @PSNAccuracy, @Pocket)";
3416
                                var cmd = connection.GetSqlStringCommand(query);
3417
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
3418
                                AddWithValue(cmd, "@Type", string.IsNullOrEmpty(row["Type"].ToString()) ? "" : row["Type"].ToString());
3419
                                AddWithValue(cmd, "@OrderNumber", string.IsNullOrEmpty(row["OrderNumber"].ToString()) ? "" : row["OrderNumber"].ToString());
3420
                                AddWithValue(cmd, "@Pipeline_OID", string.IsNullOrEmpty(row["Pipeline_OID"].ToString()) ? "" : row["Pipeline_OID"].ToString());
3421
                                AddWithValue(cmd, "@FROM_DATA", string.IsNullOrEmpty(row["FROM_DATA"].ToString()) ? "" : row["FROM_DATA"].ToString());
3422
                                AddWithValue(cmd, "@TO_DATA", string.IsNullOrEmpty(row["TO_DATA"].ToString()) ? "" : row["TO_DATA"].ToString());
3423
                                AddWithValue(cmd, "@TopologySet_OID_Key", string.IsNullOrEmpty(row["TopologySet_OID_Key"].ToString()) ? "" : row["TopologySet_OID_Key"].ToString());
3424
                                AddWithValue(cmd, "@PSNRevisionNumber", string.IsNullOrEmpty(row["PSNRevisionNumber"].ToString()) ? "" : row["PSNRevisionNumber"].ToString());
3425

    
3426
                                int IsValid = 0;
3427
                                if (row["IsValid"].ToString() == string.Empty || row["IsValid"].ToString() == "OK")
3428
                                    IsValid = 0;
3429
                                else if (row["IsValid"].ToString() == "InValid")
3430
                                    IsValid = 1;
3431
                                else if (row["IsValid"].ToString() == "Error")
3432
                                    IsValid = -1;
3433

    
3434
                                AddWithValue(cmd, "@IsValid", IsValid);
3435
                                AddWithValue(cmd, "@Status", string.IsNullOrEmpty(row["Status"].ToString()) ? "" : row["Status"].ToString());
3436

    
3437
                                AddWithValue(cmd, "@PBS", string.IsNullOrEmpty(row["PBS"].ToString()) ? "" : row["PBS"].ToString());
3438
                                AddWithValue(cmd, "@Drawings", string.IsNullOrEmpty(row["Drawings"].ToString()) ? "" : row["Drawings"].ToString());
3439

    
3440
                                AddWithValue(cmd, "@IncludingVirtualData", string.IsNullOrEmpty(row["IncludingVirtualData"].ToString()) ? "" : row["IncludingVirtualData"].ToString());
3441
                                if (string.IsNullOrEmpty(row["PSNAccuracy"].ToString()))
3442
                                    AddWithValue(cmd, "@PSNAccuracy", DBNull.Value);
3443
                                else
3444
                                    AddWithValue(cmd, "@PSNAccuracy", row["PSNAccuracy"].ToString().Replace("%", ""));
3445

    
3446
                                AddWithValue(cmd, "@Pocket", string.IsNullOrEmpty(row["Pocket"].ToString()) ? "Yes" : row["Pocket"].ToString());
3447
                                connection.ExecuteNonQuery(cmd, txn);
3448
                            }
3449

    
3450
                            //Pipeline
3451
                            query = $"DELETE FROM {PSN_PIPELINE}";
3452
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3453
                            foreach (DataRow row in item.PipeLine.Rows)
3454
                            {
3455
                                query = $"INSERT INTO {PSN_PIPELINE} (OID, PipeSystem_OID, FLUID, PMC, SEQNUMBER, INSULATION, FROM_DATA, TO_DATA, Unit) VALUES (@OID, @PipeSystem_OID, @FLUID, @PMC, @SEQNUMBER, @INSULATION, @FROM_DATA, @TO_DATA, @Unit)";
3456
                                var cmd = connection.GetSqlStringCommand(query);
3457
                                AddWithValue(cmd, "@OID", row["OID"].ToString());
3458
                                AddWithValue(cmd, "@PipeSystem_OID", row["PipeSystem_OID"].ToString());
3459
                                AddWithValue(cmd, "@FLUID", row["FLUID"].ToString());
3460
                                AddWithValue(cmd, "@PMC", row["PMC"].ToString());
3461
                                AddWithValue(cmd, "@SEQNUMBER", row["SEQNUMBER"].ToString());
3462
                                AddWithValue(cmd, "@INSULATION", row["INSULATION"].ToString());
3463
                                AddWithValue(cmd, "@FROM_DATA", row["FROM_DATA"].ToString());
3464
                                AddWithValue(cmd, "@TO_DATA", row["TO_DATA"].ToString());
3465
                                AddWithValue(cmd, "@Unit", row["Unit"].ToString());
3466
                                connection.ExecuteNonQuery(cmd, txn);
3467
                            }
3468

    
3469
                            //PipeSystem
3470
                            query = $"DELETE FROM {PSN_PIPESYSTEM}";
3471
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3472
                            foreach (DataRow row in item.PipeSystem.Rows)
3473
                            {
3474
                                query = $"INSERT INTO {PSN_PIPESYSTEM} (OID, DESCRIPTION, FLUID, PMC, PipeLineQty, GroundLevel) VALUES (@OID, @DESCRIPTION, @FLUID, @PMC, @PipeLineQty, @GroundLevel)";
3475
                                var cmd = connection.GetSqlStringCommand(query);
3476
                                AddWithValue(cmd, "@OID", row["OID"].ToString());
3477
                                AddWithValue(cmd, "@DESCRIPTION", row["DESCRIPTION"].ToString());
3478
                                AddWithValue(cmd, "@FLUID", row["FLUID"].ToString());
3479
                                AddWithValue(cmd, "@PMC", row["PMC"].ToString());
3480
                                AddWithValue(cmd, "@PipeLineQty", row["PipeLineQty"].ToString());
3481
                                AddWithValue(cmd, "@GroundLevel", row["GroundLevel"].ToString());
3482
                                connection.ExecuteNonQuery(cmd, txn);
3483
                            }
3484

    
3485
                            //Header Setting
3486
                            query = $"DELETE FROM {PSN_HEADER_SETTING}";
3487
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3488

    
3489
                            foreach (HeaderInfo headerInfo in headerInfos)
3490
                            {
3491
                                foreach (HeaderItem itemheader in headerInfo.HeaderItems)
3492
                                {
3493
                                    query = $"INSERT INTO {PSN_HEADER_SETTING} (GROUP_ID, DESCRIPTION, [INDEX], NAME) VALUES (@GROUP_ID, @DESCRIPTION, @INDEX, @NAME)";
3494
                                    var cmd = connection.GetSqlStringCommand(query);
3495
                                    AddWithValue(cmd, "@GROUP_ID", headerInfo.UID);
3496
                                    AddWithValue(cmd, "@DESCRIPTION", headerInfo.Description);
3497
                                    AddWithValue(cmd, "@INDEX", itemheader.Index);
3498
                                    AddWithValue(cmd, "@NAME", itemheader.Name);
3499
                                    connection.ExecuteNonQuery(cmd, txn);
3500
                                }
3501
                            }
3502

    
3503
                            //Vent/Drain Setting
3504
                            query = $"DELETE FROM {PSN_VENTDRAIN_SETTING}";
3505
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3506

    
3507
                            foreach (VentDrainInfo ventDrainInfo in ventDrainInfos)
3508
                            {
3509
                                foreach (VentDrainItem itemventdrain in ventDrainInfo.VentDrainItems)
3510
                                {
3511
                                    query = $"INSERT INTO {PSN_VENTDRAIN_SETTING} (GROUP_ID, DESCRIPTION, [INDEX], NAME) VALUES (@GROUP_ID, @DESCRIPTION, @INDEX, @NAME)";
3512
                                    var cmd = connection.GetSqlStringCommand(query);
3513
                                    AddWithValue(cmd, "@GROUP_ID", ventDrainInfo.UID);
3514
                                    AddWithValue(cmd, "@DESCRIPTION", ventDrainInfo.Description);
3515
                                    AddWithValue(cmd, "@INDEX", itemventdrain.Index);
3516
                                    AddWithValue(cmd, "@NAME", itemventdrain.Name);
3517
                                    connection.ExecuteNonQuery(cmd, txn);
3518
                                }
3519
                            }
3520

    
3521
                            //Keyword Setting
3522
                            query = $"DELETE FROM {PSN_TRANSFORMKEYWORD_SETTING}";
3523
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3524

    
3525
                            foreach (KeywordItem itemKeyword in keywordItems)
3526
                            {
3527
                                query = $"INSERT INTO {PSN_TRANSFORMKEYWORD_SETTING} ([INDEX], NAME, KEYWORD) VALUES (@INDEX, @NAME, @KEYWORD)";
3528
                                var cmd = connection.GetSqlStringCommand(query);
3529
                                AddWithValue(cmd, "@INDEX", itemKeyword.Index);
3530
                                AddWithValue(cmd, "@NAME", itemKeyword.Name);
3531
                                AddWithValue(cmd, "@KEYWORD", itemKeyword.Keyword);
3532
                                connection.ExecuteNonQuery(cmd, txn);
3533
                            }
3534

    
3535
                            //FulidCode
3536
                            query = $"DELETE FROM {PSN_FLUIDCODE}";
3537
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3538

    
3539
                            foreach (DataRow row in dtFluidCode.Rows)
3540
                            {
3541
                                query = $"INSERT INTO {PSN_FLUIDCODE} (UID, Code, Description, Condition, Remarks, GroundLevel) VALUES (@UID, @Code, @Description, @Condition, @Remarks, @GroundLevel)";
3542
                                var cmd = connection.GetSqlStringCommand(query);
3543
                                cmd.Parameters.Clear();
3544

    
3545
                                {
3546
                                    var param = cmd.CreateParameter();
3547
                                    param.ParameterName = "@UID";
3548
                                    param.Value = row["UID"].ToString();
3549
                                    cmd.Parameters.Add(param);
3550
                                }
3551

    
3552
                                {
3553
                                    var param = cmd.CreateParameter();
3554
                                    param.ParameterName = "@Code";
3555
                                    param.Value = row["Code"].ToString();
3556
                                    cmd.Parameters.Add(param);
3557
                                }
3558

    
3559
                                {
3560
                                    var param = cmd.CreateParameter();
3561
                                    param.ParameterName = "@Description";
3562
                                    param.Value = row["Description"].ToString();
3563
                                    cmd.Parameters.Add(param);
3564
                                }
3565

    
3566
                                {
3567
                                    var param = cmd.CreateParameter();
3568
                                    param.ParameterName = "@Condition";
3569
                                    param.Value = row["Condition"].ToString();
3570
                                    cmd.Parameters.Add(param);
3571
                                }
3572

    
3573
                                {
3574
                                    var param = cmd.CreateParameter();
3575
                                    param.ParameterName = "@Remarks";
3576
                                    param.Value = row["Remarks"].ToString();
3577
                                    cmd.Parameters.Add(param);
3578
                                }
3579

    
3580
                                {
3581
                                    var param = cmd.CreateParameter();
3582
                                    param.ParameterName = "@GroundLevel";
3583
                                    param.Value = row["GroundLevel"].ToString();
3584
                                    cmd.Parameters.Add(param);
3585
                                }
3586

    
3587
                                connection.ExecuteNonQuery(cmd, txn);
3588
                            }
3589

    
3590
                            //PMC
3591
                            query = $"DELETE FROM {PSN_PIPINGMATLCLASS}";
3592
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3593

    
3594
                            foreach (DataRow row in dtPMC.Rows)
3595
                            {
3596
                                query = $"INSERT INTO {PSN_PIPINGMATLCLASS} ( UID, Priority, Code, Description, Condition, Remarks, GroundLevel) VALUES (@UID, @Priority, @Code, @Description, @Condition, @Remarks, @GroundLevel)";
3597
                                var cmd = connection.GetSqlStringCommand(query);
3598
                                cmd.Parameters.Clear();
3599

    
3600
                                {
3601
                                    var param = cmd.CreateParameter();
3602
                                    param.ParameterName = "@UID";
3603
                                    param.Value = row["UID"].ToString();
3604
                                    cmd.Parameters.Add(param);
3605
                                }
3606

    
3607
                                {
3608
                                    var param = cmd.CreateParameter();
3609
                                    param.ParameterName = "@Priority";
3610
                                    param.Value = row["Priority"].ToString();
3611
                                    cmd.Parameters.Add(param);
3612
                                }
3613

    
3614
                                {
3615
                                    var param = cmd.CreateParameter();
3616
                                    param.ParameterName = "@Code";
3617
                                    param.Value = row["Code"].ToString();
3618
                                    cmd.Parameters.Add(param);
3619
                                }
3620

    
3621
                                {
3622
                                    var param = cmd.CreateParameter();
3623
                                    param.ParameterName = "@Description";
3624
                                    param.Value = row["Description"].ToString();
3625
                                    cmd.Parameters.Add(param);
3626
                                }
3627

    
3628
                                {
3629
                                    var param = cmd.CreateParameter();
3630
                                    param.ParameterName = "@Condition";
3631
                                    param.Value = row["Condition"].ToString();
3632
                                    cmd.Parameters.Add(param);
3633
                                }
3634

    
3635
                                {
3636
                                    var param = cmd.CreateParameter();
3637
                                    param.ParameterName = "@Remarks";
3638
                                    param.Value = row["Remarks"].ToString();
3639
                                    cmd.Parameters.Add(param);
3640
                                }
3641

    
3642
                                {
3643
                                    var param = cmd.CreateParameter();
3644
                                    param.ParameterName = "@GroundLevel";
3645
                                    param.Value = row["GroundLevel"].ToString();
3646
                                    cmd.Parameters.Add(param);
3647
                                }
3648

    
3649
                                connection.ExecuteNonQuery(cmd, txn);
3650
                            }
3651

    
3652
                            //Insulation
3653
                            query = $"DELETE FROM {PSN_INSULATIONPURPOSE}";
3654
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3655

    
3656
                            foreach (DataRow row in dtInsulation.Rows)
3657
                            {
3658
                                query = $"INSERT INTO {PSN_INSULATIONPURPOSE} (UID, Code, Description, Remarks) VALUES (@UID, @Code, @Description, @Remarks)";
3659
                                var cmd = connection.GetSqlStringCommand(query);
3660
                                cmd.Parameters.Clear();
3661

    
3662
                                {
3663
                                    var param = cmd.CreateParameter();
3664
                                    param.ParameterName = "@UID";
3665
                                    param.Value = row["UID"].ToString();
3666
                                    cmd.Parameters.Add(param);
3667
                                }
3668

    
3669
                                {
3670
                                    var param = cmd.CreateParameter();
3671
                                    param.ParameterName = "@Code";
3672
                                    param.Value = row["Code"].ToString();
3673
                                    cmd.Parameters.Add(param);
3674
                                }
3675

    
3676
                                {
3677
                                    var param = cmd.CreateParameter();
3678
                                    param.ParameterName = "@Description";
3679
                                    param.Value = row["Description"].ToString();
3680
                                    cmd.Parameters.Add(param);
3681
                                }
3682

    
3683
                                {
3684
                                    var param = cmd.CreateParameter();
3685
                                    param.ParameterName = "@Remarks";
3686
                                    param.Value = row["Remarks"].ToString();
3687
                                    cmd.Parameters.Add(param);
3688
                                }
3689

    
3690
                                connection.ExecuteNonQuery(cmd, txn);
3691
                            }
3692

    
3693
                            //Topology Rule
3694
                            query = $"DELETE FROM {PSN_TOPOLOGY_RULE}";
3695
                            var cmdtopology = connection.GetSqlStringCommand(query);
3696
                            //connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3697
                            connection.ExecuteNonQuery(cmdtopology, txn);
3698

    
3699
                            foreach (DataRow row in dtTopologyRule.Rows)
3700
                            {
3701
                                query = $"INSERT INTO {PSN_TOPOLOGY_RULE} (UID) VALUES (@UID)";
3702
                                cmdtopology = connection.GetSqlStringCommand(query);
3703
                                AddWithValue(cmdtopology, "@UID", row["UID"].ToString());
3704
                                connection.ExecuteNonQuery(cmdtopology, txn);
3705
                            }
3706

    
3707
                            //valve grouping
3708
                            query = $"DELETE FROM {PSN_VALVEGROUP_SETTING}";
3709
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3710

    
3711
                            foreach (DataRow row in dtvalvegrouping.Rows)
3712
                            {
3713
                                query = $"INSERT INTO {PSN_VALVEGROUP_SETTING} (OID, GroupType, TagIdentifier, AttributeName, SppidSymbolName) " +
3714
                                    $"VALUES (@OID, @GroupType, @TagIdentifier, @AttributeName, @SppidSymbolName)";
3715
                                var cmd = connection.GetSqlStringCommand(query);
3716
                                AddWithValue(cmd, "@OID", row["OID"].ToString());
3717
                                AddWithValue(cmd, "@GroupType", row["GroupType"].ToString());
3718
                                AddWithValue(cmd, "@TagIdentifier", row["TagIdentifier"].ToString());
3719
                                AddWithValue(cmd, "@AttributeName", row["AttributeName"].ToString());
3720
                                AddWithValue(cmd, "@SppidSymbolName", row["SppidSymbolName"].ToString());
3721
                                connection.ExecuteNonQuery(cmd, txn);
3722
                            }
3723

    
3724
                            //no pocket Setting
3725
                            query = $"DELETE FROM {PSN_NOPOCKETSETTING}";
3726
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3727

    
3728
                            foreach (DataRow row in dtnopocket.Rows)
3729
                            {
3730
                                query = $"INSERT INTO {PSN_NOPOCKETSETTING} ([INDEX], [TYPE], [NAME]) VALUES (@INDEX, @TYPE, @NAME)";
3731
                                var cmd = connection.GetSqlStringCommand(query);
3732
                                AddWithValue(cmd, "@INDEX", row["INDEX"].ToString());
3733
                                AddWithValue(cmd, "@TYPE", row["TYPE"].ToString());
3734
                                AddWithValue(cmd, "@NAME", row["NAME"].ToString());
3735
                                connection.ExecuteNonQuery(cmd, txn);
3736
                            }
3737

    
3738
                            //air fin cooler Setting
3739
                            query = $"DELETE FROM {PSN_AIRFINCOOLERSETTING}";
3740
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3741

    
3742
                            foreach (DataRow row in dtnopocket.Rows)
3743
                            {
3744
                                query = $"INSERT INTO {PSN_AIRFINCOOLERSETTING} ([INDEX], [TYPE], [NAME]) VALUES (@INDEX, @TYPE, @NAME)";
3745
                                var cmd = connection.GetSqlStringCommand(query);
3746
                                AddWithValue(cmd, "@INDEX", row["INDEX"].ToString());
3747
                                AddWithValue(cmd, "@TYPE", row["TYPE"].ToString());
3748
                                AddWithValue(cmd, "@NAME", row["NAME"].ToString());
3749
                                connection.ExecuteNonQuery(cmd, txn);
3750
                            }
3751
                            
3752

    
3753
                            txn.Commit();
3754
                        }
3755
                        catch (Exception ex)
3756
                        {
3757
                            txn.Rollback();
3758
                            result = false;
3759
                        }
3760
                    }
3761
                }
3762
                catch (Exception ex)
3763
                {
3764
                    System.Windows.Forms.MessageBox.Show(ex.Message);
3765
                    result = false;
3766
                }
3767
            }
3768

    
3769
            return result;
3770
        }
3771

    
3772
        public static bool CreatePSN_COMMON()
3773
        {
3774
            AnotherID2Info id2Info = AnotherID2Info.GetInstance();
3775

    
3776
            bool result = true;
3777
            using (IAbstractDatabase connection = id2Info.CreateConnection())
3778
            {
3779
                try
3780
                {
3781
                    using (var txn = connection.BeginTransaction())
3782
                    {
3783
                        try
3784
                        {
3785
                            
3786
                            var query = $"If(db_id(N'" + PSN_COMMON + "') IS NULL) CREATE DATABASE [" + PSN_COMMON + "]";
3787
                            if (id2Info.ID2DBType == AnotherID2DB_Type.MSSQL)
3788
                            {                                
3789
                                connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3790
                            }
3791

    
3792
                            txn.Commit();
3793
                        }
3794
                        catch (Exception ex)
3795
                        {
3796
                            txn.Rollback();
3797
                            result = false;
3798
                        }
3799
                    }
3800
                }
3801
                catch (Exception ex)
3802
                {
3803
                    System.Windows.Forms.MessageBox.Show(ex.Message);
3804
                    result = false;
3805
                }
3806
            }
3807

    
3808
            return result;
3809
        }
3810
    }
3811
}
3812

    
3813

    
클립보드 이미지 추가 (최대 크기: 500 MB)