프로젝트

일반

사용자정보

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

hytos / DTI_PID / ID2PSN / DB.cs @ 4842b66a

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

1 0dae5645 gaqhf
using System;
2
using System.Collections.Generic;
3 6b9e7a56 gaqhf
using System.Data;
4 757ab2f2 LJIYEON
using System.Data.Common;
5 1d46fca7 LJIYEON
using System.Data.SqlClient;
6 45529c16 LJIYEON
using System.Data.SQLite;
7
using System.Linq;
8
using System.Text.RegularExpressions;
9 0dae5645 gaqhf
10
namespace ID2PSN
11
{
12 45529c16 LJIYEON
    public class DB
13 0dae5645 gaqhf
    {
14 6b9e7a56 gaqhf
        const string PSN_TOPOLOGY_RULE = "T_PSN_TOPOLOGY_RULE";
15
        const string PSN_HEADER_SETTING = "T_PSN_HEADER_SETTING";
16 36a45f13 gaqhf
        const string PSN_VENTDRAIN_SETTING = "T_PSN_VENTDRAIN_SETTING";
17 5dfc785c LJIYEON
        const string PSN_VIEW = "T_PSN_VIEW";
18 3610fd3f LJIYEON
        const string PSN_TRANSFORMKEYWORD_SETTING = "T_PSN_TRANSFORMKEYWORD_SETTING";
19
        const string PSN_VALVEGROUP_SETTING = "SPPIDValveGroup";
20 5dfc785c LJIYEON
21 8f24b438 gaqhf
        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 67638be0 LJIYEON
        const string PSN_PIPINGMATLCLASS = "SPPIDPipingMatlClass";
28 36a45f13 gaqhf
        const string PSN_TOPOLOGYSET = "SPPIDTopologySet";
29 a36541fb LJIYEON
        //2021.11.17 추가 
30
        const string PSN_PIPELINE = "SPPIDPipeLine";
31 839708c6 LJIYEON
        //2021.11.26 추가
32
        const string PSN_INSULATIONPURPOSE = "SPPIDInsulationPurpose";
33 3610fd3f LJIYEON
        //2022.01.12 추가 //ARS_COMMON DB
34
        const string PSN_REVISION = "PSNRevision";
35
        const string PSN_COMMON = "ARS_COMMON";
36 531fb158 LJIYEON
        //2022.01.19 추가
37
        const string PSN_PIPESYSTEM = "SPPIDPipeSystem";
38 88c1965b gaqhf
39
        //2022.02.03 추가
40
        const string PSN_NOPOCKETSETTING = "T_PSN_NOPOCKET_SETTING";
41 f2a63376 이지연
        const string PSN_AIRFINCOOLERSETTING = "T_PSN_AIRFINCOOLER_SETTING";
42 1ae1a1c6 LJIYEON
        /// <summary>
43
        ///  ID2 Project.db 데이터를 가져온다. 
44
        ///  DB 접속 정보 및 DBType (Sqlite, Mssql) 정보를 가져옴
45
        ///  - JY
46
        /// </summary>
47
        /// <returns></returns>
48
        public static DataTable GetProject()
49 757ab2f2 LJIYEON
        {
50 1ae1a1c6 LJIYEON
            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 757ab2f2 LJIYEON
79 1ae1a1c6 LJIYEON
            return dt;
80
        }
81 757ab2f2 LJIYEON
82 1ae1a1c6 LJIYEON
        /// <summary>
83 c4a35107 humkyung
        ///  SQLite에 초기 DB 생성
84 1ae1a1c6 LJIYEON
        ///  - JY
85
        /// </summary>
86
        /// <returns></returns>
87 6b9e7a56 gaqhf
        public static bool ConnTestAndCreateTable()
88
        {
89
            bool result = false;
90
            ID2Info id2Info = ID2Info.GetInstance();
91 1ae1a1c6 LJIYEON
92 0ff2a9f1 LJIYEON
            using (IAbstractDatabase connection = id2Info.CreateConnection())
93 6b9e7a56 gaqhf
            {
94 0fe04b33 LJIYEON
                try
95 6b9e7a56 gaqhf
                {
96 23a96301 humkyung
                    var names = connection.GetTableNames();
97
                    var matched = names.FirstOrDefault(param => param == PSN_HEADER_SETTING);
98 0ff2a9f1 LJIYEON
                    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 23a96301 humkyung
                    if (matched == null)
105 6b9e7a56 gaqhf
                    {
106 23a96301 humkyung
                        var query = $"CREATE TABLE {PSN_HEADER_SETTING} (GROUP_ID TEXT, DESCRIPTION TEXT, [INDEX] INTEGER, NAME TEXT)";
107
                        using (var cmd = connection.GetSqlStringCommand(query))
108 6b9e7a56 gaqhf
                        {
109 23a96301 humkyung
                            cmd.ExecuteNonQuery();
110
                        }
111
                    }
112 0ff2a9f1 LJIYEON
                    else
113
                    {
114
                        AddColumn(PSN_HEADER_SETTING, dicColCheck);
115
                    }
116 757ab2f2 LJIYEON
117 23a96301 humkyung
                    matched = names.FirstOrDefault(param => param == PSN_VENTDRAIN_SETTING);
118 0ff2a9f1 LJIYEON
                    dicColCheck.Clear();
119
                    dicColCheck.Add("GROUP_ID", "TEXT");
120
                    dicColCheck.Add("DESCRIPTION", "TEXT");
121
                    dicColCheck.Add("INDEX", "INTEGER");
122
                    dicColCheck.Add("NAME", "TEXT");
123 23a96301 humkyung
                    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 0ff2a9f1 LJIYEON
                    else
132
                    {
133
                        AddColumn(PSN_VENTDRAIN_SETTING, dicColCheck);
134
                    }
135 757ab2f2 LJIYEON
136 23a96301 humkyung
                    matched = names.FirstOrDefault(param => param == PSN_TOPOLOGY_RULE);
137 0ff2a9f1 LJIYEON
                    dicColCheck.Clear();
138
                    dicColCheck.Add("UID", "TEXT");
139 23a96301 humkyung
                    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 757ab2f2 LJIYEON
147 23a96301 humkyung
                        DataTable topologyRule = new DataTable();
148
                        topologyRule.Columns.Add("NAME", typeof(string));
149 757ab2f2 LJIYEON
150 23a96301 humkyung
                        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 0ff2a9f1 LJIYEON
                    //else
159
                    //{
160
                    //    AddColumn(PSN_TOPOLOGY_RULE, dicColCheck);
161
                    //}
162 72775f2e LJIYEON
163
                    matched = names.FirstOrDefault(param => param == PSN_PIPESYSTEMNETWORK);
164 0ff2a9f1 LJIYEON
                    dicColCheck.Clear();
165 d1afd412 이지연
                    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 0ff2a9f1 LJIYEON
                    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 08b33e44 gaqhf
                    dicColCheck.Add("PSNAccuracy", "REAL");
179
                    dicColCheck.Add("Pocket", "NVARCHAR(10)");
180 d1afd412 이지연
                    dicColCheck.Add("EGTag", "NVARCHAR(255)");
181
                    dicColCheck.Add("HasMLTags", "NVARCHAR(50)");
182 4842b66a 이지연
                    dicColCheck.Add("GroundLevel", "NVARCHAR(20)");
183 d1afd412 이지연
184 23a96301 humkyung
                    if (matched == null)
185
                    {
186 f9f2787b LJIYEON
                        var query = $"CREATE TABLE {PSN_PIPESYSTEMNETWORK} (OID NVARCHAR(255), Type NVARCHAR(255), OrderNumber NVARCHAR(255), Pipeline_OID NVARCHAR(255), From_Data NVARCHAR(255), " +
187
                            "To_Data NVARCHAR(255), TopologySet_OID_Key NVARCHAR(125), PSNRevisionNumber NVARCHAR(255), IsValid INTEGER, Status NVARCHAR(255), PBS NVARCHAR(255), Drawings NVARCHAR(255), " +
188 4842b66a 이지연
                            "IncludingVirtualData NVARCHAR(10), PSNAccuracy REAL, Pocket NVARCHAR(10), EGTag NVARCHAR(255), HasMLTags NVARCHAR(50), GroundLevel NVARCHAR(50))";
189 23a96301 humkyung
                        using (var cmd = connection.GetSqlStringCommand(query))
190
                        {
191
                            cmd.ExecuteNonQuery();
192 757ab2f2 LJIYEON
                        }
193
                    }
194 0ff2a9f1 LJIYEON
                    else
195
                    {
196
                        AddColumn(PSN_PIPESYSTEMNETWORK, dicColCheck);
197
                    }
198 23a96301 humkyung
199 72775f2e LJIYEON
                    matched = names.FirstOrDefault(param => param == PSN_EQUIPMENT);
200 0ff2a9f1 LJIYEON
                    dicColCheck.Clear();
201
                    dicColCheck.Add("OID", "NVARCHAR(255)");
202
                    dicColCheck.Add("ItemTag", "NVARCHAR(255)");
203
                    dicColCheck.Add("Xcoords", "REAL");
204
                    dicColCheck.Add("Ycoords", "REAL");
205 23a96301 humkyung
                    if (matched == null)
206
                    {
207 f9f2787b LJIYEON
                        var query = $"CREATE TABLE {PSN_EQUIPMENT} (OID NVARCHAR(255), ItemTag NVARCHAR(255), Xcoords REAL, Ycoords REAL)";
208 23a96301 humkyung
                        using (var cmd = connection.GetSqlStringCommand(query))
209
                        {
210
                            cmd.ExecuteNonQuery();
211
                        }
212
                    }
213 0ff2a9f1 LJIYEON
                    else
214
                    {
215
                        AddColumn(PSN_EQUIPMENT, dicColCheck);
216
                    }
217
218
                    dicColCheck.Clear();
219
                    dicColCheck.Add("OID", "NVARCHAR(255)");
220
                    dicColCheck.Add("ItemTag", "NVARCHAR(255)");
221
                    dicColCheck.Add("Xcoords", "REAL");
222
                    dicColCheck.Add("Ycoords", "REAL");
223
                    dicColCheck.Add("Equipment_OID", "NVARCHAR(255)");
224
                    dicColCheck.Add("Fluid", "NVARCHAR(255)");
225
                    dicColCheck.Add("NPD", "NVARCHAR(255)");
226
                    dicColCheck.Add("PMC", "NVARCHAR(255)");
227
                    dicColCheck.Add("Rotation", "REAL");
228
                    dicColCheck.Add("FlowDirection", "NVARCHAR(255)");
229 23a96301 humkyung
230 72775f2e LJIYEON
                    matched = names.FirstOrDefault(param => param == PSN_NOZZLE);
231 23a96301 humkyung
                    if (matched == null)
232
                    {
233 f9f2787b LJIYEON
                        var query = $"CREATE TABLE {PSN_NOZZLE} (OID NVARCHAR(255), ItemTag NVARCHAR(255), Xcoords REAL, Ycoords REAL, Equipment_OID NVARCHAR(255), " +
234 33cee849 LJIYEON
                            "Fluid NVARCHAR(255), NPD NVARCHAR(255), PMC NVARCHAR(255), Rotation REAL, FlowDirection NVARCHAR(255))";
235 23a96301 humkyung
                        using (var cmd = connection.GetSqlStringCommand(query))
236
                        {
237
                            cmd.ExecuteNonQuery();
238
                        }
239
                    }
240 0ff2a9f1 LJIYEON
                    else
241
                    {
242
                        AddColumn(PSN_NOZZLE, dicColCheck);
243
                    }
244 23a96301 humkyung
245 72775f2e LJIYEON
                    matched = names.FirstOrDefault(param => param == PSN_FLUIDCODE);
246 0ff2a9f1 LJIYEON
                    dicColCheck.Clear();
247
                    dicColCheck.Add("UID", "NVARCHAR(50)");
248
                    dicColCheck.Add("Code", "NVARCHAR(255)");
249
                    dicColCheck.Add("Description", "NVARCHAR(255)");
250
                    dicColCheck.Add("Condition", "NVARCHAR(255)");
251
                    dicColCheck.Add("Remarks", "NVARCHAR(255)");
252
                    dicColCheck.Add("GroundLevel", "NVARCHAR(20)");
253 23a96301 humkyung
                    if (matched == null)
254
                    {
255 72775f2e LJIYEON
                        var query = $"CREATE TABLE {PSN_FLUIDCODE} (UID NVARCHAR(50), Code NVARCHAR(255), Description NVARCHAR(255), Condition NVARCHAR(255), Remarks NVARCHAR(255), GroundLevel NVARCHAR(20))";
256 23a96301 humkyung
                        using (var cmd = connection.GetSqlStringCommand(query))
257
                        {
258
                            cmd.ExecuteNonQuery();
259
                        }
260
                    }
261 0ff2a9f1 LJIYEON
                    else
262
                    {
263
                        AddColumn(PSN_FLUIDCODE, dicColCheck);
264
                    }
265 72775f2e LJIYEON
266
                    matched = names.FirstOrDefault(param => param == PSN_PIPINGMATLCLASS);
267 0ff2a9f1 LJIYEON
                    dicColCheck.Clear();
268
                    dicColCheck.Add("UID", "NVARCHAR(50)");
269
                    dicColCheck.Add("Priority", "INTEGER");
270
                    dicColCheck.Add("Code", "NVARCHAR(255)");
271
                    dicColCheck.Add("Description", "NVARCHAR(255)");
272
                    dicColCheck.Add("Condition", "NVARCHAR(255)");
273
                    dicColCheck.Add("Remarks", "NVARCHAR(255)");
274
                    dicColCheck.Add("GroundLevel", "NVARCHAR(20)");
275 23a96301 humkyung
                    if (matched == null)
276
                    {
277 72775f2e LJIYEON
                        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))";
278 23a96301 humkyung
                        using (var cmd = connection.GetSqlStringCommand(query))
279
                        {
280
                            cmd.ExecuteNonQuery();
281
                        }
282
                    }
283 0ff2a9f1 LJIYEON
                    else
284
                    {
285
                        AddColumn(PSN_PIPINGMATLCLASS, dicColCheck);
286
                    }
287 23a96301 humkyung
288 72775f2e LJIYEON
                    matched = names.FirstOrDefault(param => param == PSN_SEQUENCEDATA);
289 0ff2a9f1 LJIYEON
                    dicColCheck.Clear();
290
                    dicColCheck.Add("OID", "NVARCHAR(255)");
291
                    dicColCheck.Add("SERIALNUMBER", "NVARCHAR(255)");
292
                    dicColCheck.Add("PathItem_OID", "NVARCHAR(255)");
293
                    dicColCheck.Add("TopologySet_OID_Key", "NVARCHAR(255)");
294 23a96301 humkyung
                    if (matched == null)
295
                    {
296 f9f2787b LJIYEON
                        var query = $"CREATE TABLE {PSN_SEQUENCEDATA} (OID NVARCHAR(255), SERIALNUMBER NVARCHAR(255), PathItem_OID NVARCHAR(255), TopologySet_OID_Key NVARCHAR(255))";
297 23a96301 humkyung
                        using (var cmd = connection.GetSqlStringCommand(query))
298
                        {
299
                            cmd.ExecuteNonQuery();
300
                        }
301
                    }
302 0ff2a9f1 LJIYEON
                    else
303
                    {
304
                        AddColumn(PSN_SEQUENCEDATA, dicColCheck);
305
                    }
306 23a96301 humkyung
307 72775f2e LJIYEON
                    matched = names.FirstOrDefault(param => param == PSN_PATHITEMS);
308 0ff2a9f1 LJIYEON
                    dicColCheck.Clear();
309
                    dicColCheck.Add("OID", "NVARCHAR(255)");
310
                    dicColCheck.Add("SequenceData_OID", "NVARCHAR(255)");
311
                    dicColCheck.Add("TopologySet_OID", "NVARCHAR(255)");
312
                    dicColCheck.Add("BranchTopologySet_OID", "NVARCHAR(255)");
313
                    dicColCheck.Add("PipeLine_OID", "NVARCHAR(255)");
314
                    dicColCheck.Add("ItemName", "NVARCHAR(255)");
315
                    dicColCheck.Add("ItemTag", "NVARCHAR(255)");
316
                    dicColCheck.Add("DESCRIPTION", "NVARCHAR(255)");
317
                    dicColCheck.Add("CLASS", "NVARCHAR(255)");
318
                    dicColCheck.Add("SUBCLASS", "NVARCHAR(255)");
319
                    dicColCheck.Add("TYPE", "NVARCHAR(255)");
320
                    dicColCheck.Add("PIDNAME", "NVARCHAR(255)");
321
                    dicColCheck.Add("Equipment_OID", "NVARCHAR(255)");
322
                    dicColCheck.Add("NPD", "NVARCHAR(255)");
323 811d7949 LJIYEON
                    dicColCheck.Add("GROUPTAG", "NVARCHAR(255)");
324 0ff2a9f1 LJIYEON
                    dicColCheck.Add("PipeSystemNetwork_OID", "NVARCHAR(255)");
325
                    dicColCheck.Add("PipeRun_OID", "NVARCHAR(255)");
326
                    dicColCheck.Add("ViewPipeSystemNetwork_OID", "NVARCHAR(255)");
327 7106e181 LJIYEON
328 bf9e8432 이지연
                    dicColCheck.Add("EqpGroupTag", "NVARCHAR(255)");
329
                    dicColCheck.Add("MainLineTag", "NVARCHAR(255)");
330
331
                    dicColCheck.Add("EGTConnectedPoint", "INT");
332
                    dicColCheck.Add("EGFlowDirection", "NVARCHAR(10)");
333
334 23a96301 humkyung
                    if (matched == null)
335
                    {
336 f9f2787b LJIYEON
                        var query = $"CREATE TABLE {PSN_PATHITEMS} (OID NVARCHAR(255), SequenceData_OID NVARCHAR(255), " +
337
                            "TopologySet_OID NVARCHAR(255), BranchTopologySet_OID NVARCHAR(255), PipeLine_OID NVARCHAR(255), ItemName NVARCHAR(255), ItemTag NVARCHAR(255), DESCRIPTION NVARCHAR(255), " +
338 811d7949 LJIYEON
                            "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), " +
339 bf9e8432 이지연
                            "ViewPipeSystemNetwork_OID NVARCHAR(255), EqpGroupTag NVARCHAR(255), MainLineTag NVARCHAR(255), EGTConnectedPoint INT, EGFlowDirection NVARCHAR(10))";
340 23a96301 humkyung
                        using (var cmd = connection.GetSqlStringCommand(query))
341
                        {
342
                            cmd.ExecuteNonQuery();
343
                        }
344
                    }
345 0ff2a9f1 LJIYEON
                    else
346
                    {
347
                        AddColumn(PSN_PATHITEMS, dicColCheck);
348
                    }
349
350 23a96301 humkyung
                    matched = names.FirstOrDefault(param => param == PSN_VIEW);
351 0ff2a9f1 LJIYEON
                    dicColCheck.Clear();
352
                    dicColCheck.Add("OID", "TEXT");
353 23a96301 humkyung
                    if (matched == null)
354
                    {
355
                        var query = $"CREATE TABLE {PSN_VIEW} (OID TEXT)";
356
                        using (var cmd = connection.GetSqlStringCommand(query))
357
                        {
358
                            cmd.ExecuteNonQuery();
359
                        }
360
                    }
361
362
                    matched = names.FirstOrDefault(param => param == PSN_TOPOLOGYSET);
363 0ff2a9f1 LJIYEON
                    dicColCheck.Clear();
364
                    dicColCheck.Add("OID", "NVARCHAR(255)");
365
                    dicColCheck.Add("Type", "NVARCHAR(255)");
366
                    dicColCheck.Add("SubType", "NVARCHAR(255)");
367
                    dicColCheck.Add("HeadItemTag", "NVARCHAR(255)");
368
                    dicColCheck.Add("TailItemTag", "NVARCHAR(255)");
369
                    dicColCheck.Add("HeadItemSPID", "NVARCHAR(255)");
370
                    dicColCheck.Add("TailItemSPID", "NVARCHAR(255)");
371
372 23a96301 humkyung
                    if (matched == null)
373
                    {
374 88c1965b gaqhf
                        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))";
375 23a96301 humkyung
                        using (var cmd = connection.GetSqlStringCommand(query))
376
                        {
377
                            cmd.ExecuteNonQuery();
378
                        }
379
                    }
380 0ff2a9f1 LJIYEON
                    else
381
                    {
382
                        AddColumn(PSN_TOPOLOGYSET, dicColCheck);
383
                    }
384
385 ddc1c369 LJIYEON
                    matched = names.FirstOrDefault(param => param == PSN_TRANSFORMKEYWORD_SETTING);
386 0ff2a9f1 LJIYEON
                    dicColCheck.Clear();
387 284fa2c9 이지연
                    dicColCheck.Add("INDEX", "INTEGER");
388
                    dicColCheck.Add("NAME", "TEXT");
389
                    dicColCheck.Add("KEYWORD", "TEXT");
390 ddc1c369 LJIYEON
                    if (matched == null)
391
                    {
392 d4b1ab29 LJIYEON
                        var query = $"CREATE TABLE {PSN_TRANSFORMKEYWORD_SETTING} ([INDEX] INTEGER, [NAME] TEXT, [KEYWORD] TEXT)";
393 ddc1c369 LJIYEON
                        using (var cmd = connection.GetSqlStringCommand(query))
394
                        {
395
                            cmd.ExecuteNonQuery();
396
                        }
397
                    }
398 0ff2a9f1 LJIYEON
                    else
399
                    {
400
                        AddColumn(PSN_TRANSFORMKEYWORD_SETTING, dicColCheck);
401
                    }
402 ddc1c369 LJIYEON
403 a36541fb LJIYEON
                    matched = names.FirstOrDefault(param => param == PSN_PIPELINE);
404 0ff2a9f1 LJIYEON
                    dicColCheck.Clear();
405
                    dicColCheck.Add("OID", "NVARCHAR(255)");
406
                    dicColCheck.Add("PipeSystem_OID", "NVARCHAR(255)");
407
                    dicColCheck.Add("FLUID", "NVARCHAR(255)");
408
                    dicColCheck.Add("PMC", "NVARCHAR(255)");
409
                    dicColCheck.Add("SEQNUMBER", "NVARCHAR(255)");
410
                    dicColCheck.Add("INSULATION", "NVARCHAR(255)");
411
                    dicColCheck.Add("FROM_DATA", "NVARCHAR(255)");
412
                    dicColCheck.Add("TO_DATA", "NVARCHAR(255)");
413
                    dicColCheck.Add("Unit", "NVARCHAR(100)");
414 a36541fb LJIYEON
                    if (matched == null)
415
                    {
416
                        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), " +
417
                            $"FROM_DATA NVARCHAR(255), TO_DATA NVARCHAR(255), Unit NVARCHAR(100))";
418
                        using (var cmd = connection.GetSqlStringCommand(query))
419
                        {
420
                            cmd.ExecuteNonQuery();
421
                        }
422
                    }
423 0ff2a9f1 LJIYEON
                    else
424
                    {
425
                        AddColumn(PSN_PIPELINE, dicColCheck);
426
                    }
427 a36541fb LJIYEON
428 839708c6 LJIYEON
                    matched = names.FirstOrDefault(param => param == PSN_INSULATIONPURPOSE);
429 0ff2a9f1 LJIYEON
                    dicColCheck.Clear();
430
                    dicColCheck.Add("UID", "NVARCHAR(50)");
431
                    dicColCheck.Add("Code", "NVARCHAR(255)");
432
                    dicColCheck.Add("Description", "NVARCHAR(255)");
433
                    dicColCheck.Add("Remarks", "NVARCHAR(255)");
434 839708c6 LJIYEON
                    if (matched == null)
435
                    {
436
                        var query = $"CREATE TABLE {PSN_INSULATIONPURPOSE} (UID NVARCHAR(50), Code NVARCHAR(255), Description NVARCHAR(255), Remarks NVARCHAR(255))";
437
                        using (var cmd = connection.GetSqlStringCommand(query))
438
                        {
439
                            cmd.ExecuteNonQuery();
440
                        }
441
                    }
442 0ff2a9f1 LJIYEON
                    else
443
                    {
444
                        AddColumn(PSN_INSULATIONPURPOSE, dicColCheck);
445
                    }
446
447 3610fd3f LJIYEON
                    matched = names.FirstOrDefault(param => param == PSN_VALVEGROUP_SETTING);
448
                    dicColCheck.Clear();
449
                    dicColCheck.Add("OID", "NVARCHAR(255)");
450
                    dicColCheck.Add("GroupType", "NVARCHAR(255)");
451
                    dicColCheck.Add("TagIdentifier", "NVARCHAR(50)");
452
                    dicColCheck.Add("AttributeName", "NVARCHAR(255)");
453
                    dicColCheck.Add("SppidSymbolName", "NVARCHAR(255)");
454
                    if (matched == null)
455
                    {
456 531fb158 LJIYEON
                        var query = $"CREATE TABLE {PSN_VALVEGROUP_SETTING} (OID NVARCHAR(255), GroupType NVARCHAR(255), TagIdentifier NVARCHAR(50), AttributeName NVARCHAR(255), SppidSymbolName NVARCHAR(255))";
457 3610fd3f LJIYEON
                        using (var cmd = connection.GetSqlStringCommand(query))
458
                        {
459
                            cmd.ExecuteNonQuery();
460
                        }
461
                    }
462
                    else
463
                    {
464
                        AddColumn(PSN_VALVEGROUP_SETTING, dicColCheck);
465
                    }
466
467 531fb158 LJIYEON
                    matched = names.FirstOrDefault(param => param == PSN_PIPESYSTEM);
468
                    dicColCheck.Clear();
469
                    dicColCheck.Add("OID", "NVARCHAR(255)");
470
                    dicColCheck.Add("DESCRIPTION", "NVARCHAR(255)");
471
                    dicColCheck.Add("FLUID", "NVARCHAR(255)");
472
                    dicColCheck.Add("PMC", "NVARCHAR(255)");
473
                    dicColCheck.Add("PipeLineQty", "NVARCHAR(255)");
474
                    dicColCheck.Add("GroundLevel", "NVARCHAR(20)");
475
                    if (matched == null)
476
                    {
477
                        var query = $"CREATE TABLE {PSN_PIPESYSTEM} (OID NVARCHAR(255), DESCRIPTION NVARCHAR(255), FLUID NVARCHAR(255), PMC NVARCHAR(255), PipeLineQty NVARCHAR(255), GroundLevel NVARCHAR(20))";
478
                        using (var cmd = connection.GetSqlStringCommand(query))
479
                        {
480
                            cmd.ExecuteNonQuery();
481
                        }
482
                    }
483
                    else
484
                    {
485
                        AddColumn(PSN_PIPESYSTEM, dicColCheck);
486
                    }
487 88c1965b gaqhf
488
                    matched = names.FirstOrDefault(param => param == PSN_NOPOCKETSETTING);
489
                    dicColCheck.Clear();
490 284fa2c9 이지연
                    dicColCheck.Add("INDEX", "INTEGER");
491
                    dicColCheck.Add("TYPE", "TEXT");
492
                    dicColCheck.Add("NAME", "TEXT");
493 88c1965b gaqhf
                    if (matched == null)
494
                    {
495
                        var query = $"CREATE TABLE {PSN_NOPOCKETSETTING} ([INDEX] INTEGER, [TYPE] TEXT, [NAME] TEXT)";
496
                        using (var cmd = connection.GetSqlStringCommand(query))
497
                        {
498
                            cmd.ExecuteNonQuery();
499
                        }
500
                    }
501
                    else
502
                    {
503
                        AddColumn(PSN_NOPOCKETSETTING, dicColCheck);
504
                    }
505
506 f2a63376 이지연
                    matched = names.FirstOrDefault(param => param == PSN_AIRFINCOOLERSETTING);
507 284fa2c9 이지연
508 f2a63376 이지연
                    dicColCheck.Clear();
509 284fa2c9 이지연
                    dicColCheck.Add("INDEX", "INTEGER");
510
                    dicColCheck.Add("TYPE", "TEXT");
511
                    dicColCheck.Add("TagIdentifier", "TEXT");
512
                    dicColCheck.Add("AttributeName", "TEXT");
513
                    dicColCheck.Add("NAME", "TEXT");
514
515 f2a63376 이지연
                    if (matched == null)
516
                    {
517 284fa2c9 이지연
                        var query = $"CREATE TABLE {PSN_AIRFINCOOLERSETTING} ([INDEX] INTEGER, [TYPE] TEXT, [TagIdentifier] TEXT, [AttributeName] TEXT, [NAME] TEXT)";
518 f2a63376 이지연
                        using (var cmd = connection.GetSqlStringCommand(query))
519
                        {
520
                            cmd.ExecuteNonQuery();
521
                        }
522
                    }
523
                    else
524
                    {
525
                        AddColumn(PSN_AIRFINCOOLERSETTING, dicColCheck);
526
                    }
527
528 3610fd3f LJIYEON
529 0ff2a9f1 LJIYEON
                    void AddColumn(string TableName, Dictionary<string, string> dicCol)
530
                    {
531
                        var colnames = connection.GetColumnNames(TableName);
532
                        bool check = false;
533
                        if (colnames != null)
534
                        {
535
                            foreach (KeyValuePair<string, string> col in dicCol)
536
                            {
537
                                check = false;
538
                                foreach (string c in colnames)
539
                                {
540
                                    if (col.Key.Contains(c))
541
                                    {
542
                                        check = true;
543
                                        break;
544
                                    }
545
                                }
546
547
                                if (!check) //없으면 추가
548
                                {
549
                                    string i = string.Empty;
550
                                    if (col.Value.ToString().ToUpper().Contains("INT") || col.Value.ToString().ToUpper().Contains("REAL"))
551
                                        i = "DEFAULT 0";
552
553
                                    var query = $"ALTER TABLE " + TableName + " ADD [" + col.Key + "] " + col.Value + " " + i + ";";
554
                                    using (var cmd = connection.GetSqlStringCommand(query))
555
                                    {
556
                                        cmd.ExecuteNonQuery();
557
                                    }
558
                                }
559
                            }
560
                        }
561
                    }
562 839708c6 LJIYEON
563 23a96301 humkyung
                    result = true;
564 0fe04b33 LJIYEON
                }
565
                catch (Exception ex)
566
                {
567
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
568
                }
569 6b9e7a56 gaqhf
            }
570 45529c16 LJIYEON
571 6b9e7a56 gaqhf
            return result;
572
        }
573
574 1ae1a1c6 LJIYEON
        // ID2 DB 데이터
575 c4a35107 humkyung
        /// <summary>
576
        /// ID2 데이타베이스에서 OPC 데이터를 조회
577
        /// </summary>
578
        /// <returns></returns>
579 1ae1a1c6 LJIYEON
        public static DataTable SelectOPCRelations()
580 6b9e7a56 gaqhf
        {
581 23a96301 humkyung
            DataTable dt = null;
582 6b9e7a56 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
583 0fe04b33 LJIYEON
584 23a96301 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection())
585 6b9e7a56 gaqhf
            {
586 0fe04b33 LJIYEON
                try
587 6b9e7a56 gaqhf
                {
588 23a96301 humkyung
                    var query = "SELECT * FROM OPCRelations;";
589
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
590 757ab2f2 LJIYEON
                    {
591 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
592 6b9e7a56 gaqhf
                    }
593
                }
594 0fe04b33 LJIYEON
                catch (Exception ex)
595 36a45f13 gaqhf
                {
596 0fe04b33 LJIYEON
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
597
                }
598 36a45f13 gaqhf
            }
599 1ae1a1c6 LJIYEON
600 36a45f13 gaqhf
            return dt;
601
        }
602 6b9e7a56 gaqhf
603 c4a35107 humkyung
        /// <summary>
604
        /// ID2 데이타베이스에서 도면 데이터를 조회
605
        /// </summary>
606
        /// <returns></returns>
607 1ae1a1c6 LJIYEON
        public static DataTable SelectDrawings()
608 6b9e7a56 gaqhf
        {
609 23a96301 humkyung
            DataTable dt = null;
610 6b9e7a56 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
611 0fe04b33 LJIYEON
612 23a96301 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection())
613 6b9e7a56 gaqhf
            {
614 0fe04b33 LJIYEON
                try
615 6b9e7a56 gaqhf
                {
616 c3b48db0 esham21
                    var query = "SELECT DISTINCT NAME FROM [Drawings] order by Name";
617 23a96301 humkyung
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
618 1ae1a1c6 LJIYEON
                    {
619 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
620 6b9e7a56 gaqhf
                    }
621
                }
622 0fe04b33 LJIYEON
                catch (Exception ex)
623 36a45f13 gaqhf
                {
624 0fe04b33 LJIYEON
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
625
                }
626 36a45f13 gaqhf
            }
627 1ae1a1c6 LJIYEON
628
            return dt;
629 36a45f13 gaqhf
        }
630 abee404a LJIYEON
631 ec1cc293 LJIYEON
        public static DataTable AllDrawings()
632
        {
633
            DataTable dt = null;
634
            ID2Info id2Info = ID2Info.GetInstance();
635
636
            using (IAbstractDatabase connection = id2Info.CreateConnection())
637
            {
638
                try
639
                {
640
                    var query = "SELECT * FROM [Drawings]";
641
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
642
                    {
643
                        dt = ds.Tables[0].Copy();
644
                    }
645
                }
646
                catch (Exception ex)
647
                {
648
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
649
                }
650
            }
651
652
            return dt;
653
        }
654
655 1ae1a1c6 LJIYEON
        public static DataTable SelectLineProperties()
656 6b9e7a56 gaqhf
        {
657 23a96301 humkyung
            DataTable dt = null;
658 6b9e7a56 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
659 23a96301 humkyung
660
            using (IAbstractDatabase connection = id2Info.CreateConnection())
661 6b9e7a56 gaqhf
            {
662 0fe04b33 LJIYEON
                try
663 6b9e7a56 gaqhf
                {
664 23a96301 humkyung
                    var query = "SELECT * FROM LineProperties";
665
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
666 1ae1a1c6 LJIYEON
                    {
667 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
668 6b9e7a56 gaqhf
                    }
669
                }
670 0fe04b33 LJIYEON
                catch (Exception ex)
671 6b9e7a56 gaqhf
                {
672 0fe04b33 LJIYEON
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
673
                }
674 6b9e7a56 gaqhf
            }
675 0fe04b33 LJIYEON
676 6b9e7a56 gaqhf
            return dt;
677
        }
678 45529c16 LJIYEON
679 1ae1a1c6 LJIYEON
        public static DataTable SelectFluidCode()
680 6b9e7a56 gaqhf
        {
681 23a96301 humkyung
            DataTable dt = null;
682 6b9e7a56 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
683 0fe04b33 LJIYEON
684 23a96301 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection())
685 6b9e7a56 gaqhf
            {
686 0fe04b33 LJIYEON
                try
687 6b9e7a56 gaqhf
                {
688 23a96301 humkyung
                    var query = "SELECT * FROM FluidCode";
689 45529c16 LJIYEON
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
690 1ae1a1c6 LJIYEON
                    {
691 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
692 6b9e7a56 gaqhf
                    }
693
                }
694 0fe04b33 LJIYEON
                catch (Exception ex)
695 6b9e7a56 gaqhf
                {
696 0fe04b33 LJIYEON
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
697
                }
698 1ae1a1c6 LJIYEON
            }
699
700
            return dt;
701
        }
702
703
        public static DataTable SelectPipingMaterialsClass()
704
        {
705 23a96301 humkyung
            DataTable dt = null;
706 1ae1a1c6 LJIYEON
            ID2Info id2Info = ID2Info.GetInstance();
707 0fe04b33 LJIYEON
708 23a96301 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection())
709 1ae1a1c6 LJIYEON
            {
710 0fe04b33 LJIYEON
                try
711 6b9e7a56 gaqhf
                {
712 23a96301 humkyung
                    var query = "SELECT * FROM PipingMaterialsClass";
713
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
714 1ae1a1c6 LJIYEON
                    {
715 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
716 1ae1a1c6 LJIYEON
                    }
717
                }
718 0fe04b33 LJIYEON
                catch (Exception ex)
719 1ae1a1c6 LJIYEON
                {
720 0fe04b33 LJIYEON
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
721
                }
722 6b9e7a56 gaqhf
            }
723 1ae1a1c6 LJIYEON
724 6b9e7a56 gaqhf
            return dt;
725
        }
726
727 1ae1a1c6 LJIYEON
        public static DataTable SelectPSNPIPINGMATLCLASS()
728 6b9e7a56 gaqhf
        {
729 23a96301 humkyung
            DataTable dt = null;
730 6b9e7a56 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
731 0fe04b33 LJIYEON
732 0ff2a9f1 LJIYEON
            using (IAbstractDatabase connection = id2Info.CreateConnection())
733 1ae1a1c6 LJIYEON
            {
734 0fe04b33 LJIYEON
                try
735
                {
736 23a96301 humkyung
                    var query = $"SELECT * FROM {PSN_PIPINGMATLCLASS}";
737
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
738 1ae1a1c6 LJIYEON
                    {
739 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
740 1ae1a1c6 LJIYEON
                    }
741 0fe04b33 LJIYEON
                }
742
                catch (Exception ex)
743
                {
744
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
745
                }
746 1ae1a1c6 LJIYEON
            }
747
748
            return dt;
749
        }
750 d1afd412 이지연
751 839708c6 LJIYEON
        public static DataTable SelectInsulationPurpose()
752
        {
753
            DataTable dt = null;
754
            ID2Info id2Info = ID2Info.GetInstance();
755
756
            using (IAbstractDatabase connection = id2Info.CreateConnection())
757
            {
758
                try
759
                {
760
                    var query = "SELECT * FROM InsulationPurpose";
761
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
762
                    {
763
                        dt = ds.Tables[0].Copy();
764
                    }
765
                }
766
                catch (Exception ex)
767
                {
768
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
769
                }
770
            }
771
772
            return dt;
773
        }
774
775
        public static DataTable SelectPSNINSULATIONPURPOSE()
776
        {
777
            DataTable dt = null;
778
            ID2Info id2Info = ID2Info.GetInstance();
779
780 0ff2a9f1 LJIYEON
            using (IAbstractDatabase connection = id2Info.CreateConnection())
781 839708c6 LJIYEON
            {
782
                try
783
                {
784
                    var query = $"SELECT * FROM {PSN_INSULATIONPURPOSE}";
785
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
786
                    {
787
                        dt = ds.Tables[0].Copy();
788
                    }
789
                }
790
                catch (Exception ex)
791
                {
792
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
793
                }
794
            }
795
796
            return dt;
797
        }
798
799 1ae1a1c6 LJIYEON
        public static DataTable SelectNominalDiameter()
800
        {
801 23a96301 humkyung
            DataTable dt = null;
802 1ae1a1c6 LJIYEON
            ID2Info id2Info = ID2Info.GetInstance();
803 0fe04b33 LJIYEON
804 23a96301 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection())
805 1ae1a1c6 LJIYEON
            {
806 0fe04b33 LJIYEON
                try
807 6b9e7a56 gaqhf
                {
808 23a96301 humkyung
                    var query = "SELECT * FROM NominalDiameter ORDER BY Metric DESC";
809
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
810 1ae1a1c6 LJIYEON
                    {
811 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
812 1ae1a1c6 LJIYEON
                    }
813 6b9e7a56 gaqhf
                }
814 0fe04b33 LJIYEON
                catch (Exception ex)
815 1ae1a1c6 LJIYEON
                {
816 0fe04b33 LJIYEON
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
817
                }
818 1ae1a1c6 LJIYEON
            }
819
820 c4a35107 humkyung
            ///TODO: need to check below code
821 1ae1a1c6 LJIYEON
            dt.Rows.RemoveAt(0);
822
            dt.Rows.RemoveAt(0);
823
            dt.Rows.RemoveAt(0);
824
            dt.Rows.RemoveAt(0);
825
826 6b9e7a56 gaqhf
            return dt;
827
        }
828 abee404a LJIYEON
829 b267209c LJIYEON
        public static DataTable SelectAllSymbolAttribute()
830
        {
831
            DataTable dt = null;
832
            ID2Info id2Info = ID2Info.GetInstance();
833
834
            using (IAbstractDatabase connection = id2Info.CreateConnection())
835
            {
836
                try
837
                {
838 353c2919 LJIYEON
                    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; ";
839 b267209c LJIYEON
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
840
                    {
841
                        dt = ds.Tables[0].Copy();
842
                    }
843
                }
844
                catch (Exception ex)
845
                {
846
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
847
                }
848
            }
849
850
            return dt;
851
        }
852
853 1ae1a1c6 LJIYEON
        public static DataTable SelectSymbolAttribute()
854 6b9e7a56 gaqhf
        {
855 23b86f8b LJIYEON
            DataTable dt = null;
856 6b9e7a56 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
857 0fe04b33 LJIYEON
858 23a96301 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection())
859 6b9e7a56 gaqhf
            {
860 0fe04b33 LJIYEON
                try
861 6b9e7a56 gaqhf
                {
862 d1afd412 이지연
                    // var query = "SELECT DISTINCT Attribute, DisplayAttribute FROM SymbolAttribute;";
863 502d1d50 LJIYEON
                    var query = "SELECT DISTINCT Attribute FROM SymbolAttribute;";
864 23a96301 humkyung
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
865 1ae1a1c6 LJIYEON
                    {
866 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
867 1ae1a1c6 LJIYEON
                    }
868
                }
869 0fe04b33 LJIYEON
                catch (Exception ex)
870 1ae1a1c6 LJIYEON
                {
871 0fe04b33 LJIYEON
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
872
                }
873 1ae1a1c6 LJIYEON
            }
874 0fe04b33 LJIYEON
875 1ae1a1c6 LJIYEON
            return dt;
876
        }
877
878
        public static DataTable SelectSymbolName()
879
        {
880 23a96301 humkyung
            DataTable dt = null;
881 1ae1a1c6 LJIYEON
            ID2Info id2Info = ID2Info.GetInstance();
882 0fe04b33 LJIYEON
883 23a96301 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection())
884 1ae1a1c6 LJIYEON
            {
885 0fe04b33 LJIYEON
                try
886 1ae1a1c6 LJIYEON
                {
887 23a96301 humkyung
                    var query = "SELECT * FROM SymbolName;";
888
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
889 1ae1a1c6 LJIYEON
                    {
890 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
891 1ae1a1c6 LJIYEON
                    }
892
                }
893 0fe04b33 LJIYEON
                catch (Exception ex)
894 1ae1a1c6 LJIYEON
                {
895 0fe04b33 LJIYEON
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
896
                }
897 1ae1a1c6 LJIYEON
            }
898 0fe04b33 LJIYEON
899 1ae1a1c6 LJIYEON
            return dt;
900 45529c16 LJIYEON
        }
901 1ae1a1c6 LJIYEON
902
        public static double[] GetDrawingSize()
903
        {
904
            double[] result = null;
905
906
            ID2Info id2Info = ID2Info.GetInstance();
907 23a96301 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection())
908 1ae1a1c6 LJIYEON
            {
909 0fe04b33 LJIYEON
                try
910 1ae1a1c6 LJIYEON
                {
911 d36e2fe0 esham21
                    var query = "SELECT value FROM Configuration WHERE Section = 'Area' AND [Key] = 'Drawing';";
912 23a96301 humkyung
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
913 1ae1a1c6 LJIYEON
                    {
914 23a96301 humkyung
                        if (ds.Tables[0].Rows.Count == 1)
915 0fe04b33 LJIYEON
                        {
916 23a96301 humkyung
                            string value = ds.Tables[0].Rows[0][0].ToString();
917 0fe04b33 LJIYEON
                            string[] split = value.Split(new char[] { ',' });
918
                            result = new double[] {
919 45529c16 LJIYEON
                                Convert.ToDouble(Regex.Replace(split[0], @"[^0-9]", string.Empty)),
920
                                Convert.ToDouble(Regex.Replace(split[1], @"[^0-9]", string.Empty)),
921
                                Convert.ToDouble(Regex.Replace(split[2], @"[^0-9]", string.Empty)),
922
                                Convert.ToDouble(Regex.Replace(split[3], @"[^0-9]", string.Empty))
923 1ae1a1c6 LJIYEON
                                };
924 0fe04b33 LJIYEON
                            result = new double[] {
925 1ae1a1c6 LJIYEON
                                Math.Min(result[0], result[2]),
926
                                Math.Min(result[1], result[3]),
927
                                Math.Max(result[0], result[2]),
928
                                Math.Max(result[1], result[3])
929
                                };
930
                        }
931
                    }
932
                }
933 0fe04b33 LJIYEON
                catch (Exception ex)
934 1ae1a1c6 LJIYEON
                {
935 0fe04b33 LJIYEON
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
936
                }
937 1ae1a1c6 LJIYEON
            }
938
939
            return result;
940
        }
941
942
        public static DataTable GetEquipmentType()
943
        {
944 23a96301 humkyung
            DataTable dt = null;
945 1ae1a1c6 LJIYEON
            ID2Info id2Info = ID2Info.GetInstance();
946 0fe04b33 LJIYEON
947 23a96301 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection())
948 1ae1a1c6 LJIYEON
            {
949 0fe04b33 LJIYEON
                try
950 1ae1a1c6 LJIYEON
                {
951 23a96301 humkyung
                    var query = "SELECT Type FROM SymbolType WHERE Category = 'Equipment';";
952
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
953 1ae1a1c6 LJIYEON
                    {
954 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
955 1ae1a1c6 LJIYEON
                    }
956
                }
957 0fe04b33 LJIYEON
                catch (Exception ex)
958 1ae1a1c6 LJIYEON
                {
959 0fe04b33 LJIYEON
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
960
                }
961 6b9e7a56 gaqhf
            }
962 0fe04b33 LJIYEON
963 6b9e7a56 gaqhf
            return dt;
964
        }
965 abee404a LJIYEON
966 1ae1a1c6 LJIYEON
        /// <summary>
967
        ///  Zoom 을 위하여 저장 T_PSN_VIEW 데이터로 PSN 데이터지만 Msqql 과 Sqlite 둘다 저장되어 있음
968
        ///  => ID2 가 DB 타입에 따라서 바라보는 DB가 mssql이냐 sqlite냐로 지정되기 때문에 zoom 기능을 그대로 사용하려면 해당 데이터는 psn도 id2 dbtype에 맞춰서 저장 및 로드해야함
969 c4a35107 humkyung
        ///  => 더 이상 사용하지 않음
970 1ae1a1c6 LJIYEON
        /// </summary>
971
        /// <param name="values"></param>
972
        /// <returns></returns>
973
        public static bool SaveView(List<string> values)
974 6b9e7a56 gaqhf
        {
975
            ID2Info id2Info = ID2Info.GetInstance();
976 1ae1a1c6 LJIYEON
977
            bool result = true;
978
979 23a96301 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection())
980
            {
981
                try
982 6b9e7a56 gaqhf
                {
983 23a96301 humkyung
                    using (var txn = connection.BeginTransaction())
984 6b9e7a56 gaqhf
                    {
985 23a96301 humkyung
                        try
986 6b9e7a56 gaqhf
                        {
987 23a96301 humkyung
                            var query = $"DELETE FROM {PSN_VIEW}";
988
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
989
990
                            foreach (string value in values)
991 1ae1a1c6 LJIYEON
                            {
992 0ff2a9f1 LJIYEON
                                query = $"INSERT INTO {PSN_VIEW} (OID) VALUES (@OID)";
993 23a96301 humkyung
                                var cmd = connection.GetSqlStringCommand(query);
994
                                AddWithValue(cmd, "@OID", value);
995
                                connection.ExecuteNonQuery(cmd, txn);
996 1ae1a1c6 LJIYEON
                            }
997 23a96301 humkyung
                            txn.Commit();
998
                        }
999
                        catch (Exception ex)
1000
                        {
1001
                            txn.Rollback();
1002
                            result = false;
1003 6b9e7a56 gaqhf
                        }
1004 1ae1a1c6 LJIYEON
                    }
1005 6b9e7a56 gaqhf
                }
1006 23a96301 humkyung
                catch (Exception ex)
1007
                {
1008
                    System.Windows.Forms.MessageBox.Show(ex.Message);
1009
                    result = false;
1010
                }
1011
            }
1012
1013 1ae1a1c6 LJIYEON
            return result;
1014 6b9e7a56 gaqhf
        }
1015
1016 1ae1a1c6 LJIYEON
        public static bool DeleteView()
1017 6b9e7a56 gaqhf
        {
1018
            ID2Info id2Info = ID2Info.GetInstance();
1019 1ae1a1c6 LJIYEON
1020
            bool result = true;
1021 23a96301 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1022
            {
1023
                try
1024 6b9e7a56 gaqhf
                {
1025 23a96301 humkyung
                    using (var txn = connection.BeginTransaction())
1026 6b9e7a56 gaqhf
                    {
1027 23a96301 humkyung
                        try
1028 1ae1a1c6 LJIYEON
                        {
1029 23a96301 humkyung
                            var query = $"DELETE FROM {PSN_VIEW}";
1030
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1031
                            txn.Commit();
1032
                        }
1033
                        catch (Exception ex)
1034
                        {
1035
                            txn.Rollback();
1036
                            result = false;
1037 1ae1a1c6 LJIYEON
                        }
1038 6b9e7a56 gaqhf
                    }
1039
                }
1040 23a96301 humkyung
                catch (Exception ex)
1041
                {
1042
                    System.Windows.Forms.MessageBox.Show(ex.Message);
1043
                    result = false;
1044
                }
1045
            }
1046 1ae1a1c6 LJIYEON
1047
            return result;
1048 6b9e7a56 gaqhf
        }
1049 abee404a LJIYEON
1050 1ae1a1c6 LJIYEON
        //PSN Sqlite 
1051
        public static DataTable SelectHeaderSetting()
1052 6b9e7a56 gaqhf
        {
1053 23a96301 humkyung
            DataTable dt = null;
1054 6b9e7a56 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
1055 1ae1a1c6 LJIYEON
1056 0ff2a9f1 LJIYEON
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1057 6b9e7a56 gaqhf
            {
1058
                try
1059
                {
1060 23a96301 humkyung
                    var query = $@"SELECT GROUP_ID, DESCRIPTION, [INDEX], NAME FROM {PSN_HEADER_SETTING};";
1061
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1062 6b9e7a56 gaqhf
                    {
1063 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
1064 6b9e7a56 gaqhf
                    }
1065
                }
1066
                catch (Exception ex)
1067
                {
1068
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1069
                }
1070
            }
1071 1ae1a1c6 LJIYEON
1072 6b9e7a56 gaqhf
            return dt;
1073
        }
1074
1075 1ae1a1c6 LJIYEON
        public static DataTable SelectVentDrainSetting()
1076 6b9e7a56 gaqhf
        {
1077 23a96301 humkyung
            DataTable dt = null;
1078 6b9e7a56 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
1079 23a96301 humkyung
1080 0ff2a9f1 LJIYEON
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1081 6b9e7a56 gaqhf
            {
1082
                try
1083
                {
1084 23a96301 humkyung
                    var query = $@"SELECT GROUP_ID, DESCRIPTION, [INDEX], NAME FROM {PSN_VENTDRAIN_SETTING};";
1085
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1086 6b9e7a56 gaqhf
                    {
1087 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
1088 6b9e7a56 gaqhf
                    }
1089
                }
1090
                catch (Exception ex)
1091
                {
1092
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1093
                }
1094
            }
1095 23a96301 humkyung
1096 6b9e7a56 gaqhf
            return dt;
1097
        }
1098 abee404a LJIYEON
1099 ddc1c369 LJIYEON
        public static DataTable SelectKeywordsSetting()
1100
        {
1101
            DataTable dt = null;
1102
            ID2Info id2Info = ID2Info.GetInstance();
1103
1104 0ff2a9f1 LJIYEON
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1105 ddc1c369 LJIYEON
            {
1106
                try
1107
                {
1108 d4b1ab29 LJIYEON
                    var query = $@"SELECT [KEYWORD], [INDEX], [NAME] FROM {PSN_TRANSFORMKEYWORD_SETTING};";
1109 ddc1c369 LJIYEON
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1110
                    {
1111
                        dt = ds.Tables[0].Copy();
1112
                    }
1113
                }
1114
                catch (Exception ex)
1115
                {
1116
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1117
                }
1118
            }
1119
1120
            return dt;
1121
        }
1122
1123 3610fd3f LJIYEON
        public static DataTable SelectValveGroupItemsSetting()
1124
        {
1125
            DataTable dt = null;
1126
            ID2Info id2Info = ID2Info.GetInstance();
1127
1128
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1129
            {
1130
                try
1131
                {
1132
                    var query = $@"SELECT OID, GroupType, TagIdentifier, AttributeName, SppidSymbolName FROM {PSN_VALVEGROUP_SETTING};";
1133
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1134
                    {
1135
                        dt = ds.Tables[0].Copy();
1136
                    }
1137
                }
1138
                catch (Exception ex)
1139
                {
1140
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1141
                }
1142
            }
1143
1144
            return dt;
1145
        }
1146
1147 d1afd412 이지연
1148 88c1965b gaqhf
        public static DataTable SelectEquipmentNoPocketSetting()
1149
        {
1150
            DataTable dt = null;
1151
            ID2Info id2Info = ID2Info.GetInstance();
1152
1153
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1154
            {
1155
                try
1156
                {
1157
                    var query = $@"SELECT [INDEX], [TYPE], [NAME] FROM {PSN_NOPOCKETSETTING};";
1158
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1159
                    {
1160
                        dt = ds.Tables[0].Copy();
1161
                    }
1162
                }
1163
                catch (Exception ex)
1164
                {
1165
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1166
                }
1167
            }
1168
1169
            return dt;
1170
        }
1171
1172 f2a63376 이지연
        public static DataTable SelectAirFinCoolerSetting()
1173
        {
1174
            DataTable dt = null;
1175
            ID2Info id2Info = ID2Info.GetInstance();
1176
1177
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1178
            {
1179
                try
1180
                {
1181 284fa2c9 이지연
                    var query = $@"SELECT [INDEX], [TYPE], [TagIdentifier], [AttributeName], [NAME] FROM {PSN_AIRFINCOOLERSETTING};";
1182 f2a63376 이지연
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1183
                    {
1184
                        dt = ds.Tables[0].Copy();
1185
                    }
1186
                }
1187
                catch (Exception ex)
1188
                {
1189
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1190
                }
1191
            }
1192
1193 d1afd412 이지연
            return dt;
1194 f2a63376 이지연
        }
1195
1196 1ae1a1c6 LJIYEON
        public static bool SaveHeaderSetting(List<HeaderInfo> headerInfos)
1197 6b9e7a56 gaqhf
        {
1198
            ID2Info id2Info = ID2Info.GetInstance();
1199 0ff2a9f1 LJIYEON
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1200 6b9e7a56 gaqhf
            {
1201
                try
1202
                {
1203 23a96301 humkyung
                    using (var txn = connection.BeginTransaction())
1204 6b9e7a56 gaqhf
                    {
1205 23a96301 humkyung
                        var query = $"DELETE FROM {PSN_HEADER_SETTING}";
1206
                        connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1207 1ae1a1c6 LJIYEON
1208
                        foreach (HeaderInfo headerInfo in headerInfos)
1209
                        {
1210
                            foreach (HeaderItem item in headerInfo.HeaderItems)
1211
                            {
1212 0ff2a9f1 LJIYEON
                                query = $"INSERT INTO {PSN_HEADER_SETTING} (GROUP_ID, DESCRIPTION, [INDEX], NAME) VALUES (@GROUP_ID, @DESCRIPTION, @INDEX, @NAME)";
1213 23a96301 humkyung
                                var cmd = connection.GetSqlStringCommand(query);
1214
                                AddWithValue(cmd, "@GROUP_ID", headerInfo.UID);
1215
                                AddWithValue(cmd, "@DESCRIPTION", headerInfo.Description);
1216
                                AddWithValue(cmd, "@INDEX", item.Index);
1217
                                AddWithValue(cmd, "@NAME", item.Name);
1218
                                connection.ExecuteNonQuery(cmd, txn);
1219 1ae1a1c6 LJIYEON
                            }
1220
                        }
1221 81bdaeed LJIYEON
                        txn.Commit();
1222 6b9e7a56 gaqhf
                    }
1223 d1afd412 이지연
1224 6b9e7a56 gaqhf
                }
1225
                catch (Exception ex)
1226
                {
1227
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1228 1ae1a1c6 LJIYEON
                    return false;
1229 6b9e7a56 gaqhf
                }
1230
            }
1231 1ae1a1c6 LJIYEON
            return true;
1232 6b9e7a56 gaqhf
        }
1233 abee404a LJIYEON
1234 1ae1a1c6 LJIYEON
        public static bool SaveVentDrainSetting(List<VentDrainInfo> ventDrainInfos)
1235 6b9e7a56 gaqhf
        {
1236
            ID2Info id2Info = ID2Info.GetInstance();
1237 0ff2a9f1 LJIYEON
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1238 6b9e7a56 gaqhf
            {
1239 23a96301 humkyung
                using (var txn = connection.BeginTransaction())
1240 6b9e7a56 gaqhf
                {
1241 23a96301 humkyung
                    try
1242 6b9e7a56 gaqhf
                    {
1243 23a96301 humkyung
                        var query = $"DELETE FROM {PSN_VENTDRAIN_SETTING}";
1244
                        connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1245 1ae1a1c6 LJIYEON
1246
                        foreach (VentDrainInfo ventDrainInfo in ventDrainInfos)
1247
                        {
1248
                            foreach (VentDrainItem item in ventDrainInfo.VentDrainItems)
1249
                            {
1250 0ff2a9f1 LJIYEON
                                query = $"INSERT INTO {PSN_VENTDRAIN_SETTING} (GROUP_ID, DESCRIPTION, [INDEX], NAME) VALUES (@GROUP_ID, @DESCRIPTION, @INDEX, @NAME)";
1251 23a96301 humkyung
                                var cmd = connection.GetSqlStringCommand(query);
1252
                                AddWithValue(cmd, "@GROUP_ID", ventDrainInfo.UID);
1253
                                AddWithValue(cmd, "@DESCRIPTION", ventDrainInfo.Description);
1254
                                AddWithValue(cmd, "@INDEX", item.Index);
1255
                                AddWithValue(cmd, "@NAME", item.Name);
1256
                                connection.ExecuteNonQuery(cmd, txn);
1257 1ae1a1c6 LJIYEON
                            }
1258
                        }
1259 81bdaeed LJIYEON
1260
                        txn.Commit();
1261 6b9e7a56 gaqhf
                    }
1262 23a96301 humkyung
                    catch (Exception ex)
1263
                    {
1264
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1265
                        return false;
1266
                    }
1267 6b9e7a56 gaqhf
                }
1268
            }
1269 23a96301 humkyung
1270 1ae1a1c6 LJIYEON
            return true;
1271 6b9e7a56 gaqhf
        }
1272 abee404a LJIYEON
1273 3610fd3f LJIYEON
        public static bool SaveValveGroupItemsSetting(List<ValveGroupItem> valveGroupItems)
1274
        {
1275
            ID2Info id2Info = ID2Info.GetInstance();
1276
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1277
            {
1278
                using (var txn = connection.BeginTransaction())
1279
                {
1280
                    try
1281
                    {
1282
                        var query = $"DELETE FROM {PSN_VALVEGROUP_SETTING}";
1283
                        connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1284
1285
                        foreach (ValveGroupItem item in valveGroupItems)
1286
                        {
1287
                            query = $"INSERT INTO {PSN_VALVEGROUP_SETTING} (OID, GroupType, TagIdentifier, AttributeName, SppidSymbolName) " +
1288
                                $"VALUES (@OID, @GroupType, @TagIdentifier, @AttributeName, @SppidSymbolName)";
1289
                            var cmd = connection.GetSqlStringCommand(query);
1290
                            AddWithValue(cmd, "@OID", item.OID);
1291
                            AddWithValue(cmd, "@GroupType", item.GroupType);
1292
                            AddWithValue(cmd, "@TagIdentifier", item.TagIdentifier);
1293
                            AddWithValue(cmd, "@AttributeName", item.AttributeName);
1294
                            AddWithValue(cmd, "@SppidSymbolName", item.SppidSymbolName);
1295
                            connection.ExecuteNonQuery(cmd, txn);
1296
                        }
1297
1298
                        txn.Commit();
1299
                    }
1300
                    catch (Exception ex)
1301
                    {
1302
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1303
                        return false;
1304
                    }
1305
                }
1306
            }
1307
1308
            return true;
1309
        }
1310
1311 8ab98ea3 LJIYEON
        public static bool SaveKeywordsSetting(List<KeywordItem> keywordItems)
1312 ddc1c369 LJIYEON
        {
1313
            ID2Info id2Info = ID2Info.GetInstance();
1314 0ff2a9f1 LJIYEON
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1315 ddc1c369 LJIYEON
            {
1316
                using (var txn = connection.BeginTransaction())
1317
                {
1318
                    try
1319
                    {
1320 81bdaeed LJIYEON
                        var query = $"DELETE FROM {PSN_TRANSFORMKEYWORD_SETTING}";
1321 ddc1c369 LJIYEON
                        connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1322 d1afd412 이지연
1323 8ab98ea3 LJIYEON
                        foreach (KeywordItem item in keywordItems)
1324 ddc1c369 LJIYEON
                        {
1325 0ff2a9f1 LJIYEON
                            query = $"INSERT INTO {PSN_TRANSFORMKEYWORD_SETTING} ([INDEX], NAME, KEYWORD) VALUES (@INDEX, @NAME, @KEYWORD)";
1326 8ab98ea3 LJIYEON
                            var cmd = connection.GetSqlStringCommand(query);
1327
                            AddWithValue(cmd, "@INDEX", item.Index);
1328
                            AddWithValue(cmd, "@NAME", item.Name);
1329 d1afd412 이지연
                            AddWithValue(cmd, "@KEYWORD", item.Keyword);
1330 8ab98ea3 LJIYEON
                            connection.ExecuteNonQuery(cmd, txn);
1331 ddc1c369 LJIYEON
                        }
1332 d1afd412 이지연
1333 81bdaeed LJIYEON
                        txn.Commit();
1334 ddc1c369 LJIYEON
                    }
1335
                    catch (Exception ex)
1336
                    {
1337
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1338
                        return false;
1339
                    }
1340
                }
1341
            }
1342
1343
            return true;
1344
        }
1345
1346 88c1965b gaqhf
        public static bool SaveEquipmentNopocketSetting(List<EquipmentNoPocketItem> keywordItems)
1347
        {
1348
            ID2Info id2Info = ID2Info.GetInstance();
1349
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1350
            {
1351
                using (var txn = connection.BeginTransaction())
1352
                {
1353
                    try
1354
                    {
1355
                        var query = $"DELETE FROM {PSN_NOPOCKETSETTING}";
1356
                        connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1357
1358
                        foreach (EquipmentNoPocketItem item in keywordItems)
1359
                        {
1360
                            query = $"INSERT INTO {PSN_NOPOCKETSETTING} ([INDEX], [TYPE], [NAME]) VALUES (@INDEX, @TYPE, @NAME)";
1361
                            var cmd = connection.GetSqlStringCommand(query);
1362
                            AddWithValue(cmd, "@INDEX", item.Index);
1363
                            AddWithValue(cmd, "@TYPE", item.Type);
1364
                            AddWithValue(cmd, "@NAME", item.Name);
1365
                            connection.ExecuteNonQuery(cmd, txn);
1366
                        }
1367
1368
                        txn.Commit();
1369
                    }
1370
                    catch (Exception ex)
1371
                    {
1372
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1373
                        return false;
1374
                    }
1375
                }
1376
            }
1377
1378
            return true;
1379
        }
1380
1381 f2a63376 이지연
        public static bool SaveAirFinCoolerSetting(List<EquipmentAirFinCoolerItem> keywordItems)
1382
        {
1383
            ID2Info id2Info = ID2Info.GetInstance();
1384
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1385
            {
1386
                using (var txn = connection.BeginTransaction())
1387
                {
1388
                    try
1389
                    {
1390
                        var query = $"DELETE FROM {PSN_AIRFINCOOLERSETTING}";
1391
                        connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1392
1393
                        foreach (EquipmentAirFinCoolerItem item in keywordItems)
1394
                        {
1395 284fa2c9 이지연
                            query = $"INSERT INTO {PSN_AIRFINCOOLERSETTING} ([INDEX], [TYPE], [TagIdentifier], [AttributeName], [NAME]) VALUES (@INDEX, @TYPE, @TagIdentifier, @AttributeName, @NAME)";
1396 f2a63376 이지연
                            var cmd = connection.GetSqlStringCommand(query);
1397
                            AddWithValue(cmd, "@INDEX", item.Index);
1398
                            AddWithValue(cmd, "@TYPE", item.Type);
1399 284fa2c9 이지연
                            AddWithValue(cmd, "@TagIdentifier", item.TagIdentifier);
1400
                            AddWithValue(cmd, "@AttributeName", item.AttributeName);
1401 f2a63376 이지연
                            AddWithValue(cmd, "@NAME", item.Name);
1402
                            connection.ExecuteNonQuery(cmd, txn);
1403 284fa2c9 이지연
1404 f2a63376 이지연
                        }
1405
1406
                        txn.Commit();
1407
                    }
1408
                    catch (Exception ex)
1409
                    {
1410
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1411
                        return false;
1412
                    }
1413
                }
1414
            }
1415
1416
            return true;
1417
        }
1418
1419 1ae1a1c6 LJIYEON
        public static bool SaveTopologyRule(DataTable dt)
1420 c6503eaa gaqhf
        {
1421
            ID2Info id2Info = ID2Info.GetInstance();
1422 0ff2a9f1 LJIYEON
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1423 c6503eaa gaqhf
            {
1424 23a96301 humkyung
                using (var txn = connection.BeginTransaction())
1425 c6503eaa gaqhf
                {
1426 23a96301 humkyung
                    try
1427 c6503eaa gaqhf
                    {
1428 23a96301 humkyung
                        var query = $"DELETE FROM {PSN_TOPOLOGY_RULE}";
1429
                        var cmd = connection.GetSqlStringCommand(query);
1430 0ff2a9f1 LJIYEON
                        //connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1431
                        connection.ExecuteNonQuery(cmd, txn);
1432 1ae1a1c6 LJIYEON
1433
                        foreach (DataRow row in dt.Rows)
1434
                        {
1435 0ff2a9f1 LJIYEON
                            query = $"INSERT INTO {PSN_TOPOLOGY_RULE} (UID) VALUES (@UID)";
1436 23a96301 humkyung
                            cmd = connection.GetSqlStringCommand(query);
1437
                            AddWithValue(cmd, "@UID", row["NAME"].ToString());
1438
                            connection.ExecuteNonQuery(cmd, txn);
1439 1ae1a1c6 LJIYEON
                        }
1440 23a96301 humkyung
1441
                        txn.Commit();
1442
                    }
1443
                    catch (Exception ex)
1444
                    {
1445
                        txn.Rollback();
1446
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1447
                        return false;
1448 c6503eaa gaqhf
                    }
1449
                }
1450
            }
1451 23a96301 humkyung
1452 1ae1a1c6 LJIYEON
            return true;
1453 c6503eaa gaqhf
        }
1454 abee404a LJIYEON
1455 1ae1a1c6 LJIYEON
        public static DataTable SelectTopologyRule()
1456 7881ec8f gaqhf
        {
1457 23a96301 humkyung
            DataTable dt = null;
1458
1459 7881ec8f gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
1460 0ff2a9f1 LJIYEON
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1461 7881ec8f gaqhf
            {
1462
                try
1463
                {
1464 23a96301 humkyung
                    var query = $"SELECT * FROM {PSN_TOPOLOGY_RULE}";
1465
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1466 7881ec8f gaqhf
                    {
1467 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
1468 7881ec8f gaqhf
                    }
1469
                }
1470
                catch (Exception ex)
1471
                {
1472
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1473
                }
1474
            }
1475 23a96301 humkyung
1476 7881ec8f gaqhf
            return dt;
1477
        }
1478 45529c16 LJIYEON
1479 23a96301 humkyung
        private static void AddWithValue(DbCommand cmd, string PropName, object Value)
1480
        {
1481
            var param = cmd.CreateParameter();
1482
            param.ParameterName = PropName;
1483
            param.Value = Value;
1484
            cmd.Parameters.Add(param);
1485
        }
1486 3610fd3f LJIYEON
1487 1d46fca7 LJIYEON
        public static DataTable SelectRevisionTable()
1488 3610fd3f LJIYEON
        {
1489 1d46fca7 LJIYEON
            DataTable dt = null;
1490 3610fd3f LJIYEON
            ID2Info id2Info = ID2Info.GetInstance();
1491 1d46fca7 LJIYEON
1492
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1493 3610fd3f LJIYEON
            {
1494
                try
1495
                {
1496 7106e181 LJIYEON
                    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'";
1497
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1498
                    {
1499
                        dt = ds.Tables[0].Copy();
1500
                    }
1501
                }
1502
                catch (Exception ex)
1503
                {
1504
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1505
                }
1506
            }
1507
1508
            return dt;
1509
        }
1510
1511
        public static DataTable SelectRevision()
1512
        {
1513
            DataTable dt = null;
1514
            ID2Info id2Info = ID2Info.GetInstance();
1515
1516
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1517
            {
1518
                try
1519
                {
1520
                    var query = $"SELECT * FROM ARS_COMMON.dbo.PSNREVISION";
1521
1522 1d46fca7 LJIYEON
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1523 3610fd3f LJIYEON
                    {
1524 1d46fca7 LJIYEON
                        dt = ds.Tables[0].Copy();
1525
                    }
1526
                }
1527
                catch (Exception ex)
1528
                {
1529
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1530
                }
1531
            }
1532 3610fd3f LJIYEON
1533 1d46fca7 LJIYEON
            return dt;
1534
        }
1535 54b6df95 LJIYEON
1536 1d46fca7 LJIYEON
        public static bool ConnCreateRevisionTable(Dictionary<string, string> dicColCheck, List<string> names)
1537
        {
1538
            bool result = false;
1539
            ID2Info id2Info = ID2Info.GetInstance();
1540
1541
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1542
            {
1543
                try
1544
                {
1545
                    if (names.Count == 0)
1546
                    {
1547 d1afd412 이지연
1548 1d46fca7 LJIYEON
                        var query = $"CREATE TABLE ARS_COMMON.dbo.PSNRevision ([OID] [uniqueidentifier] ,[Project_OID] [uniqueidentifier] ," +
1549
                            $"[ProjectCode] nvarchar(255), [RevNumber] int ,[UserName] nvarchar(255) ,[TimeData] nvarchar(255) ," +
1550
                            $"[PSNDatabasePath] nvarchar(255) ,	[PsnByPBSFilter] varchar(20) ,[PsnByNPDFilter] varchar(20) ,[PidDrawings] int ,	" +
1551
                            $"[PipeSystems] int ,[PipeLines] int ,[Topologies] int ,[PipeSystemNetworks] int ,[InValidPSNs] int ,[E2E] int ," +
1552 91c75c0b 이지연
                            $"[E2B] int ,[B2E] int ,[HDE] int ,[HD2] int ,[HDB] int ,[B2B] int, [LastModificationdate] nvarchar(255), [ID2_PSN] nvarchar(10))";
1553 1d46fca7 LJIYEON
                        using (var cmd = connection.GetSqlStringCommand(query))
1554 3610fd3f LJIYEON
                        {
1555 1d46fca7 LJIYEON
                            cmd.ExecuteNonQuery();
1556 3610fd3f LJIYEON
                        }
1557 1d46fca7 LJIYEON
                    }
1558
                    else
1559
                    {
1560
                        AddColumn(PSN_REVISION, dicColCheck, names);
1561 3610fd3f LJIYEON
                    }
1562
1563 1d46fca7 LJIYEON
                    void AddColumn(string TableName, Dictionary<string, string> dicCol, List<string> colnames)
1564 3610fd3f LJIYEON
                    {
1565
                        bool check = false;
1566
                        if (colnames != null)
1567
                        {
1568
                            foreach (KeyValuePair<string, string> col in dicCol)
1569
                            {
1570
                                check = false;
1571
                                foreach (string c in colnames)
1572
                                {
1573
                                    if (col.Key.Contains(c))
1574
                                    {
1575
                                        check = true;
1576
                                        break;
1577
                                    }
1578
                                }
1579
1580
                                if (!check) //없으면 추가
1581
                                {
1582
                                    string i = string.Empty;
1583
                                    if (col.Value.ToString().ToUpper().Contains("INT") || col.Value.ToString().ToUpper().Contains("REAL"))
1584
                                        i = "DEFAULT 0";
1585
1586 1d46fca7 LJIYEON
                                    var queryalter = $"ALTER TABLE ARS_COMMON.dbo.PSNRevision ADD [" + col.Key + "] " + col.Value + " " + i + ";";
1587
                                    using (var cmd = connection.GetSqlStringCommand(queryalter))
1588 3610fd3f LJIYEON
                                    {
1589
                                        cmd.ExecuteNonQuery();
1590
                                    }
1591
                                }
1592
                            }
1593
                        }
1594
                    }
1595 1d46fca7 LJIYEON
1596
                    result = true;
1597 3610fd3f LJIYEON
                }
1598
                catch (Exception ex)
1599
                {
1600 1d46fca7 LJIYEON
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1601 3610fd3f LJIYEON
                }
1602
            }
1603 1d46fca7 LJIYEON
1604
            return result;
1605 3610fd3f LJIYEON
        }
1606 1d46fca7 LJIYEON
1607 7106e181 LJIYEON
        public static bool UpdateRevision(string TimeData, string ProjectCode, int RevNumber, string UserName, string PSNDatabasePath, string PsnByPBSFilter, string PsnByNPDFilter,
1608
           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)
1609
        {
1610
            ID2Info id2Info = ID2Info.GetInstance();
1611
            bool result = true;
1612
1613
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1614
            {
1615
                try
1616
                {
1617
                    using (var txn = connection.BeginTransaction())
1618
                    {
1619
                        try
1620
                        {
1621
                            string where = string.Format("DELETE FROM ARS_COMMON.dbo.PSNRevision WHERE ProjectCode = '{0}' AND PSNDatabasePath = '{1}' AND RevNumber = {2}", ProjectCode, PSNDatabasePath, RevNumber);
1622
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(where), txn);
1623
                            var query = $"INSERT INTO ARS_COMMON.dbo.PSNRevision (OID, Project_OID, ProjectCode, RevNumber, UserName, TimeData, PSNDatabasePath, " +
1624
                                $"PsnByPBSFilter, PsnByNPDFilter, PidDrawings, PipeSystems, PipeLines, Topologies, PipeSystemNetworks, InValidPSNs, E2E, E2B, B2E, HDE, " +
1625 91c75c0b 이지연
                                $"HD2, HDB, B2B, LastModificationdate, ID2_PSN) VALUES (NEWID(), NEWID(), @ProjectCode, @RevNumber, @UserName, @TimeData, @PSNDatabasePath" +
1626 7106e181 LJIYEON
                                $", @PsnByPBSFilter, @PsnByNPDFilter, @PidDrawings, @PipeSystems, @PipeLines, @Topologies, @PipeSystemNetworks, @InValidPSNs, " +
1627 91c75c0b 이지연
                                $"@E2E, @E2B, @B2E, @HDE, @HD2, @HDB, @B2B, @LastModificationdate, @ID2_PSN)";
1628 7106e181 LJIYEON
                            var cmd = connection.GetSqlStringCommand(query);
1629 d1afd412 이지연
1630 7106e181 LJIYEON
                            AddWithValue(cmd, "@ProjectCode", ProjectCode);
1631
                            AddWithValue(cmd, "@RevNumber", RevNumber);
1632
                            AddWithValue(cmd, "@UserName", UserName);
1633
                            AddWithValue(cmd, "@TimeData", TimeData); //String.Format("{0:G}", dt) // DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
1634
1635
                            AddWithValue(cmd, "@PSNDatabasePath", PSNDatabasePath);
1636
1637
                            AddWithValue(cmd, "@PsnByPBSFilter", PsnByPBSFilter);
1638
                            AddWithValue(cmd, "@PsnByNPDFilter", PsnByNPDFilter);
1639
                            AddWithValue(cmd, "@PidDrawings", PidDrawings);
1640
                            AddWithValue(cmd, "@PipeSystems", PipeSystems);
1641
                            AddWithValue(cmd, "@PipeLines", PipeLines);
1642
1643
                            AddWithValue(cmd, "@Topologies", Topologies);
1644
                            AddWithValue(cmd, "@PipeSystemNetworks", PipeSystemNetworks);
1645
                            AddWithValue(cmd, "@InValidPSNs", InValidPSNs);
1646
                            AddWithValue(cmd, "@E2E", E2E);
1647
                            AddWithValue(cmd, "@E2B", E2B);
1648
                            AddWithValue(cmd, "@B2E", B2E);
1649
                            AddWithValue(cmd, "@HDE", HDE);
1650
                            AddWithValue(cmd, "@HD2", HD2);
1651
                            AddWithValue(cmd, "@HDB", HDB);
1652
                            AddWithValue(cmd, "@B2B", B2B);
1653
                            System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US");
1654
                            DateTime oDateTime = DateTime.Now;
1655
                            AddWithValue(cmd, "@LastModificationdate", oDateTime.ToString(ci));
1656 91c75c0b 이지연
                            AddWithValue(cmd, "@ID2_PSN", "Y");
1657 7106e181 LJIYEON
                            connection.ExecuteNonQuery(cmd, txn);
1658
1659
                            txn.Commit();
1660
                        }
1661
                        catch (Exception ex)
1662
                        {
1663
                            txn.Rollback();
1664
                            result = false;
1665
                        }
1666
                    }
1667
                }
1668
                catch (Exception ex)
1669
                {
1670
                    System.Windows.Forms.MessageBox.Show(ex.Message);
1671
                    result = false;
1672
                }
1673
            }
1674
1675
            return result;
1676
        }
1677
1678
1679 1621e1e9 LJIYEON
        public static bool SaveRevision(string ProjectCode, int RevNumber, string UserName, string PSNDatabasePath, string PsnByPBSFilter, string PsnByNPDFilter,
1680
            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)
1681
        {
1682
            ID2Info id2Info = ID2Info.GetInstance();
1683
1684
            bool result = true;
1685
1686
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1687
            {
1688
                try
1689
                {
1690
                    using (var txn = connection.BeginTransaction())
1691
                    {
1692
                        try
1693 d1afd412 이지연
                        {
1694
1695 1621e1e9 LJIYEON
                            var query = $"INSERT INTO ARS_COMMON.dbo.PSNRevision (OID, Project_OID, ProjectCode, RevNumber, UserName, TimeData, PSNDatabasePath, " +
1696
                                $"PsnByPBSFilter, PsnByNPDFilter, PidDrawings, PipeSystems, PipeLines, Topologies, PipeSystemNetworks, InValidPSNs, E2E, E2B, B2E, HDE, " +
1697 91c75c0b 이지연
                                $"HD2, HDB, B2B, LastModificationdate, ID2_PSN) VALUES (NEWID(), NEWID(), @ProjectCode, @RevNumber, @UserName, @TimeData, @PSNDatabasePath" +
1698 1621e1e9 LJIYEON
                                $", @PsnByPBSFilter, @PsnByNPDFilter, @PidDrawings, @PipeSystems, @PipeLines, @Topologies, @PipeSystemNetworks, @InValidPSNs, " +
1699 91c75c0b 이지연
                                $"@E2E, @E2B, @B2E, @HDE, @HD2, @HDB, @B2B, @LastModificationdate, @ID2_PSN)";
1700 1621e1e9 LJIYEON
                            var cmd = connection.GetSqlStringCommand(query);
1701
                            AddWithValue(cmd, "@OID", Guid.NewGuid().ToString());
1702
                            AddWithValue(cmd, "@Project_OID", Guid.NewGuid().ToString());
1703
                            AddWithValue(cmd, "@ProjectCode", ProjectCode);
1704
                            AddWithValue(cmd, "@RevNumber", RevNumber);
1705
                            AddWithValue(cmd, "@UserName", UserName);
1706 54b6df95 LJIYEON
1707
                            System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US");
1708
                            DateTime oDateTime = DateTime.Now;
1709
1710
                            AddWithValue(cmd, "@TimeData", oDateTime.ToString(ci)); //String.Format("{0:G}", dt) // DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
1711
1712 1621e1e9 LJIYEON
                            AddWithValue(cmd, "@PSNDatabasePath", PSNDatabasePath);
1713
1714
                            AddWithValue(cmd, "@PsnByPBSFilter", PsnByPBSFilter);
1715
                            AddWithValue(cmd, "@PsnByNPDFilter", PsnByNPDFilter);
1716
                            AddWithValue(cmd, "@PidDrawings", PidDrawings);
1717
                            AddWithValue(cmd, "@PipeSystems", PipeSystems);
1718
                            AddWithValue(cmd, "@PipeLines", PipeLines);
1719
1720
                            AddWithValue(cmd, "@Topologies", Topologies);
1721
                            AddWithValue(cmd, "@PipeSystemNetworks", PipeSystemNetworks);
1722
                            AddWithValue(cmd, "@InValidPSNs", InValidPSNs);
1723
                            AddWithValue(cmd, "@E2E", E2E);
1724
                            AddWithValue(cmd, "@E2B", E2B);
1725
                            AddWithValue(cmd, "@B2E", B2E);
1726
                            AddWithValue(cmd, "@HDE", HDE);
1727
                            AddWithValue(cmd, "@HD2", HD2);
1728
                            AddWithValue(cmd, "@HDB", HDB);
1729
                            AddWithValue(cmd, "@B2B", B2B);
1730 3b253d62 gaqhf
                            // AddWithValue(cmd, "@LastModificationdate", oDateTime.ToString(ci));
1731
                            AddWithValue(cmd, "@LastModificationdate", "");
1732 91c75c0b 이지연
                            AddWithValue(cmd, "@ID2_PSN", "Y");
1733 d1afd412 이지연
1734 1621e1e9 LJIYEON
                            connection.ExecuteNonQuery(cmd, txn);
1735 d1afd412 이지연
1736 1621e1e9 LJIYEON
                            txn.Commit();
1737
                        }
1738
                        catch (Exception ex)
1739
                        {
1740
                            txn.Rollback();
1741
                            result = false;
1742
                        }
1743
                    }
1744
                }
1745
                catch (Exception ex)
1746
                {
1747
                    System.Windows.Forms.MessageBox.Show(ex.Message);
1748
                    result = false;
1749
                }
1750
            }
1751
1752
            return result;
1753
        }
1754
1755 5c248ee3 gaqhf
        public static bool SavePSNData(PSN item)
1756 6b9e7a56 gaqhf
        {
1757
            ID2Info id2Info = ID2Info.GetInstance();
1758
1759 d1afd412 이지연
            bool result = true;
1760 3610fd3f LJIYEON
1761 0ff2a9f1 LJIYEON
            using (IAbstractDatabase connection = id2Info.CreateConnection())
1762 6b9e7a56 gaqhf
            {
1763
                try
1764
                {
1765 23a96301 humkyung
                    using (var txn = connection.BeginTransaction())
1766 6b9e7a56 gaqhf
                    {
1767
                        try
1768
                        {
1769 23a96301 humkyung
                            // Path Items
1770
                            var query = $"DELETE FROM {PSN_PATHITEMS}";
1771
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1772 9c151350 gaqhf
                            for (int i = 0; i < item.PathItems.Rows.Count; i++)
1773 6b9e7a56 gaqhf
                            {
1774 9c151350 gaqhf
                                DataRow row = item.PathItems.Rows[i];
1775 0ff2a9f1 LJIYEON
                                query = $"INSERT INTO {PSN_PATHITEMS} " +
1776
                                    $"(OID, SequenceData_OID, TopologySet_OID, BranchTopologySet_OID, PipeLine_OID, ItemName, ItemTag, DESCRIPTION, CLASS, SUBCLASS, TYPE, " +
1777 bf9e8432 이지연
                                    $"PIDNAME, Equipment_OID, NPD, GROUPTAG, PipeSystemNetwork_OID, PipeRun_OID, ViewPipeSystemNetwork_OID, EqpGroupTag, MainLineTag, EGTConnectedPoint, EGFlowDirection) VALUES " +
1778 811d7949 LJIYEON
                                    $"(@OID, @SequenceData_OID, @TopologySet_OID, @BranchTopologySet_OID, @PipeLine_OID, @ITEMNAME, @ITEMTAG, @DESCRIPTION, @Class, @SubClass, @TYPE, @PIDNAME, " +
1779 bf9e8432 이지연
                                    $"@Equipment_OID, @NPD, @GROUPTAG, @PipeSystemNetwork_OID,@PipeRun_OID, @ViewPipeSystemNetwork_OID, @EqpGroupTag , @MainLineTag, @EGTConnectedPoint, @EGFlowDirection)";
1780 23a96301 humkyung
                                var cmd = connection.GetSqlStringCommand(query);
1781 f9f2787b LJIYEON
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
1782
                                AddWithValue(cmd, "@SequenceData_OID", string.IsNullOrEmpty(row["SequenceData_OID"].ToString()) ? "" : row["SequenceData_OID"].ToString());
1783
                                AddWithValue(cmd, "@TopologySet_OID", string.IsNullOrEmpty(row["TopologySet_OID"].ToString()) ? "" : row["TopologySet_OID"].ToString());
1784
                                AddWithValue(cmd, "@BranchTopologySet_OID", string.IsNullOrEmpty(row["BranchTopologySet_OID"].ToString()) ? "" : row["BranchTopologySet_OID"].ToString());
1785
                                AddWithValue(cmd, "@PipeLine_OID", string.IsNullOrEmpty(row["PipeLine_OID"].ToString()) ? "" : row["PipeLine_OID"].ToString());
1786
                                AddWithValue(cmd, "@ITEMNAME", string.IsNullOrEmpty(row["ITEMNAME"].ToString()) ? "" : row["ITEMNAME"].ToString());
1787
                                AddWithValue(cmd, "@ITEMTAG", string.IsNullOrEmpty(row["ITEMTAG"].ToString()) ? "" : row["ITEMTAG"].ToString());
1788 3610fd3f LJIYEON
                                AddWithValue(cmd, "@DESCRIPTION", string.IsNullOrEmpty(row["DESCRIPTION"].ToString()) ? "" : row["DESCRIPTION"].ToString());
1789 f9f2787b LJIYEON
                                AddWithValue(cmd, "@Class", string.IsNullOrEmpty(row["Class"].ToString()) ? "" : row["Class"].ToString());
1790
                                AddWithValue(cmd, "@SubClass", string.IsNullOrEmpty(row["SubClass"].ToString()) ? "" : row["SubClass"].ToString());
1791
                                AddWithValue(cmd, "@TYPE", string.IsNullOrEmpty(row["TYPE"].ToString()) ? "" : row["TYPE"].ToString());
1792
                                AddWithValue(cmd, "@PIDNAME", string.IsNullOrEmpty(row["PIDNAME"].ToString()) ? "" : row["PIDNAME"].ToString());
1793 3610fd3f LJIYEON
                                AddWithValue(cmd, "@Equipment_OID", string.IsNullOrEmpty(row["Equipment_OID"].ToString()) ? "" : row["Equipment_OID"].ToString());
1794 f9f2787b LJIYEON
                                AddWithValue(cmd, "@NPD", string.IsNullOrEmpty(row["NPD"].ToString()) ? "" : row["NPD"].ToString());
1795 811d7949 LJIYEON
                                AddWithValue(cmd, "@GROUPTAG", string.IsNullOrEmpty(row["GROUPTAG"].ToString()) ? "" : row["GROUPTAG"].ToString());
1796 f9f2787b LJIYEON
                                AddWithValue(cmd, "@PipeSystemNetwork_OID", string.IsNullOrEmpty(row["PipeSystemNetwork_OID"].ToString()) ? "" : row["PipeSystemNetwork_OID"].ToString());
1797
                                AddWithValue(cmd, "@ViewPipeSystemNetwork_OID", string.IsNullOrEmpty(row["ViewPipeSystemNetwork_OID"].ToString()) ? "" : row["ViewPipeSystemNetwork_OID"].ToString());
1798
                                AddWithValue(cmd, "@PipeRun_OID", string.IsNullOrEmpty(row["PipeRun_OID"].ToString()) ? "" : row["PipeRun_OID"].ToString());
1799 bf9e8432 이지연
                                AddWithValue(cmd, "@EqpGroupTag", string.IsNullOrEmpty(row["EqpGroupTag"].ToString()) ? "" : row["EqpGroupTag"].ToString());
1800
                                AddWithValue(cmd, "@MainLineTag", string.IsNullOrEmpty(row["MainLineTag"].ToString()) ? "" : row["MainLineTag"].ToString());
1801
1802
                                AddWithValue(cmd, "@EGTConnectedPoint", string.IsNullOrEmpty(row["EGTConnectedPoint"].ToString()) ? "0" : row["EGTConnectedPoint"].ToString());
1803
                                AddWithValue(cmd, "@EGFlowDirection", string.IsNullOrEmpty(row["EGFlowDirection"].ToString()) ? "" : row["EGFlowDirection"].ToString());
1804 23a96301 humkyung
                                connection.ExecuteNonQuery(cmd, txn);
1805
                            }
1806 6b9e7a56 gaqhf
1807 23a96301 humkyung
                            // Sequence
1808
                            query = $"DELETE FROM {PSN_SEQUENCEDATA}";
1809
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1810
                            foreach (DataRow row in item.SequenceData.Rows)
1811
                            {
1812 0ff2a9f1 LJIYEON
                                query = $"INSERT INTO {PSN_SEQUENCEDATA} (OID, SERIALNUMBER, PathItem_OID, TopologySet_OID_Key) VALUES (@OID, @SERIALNUMBER, @PathItem_OID, @TopologySet_OID_Key)";
1813 23a96301 humkyung
                                var cmd = connection.GetSqlStringCommand(query);
1814 f9f2787b LJIYEON
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
1815
                                AddWithValue(cmd, "@SERIALNUMBER", string.IsNullOrEmpty(row["SERIALNUMBER"].ToString()) ? "" : row["SERIALNUMBER"].ToString());
1816
                                AddWithValue(cmd, "@PathItem_OID", string.IsNullOrEmpty(row["PathItem_OID"].ToString()) ? "" : row["PathItem_OID"].ToString());
1817
                                AddWithValue(cmd, "@TopologySet_OID_Key", string.IsNullOrEmpty(row["TopologySet_OID_Key"].ToString()) ? "" : row["TopologySet_OID_Key"].ToString());
1818 23a96301 humkyung
                                connection.ExecuteNonQuery(cmd, txn);
1819
                            }
1820 5c248ee3 gaqhf
1821 23a96301 humkyung
                            // Nozzle
1822
                            query = $"DELETE FROM {PSN_NOZZLE}";
1823
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1824
                            foreach (DataRow row in item.Nozzle.Rows)
1825
                            {
1826 0ff2a9f1 LJIYEON
                                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)";
1827 23a96301 humkyung
                                var cmd = connection.GetSqlStringCommand(query);
1828 f9f2787b LJIYEON
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
1829
                                AddWithValue(cmd, "@ITEMTAG", string.IsNullOrEmpty(row["ITEMTAG"].ToString()) ? "" : row["ITEMTAG"].ToString());
1830
1831
                                if (string.IsNullOrEmpty(row["XCOORDS"].ToString()))
1832
                                    AddWithValue(cmd, "@XCOORDS", DBNull.Value);
1833
                                else
1834
                                    AddWithValue(cmd, "@XCOORDS", row["XCOORDS"].ToString());
1835
1836
                                if (string.IsNullOrEmpty(row["YCOORDS"].ToString()))
1837
                                    AddWithValue(cmd, "@YCOORDS", DBNull.Value);
1838
                                else
1839
                                    AddWithValue(cmd, "@YCOORDS", row["YCOORDS"].ToString());
1840
1841
                                AddWithValue(cmd, "@Equipment_OID", string.IsNullOrEmpty(row["Equipment_OID"].ToString()) ? "" : row["Equipment_OID"].ToString());
1842
                                AddWithValue(cmd, "@FLUID", string.IsNullOrEmpty(row["FLUID"].ToString()) ? "" : row["FLUID"].ToString());
1843
                                AddWithValue(cmd, "@NPD", string.IsNullOrEmpty(row["NPD"].ToString()) ? "" : row["NPD"].ToString());
1844 33cee849 LJIYEON
                                AddWithValue(cmd, "@PMC", string.IsNullOrEmpty(row["PMC"].ToString()) ? "" : row["PMC"].ToString());
1845 f9f2787b LJIYEON
1846
                                if (string.IsNullOrEmpty(row["ROTATION"].ToString()))
1847
                                    AddWithValue(cmd, "@ROTATION", DBNull.Value);
1848
                                else
1849
                                    AddWithValue(cmd, "@ROTATION", row["ROTATION"].ToString());
1850 3610fd3f LJIYEON
1851 f9f2787b LJIYEON
                                AddWithValue(cmd, "@FlowDirection", string.IsNullOrEmpty(row["FlowDirection"].ToString()) ? "" : row["FlowDirection"].ToString());
1852 23a96301 humkyung
                                connection.ExecuteNonQuery(cmd, txn);
1853
                            }
1854 5c248ee3 gaqhf
1855 23a96301 humkyung
                            //Equipment
1856
                            query = $"DELETE FROM {PSN_EQUIPMENT}";
1857
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1858
                            foreach (DataRow row in item.Equipment.Rows)
1859
                            {
1860 0ff2a9f1 LJIYEON
                                query = $"INSERT INTO {PSN_EQUIPMENT} (OID, ItemTag, Xcoords, Ycoords) VALUES (@OID, @ITEMTAG, @XCOORDS, @YCOORDS)";
1861 23a96301 humkyung
                                var cmd = connection.GetSqlStringCommand(query);
1862 f9f2787b LJIYEON
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
1863
                                AddWithValue(cmd, "@ITEMTAG", string.IsNullOrEmpty(row["ITEMTAG"].ToString()) ? "" : row["ITEMTAG"].ToString());
1864
1865
                                if (string.IsNullOrEmpty(row["XCOORDS"].ToString()))
1866
                                    AddWithValue(cmd, "@XCOORDS", DBNull.Value);
1867
                                else
1868
                                    AddWithValue(cmd, "@XCOORDS", row["XCOORDS"].ToString());
1869
1870
                                if (string.IsNullOrEmpty(row["YCOORDS"].ToString()))
1871
                                    AddWithValue(cmd, "@YCOORDS", DBNull.Value);
1872
                                else
1873
                                    AddWithValue(cmd, "@YCOORDS", row["YCOORDS"].ToString());
1874
1875 23a96301 humkyung
                                connection.ExecuteNonQuery(cmd, txn);
1876
                            }
1877 5c248ee3 gaqhf
1878 23a96301 humkyung
                            // TopologySet
1879
                            query = $"DELETE FROM {PSN_TOPOLOGYSET}";
1880
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1881
                            foreach (DataRow row in item.TopologySet.Rows)
1882
                            {
1883 0ff2a9f1 LJIYEON
                                query = $"INSERT INTO {PSN_TOPOLOGYSET} (OID, Type, SubType, HeadItemTag, TailItemTag, HeadItemSPID, TailItemSPID) VALUES (@OID, @Type, @SubType, @HeadItemTag, @TailItemTag, @HeadItemSPID, @TailItemSPID)";
1884 23a96301 humkyung
                                var cmd = connection.GetSqlStringCommand(query);
1885 f9f2787b LJIYEON
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
1886
                                AddWithValue(cmd, "@Type", string.IsNullOrEmpty(row["Type"].ToString()) ? "" : row["Type"].ToString());
1887
                                AddWithValue(cmd, "@SubType", string.IsNullOrEmpty(row["SubType"].ToString()) ? "" : row["SubType"].ToString());
1888
                                AddWithValue(cmd, "@HeadItemTag", string.IsNullOrEmpty(row["HeadItemTag"].ToString()) ? "" : row["HeadItemTag"].ToString());
1889
                                AddWithValue(cmd, "@TailItemTag", string.IsNullOrEmpty(row["TailItemTag"].ToString()) ? "" : row["TailItemTag"].ToString());
1890
                                AddWithValue(cmd, "@HeadItemSPID", string.IsNullOrEmpty(row["HeadItemSPID"].ToString()) ? "" : row["HeadItemSPID"].ToString());
1891
                                AddWithValue(cmd, "@TailItemSPID", string.IsNullOrEmpty(row["TailItemSPID"].ToString()) ? "" : row["TailItemSPID"].ToString());
1892 23a96301 humkyung
                                connection.ExecuteNonQuery(cmd, txn);
1893
                            }
1894 36a45f13 gaqhf
1895 23a96301 humkyung
                            // PSN
1896
                            query = $"DELETE FROM {PSN_PIPESYSTEMNETWORK} WHERE PSNRevisionNumber = '{string.Format("V{0:D4}", item.Revision)}'";
1897
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1898
                            foreach (DataRow row in item.PipeSystemNetwork.Rows)
1899
                            {
1900 eb44d82c LJIYEON
                                query = $"INSERT INTO {PSN_PIPESYSTEMNETWORK} " +
1901 4842b66a 이지연
                                    $"(OID, Type, OrderNumber, Pipeline_OID, FROM_DATA, TO_DATA, TopologySet_OID_Key, PSNRevisionNumber, PBS, Drawings, IsValid, Status, IncludingVirtualData, PSNAccuracy, Pocket, EGTag, HasMLTags, GroundLevel) VALUES " +
1902
                                    $"(@OID, @Type, @OrderNumber, @Pipeline_OID, @FROM_DATA, @TO_DATA, @TopologySet_OID_Key, @PSNRevisionNumber,  @PBS, @Drawings, @IsValid, @Status, @IncludingVirtualData, @PSNAccuracy, @Pocket, @EGTag, @HasMLTags, @GroundLevel)";
1903 23a96301 humkyung
                                var cmd = connection.GetSqlStringCommand(query);
1904 f9f2787b LJIYEON
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
1905
                                AddWithValue(cmd, "@Type", string.IsNullOrEmpty(row["Type"].ToString()) ? "" : row["Type"].ToString());
1906
                                AddWithValue(cmd, "@OrderNumber", string.IsNullOrEmpty(row["OrderNumber"].ToString()) ? "" : row["OrderNumber"].ToString());
1907
                                AddWithValue(cmd, "@Pipeline_OID", string.IsNullOrEmpty(row["Pipeline_OID"].ToString()) ? "" : row["Pipeline_OID"].ToString());
1908
                                AddWithValue(cmd, "@FROM_DATA", string.IsNullOrEmpty(row["FROM_DATA"].ToString()) ? "" : row["FROM_DATA"].ToString());
1909
                                AddWithValue(cmd, "@TO_DATA", string.IsNullOrEmpty(row["TO_DATA"].ToString()) ? "" : row["TO_DATA"].ToString());
1910
                                AddWithValue(cmd, "@TopologySet_OID_Key", string.IsNullOrEmpty(row["TopologySet_OID_Key"].ToString()) ? "" : row["TopologySet_OID_Key"].ToString());
1911
                                AddWithValue(cmd, "@PSNRevisionNumber", string.IsNullOrEmpty(row["PSNRevisionNumber"].ToString()) ? "" : row["PSNRevisionNumber"].ToString());
1912 eb44d82c LJIYEON
1913 72775f2e LJIYEON
                                int IsValid = 0;
1914 eb44d82c LJIYEON
                                if (row["IsValid"].ToString() == string.Empty || row["IsValid"].ToString() == "OK")
1915 72775f2e LJIYEON
                                    IsValid = 0;
1916
                                else if (row["IsValid"].ToString() == "InValid")
1917
                                    IsValid = 1;
1918
                                else if (row["IsValid"].ToString() == "Error")
1919
                                    IsValid = -1;
1920 f9f2787b LJIYEON
1921 72775f2e LJIYEON
                                AddWithValue(cmd, "@IsValid", IsValid);
1922 f9f2787b LJIYEON
                                AddWithValue(cmd, "@Status", string.IsNullOrEmpty(row["Status"].ToString()) ? "" : row["Status"].ToString());
1923
1924
                                AddWithValue(cmd, "@PBS", string.IsNullOrEmpty(row["PBS"].ToString()) ? "" : row["PBS"].ToString());
1925
                                AddWithValue(cmd, "@Drawings", string.IsNullOrEmpty(row["Drawings"].ToString()) ? "" : row["Drawings"].ToString());
1926
1927
                                AddWithValue(cmd, "@IncludingVirtualData", string.IsNullOrEmpty(row["IncludingVirtualData"].ToString()) ? "" : row["IncludingVirtualData"].ToString());
1928
                                if (string.IsNullOrEmpty(row["PSNAccuracy"].ToString()))
1929
                                    AddWithValue(cmd, "@PSNAccuracy", DBNull.Value);
1930
                                else
1931 d3fbf0c0 gaqhf
                                    AddWithValue(cmd, "@PSNAccuracy", row["PSNAccuracy"].ToString().Replace("%", ""));
1932 eb44d82c LJIYEON
1933 08b33e44 gaqhf
                                AddWithValue(cmd, "@Pocket", string.IsNullOrEmpty(row["Pocket"].ToString()) ? "Yes" : row["Pocket"].ToString());
1934
1935 d1afd412 이지연
                                AddWithValue(cmd, "@EGTag", string.IsNullOrEmpty(row["EGTag"].ToString()) ? "" : row["EGTag"].ToString());
1936
                                AddWithValue(cmd, "@HasMLTags", string.IsNullOrEmpty(row["HasMLTags"].ToString()) ? "False" : row["HasMLTags"].ToString());
1937 4842b66a 이지연
                                AddWithValue(cmd, "@GroundLevel", string.IsNullOrEmpty(row["GroundLevel"].ToString()) ? "" : row["GroundLevel"].ToString());
1938 23a96301 humkyung
                                connection.ExecuteNonQuery(cmd, txn);
1939 6b9e7a56 gaqhf
                            }
1940 23a96301 humkyung
1941 f9f2787b LJIYEON
                            //Pipeline
1942
                            query = $"DELETE FROM {PSN_PIPELINE}";
1943
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1944
                            foreach (DataRow row in item.PipeLine.Rows)
1945
                            {
1946 0ff2a9f1 LJIYEON
                                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)";
1947 f9f2787b LJIYEON
                                var cmd = connection.GetSqlStringCommand(query);
1948
                                AddWithValue(cmd, "@OID", row["OID"].ToString());
1949
                                AddWithValue(cmd, "@PipeSystem_OID", row["PipeSystem_OID"].ToString());
1950
                                AddWithValue(cmd, "@FLUID", row["FLUID"].ToString());
1951
                                AddWithValue(cmd, "@PMC", row["PMC"].ToString());
1952
                                AddWithValue(cmd, "@SEQNUMBER", row["SEQNUMBER"].ToString());
1953
                                AddWithValue(cmd, "@INSULATION", row["INSULATION"].ToString());
1954
                                AddWithValue(cmd, "@FROM_DATA", row["FROM_DATA"].ToString());
1955
                                AddWithValue(cmd, "@TO_DATA", row["TO_DATA"].ToString());
1956
                                AddWithValue(cmd, "@Unit", row["Unit"].ToString());
1957
                                connection.ExecuteNonQuery(cmd, txn);
1958
                            }
1959 a36541fb LJIYEON
1960 531fb158 LJIYEON
                            //PipeSystem
1961
                            query = $"DELETE FROM {PSN_PIPESYSTEM}";
1962
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1963
                            foreach (DataRow row in item.PipeSystem.Rows)
1964
                            {
1965
                                query = $"INSERT INTO {PSN_PIPESYSTEM} (OID, DESCRIPTION, FLUID, PMC, PipeLineQty, GroundLevel) VALUES (@OID, @DESCRIPTION, @FLUID, @PMC, @PipeLineQty, @GroundLevel)";
1966
                                var cmd = connection.GetSqlStringCommand(query);
1967
                                AddWithValue(cmd, "@OID", row["OID"].ToString());
1968
                                AddWithValue(cmd, "@DESCRIPTION", row["DESCRIPTION"].ToString());
1969
                                AddWithValue(cmd, "@FLUID", row["FLUID"].ToString());
1970
                                AddWithValue(cmd, "@PMC", row["PMC"].ToString());
1971
                                AddWithValue(cmd, "@PipeLineQty", row["PipeLineQty"].ToString());
1972
                                AddWithValue(cmd, "@GroundLevel", row["GroundLevel"].ToString());
1973
                                connection.ExecuteNonQuery(cmd, txn);
1974
                            }
1975
1976 d1afd412 이지연
                            if (id2Info.ID2DBType == ID2DB_Type.MSSQL)
1977 ad39d1ee LJIYEON
                            {
1978
                                query = $"If(db_id(N'" + PSN_COMMON + "') IS NULL) CREATE DATABASE [" + PSN_COMMON + "]";
1979
                                connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1980
                            }
1981 d1afd412 이지연
1982 3610fd3f LJIYEON
1983 23a96301 humkyung
                            txn.Commit();
1984 6b9e7a56 gaqhf
                        }
1985
                        catch (Exception ex)
1986
                        {
1987 23a96301 humkyung
                            txn.Rollback();
1988 6b9e7a56 gaqhf
                            result = false;
1989
                        }
1990 1d46fca7 LJIYEON
1991
                    }
1992
                    void AddColumn(string TableName, Dictionary<string, string> dicCol, List<string> colnames)
1993 d1afd412 이지연
                    {
1994 1d46fca7 LJIYEON
                        bool check = false;
1995
                        if (colnames != null)
1996
                        {
1997
                            foreach (KeyValuePair<string, string> col in dicCol)
1998
                            {
1999
                                check = false;
2000
                                foreach (string c in colnames)
2001
                                {
2002
                                    if (col.Key.Contains(c))
2003
                                    {
2004
                                        check = true;
2005
                                        break;
2006
                                    }
2007
                                }
2008
2009
                                if (!check) //없으면 추가
2010
                                {
2011
                                    string i = string.Empty;
2012
                                    if (col.Value.ToString().ToUpper().Contains("INT") || col.Value.ToString().ToUpper().Contains("REAL"))
2013
                                        i = "DEFAULT 0";
2014
2015
                                    var queryalter = $"ALTER TABLE " + TableName + " ADD [" + col.Key + "] " + col.Value + " " + i + ";";
2016
                                    using (var cmd = connection.GetSqlStringCommand(queryalter))
2017
                                    {
2018
                                        cmd.ExecuteNonQuery();
2019
                                    }
2020
                                }
2021
                            }
2022
                        }
2023 6b9e7a56 gaqhf
                    }
2024
                }
2025
                catch (Exception ex)
2026
                {
2027
                    System.Windows.Forms.MessageBox.Show(ex.Message);
2028
                    result = false;
2029
                }
2030
            }
2031
2032
            return result;
2033
        }
2034
2035 5c248ee3 gaqhf
        public static bool SavePSNFluidCode(DataTable dt)
2036 6b9e7a56 gaqhf
        {
2037
            ID2Info id2Info = ID2Info.GetInstance();
2038
2039
            bool result = true;
2040 0ff2a9f1 LJIYEON
            using (IAbstractDatabase connection = id2Info.CreateConnection())
2041 6b9e7a56 gaqhf
            {
2042 1ae1a1c6 LJIYEON
                try
2043 6b9e7a56 gaqhf
                {
2044 23a96301 humkyung
                    using (var txn = connection.BeginTransaction())
2045 1ae1a1c6 LJIYEON
                    {
2046
                        try
2047 757ab2f2 LJIYEON
                        {
2048 23a96301 humkyung
                            var query = $"DELETE FROM {PSN_FLUIDCODE}";
2049
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
2050
2051
                            foreach (DataRow row in dt.Rows)
2052 757ab2f2 LJIYEON
                            {
2053 0ff2a9f1 LJIYEON
                                query = $"INSERT INTO {PSN_FLUIDCODE} (UID, Code, Description, Condition, Remarks, GroundLevel) VALUES (@UID, @Code, @Description, @Condition, @Remarks, @GroundLevel)";
2054 23a96301 humkyung
                                var cmd = connection.GetSqlStringCommand(query);
2055
                                cmd.Parameters.Clear();
2056
2057
                                {
2058
                                    var param = cmd.CreateParameter();
2059
                                    param.ParameterName = "@UID";
2060
                                    param.Value = row["UID"].ToString();
2061
                                    cmd.Parameters.Add(param);
2062
                                }
2063
2064
                                {
2065
                                    var param = cmd.CreateParameter();
2066
                                    param.ParameterName = "@Code";
2067
                                    param.Value = row["Code"].ToString();
2068
                                    cmd.Parameters.Add(param);
2069
                                }
2070
2071
                                {
2072
                                    var param = cmd.CreateParameter();
2073
                                    param.ParameterName = "@Description";
2074
                                    param.Value = row["Description"].ToString();
2075
                                    cmd.Parameters.Add(param);
2076
                                }
2077
2078
                                {
2079
                                    var param = cmd.CreateParameter();
2080
                                    param.ParameterName = "@Condition";
2081
                                    param.Value = row["Condition"].ToString();
2082
                                    cmd.Parameters.Add(param);
2083
                                }
2084
2085
                                {
2086
                                    var param = cmd.CreateParameter();
2087
                                    param.ParameterName = "@Remarks";
2088
                                    param.Value = row["Remarks"].ToString();
2089
                                    cmd.Parameters.Add(param);
2090
                                }
2091 1ae1a1c6 LJIYEON
2092 757ab2f2 LJIYEON
                                {
2093 23a96301 humkyung
                                    var param = cmd.CreateParameter();
2094
                                    param.ParameterName = "@GroundLevel";
2095
                                    param.Value = row["GroundLevel"].ToString();
2096
                                    cmd.Parameters.Add(param);
2097 757ab2f2 LJIYEON
                                }
2098 23a96301 humkyung
2099
                                connection.ExecuteNonQuery(cmd, txn);
2100 757ab2f2 LJIYEON
                            }
2101 23a96301 humkyung
                            txn.Commit();
2102 757ab2f2 LJIYEON
                        }
2103 1ae1a1c6 LJIYEON
                        catch (Exception ex)
2104 6b9e7a56 gaqhf
                        {
2105 23a96301 humkyung
                            txn.Rollback();
2106 1ae1a1c6 LJIYEON
                            result = false;
2107 6b9e7a56 gaqhf
                        }
2108
                    }
2109 1ae1a1c6 LJIYEON
                }
2110
                catch (Exception ex)
2111
                {
2112
                    System.Windows.Forms.MessageBox.Show(ex.Message);
2113
                    result = false;
2114
                }
2115 6b9e7a56 gaqhf
            }
2116
2117
            return result;
2118
        }
2119
2120 1ae1a1c6 LJIYEON
        public static DataTable SelectPSNFluidCode()
2121 31d37d58 LJIYEON
        {
2122 23a96301 humkyung
            DataTable dt = null;
2123 31d37d58 LJIYEON
            ID2Info id2Info = ID2Info.GetInstance();
2124 1ae1a1c6 LJIYEON
2125 0ff2a9f1 LJIYEON
            using (IAbstractDatabase connection = id2Info.CreateConnection())
2126 31d37d58 LJIYEON
            {
2127 1ae1a1c6 LJIYEON
                try
2128 31d37d58 LJIYEON
                {
2129 23a96301 humkyung
                    var query = $"SELECT * FROM {PSN_FLUIDCODE}";
2130
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2131 31d37d58 LJIYEON
                    {
2132 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
2133 31d37d58 LJIYEON
                    }
2134
                }
2135 1ae1a1c6 LJIYEON
                catch (Exception ex)
2136
                {
2137
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2138
                }
2139 31d37d58 LJIYEON
            }
2140 23a96301 humkyung
2141 1ae1a1c6 LJIYEON
            return dt;
2142
        }
2143
2144
        public static bool SavePSNPMC(DataTable dt)
2145
        {
2146
            ID2Info id2Info = ID2Info.GetInstance();
2147
2148
            bool result = true;
2149 0ff2a9f1 LJIYEON
            using (IAbstractDatabase connection = id2Info.CreateConnection())
2150 31d37d58 LJIYEON
            {
2151 1ae1a1c6 LJIYEON
                try
2152
                {
2153 23a96301 humkyung
                    using (var txn = connection.BeginTransaction())
2154 1ae1a1c6 LJIYEON
                    {
2155
                        try
2156
                        {
2157 23a96301 humkyung
                            var query = $"DELETE FROM {PSN_PIPINGMATLCLASS}";
2158
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
2159
2160
                            foreach (DataRow row in dt.Rows)
2161 1ae1a1c6 LJIYEON
                            {
2162 0ff2a9f1 LJIYEON
                                query = $"INSERT INTO {PSN_PIPINGMATLCLASS} ( UID, Priority, Code, Description, Condition, Remarks, GroundLevel) VALUES (@UID, @Priority, @Code, @Description, @Condition, @Remarks, @GroundLevel)";
2163 23a96301 humkyung
                                var cmd = connection.GetSqlStringCommand(query);
2164
                                cmd.Parameters.Clear();
2165
2166
                                {
2167
                                    var param = cmd.CreateParameter();
2168
                                    param.ParameterName = "@UID";
2169
                                    param.Value = row["UID"].ToString();
2170
                                    cmd.Parameters.Add(param);
2171
                                }
2172
2173
                                {
2174
                                    var param = cmd.CreateParameter();
2175
                                    param.ParameterName = "@Priority";
2176
                                    param.Value = row["Priority"].ToString();
2177
                                    cmd.Parameters.Add(param);
2178
                                }
2179
2180
                                {
2181
                                    var param = cmd.CreateParameter();
2182
                                    param.ParameterName = "@Code";
2183
                                    param.Value = row["Code"].ToString();
2184
                                    cmd.Parameters.Add(param);
2185
                                }
2186
2187
                                {
2188
                                    var param = cmd.CreateParameter();
2189
                                    param.ParameterName = "@Description";
2190
                                    param.Value = row["Description"].ToString();
2191
                                    cmd.Parameters.Add(param);
2192
                                }
2193 31d37d58 LJIYEON
2194 1ae1a1c6 LJIYEON
                                {
2195 23a96301 humkyung
                                    var param = cmd.CreateParameter();
2196
                                    param.ParameterName = "@Condition";
2197
                                    param.Value = row["Condition"].ToString();
2198
                                    cmd.Parameters.Add(param);
2199 1ae1a1c6 LJIYEON
                                }
2200 23a96301 humkyung
2201
                                {
2202
                                    var param = cmd.CreateParameter();
2203
                                    param.ParameterName = "@Remarks";
2204
                                    param.Value = row["Remarks"].ToString();
2205
                                    cmd.Parameters.Add(param);
2206
                                }
2207
2208
                                {
2209
                                    var param = cmd.CreateParameter();
2210
                                    param.ParameterName = "@GroundLevel";
2211
                                    param.Value = row["GroundLevel"].ToString();
2212
                                    cmd.Parameters.Add(param);
2213
                                }
2214
2215
                                connection.ExecuteNonQuery(cmd, txn);
2216 1ae1a1c6 LJIYEON
                            }
2217 23a96301 humkyung
2218
                            txn.Commit();
2219 1ae1a1c6 LJIYEON
                        }
2220
                        catch (Exception ex)
2221
                        {
2222 23a96301 humkyung
                            txn.Rollback();
2223 1ae1a1c6 LJIYEON
                            result = false;
2224
                        }
2225
                    }
2226
                }
2227
                catch (Exception ex)
2228
                {
2229
                    System.Windows.Forms.MessageBox.Show(ex.Message);
2230
                    result = false;
2231
                }
2232
            }
2233 31d37d58 LJIYEON
2234 1ae1a1c6 LJIYEON
            return result;
2235 31d37d58 LJIYEON
        }
2236
2237 33cee849 LJIYEON
        public static bool SavePSNInsulation(DataTable dt)
2238
        {
2239
            ID2Info id2Info = ID2Info.GetInstance();
2240
2241
            bool result = true;
2242 0ff2a9f1 LJIYEON
            using (IAbstractDatabase connection = id2Info.CreateConnection())
2243 33cee849 LJIYEON
            {
2244
                try
2245
                {
2246
                    using (var txn = connection.BeginTransaction())
2247
                    {
2248
                        try
2249
                        {
2250
                            var query = $"DELETE FROM {PSN_INSULATIONPURPOSE}";
2251
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
2252
2253
                            foreach (DataRow row in dt.Rows)
2254
                            {
2255 0ff2a9f1 LJIYEON
                                query = $"INSERT INTO {PSN_INSULATIONPURPOSE} (UID, Code, Description, Remarks) VALUES (@UID, @Code, @Description, @Remarks)";
2256 33cee849 LJIYEON
                                var cmd = connection.GetSqlStringCommand(query);
2257
                                cmd.Parameters.Clear();
2258
2259
                                {
2260
                                    var param = cmd.CreateParameter();
2261
                                    param.ParameterName = "@UID";
2262
                                    param.Value = row["UID"].ToString();
2263
                                    cmd.Parameters.Add(param);
2264
                                }
2265 d1afd412 이지연
2266 33cee849 LJIYEON
                                {
2267
                                    var param = cmd.CreateParameter();
2268
                                    param.ParameterName = "@Code";
2269
                                    param.Value = row["Code"].ToString();
2270
                                    cmd.Parameters.Add(param);
2271
                                }
2272
2273
                                {
2274
                                    var param = cmd.CreateParameter();
2275
                                    param.ParameterName = "@Description";
2276
                                    param.Value = row["Description"].ToString();
2277
                                    cmd.Parameters.Add(param);
2278
                                }
2279 d1afd412 이지연
2280 33cee849 LJIYEON
                                {
2281
                                    var param = cmd.CreateParameter();
2282
                                    param.ParameterName = "@Remarks";
2283
                                    param.Value = row["Remarks"].ToString();
2284
                                    cmd.Parameters.Add(param);
2285
                                }
2286
2287
                                connection.ExecuteNonQuery(cmd, txn);
2288
                            }
2289
2290
                            txn.Commit();
2291
                        }
2292
                        catch (Exception ex)
2293
                        {
2294
                            txn.Rollback();
2295
                            result = false;
2296
                        }
2297
                    }
2298
                }
2299
                catch (Exception ex)
2300
                {
2301
                    System.Windows.Forms.MessageBox.Show(ex.Message);
2302
                    result = false;
2303
                }
2304
            }
2305
2306
            return result;
2307
        }
2308 3210f690 LJIYEON
2309 5c248ee3 gaqhf
        public static PSN GetDBPSN()
2310 6b9e7a56 gaqhf
        {
2311 5c248ee3 gaqhf
            PSN result = new PSN();
2312 6b9e7a56 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
2313
2314 0ff2a9f1 LJIYEON
            using (IAbstractDatabase connection = id2Info.CreateConnection())
2315 6b9e7a56 gaqhf
            {
2316
                try
2317
                {
2318 3210f690 LJIYEON
                    //query = $"SELECT * FROM {PSN_PIPESYSTEMNETWORK}";
2319 eb44d82c LJIYEON
                    //using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2320
                    //{
2321 3210f690 LJIYEON
                    //    result.PipeSystemNetwork = ds.Tables[0].Copy();
2322 eb44d82c LJIYEON
                    //}
2323
2324 3210f690 LJIYEON
                    var query = $"SELECT * FROM {PSN_PIPESYSTEMNETWORK} WHERE PSNRevisionNumber = '{string.Format("V{0:D4}", GetRevision())}'";
2325
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2326
                    {
2327
                        result.PipeSystemNetwork = ds.Tables[0].Clone();
2328
                        result.PipeSystemNetwork.Columns["IsValid"].DataType = typeof(string);
2329
2330
                        foreach (DataRow row in ds.Tables[0].Rows)
2331
                        {
2332
                            DataRow newRow = result.PipeSystemNetwork.NewRow();
2333
                            newRow["OID"] = row["OID"].ToString();
2334
                            newRow["Type"] = row["Type"].ToString();
2335
                            newRow["OrderNumber"] = row["OrderNumber"].ToString();
2336
                            newRow["Pipeline_OID"] = row["Pipeline_OID"].ToString();
2337
                            newRow["FROM_DATA"] = row["FROM_DATA"].ToString();
2338
                            newRow["TO_DATA"] = row["TO_DATA"].ToString();
2339
                            newRow["TopologySet_OID_Key"] = row["TopologySet_OID_Key"].ToString();
2340
                            newRow["PSNRevisionNumber"] = row["PSNRevisionNumber"].ToString();
2341
2342
                            string IsValid = string.Empty;
2343
2344
                            if (Convert.ToInt32(row["IsValid"].ToString()) == 0)
2345
                                IsValid = string.Empty;//"OK";
2346
                            else if (Convert.ToInt32(row["IsValid"].ToString()) == 1)
2347
                                IsValid = "InValid";
2348
                            else if (Convert.ToInt32(row["IsValid"].ToString()) == -1)
2349
                                IsValid = "Error";
2350
2351
                            newRow["IsValid"] = IsValid;
2352
2353
                            newRow["Status"] = row["Status"].ToString();
2354
                            newRow["PBS"] = row["PBS"].ToString();
2355
                            newRow["Drawings"] = row["Drawings"].ToString();
2356
2357
                            newRow["IncludingVirtualData"] = row["IncludingVirtualData"].ToString();
2358
                            newRow["PSNAccuracy"] = row["PSNAccuracy"].ToString();
2359
2360 08b33e44 gaqhf
                            newRow["Pocket"] = row["Pocket"].ToString();
2361 d1afd412 이지연
2362
                            newRow["EGTag"] = row["EGTag"].ToString();
2363
                            newRow["HasMLTags"] = row["HasMLTags"].ToString();
2364 4842b66a 이지연
                            newRow["GroundLevel"] = row["GroundLevel"].ToString();
2365 3210f690 LJIYEON
                            result.PipeSystemNetwork.Rows.Add(newRow);
2366
                        }
2367
                    }
2368
2369
                    query = $"SELECT * FROM {PSN_EQUIPMENT}";
2370 23a96301 humkyung
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2371 6b9e7a56 gaqhf
                    {
2372 23a96301 humkyung
                        result.Equipment = ds.Tables[0].Copy();
2373
                    }
2374
2375
                    query = $"SELECT * FROM {PSN_NOZZLE}";
2376
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2377
                    {
2378
                        result.Nozzle = ds.Tables[0].Copy();
2379 6b9e7a56 gaqhf
                    }
2380 23a96301 humkyung
2381
                    query = $"SELECT * FROM {PSN_PATHITEMS}";
2382
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2383
                    {
2384
                        result.PathItems = ds.Tables[0].Copy();
2385
                    }
2386
2387
                    query = $"SELECT * FROM {PSN_SEQUENCEDATA}";
2388
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2389
                    {
2390
                        result.SequenceData = ds.Tables[0].Copy();
2391
                    }
2392
2393 aadd8450 LJIYEON
                    query = $"SELECT * FROM {PSN_TOPOLOGYSET}";
2394
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2395
                    {
2396
                        result.TopologySet = ds.Tables[0].Copy();
2397
                    }
2398
2399 a36541fb LJIYEON
                    query = $"SELECT * FROM {PSN_PIPELINE}";
2400
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2401
                    {
2402
                        result.PipeLine = ds.Tables[0].Copy();
2403 531fb158 LJIYEON
                    }
2404
2405
                    query = $"SELECT * FROM {PSN_PIPESYSTEM}";
2406
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2407
                    {
2408
                        result.PipeSystem = ds.Tables[0].Copy();
2409
                    }
2410 a36541fb LJIYEON
2411 23a96301 humkyung
                    result.Revision = GetRevision();
2412 6b9e7a56 gaqhf
                }
2413
                catch (Exception ex)
2414
                {
2415
                    System.Windows.Forms.MessageBox.Show(ex.Message);
2416 5c248ee3 gaqhf
                    result = null;
2417 6b9e7a56 gaqhf
                }
2418
            }
2419 23a96301 humkyung
2420 6b9e7a56 gaqhf
            return result;
2421
        }
2422 8f24b438 gaqhf
2423
        public static int GetRevision()
2424
        {
2425
            int result = 0;
2426
            ID2Info id2Info = ID2Info.GetInstance();
2427 23a96301 humkyung
2428 0ff2a9f1 LJIYEON
            using (IAbstractDatabase connection = id2Info.CreateConnection())
2429 8f24b438 gaqhf
            {
2430
                try
2431
                {
2432 23a96301 humkyung
                    var query = $"SELECT DISTINCT PSNRevisionNumber FROM {PSN_PIPESYSTEMNETWORK};";
2433
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2434 8f24b438 gaqhf
                    {
2435 23a96301 humkyung
                        foreach (DataRow row in ds.Tables[0].Rows)
2436 8f24b438 gaqhf
                        {
2437 d5637426 gaqhf
                            string value = row["PSNRevisionNumber"].ToString();
2438 36a45f13 gaqhf
                            if (value.StartsWith("V"))
2439 d5637426 gaqhf
                                value = value.Remove(0, 1);
2440
                            int revisionNumber = Convert.ToInt32(value);
2441 8f24b438 gaqhf
                            if (result < revisionNumber)
2442
                                result = revisionNumber;
2443
                        }
2444
                    }
2445
                }
2446
                catch (Exception ex)
2447
                {
2448
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2449
                    result = -1;
2450
                }
2451
            }
2452
2453
            return result;
2454
        }
2455
2456 5c248ee3 gaqhf
        public static DataTable GetPathItem()
2457
        {
2458 23a96301 humkyung
            DataTable dt = null;
2459
2460 5c248ee3 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
2461 0ff2a9f1 LJIYEON
            using (IAbstractDatabase connection = id2Info.CreateConnection())
2462 5c248ee3 gaqhf
            {
2463
                try
2464
                {
2465 23a96301 humkyung
                    var query = $"SELECT * FROM {PSN_PATHITEMS}";
2466
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2467 5c248ee3 gaqhf
                    {
2468 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
2469 5c248ee3 gaqhf
                    }
2470
                }
2471
                catch (Exception ex)
2472
                {
2473
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2474
                }
2475
            }
2476 23a96301 humkyung
2477 5c248ee3 gaqhf
            return dt;
2478
        }
2479 757ab2f2 LJIYEON
2480 36a45f13 gaqhf
        public static DataTable GetTopologySet()
2481 5c248ee3 gaqhf
        {
2482 23a96301 humkyung
            DataTable dt = null;
2483
2484 5c248ee3 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
2485 0ff2a9f1 LJIYEON
            using (IAbstractDatabase connection = id2Info.CreateConnection())
2486 5c248ee3 gaqhf
            {
2487
                try
2488
                {
2489 23a96301 humkyung
                    var query = $"SELECT * FROM {PSN_TOPOLOGYSET}";
2490
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2491 5c248ee3 gaqhf
                    {
2492 aadd8450 LJIYEON
                        dt = ds.Tables[0].Clone();
2493
                        foreach (DataRow row in ds.Tables[0].Rows)
2494
                        {
2495
                            DataRow newRow = dt.NewRow();
2496
                            newRow["OID"] = row["OID"].ToString();
2497
                            newRow["Type"] = row["Type"].ToString();
2498
                            newRow["SubType"] = row["SubType"].ToString();
2499
                            newRow["HeadItemTag"] = row["HeadItemTag"].ToString();
2500
                            newRow["TailItemTag"] = row["TailItemTag"].ToString();
2501 72775f2e LJIYEON
                            newRow["HeadItemSPID"] = row["HeadItemSPID"].ToString();
2502
                            newRow["TailItemSPID"] = row["TailItemSPID"].ToString();
2503 aadd8450 LJIYEON
                            dt.Rows.Add(newRow);
2504
                        }
2505 5c248ee3 gaqhf
                    }
2506
                }
2507
                catch (Exception ex)
2508
                {
2509
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2510
                }
2511
            }
2512 23a96301 humkyung
2513 5c248ee3 gaqhf
            return dt;
2514
        }
2515 757ab2f2 LJIYEON
2516 5c248ee3 gaqhf
        public static DataTable GetPipeSystemNetwork()
2517
        {
2518 23a96301 humkyung
            DataTable dt = null;
2519
2520 5c248ee3 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
2521 0ff2a9f1 LJIYEON
            using (IAbstractDatabase connection = id2Info.CreateConnection())
2522 5c248ee3 gaqhf
            {
2523
                try
2524
                {
2525 811d7949 LJIYEON
                    var query = $"SELECT * FROM {PSN_PIPESYSTEMNETWORK} WHERE PSNRevisionNumber = '{string.Format("V{0:D4}", GetRevision())}' ORDER BY OID, OrderNumber";
2526 23a96301 humkyung
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2527 5c248ee3 gaqhf
                    {
2528 45529c16 LJIYEON
                        dt = ds.Tables[0].Clone();
2529 72775f2e LJIYEON
                        dt.Columns["IsValid"].DataType = typeof(string);
2530 45529c16 LJIYEON
                        foreach (DataRow row in ds.Tables[0].Rows)
2531
                        {
2532
                            DataRow newRow = dt.NewRow();
2533
                            newRow["OID"] = row["OID"].ToString();
2534
                            newRow["Type"] = row["Type"].ToString();
2535
                            newRow["OrderNumber"] = row["OrderNumber"].ToString();
2536
                            newRow["Pipeline_OID"] = row["Pipeline_OID"].ToString();
2537
                            newRow["FROM_DATA"] = row["FROM_DATA"].ToString();
2538
                            newRow["TO_DATA"] = row["TO_DATA"].ToString();
2539
                            newRow["TopologySet_OID_Key"] = row["TopologySet_OID_Key"].ToString();
2540
                            newRow["PSNRevisionNumber"] = row["PSNRevisionNumber"].ToString();
2541 eb44d82c LJIYEON
2542 72775f2e LJIYEON
                            string IsValid = string.Empty;
2543 45529c16 LJIYEON
2544 72775f2e LJIYEON
                            if (Convert.ToInt32(row["IsValid"].ToString()) == 0)
2545
                                IsValid = string.Empty;//"OK";
2546
                            else if (Convert.ToInt32(row["IsValid"].ToString()) == 1)
2547
                                IsValid = "InValid";
2548
                            else if (Convert.ToInt32(row["IsValid"].ToString()) == -1)
2549
                                IsValid = "Error";
2550 45529c16 LJIYEON
2551 72775f2e LJIYEON
                            newRow["IsValid"] = IsValid;
2552 45529c16 LJIYEON
                            newRow["Status"] = row["Status"].ToString();
2553 eb44d82c LJIYEON
2554
                            newRow["PBS"] = row["PBS"].ToString();
2555
                            newRow["Drawings"] = row["Drawings"].ToString();
2556 d1afd412 이지연
2557 ddc1c369 LJIYEON
                            newRow["IncludingVirtualData"] = row["IncludingVirtualData"].ToString();
2558 08b33e44 gaqhf
                            newRow["PSNAccuracy"] = row["PSNAccuracy"].ToString();
2559
2560
                            newRow["Pocket"] = row["Pocket"].ToString();
2561 d1afd412 이지연
                            newRow["EGTag"] = row["EGTag"].ToString();
2562
                            newRow["HasMLTags"] = row["HasMLTags"].ToString();
2563 4842b66a 이지연
                            newRow["GroundLevel"] = row["GroundLevel"].ToString();
2564 45529c16 LJIYEON
                            dt.Rows.Add(newRow);
2565
                        }
2566 5c248ee3 gaqhf
                    }
2567
                }
2568
                catch (Exception ex)
2569
                {
2570
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2571
                }
2572
            }
2573 23a96301 humkyung
2574 5c248ee3 gaqhf
            return dt;
2575
        }
2576 757ab2f2 LJIYEON
2577 5c248ee3 gaqhf
        public static DataTable GetSequenceData()
2578
        {
2579 23a96301 humkyung
            DataTable dt = null;
2580
2581 5c248ee3 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
2582 0ff2a9f1 LJIYEON
            using (IAbstractDatabase connection = id2Info.CreateConnection())
2583 5c248ee3 gaqhf
            {
2584
                try
2585
                {
2586 23a96301 humkyung
                    var query = $"SELECT * FROM {PSN_SEQUENCEDATA}";
2587
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
2588 5c248ee3 gaqhf
                    {
2589 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
2590 5c248ee3 gaqhf
                    }
2591
                }
2592
                catch (Exception ex)
2593
                {
2594
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2595
                }
2596
            }
2597 23a96301 humkyung
2598 5c248ee3 gaqhf
            return dt;
2599
        }
2600 3d842083 LJIYEON
2601 d1afd412 이지연
2602 3d842083 LJIYEON
        //Anohter DB
2603
        public static bool ConnTestAndCreateAnotherTable()
2604
        {
2605
            bool result = false;
2606
            AnotherID2Info id2Info = AnotherID2Info.GetInstance();
2607
2608
            using (IAbstractDatabase connection = id2Info.CreateConnection())
2609
            {
2610
                try
2611
                {
2612
                    var names = connection.GetTableNames();
2613
                    var matched = names.FirstOrDefault(param => param == PSN_HEADER_SETTING);
2614
                    Dictionary<string, string> dicColCheck = new Dictionary<string, string>();
2615
                    dicColCheck.Add("GROUP_ID", "TEXT");
2616
                    dicColCheck.Add("DESCRIPTION", "TEXT");
2617
                    dicColCheck.Add("INDEX", "INTEGER");
2618
                    dicColCheck.Add("NAME", "TEXT");
2619
2620
                    if (matched == null)
2621
                    {
2622
                        var query = $"CREATE TABLE {PSN_HEADER_SETTING} (GROUP_ID TEXT, DESCRIPTION TEXT, [INDEX] INTEGER, NAME TEXT)";
2623
                        using (var cmd = connection.GetSqlStringCommand(query))
2624
                        {
2625
                            cmd.ExecuteNonQuery();
2626
                        }
2627
                    }
2628
                    else
2629
                    {
2630
                        AddColumn(PSN_HEADER_SETTING, dicColCheck);
2631
                    }
2632
2633
                    matched = names.FirstOrDefault(param => param == PSN_VENTDRAIN_SETTING);
2634
                    dicColCheck.Clear();
2635
                    dicColCheck.Add("GROUP_ID", "TEXT");
2636
                    dicColCheck.Add("DESCRIPTION", "TEXT");
2637
                    dicColCheck.Add("INDEX", "INTEGER");
2638
                    dicColCheck.Add("NAME", "TEXT");
2639
                    if (matched == null)
2640
                    {
2641
                        var query = $"CREATE TABLE {PSN_VENTDRAIN_SETTING} (GROUP_ID TEXT, DESCRIPTION TEXT, [INDEX] INTEGER, NAME TEXT)";
2642
                        using (var cmd = connection.GetSqlStringCommand(query))
2643
                        {
2644
                            cmd.ExecuteNonQuery();
2645
                        }
2646
                    }
2647
                    else
2648
                    {
2649
                        AddColumn(PSN_VENTDRAIN_SETTING, dicColCheck);
2650
                    }
2651
2652
                    matched = names.FirstOrDefault(param => param == PSN_TOPOLOGY_RULE);
2653
                    dicColCheck.Clear();
2654
                    dicColCheck.Add("UID", "TEXT");
2655
                    if (matched == null)
2656
                    {
2657
                        var query = $"CREATE TABLE {PSN_TOPOLOGY_RULE} (UID TEXT)";
2658
                        using (var cmd = connection.GetSqlStringCommand(query))
2659
                        {
2660
                            cmd.ExecuteNonQuery();
2661
                        }
2662
2663
                        DataTable topologyRule = new DataTable();
2664
                        topologyRule.Columns.Add("NAME", typeof(string));
2665
2666
                        topologyRule.Rows.Add("FluidCode");
2667
                        topologyRule.Rows.Add("-");
2668
                        topologyRule.Rows.Add("PipingMaterialsClass");
2669
                        topologyRule.Rows.Add("-");
2670
                        topologyRule.Rows.Add("Tag Seq No");
2671
2672
                        SaveTopologyRule(topologyRule);
2673
                    }
2674
                    //else
2675
                    //{
2676
                    //    AddColumn(PSN_TOPOLOGY_RULE, dicColCheck);
2677
                    //}
2678
2679
                    matched = names.FirstOrDefault(param => param == PSN_PIPESYSTEMNETWORK);
2680
                    dicColCheck.Clear();
2681
                    dicColCheck.Add("OID", "NVARCHAR(255)");
2682
                    dicColCheck.Add("Type", "NVARCHAR(255)");
2683
                    dicColCheck.Add("OrderNumber", "NVARCHAR(255)");
2684
                    dicColCheck.Add("Pipeline_OID", "NVARCHAR(255)");
2685
                    dicColCheck.Add("From_Data", "NVARCHAR(255)");
2686
                    dicColCheck.Add("To_Data", "NVARCHAR(255)");
2687
                    dicColCheck.Add("TopologySet_OID_Key", "NVARCHAR(125)");
2688
                    dicColCheck.Add("PSNRevisionNumber", "NVARCHAR(255)");
2689
                    dicColCheck.Add("IsValid", "INT");
2690
                    dicColCheck.Add("Status", "NVARCHAR(255)");
2691
                    dicColCheck.Add("PBS", "NVARCHAR(255)");
2692
                    dicColCheck.Add("Drawings", "NVARCHAR(255)");
2693
                    dicColCheck.Add("IncludingVirtualData", "NVARCHAR(10)");
2694
                    dicColCheck.Add("PSNAccuracy", "REAL");
2695 08b33e44 gaqhf
                    dicColCheck.Add("Pocket", "NVARCHAR(10)");
2696 d1afd412 이지연
                    dicColCheck.Add("EGTag", "NVARCHAR(255)");
2697
                    dicColCheck.Add("HasMLTags", "NVARCHAR(50)");
2698 4842b66a 이지연
                    dicColCheck.Add("GroundLevel", "NVARCHAR(20)");
2699 3d842083 LJIYEON
                    if (matched == null)
2700
                    {
2701
                        var query = $"CREATE TABLE {PSN_PIPESYSTEMNETWORK} (OID NVARCHAR(255), Type NVARCHAR(255), OrderNumber NVARCHAR(255), Pipeline_OID NVARCHAR(255), From_Data NVARCHAR(255), " +
2702
                            "To_Data NVARCHAR(255), TopologySet_OID_Key NVARCHAR(125), PSNRevisionNumber NVARCHAR(255), IsValid INTEGER, Status NVARCHAR(255), PBS NVARCHAR(255), Drawings NVARCHAR(255), " +
2703 4842b66a 이지연
                            "IncludingVirtualData NVARCHAR(10),  PSNAccuracy REAL, Pocket NVARCHAR(10), EGTag NVARCHAR(255), HasMLTags NVARCHAR(50), GroundLevel NVARCHAR(50))";
2704 3d842083 LJIYEON
                        using (var cmd = connection.GetSqlStringCommand(query))
2705
                        {
2706
                            cmd.ExecuteNonQuery();
2707
                        }
2708
                    }
2709
                    else
2710
                    {
2711
                        AddColumn(PSN_PIPESYSTEMNETWORK, dicColCheck);
2712
                    }
2713
2714
                    matched = names.FirstOrDefault(param => param == PSN_EQUIPMENT);
2715
                    dicColCheck.Clear();
2716
                    dicColCheck.Add("OID", "NVARCHAR(255)");
2717
                    dicColCheck.Add("ItemTag", "NVARCHAR(255)");
2718
                    dicColCheck.Add("Xcoords", "REAL");
2719
                    dicColCheck.Add("Ycoords", "REAL");
2720
                    if (matched == null)
2721
                    {
2722
                        var query = $"CREATE TABLE {PSN_EQUIPMENT} (OID NVARCHAR(255), ItemTag NVARCHAR(255), Xcoords REAL, Ycoords REAL)";
2723
                        using (var cmd = connection.GetSqlStringCommand(query))
2724
                        {
2725
                            cmd.ExecuteNonQuery();
2726
                        }
2727
                    }
2728
                    else
2729
                    {
2730
                        AddColumn(PSN_EQUIPMENT, dicColCheck);
2731
                    }
2732
2733
                    dicColCheck.Clear();
2734
                    dicColCheck.Add("OID", "NVARCHAR(255)");
2735
                    dicColCheck.Add("ItemTag", "NVARCHAR(255)");
2736
                    dicColCheck.Add("Xcoords", "REAL");
2737
                    dicColCheck.Add("Ycoords", "REAL");
2738
                    dicColCheck.Add("Equipment_OID", "NVARCHAR(255)");
2739
                    dicColCheck.Add("Fluid", "NVARCHAR(255)");
2740
                    dicColCheck.Add("NPD", "NVARCHAR(255)");
2741
                    dicColCheck.Add("PMC", "NVARCHAR(255)");
2742
                    dicColCheck.Add("Rotation", "REAL");
2743
                    dicColCheck.Add("FlowDirection", "NVARCHAR(255)");
2744
2745
                    matched = names.FirstOrDefault(param => param == PSN_NOZZLE);
2746
                    if (matched == null)
2747
                    {
2748
                        var query = $"CREATE TABLE {PSN_NOZZLE} (OID NVARCHAR(255), ItemTag NVARCHAR(255), Xcoords REAL, Ycoords REAL, Equipment_OID NVARCHAR(255), " +
2749
                            "Fluid NVARCHAR(255), NPD NVARCHAR(255), PMC NVARCHAR(255), Rotation REAL, FlowDirection NVARCHAR(255))";
2750
                        using (var cmd = connection.GetSqlStringCommand(query))
2751
                        {
2752
                            cmd.ExecuteNonQuery();
2753
                        }
2754
                    }
2755
                    else
2756
                    {
2757
                        AddColumn(PSN_NOZZLE, dicColCheck);
2758
                    }
2759
2760
                    matched = names.FirstOrDefault(param => param == PSN_FLUIDCODE);
2761
                    dicColCheck.Clear();
2762
                    dicColCheck.Add("UID", "NVARCHAR(50)");
2763
                    dicColCheck.Add("Code", "NVARCHAR(255)");
2764
                    dicColCheck.Add("Description", "NVARCHAR(255)");
2765
                    dicColCheck.Add("Condition", "NVARCHAR(255)");
2766
                    dicColCheck.Add("Remarks", "NVARCHAR(255)");
2767
                    dicColCheck.Add("GroundLevel", "NVARCHAR(20)");
2768
                    if (matched == null)
2769
                    {
2770
                        var query = $"CREATE TABLE {PSN_FLUIDCODE} (UID NVARCHAR(50), Code NVARCHAR(255), Description NVARCHAR(255), Condition NVARCHAR(255), Remarks NVARCHAR(255), GroundLevel NVARCHAR(20))";
2771
                        using (var cmd = connection.GetSqlStringCommand(query))
2772
                        {
2773
                            cmd.ExecuteNonQuery();
2774
                        }
2775
                    }
2776
                    else
2777
                    {
2778
                        AddColumn(PSN_FLUIDCODE, dicColCheck);
2779
                    }
2780
2781
                    matched = names.FirstOrDefault(param => param == PSN_PIPINGMATLCLASS);
2782
                    dicColCheck.Clear();
2783
                    dicColCheck.Add("UID", "NVARCHAR(50)");
2784
                    dicColCheck.Add("Priority", "INTEGER");
2785
                    dicColCheck.Add("Code", "NVARCHAR(255)");
2786
                    dicColCheck.Add("Description", "NVARCHAR(255)");
2787
                    dicColCheck.Add("Condition", "NVARCHAR(255)");
2788
                    dicColCheck.Add("Remarks", "NVARCHAR(255)");
2789
                    dicColCheck.Add("GroundLevel", "NVARCHAR(20)");
2790
                    if (matched == null)
2791
                    {
2792
                        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))";
2793
                        using (var cmd = connection.GetSqlStringCommand(query))
2794
                        {
2795
                            cmd.ExecuteNonQuery();
2796
                        }
2797
                    }
2798
                    else
2799
                    {
2800
                        AddColumn(PSN_PIPINGMATLCLASS, dicColCheck);
2801
                    }
2802
2803
                    matched = names.FirstOrDefault(param => param == PSN_SEQUENCEDATA);
2804
                    dicColCheck.Clear();
2805
                    dicColCheck.Add("OID", "NVARCHAR(255)");
2806
                    dicColCheck.Add("SERIALNUMBER", "NVARCHAR(255)");
2807
                    dicColCheck.Add("PathItem_OID", "NVARCHAR(255)");
2808
                    dicColCheck.Add("TopologySet_OID_Key", "NVARCHAR(255)");
2809
                    if (matched == null)
2810
                    {
2811
                        var query = $"CREATE TABLE {PSN_SEQUENCEDATA} (OID NVARCHAR(255), SERIALNUMBER NVARCHAR(255), PathItem_OID NVARCHAR(255), TopologySet_OID_Key NVARCHAR(255))";
2812
                        using (var cmd = connection.GetSqlStringCommand(query))
2813
                        {
2814
                            cmd.ExecuteNonQuery();
2815
                        }
2816
                    }
2817
                    else
2818
                    {
2819
                        AddColumn(PSN_SEQUENCEDATA, dicColCheck);
2820
                    }
2821
2822
                    matched = names.FirstOrDefault(param => param == PSN_PATHITEMS);
2823
                    dicColCheck.Clear();
2824
                    dicColCheck.Add("OID", "NVARCHAR(255)");
2825
                    dicColCheck.Add("SequenceData_OID", "NVARCHAR(255)");
2826
                    dicColCheck.Add("TopologySet_OID", "NVARCHAR(255)");
2827
                    dicColCheck.Add("BranchTopologySet_OID", "NVARCHAR(255)");
2828
                    dicColCheck.Add("PipeLine_OID", "NVARCHAR(255)");
2829
                    dicColCheck.Add("ItemName", "NVARCHAR(255)");
2830
                    dicColCheck.Add("ItemTag", "NVARCHAR(255)");
2831
                    dicColCheck.Add("DESCRIPTION", "NVARCHAR(255)");
2832
                    dicColCheck.Add("CLASS", "NVARCHAR(255)");
2833
                    dicColCheck.Add("SUBCLASS", "NVARCHAR(255)");
2834
                    dicColCheck.Add("TYPE", "NVARCHAR(255)");
2835
                    dicColCheck.Add("PIDNAME", "NVARCHAR(255)");
2836
                    dicColCheck.Add("Equipment_OID", "NVARCHAR(255)");
2837
                    dicColCheck.Add("NPD", "NVARCHAR(255)");
2838 811d7949 LJIYEON
                    dicColCheck.Add("GROUPTAG", "NVARCHAR(255)");
2839 3d842083 LJIYEON
                    dicColCheck.Add("PipeSystemNetwork_OID", "NVARCHAR(255)");
2840
                    dicColCheck.Add("PipeRun_OID", "NVARCHAR(255)");
2841
                    dicColCheck.Add("ViewPipeSystemNetwork_OID", "NVARCHAR(255)");
2842 bf9e8432 이지연
                    dicColCheck.Add("EqpGroupTag", "NVARCHAR(255)");
2843
                    dicColCheck.Add("MainLineTag", "NVARCHAR(255)");
2844
                    dicColCheck.Add("EGTConnectedPoint", "INT");
2845
                    dicColCheck.Add("EGFlowDirection", "NVARCHAR(10)");
2846 3d842083 LJIYEON
                    if (matched == null)
2847
                    {
2848
                        var query = $"CREATE TABLE {PSN_PATHITEMS} (OID NVARCHAR(255), SequenceData_OID NVARCHAR(255), " +
2849
                            "TopologySet_OID NVARCHAR(255), BranchTopologySet_OID NVARCHAR(255), PipeLine_OID NVARCHAR(255), ItemName NVARCHAR(255), ItemTag NVARCHAR(255), DESCRIPTION NVARCHAR(255), " +
2850 811d7949 LJIYEON
                            "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), " +
2851 bf9e8432 이지연
                            "ViewPipeSystemNetwork_OID NVARCHAR(255), EqpGroupTag NVARCHAR(255), MainLineTag NVARCHAR(255), EGTConnectedPoint INT, EGFlowDirection NVARCHAR(10))";
2852 3d842083 LJIYEON
                        using (var cmd = connection.GetSqlStringCommand(query))
2853
                        {
2854
                            cmd.ExecuteNonQuery();
2855
                        }
2856
                    }
2857
                    else
2858
                    {
2859
                        AddColumn(PSN_PATHITEMS, dicColCheck);
2860
                    }
2861
2862
                    matched = names.FirstOrDefault(param => param == PSN_VIEW);
2863
                    dicColCheck.Clear();
2864
                    dicColCheck.Add("OID", "TEXT");
2865
                    if (matched == null)
2866
                    {
2867
                        var query = $"CREATE TABLE {PSN_VIEW} (OID TEXT)";
2868
                        using (var cmd = connection.GetSqlStringCommand(query))
2869
                        {
2870
                            cmd.ExecuteNonQuery();
2871
                        }
2872
                    }
2873
2874
                    matched = names.FirstOrDefault(param => param == PSN_TOPOLOGYSET);
2875
                    dicColCheck.Clear();
2876
                    dicColCheck.Add("OID", "NVARCHAR(255)");
2877
                    dicColCheck.Add("Type", "NVARCHAR(255)");
2878
                    dicColCheck.Add("SubType", "NVARCHAR(255)");
2879
                    dicColCheck.Add("HeadItemTag", "NVARCHAR(255)");
2880
                    dicColCheck.Add("TailItemTag", "NVARCHAR(255)");
2881
                    dicColCheck.Add("HeadItemSPID", "NVARCHAR(255)");
2882
                    dicColCheck.Add("TailItemSPID", "NVARCHAR(255)");
2883
2884
                    if (matched == null)
2885
                    {
2886
                        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))";
2887
                        using (var cmd = connection.GetSqlStringCommand(query))
2888
                        {
2889
                            cmd.ExecuteNonQuery();
2890
                        }
2891
                    }
2892
                    else
2893
                    {
2894
                        AddColumn(PSN_TOPOLOGYSET, dicColCheck);
2895
                    }
2896
2897
                    matched = names.FirstOrDefault(param => param == PSN_TRANSFORMKEYWORD_SETTING);
2898
                    dicColCheck.Clear();
2899 b56d3ccb LJIYEON
                    dicColCheck.Add("INDEX", "INTEGER");
2900
                    dicColCheck.Add("NAME", "TEXT");
2901
                    dicColCheck.Add("KEYWORD", "TEXT");
2902 3d842083 LJIYEON
                    if (matched == null)
2903
                    {
2904
                        var query = $"CREATE TABLE {PSN_TRANSFORMKEYWORD_SETTING} ([INDEX] INTEGER, [NAME] TEXT, [KEYWORD] TEXT)";
2905
                        using (var cmd = connection.GetSqlStringCommand(query))
2906
                        {
2907
                            cmd.ExecuteNonQuery();
2908
                        }
2909
                    }
2910
                    else
2911
                    {
2912
                        AddColumn(PSN_TRANSFORMKEYWORD_SETTING, dicColCheck);
2913
                    }
2914
2915
                    matched = names.FirstOrDefault(param => param == PSN_PIPELINE);
2916
                    dicColCheck.Clear();
2917
                    dicColCheck.Add("OID", "NVARCHAR(255)");
2918
                    dicColCheck.Add("PipeSystem_OID", "NVARCHAR(255)");
2919
                    dicColCheck.Add("FLUID", "NVARCHAR(255)");
2920
                    dicColCheck.Add("PMC", "NVARCHAR(255)");
2921
                    dicColCheck.Add("SEQNUMBER", "NVARCHAR(255)");
2922
                    dicColCheck.Add("INSULATION", "NVARCHAR(255)");
2923
                    dicColCheck.Add("FROM_DATA", "NVARCHAR(255)");
2924
                    dicColCheck.Add("TO_DATA", "NVARCHAR(255)");
2925
                    dicColCheck.Add("Unit", "NVARCHAR(100)");
2926
                    if (matched == null)
2927
                    {
2928
                        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), " +
2929
                            $"FROM_DATA NVARCHAR(255), TO_DATA NVARCHAR(255), Unit NVARCHAR(100))";
2930
                        using (var cmd = connection.GetSqlStringCommand(query))
2931
                        {
2932
                            cmd.ExecuteNonQuery();
2933
                        }
2934
                    }
2935
                    else
2936
                    {
2937
                        AddColumn(PSN_PIPELINE, dicColCheck);
2938
                    }
2939
2940
                    matched = names.FirstOrDefault(param => param == PSN_INSULATIONPURPOSE);
2941
                    dicColCheck.Clear();
2942
                    dicColCheck.Add("UID", "NVARCHAR(50)");
2943
                    dicColCheck.Add("Code", "NVARCHAR(255)");
2944
                    dicColCheck.Add("Description", "NVARCHAR(255)");
2945
                    dicColCheck.Add("Remarks", "NVARCHAR(255)");
2946
                    if (matched == null)
2947
                    {
2948
                        var query = $"CREATE TABLE {PSN_INSULATIONPURPOSE} (UID NVARCHAR(50), Code NVARCHAR(255), Description NVARCHAR(255), Remarks NVARCHAR(255))";
2949
                        using (var cmd = connection.GetSqlStringCommand(query))
2950
                        {
2951
                            cmd.ExecuteNonQuery();
2952
                        }
2953
                    }
2954
                    else
2955
                    {
2956
                        AddColumn(PSN_INSULATIONPURPOSE, dicColCheck);
2957
                    }
2958
2959 811d7949 LJIYEON
                    matched = names.FirstOrDefault(param => param == PSN_VALVEGROUP_SETTING);
2960
                    dicColCheck.Clear();
2961
                    dicColCheck.Add("OID", "NVARCHAR(255)");
2962
                    dicColCheck.Add("GroupType", "NVARCHAR(255)");
2963
                    dicColCheck.Add("TagIdentifier", "NVARCHAR(50)");
2964
                    dicColCheck.Add("AttributeName", "NVARCHAR(255)");
2965
                    dicColCheck.Add("SppidSymbolName", "NVARCHAR(255)");
2966
                    if (matched == null)
2967
                    {
2968
                        var query = $"CREATE TABLE {PSN_VALVEGROUP_SETTING} (OID NVARCHAR(50), GroupType NVARCHAR(255), TagIdentifier NVARCHAR(50), AttributeName NVARCHAR(255), SppidSymbolName NVARCHAR(255))";
2969
                        using (var cmd = connection.GetSqlStringCommand(query))
2970
                        {
2971
                            cmd.ExecuteNonQuery();
2972
                        }
2973
                    }
2974
                    else
2975
                    {
2976
                        AddColumn(PSN_VALVEGROUP_SETTING, dicColCheck);
2977
                    }
2978
2979 531fb158 LJIYEON
                    matched = names.FirstOrDefault(param => param == PSN_PIPESYSTEM);
2980
                    dicColCheck.Clear();
2981
                    dicColCheck.Add("OID", "NVARCHAR(255)");
2982
                    dicColCheck.Add("DESCRIPTION", "NVARCHAR(255)");
2983
                    dicColCheck.Add("FLUID", "NVARCHAR(255)");
2984
                    dicColCheck.Add("PMC", "NVARCHAR(255)");
2985
                    dicColCheck.Add("PipeLineQty", "NVARCHAR(255)");
2986
                    dicColCheck.Add("GroundLevel", "NVARCHAR(20)");
2987
                    if (matched == null)
2988
                    {
2989
                        var query = $"CREATE TABLE {PSN_PIPESYSTEM} (OID NVARCHAR(255), DESCRIPTION NVARCHAR(255), FLUID NVARCHAR(255), PMC NVARCHAR(255), PipeLineQty NVARCHAR(255), GroundLevel NVARCHAR(20))";
2990
                        using (var cmd = connection.GetSqlStringCommand(query))
2991
                        {
2992
                            cmd.ExecuteNonQuery();
2993
                        }
2994
                    }
2995
                    else
2996
                    {
2997
                        AddColumn(PSN_PIPESYSTEM, dicColCheck);
2998
                    }
2999
3000 88c1965b gaqhf
                    matched = names.FirstOrDefault(param => param == PSN_NOPOCKETSETTING);
3001
                    dicColCheck.Clear();
3002 284fa2c9 이지연
                    dicColCheck.Add("INDEX", "INTEGER");
3003
                    dicColCheck.Add("TYPE", "TEXT");
3004
                    dicColCheck.Add("NAME", "TEXT");
3005 88c1965b gaqhf
                    if (matched == null)
3006
                    {
3007
                        var query = $"CREATE TABLE {PSN_NOPOCKETSETTING} ([INDEX] INTEGER, [TYPE] TEXT, [NAME] TEXT)";
3008
                        using (var cmd = connection.GetSqlStringCommand(query))
3009
                        {
3010
                            cmd.ExecuteNonQuery();
3011
                        }
3012
                    }
3013
                    else
3014
                    {
3015
                        AddColumn(PSN_NOPOCKETSETTING, dicColCheck);
3016
                    }
3017 54b6df95 LJIYEON
3018 f2a63376 이지연
                    matched = names.FirstOrDefault(param => param == PSN_AIRFINCOOLERSETTING);
3019
                    dicColCheck.Clear();
3020 284fa2c9 이지연
                    dicColCheck.Add("INDEX", "INTEGER");
3021
                    dicColCheck.Add("TYPE", "TEXT");
3022
                    dicColCheck.Add("TagIdentifier", "NVARCHAR(50)");
3023
                    dicColCheck.Add("AttributeName", "NVARCHAR(255)");
3024
                    dicColCheck.Add("NAME", "TEXT");
3025
3026 f2a63376 이지연
                    if (matched == null)
3027
                    {
3028 284fa2c9 이지연
                        var query = $"CREATE TABLE {PSN_AIRFINCOOLERSETTING} ([INDEX] INTEGER, [TYPE] TEXT, [TagIdentifier] TEXT, [AttributeName] TEXT, [NAME] TEXT)";
3029
                       
3030 f2a63376 이지연
                        using (var cmd = connection.GetSqlStringCommand(query))
3031
                        {
3032
                            cmd.ExecuteNonQuery();
3033
                        }
3034
                    }
3035
                    else
3036
                    {
3037
                        AddColumn(PSN_AIRFINCOOLERSETTING, dicColCheck);
3038
                    }
3039 d1afd412 이지연
3040 f2a63376 이지연
3041 54b6df95 LJIYEON
                    var query2 = $"If(db_id(N'" + PSN_COMMON + "') IS NULL) CREATE DATABASE [" + PSN_COMMON + "]";
3042
                    if (id2Info.ID2DBType == AnotherID2DB_Type.MSSQL)
3043
                    {
3044
                        //connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3045
                        using (var cmd = connection.GetSqlStringCommand(query2))
3046
                        {
3047
                            cmd.ExecuteNonQuery();
3048
                        }
3049
                    }
3050
3051 3d842083 LJIYEON
                    void AddColumn(string TableName, Dictionary<string, string> dicCol)
3052
                    {
3053
                        var colnames = connection.GetColumnNames(TableName);
3054
                        bool check = false;
3055
                        if (colnames != null)
3056
                        {
3057
                            foreach (KeyValuePair<string, string> col in dicCol)
3058
                            {
3059
                                check = false;
3060
                                foreach (string c in colnames)
3061
                                {
3062 7ad289b2 LJIYEON
                                    if (col.Key.ToUpper().Equals(c.ToUpper()))
3063 3d842083 LJIYEON
                                    {
3064
                                        check = true;
3065
                                        break;
3066
                                    }
3067
                                }
3068
3069
                                if (!check) //없으면 추가
3070
                                {
3071
                                    string i = string.Empty;
3072
                                    if (col.Value.ToString().ToUpper().Contains("INT") || col.Value.ToString().ToUpper().Contains("REAL"))
3073
                                        i = "DEFAULT 0";
3074
3075
                                    var query = $"ALTER TABLE " + TableName + " ADD [" + col.Key + "] " + col.Value + " " + i + ";";
3076
                                    using (var cmd = connection.GetSqlStringCommand(query))
3077
                                    {
3078
                                        cmd.ExecuteNonQuery();
3079
                                    }
3080
                                }
3081
                            }
3082
                        }
3083
                    }
3084
3085
                    result = true;
3086
                }
3087
                catch (Exception ex)
3088
                {
3089
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
3090
                }
3091
            }
3092
3093
            return result;
3094
        }
3095
3096 54b6df95 LJIYEON
        public static bool SaveAnotherRevision(string ProjectCode, int RevNumber, string UserName, string PSNDatabasePath, string PsnByPBSFilter, string PsnByNPDFilter,
3097
         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)
3098
        {
3099
            AnotherID2Info id2Info = AnotherID2Info.GetInstance();
3100
3101
            bool result = true;
3102
3103
            using (IAbstractDatabase connection = id2Info.CreateConnection())
3104
            {
3105
                try
3106
                {
3107
                    using (var txn = connection.BeginTransaction())
3108
                    {
3109
                        try
3110
                        {
3111
3112
                            var query = $"INSERT INTO ARS_COMMON.dbo.PSNRevision (OID, Project_OID, ProjectCode, RevNumber, UserName, TimeData, PSNDatabasePath, " +
3113
                                $"PsnByPBSFilter, PsnByNPDFilter, PidDrawings, PipeSystems, PipeLines, Topologies, PipeSystemNetworks, InValidPSNs, E2E, E2B, B2E, HDE, " +
3114 91c75c0b 이지연
                                $"HD2, HDB, B2B, LastModificationdate, ID2_PSN) VALUES (NEWID(), NEWID(), @ProjectCode, @RevNumber, @UserName, @TimeData, @PSNDatabasePath" +
3115 54b6df95 LJIYEON
                                $", @PsnByPBSFilter, @PsnByNPDFilter, @PidDrawings, @PipeSystems, @PipeLines, @Topologies, @PipeSystemNetworks, @InValidPSNs, " +
3116 91c75c0b 이지연
                                $"@E2E, @E2B, @B2E, @HDE, @HD2, @HDB, @B2B, @LastModificationdate, @ID2_PSN)";
3117 54b6df95 LJIYEON
                            var cmd = connection.GetSqlStringCommand(query);
3118
                            AddWithValue(cmd, "@OID", Guid.NewGuid().ToString());
3119
                            AddWithValue(cmd, "@Project_OID", Guid.NewGuid().ToString());
3120
                            AddWithValue(cmd, "@ProjectCode", ProjectCode);
3121
                            AddWithValue(cmd, "@RevNumber", RevNumber);
3122
                            AddWithValue(cmd, "@UserName", UserName);
3123
3124
                            System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US");
3125 d1afd412 이지연
                            DateTime oDateTime = DateTime.Now;
3126 54b6df95 LJIYEON
3127
                            AddWithValue(cmd, "@TimeData", oDateTime.ToString(ci)); //String.Format("{0:G}", dt) // DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
3128 d1afd412 이지연
3129 54b6df95 LJIYEON
                            AddWithValue(cmd, "@PSNDatabasePath", PSNDatabasePath);
3130
3131
                            AddWithValue(cmd, "@PsnByPBSFilter", PsnByPBSFilter);
3132
                            AddWithValue(cmd, "@PsnByNPDFilter", PsnByNPDFilter);
3133
                            AddWithValue(cmd, "@PidDrawings", PidDrawings);
3134
                            AddWithValue(cmd, "@PipeSystems", PipeSystems);
3135
                            AddWithValue(cmd, "@PipeLines", PipeLines);
3136
3137
                            AddWithValue(cmd, "@Topologies", Topologies);
3138
                            AddWithValue(cmd, "@PipeSystemNetworks", PipeSystemNetworks);
3139
                            AddWithValue(cmd, "@InValidPSNs", InValidPSNs);
3140
                            AddWithValue(cmd, "@E2E", E2E);
3141
                            AddWithValue(cmd, "@E2B", E2B);
3142
                            AddWithValue(cmd, "@B2E", B2E);
3143
                            AddWithValue(cmd, "@HDE", HDE);
3144
                            AddWithValue(cmd, "@HD2", HD2);
3145
                            AddWithValue(cmd, "@HDB", HDB);
3146
                            AddWithValue(cmd, "@B2B", B2B);
3147 7106e181 LJIYEON
3148
                            AddWithValue(cmd, "@LastModificationdate", oDateTime.ToString(ci));
3149 91c75c0b 이지연
                            AddWithValue(cmd, "@ID2_PSN", "Y");
3150 d1afd412 이지연
3151 54b6df95 LJIYEON
                            connection.ExecuteNonQuery(cmd, txn);
3152
3153
                            txn.Commit();
3154
                        }
3155
                        catch (Exception ex)
3156
                        {
3157
                            txn.Rollback();
3158
                            result = false;
3159
                        }
3160
                    }
3161
                }
3162
                catch (Exception ex)
3163
                {
3164
                    System.Windows.Forms.MessageBox.Show(ex.Message);
3165
                    result = false;
3166
                }
3167
            }
3168
3169
            return result;
3170
        }
3171
3172
        public static bool ConnAnotherCreateRevisionTable(Dictionary<string, string> dicColCheck, List<string> names)
3173
        {
3174
            bool result = false;
3175
            AnotherID2Info id2Info = AnotherID2Info.GetInstance();
3176
3177
            using (IAbstractDatabase connection = id2Info.CreateConnection())
3178
            {
3179
                try
3180
                {
3181
                    if (names.Count == 0)
3182
                    {
3183
3184
                        var query = $"CREATE TABLE ARS_COMMON.dbo.PSNRevision ([OID] [uniqueidentifier] ,[Project_OID] [uniqueidentifier] ," +
3185
                            $"[ProjectCode] nvarchar(255), [RevNumber] int ,[UserName] nvarchar(255) ,[TimeData] nvarchar(255) ," +
3186
                            $"[PSNDatabasePath] nvarchar(255) ,	[PsnByPBSFilter] varchar(20) ,[PsnByNPDFilter] varchar(20) ,[PidDrawings] int ,	" +
3187
                            $"[PipeSystems] int ,[PipeLines] int ,[Topologies] int ,[PipeSystemNetworks] int ,[InValidPSNs] int ,[E2E] int ," +
3188 91c75c0b 이지연
                            $"[E2B] int ,[B2E] int ,[HDE] int ,[HD2] int ,[HDB] int ,[B2B] int , [LastModificationdate] nvarchar(255), [ID2_PSN] nvarchar(10))";
3189 54b6df95 LJIYEON
                        using (var cmd = connection.GetSqlStringCommand(query))
3190
                        {
3191
                            cmd.ExecuteNonQuery();
3192
                        }
3193
                    }
3194
                    else
3195
                    {
3196
                        AddColumn(PSN_REVISION, dicColCheck, names);
3197
                    }
3198
3199
                    void AddColumn(string TableName, Dictionary<string, string> dicCol, List<string> colnames)
3200
                    {
3201
                        bool check = false;
3202
                        if (colnames != null)
3203
                        {
3204
                            foreach (KeyValuePair<string, string> col in dicCol)
3205
                            {
3206
                                check = false;
3207
                                foreach (string c in colnames)
3208
                                {
3209
                                    if (col.Key.Contains(c))
3210
                                    {
3211
                                        check = true;
3212
                                        break;
3213
                                    }
3214
                                }
3215
3216
                                if (!check) //없으면 추가
3217
                                {
3218
                                    string i = string.Empty;
3219
                                    if (col.Value.ToString().ToUpper().Contains("INT") || col.Value.ToString().ToUpper().Contains("REAL"))
3220
                                        i = "DEFAULT 0";
3221
3222
                                    var queryalter = $"ALTER TABLE ARS_COMMON.dbo.PSNRevision ADD [" + col.Key + "] " + col.Value + " " + i + ";";
3223
                                    using (var cmd = connection.GetSqlStringCommand(queryalter))
3224
                                    {
3225
                                        cmd.ExecuteNonQuery();
3226
                                    }
3227
                                }
3228
                            }
3229
                        }
3230
                    }
3231
3232
                    result = true;
3233
                }
3234
                catch (Exception ex)
3235
                {
3236
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
3237
                }
3238
            }
3239
3240
            return result;
3241
        }
3242
3243 7106e181 LJIYEON
        public static DataTable SelectAnotherRevision()
3244
        {
3245
            DataTable dt = null;
3246
            AnotherID2Info id2Info = AnotherID2Info.GetInstance();
3247
3248
            using (IAbstractDatabase connection = id2Info.CreateConnection())
3249
            {
3250
                try
3251
                {
3252
                    var query = $"SELECT * FROM ARS_COMMON.dbo.PSNREVISION";
3253
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 54b6df95 LJIYEON
        public static DataTable SelectAnotherRevisionTable()
3269
        {
3270
            DataTable dt = null;
3271
            AnotherID2Info id2Info = AnotherID2Info.GetInstance();
3272
3273
            using (IAbstractDatabase connection = id2Info.CreateConnection())
3274
            {
3275
                try
3276
                {
3277 7106e181 LJIYEON
                    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'";
3278 54b6df95 LJIYEON
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
3279
                    {
3280
                        dt = ds.Tables[0].Copy();
3281
                    }
3282
                }
3283
                catch (Exception ex)
3284
                {
3285
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
3286
                }
3287
            }
3288
3289
            return dt;
3290
        }
3291
3292 3d842083 LJIYEON
        public static bool SaveAnotherPSNData(PSN item, List<HeaderInfo> headerInfos, List<VentDrainInfo> ventDrainInfos,
3293 284fa2c9 이지연
          List<KeywordItem> keywordItems, DataTable dtTopologyRule, DataTable dtFluidCode, DataTable dtPMC, DataTable dtInsulation, DataTable dtvalvegrouping, DataTable dtnopocket, DataTable dtafc)
3294 3d842083 LJIYEON
        {
3295
            AnotherID2Info id2Info = AnotherID2Info.GetInstance();
3296
3297
            bool result = true;
3298
            using (IAbstractDatabase connection = id2Info.CreateConnection())
3299
            {
3300
                try
3301
                {
3302
                    using (var txn = connection.BeginTransaction())
3303
                    {
3304
                        try
3305
                        {
3306
                            // Path Items
3307
                            var query = $"DELETE FROM {PSN_PATHITEMS}";
3308
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3309
                            for (int i = 0; i < item.PathItems.Rows.Count; i++)
3310
                            {
3311
                                DataRow row = item.PathItems.Rows[i];
3312
                                query = $"INSERT INTO {PSN_PATHITEMS} " +
3313
                                    $"(OID, SequenceData_OID, TopologySet_OID, BranchTopologySet_OID, PipeLine_OID, ItemName, ItemTag, DESCRIPTION, CLASS, SUBCLASS, TYPE, " +
3314 bf9e8432 이지연
                                    $"PIDNAME, Equipment_OID, NPD, GROUPTAG, PipeSystemNetwork_OID, PipeRun_OID, ViewPipeSystemNetwork_OID, EqpGroupTag , MainLineTag, EGTConnectedPoint, EGFlowDirection ) VALUES " +
3315 811d7949 LJIYEON
                                    $"(@OID, @SequenceData_OID, @TopologySet_OID, @BranchTopologySet_OID, @PipeLine_OID, @ITEMNAME, @ITEMTAG, @DESCRIPTION, @Class, @SubClass, @TYPE, @PIDNAME," +
3316 bf9e8432 이지연
                                    $" @Equipment_OID, @NPD, @GROUPTAG, @PipeSystemNetwork_OID,@PipeRun_OID, @ViewPipeSystemNetwork_OID, @EqpGroupTag , @MainLineTag, @EGTConnectedPoint, @EGFlowDirection )";
3317 3d842083 LJIYEON
                                var cmd = connection.GetSqlStringCommand(query);
3318
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
3319
                                AddWithValue(cmd, "@SequenceData_OID", string.IsNullOrEmpty(row["SequenceData_OID"].ToString()) ? "" : row["SequenceData_OID"].ToString());
3320
                                AddWithValue(cmd, "@TopologySet_OID", string.IsNullOrEmpty(row["TopologySet_OID"].ToString()) ? "" : row["TopologySet_OID"].ToString());
3321
                                AddWithValue(cmd, "@BranchTopologySet_OID", string.IsNullOrEmpty(row["BranchTopologySet_OID"].ToString()) ? "" : row["BranchTopologySet_OID"].ToString());
3322
                                AddWithValue(cmd, "@PipeLine_OID", string.IsNullOrEmpty(row["PipeLine_OID"].ToString()) ? "" : row["PipeLine_OID"].ToString());
3323
                                AddWithValue(cmd, "@ITEMNAME", string.IsNullOrEmpty(row["ITEMNAME"].ToString()) ? "" : row["ITEMNAME"].ToString());
3324
                                AddWithValue(cmd, "@ITEMTAG", string.IsNullOrEmpty(row["ITEMTAG"].ToString()) ? "" : row["ITEMTAG"].ToString());
3325
                                AddWithValue(cmd, "@DESCRIPTION", string.IsNullOrEmpty(row["DESCRIPTION"].ToString()) ? "" : row["DESCRIPTION"].ToString());
3326
                                AddWithValue(cmd, "@Class", string.IsNullOrEmpty(row["Class"].ToString()) ? "" : row["Class"].ToString());
3327
                                AddWithValue(cmd, "@SubClass", string.IsNullOrEmpty(row["SubClass"].ToString()) ? "" : row["SubClass"].ToString());
3328
                                AddWithValue(cmd, "@TYPE", string.IsNullOrEmpty(row["TYPE"].ToString()) ? "" : row["TYPE"].ToString());
3329
                                AddWithValue(cmd, "@PIDNAME", string.IsNullOrEmpty(row["PIDNAME"].ToString()) ? "" : row["PIDNAME"].ToString());
3330
                                AddWithValue(cmd, "@Equipment_OID", string.IsNullOrEmpty(row["Equipment_OID"].ToString()) ? "" : row["Equipment_OID"].ToString());
3331
                                AddWithValue(cmd, "@NPD", string.IsNullOrEmpty(row["NPD"].ToString()) ? "" : row["NPD"].ToString());
3332 811d7949 LJIYEON
                                AddWithValue(cmd, "@GROUPTAG", string.IsNullOrEmpty(row["GROUPTAG"].ToString()) ? "" : row["GROUPTAG"].ToString());
3333 3d842083 LJIYEON
                                AddWithValue(cmd, "@PipeSystemNetwork_OID", string.IsNullOrEmpty(row["PipeSystemNetwork_OID"].ToString()) ? "" : row["PipeSystemNetwork_OID"].ToString());
3334
                                AddWithValue(cmd, "@ViewPipeSystemNetwork_OID", string.IsNullOrEmpty(row["ViewPipeSystemNetwork_OID"].ToString()) ? "" : row["ViewPipeSystemNetwork_OID"].ToString());
3335
                                AddWithValue(cmd, "@PipeRun_OID", string.IsNullOrEmpty(row["PipeRun_OID"].ToString()) ? "" : row["PipeRun_OID"].ToString());
3336 bf9e8432 이지연
                                AddWithValue(cmd, "@EqpGroupTag", string.IsNullOrEmpty(row["EqpGroupTag"].ToString()) ? "" : row["EqpGroupTag"].ToString());
3337
                                AddWithValue(cmd, "@MainLineTag", string.IsNullOrEmpty(row["MainLineTag"].ToString()) ? "" : row["MainLineTag"].ToString());
3338
                                AddWithValue(cmd, "@EGTConnectedPoint", string.IsNullOrEmpty(row["EGTConnectedPoint"].ToString()) ? "0" : row["EGTConnectedPoint"].ToString());
3339
                                AddWithValue(cmd, "@EGFlowDirection", string.IsNullOrEmpty(row["EGFlowDirection"].ToString()) ? "" : row["EGFlowDirection"].ToString());
3340
3341 3d842083 LJIYEON
                                connection.ExecuteNonQuery(cmd, txn);
3342
                            }
3343
3344
                            // Sequence
3345
                            query = $"DELETE FROM {PSN_SEQUENCEDATA}";
3346
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3347
                            foreach (DataRow row in item.SequenceData.Rows)
3348
                            {
3349
                                query = $"INSERT INTO {PSN_SEQUENCEDATA} (OID, SERIALNUMBER, PathItem_OID, TopologySet_OID_Key) VALUES (@OID, @SERIALNUMBER, @PathItem_OID, @TopologySet_OID_Key)";
3350
                                var cmd = connection.GetSqlStringCommand(query);
3351
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
3352
                                AddWithValue(cmd, "@SERIALNUMBER", string.IsNullOrEmpty(row["SERIALNUMBER"].ToString()) ? "" : row["SERIALNUMBER"].ToString());
3353
                                AddWithValue(cmd, "@PathItem_OID", string.IsNullOrEmpty(row["PathItem_OID"].ToString()) ? "" : row["PathItem_OID"].ToString());
3354
                                AddWithValue(cmd, "@TopologySet_OID_Key", string.IsNullOrEmpty(row["TopologySet_OID_Key"].ToString()) ? "" : row["TopologySet_OID_Key"].ToString());
3355
                                connection.ExecuteNonQuery(cmd, txn);
3356
                            }
3357
3358
                            // Nozzle
3359
                            query = $"DELETE FROM {PSN_NOZZLE}";
3360
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3361
                            foreach (DataRow row in item.Nozzle.Rows)
3362
                            {
3363
                                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)";
3364
                                var cmd = connection.GetSqlStringCommand(query);
3365
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
3366
                                AddWithValue(cmd, "@ITEMTAG", string.IsNullOrEmpty(row["ITEMTAG"].ToString()) ? "" : row["ITEMTAG"].ToString());
3367
3368
                                if (string.IsNullOrEmpty(row["XCOORDS"].ToString()))
3369
                                    AddWithValue(cmd, "@XCOORDS", DBNull.Value);
3370
                                else
3371
                                    AddWithValue(cmd, "@XCOORDS", row["XCOORDS"].ToString());
3372
3373
                                if (string.IsNullOrEmpty(row["YCOORDS"].ToString()))
3374
                                    AddWithValue(cmd, "@YCOORDS", DBNull.Value);
3375
                                else
3376
                                    AddWithValue(cmd, "@YCOORDS", row["YCOORDS"].ToString());
3377
3378
                                AddWithValue(cmd, "@Equipment_OID", string.IsNullOrEmpty(row["Equipment_OID"].ToString()) ? "" : row["Equipment_OID"].ToString());
3379
                                AddWithValue(cmd, "@FLUID", string.IsNullOrEmpty(row["FLUID"].ToString()) ? "" : row["FLUID"].ToString());
3380
                                AddWithValue(cmd, "@NPD", string.IsNullOrEmpty(row["NPD"].ToString()) ? "" : row["NPD"].ToString());
3381
                                AddWithValue(cmd, "@PMC", string.IsNullOrEmpty(row["PMC"].ToString()) ? "" : row["PMC"].ToString());
3382
3383
                                if (string.IsNullOrEmpty(row["ROTATION"].ToString()))
3384
                                    AddWithValue(cmd, "@ROTATION", DBNull.Value);
3385
                                else
3386
                                    AddWithValue(cmd, "@ROTATION", row["ROTATION"].ToString());
3387
3388
                                AddWithValue(cmd, "@FlowDirection", string.IsNullOrEmpty(row["FlowDirection"].ToString()) ? "" : row["FlowDirection"].ToString());
3389
                                connection.ExecuteNonQuery(cmd, txn);
3390
                            }
3391
3392
                            //Equipment
3393
                            query = $"DELETE FROM {PSN_EQUIPMENT}";
3394
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3395
                            foreach (DataRow row in item.Equipment.Rows)
3396
                            {
3397
                                query = $"INSERT INTO {PSN_EQUIPMENT} (OID, ItemTag, Xcoords, Ycoords) VALUES (@OID, @ITEMTAG, @XCOORDS, @YCOORDS)";
3398
                                var cmd = connection.GetSqlStringCommand(query);
3399
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
3400
                                AddWithValue(cmd, "@ITEMTAG", string.IsNullOrEmpty(row["ITEMTAG"].ToString()) ? "" : row["ITEMTAG"].ToString());
3401
3402
                                if (string.IsNullOrEmpty(row["XCOORDS"].ToString()))
3403
                                    AddWithValue(cmd, "@XCOORDS", DBNull.Value);
3404
                                else
3405
                                    AddWithValue(cmd, "@XCOORDS", row["XCOORDS"].ToString());
3406
3407
                                if (string.IsNullOrEmpty(row["YCOORDS"].ToString()))
3408
                                    AddWithValue(cmd, "@YCOORDS", DBNull.Value);
3409
                                else
3410
                                    AddWithValue(cmd, "@YCOORDS", row["YCOORDS"].ToString());
3411
3412
                                connection.ExecuteNonQuery(cmd, txn);
3413
                            }
3414
3415
                            // TopologySet
3416
                            query = $"DELETE FROM {PSN_TOPOLOGYSET}";
3417
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3418
                            foreach (DataRow row in item.TopologySet.Rows)
3419
                            {
3420
                                query = $"INSERT INTO {PSN_TOPOLOGYSET} (OID, Type, SubType, HeadItemTag, TailItemTag, HeadItemSPID, TailItemSPID) VALUES (@OID, @Type, @SubType, @HeadItemTag, @TailItemTag, @HeadItemSPID, @TailItemSPID)";
3421
                                var cmd = connection.GetSqlStringCommand(query);
3422
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
3423
                                AddWithValue(cmd, "@Type", string.IsNullOrEmpty(row["Type"].ToString()) ? "" : row["Type"].ToString());
3424
                                AddWithValue(cmd, "@SubType", string.IsNullOrEmpty(row["SubType"].ToString()) ? "" : row["SubType"].ToString());
3425
                                AddWithValue(cmd, "@HeadItemTag", string.IsNullOrEmpty(row["HeadItemTag"].ToString()) ? "" : row["HeadItemTag"].ToString());
3426
                                AddWithValue(cmd, "@TailItemTag", string.IsNullOrEmpty(row["TailItemTag"].ToString()) ? "" : row["TailItemTag"].ToString());
3427
                                AddWithValue(cmd, "@HeadItemSPID", string.IsNullOrEmpty(row["HeadItemSPID"].ToString()) ? "" : row["HeadItemSPID"].ToString());
3428
                                AddWithValue(cmd, "@TailItemSPID", string.IsNullOrEmpty(row["TailItemSPID"].ToString()) ? "" : row["TailItemSPID"].ToString());
3429
                                connection.ExecuteNonQuery(cmd, txn);
3430
                            }
3431
3432
                            // PSN
3433
                            query = $"DELETE FROM {PSN_PIPESYSTEMNETWORK} WHERE PSNRevisionNumber = '{string.Format("V{0:D4}", item.Revision)}'";
3434
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3435
                            foreach (DataRow row in item.PipeSystemNetwork.Rows)
3436
                            {
3437
                                query = $"INSERT INTO {PSN_PIPESYSTEMNETWORK} " +
3438 4842b66a 이지연
                                    $"(OID, Type, OrderNumber, Pipeline_OID, FROM_DATA, TO_DATA, TopologySet_OID_Key, PSNRevisionNumber, PBS, Drawings, IsValid, Status, IncludingVirtualData, PSNAccuracy, Pocket, EGTag, HasMLTags, GroundLevel) VALUES " +
3439
                                    $"(@OID, @Type, @OrderNumber, @Pipeline_OID, @FROM_DATA, @TO_DATA, @TopologySet_OID_Key, @PSNRevisionNumber,  @PBS, @Drawings, @IsValid, @Status, @IncludingVirtualData, @PSNAccuracy, @Pocket, @EGTag, @HasMLTags, @GroundLevel)";
3440 3d842083 LJIYEON
                                var cmd = connection.GetSqlStringCommand(query);
3441
                                AddWithValue(cmd, "@OID", string.IsNullOrEmpty(row["OID"].ToString()) ? "" : row["OID"].ToString());
3442
                                AddWithValue(cmd, "@Type", string.IsNullOrEmpty(row["Type"].ToString()) ? "" : row["Type"].ToString());
3443
                                AddWithValue(cmd, "@OrderNumber", string.IsNullOrEmpty(row["OrderNumber"].ToString()) ? "" : row["OrderNumber"].ToString());
3444
                                AddWithValue(cmd, "@Pipeline_OID", string.IsNullOrEmpty(row["Pipeline_OID"].ToString()) ? "" : row["Pipeline_OID"].ToString());
3445
                                AddWithValue(cmd, "@FROM_DATA", string.IsNullOrEmpty(row["FROM_DATA"].ToString()) ? "" : row["FROM_DATA"].ToString());
3446
                                AddWithValue(cmd, "@TO_DATA", string.IsNullOrEmpty(row["TO_DATA"].ToString()) ? "" : row["TO_DATA"].ToString());
3447
                                AddWithValue(cmd, "@TopologySet_OID_Key", string.IsNullOrEmpty(row["TopologySet_OID_Key"].ToString()) ? "" : row["TopologySet_OID_Key"].ToString());
3448
                                AddWithValue(cmd, "@PSNRevisionNumber", string.IsNullOrEmpty(row["PSNRevisionNumber"].ToString()) ? "" : row["PSNRevisionNumber"].ToString());
3449
3450
                                int IsValid = 0;
3451
                                if (row["IsValid"].ToString() == string.Empty || row["IsValid"].ToString() == "OK")
3452
                                    IsValid = 0;
3453
                                else if (row["IsValid"].ToString() == "InValid")
3454
                                    IsValid = 1;
3455
                                else if (row["IsValid"].ToString() == "Error")
3456
                                    IsValid = -1;
3457
3458
                                AddWithValue(cmd, "@IsValid", IsValid);
3459
                                AddWithValue(cmd, "@Status", string.IsNullOrEmpty(row["Status"].ToString()) ? "" : row["Status"].ToString());
3460
3461
                                AddWithValue(cmd, "@PBS", string.IsNullOrEmpty(row["PBS"].ToString()) ? "" : row["PBS"].ToString());
3462
                                AddWithValue(cmd, "@Drawings", string.IsNullOrEmpty(row["Drawings"].ToString()) ? "" : row["Drawings"].ToString());
3463
3464
                                AddWithValue(cmd, "@IncludingVirtualData", string.IsNullOrEmpty(row["IncludingVirtualData"].ToString()) ? "" : row["IncludingVirtualData"].ToString());
3465
                                if (string.IsNullOrEmpty(row["PSNAccuracy"].ToString()))
3466
                                    AddWithValue(cmd, "@PSNAccuracy", DBNull.Value);
3467
                                else
3468 d3fbf0c0 gaqhf
                                    AddWithValue(cmd, "@PSNAccuracy", row["PSNAccuracy"].ToString().Replace("%", ""));
3469 3d842083 LJIYEON
3470 08b33e44 gaqhf
                                AddWithValue(cmd, "@Pocket", string.IsNullOrEmpty(row["Pocket"].ToString()) ? "Yes" : row["Pocket"].ToString());
3471 d1afd412 이지연
                                AddWithValue(cmd, "@EGTag", string.IsNullOrEmpty(row["EGTag"].ToString()) ? "" : row["EGTag"].ToString());
3472
                                AddWithValue(cmd, "@HasMLTags", string.IsNullOrEmpty(row["HasMLTags"].ToString()) ? "False" : row["HasMLTags"].ToString());
3473 4842b66a 이지연
                                AddWithValue(cmd, "@GroundLevel", string.IsNullOrEmpty(row["GroundLevel"].ToString()) ? "" : row["GroundLevel"].ToString());
3474 3d842083 LJIYEON
                                connection.ExecuteNonQuery(cmd, txn);
3475
                            }
3476
3477
                            //Pipeline
3478
                            query = $"DELETE FROM {PSN_PIPELINE}";
3479
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3480
                            foreach (DataRow row in item.PipeLine.Rows)
3481
                            {
3482
                                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)";
3483
                                var cmd = connection.GetSqlStringCommand(query);
3484
                                AddWithValue(cmd, "@OID", row["OID"].ToString());
3485
                                AddWithValue(cmd, "@PipeSystem_OID", row["PipeSystem_OID"].ToString());
3486
                                AddWithValue(cmd, "@FLUID", row["FLUID"].ToString());
3487
                                AddWithValue(cmd, "@PMC", row["PMC"].ToString());
3488
                                AddWithValue(cmd, "@SEQNUMBER", row["SEQNUMBER"].ToString());
3489
                                AddWithValue(cmd, "@INSULATION", row["INSULATION"].ToString());
3490
                                AddWithValue(cmd, "@FROM_DATA", row["FROM_DATA"].ToString());
3491
                                AddWithValue(cmd, "@TO_DATA", row["TO_DATA"].ToString());
3492
                                AddWithValue(cmd, "@Unit", row["Unit"].ToString());
3493
                                connection.ExecuteNonQuery(cmd, txn);
3494
                            }
3495
3496 531fb158 LJIYEON
                            //PipeSystem
3497
                            query = $"DELETE FROM {PSN_PIPESYSTEM}";
3498
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3499
                            foreach (DataRow row in item.PipeSystem.Rows)
3500
                            {
3501
                                query = $"INSERT INTO {PSN_PIPESYSTEM} (OID, DESCRIPTION, FLUID, PMC, PipeLineQty, GroundLevel) VALUES (@OID, @DESCRIPTION, @FLUID, @PMC, @PipeLineQty, @GroundLevel)";
3502
                                var cmd = connection.GetSqlStringCommand(query);
3503
                                AddWithValue(cmd, "@OID", row["OID"].ToString());
3504
                                AddWithValue(cmd, "@DESCRIPTION", row["DESCRIPTION"].ToString());
3505
                                AddWithValue(cmd, "@FLUID", row["FLUID"].ToString());
3506
                                AddWithValue(cmd, "@PMC", row["PMC"].ToString());
3507
                                AddWithValue(cmd, "@PipeLineQty", row["PipeLineQty"].ToString());
3508
                                AddWithValue(cmd, "@GroundLevel", row["GroundLevel"].ToString());
3509
                                connection.ExecuteNonQuery(cmd, txn);
3510
                            }
3511
3512 3d842083 LJIYEON
                            //Header Setting
3513
                            query = $"DELETE FROM {PSN_HEADER_SETTING}";
3514
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3515
3516
                            foreach (HeaderInfo headerInfo in headerInfos)
3517
                            {
3518
                                foreach (HeaderItem itemheader in headerInfo.HeaderItems)
3519
                                {
3520
                                    query = $"INSERT INTO {PSN_HEADER_SETTING} (GROUP_ID, DESCRIPTION, [INDEX], NAME) VALUES (@GROUP_ID, @DESCRIPTION, @INDEX, @NAME)";
3521
                                    var cmd = connection.GetSqlStringCommand(query);
3522
                                    AddWithValue(cmd, "@GROUP_ID", headerInfo.UID);
3523
                                    AddWithValue(cmd, "@DESCRIPTION", headerInfo.Description);
3524
                                    AddWithValue(cmd, "@INDEX", itemheader.Index);
3525
                                    AddWithValue(cmd, "@NAME", itemheader.Name);
3526
                                    connection.ExecuteNonQuery(cmd, txn);
3527
                                }
3528
                            }
3529
3530
                            //Vent/Drain Setting
3531
                            query = $"DELETE FROM {PSN_VENTDRAIN_SETTING}";
3532
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3533
3534
                            foreach (VentDrainInfo ventDrainInfo in ventDrainInfos)
3535
                            {
3536
                                foreach (VentDrainItem itemventdrain in ventDrainInfo.VentDrainItems)
3537
                                {
3538
                                    query = $"INSERT INTO {PSN_VENTDRAIN_SETTING} (GROUP_ID, DESCRIPTION, [INDEX], NAME) VALUES (@GROUP_ID, @DESCRIPTION, @INDEX, @NAME)";
3539
                                    var cmd = connection.GetSqlStringCommand(query);
3540
                                    AddWithValue(cmd, "@GROUP_ID", ventDrainInfo.UID);
3541
                                    AddWithValue(cmd, "@DESCRIPTION", ventDrainInfo.Description);
3542
                                    AddWithValue(cmd, "@INDEX", itemventdrain.Index);
3543
                                    AddWithValue(cmd, "@NAME", itemventdrain.Name);
3544
                                    connection.ExecuteNonQuery(cmd, txn);
3545
                                }
3546
                            }
3547
3548
                            //Keyword Setting
3549
                            query = $"DELETE FROM {PSN_TRANSFORMKEYWORD_SETTING}";
3550
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3551
3552
                            foreach (KeywordItem itemKeyword in keywordItems)
3553
                            {
3554
                                query = $"INSERT INTO {PSN_TRANSFORMKEYWORD_SETTING} ([INDEX], NAME, KEYWORD) VALUES (@INDEX, @NAME, @KEYWORD)";
3555
                                var cmd = connection.GetSqlStringCommand(query);
3556
                                AddWithValue(cmd, "@INDEX", itemKeyword.Index);
3557
                                AddWithValue(cmd, "@NAME", itemKeyword.Name);
3558
                                AddWithValue(cmd, "@KEYWORD", itemKeyword.Keyword);
3559
                                connection.ExecuteNonQuery(cmd, txn);
3560
                            }
3561
3562
                            //FulidCode
3563
                            query = $"DELETE FROM {PSN_FLUIDCODE}";
3564
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3565
3566
                            foreach (DataRow row in dtFluidCode.Rows)
3567
                            {
3568
                                query = $"INSERT INTO {PSN_FLUIDCODE} (UID, Code, Description, Condition, Remarks, GroundLevel) VALUES (@UID, @Code, @Description, @Condition, @Remarks, @GroundLevel)";
3569
                                var cmd = connection.GetSqlStringCommand(query);
3570
                                cmd.Parameters.Clear();
3571
3572
                                {
3573
                                    var param = cmd.CreateParameter();
3574
                                    param.ParameterName = "@UID";
3575
                                    param.Value = row["UID"].ToString();
3576
                                    cmd.Parameters.Add(param);
3577
                                }
3578
3579
                                {
3580
                                    var param = cmd.CreateParameter();
3581
                                    param.ParameterName = "@Code";
3582
                                    param.Value = row["Code"].ToString();
3583
                                    cmd.Parameters.Add(param);
3584
                                }
3585
3586
                                {
3587
                                    var param = cmd.CreateParameter();
3588
                                    param.ParameterName = "@Description";
3589
                                    param.Value = row["Description"].ToString();
3590
                                    cmd.Parameters.Add(param);
3591
                                }
3592
3593
                                {
3594
                                    var param = cmd.CreateParameter();
3595
                                    param.ParameterName = "@Condition";
3596
                                    param.Value = row["Condition"].ToString();
3597
                                    cmd.Parameters.Add(param);
3598
                                }
3599
3600
                                {
3601
                                    var param = cmd.CreateParameter();
3602
                                    param.ParameterName = "@Remarks";
3603
                                    param.Value = row["Remarks"].ToString();
3604
                                    cmd.Parameters.Add(param);
3605
                                }
3606
3607
                                {
3608
                                    var param = cmd.CreateParameter();
3609
                                    param.ParameterName = "@GroundLevel";
3610
                                    param.Value = row["GroundLevel"].ToString();
3611
                                    cmd.Parameters.Add(param);
3612
                                }
3613
3614
                                connection.ExecuteNonQuery(cmd, txn);
3615
                            }
3616
3617
                            //PMC
3618
                            query = $"DELETE FROM {PSN_PIPINGMATLCLASS}";
3619
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3620
3621
                            foreach (DataRow row in dtPMC.Rows)
3622
                            {
3623
                                query = $"INSERT INTO {PSN_PIPINGMATLCLASS} ( UID, Priority, Code, Description, Condition, Remarks, GroundLevel) VALUES (@UID, @Priority, @Code, @Description, @Condition, @Remarks, @GroundLevel)";
3624
                                var cmd = connection.GetSqlStringCommand(query);
3625
                                cmd.Parameters.Clear();
3626
3627
                                {
3628
                                    var param = cmd.CreateParameter();
3629
                                    param.ParameterName = "@UID";
3630
                                    param.Value = row["UID"].ToString();
3631
                                    cmd.Parameters.Add(param);
3632
                                }
3633
3634
                                {
3635
                                    var param = cmd.CreateParameter();
3636
                                    param.ParameterName = "@Priority";
3637
                                    param.Value = row["Priority"].ToString();
3638
                                    cmd.Parameters.Add(param);
3639
                                }
3640
3641
                                {
3642
                                    var param = cmd.CreateParameter();
3643
                                    param.ParameterName = "@Code";
3644
                                    param.Value = row["Code"].ToString();
3645
                                    cmd.Parameters.Add(param);
3646
                                }
3647
3648
                                {
3649
                                    var param = cmd.CreateParameter();
3650
                                    param.ParameterName = "@Description";
3651
                                    param.Value = row["Description"].ToString();
3652
                                    cmd.Parameters.Add(param);
3653
                                }
3654
3655
                                {
3656
                                    var param = cmd.CreateParameter();
3657
                                    param.ParameterName = "@Condition";
3658
                                    param.Value = row["Condition"].ToString();
3659
                                    cmd.Parameters.Add(param);
3660
                                }
3661
3662
                                {
3663
                                    var param = cmd.CreateParameter();
3664
                                    param.ParameterName = "@Remarks";
3665
                                    param.Value = row["Remarks"].ToString();
3666
                                    cmd.Parameters.Add(param);
3667
                                }
3668
3669
                                {
3670
                                    var param = cmd.CreateParameter();
3671
                                    param.ParameterName = "@GroundLevel";
3672
                                    param.Value = row["GroundLevel"].ToString();
3673
                                    cmd.Parameters.Add(param);
3674
                                }
3675
3676
                                connection.ExecuteNonQuery(cmd, txn);
3677
                            }
3678
3679
                            //Insulation
3680
                            query = $"DELETE FROM {PSN_INSULATIONPURPOSE}";
3681
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3682
3683
                            foreach (DataRow row in dtInsulation.Rows)
3684
                            {
3685
                                query = $"INSERT INTO {PSN_INSULATIONPURPOSE} (UID, Code, Description, Remarks) VALUES (@UID, @Code, @Description, @Remarks)";
3686
                                var cmd = connection.GetSqlStringCommand(query);
3687
                                cmd.Parameters.Clear();
3688
3689
                                {
3690
                                    var param = cmd.CreateParameter();
3691
                                    param.ParameterName = "@UID";
3692
                                    param.Value = row["UID"].ToString();
3693
                                    cmd.Parameters.Add(param);
3694
                                }
3695
3696
                                {
3697
                                    var param = cmd.CreateParameter();
3698
                                    param.ParameterName = "@Code";
3699
                                    param.Value = row["Code"].ToString();
3700
                                    cmd.Parameters.Add(param);
3701
                                }
3702
3703
                                {
3704
                                    var param = cmd.CreateParameter();
3705
                                    param.ParameterName = "@Description";
3706
                                    param.Value = row["Description"].ToString();
3707
                                    cmd.Parameters.Add(param);
3708
                                }
3709
3710
                                {
3711
                                    var param = cmd.CreateParameter();
3712
                                    param.ParameterName = "@Remarks";
3713
                                    param.Value = row["Remarks"].ToString();
3714
                                    cmd.Parameters.Add(param);
3715
                                }
3716
3717
                                connection.ExecuteNonQuery(cmd, txn);
3718
                            }
3719
3720
                            //Topology Rule
3721
                            query = $"DELETE FROM {PSN_TOPOLOGY_RULE}";
3722
                            var cmdtopology = connection.GetSqlStringCommand(query);
3723
                            //connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3724
                            connection.ExecuteNonQuery(cmdtopology, txn);
3725
3726
                            foreach (DataRow row in dtTopologyRule.Rows)
3727
                            {
3728
                                query = $"INSERT INTO {PSN_TOPOLOGY_RULE} (UID) VALUES (@UID)";
3729
                                cmdtopology = connection.GetSqlStringCommand(query);
3730
                                AddWithValue(cmdtopology, "@UID", row["UID"].ToString());
3731
                                connection.ExecuteNonQuery(cmdtopology, txn);
3732
                            }
3733
3734 811d7949 LJIYEON
                            //valve grouping
3735
                            query = $"DELETE FROM {PSN_VALVEGROUP_SETTING}";
3736
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3737
3738
                            foreach (DataRow row in dtvalvegrouping.Rows)
3739
                            {
3740
                                query = $"INSERT INTO {PSN_VALVEGROUP_SETTING} (OID, GroupType, TagIdentifier, AttributeName, SppidSymbolName) " +
3741
                                    $"VALUES (@OID, @GroupType, @TagIdentifier, @AttributeName, @SppidSymbolName)";
3742
                                var cmd = connection.GetSqlStringCommand(query);
3743
                                AddWithValue(cmd, "@OID", row["OID"].ToString());
3744
                                AddWithValue(cmd, "@GroupType", row["GroupType"].ToString());
3745
                                AddWithValue(cmd, "@TagIdentifier", row["TagIdentifier"].ToString());
3746
                                AddWithValue(cmd, "@AttributeName", row["AttributeName"].ToString());
3747
                                AddWithValue(cmd, "@SppidSymbolName", row["SppidSymbolName"].ToString());
3748
                                connection.ExecuteNonQuery(cmd, txn);
3749
                            }
3750
3751 88c1965b gaqhf
                            //no pocket Setting
3752
                            query = $"DELETE FROM {PSN_NOPOCKETSETTING}";
3753
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3754
3755
                            foreach (DataRow row in dtnopocket.Rows)
3756
                            {
3757
                                query = $"INSERT INTO {PSN_NOPOCKETSETTING} ([INDEX], [TYPE], [NAME]) VALUES (@INDEX, @TYPE, @NAME)";
3758
                                var cmd = connection.GetSqlStringCommand(query);
3759
                                AddWithValue(cmd, "@INDEX", row["INDEX"].ToString());
3760
                                AddWithValue(cmd, "@TYPE", row["TYPE"].ToString());
3761
                                AddWithValue(cmd, "@NAME", row["NAME"].ToString());
3762
                                connection.ExecuteNonQuery(cmd, txn);
3763
                            }
3764
3765 f2a63376 이지연
                            //air fin cooler Setting
3766
                            query = $"DELETE FROM {PSN_AIRFINCOOLERSETTING}";
3767
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3768 284fa2c9 이지연
                             
3769
                            foreach (DataRow row in dtafc.Rows)
3770 f2a63376 이지연
                            {
3771 284fa2c9 이지연
                                query = $"INSERT INTO {PSN_AIRFINCOOLERSETTING} ([INDEX], [TYPE], [TagIdentifier], [AttributeName], [NAME]) VALUES (@INDEX, @TYPE, @TagIdentifier, @AttributeName, @NAME)";
3772 f2a63376 이지연
                                var cmd = connection.GetSqlStringCommand(query);
3773
                                AddWithValue(cmd, "@INDEX", row["INDEX"].ToString());
3774
                                AddWithValue(cmd, "@TYPE", row["TYPE"].ToString());
3775 284fa2c9 이지연
                                AddWithValue(cmd, "@TagIdentifier", row["TagIdentifier"].ToString());
3776
                                AddWithValue(cmd, "@AttributeName", row["AttributeName"].ToString());
3777 f2a63376 이지연
                                AddWithValue(cmd, "@NAME", row["NAME"].ToString());
3778
                                connection.ExecuteNonQuery(cmd, txn);
3779
                            }
3780 d1afd412 이지연
3781 f2a63376 이지연
3782 3d842083 LJIYEON
                            txn.Commit();
3783
                        }
3784
                        catch (Exception ex)
3785
                        {
3786
                            txn.Rollback();
3787
                            result = false;
3788
                        }
3789
                    }
3790
                }
3791
                catch (Exception ex)
3792
                {
3793
                    System.Windows.Forms.MessageBox.Show(ex.Message);
3794
                    result = false;
3795
                }
3796
            }
3797
3798
            return result;
3799
        }
3800 1d46fca7 LJIYEON
3801 54b6df95 LJIYEON
        public static bool CreatePSN_COMMON()
3802
        {
3803
            AnotherID2Info id2Info = AnotherID2Info.GetInstance();
3804
3805
            bool result = true;
3806
            using (IAbstractDatabase connection = id2Info.CreateConnection())
3807
            {
3808
                try
3809
                {
3810
                    using (var txn = connection.BeginTransaction())
3811
                    {
3812
                        try
3813
                        {
3814 d1afd412 이지연
3815 54b6df95 LJIYEON
                            var query = $"If(db_id(N'" + PSN_COMMON + "') IS NULL) CREATE DATABASE [" + PSN_COMMON + "]";
3816
                            if (id2Info.ID2DBType == AnotherID2DB_Type.MSSQL)
3817 d1afd412 이지연
                            {
3818 54b6df95 LJIYEON
                                connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
3819
                            }
3820
3821
                            txn.Commit();
3822
                        }
3823
                        catch (Exception ex)
3824
                        {
3825
                            txn.Rollback();
3826
                            result = false;
3827
                        }
3828
                    }
3829
                }
3830
                catch (Exception ex)
3831
                {
3832
                    System.Windows.Forms.MessageBox.Show(ex.Message);
3833
                    result = false;
3834
                }
3835
            }
3836
3837
            return result;
3838
        }
3839
    }
3840 0dae5645 gaqhf
}
3841 54b6df95 LJIYEON
클립보드 이미지 추가 (최대 크기: 500 MB)