프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / DB / Project_DB.cs @ 8847ea67

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

1 b18dc619 gaqhf
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6 fab4f207 gaqhf
using System.Globalization;
7
using System.Data.SQLite;
8
using System.Data;
9 8847ea67 gaqhf
using System.Data.SqlClient;
10 224535bb gaqhf
using Newtonsoft.Json;
11 b18dc619 gaqhf
12 171142c5 gaqhf
namespace Converter.BaseModel
13 b18dc619 gaqhf
{
14 171142c5 gaqhf
    public class Project_DB
15 b18dc619 gaqhf
    {
16 bca86986 gaqhf
        const string SPPID_DB_INFO_TABLE = "T_SPPID_CONNECTION_INFO";
17
        const string SPPID_SYMBOL_MAPPING_TABLE = "T_SPPID_SYMBOL_MAPPING";
18
        const string SPPID_ATTRIBUTE_MAPPING_TABLE = "T_SPPID_ATTRIBUTE_MAPPING";
19 7cbb1038 gaqhf
        const string SPPID_SETTING_TABLE = "T_SPPID_SETTING_TABLE";
20 b8bd98aa gaqhf
        const string SPPID_LABEL_INFO_TABLE = "T_SPPID_LABEL_INFO";
21 e8536f2b gaqhf
        const string SPPID_DRAWING_INFO = "T_SPPID_DRAWING_INFO";
22 154d8f43 gaqhf
        const string SPPID_OPC_INFO = "T_SPPID_OPC_INFO";
23 171142c5 gaqhf
24 bca86986 gaqhf
        const string LineProperties_TABLE = "LineProperties";
25
        const string LineTypes_TABLE = "LineTypes";
26
        const string SymbolType_TABLE = "SymbolType";
27
        const string SymbolAttribute_TABLE = "SymbolAttribute";
28
        const string Symbol_TABLE = "Symbol";
29 154d8f43 gaqhf
        const string OPCRelations_TABLE = "OPCRelations";
30 171142c5 gaqhf
31 8847ea67 gaqhf
        private static SqlConnection GetSqlConnection()
32 fab4f207 gaqhf
        {
33
            Project_Info projectInfo = Project_Info.GetInstance();
34 8847ea67 gaqhf
            SqlConnection connection = null;
35 fab4f207 gaqhf
            try
36
            {
37 8847ea67 gaqhf
                connection = new SqlConnection(string.Format(CultureInfo.CurrentCulture,
38
                    @"Data Source = {0},{1}; Initial Catalog = {2}; User ID = {3}; Password = {4};",
39
                    projectInfo.ServerIP,
40
                    projectInfo.Port,
41
                    System.IO.Path.GetFileName(projectInfo.DefaultPath),
42
                    projectInfo.DBUser,
43
                    projectInfo.DBPassword));
44
45 fab4f207 gaqhf
                connection.Open();
46
            }
47
            catch (Exception ex)
48
            {
49
                connection.Dispose();
50 8847ea67 gaqhf
                connection = null;
51 fab4f207 gaqhf
            }
52
53 8847ea67 gaqhf
            return connection;
54 fab4f207 gaqhf
        }
55
56 8847ea67 gaqhf
        public static bool ConnTestAndCreateTable()
57 fab4f207 gaqhf
        {
58 8847ea67 gaqhf
            bool result = false;
59 fab4f207 gaqhf
            Project_Info projectInfo = Project_Info.GetInstance();
60 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
61 fab4f207 gaqhf
            {
62 8847ea67 gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, @"Data Source = {0}", projectInfo.DBFilePath)))
63 fab4f207 gaqhf
                {
64 8847ea67 gaqhf
                    try
65 fab4f207 gaqhf
                    {
66 8847ea67 gaqhf
                        connection.Open();
67
                        if (connection.State == ConnectionState.Open)
68
                        {
69
                            using (SQLiteCommand cmd = connection.CreateCommand())
70
                            {
71
                                cmd.CommandText = "SELECT NAME FROM sqlite_master WHERE type='table'";
72
                                using (SQLiteDataReader dr = cmd.ExecuteReader())
73
                                using (DataTable dt = new DataTable())
74
                                {
75
                                    dt.Load(dr);
76
77
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_DB_INFO_TABLE)).Length == 0)
78
                                    {
79
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (JsonString TEXT)", SPPID_DB_INFO_TABLE);
80
                                        cmd.ExecuteNonQuery();
81
                                    }
82
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_SETTING_TABLE)).Length == 0)
83
                                    {
84
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (JsonString TEXT, SettingType TEXT)", SPPID_SETTING_TABLE);
85
                                        cmd.ExecuteNonQuery();
86
                                    }
87
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_SYMBOL_MAPPING_TABLE)).Length == 0)
88
                                    {
89
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, NAME TEXT, SPPID_SYMBOL_PATH TEXT, LEADERLINE BOOLEAN)", SPPID_SYMBOL_MAPPING_TABLE);
90
                                        cmd.ExecuteNonQuery();
91
                                    }
92
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_ATTRIBUTE_MAPPING_TABLE)).Length == 0)
93
                                    {
94
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, SPPID_ATTRIBUTE TEXT)", SPPID_ATTRIBUTE_MAPPING_TABLE);
95
                                        cmd.ExecuteNonQuery();
96
                                    }
97
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_LABEL_INFO_TABLE)).Length == 0)
98
                                    {
99
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, LOCATION INT DEFAULT 0, LEADERLINE BOOLEAN)", SPPID_LABEL_INFO_TABLE);
100
                                        cmd.ExecuteNonQuery();
101
                                    }
102
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_DRAWING_INFO)).Length == 0)
103
                                    {
104
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_DRAWING_UID Text PRIMARY KEY, PATH TEXT, DRAWINGNUMBER TEXT, DRAWINGNAME TEXT)", SPPID_DRAWING_INFO);
105
                                        cmd.ExecuteNonQuery();
106
                                    }
107
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_OPC_INFO)).Length == 0)
108
                                    {
109
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_OPC_UID TEXT PRIMARY KEY, SPPID_OPC_MODELITEM_ID TEXT, ID2_DRAWING_UID TEXT, ATTRIBUTES TEXT, PAIRED BOOL)", SPPID_OPC_INFO);
110
                                        cmd.ExecuteNonQuery();
111
                                    }
112
                                }
113
114
                                #region Check Column 업데이트시 예비용
115
                                cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_SYMBOL_MAPPING_TABLE);
116
                                using (SQLiteDataReader dr = cmd.ExecuteReader())
117
                                using (DataTable dt = new DataTable())
118
                                {
119
                                    dt.Load(dr);
120
                                    if (!dt.Columns.Contains("LEADERLINE"))
121
                                    {
122
                                        cmd.CommandText = string.Format("ALTER TABLE {0} ADD COLUMN LEADERLINE BOOLEAN", SPPID_SYMBOL_MAPPING_TABLE);
123
                                        cmd.ExecuteNonQuery();
124
                                    }
125
                                }
126
127
                                cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_SETTING_TABLE);
128
                                using (SQLiteDataReader dr = cmd.ExecuteReader())
129
                                using (DataTable dt = new DataTable())
130
                                {
131
                                    dt.Load(dr);
132
                                    if (!dt.Columns.Contains("SettingType"))
133
                                    {
134
                                        cmd.CommandText = string.Format("ALTER TABLE {0} ADD COLUMN SettingType Text", SPPID_SETTING_TABLE);
135
                                        cmd.ExecuteNonQuery();
136
                                    }
137
                                }
138 fab4f207 gaqhf
139 8847ea67 gaqhf
                                cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_DRAWING_INFO);
140
                                using (SQLiteDataReader dr = cmd.ExecuteReader())
141
                                using (DataTable dt = new DataTable())
142
                                {
143
                                    dt.Load(dr);
144
                                    if (dt.Columns.Contains("DOCUMENT"))
145
                                    {
146
                                        cmd.CommandText = string.Format("DROP TABLE {0}", SPPID_DRAWING_INFO);
147
                                        cmd.ExecuteNonQuery();
148
149
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_DRAWING_UID Text PRIMARY KEY, PATH TEXT, DRAWINGNUMBER TEXT, DRAWINGNAME TEXT)", SPPID_DRAWING_INFO);
150
                                        cmd.ExecuteNonQuery();
151
                                    }
152
                                }
153
                                #endregion
154
                            }
155
                            result = true;
156
                        }
157
                        connection.Close();
158
                    }
159
                    catch (Exception ex)
160
                    {
161
162
                    }
163
                    finally
164
                    {
165
                        connection.Dispose();
166 fab4f207 gaqhf
                    }
167
                }
168
            }
169 8847ea67 gaqhf
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
170 fab4f207 gaqhf
            {
171 8847ea67 gaqhf
                using (SqlConnection connection = GetSqlConnection())
172 fab4f207 gaqhf
                {
173 8847ea67 gaqhf
                    try
174 fab4f207 gaqhf
                    {
175 8847ea67 gaqhf
                        if (connection != null && connection.State == ConnectionState.Open)
176
                        {
177
                            using (SqlCommand cmd = connection.CreateCommand())
178
                            {
179
                                cmd.CommandText = "SELECT TABLE_NAME AS NAME FROM INFORMATION_SCHEMA.TABLES";
180
                                using (SqlDataReader dr = cmd.ExecuteReader())
181
                                using (DataTable dt = new DataTable())
182
                                {
183
                                    dt.Load(dr);
184
185
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_DB_INFO_TABLE)).Length == 0)
186
                                    {
187
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (JsonString varchar(255))", SPPID_DB_INFO_TABLE);
188
                                        cmd.ExecuteNonQuery();
189
                                    }
190
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_SETTING_TABLE)).Length == 0)
191
                                    {
192
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (JsonString varchar(255), SettingType varchar(255))", SPPID_SETTING_TABLE);
193
                                        cmd.ExecuteNonQuery();
194
                                    }
195
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_SYMBOL_MAPPING_TABLE)).Length == 0)
196
                                    {
197
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID varchar(255) PRIMARY KEY, NAME varchar(255), SPPID_SYMBOL_PATH varchar(255), LEADERLINE BIT)", SPPID_SYMBOL_MAPPING_TABLE);
198
                                        cmd.ExecuteNonQuery();
199
                                    }
200
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_ATTRIBUTE_MAPPING_TABLE)).Length == 0)
201
                                    {
202
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID varchar(255) PRIMARY KEY, SPPID_ATTRIBUTE varchar(255))", SPPID_ATTRIBUTE_MAPPING_TABLE);
203
                                        cmd.ExecuteNonQuery();
204
                                    }
205
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_LABEL_INFO_TABLE)).Length == 0)
206
                                    {
207
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID varchar(255) PRIMARY KEY, LOCATION INT DEFAULT 0, LEADERLINE BIT)", SPPID_LABEL_INFO_TABLE);
208
                                        cmd.ExecuteNonQuery();
209
                                    }
210
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_DRAWING_INFO)).Length == 0)
211
                                    {
212
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_DRAWING_UID varchar(255) PRIMARY KEY, PATH varchar(255), DRAWINGNUMBER varchar(255), DRAWINGNAME varchar(255))", SPPID_DRAWING_INFO);
213
                                        cmd.ExecuteNonQuery();
214
                                    }
215
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_OPC_INFO)).Length == 0)
216
                                    {
217
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_OPC_UID varchar(255) PRIMARY KEY, SPPID_OPC_MODELITEM_ID varchar(255), ID2_DRAWING_UID varchar(255), ATTRIBUTES varchar(255), PAIRED BIT)", SPPID_OPC_INFO);
218
                                        cmd.ExecuteNonQuery();
219
                                    }
220
                                }
221
222
                                #region Check Column 업데이트시 예비용
223
                                #endregion
224
                            }
225
                            result = true;
226
                        }
227 fab4f207 gaqhf
                    }
228 8847ea67 gaqhf
                    catch (Exception ex)
229
                    {
230 fab4f207 gaqhf
231 8847ea67 gaqhf
                    }
232
                    finally
233
                    {
234
                        if (connection != null)
235
                            connection.Dispose();
236
                    }
237 fab4f207 gaqhf
                }
238
            }
239
240 8847ea67 gaqhf
            return result;
241 fab4f207 gaqhf
        }
242
243 8847ea67 gaqhf
        public static bool SaveSPPID_DB_INFO(string jsonString)
244 e00e891d gaqhf
        {
245
            Project_Info projectInfo = Project_Info.GetInstance();
246 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
247 e00e891d gaqhf
            {
248 8847ea67 gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
249 e00e891d gaqhf
                {
250
251 8847ea67 gaqhf
                    try
252
                    {
253
                        connection.Open();
254
                        using (SQLiteCommand cmd = connection.CreateCommand())
255 7cbb1038 gaqhf
                        {
256 8847ea67 gaqhf
                            cmd.CommandText = string.Format("DELETE FROM {0}", SPPID_DB_INFO_TABLE);
257
                            cmd.ExecuteNonQuery();
258
259
                            cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@jsonString)", SPPID_DB_INFO_TABLE);
260
                            cmd.Parameters.AddWithValue("@jsonString", jsonString);
261 7cbb1038 gaqhf
                            cmd.ExecuteNonQuery();
262
                        }
263 8847ea67 gaqhf
                        connection.Close();
264
                    }
265
                    catch (Exception ex)
266
                    {
267
                        return false;
268
                    }
269
                    finally
270
                    {
271
                        connection.Dispose();
272 e00e891d gaqhf
                    }
273
                }
274 8847ea67 gaqhf
            }
275
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
276
            {
277
                using (SqlConnection connection = GetSqlConnection())
278 e00e891d gaqhf
                {
279 8847ea67 gaqhf
                    try
280
                    {
281
                        if (connection != null && connection.State == ConnectionState.Open)
282
                        {
283
284
                        }
285
                    }
286
                    catch (Exception ex)
287
                    {
288
289
                    }
290
                    finally
291
                    {
292
                        if (connection != null)
293
                            connection.Dispose();
294
                    }
295 e00e891d gaqhf
                }
296
            }
297
298 8847ea67 gaqhf
299 e00e891d gaqhf
            return true;
300
        }
301
302 8847ea67 gaqhf
        public static DataTable SelectSPPID_DB_INFO()
303 e00e891d gaqhf
        {
304
            DataTable dt = new DataTable();
305
            Project_Info projectInfo = Project_Info.GetInstance();
306 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
307 e00e891d gaqhf
            {
308 8847ea67 gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
309 e00e891d gaqhf
                {
310 8847ea67 gaqhf
                    try
311 e00e891d gaqhf
                    {
312 8847ea67 gaqhf
                        connection.Open();
313
                        using (SQLiteCommand cmd = connection.CreateCommand())
314
                        {
315
                            cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_DB_INFO_TABLE);
316
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
317
                                dt.Load(dr);
318
                        }
319
                        connection.Close();
320 e00e891d gaqhf
                    }
321 8847ea67 gaqhf
                    catch (Exception ex)
322
                    {
323 e00e891d gaqhf
324 8847ea67 gaqhf
                    }
325
                    finally
326
                    {
327
                        connection.Dispose();
328
                    }
329 e00e891d gaqhf
                }
330 8847ea67 gaqhf
            }
331
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
332
            {
333
                using (SqlConnection connection = GetSqlConnection())
334 e00e891d gaqhf
                {
335 8847ea67 gaqhf
                    try
336
                    {
337
                        if (connection != null && connection.State == ConnectionState.Open)
338
                        {
339
340
                        }
341
                    }
342
                    catch (Exception ex)
343
                    {
344
345
                    }
346
                    finally
347
                    {
348
                        if (connection != null)
349
                            connection.Dispose();
350
                    }
351 e00e891d gaqhf
                }
352
            }
353
354
            return dt;
355
        }
356
357 8847ea67 gaqhf
        public static bool SaveETCSetting(Dictionary<string,string> dicSetting)
358 fab4f207 gaqhf
        {
359 8847ea67 gaqhf
            Project_Info projectInfo = Project_Info.GetInstance();
360
            if (projectInfo.DBType == ID2DB_Type.SQLite)
361 fab4f207 gaqhf
            {
362 8847ea67 gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
363 fab4f207 gaqhf
                {
364
365 8847ea67 gaqhf
                    try
366 e00e891d gaqhf
                    {
367 8847ea67 gaqhf
                        connection.Open();
368
                        using (SQLiteCommand cmd = connection.CreateCommand())
369
                        {
370
                            cmd.CommandText = string.Format("DELETE FROM {0}", SPPID_SETTING_TABLE);
371
                            cmd.ExecuteNonQuery();
372
373
                            foreach (var item in dicSetting)
374
                            {
375
                                cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@jsonString, @SettingType)", SPPID_SETTING_TABLE);
376
                                cmd.Parameters.AddWithValue("@jsonString", item.Value);
377
                                cmd.Parameters.AddWithValue("@SettingType", item.Key);
378
                                cmd.ExecuteNonQuery();
379
                            }
380
                        }
381
                        connection.Close();
382 e00e891d gaqhf
                    }
383 8847ea67 gaqhf
                    catch (Exception ex)
384 bca86986 gaqhf
                    {
385 8847ea67 gaqhf
                        return false;
386 bca86986 gaqhf
                    }
387 8847ea67 gaqhf
                    finally
388 bca86986 gaqhf
                    {
389 8847ea67 gaqhf
                        connection.Dispose();
390 bca86986 gaqhf
                    }
391 8847ea67 gaqhf
                }
392
            }
393
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
394
            {
395
                using (SqlConnection connection = GetSqlConnection())
396
                {
397
                    try
398 1a3a74a8 gaqhf
                    {
399 8847ea67 gaqhf
                        if (connection != null && connection.State == ConnectionState.Open)
400
                        {
401
402
                        }
403 1a3a74a8 gaqhf
                    }
404 8847ea67 gaqhf
                    catch (Exception ex)
405 e8536f2b gaqhf
                    {
406 8847ea67 gaqhf
407 154d8f43 gaqhf
                    }
408 8847ea67 gaqhf
                    finally
409 154d8f43 gaqhf
                    {
410 8847ea67 gaqhf
                        if (connection != null)
411
                            connection.Dispose();
412 e8536f2b gaqhf
                    }
413 fab4f207 gaqhf
                }
414 8847ea67 gaqhf
            }
415 cf924377 gaqhf
416 8847ea67 gaqhf
            return true;
417
        }
418
419
        public static DataTable SelectSetting()
420
        {
421
            DataTable dt = new DataTable();
422
            Project_Info projectInfo = Project_Info.GetInstance();
423
            if (projectInfo.DBType == ID2DB_Type.SQLite)
424
            {
425
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
426 cf924377 gaqhf
                {
427 8847ea67 gaqhf
                    try
428 cf924377 gaqhf
                    {
429 8847ea67 gaqhf
                        connection.Open();
430
                        using (SQLiteCommand cmd = connection.CreateCommand())
431
                        {
432
                            cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_SETTING_TABLE);
433
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
434
                                dt.Load(dr);
435
                        }
436
                        connection.Close();
437 cf924377 gaqhf
                    }
438 8847ea67 gaqhf
                    catch (Exception ex)
439
                    {
440 7cbb1038 gaqhf
441 8847ea67 gaqhf
                    }
442
                    finally
443 7cbb1038 gaqhf
                    {
444 8847ea67 gaqhf
                        connection.Dispose();
445 7cbb1038 gaqhf
                    }
446
                }
447 8847ea67 gaqhf
            }
448
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
449
            {
450
                using (SqlConnection connection = GetSqlConnection())
451 224535bb gaqhf
                {
452 8847ea67 gaqhf
                    try
453
                    {
454
                        if (connection != null && connection.State == ConnectionState.Open)
455
                        {
456
457
                        }
458
                    }
459
                    catch (Exception ex)
460 224535bb gaqhf
                    {
461 154d8f43 gaqhf
462 8847ea67 gaqhf
                    }
463
                    finally
464
                    {
465
                        if (connection != null)
466
                            connection.Dispose();
467 224535bb gaqhf
                    }
468
                }
469 fab4f207 gaqhf
            }
470 8847ea67 gaqhf
471
            return dt;
472 fab4f207 gaqhf
        }
473 bca86986 gaqhf
474
        public static DataTable SelectProjectSymbol()
475
        {
476
            DataTable dt = new DataTable();
477
            Project_Info projectInfo = Project_Info.GetInstance();
478 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
479 bca86986 gaqhf
            {
480 8847ea67 gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
481 bca86986 gaqhf
                {
482 8847ea67 gaqhf
                    try
483 bca86986 gaqhf
                    {
484 8847ea67 gaqhf
                        connection.Open();
485
                        using (SQLiteCommand cmd = connection.CreateCommand())
486
                        {
487
                            cmd.CommandText = string.Format(@"
488 cf924377 gaqhf
                            SELECT s.UID, s.Name, st.Type, sp.SPPID_SYMBOL_PATH, sp.LEADERLINE FROM {1} as st, {0} as s 
489 bca86986 gaqhf
                                LEFT OUTER JOIN {2} as sp 
490
                                    ON s.UID = SP.UID 
491
                            WHERE s.SymbolType_UID = st.UID 
492
                            ORDER BY st.TYPE ASC;", Symbol_TABLE, SymbolType_TABLE, SPPID_SYMBOL_MAPPING_TABLE);
493 8847ea67 gaqhf
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
494
                                dt.Load(dr);
495 310aeb31 gaqhf
496 8847ea67 gaqhf
                            DataTable dtClone = dt.Clone();
497
                            dtClone.Columns["UID"].DataType = typeof(string);
498
                            foreach (DataRow row in dt.Rows)
499
                            {
500
                                dtClone.ImportRow(row);
501
                            }
502
                            dt.Dispose();
503
                            dt = dtClone;
504 310aeb31 gaqhf
                        }
505 8847ea67 gaqhf
                        connection.Close();
506 bca86986 gaqhf
                    }
507 8847ea67 gaqhf
                    catch (Exception ex)
508
                    {
509 bca86986 gaqhf
510 8847ea67 gaqhf
                    }
511
                    finally
512
                    {
513
                        connection.Dispose();
514
                    }
515 bca86986 gaqhf
                }
516 8847ea67 gaqhf
            }
517
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
518
            {
519
                using (SqlConnection connection = GetSqlConnection())
520 bca86986 gaqhf
                {
521 8847ea67 gaqhf
                    try
522
                    {
523
                        if (connection != null && connection.State == ConnectionState.Open)
524
                        {
525
526
                        }
527
                    }
528
                    catch (Exception ex)
529
                    {
530
531
                    }
532
                    finally
533
                    {
534
                        if (connection != null)
535
                            connection.Dispose();
536
                    }
537 bca86986 gaqhf
                }
538
            }
539
540
            return dt;
541
        }
542
543 4b4dbca9 gaqhf
        public static DataTable SelectProjectChildSymbol()
544
        {
545
            DataTable result = new DataTable();
546
            result.Columns.Add("UID");
547
            result.Columns.Add("Name");
548
            result.Columns.Add("Type");
549
            result.Columns.Add("SPPID_SYMBOL_PATH");
550
            
551
            Project_Info projectInfo = Project_Info.GetInstance();
552 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
553 4b4dbca9 gaqhf
            {
554 8847ea67 gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
555
                using (DataTable dt = new DataTable())
556 4b4dbca9 gaqhf
                {
557 8847ea67 gaqhf
                    try
558 4b4dbca9 gaqhf
                    {
559 8847ea67 gaqhf
                        connection.Open();
560
                        using (SQLiteCommand cmd = connection.CreateCommand())
561
                        {
562
                            cmd.CommandText = string.Format(@"
563 4b4dbca9 gaqhf
                            SELECT AdditionalSymbol FROM Symbol");
564 8847ea67 gaqhf
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
565
                                dt.Load(dr);
566
                            List<string> childList = new List<string>();
567
                            foreach (DataRow row in dt.Rows)
568 4b4dbca9 gaqhf
                            {
569 8847ea67 gaqhf
                                if (row["AdditionalSymbol"] != null && !DBNull.Value.Equals(row["AdditionalSymbol"]) && !string.IsNullOrEmpty((string)row["AdditionalSymbol"]))
570 4b4dbca9 gaqhf
                                {
571 8847ea67 gaqhf
                                    string[] array = row["AdditionalSymbol"].ToString().Split(new char[] { '/' });
572
                                    foreach (var childString in array)
573
                                    {
574
                                        childList.Add(childString.Split(new char[] { ',' })[2]);
575
                                    }
576 4b4dbca9 gaqhf
                                }
577
578 8847ea67 gaqhf
                            }
579 4b4dbca9 gaqhf
580 8847ea67 gaqhf
                            dt.Clear();
581
                            cmd.Reset();
582
                            cmd.CommandText = string.Format(@"
583 4b4dbca9 gaqhf
                            SELECT * FROM {0}", SPPID_SYMBOL_MAPPING_TABLE);
584 8847ea67 gaqhf
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
585
                                dt.Load(dr);
586 4b4dbca9 gaqhf
587 8847ea67 gaqhf
                            childList = childList.Distinct().ToList();
588
                            foreach (var child in childList)
589
                            {
590
                                string mappingPath = string.Empty;
591
                                DataRow[] rows = dt.Select(string.Format("UID = '{0}'", child));
592
                                if (rows.Length == 1)
593
                                    mappingPath = !DBNull.Value.Equals(rows[0]["SPPID_SYMBOL_PATH"]) ? (string)rows[0]["SPPID_SYMBOL_PATH"] : null;
594
595
                                DataRow newRow = result.NewRow();
596
                                newRow["UID"] = child;
597
                                newRow["Name"] = child;
598
                                newRow["Type"] = "Child Symbol";
599
                                newRow["SPPID_SYMBOL_PATH"] = mappingPath;
600
                                result.Rows.Add(newRow);
601
                            }
602 4b4dbca9 gaqhf
                        }
603 8847ea67 gaqhf
                        connection.Close();
604 4b4dbca9 gaqhf
                    }
605 8847ea67 gaqhf
                    catch (Exception ex)
606
                    {
607 4b4dbca9 gaqhf
608 8847ea67 gaqhf
                    }
609
                    finally
610
                    {
611
                        connection.Dispose();
612
                    }
613 4b4dbca9 gaqhf
                }
614 8847ea67 gaqhf
            }
615
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
616
            {
617
                using (SqlConnection connection = GetSqlConnection())
618 4b4dbca9 gaqhf
                {
619 8847ea67 gaqhf
                    try
620
                    {
621
                        if (connection != null && connection.State == ConnectionState.Open)
622
                        {
623
624
                        }
625
                    }
626
                    catch (Exception ex)
627
                    {
628
629
                    }
630
                    finally
631
                    {
632
                        if (connection != null)
633
                            connection.Dispose();
634
                    }
635 4b4dbca9 gaqhf
                }
636
            }
637
            return result;
638
        }
639
640 bca86986 gaqhf
        public static DataTable SelectProjectLine()
641
        {
642
            DataTable dt = new DataTable();
643
            Project_Info projectInfo = Project_Info.GetInstance();
644 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
645 bca86986 gaqhf
            {
646 8847ea67 gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
647 bca86986 gaqhf
                {
648 8847ea67 gaqhf
                    try
649 bca86986 gaqhf
                    {
650 8847ea67 gaqhf
                        connection.Open();
651
                        using (SQLiteCommand cmd = connection.CreateCommand())
652
                        {
653
                            cmd.CommandText = string.Format(@"
654 bca86986 gaqhf
                            SELECT l.UID, l.Name, sp.SPPID_SYMBOL_PATH FROM {0} as l 
655
                                LEFT OUTER JOIN {1} as sp 
656
                                    ON l.UID = SP.UID ;", LineTypes_TABLE, SPPID_SYMBOL_MAPPING_TABLE);
657 8847ea67 gaqhf
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
658
                                dt.Load(dr);
659
                        }
660
                        connection.Close();
661 bca86986 gaqhf
                    }
662 8847ea67 gaqhf
                    catch (Exception ex)
663
                    {
664 bca86986 gaqhf
665 8847ea67 gaqhf
                    }
666
                    finally
667
                    {
668
                        connection.Dispose();
669
                    }
670 bca86986 gaqhf
                }
671 8847ea67 gaqhf
            }
672
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
673
            {
674
                using (SqlConnection connection = GetSqlConnection())
675 bca86986 gaqhf
                {
676 8847ea67 gaqhf
                    try
677
                    {
678
                        if (connection != null && connection.State == ConnectionState.Open)
679
                        {
680
681
                        }
682
                    }
683
                    catch (Exception ex)
684
                    {
685
686
                    }
687
                    finally
688
                    {
689
                        if (connection != null)
690
                            connection.Dispose();
691
                    }
692 bca86986 gaqhf
                }
693
            }
694
695
            return dt;
696
        }
697
698
        public static DataTable SelectProjectLineProperties()
699
        {
700
            DataTable dt = new DataTable();
701
            Project_Info projectInfo = Project_Info.GetInstance();
702 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
703 bca86986 gaqhf
            {
704 8847ea67 gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
705 bca86986 gaqhf
                {
706 8847ea67 gaqhf
                    try
707 bca86986 gaqhf
                    {
708 8847ea67 gaqhf
                        connection.Open();
709
                        using (SQLiteCommand cmd = connection.CreateCommand())
710
                        {
711
                            cmd.CommandText = string.Format(@"
712 bca86986 gaqhf
                            SELECT lp.UID, lp.DisplayName, sp.SPPID_SYMBOL_PATH, spa.SPPID_ATTRIBUTE
713
                            FROM {0} as lp 
714
                                 LEFT OUTER JOIN {1} as sp 
715
                                      ON lp.UID = sp.UID
716
                                 LEFT OUTER JOIN {2} as spa 
717
                                      ON lp.UID = spa.UID;", LineProperties_TABLE, SPPID_SYMBOL_MAPPING_TABLE, SPPID_ATTRIBUTE_MAPPING_TABLE);
718 8847ea67 gaqhf
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
719
                                dt.Load(dr);
720
                        }
721
                        connection.Close();
722 bca86986 gaqhf
                    }
723 8847ea67 gaqhf
                    catch (Exception ex)
724
                    {
725 bca86986 gaqhf
726 8847ea67 gaqhf
                    }
727
                    finally
728
                    {
729
                        connection.Dispose();
730
                    }
731 bca86986 gaqhf
                }
732 8847ea67 gaqhf
            }
733
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
734
            {
735
                using (SqlConnection connection = GetSqlConnection())
736 bca86986 gaqhf
                {
737 8847ea67 gaqhf
                    try
738
                    {
739
                        if (connection != null && connection.State == ConnectionState.Open)
740
                        {
741
742
                        }
743
                    }
744
                    catch (Exception ex)
745
                    {
746
747
                    }
748
                    finally
749
                    {
750
                        if (connection != null)
751
                            connection.Dispose();
752
                    }
753 bca86986 gaqhf
                }
754
            }
755
756
            return dt;
757
        }
758
759 1efc25a3 gaqhf
        public static DataTable SelectProjectAttribute()
760 bca86986 gaqhf
        {
761
            DataTable dt = new DataTable();
762
            Project_Info projectInfo = Project_Info.GetInstance();
763 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
764 bca86986 gaqhf
            {
765 8847ea67 gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
766 bca86986 gaqhf
                {
767 8847ea67 gaqhf
                    try
768 bca86986 gaqhf
                    {
769 8847ea67 gaqhf
                        connection.Open();
770
                        using (SQLiteCommand cmd = connection.CreateCommand())
771
                        {
772
                            cmd.CommandText = string.Format(@"
773 401efcff gaqhf
                            SELECT sa.UID, sa.DisplayAttribute, st.TYPE, spa.SPPID_ATTRIBUTE, sp.SPPID_SYMBOL_PATH, spl.LOCATION, spl.LEADERLINE, sa.Property
774 bca86986 gaqhf
                            FROM {1} as sa, {0} as st 
775
                                 LEFT OUTER JOIN {2} as sp 
776
                                      ON sa.UID = SP.UID 
777
                                LEFT OUTER JOIN {3} as spa 
778
                                     ON sa.UID = spa.UID
779 1a3a74a8 gaqhf
                                LEFT OUTER JOIN {4} as spl 
780
                                     ON sa.UID = spl.UID
781 401efcff gaqhf
                            WHERE sa.SymbolType_UID = st.UID AND (sa.Property != 2 OR sa.Property IS NULL);", SymbolType_TABLE, SymbolAttribute_TABLE, SPPID_SYMBOL_MAPPING_TABLE, SPPID_ATTRIBUTE_MAPPING_TABLE, SPPID_LABEL_INFO_TABLE);
782 8847ea67 gaqhf
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
783
                                dt.Load(dr);
784
                        }
785
                        connection.Close();
786 bca86986 gaqhf
                    }
787 8847ea67 gaqhf
                    catch (Exception ex)
788
                    {
789 bca86986 gaqhf
790 8847ea67 gaqhf
                    }
791
                    finally
792
                    {
793
                        connection.Dispose();
794
                    }
795
                }
796
            }
797
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
798
            {
799
                using (SqlConnection connection = GetSqlConnection())
800 bca86986 gaqhf
                {
801 8847ea67 gaqhf
                    try
802
                    {
803
                        if (connection != null && connection.State == ConnectionState.Open)
804
                        {
805
806
                        }
807
                    }
808
                    catch (Exception ex)
809
                    {
810
811
                    }
812
                    finally
813
                    {
814
                        if (connection != null)
815
                            connection.Dispose();
816
                    }
817 bca86986 gaqhf
                }
818
            }
819
820 8847ea67 gaqhf
821 bca86986 gaqhf
            return dt;
822
        }
823
824 4d2571ab gaqhf
        public static DataTable SelectID2SymbolTable()
825
        {
826
            DataTable dt = new DataTable();
827
            Project_Info projectInfo = Project_Info.GetInstance();
828 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
829 4d2571ab gaqhf
            {
830 8847ea67 gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
831 4d2571ab gaqhf
                {
832 8847ea67 gaqhf
                    try
833 4d2571ab gaqhf
                    {
834 8847ea67 gaqhf
                        connection.Open();
835
                        using (SQLiteCommand cmd = connection.CreateCommand())
836
                        {
837
                            cmd.CommandText = @"SELECT * FROM Symbol";
838
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
839
                                dt.Load(dr);
840
                        }
841
                        connection.Close();
842 4d2571ab gaqhf
                    }
843 8847ea67 gaqhf
                    catch (Exception ex)
844
                    {
845 4d2571ab gaqhf
846 8847ea67 gaqhf
                    }
847
                    finally
848
                    {
849
                        connection.Dispose();
850
                    }
851 4d2571ab gaqhf
                }
852 8847ea67 gaqhf
            }
853
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
854
            {
855
                using (SqlConnection connection = GetSqlConnection())
856 4d2571ab gaqhf
                {
857 8847ea67 gaqhf
                    try
858
                    {
859
                        if (connection != null && connection.State == ConnectionState.Open)
860
                        {
861
862
                        }
863
                    }
864
                    catch (Exception ex)
865
                    {
866
867
                    }
868
                    finally
869
                    {
870
                        if (connection != null)
871
                            connection.Dispose();
872
                    }
873 4d2571ab gaqhf
                }
874
            }
875
876
            return dt;
877
        }
878
879 154d8f43 gaqhf
        public static DataTable SelectOPCRelations()
880
        {
881
            DataTable dt = new DataTable();
882
            Project_Info projectInfo = Project_Info.GetInstance();
883 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
884 154d8f43 gaqhf
            {
885 8847ea67 gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
886 154d8f43 gaqhf
                {
887 8847ea67 gaqhf
                    try
888 154d8f43 gaqhf
                    {
889 8847ea67 gaqhf
                        connection.Open();
890
                        using (SQLiteCommand cmd = connection.CreateCommand())
891
                        {
892
                            cmd.CommandText = string.Format("SELECT * FROM {0}", OPCRelations_TABLE);
893
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
894
                                dt.Load(dr);
895
                        }
896
                        connection.Close();
897 154d8f43 gaqhf
                    }
898 8847ea67 gaqhf
                    catch (Exception ex)
899
                    {
900 154d8f43 gaqhf
901 8847ea67 gaqhf
                    }
902
                    finally
903
                    {
904
                        connection.Dispose();
905
                    }
906 154d8f43 gaqhf
                }
907 8847ea67 gaqhf
            }
908
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
909
            {
910
                using (SqlConnection connection = GetSqlConnection())
911 154d8f43 gaqhf
                {
912 8847ea67 gaqhf
                    try
913
                    {
914
                        if (connection != null && connection.State == ConnectionState.Open)
915
                        {
916
917
                        }
918
                    }
919
                    catch (Exception ex)
920
                    {
921
922
                    }
923
                    finally
924
                    {
925
                        if (connection != null)
926
                            connection.Dispose();
927
                    }
928 154d8f43 gaqhf
                }
929
            }
930
931
            return dt;
932
        }
933
934
        public static DataTable SelectDrawings()
935
        {
936
            DataTable dt = new DataTable();
937
            Project_Info projectInfo = Project_Info.GetInstance();
938 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
939 154d8f43 gaqhf
            {
940 8847ea67 gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
941 154d8f43 gaqhf
                {
942 8847ea67 gaqhf
                    try
943 154d8f43 gaqhf
                    {
944 8847ea67 gaqhf
                        connection.Open();
945
                        using (SQLiteCommand cmd = connection.CreateCommand())
946
                        {
947
                            cmd.CommandText = string.Format("SELECT * FROM {0}", "Drawings");
948
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
949
                                dt.Load(dr);
950
                        }
951
                        connection.Close();
952 154d8f43 gaqhf
                    }
953 8847ea67 gaqhf
                    catch (Exception ex)
954
                    {
955 154d8f43 gaqhf
956 8847ea67 gaqhf
                    }
957
                    finally
958
                    {
959
                        connection.Dispose();
960
                    }
961 154d8f43 gaqhf
                }
962 8847ea67 gaqhf
            }
963
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
964
            {
965
                using (SqlConnection connection = GetSqlConnection())
966 154d8f43 gaqhf
                {
967 8847ea67 gaqhf
                    try
968
                    {
969
                        if (connection != null && connection.State == ConnectionState.Open)
970
                        {
971
972
                        }
973
                    }
974
                    catch (Exception ex)
975
                    {
976
977
                    }
978
                    finally
979
                    {
980
                        if (connection != null)
981
                            connection.Dispose();
982
                    }
983 154d8f43 gaqhf
                }
984
            }
985
986
            return dt;
987
        }
988
989
        public static DataTable SelectOPCInfo()
990
        {
991
            DataTable dt = new DataTable();
992
            Project_Info projectInfo = Project_Info.GetInstance();
993 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
994 154d8f43 gaqhf
            {
995 8847ea67 gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
996 154d8f43 gaqhf
                {
997 8847ea67 gaqhf
                    try
998 154d8f43 gaqhf
                    {
999 8847ea67 gaqhf
                        connection.Open();
1000
                        using (SQLiteCommand cmd = connection.CreateCommand())
1001
                        {
1002
                            cmd.CommandText = string.Format("SELECT * FROM {0} WHERE SPPID_OPC_MODELITEM_ID IS NOT NULL AND PAIRED = False", SPPID_OPC_INFO);
1003
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
1004
                                dt.Load(dr);
1005
                        }
1006
                        connection.Close();
1007 154d8f43 gaqhf
                    }
1008 8847ea67 gaqhf
                    catch (Exception ex)
1009
                    {
1010 154d8f43 gaqhf
1011 8847ea67 gaqhf
                    }
1012
                    finally
1013
                    {
1014
                        connection.Dispose();
1015
                    }
1016 154d8f43 gaqhf
                }
1017 8847ea67 gaqhf
            }
1018
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1019
            {
1020
                using (SqlConnection connection = GetSqlConnection())
1021 154d8f43 gaqhf
                {
1022 8847ea67 gaqhf
                    try
1023
                    {
1024
                        if (connection != null && connection.State == ConnectionState.Open)
1025
                        {
1026
1027
                        }
1028
                    }
1029
                    catch (Exception ex)
1030
                    {
1031
1032
                    }
1033
                    finally
1034
                    {
1035
                        if (connection != null)
1036
                            connection.Dispose();
1037
                    }
1038 154d8f43 gaqhf
                }
1039
            }
1040
1041
            return dt;
1042
        }
1043 7e680366 gaqhf
1044
        public static DataTable SelectSymbolType()
1045
        {
1046
            DataTable dt = new DataTable();
1047
            Project_Info projectInfo = Project_Info.GetInstance();
1048 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
1049 7e680366 gaqhf
            {
1050 8847ea67 gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
1051 7e680366 gaqhf
                {
1052 8847ea67 gaqhf
                    try
1053 7e680366 gaqhf
                    {
1054 8847ea67 gaqhf
                        connection.Open();
1055
                        using (SQLiteCommand cmd = connection.CreateCommand())
1056
                        {
1057
                            cmd.CommandText = string.Format("SELECT * FROM {0}", SymbolType_TABLE);
1058
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
1059
                                dt.Load(dr);
1060
                        }
1061
                        connection.Close();
1062 7e680366 gaqhf
                    }
1063 8847ea67 gaqhf
                    catch (Exception ex)
1064
                    {
1065 7e680366 gaqhf
1066 8847ea67 gaqhf
                    }
1067
                    finally
1068
                    {
1069
                        connection.Dispose();
1070
                    }
1071 7e680366 gaqhf
                }
1072 8847ea67 gaqhf
            }
1073
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1074
            {
1075
                using (SqlConnection connection = GetSqlConnection())
1076 7e680366 gaqhf
                {
1077 8847ea67 gaqhf
                    try
1078
                    {
1079
                        if (connection != null && connection.State == ConnectionState.Open)
1080
                        {
1081
1082
                        }
1083
                    }
1084
                    catch (Exception ex)
1085
                    {
1086
1087
                    }
1088
                    finally
1089
                    {
1090
                        if (connection != null)
1091
                            connection.Dispose();
1092
                    }
1093 7e680366 gaqhf
                }
1094
            }
1095
1096
            return dt;
1097
        }
1098
1099 4fb0f8d5 gaqhf
        public static DataTable SelectDrawingInfo()
1100
        {
1101 154d8f43 gaqhf
            DataTable dt = new DataTable();
1102 4fb0f8d5 gaqhf
            Project_Info projectInfo = Project_Info.GetInstance();
1103 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
1104 4fb0f8d5 gaqhf
            {
1105 8847ea67 gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
1106 4fb0f8d5 gaqhf
                {
1107 8847ea67 gaqhf
                    try
1108 4fb0f8d5 gaqhf
                    {
1109 8847ea67 gaqhf
                        connection.Open();
1110
                        using (SQLiteCommand cmd = connection.CreateCommand())
1111
                        {
1112
                            cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_DRAWING_INFO);
1113
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
1114
                                dt.Load(dr);
1115
                        }
1116
                        connection.Close();
1117 4fb0f8d5 gaqhf
                    }
1118 8847ea67 gaqhf
                    catch (Exception ex)
1119
                    {
1120 4fb0f8d5 gaqhf
1121 8847ea67 gaqhf
                    }
1122
                    finally
1123
                    {
1124
                        connection.Dispose();
1125
                    }
1126 4fb0f8d5 gaqhf
                }
1127 8847ea67 gaqhf
            }
1128
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1129
            {
1130
                using (SqlConnection connection = GetSqlConnection())
1131 4fb0f8d5 gaqhf
                {
1132 8847ea67 gaqhf
                    try
1133
                    {
1134
                        if (connection != null && connection.State == ConnectionState.Open)
1135
                        {
1136
1137
                        }
1138
                    }
1139
                    catch (Exception ex)
1140
                    {
1141
1142
                    }
1143
                    finally
1144
                    {
1145
                        if (connection != null)
1146
                            connection.Dispose();
1147
                    }
1148 4fb0f8d5 gaqhf
                }
1149
            }
1150
1151
            return dt;
1152
        }
1153
1154 cf924377 gaqhf
        public static bool InsertSymbolMapping(List<Tuple<string, string, string, bool>> datas)
1155 bca86986 gaqhf
        {
1156
            Project_Info projectInfo = Project_Info.GetInstance();
1157 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
1158 bca86986 gaqhf
            {
1159 8847ea67 gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
1160 bca86986 gaqhf
                {
1161 8847ea67 gaqhf
                    try
1162 bca86986 gaqhf
                    {
1163 8847ea67 gaqhf
                        connection.Open();
1164
                        using (SQLiteTransaction transaction = connection.BeginTransaction())
1165 1421f1d6 gaqhf
                        {
1166 8847ea67 gaqhf
                            try
1167 1421f1d6 gaqhf
                            {
1168 8847ea67 gaqhf
                                using (SQLiteCommand cmd = connection.CreateCommand())
1169 1421f1d6 gaqhf
                                {
1170 8847ea67 gaqhf
                                    foreach (var item in datas)
1171
                                    {
1172
                                        cmd.Parameters.Clear();
1173
                                        cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, NAME, SPPID_SYMBOL_PATH, LEADERLINE) VALUES (@UID, @NAME, @SPPID_SYMBOL_PATH, @LEADERLINE)", SPPID_SYMBOL_MAPPING_TABLE);
1174
                                        cmd.Parameters.AddWithValue("@UID", item.Item1);
1175
                                        cmd.Parameters.AddWithValue("@NAME", item.Item2);
1176
                                        cmd.Parameters.AddWithValue("@SPPID_SYMBOL_PATH", item.Item3);
1177
                                        cmd.Parameters.AddWithValue("@LEADERLINE", item.Item4);
1178
                                        cmd.ExecuteNonQuery();
1179
                                    }
1180 1421f1d6 gaqhf
                                }
1181 8847ea67 gaqhf
                                transaction.Commit();
1182
                                connection.Close();
1183
                            }
1184
                            catch (Exception ex)
1185
                            {
1186
                                transaction.Rollback();
1187
                            }
1188
                            finally
1189
                            {
1190
                                transaction.Dispose();
1191 1421f1d6 gaqhf
                            }
1192 bca86986 gaqhf
                        }
1193
                    }
1194 8847ea67 gaqhf
                    catch (Exception ex)
1195
                    {
1196
                        return false;
1197
                    }
1198
                    finally
1199
                    {
1200
                        connection.Dispose();
1201
                    }
1202 bca86986 gaqhf
                }
1203 8847ea67 gaqhf
            }
1204
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1205
            {
1206
                using (SqlConnection connection = GetSqlConnection())
1207 bca86986 gaqhf
                {
1208 8847ea67 gaqhf
                    try
1209
                    {
1210
                        if (connection != null && connection.State == ConnectionState.Open)
1211
                        {
1212
1213
                        }
1214
                    }
1215
                    catch (Exception ex)
1216
                    {
1217
1218
                    }
1219
                    finally
1220
                    {
1221
                        if (connection != null)
1222
                            connection.Dispose();
1223
                    }
1224 bca86986 gaqhf
                }
1225
            }
1226
1227
            return true;
1228
        }
1229
1230
        public static bool InsertAttributeMapping(List<Tuple<string, string>> datas)
1231
        {
1232
            Project_Info projectInfo = Project_Info.GetInstance();
1233 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
1234 bca86986 gaqhf
            {
1235 8847ea67 gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
1236 bca86986 gaqhf
                {
1237 8847ea67 gaqhf
                    try
1238 bca86986 gaqhf
                    {
1239 8847ea67 gaqhf
                        connection.Open();
1240
                        using (SQLiteTransaction transaction = connection.BeginTransaction())
1241 1421f1d6 gaqhf
                        {
1242 8847ea67 gaqhf
                            try
1243 1421f1d6 gaqhf
                            {
1244 8847ea67 gaqhf
                                using (SQLiteCommand cmd = connection.CreateCommand())
1245 1421f1d6 gaqhf
                                {
1246 8847ea67 gaqhf
                                    foreach (var item in datas)
1247
                                    {
1248
                                        cmd.Parameters.Clear();
1249
                                        cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, SPPID_ATTRIBUTE) VALUES (@UID, @SPPID_ATTRIBUTE)", SPPID_ATTRIBUTE_MAPPING_TABLE);
1250
                                        cmd.Parameters.AddWithValue("@UID", item.Item1);
1251
                                        cmd.Parameters.AddWithValue("@SPPID_ATTRIBUTE", item.Item2);
1252
                                        cmd.ExecuteNonQuery();
1253
                                    }
1254 1421f1d6 gaqhf
                                }
1255 8847ea67 gaqhf
                                transaction.Commit();
1256
                                connection.Close();
1257
                            }
1258
                            catch (Exception ex)
1259
                            {
1260
                                transaction.Rollback();
1261
                            }
1262
                            finally
1263
                            {
1264
                                transaction.Dispose();
1265 1421f1d6 gaqhf
                            }
1266 bca86986 gaqhf
                        }
1267
                    }
1268 8847ea67 gaqhf
                    catch (Exception ex)
1269
                    {
1270
                        return false;
1271
                    }
1272
                    finally
1273
                    {
1274
                        connection.Dispose();
1275
                    }
1276 bca86986 gaqhf
                }
1277 8847ea67 gaqhf
            }
1278
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1279
            {
1280
                using (SqlConnection connection = GetSqlConnection())
1281 bca86986 gaqhf
                {
1282 8847ea67 gaqhf
                    try
1283
                    {
1284
                        if (connection != null && connection.State == ConnectionState.Open)
1285
                        {
1286
1287
                        }
1288
                    }
1289
                    catch (Exception ex)
1290
                    {
1291
1292
                    }
1293
                    finally
1294
                    {
1295
                        if (connection != null)
1296
                            connection.Dispose();
1297
                    }
1298 bca86986 gaqhf
                }
1299
            }
1300
            return true;
1301
        }
1302 1a3a74a8 gaqhf
1303 cf924377 gaqhf
        public static bool InsertLabelInfoMapping(List<Tuple<string, int, bool>> datas)
1304 1a3a74a8 gaqhf
        {
1305
            Project_Info projectInfo = Project_Info.GetInstance();
1306 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
1307 1a3a74a8 gaqhf
            {
1308 8847ea67 gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
1309 1a3a74a8 gaqhf
                {
1310 8847ea67 gaqhf
                    try
1311 1a3a74a8 gaqhf
                    {
1312 8847ea67 gaqhf
                        connection.Open();
1313
                        using (SQLiteTransaction transaction = connection.BeginTransaction())
1314 1a3a74a8 gaqhf
                        {
1315 8847ea67 gaqhf
                            try
1316 1a3a74a8 gaqhf
                            {
1317 8847ea67 gaqhf
                                using (SQLiteCommand cmd = connection.CreateCommand())
1318 1a3a74a8 gaqhf
                                {
1319 8847ea67 gaqhf
                                    foreach (var item in datas)
1320
                                    {
1321
                                        cmd.Parameters.Clear();
1322
                                        cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, LOCATION, LEADERLINE) VALUES (@UID, @LOCATION, @LEADERLINE)", SPPID_LABEL_INFO_TABLE);
1323
                                        cmd.Parameters.AddWithValue("@UID", item.Item1);
1324
                                        cmd.Parameters.AddWithValue("@LOCATION", item.Item2);
1325
                                        cmd.Parameters.AddWithValue("@LEADERLINE", item.Item3);
1326
                                        cmd.ExecuteNonQuery();
1327
                                    }
1328 1a3a74a8 gaqhf
                                }
1329 8847ea67 gaqhf
                                transaction.Commit();
1330
                                connection.Close();
1331
                            }
1332
                            catch (Exception ex)
1333
                            {
1334
                                transaction.Rollback();
1335
                            }
1336
                            finally
1337
                            {
1338
                                transaction.Dispose();
1339 1a3a74a8 gaqhf
                            }
1340
                        }
1341
                    }
1342 8847ea67 gaqhf
                    catch (Exception ex)
1343
                    {
1344
                        return false;
1345
                    }
1346
                    finally
1347
                    {
1348
                        connection.Dispose();
1349
                    }
1350 1a3a74a8 gaqhf
                }
1351 8847ea67 gaqhf
            }
1352
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1353
            {
1354
                using (SqlConnection connection = GetSqlConnection())
1355 1a3a74a8 gaqhf
                {
1356 8847ea67 gaqhf
                    try
1357
                    {
1358
                        if (connection != null && connection.State == ConnectionState.Open)
1359
                        {
1360
1361
                        }
1362
                    }
1363
                    catch (Exception ex)
1364
                    {
1365
1366
                    }
1367
                    finally
1368
                    {
1369
                        if (connection != null)
1370
                            connection.Dispose();
1371
                    }
1372 1a3a74a8 gaqhf
                }
1373
            }
1374
            return true;
1375
        }
1376 69b7387a gaqhf
1377 154d8f43 gaqhf
        public static bool InsertDrawingInfoAndOPCInfo(string path, string drawingNumber, string drawingName, SPPID.Model.SPPID_Document document)
1378 69b7387a gaqhf
        {
1379
            Project_Info projectInfo = Project_Info.GetInstance();
1380 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
1381 69b7387a gaqhf
            {
1382 8847ea67 gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
1383 69b7387a gaqhf
                {
1384 8847ea67 gaqhf
                    try
1385 69b7387a gaqhf
                    {
1386 8847ea67 gaqhf
                        connection.Open();
1387
                        using (SQLiteTransaction transaction = connection.BeginTransaction())
1388 69b7387a gaqhf
                        {
1389 8847ea67 gaqhf
                            try
1390 154d8f43 gaqhf
                            {
1391
                                using (SQLiteCommand cmd = connection.CreateCommand())
1392
                                {
1393 8847ea67 gaqhf
                                    cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (ID2_DRAWING_UID, PATH, DRAWINGNUMBER, DRAWINGNAME) VALUES (@ID2_DRAWING_UID, @PATH, @DRAWINGNUMBER, @DRAWINGNAME)", SPPID_DRAWING_INFO);
1394 154d8f43 gaqhf
                                    cmd.Parameters.AddWithValue("@ID2_DRAWING_UID", document.UID);
1395 8847ea67 gaqhf
                                    cmd.Parameters.AddWithValue("@PATH", path);
1396
                                    cmd.Parameters.AddWithValue("@DRAWINGNUMBER", drawingNumber);
1397
                                    cmd.Parameters.AddWithValue("@DRAWINGNAME", drawingName);
1398 154d8f43 gaqhf
                                    cmd.ExecuteNonQuery();
1399
                                }
1400
1401 8847ea67 gaqhf
                                List<Symbol> OPCs = document.SYMBOLS.FindAll(x => x.TYPE == "Piping OPC's" || x.TYPE == "Instrument OPC's");
1402
                                foreach (var item in OPCs)
1403
                                {
1404
                                    using (SQLiteCommand cmd = connection.CreateCommand())
1405
                                    {
1406
                                        cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (ID2_OPC_UID, SPPID_OPC_MODELITEM_ID, ID2_DRAWING_UID, ATTRIBUTES, PAIRED) VALUES (@ID2_OPC_UID, @SPPID_OPC_MODELITEM_ID, @ID2_DRAWING_UID, @ATTRIBUTES, @PAIRED)", SPPID_OPC_INFO);
1407
                                        cmd.Parameters.AddWithValue("@ID2_OPC_UID", item.UID);
1408
                                        cmd.Parameters.AddWithValue("@SPPID_OPC_MODELITEM_ID", item.SPPID.ModelItemID);
1409
                                        cmd.Parameters.AddWithValue("@ID2_DRAWING_UID", document.UID);
1410
                                        cmd.Parameters.AddWithValue("@ATTRIBUTES", JsonConvert.SerializeObject(item.SPPID.Attributes));
1411
                                        cmd.Parameters.AddWithValue("@PAIRED", false);
1412
                                        cmd.ExecuteNonQuery();
1413
                                    }
1414
                                }
1415
1416
                                transaction.Commit();
1417
                                connection.Close();
1418
                            }
1419
                            catch (Exception ex)
1420
                            {
1421
                                transaction.Rollback();
1422
                            }
1423
                            finally
1424
                            {
1425
                                transaction.Dispose();
1426
                            }
1427 154d8f43 gaqhf
                        }
1428
                    }
1429 8847ea67 gaqhf
                    catch (Exception ex)
1430
                    {
1431
                        return false;
1432
                    }
1433
                    finally
1434
                    {
1435
                        connection.Dispose();
1436
                    }
1437 154d8f43 gaqhf
                }
1438 8847ea67 gaqhf
            }
1439
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1440
            {
1441
                using (SqlConnection connection = GetSqlConnection())
1442 154d8f43 gaqhf
                {
1443 8847ea67 gaqhf
                    try
1444
                    {
1445
                        if (connection != null && connection.State == ConnectionState.Open)
1446
                        {
1447
1448
                        }
1449
                    }
1450
                    catch (Exception ex)
1451
                    {
1452
1453
                    }
1454
                    finally
1455
                    {
1456
                        if (connection != null)
1457
                            connection.Dispose();
1458
                    }
1459 154d8f43 gaqhf
                }
1460
            }
1461
            return true;
1462
        }
1463
1464
        public static bool InsertOPCInfo(string UID, string ModelItemID, string drawingUID, bool Paired)
1465
        {
1466
            Project_Info projectInfo = Project_Info.GetInstance();
1467 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
1468 154d8f43 gaqhf
            {
1469 8847ea67 gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
1470 154d8f43 gaqhf
                {
1471 8847ea67 gaqhf
                    try
1472 154d8f43 gaqhf
                    {
1473 8847ea67 gaqhf
                        connection.Open();
1474
                        using (SQLiteTransaction transaction = connection.BeginTransaction())
1475 154d8f43 gaqhf
                        {
1476 8847ea67 gaqhf
                            try
1477 154d8f43 gaqhf
                            {
1478 8847ea67 gaqhf
                                using (SQLiteCommand cmd = connection.CreateCommand())
1479
                                {
1480
                                    cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (ID2_OPC_UID, SPPID_OPC_MODELITEM_ID, ID2_DRAWING_UID, PAIRED) VALUES (@ID2_OPC_UID, @SPPID_OPC_MODELITEM_ID, @ID2_DRAWING_UID, @PAIRED)", SPPID_OPC_INFO);
1481
                                    cmd.Parameters.AddWithValue("@ID2_OPC_UID", UID);
1482
                                    cmd.Parameters.AddWithValue("@SPPID_OPC_MODELITEM_ID", ModelItemID);
1483
                                    cmd.Parameters.AddWithValue("@ID2_DRAWING_UID", drawingUID);
1484
                                    cmd.Parameters.AddWithValue("@PAIRED", Paired);
1485
                                    cmd.ExecuteNonQuery();
1486
                                }
1487 154d8f43 gaqhf
1488 8847ea67 gaqhf
                                transaction.Commit();
1489
                                connection.Close();
1490
                            }
1491
                            catch (Exception ex)
1492
                            {
1493
                                transaction.Rollback();
1494
                            }
1495
                            finally
1496
                            {
1497
                                transaction.Dispose();
1498
                            }
1499 69b7387a gaqhf
                        }
1500
                    }
1501 8847ea67 gaqhf
                    catch (Exception ex)
1502
                    {
1503
                        return false;
1504
                    }
1505
                    finally
1506
                    {
1507
                        connection.Dispose();
1508
                    }
1509 69b7387a gaqhf
                }
1510 8847ea67 gaqhf
            }
1511
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1512
            {
1513
                using (SqlConnection connection = GetSqlConnection())
1514 69b7387a gaqhf
                {
1515 8847ea67 gaqhf
                    try
1516
                    {
1517
                        if (connection != null && connection.State == ConnectionState.Open)
1518
                        {
1519
1520
                        }
1521
                    }
1522
                    catch (Exception ex)
1523
                    {
1524
1525
                    }
1526
                    finally
1527
                    {
1528
                        if (connection != null)
1529
                            connection.Dispose();
1530
                    }
1531 69b7387a gaqhf
                }
1532
            }
1533
            return true;
1534
        }
1535 b18dc619 gaqhf
    }
1536
}
클립보드 이미지 추가 (최대 크기: 500 MB)