프로젝트

일반

사용자정보

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

hytos / DTI_PID / ID2PSN / DB.cs @ 2ada3be8

이력 | 보기 | 이력해설 | 다운로드 (63.8 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 45529c16 LJIYEON
using System.Data.SQLite;
6
using System.Linq;
7
using System.Text.RegularExpressions;
8 0dae5645 gaqhf
9
namespace ID2PSN
10
{
11 45529c16 LJIYEON
    public class DB
12 0dae5645 gaqhf
    {
13 6b9e7a56 gaqhf
        const string PSN_TOPOLOGY_RULE = "T_PSN_TOPOLOGY_RULE";
14
        const string PSN_HEADER_SETTING = "T_PSN_HEADER_SETTING";
15 36a45f13 gaqhf
        const string PSN_VENTDRAIN_SETTING = "T_PSN_VENTDRAIN_SETTING";
16 5dfc785c LJIYEON
        const string PSN_VIEW = "T_PSN_VIEW";
17 ddc1c369 LJIYEON
        const string PSN_TRANSFORMKEYWORD_SETTING = "T_PSN_TRANSFORMKEYWORD_SETTING"; 
18 5dfc785c LJIYEON
19 8f24b438 gaqhf
        const string PSN_PATHITEMS = "SPPIDPathItem";
20
        const string PSN_SEQUENCEDATA = "SPPIDSequenceData";
21
        const string PSN_PIPESYSTEMNETWORK = "SPPIDPipeSystemNetwork";
22
        const string PSN_EQUIPMENT = "SPPIDEquipment";
23
        const string PSN_NOZZLE = "SPPIDNozzle";
24
        const string PSN_FLUIDCODE = "SPPIDFluidCode";
25 45529c16 LJIYEON
        const string PSN_PIPINGMATLCLASS = "SPPIDPipingMatClass";
26 36a45f13 gaqhf
        const string PSN_TOPOLOGYSET = "SPPIDTopologySet";
27 abee404a LJIYEON
28 1ae1a1c6 LJIYEON
        /// <summary>
29
        ///  ID2 Project.db 데이터를 가져온다. 
30
        ///  DB 접속 정보 및 DBType (Sqlite, Mssql) 정보를 가져옴
31
        ///  - JY
32
        /// </summary>
33
        /// <returns></returns>
34
        public static DataTable GetProject()
35 757ab2f2 LJIYEON
        {
36 1ae1a1c6 LJIYEON
            DataTable dt = new DataTable();
37
            ID2Info id2Info = ID2Info.GetInstance();
38
            try
39
            {
40
                using (SQLiteConnection connection = new SQLiteConnection(@"Data Source = C:\ProgramData\Digital PID\Project.db", true))
41
                {
42
                    connection.Open();
43
                    if (connection.State.Equals(ConnectionState.Open))
44
                    {
45
                        using (SQLiteCommand cmd = connection.CreateCommand())
46
                        {
47
                            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]";
48
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
49
                                dt.Load(dr);
50
                        }
51
52
                    }
53
                    connection.Close();
54
                }
55
            }
56
            catch (Exception ex)
57
            {
58
                System.Windows.Forms.MessageBox.Show(ex.Message);
59
            }
60
61
            dt.AcceptChanges();
62
            dt.DefaultView.Sort = "Name";
63
            dt = dt.DefaultView.ToTable();
64 757ab2f2 LJIYEON
65 1ae1a1c6 LJIYEON
            return dt;
66
        }
67 757ab2f2 LJIYEON
68 1ae1a1c6 LJIYEON
        /// <summary>
69 c4a35107 humkyung
        ///  SQLite에 초기 DB 생성
70 1ae1a1c6 LJIYEON
        ///  - JY
71
        /// </summary>
72
        /// <returns></returns>
73 6b9e7a56 gaqhf
        public static bool ConnTestAndCreateTable()
74
        {
75
            bool result = false;
76
            ID2Info id2Info = ID2Info.GetInstance();
77 1ae1a1c6 LJIYEON
78 c4a35107 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection(ID2DB_Type.SQLite))
79 6b9e7a56 gaqhf
            {
80 0fe04b33 LJIYEON
                try
81 6b9e7a56 gaqhf
                {
82 23a96301 humkyung
                    var names = connection.GetTableNames();
83
                    var matched = names.FirstOrDefault(param => param == PSN_HEADER_SETTING);
84
                    if (matched == null)
85 6b9e7a56 gaqhf
                    {
86 23a96301 humkyung
                        var query = $"CREATE TABLE {PSN_HEADER_SETTING} (GROUP_ID TEXT, DESCRIPTION TEXT, [INDEX] INTEGER, NAME TEXT)";
87
                        using (var cmd = connection.GetSqlStringCommand(query))
88 6b9e7a56 gaqhf
                        {
89 23a96301 humkyung
                            cmd.ExecuteNonQuery();
90
                        }
91
                    }
92 757ab2f2 LJIYEON
93 23a96301 humkyung
                    matched = names.FirstOrDefault(param => param == PSN_VENTDRAIN_SETTING);
94
                    if (matched == null)
95
                    {
96
                        var query = $"CREATE TABLE {PSN_VENTDRAIN_SETTING} (GROUP_ID TEXT, DESCRIPTION TEXT, [INDEX] INTEGER, NAME TEXT)";
97
                        using (var cmd = connection.GetSqlStringCommand(query))
98
                        {
99
                            cmd.ExecuteNonQuery();
100
                        }
101
                    }
102 757ab2f2 LJIYEON
103 23a96301 humkyung
                    matched = names.FirstOrDefault(param => param == PSN_TOPOLOGY_RULE);
104
                    if (matched == null)
105
                    {
106
                        var query = $"CREATE TABLE {PSN_TOPOLOGY_RULE} (UID TEXT)";
107
                        using (var cmd = connection.GetSqlStringCommand(query))
108
                        {
109
                            cmd.ExecuteNonQuery();
110
                        }
111 757ab2f2 LJIYEON
112 23a96301 humkyung
                        DataTable topologyRule = new DataTable();
113
                        topologyRule.Columns.Add("NAME", typeof(string));
114 757ab2f2 LJIYEON
115 23a96301 humkyung
                        topologyRule.Rows.Add("FluidCode");
116
                        topologyRule.Rows.Add("-");
117
                        topologyRule.Rows.Add("PipingMaterialsClass");
118
                        topologyRule.Rows.Add("-");
119
                        topologyRule.Rows.Add("Tag Seq No");
120
121
                        SaveTopologyRule(topologyRule);
122
                    }
123
124
                    matched = names.FirstOrDefault(param => param == PSN_PATHITEMS);
125
                    if (matched == null)
126
                    {
127
                        var query = $"CREATE TABLE {PSN_PATHITEMS} (OID NVARCHAR(50), SequenceData_OID NVARCHAR(125), " +
128
                            "TopologySet_OID NVARCHAR(125), BranchTopologySet_OID NVARCHAR(125), PipeLine_OID NVARCHAR(125), ITEMNAME NVARCHAR(50), ITEMTAG NVARCHAR(125), " +
129
                            "Class NVARCHAR(80), SubClass NVARCHAR(80), TYPE NVARCHAR(80), PIDNAME NVARCHAR(10), NPD NVARCHAR(20), PipeSystemNetwork_OID NVARCHAR(20), " +
130
                            "ViewPipeSystemNetwork_OID NVARCHAR(255), PipeRun_OID NVARCHAR(255))";
131
                        using (var cmd = connection.GetSqlStringCommand(query))
132
                        {
133
                            cmd.ExecuteNonQuery();
134 757ab2f2 LJIYEON
                        }
135
                    }
136 23a96301 humkyung
137
                    matched = names.FirstOrDefault(param => param == PSN_SEQUENCEDATA);
138
                    if (matched == null)
139
                    {
140
                        var query = $"CREATE TABLE {PSN_SEQUENCEDATA} (OID NVARCHAR(125), SERIALNUMBER NVARCHAR(10), PathItem_OID NVARCHAR(50), TopologySet_OID_Key NVARCHAR(125))";
141
                        using (var cmd = connection.GetSqlStringCommand(query))
142
                        {
143
                            cmd.ExecuteNonQuery();
144
                        }
145
                    }
146
147
                    matched = names.FirstOrDefault(param => param == PSN_PIPESYSTEMNETWORK);
148
                    if (matched == null)
149
                    {
150
                        var query = $"CREATE TABLE {PSN_PIPESYSTEMNETWORK} (OID NVARCHAR(50), Type NVARCHAR(20), OrderNumber NVARCHAR(20), Pipeline_OID NVARCHAR(125), FROM_DATA NVARCHAR(255), " +
151
                            "TO_DATA NVARCHAR(255), TopologySet_OID_Key NVARCHAR(125), PSNRevisionNumber NVARCHAR(255), PBS NVARCHAR(255), PIDDrawings NVARCHAR(255), " +
152 ddc1c369 LJIYEON
                            "Validity INTEGER, Status NVARCHAR(255), IncludingVirtualData NVARCHAR(10),  PSNAccuracy REAL)";
153 23a96301 humkyung
                        using (var cmd = connection.GetSqlStringCommand(query))
154
                        {
155
                            cmd.ExecuteNonQuery();
156
                        }
157
                    }
158
159
                    matched = names.FirstOrDefault(param => param == PSN_EQUIPMENT);
160
                    if (matched == null)
161
                    {
162
                        var query = $"CREATE TABLE {PSN_EQUIPMENT} (OID NVARCHAR(50), ITEMTAG NVARCHAR(50), XCOORDS REAL, YCOORDS REAL)";
163
                        using (var cmd = connection.GetSqlStringCommand(query))
164
                        {
165
                            cmd.ExecuteNonQuery();
166
                        }
167
                    }
168
169
                    matched = names.FirstOrDefault(param => param == PSN_NOZZLE);
170
                    if (matched == null)
171
                    {
172
                        var query = $"CREATE TABLE {PSN_NOZZLE} (OID NVARCHAR(50), ITEMTAG NVARCHAR(50), XCOORDS REAL, YCOORDS REAL, Equipment_OID NVARCHAR(50), " +
173
                            "FLUID NVARCHAR(50), NPD NVARCHAR(20), ROTATION REAL, FlowDirection NVARCHAR(10))";
174
                        using (var cmd = connection.GetSqlStringCommand(query))
175
                        {
176
                            cmd.ExecuteNonQuery();
177
                        }
178
                    }
179
180
                    matched = names.FirstOrDefault(param => param == PSN_FLUIDCODE);
181
                    if (matched == null)
182
                    {
183
                        var query = $"CREATE TABLE {PSN_FLUIDCODE} (UID NVARCHAR(50), Code NVARCHAR(50), Description NVARCHAR(255), Condition NVARCHAR(50), Remarks NVARCHAR(255), GroundLevel NVARCHAR(50))";
184
                        using (var cmd = connection.GetSqlStringCommand(query))
185
                        {
186
                            cmd.ExecuteNonQuery();
187
                        }
188
                    }
189
190
                    matched = names.FirstOrDefault(param => param == PSN_PIPINGMATLCLASS);
191
                    if (matched == null)
192
                    {
193
                        var query = $"CREATE TABLE {PSN_PIPINGMATLCLASS} (UID NVARCHAR(50), Priority INTEGER, Code NVARCHAR(255), Description NVARCHAR(50), Condition NVARCHAR(255), Remarks NVARCHAR(80), GroundLevel NVARCHAR(50))";
194
                        using (var cmd = connection.GetSqlStringCommand(query))
195
                        {
196
                            cmd.ExecuteNonQuery();
197
                        }
198
                    }
199
200
                    matched = names.FirstOrDefault(param => param == PSN_VIEW);
201
                    if (matched == null)
202
                    {
203
                        var query = $"CREATE TABLE {PSN_VIEW} (OID TEXT)";
204
                        using (var cmd = connection.GetSqlStringCommand(query))
205
                        {
206
                            cmd.ExecuteNonQuery();
207
                        }
208
                    }
209
210
                    matched = names.FirstOrDefault(param => param == PSN_TOPOLOGYSET);
211
                    if (matched == null)
212
                    {
213
                        var query = $"CREATE TABLE {PSN_TOPOLOGYSET} (OID NVARCHAR(125), Type NVARCHAR(30), SubType NVARCHAR(30), HeadItemTag NVARCHAR(50), TailItemTag NVARCHAR(50), HeadItemID NVARCHAR(50), TailItemID NVARCHAR(50))";
214
                        using (var cmd = connection.GetSqlStringCommand(query))
215
                        {
216
                            cmd.ExecuteNonQuery();
217
                        }
218
                    }
219 ddc1c369 LJIYEON
                   
220
                    matched = names.FirstOrDefault(param => param == PSN_TRANSFORMKEYWORD_SETTING);
221
                    if (matched == null)
222
                    {
223 81bdaeed LJIYEON
                        var query = $"CREATE TABLE {PSN_TRANSFORMKEYWORD_SETTING} (GROUP_ID TEXT, DESCRIPTION TEXT, [INDEX] INTEGER, [NAME] TEXT, [KEYWORD] TEXT)";
224 ddc1c369 LJIYEON
                        using (var cmd = connection.GetSqlStringCommand(query))
225
                        {
226
                            cmd.ExecuteNonQuery();
227
                        }
228
                    }
229
230 23a96301 humkyung
                    result = true;
231 0fe04b33 LJIYEON
                }
232
                catch (Exception ex)
233
                {
234
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
235
                }
236 6b9e7a56 gaqhf
            }
237 45529c16 LJIYEON
238 6b9e7a56 gaqhf
            return result;
239
        }
240
241 1ae1a1c6 LJIYEON
        // ID2 DB 데이터
242 c4a35107 humkyung
        /// <summary>
243
        /// ID2 데이타베이스에서 OPC 데이터를 조회
244
        /// </summary>
245
        /// <returns></returns>
246 1ae1a1c6 LJIYEON
        public static DataTable SelectOPCRelations()
247 6b9e7a56 gaqhf
        {
248 23a96301 humkyung
            DataTable dt = null;
249 6b9e7a56 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
250 0fe04b33 LJIYEON
251 23a96301 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection())
252 6b9e7a56 gaqhf
            {
253 0fe04b33 LJIYEON
                try
254 6b9e7a56 gaqhf
                {
255 23a96301 humkyung
                    var query = "SELECT * FROM OPCRelations;";
256
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
257 757ab2f2 LJIYEON
                    {
258 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
259 6b9e7a56 gaqhf
                    }
260
                }
261 0fe04b33 LJIYEON
                catch (Exception ex)
262 36a45f13 gaqhf
                {
263 0fe04b33 LJIYEON
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
264
                }
265 36a45f13 gaqhf
            }
266 1ae1a1c6 LJIYEON
267 36a45f13 gaqhf
            return dt;
268
        }
269 6b9e7a56 gaqhf
270 c4a35107 humkyung
        /// <summary>
271
        /// ID2 데이타베이스에서 도면 데이터를 조회
272
        /// </summary>
273
        /// <returns></returns>
274 1ae1a1c6 LJIYEON
        public static DataTable SelectDrawings()
275 6b9e7a56 gaqhf
        {
276 23a96301 humkyung
            DataTable dt = null;
277 6b9e7a56 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
278 0fe04b33 LJIYEON
279 23a96301 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection())
280 6b9e7a56 gaqhf
            {
281 0fe04b33 LJIYEON
                try
282 6b9e7a56 gaqhf
                {
283 23a96301 humkyung
                    var query = "SELECT * FROM Drawings";
284
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
285 1ae1a1c6 LJIYEON
                    {
286 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
287 6b9e7a56 gaqhf
                    }
288
                }
289 0fe04b33 LJIYEON
                catch (Exception ex)
290 36a45f13 gaqhf
                {
291 0fe04b33 LJIYEON
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
292
                }
293 36a45f13 gaqhf
            }
294 1ae1a1c6 LJIYEON
295
            return dt;
296 36a45f13 gaqhf
        }
297 abee404a LJIYEON
298 1ae1a1c6 LJIYEON
        public static DataTable SelectLineProperties()
299 6b9e7a56 gaqhf
        {
300 23a96301 humkyung
            DataTable dt = null;
301 6b9e7a56 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
302 23a96301 humkyung
303
            using (IAbstractDatabase connection = id2Info.CreateConnection())
304 6b9e7a56 gaqhf
            {
305 0fe04b33 LJIYEON
                try
306 6b9e7a56 gaqhf
                {
307 23a96301 humkyung
                    var query = "SELECT * FROM LineProperties";
308
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
309 1ae1a1c6 LJIYEON
                    {
310 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
311 6b9e7a56 gaqhf
                    }
312
                }
313 0fe04b33 LJIYEON
                catch (Exception ex)
314 6b9e7a56 gaqhf
                {
315 0fe04b33 LJIYEON
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
316
                }
317 6b9e7a56 gaqhf
            }
318 0fe04b33 LJIYEON
319 6b9e7a56 gaqhf
            return dt;
320
        }
321 45529c16 LJIYEON
322 1ae1a1c6 LJIYEON
        public static DataTable SelectFluidCode()
323 6b9e7a56 gaqhf
        {
324 23a96301 humkyung
            DataTable dt = null;
325 6b9e7a56 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
326 0fe04b33 LJIYEON
327 23a96301 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection())
328 6b9e7a56 gaqhf
            {
329 0fe04b33 LJIYEON
                try
330 6b9e7a56 gaqhf
                {
331 23a96301 humkyung
                    var query = "SELECT * FROM FluidCode";
332 45529c16 LJIYEON
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
333 1ae1a1c6 LJIYEON
                    {
334 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
335 6b9e7a56 gaqhf
                    }
336
                }
337 0fe04b33 LJIYEON
                catch (Exception ex)
338 6b9e7a56 gaqhf
                {
339 0fe04b33 LJIYEON
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
340
                }
341 1ae1a1c6 LJIYEON
            }
342
343
            return dt;
344
        }
345
346
        public static DataTable SelectPipingMaterialsClass()
347
        {
348 23a96301 humkyung
            DataTable dt = null;
349 1ae1a1c6 LJIYEON
            ID2Info id2Info = ID2Info.GetInstance();
350 0fe04b33 LJIYEON
351 23a96301 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection())
352 1ae1a1c6 LJIYEON
            {
353 0fe04b33 LJIYEON
                try
354 6b9e7a56 gaqhf
                {
355 23a96301 humkyung
                    var query = "SELECT * FROM PipingMaterialsClass";
356
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
357 1ae1a1c6 LJIYEON
                    {
358 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
359 1ae1a1c6 LJIYEON
                    }
360
                }
361 0fe04b33 LJIYEON
                catch (Exception ex)
362 1ae1a1c6 LJIYEON
                {
363 0fe04b33 LJIYEON
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
364
                }
365 6b9e7a56 gaqhf
            }
366 1ae1a1c6 LJIYEON
367 6b9e7a56 gaqhf
            return dt;
368
        }
369
370 1ae1a1c6 LJIYEON
        public static DataTable SelectPSNPIPINGMATLCLASS()
371 6b9e7a56 gaqhf
        {
372 23a96301 humkyung
            DataTable dt = null;
373 6b9e7a56 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
374 0fe04b33 LJIYEON
375 c4a35107 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection(ID2DB_Type.SQLite))
376 1ae1a1c6 LJIYEON
            {
377 0fe04b33 LJIYEON
                try
378
                {
379 23a96301 humkyung
                    var query = $"SELECT * FROM {PSN_PIPINGMATLCLASS}";
380
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
381 1ae1a1c6 LJIYEON
                    {
382 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
383 1ae1a1c6 LJIYEON
                    }
384 0fe04b33 LJIYEON
                }
385
                catch (Exception ex)
386
                {
387
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
388
                }
389 1ae1a1c6 LJIYEON
            }
390
391
            return dt;
392
        }
393
394
        public static DataTable SelectNominalDiameter()
395
        {
396 23a96301 humkyung
            DataTable dt = null;
397 1ae1a1c6 LJIYEON
            ID2Info id2Info = ID2Info.GetInstance();
398 0fe04b33 LJIYEON
399 23a96301 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection())
400 1ae1a1c6 LJIYEON
            {
401 0fe04b33 LJIYEON
                try
402 6b9e7a56 gaqhf
                {
403 23a96301 humkyung
                    var query = "SELECT * FROM NominalDiameter ORDER BY Metric DESC";
404
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
405 1ae1a1c6 LJIYEON
                    {
406 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
407 1ae1a1c6 LJIYEON
                    }
408 6b9e7a56 gaqhf
                }
409 0fe04b33 LJIYEON
                catch (Exception ex)
410 1ae1a1c6 LJIYEON
                {
411 0fe04b33 LJIYEON
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
412
                }
413 1ae1a1c6 LJIYEON
            }
414
415 c4a35107 humkyung
            ///TODO: need to check below code
416 1ae1a1c6 LJIYEON
            dt.Rows.RemoveAt(0);
417
            dt.Rows.RemoveAt(0);
418
            dt.Rows.RemoveAt(0);
419
            dt.Rows.RemoveAt(0);
420
421 6b9e7a56 gaqhf
            return dt;
422
        }
423 abee404a LJIYEON
424 1ae1a1c6 LJIYEON
        public static DataTable SelectSymbolAttribute()
425 6b9e7a56 gaqhf
        {
426 23b86f8b LJIYEON
            DataTable dt = null;
427 6b9e7a56 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
428 0fe04b33 LJIYEON
429 23a96301 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection())
430 6b9e7a56 gaqhf
            {
431 0fe04b33 LJIYEON
                try
432 6b9e7a56 gaqhf
                {
433 23b86f8b LJIYEON
                   // var query = "SELECT DISTINCT Attribute, DisplayAttribute FROM SymbolAttribute;";
434 502d1d50 LJIYEON
                    var query = "SELECT DISTINCT Attribute FROM SymbolAttribute;";
435 23a96301 humkyung
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
436 1ae1a1c6 LJIYEON
                    {
437 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
438 1ae1a1c6 LJIYEON
                    }
439
                }
440 0fe04b33 LJIYEON
                catch (Exception ex)
441 1ae1a1c6 LJIYEON
                {
442 0fe04b33 LJIYEON
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
443
                }
444 1ae1a1c6 LJIYEON
            }
445 0fe04b33 LJIYEON
446 1ae1a1c6 LJIYEON
            return dt;
447
        }
448
449
        public static DataTable SelectSymbolName()
450
        {
451 23a96301 humkyung
            DataTable dt = null;
452 1ae1a1c6 LJIYEON
            ID2Info id2Info = ID2Info.GetInstance();
453 0fe04b33 LJIYEON
454 23a96301 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection())
455 1ae1a1c6 LJIYEON
            {
456 0fe04b33 LJIYEON
                try
457 1ae1a1c6 LJIYEON
                {
458 23a96301 humkyung
                    var query = "SELECT * FROM SymbolName;";
459
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
460 1ae1a1c6 LJIYEON
                    {
461 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
462 1ae1a1c6 LJIYEON
                    }
463
                }
464 0fe04b33 LJIYEON
                catch (Exception ex)
465 1ae1a1c6 LJIYEON
                {
466 0fe04b33 LJIYEON
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
467
                }
468 1ae1a1c6 LJIYEON
            }
469 0fe04b33 LJIYEON
470 1ae1a1c6 LJIYEON
            return dt;
471 45529c16 LJIYEON
        }
472 1ae1a1c6 LJIYEON
473
        public static double[] GetDrawingSize()
474
        {
475
            double[] result = null;
476
477
            ID2Info id2Info = ID2Info.GetInstance();
478 23a96301 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection())
479 1ae1a1c6 LJIYEON
            {
480 0fe04b33 LJIYEON
                try
481 1ae1a1c6 LJIYEON
                {
482 d36e2fe0 esham21
                    var query = "SELECT value FROM Configuration WHERE Section = 'Area' AND [Key] = 'Drawing';";
483 23a96301 humkyung
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
484 1ae1a1c6 LJIYEON
                    {
485 23a96301 humkyung
                        if (ds.Tables[0].Rows.Count == 1)
486 0fe04b33 LJIYEON
                        {
487 23a96301 humkyung
                            string value = ds.Tables[0].Rows[0][0].ToString();
488 0fe04b33 LJIYEON
                            string[] split = value.Split(new char[] { ',' });
489
                            result = new double[] {
490 45529c16 LJIYEON
                                Convert.ToDouble(Regex.Replace(split[0], @"[^0-9]", string.Empty)),
491
                                Convert.ToDouble(Regex.Replace(split[1], @"[^0-9]", string.Empty)),
492
                                Convert.ToDouble(Regex.Replace(split[2], @"[^0-9]", string.Empty)),
493
                                Convert.ToDouble(Regex.Replace(split[3], @"[^0-9]", string.Empty))
494 1ae1a1c6 LJIYEON
                                };
495 0fe04b33 LJIYEON
                            result = new double[] {
496 1ae1a1c6 LJIYEON
                                Math.Min(result[0], result[2]),
497
                                Math.Min(result[1], result[3]),
498
                                Math.Max(result[0], result[2]),
499
                                Math.Max(result[1], result[3])
500
                                };
501
                        }
502
                    }
503
                }
504 0fe04b33 LJIYEON
                catch (Exception ex)
505 1ae1a1c6 LJIYEON
                {
506 0fe04b33 LJIYEON
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
507
                }
508 1ae1a1c6 LJIYEON
            }
509
510
            return result;
511
        }
512
513
        public static DataTable GetEquipmentType()
514
        {
515 23a96301 humkyung
            DataTable dt = null;
516 1ae1a1c6 LJIYEON
            ID2Info id2Info = ID2Info.GetInstance();
517 0fe04b33 LJIYEON
518 23a96301 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection())
519 1ae1a1c6 LJIYEON
            {
520 0fe04b33 LJIYEON
                try
521 1ae1a1c6 LJIYEON
                {
522 23a96301 humkyung
                    var query = "SELECT Type FROM SymbolType WHERE Category = 'Equipment';";
523
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
524 1ae1a1c6 LJIYEON
                    {
525 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
526 1ae1a1c6 LJIYEON
                    }
527
                }
528 0fe04b33 LJIYEON
                catch (Exception ex)
529 1ae1a1c6 LJIYEON
                {
530 0fe04b33 LJIYEON
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
531
                }
532 6b9e7a56 gaqhf
            }
533 0fe04b33 LJIYEON
534 6b9e7a56 gaqhf
            return dt;
535
        }
536 abee404a LJIYEON
537 1ae1a1c6 LJIYEON
        /// <summary>
538
        ///  Zoom 을 위하여 저장 T_PSN_VIEW 데이터로 PSN 데이터지만 Msqql 과 Sqlite 둘다 저장되어 있음
539
        ///  => ID2 가 DB 타입에 따라서 바라보는 DB가 mssql이냐 sqlite냐로 지정되기 때문에 zoom 기능을 그대로 사용하려면 해당 데이터는 psn도 id2 dbtype에 맞춰서 저장 및 로드해야함
540 c4a35107 humkyung
        ///  => 더 이상 사용하지 않음
541 1ae1a1c6 LJIYEON
        /// </summary>
542
        /// <param name="values"></param>
543
        /// <returns></returns>
544
        public static bool SaveView(List<string> values)
545 6b9e7a56 gaqhf
        {
546
            ID2Info id2Info = ID2Info.GetInstance();
547 1ae1a1c6 LJIYEON
548
            bool result = true;
549
550 23a96301 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection())
551
            {
552
                try
553 6b9e7a56 gaqhf
                {
554 23a96301 humkyung
                    using (var txn = connection.BeginTransaction())
555 6b9e7a56 gaqhf
                    {
556 23a96301 humkyung
                        try
557 6b9e7a56 gaqhf
                        {
558 23a96301 humkyung
                            var query = $"DELETE FROM {PSN_VIEW}";
559
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
560
561
                            foreach (string value in values)
562 1ae1a1c6 LJIYEON
                            {
563 23a96301 humkyung
                                query = $"INSERT INTO {PSN_VIEW} VALUES (@OID)";
564
                                var cmd = connection.GetSqlStringCommand(query);
565
                                AddWithValue(cmd, "@OID", value);
566
                                connection.ExecuteNonQuery(cmd, txn);
567 1ae1a1c6 LJIYEON
                            }
568 23a96301 humkyung
                            txn.Commit();
569
                        }
570
                        catch (Exception ex)
571
                        {
572
                            txn.Rollback();
573
                            result = false;
574 6b9e7a56 gaqhf
                        }
575 1ae1a1c6 LJIYEON
                    }
576 6b9e7a56 gaqhf
                }
577 23a96301 humkyung
                catch (Exception ex)
578
                {
579
                    System.Windows.Forms.MessageBox.Show(ex.Message);
580
                    result = false;
581
                }
582
            }
583
584 1ae1a1c6 LJIYEON
            return result;
585 6b9e7a56 gaqhf
        }
586
587 1ae1a1c6 LJIYEON
        public static bool DeleteView()
588 6b9e7a56 gaqhf
        {
589
            ID2Info id2Info = ID2Info.GetInstance();
590 1ae1a1c6 LJIYEON
591
            bool result = true;
592 23a96301 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection())
593
            {
594
                try
595 6b9e7a56 gaqhf
                {
596 23a96301 humkyung
                    using (var txn = connection.BeginTransaction())
597 6b9e7a56 gaqhf
                    {
598 23a96301 humkyung
                        try
599 1ae1a1c6 LJIYEON
                        {
600 23a96301 humkyung
                            var query = $"DELETE FROM {PSN_VIEW}";
601
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
602
                            txn.Commit();
603
                        }
604
                        catch (Exception ex)
605
                        {
606
                            txn.Rollback();
607
                            result = false;
608 1ae1a1c6 LJIYEON
                        }
609 6b9e7a56 gaqhf
                    }
610
                }
611 23a96301 humkyung
                catch (Exception ex)
612
                {
613
                    System.Windows.Forms.MessageBox.Show(ex.Message);
614
                    result = false;
615
                }
616
            }
617 1ae1a1c6 LJIYEON
618
            return result;
619 6b9e7a56 gaqhf
        }
620 abee404a LJIYEON
621 1ae1a1c6 LJIYEON
        //PSN Sqlite 
622
        public static DataTable SelectHeaderSetting()
623 6b9e7a56 gaqhf
        {
624 23a96301 humkyung
            DataTable dt = null;
625 6b9e7a56 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
626 1ae1a1c6 LJIYEON
627 c4a35107 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection(ID2DB_Type.SQLite))
628 6b9e7a56 gaqhf
            {
629
                try
630
                {
631 23a96301 humkyung
                    var query = $@"SELECT GROUP_ID, DESCRIPTION, [INDEX], NAME FROM {PSN_HEADER_SETTING};";
632
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
633 6b9e7a56 gaqhf
                    {
634 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
635 6b9e7a56 gaqhf
                    }
636
                }
637
                catch (Exception ex)
638
                {
639
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
640
                }
641
            }
642 1ae1a1c6 LJIYEON
643 6b9e7a56 gaqhf
            return dt;
644
        }
645
646 1ae1a1c6 LJIYEON
        public static DataTable SelectVentDrainSetting()
647 6b9e7a56 gaqhf
        {
648 23a96301 humkyung
            DataTable dt = null;
649 6b9e7a56 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
650 23a96301 humkyung
651 c4a35107 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection(ID2DB_Type.SQLite))
652 6b9e7a56 gaqhf
            {
653
                try
654
                {
655 23a96301 humkyung
                    var query = $@"SELECT GROUP_ID, DESCRIPTION, [INDEX], NAME FROM {PSN_VENTDRAIN_SETTING};";
656
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
657 6b9e7a56 gaqhf
                    {
658 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
659 6b9e7a56 gaqhf
                    }
660
                }
661
                catch (Exception ex)
662
                {
663
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
664
                }
665
            }
666 23a96301 humkyung
667 6b9e7a56 gaqhf
            return dt;
668
        }
669 abee404a LJIYEON
670 ddc1c369 LJIYEON
        public static DataTable SelectKeywordsSetting()
671
        {
672
            DataTable dt = null;
673
            ID2Info id2Info = ID2Info.GetInstance();
674
675
            using (IAbstractDatabase connection = id2Info.CreateConnection(ID2DB_Type.SQLite))
676
            {
677
                try
678
                {
679 81bdaeed LJIYEON
                    var query = $@"SELECT GROUP_ID, DESCRIPTION, [INDEX], [NAME], [KEYWORD] FROM {PSN_TRANSFORMKEYWORD_SETTING};";
680 ddc1c369 LJIYEON
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
681
                    {
682
                        dt = ds.Tables[0].Copy();
683
                    }
684
                }
685
                catch (Exception ex)
686
                {
687
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
688
                }
689
            }
690
691
            return dt;
692
        }
693
694 1ae1a1c6 LJIYEON
        public static bool SaveHeaderSetting(List<HeaderInfo> headerInfos)
695 6b9e7a56 gaqhf
        {
696
            ID2Info id2Info = ID2Info.GetInstance();
697 c4a35107 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection(ID2DB_Type.SQLite))
698 6b9e7a56 gaqhf
            {
699
                try
700
                {
701 23a96301 humkyung
                    using (var txn = connection.BeginTransaction())
702 6b9e7a56 gaqhf
                    {
703 23a96301 humkyung
                        var query = $"DELETE FROM {PSN_HEADER_SETTING}";
704
                        connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
705 1ae1a1c6 LJIYEON
706
                        foreach (HeaderInfo headerInfo in headerInfos)
707
                        {
708
                            foreach (HeaderItem item in headerInfo.HeaderItems)
709
                            {
710 23a96301 humkyung
                                query = $"INSERT INTO {PSN_HEADER_SETTING} VALUES (@GROUP_ID, @DESCRIPTION, @INDEX, @NAME)";
711
                                var cmd = connection.GetSqlStringCommand(query);
712
                                AddWithValue(cmd, "@GROUP_ID", headerInfo.UID);
713
                                AddWithValue(cmd, "@DESCRIPTION", headerInfo.Description);
714
                                AddWithValue(cmd, "@INDEX", item.Index);
715
                                AddWithValue(cmd, "@NAME", item.Name);
716
                                connection.ExecuteNonQuery(cmd, txn);
717 1ae1a1c6 LJIYEON
                            }
718
                        }
719 81bdaeed LJIYEON
                        txn.Commit();
720 6b9e7a56 gaqhf
                    }
721 81bdaeed LJIYEON
                    
722 6b9e7a56 gaqhf
                }
723
                catch (Exception ex)
724
                {
725
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
726 1ae1a1c6 LJIYEON
                    return false;
727 6b9e7a56 gaqhf
                }
728
            }
729 1ae1a1c6 LJIYEON
            return true;
730 6b9e7a56 gaqhf
        }
731 abee404a LJIYEON
732 1ae1a1c6 LJIYEON
        public static bool SaveVentDrainSetting(List<VentDrainInfo> ventDrainInfos)
733 6b9e7a56 gaqhf
        {
734
            ID2Info id2Info = ID2Info.GetInstance();
735 c4a35107 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection(ID2DB_Type.SQLite))
736 6b9e7a56 gaqhf
            {
737 23a96301 humkyung
                using (var txn = connection.BeginTransaction())
738 6b9e7a56 gaqhf
                {
739 23a96301 humkyung
                    try
740 6b9e7a56 gaqhf
                    {
741 23a96301 humkyung
                        var query = $"DELETE FROM {PSN_VENTDRAIN_SETTING}";
742
                        connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
743 1ae1a1c6 LJIYEON
744
                        foreach (VentDrainInfo ventDrainInfo in ventDrainInfos)
745
                        {
746
                            foreach (VentDrainItem item in ventDrainInfo.VentDrainItems)
747
                            {
748 23a96301 humkyung
                                query = $"INSERT INTO {PSN_VENTDRAIN_SETTING} VALUES (@GROUP_ID, @DESCRIPTION, @INDEX, @NAME)";
749
                                var cmd = connection.GetSqlStringCommand(query);
750
                                AddWithValue(cmd, "@GROUP_ID", ventDrainInfo.UID);
751
                                AddWithValue(cmd, "@DESCRIPTION", ventDrainInfo.Description);
752
                                AddWithValue(cmd, "@INDEX", item.Index);
753
                                AddWithValue(cmd, "@NAME", item.Name);
754
                                connection.ExecuteNonQuery(cmd, txn);
755 1ae1a1c6 LJIYEON
                            }
756
                        }
757 81bdaeed LJIYEON
758
                        txn.Commit();
759 6b9e7a56 gaqhf
                    }
760 23a96301 humkyung
                    catch (Exception ex)
761
                    {
762
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
763
                        return false;
764
                    }
765 6b9e7a56 gaqhf
                }
766
            }
767 23a96301 humkyung
768 1ae1a1c6 LJIYEON
            return true;
769 6b9e7a56 gaqhf
        }
770 abee404a LJIYEON
771 ddc1c369 LJIYEON
        public static bool SaveKeywordsSetting(List<KeywordInfo> keywordInfos)
772
        {
773
            ID2Info id2Info = ID2Info.GetInstance();
774
            using (IAbstractDatabase connection = id2Info.CreateConnection(ID2DB_Type.SQLite))
775
            {
776
                using (var txn = connection.BeginTransaction())
777
                {
778
                    try
779
                    {
780 81bdaeed LJIYEON
                        var query = $"DELETE FROM {PSN_TRANSFORMKEYWORD_SETTING}";
781 ddc1c369 LJIYEON
                        connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
782
783
                        foreach (KeywordInfo keywordInfo in keywordInfos)
784
                        {
785 81bdaeed LJIYEON
                            foreach (KeywordItem item in keywordInfo.KeywordItems)
786 ddc1c369 LJIYEON
                            {
787 81bdaeed LJIYEON
                                query = $"INSERT INTO {PSN_TRANSFORMKEYWORD_SETTING} VALUES (@GROUP_ID, @DESCRIPTION, @INDEX, @NAME, @KEYWORD)";
788 ddc1c369 LJIYEON
                                var cmd = connection.GetSqlStringCommand(query);
789 81bdaeed LJIYEON
                                AddWithValue(cmd, "@GROUP_ID", keywordInfo.UID);
790
                                AddWithValue(cmd, "@DESCRIPTION", keywordInfo.Description);
791
                                AddWithValue(cmd, "@INDEX", item.Index);
792
                                AddWithValue(cmd, "@NAME", item.Name);
793
                                AddWithValue(cmd, "@KEYWORD", item.Keyword);
794 ddc1c369 LJIYEON
                                connection.ExecuteNonQuery(cmd, txn);
795
                            }
796
                        }
797 81bdaeed LJIYEON
                        txn.Commit();
798 ddc1c369 LJIYEON
                    }
799
                    catch (Exception ex)
800
                    {
801
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
802
                        return false;
803
                    }
804
                }
805
            }
806
807
            return true;
808
        }
809
810 1ae1a1c6 LJIYEON
        public static bool SaveTopologyRule(DataTable dt)
811 c6503eaa gaqhf
        {
812
            ID2Info id2Info = ID2Info.GetInstance();
813 c4a35107 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection(ID2DB_Type.SQLite))
814 c6503eaa gaqhf
            {
815 23a96301 humkyung
                using (var txn = connection.BeginTransaction())
816 c6503eaa gaqhf
                {
817 23a96301 humkyung
                    try
818 c6503eaa gaqhf
                    {
819 23a96301 humkyung
                        var query = $"DELETE FROM {PSN_TOPOLOGY_RULE}";
820
                        var cmd = connection.GetSqlStringCommand(query);
821 1ae1a1c6 LJIYEON
                        cmd.ExecuteNonQuery();
822
823
                        foreach (DataRow row in dt.Rows)
824
                        {
825 23a96301 humkyung
                            query = $"INSERT INTO {PSN_TOPOLOGY_RULE} VALUES (@UID)";
826
                            cmd = connection.GetSqlStringCommand(query);
827
                            AddWithValue(cmd, "@UID", row["NAME"].ToString());
828
                            connection.ExecuteNonQuery(cmd, txn);
829 1ae1a1c6 LJIYEON
                        }
830 23a96301 humkyung
831
                        txn.Commit();
832
                    }
833
                    catch (Exception ex)
834
                    {
835
                        txn.Rollback();
836
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
837
                        return false;
838 c6503eaa gaqhf
                    }
839
                }
840
            }
841 23a96301 humkyung
842 1ae1a1c6 LJIYEON
            return true;
843 c6503eaa gaqhf
        }
844 abee404a LJIYEON
845 1ae1a1c6 LJIYEON
        public static DataTable SelectTopologyRule()
846 7881ec8f gaqhf
        {
847 23a96301 humkyung
            DataTable dt = null;
848
849 7881ec8f gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
850 c4a35107 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection(ID2DB_Type.SQLite))
851 7881ec8f gaqhf
            {
852
                try
853
                {
854 23a96301 humkyung
                    var query = $"SELECT * FROM {PSN_TOPOLOGY_RULE}";
855
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
856 7881ec8f gaqhf
                    {
857 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
858 7881ec8f gaqhf
                    }
859
                }
860
                catch (Exception ex)
861
                {
862
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
863
                }
864
            }
865 23a96301 humkyung
866 7881ec8f gaqhf
            return dt;
867
        }
868 45529c16 LJIYEON
869 23a96301 humkyung
        private static void AddWithValue(DbCommand cmd, string PropName, object Value)
870
        {
871
            var param = cmd.CreateParameter();
872
            param.ParameterName = PropName;
873
            param.Value = Value;
874
            cmd.Parameters.Add(param);
875
        }
876
877 5c248ee3 gaqhf
        public static bool SavePSNData(PSN item)
878 6b9e7a56 gaqhf
        {
879
            ID2Info id2Info = ID2Info.GetInstance();
880
881
            bool result = true;
882 c4a35107 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection(ID2DB_Type.SQLite))
883 6b9e7a56 gaqhf
            {
884
                try
885
                {
886 23a96301 humkyung
                    using (var txn = connection.BeginTransaction())
887 6b9e7a56 gaqhf
                    {
888
                        try
889
                        {
890 23a96301 humkyung
                            // Path Items
891
                            var query = $"DELETE FROM {PSN_PATHITEMS}";
892
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
893
                            foreach (DataRow row in item.PathItems.Rows)
894 6b9e7a56 gaqhf
                            {
895 23a96301 humkyung
                                query = $"INSERT INTO {PSN_PATHITEMS} VALUES (@OID, @SequenceData_OID, @TopologySet_OID, @BranchTopologySet_OID, @PipeLine_OID, @ITEMNAME, @ITEMTAG, @Class, @SubClass, @TYPE, @PIDNAME, @NPD, @PipeSystemNetwork_OID, @ViewPipeSystemNetwork_OID, @PipeRun_OID)";
896
                                var cmd = connection.GetSqlStringCommand(query);
897
                                AddWithValue(cmd, "@OID", row["OID"].ToString());
898
                                AddWithValue(cmd, "@SequenceData_OID", row["SequenceData_OID"].ToString());
899
                                AddWithValue(cmd, "@TopologySet_OID", row["TopologySet_OID"].ToString());
900
                                AddWithValue(cmd, "@BranchTopologySet_OID", row["BranchTopologySet_OID"].ToString());
901
                                AddWithValue(cmd, "@PipeLine_OID", row["PipeLine_OID"].ToString());
902
                                AddWithValue(cmd, "@ITEMNAME", row["ITEMNAME"].ToString());
903
                                AddWithValue(cmd, "@ITEMTAG", row["ITEMTAG"].ToString());
904
                                AddWithValue(cmd, "@Class", row["Class"].ToString());
905
                                AddWithValue(cmd, "@SubClass", row["SubClass"].ToString());
906
                                AddWithValue(cmd, "@TYPE", row["TYPE"].ToString());
907
                                AddWithValue(cmd, "@PIDNAME", row["PIDNAME"].ToString());
908
                                AddWithValue(cmd, "@NPD", row["NPD"].ToString());
909
                                AddWithValue(cmd, "@PipeSystemNetwork_OID", row["PipeSystemNetwork_OID"].ToString());
910
                                AddWithValue(cmd, "@ViewPipeSystemNetwork_OID", row["ViewPipeSystemNetwork_OID"].ToString());
911
                                AddWithValue(cmd, "@PipeRun_OID", row["PipeRun_OID"].ToString());
912
                                connection.ExecuteNonQuery(cmd, txn);
913
                            }
914 6b9e7a56 gaqhf
915 23a96301 humkyung
                            // Sequence
916
                            query = $"DELETE FROM {PSN_SEQUENCEDATA}";
917
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
918
                            foreach (DataRow row in item.SequenceData.Rows)
919
                            {
920
                                query = $"INSERT INTO {PSN_SEQUENCEDATA} VALUES (@OID, @SERIALNUMBER, @PathItem_OID, @TopologySet_OID_Key)";
921
                                var cmd = connection.GetSqlStringCommand(query);
922
                                AddWithValue(cmd, "@OID", row["OID"].ToString());
923
                                AddWithValue(cmd, "@SERIALNUMBER", row["SERIALNUMBER"].ToString());
924
                                AddWithValue(cmd, "@PathItem_OID", row["PathItem_OID"].ToString());
925
                                AddWithValue(cmd, "@TopologySet_OID_Key", row["TopologySet_OID_Key"].ToString());
926
                                connection.ExecuteNonQuery(cmd, txn);
927
                            }
928 5c248ee3 gaqhf
929 23a96301 humkyung
                            // Nozzle
930
                            query = $"DELETE FROM {PSN_NOZZLE}";
931
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
932
                            foreach (DataRow row in item.Nozzle.Rows)
933
                            {
934
                                query = $"INSERT INTO {PSN_NOZZLE} VALUES (@OID, @ITEMTAG, @XCOORDS, @YCOORDS, @Equipment_OID, @FLUID, @NPD, @ROTATION, @FlowDirection)";
935
                                var cmd = connection.GetSqlStringCommand(query);
936
                                AddWithValue(cmd, "@OID", row["OID"].ToString());
937
                                AddWithValue(cmd, "@ITEMTAG", row["ITEMTAG"].ToString());
938
                                AddWithValue(cmd, "@XCOORDS", row["XCOORDS"].ToString());
939
                                AddWithValue(cmd, "@YCOORDS", row["YCOORDS"].ToString());
940
                                AddWithValue(cmd, "@Equipment_OID", row["Equipment_OID"].ToString());
941
                                AddWithValue(cmd, "@FLUID", row["FLUID"].ToString());
942
                                AddWithValue(cmd, "@NPD", row["NPD"].ToString());
943
                                AddWithValue(cmd, "@ROTATION", row["ROTATION"].ToString());
944
                                AddWithValue(cmd, "@FlowDirection", row["FlowDirection"].ToString());
945
                                connection.ExecuteNonQuery(cmd, txn);
946
                            }
947 5c248ee3 gaqhf
948 23a96301 humkyung
                            //Equipment
949
                            query = $"DELETE FROM {PSN_EQUIPMENT}";
950
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
951
                            foreach (DataRow row in item.Equipment.Rows)
952
                            {
953
                                query = $"INSERT INTO {PSN_EQUIPMENT} VALUES (@OID, @ITEMTAG, @XCOORDS, @YCOORDS)";
954
                                var cmd = connection.GetSqlStringCommand(query);
955
                                AddWithValue(cmd, "@OID", row["OID"].ToString());
956
                                AddWithValue(cmd, "@ITEMTAG", row["ITEMTAG"].ToString());
957
                                AddWithValue(cmd, "@XCOORDS", row["XCOORDS"].ToString());
958
                                AddWithValue(cmd, "@YCOORDS", row["YCOORDS"].ToString());
959
                                connection.ExecuteNonQuery(cmd, txn);
960
                            }
961 5c248ee3 gaqhf
962 23a96301 humkyung
                            // TopologySet
963
                            query = $"DELETE FROM {PSN_TOPOLOGYSET}";
964
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
965
                            foreach (DataRow row in item.TopologySet.Rows)
966
                            {
967
                                query = $"INSERT INTO {PSN_TOPOLOGYSET} VALUES (@OID, @Type, @SubType, @HeadItemTag, @TailItemTag, @HeadItemID, @TailItemID)";
968
                                var cmd = connection.GetSqlStringCommand(query);
969
                                AddWithValue(cmd, "@OID", row["OID"].ToString());
970
                                AddWithValue(cmd, "@Type", row["Type"].ToString());
971
                                AddWithValue(cmd, "@SubType", row["SubType"].ToString());
972
                                AddWithValue(cmd, "@HeadItemTag", row["HeadItemTag"].ToString());
973
                                AddWithValue(cmd, "@TailItemTag", row["TailItemTag"].ToString());
974
                                AddWithValue(cmd, "@HeadItemID", row["HeadItemID"].ToString());
975
                                AddWithValue(cmd, "@TailItemID", row["TailItemID"].ToString());
976
                                connection.ExecuteNonQuery(cmd, txn);
977
                            }
978 36a45f13 gaqhf
979 23a96301 humkyung
                            // PSN
980
                            query = $"DELETE FROM {PSN_PIPESYSTEMNETWORK} WHERE PSNRevisionNumber = '{string.Format("V{0:D4}", item.Revision)}'";
981
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
982
                            foreach (DataRow row in item.PipeSystemNetwork.Rows)
983
                            {
984 ddc1c369 LJIYEON
                                query = $"INSERT INTO {PSN_PIPESYSTEMNETWORK} VALUES (@OID, @Type, @OrderNumber, @Pipeline_OID, @FROM_DATA, @TO_DATA, @TopologySet_OID_Key, @PSNRevisionNumber, " +
985
                                    $"@PBS, @PIDDrawings, @Validity, @Status, @IncludingVirtualData, @PSNAccuracy)";
986 23a96301 humkyung
                                var cmd = connection.GetSqlStringCommand(query);
987
                                AddWithValue(cmd, "@OID", row["OID"].ToString());
988
                                AddWithValue(cmd, "@Type", row["Type"].ToString());
989
                                AddWithValue(cmd, "@OrderNumber", row["OrderNumber"].ToString());
990
                                AddWithValue(cmd, "@Pipeline_OID", row["Pipeline_OID"].ToString());
991
                                AddWithValue(cmd, "@FROM_DATA", row["FROM_DATA"].ToString());
992
                                AddWithValue(cmd, "@TO_DATA", row["TO_DATA"].ToString());
993
                                AddWithValue(cmd, "@TopologySet_OID_Key", row["TopologySet_OID_Key"].ToString());
994
                                AddWithValue(cmd, "@PSNRevisionNumber", row["PSNRevisionNumber"].ToString());
995
                                AddWithValue(cmd, "@PBS", row["PBS"].ToString());
996
                                AddWithValue(cmd, "@PIDDrawings", row["PIDDrawings"].ToString());
997 45529c16 LJIYEON
                                int Validity = 0;
998
                                if (row["Validity"].ToString() == "OK")
999
                                    Validity = 0;
1000
                                else if (row["Validity"].ToString() == "InValid")
1001
                                    Validity = 1;
1002
                                else if (row["Validity"].ToString() == "Error")
1003
                                    Validity = -1;
1004
                                AddWithValue(cmd, "@Validity", Validity);
1005 23a96301 humkyung
                                AddWithValue(cmd, "@Status", row["Status"].ToString());
1006 ddc1c369 LJIYEON
                                AddWithValue(cmd, "@IncludingVirtualData", row["IncludingVirtualData"].ToString());
1007
                                AddWithValue(cmd, "@PSNAccuracy", row["PSNAccuracy"].ToString()); 
1008 23a96301 humkyung
                                connection.ExecuteNonQuery(cmd, txn);
1009 6b9e7a56 gaqhf
                            }
1010 23a96301 humkyung
1011
                            txn.Commit();
1012 6b9e7a56 gaqhf
                        }
1013
                        catch (Exception ex)
1014
                        {
1015 23a96301 humkyung
                            txn.Rollback();
1016 6b9e7a56 gaqhf
                            result = false;
1017
                        }
1018
                    }
1019
                }
1020
                catch (Exception ex)
1021
                {
1022
                    System.Windows.Forms.MessageBox.Show(ex.Message);
1023
                    result = false;
1024
                }
1025
            }
1026
1027
            return result;
1028
        }
1029
1030 5c248ee3 gaqhf
        public static bool SavePSNFluidCode(DataTable dt)
1031 6b9e7a56 gaqhf
        {
1032
            ID2Info id2Info = ID2Info.GetInstance();
1033
1034
            bool result = true;
1035 c4a35107 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection(ID2DB_Type.SQLite))
1036 6b9e7a56 gaqhf
            {
1037 1ae1a1c6 LJIYEON
                try
1038 6b9e7a56 gaqhf
                {
1039 23a96301 humkyung
                    using (var txn = connection.BeginTransaction())
1040 1ae1a1c6 LJIYEON
                    {
1041
                        try
1042 757ab2f2 LJIYEON
                        {
1043 23a96301 humkyung
                            var query = $"DELETE FROM {PSN_FLUIDCODE}";
1044
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1045
1046
                            foreach (DataRow row in dt.Rows)
1047 757ab2f2 LJIYEON
                            {
1048 23a96301 humkyung
                                query = $"INSERT INTO {PSN_FLUIDCODE} VALUES (@UID, @Code, @Description, @Condition, @Remarks, @GroundLevel)";
1049
                                var cmd = connection.GetSqlStringCommand(query);
1050
                                cmd.Parameters.Clear();
1051
1052
                                {
1053
                                    var param = cmd.CreateParameter();
1054
                                    param.ParameterName = "@UID";
1055
                                    param.Value = row["UID"].ToString();
1056
                                    cmd.Parameters.Add(param);
1057
                                }
1058
1059
                                {
1060
                                    var param = cmd.CreateParameter();
1061
                                    param.ParameterName = "@Code";
1062
                                    param.Value = row["Code"].ToString();
1063
                                    cmd.Parameters.Add(param);
1064
                                }
1065
1066
                                {
1067
                                    var param = cmd.CreateParameter();
1068
                                    param.ParameterName = "@Description";
1069
                                    param.Value = row["Description"].ToString();
1070
                                    cmd.Parameters.Add(param);
1071
                                }
1072
1073
                                {
1074
                                    var param = cmd.CreateParameter();
1075
                                    param.ParameterName = "@Condition";
1076
                                    param.Value = row["Condition"].ToString();
1077
                                    cmd.Parameters.Add(param);
1078
                                }
1079
1080
                                {
1081
                                    var param = cmd.CreateParameter();
1082
                                    param.ParameterName = "@Remarks";
1083
                                    param.Value = row["Remarks"].ToString();
1084
                                    cmd.Parameters.Add(param);
1085
                                }
1086 1ae1a1c6 LJIYEON
1087 757ab2f2 LJIYEON
                                {
1088 23a96301 humkyung
                                    var param = cmd.CreateParameter();
1089
                                    param.ParameterName = "@GroundLevel";
1090
                                    param.Value = row["GroundLevel"].ToString();
1091
                                    cmd.Parameters.Add(param);
1092 757ab2f2 LJIYEON
                                }
1093 23a96301 humkyung
1094
                                connection.ExecuteNonQuery(cmd, txn);
1095 757ab2f2 LJIYEON
                            }
1096 23a96301 humkyung
                            txn.Commit();
1097 757ab2f2 LJIYEON
                        }
1098 1ae1a1c6 LJIYEON
                        catch (Exception ex)
1099 6b9e7a56 gaqhf
                        {
1100 23a96301 humkyung
                            txn.Rollback();
1101 1ae1a1c6 LJIYEON
                            result = false;
1102 6b9e7a56 gaqhf
                        }
1103
                    }
1104 1ae1a1c6 LJIYEON
                }
1105
                catch (Exception ex)
1106
                {
1107
                    System.Windows.Forms.MessageBox.Show(ex.Message);
1108
                    result = false;
1109
                }
1110 6b9e7a56 gaqhf
            }
1111
1112
            return result;
1113
        }
1114
1115 1ae1a1c6 LJIYEON
        public static DataTable SelectPSNFluidCode()
1116 31d37d58 LJIYEON
        {
1117 23a96301 humkyung
            DataTable dt = null;
1118 31d37d58 LJIYEON
            ID2Info id2Info = ID2Info.GetInstance();
1119 1ae1a1c6 LJIYEON
1120 c4a35107 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection(ID2DB_Type.SQLite))
1121 31d37d58 LJIYEON
            {
1122 1ae1a1c6 LJIYEON
                try
1123 31d37d58 LJIYEON
                {
1124 23a96301 humkyung
                    var query = $"SELECT * FROM {PSN_FLUIDCODE}";
1125
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1126 31d37d58 LJIYEON
                    {
1127 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
1128 31d37d58 LJIYEON
                    }
1129
                }
1130 1ae1a1c6 LJIYEON
                catch (Exception ex)
1131
                {
1132
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1133
                }
1134 31d37d58 LJIYEON
            }
1135 23a96301 humkyung
1136 1ae1a1c6 LJIYEON
            return dt;
1137
        }
1138
1139
        public static bool SavePSNPMC(DataTable dt)
1140
        {
1141
            ID2Info id2Info = ID2Info.GetInstance();
1142
1143
            bool result = true;
1144 c4a35107 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection(ID2DB_Type.SQLite))
1145 31d37d58 LJIYEON
            {
1146 1ae1a1c6 LJIYEON
                try
1147
                {
1148 23a96301 humkyung
                    using (var txn = connection.BeginTransaction())
1149 1ae1a1c6 LJIYEON
                    {
1150
                        try
1151
                        {
1152 23a96301 humkyung
                            var query = $"DELETE FROM {PSN_PIPINGMATLCLASS}";
1153
                            connection.ExecuteNonQuery(connection.GetSqlStringCommand(query), txn);
1154
1155
                            foreach (DataRow row in dt.Rows)
1156 1ae1a1c6 LJIYEON
                            {
1157 23a96301 humkyung
                                query = $"INSERT INTO {PSN_PIPINGMATLCLASS} VALUES (@UID, @Priority, @Code, @Description, @Condition, @Remarks, @GroundLevel)";
1158
                                var cmd = connection.GetSqlStringCommand(query);
1159
                                cmd.Parameters.Clear();
1160
1161
                                {
1162
                                    var param = cmd.CreateParameter();
1163
                                    param.ParameterName = "@UID";
1164
                                    param.Value = row["UID"].ToString();
1165
                                    cmd.Parameters.Add(param);
1166
                                }
1167
1168
                                {
1169
                                    var param = cmd.CreateParameter();
1170
                                    param.ParameterName = "@Priority";
1171
                                    param.Value = row["Priority"].ToString();
1172
                                    cmd.Parameters.Add(param);
1173
                                }
1174
1175
                                {
1176
                                    var param = cmd.CreateParameter();
1177
                                    param.ParameterName = "@Code";
1178
                                    param.Value = row["Code"].ToString();
1179
                                    cmd.Parameters.Add(param);
1180
                                }
1181
1182
                                {
1183
                                    var param = cmd.CreateParameter();
1184
                                    param.ParameterName = "@Description";
1185
                                    param.Value = row["Description"].ToString();
1186
                                    cmd.Parameters.Add(param);
1187
                                }
1188 31d37d58 LJIYEON
1189 1ae1a1c6 LJIYEON
                                {
1190 23a96301 humkyung
                                    var param = cmd.CreateParameter();
1191
                                    param.ParameterName = "@Condition";
1192
                                    param.Value = row["Condition"].ToString();
1193
                                    cmd.Parameters.Add(param);
1194 1ae1a1c6 LJIYEON
                                }
1195 23a96301 humkyung
1196
                                {
1197
                                    var param = cmd.CreateParameter();
1198
                                    param.ParameterName = "@Remarks";
1199
                                    param.Value = row["Remarks"].ToString();
1200
                                    cmd.Parameters.Add(param);
1201
                                }
1202
1203
                                {
1204
                                    var param = cmd.CreateParameter();
1205
                                    param.ParameterName = "@GroundLevel";
1206
                                    param.Value = row["GroundLevel"].ToString();
1207
                                    cmd.Parameters.Add(param);
1208
                                }
1209
1210
                                connection.ExecuteNonQuery(cmd, txn);
1211 1ae1a1c6 LJIYEON
                            }
1212 23a96301 humkyung
1213
                            txn.Commit();
1214 1ae1a1c6 LJIYEON
                        }
1215
                        catch (Exception ex)
1216
                        {
1217 23a96301 humkyung
                            txn.Rollback();
1218 1ae1a1c6 LJIYEON
                            result = false;
1219
                        }
1220
                    }
1221
                }
1222
                catch (Exception ex)
1223
                {
1224
                    System.Windows.Forms.MessageBox.Show(ex.Message);
1225
                    result = false;
1226
                }
1227
            }
1228 31d37d58 LJIYEON
1229 1ae1a1c6 LJIYEON
            return result;
1230 31d37d58 LJIYEON
        }
1231
1232 5c248ee3 gaqhf
        public static PSN GetDBPSN()
1233 6b9e7a56 gaqhf
        {
1234 5c248ee3 gaqhf
            PSN result = new PSN();
1235 6b9e7a56 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
1236
1237 c4a35107 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection(ID2DB_Type.SQLite))
1238 6b9e7a56 gaqhf
            {
1239
                try
1240
                {
1241 23a96301 humkyung
                    var query = $"SELECT * FROM {PSN_PIPESYSTEMNETWORK} WHERE PSNRevisionNumber = '{string.Format("V{0:D4}", GetRevision())}'";
1242
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1243
                    {
1244 45529c16 LJIYEON
                        result.PipeSystemNetwork = ds.Tables[0].Clone();
1245
                        result.PipeSystemNetwork.Columns["Validity"].DataType = typeof(string);
1246
1247
                        foreach (DataRow row in ds.Tables[0].Rows)
1248
                        {
1249
                            DataRow newRow = result.PipeSystemNetwork.NewRow();
1250
                            newRow["OID"] = row["OID"].ToString();
1251
                            newRow["Type"] = row["Type"].ToString();
1252
                            newRow["OrderNumber"] = row["OrderNumber"].ToString();
1253
                            newRow["Pipeline_OID"] = row["Pipeline_OID"].ToString();
1254
                            newRow["FROM_DATA"] = row["FROM_DATA"].ToString();
1255
                            newRow["TO_DATA"] = row["TO_DATA"].ToString();
1256
                            newRow["TopologySet_OID_Key"] = row["TopologySet_OID_Key"].ToString();
1257
                            newRow["PSNRevisionNumber"] = row["PSNRevisionNumber"].ToString();
1258
                            newRow["PBS"] = row["PBS"].ToString();
1259
                            newRow["PIDDrawings"] = row["PIDDrawings"].ToString();
1260
                            string Validity = string.Empty;
1261
1262
                            if (Convert.ToInt32(row["Validity"].ToString()) == 0)
1263
                                Validity = string.Empty;//"OK";
1264
                            else if (Convert.ToInt32(row["Validity"].ToString()) == 1)
1265
                                Validity = "InValid";
1266
                            else if (Convert.ToInt32(row["Validity"].ToString()) == -1)
1267
                                Validity = "Error";
1268
1269
                            newRow["Validity"] = Validity;
1270
1271
                            newRow["Status"] = row["Status"].ToString();
1272 ddc1c369 LJIYEON
                            newRow["IncludingVirtualData"] = row["IncludingVirtualData"].ToString();
1273
                            newRow["PSNAccuracy"] = row["PSNAccuracy"].ToString();
1274
1275 45529c16 LJIYEON
                            result.PipeSystemNetwork.Rows.Add(newRow);
1276
                        }
1277 23a96301 humkyung
                    }
1278 6b9e7a56 gaqhf
1279 23a96301 humkyung
                    query = $"SELECT * FROM {PSN_EQUIPMENT}";
1280
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1281 6b9e7a56 gaqhf
                    {
1282 23a96301 humkyung
                        result.Equipment = ds.Tables[0].Copy();
1283
                    }
1284
1285
                    query = $"SELECT * FROM {PSN_NOZZLE}";
1286
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1287
                    {
1288
                        result.Nozzle = ds.Tables[0].Copy();
1289 6b9e7a56 gaqhf
                    }
1290 23a96301 humkyung
1291
                    query = $"SELECT * FROM {PSN_PATHITEMS}";
1292
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1293
                    {
1294
                        result.PathItems = ds.Tables[0].Copy();
1295
                    }
1296
1297
                    query = $"SELECT * FROM {PSN_SEQUENCEDATA}";
1298
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1299
                    {
1300
                        result.SequenceData = ds.Tables[0].Copy();
1301
                    }
1302
1303 aadd8450 LJIYEON
                    query = $"SELECT * FROM {PSN_TOPOLOGYSET}";
1304
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1305
                    {
1306
                        result.TopologySet = ds.Tables[0].Copy();
1307
                    }
1308
1309 23a96301 humkyung
                    result.Revision = GetRevision();
1310 6b9e7a56 gaqhf
                }
1311
                catch (Exception ex)
1312
                {
1313
                    System.Windows.Forms.MessageBox.Show(ex.Message);
1314 5c248ee3 gaqhf
                    result = null;
1315 6b9e7a56 gaqhf
                }
1316
            }
1317 23a96301 humkyung
1318 6b9e7a56 gaqhf
            return result;
1319
        }
1320 8f24b438 gaqhf
1321
        public static int GetRevision()
1322
        {
1323
            int result = 0;
1324
            ID2Info id2Info = ID2Info.GetInstance();
1325 23a96301 humkyung
1326 c4a35107 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection(ID2DB_Type.SQLite))
1327 8f24b438 gaqhf
            {
1328
                try
1329
                {
1330 23a96301 humkyung
                    var query = $"SELECT DISTINCT PSNRevisionNumber FROM {PSN_PIPESYSTEMNETWORK};";
1331
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1332 8f24b438 gaqhf
                    {
1333 23a96301 humkyung
                        foreach (DataRow row in ds.Tables[0].Rows)
1334 8f24b438 gaqhf
                        {
1335 d5637426 gaqhf
                            string value = row["PSNRevisionNumber"].ToString();
1336 36a45f13 gaqhf
                            if (value.StartsWith("V"))
1337 d5637426 gaqhf
                                value = value.Remove(0, 1);
1338
                            int revisionNumber = Convert.ToInt32(value);
1339 8f24b438 gaqhf
                            if (result < revisionNumber)
1340
                                result = revisionNumber;
1341
                        }
1342
                    }
1343
                }
1344
                catch (Exception ex)
1345
                {
1346
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1347
                    result = -1;
1348
                }
1349
            }
1350
1351
            return result;
1352
        }
1353
1354 5c248ee3 gaqhf
        public static DataTable GetPathItem()
1355
        {
1356 23a96301 humkyung
            DataTable dt = null;
1357
1358 5c248ee3 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
1359 c4a35107 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection(ID2DB_Type.SQLite))
1360 5c248ee3 gaqhf
            {
1361
                try
1362
                {
1363 23a96301 humkyung
                    var query = $"SELECT * FROM {PSN_PATHITEMS}";
1364
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1365 5c248ee3 gaqhf
                    {
1366 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
1367 5c248ee3 gaqhf
                    }
1368
                }
1369
                catch (Exception ex)
1370
                {
1371
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1372
                }
1373
            }
1374 23a96301 humkyung
1375 5c248ee3 gaqhf
            return dt;
1376
        }
1377 757ab2f2 LJIYEON
1378 36a45f13 gaqhf
        public static DataTable GetTopologySet()
1379 5c248ee3 gaqhf
        {
1380 23a96301 humkyung
            DataTable dt = null;
1381
1382 5c248ee3 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
1383 c4a35107 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection(ID2DB_Type.SQLite))
1384 5c248ee3 gaqhf
            {
1385
                try
1386
                {
1387 23a96301 humkyung
                    var query = $"SELECT * FROM {PSN_TOPOLOGYSET}";
1388
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1389 5c248ee3 gaqhf
                    {
1390 aadd8450 LJIYEON
                        dt = ds.Tables[0].Clone();
1391
                        foreach (DataRow row in ds.Tables[0].Rows)
1392
                        {
1393
                            DataRow newRow = dt.NewRow();
1394
                            newRow["OID"] = row["OID"].ToString();
1395
                            newRow["Type"] = row["Type"].ToString();
1396
                            newRow["SubType"] = row["SubType"].ToString();
1397
                            newRow["HeadItemTag"] = row["HeadItemTag"].ToString();
1398
                            newRow["TailItemTag"] = row["TailItemTag"].ToString();
1399
                            newRow["HeadItemID"] = row["HeadItemID"].ToString();
1400
                            newRow["TailItemID"] = row["TailItemID"].ToString();
1401
                            dt.Rows.Add(newRow);
1402
                        }
1403 5c248ee3 gaqhf
                    }
1404
                }
1405
                catch (Exception ex)
1406
                {
1407
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1408
                }
1409
            }
1410 23a96301 humkyung
1411 5c248ee3 gaqhf
            return dt;
1412
        }
1413 757ab2f2 LJIYEON
1414 5c248ee3 gaqhf
        public static DataTable GetPipeSystemNetwork()
1415
        {
1416 23a96301 humkyung
            DataTable dt = null;
1417
1418 5c248ee3 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
1419 c4a35107 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection(ID2DB_Type.SQLite))
1420 5c248ee3 gaqhf
            {
1421
                try
1422
                {
1423 23a96301 humkyung
                    var query = $"SELECT * FROM {PSN_PIPESYSTEMNETWORK} WHERE PSNRevisionNumber = '{string.Format("V{0:D4}", GetRevision())}'";
1424
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1425 5c248ee3 gaqhf
                    {
1426 45529c16 LJIYEON
                        dt = ds.Tables[0].Clone();
1427
                        dt.Columns["Validity"].DataType = typeof(string);
1428
                        foreach (DataRow row in ds.Tables[0].Rows)
1429
                        {
1430
                            DataRow newRow = dt.NewRow();
1431
                            newRow["OID"] = row["OID"].ToString();
1432
                            newRow["Type"] = row["Type"].ToString();
1433
                            newRow["OrderNumber"] = row["OrderNumber"].ToString();
1434
                            newRow["Pipeline_OID"] = row["Pipeline_OID"].ToString();
1435
                            newRow["FROM_DATA"] = row["FROM_DATA"].ToString();
1436
                            newRow["TO_DATA"] = row["TO_DATA"].ToString();
1437
                            newRow["TopologySet_OID_Key"] = row["TopologySet_OID_Key"].ToString();
1438
                            newRow["PSNRevisionNumber"] = row["PSNRevisionNumber"].ToString();
1439
                            newRow["PBS"] = row["PBS"].ToString();
1440
                            newRow["PIDDrawings"] = row["PIDDrawings"].ToString();
1441
                            string Validity = string.Empty;
1442
1443
                            if (Convert.ToInt32(row["Validity"].ToString()) == 0)
1444
                                Validity = string.Empty;//"OK";
1445
                            else if (Convert.ToInt32(row["Validity"].ToString()) == 1)
1446
                                Validity = "InValid";
1447
                            else if (Convert.ToInt32(row["Validity"].ToString()) == -1)
1448
                                Validity = "Error";
1449
1450
                            newRow["Validity"] = Validity;
1451
1452
                            newRow["Status"] = row["Status"].ToString();
1453 ddc1c369 LJIYEON
                            newRow["IncludingVirtualData"] = row["IncludingVirtualData"].ToString();
1454
                            newRow["PSNAccuracy"] = row["PSNAccuracy"].ToString();
1455 45529c16 LJIYEON
                            dt.Rows.Add(newRow);
1456
                        }
1457 5c248ee3 gaqhf
                    }
1458
                }
1459
                catch (Exception ex)
1460
                {
1461
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1462
                }
1463
            }
1464 23a96301 humkyung
1465 5c248ee3 gaqhf
            return dt;
1466
        }
1467 757ab2f2 LJIYEON
1468 5c248ee3 gaqhf
        public static DataTable GetSequenceData()
1469
        {
1470 23a96301 humkyung
            DataTable dt = null;
1471
1472 5c248ee3 gaqhf
            ID2Info id2Info = ID2Info.GetInstance();
1473 c4a35107 humkyung
            using (IAbstractDatabase connection = id2Info.CreateConnection(ID2DB_Type.SQLite))
1474 5c248ee3 gaqhf
            {
1475
                try
1476
                {
1477 23a96301 humkyung
                    var query = $"SELECT * FROM {PSN_SEQUENCEDATA}";
1478
                    using (var ds = connection.ExecuteDataSet(connection.GetSqlStringCommand(query)))
1479 5c248ee3 gaqhf
                    {
1480 23a96301 humkyung
                        dt = ds.Tables[0].Copy();
1481 5c248ee3 gaqhf
                    }
1482
                }
1483
                catch (Exception ex)
1484
                {
1485
                    Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1486
                }
1487
            }
1488 23a96301 humkyung
1489 5c248ee3 gaqhf
            return dt;
1490
        }
1491 0dae5645 gaqhf
    }
1492
}
클립보드 이미지 추가 (최대 크기: 500 MB)