프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / ID2PSN / DB.cs @ e17d4c6f

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