프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / DB / Project_DB.cs @ 37c2875e

이력 | 보기 | 이력해설 | 다운로드 (137 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 2425d530 gaqhf
using Converter.SPPID;
11
using System.IO;
12 224535bb gaqhf
using Newtonsoft.Json;
13 82ab5276 gaqhf
using Converter.SPPID.Model;
14 6b60e542 Denny
using Converter.SPPID.DB;
15 b18dc619 gaqhf
16 171142c5 gaqhf
namespace Converter.BaseModel
17 b18dc619 gaqhf
{
18 171142c5 gaqhf
    public class Project_DB
19 b18dc619 gaqhf
    {
20 bca86986 gaqhf
        const string SPPID_DB_INFO_TABLE = "T_SPPID_CONNECTION_INFO";
21
        const string SPPID_SYMBOL_MAPPING_TABLE = "T_SPPID_SYMBOL_MAPPING";
22
        const string SPPID_ATTRIBUTE_MAPPING_TABLE = "T_SPPID_ATTRIBUTE_MAPPING";
23 7cbb1038 gaqhf
        const string SPPID_SETTING_TABLE = "T_SPPID_SETTING_TABLE";
24 b8bd98aa gaqhf
        const string SPPID_LABEL_INFO_TABLE = "T_SPPID_LABEL_INFO";
25 e8536f2b gaqhf
        const string SPPID_DRAWING_INFO = "T_SPPID_DRAWING_INFO";
26 154d8f43 gaqhf
        const string SPPID_OPC_INFO = "T_SPPID_OPC_INFO";
27 6b60e542 Denny
        const string SPPID_PIPERUN_PROP_SETTING = "T_SPPID_PIPERUN_PROP_SETTING";
28 306a0af9 gaqhf
        const string ID2_DRAWINGATTRIBUTE_TABLE = "T_ID2_DRAWINGATTRIBUTE";
29 c9264d17 gaqhf
        const string ID2_NOMINALDIAMETER_TABLE = "NominalDiameter";
30 171142c5 gaqhf
31 bca86986 gaqhf
        const string LineProperties_TABLE = "LineProperties";
32
        const string LineTypes_TABLE = "LineTypes";
33
        const string SymbolType_TABLE = "SymbolType";
34
        const string SymbolAttribute_TABLE = "SymbolAttribute";
35
        const string Symbol_TABLE = "Symbol";
36 154d8f43 gaqhf
        const string OPCRelations_TABLE = "OPCRelations";
37 306a0af9 gaqhf
        const string DrawingAttribute_Table = "TitleBlockProperties";
38 171142c5 gaqhf
39 8847ea67 gaqhf
        private static SqlConnection GetSqlConnection()
40 fab4f207 gaqhf
        {
41
            Project_Info projectInfo = Project_Info.GetInstance();
42 8847ea67 gaqhf
            SqlConnection connection = null;
43 fab4f207 gaqhf
            try
44
            {
45 8847ea67 gaqhf
                connection = new SqlConnection(string.Format(CultureInfo.CurrentCulture,
46
                    @"Data Source = {0},{1}; Initial Catalog = {2}; User ID = {3}; Password = {4};",
47
                    projectInfo.ServerIP,
48
                    projectInfo.Port,
49
                    System.IO.Path.GetFileName(projectInfo.DefaultPath),
50
                    projectInfo.DBUser,
51
                    projectInfo.DBPassword));
52
53 fab4f207 gaqhf
                connection.Open();
54
            }
55
            catch (Exception ex)
56
            {
57 2425d530 gaqhf
                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
58 da84b14b gaqhf
                if (connection != null)
59
                    connection.Dispose();
60 8847ea67 gaqhf
                connection = null;
61 fab4f207 gaqhf
            }
62
63 8847ea67 gaqhf
            return connection;
64 fab4f207 gaqhf
        }
65
66 8847ea67 gaqhf
        public static bool ConnTestAndCreateTable()
67 fab4f207 gaqhf
        {
68 8847ea67 gaqhf
            bool result = false;
69 fab4f207 gaqhf
            Project_Info projectInfo = Project_Info.GetInstance();
70 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
71 fab4f207 gaqhf
            {
72 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, @"Data Source = {0}", projectInfo.DBFilePath), true))
73 fab4f207 gaqhf
                {
74 8847ea67 gaqhf
                    try
75 fab4f207 gaqhf
                    {
76 8847ea67 gaqhf
                        connection.Open();
77
                        if (connection.State == ConnectionState.Open)
78
                        {
79
                            using (SQLiteCommand cmd = connection.CreateCommand())
80
                            {
81
                                cmd.CommandText = "SELECT NAME FROM sqlite_master WHERE type='table'";
82
                                using (SQLiteDataReader dr = cmd.ExecuteReader())
83
                                using (DataTable dt = new DataTable())
84
                                {
85
                                    dt.Load(dr);
86
87
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_DB_INFO_TABLE)).Length == 0)
88
                                    {
89
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (JsonString TEXT)", SPPID_DB_INFO_TABLE);
90
                                        cmd.ExecuteNonQuery();
91
                                    }
92
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_SETTING_TABLE)).Length == 0)
93
                                    {
94
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (JsonString TEXT, SettingType TEXT)", SPPID_SETTING_TABLE);
95
                                        cmd.ExecuteNonQuery();
96
                                    }
97
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_SYMBOL_MAPPING_TABLE)).Length == 0)
98
                                    {
99
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, NAME TEXT, SPPID_SYMBOL_PATH TEXT, LEADERLINE BOOLEAN)", SPPID_SYMBOL_MAPPING_TABLE);
100
                                        cmd.ExecuteNonQuery();
101
                                    }
102
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_ATTRIBUTE_MAPPING_TABLE)).Length == 0)
103
                                    {
104
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, SPPID_ATTRIBUTE TEXT)", SPPID_ATTRIBUTE_MAPPING_TABLE);
105
                                        cmd.ExecuteNonQuery();
106
                                    }
107
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_LABEL_INFO_TABLE)).Length == 0)
108
                                    {
109
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, LOCATION INT DEFAULT 0, LEADERLINE BOOLEAN)", SPPID_LABEL_INFO_TABLE);
110
                                        cmd.ExecuteNonQuery();
111
                                    }
112
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_DRAWING_INFO)).Length == 0)
113
                                    {
114
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_DRAWING_UID Text PRIMARY KEY, PATH TEXT, DRAWINGNUMBER TEXT, DRAWINGNAME TEXT)", SPPID_DRAWING_INFO);
115
                                        cmd.ExecuteNonQuery();
116
                                    }
117
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_OPC_INFO)).Length == 0)
118
                                    {
119
                                        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);
120
                                        cmd.ExecuteNonQuery();
121
                                    }
122 6b60e542 Denny
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_PIPERUN_PROP_SETTING)).Length == 0)
123
                                    {
124
                                        cmd.CommandText = string.Format(@"CREATE TABLE {0} (UID TEXT NOT NULL PRIMARY KEY,
125
                                                                          ShowType int NOT NULL,Name TEXT NOT NULL,DisplayName TEXT NOT NULL,TableName TEXT NOT NULL,DataType TEXT NOT NULL,Value TEXT NOT NULL,
126
                                                                          Cond1_Name TEXT NOT NULL,Cond1_DisplayName TEXT NOT NULL,Cond1_TableName TEXT NOT NULL,Cond1_DataType TEXT NOT NULL,Cond1_Value TEXT NOT NULL,
127
                                                                          Cond2_Name TEXT,Cond2_DisplayName TEXT,Cond2_TableName TEXT,Cond2_DataType TEXT,Cond2_Value TEXT,SortOrder int NOT NULL)", SPPID_PIPERUN_PROP_SETTING);
128
                                        cmd.ExecuteNonQuery();
129
                                    }
130 306a0af9 gaqhf
                                    if (dt.Select(string.Format("NAME = '{0}'", ID2_DRAWINGATTRIBUTE_TABLE)).Length == 0)
131
                                    {
132
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, NAME TEXT)", ID2_DRAWINGATTRIBUTE_TABLE);
133
                                        cmd.ExecuteNonQuery();
134
135
                                        List<string> datas = new List<string>() { "Unit", "Rev No", "Drawing No" };
136
                                        foreach (var data in datas)
137
                                        {
138
                                            cmd.CommandText = string.Format("INSERT INTO {0} VALUES('{1}', '{1}')", ID2_DRAWINGATTRIBUTE_TABLE, data);
139
                                            cmd.ExecuteNonQuery();
140
                                        }
141
                                    }
142 8847ea67 gaqhf
                                }
143
144
                                #region Check Column 업데이트시 예비용
145 93c417a9 gaqhf
                                cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_ATTRIBUTE_MAPPING_TABLE);
146
                                using (SQLiteDataReader dr = cmd.ExecuteReader())
147
                                using (DataTable dt = new DataTable())
148
                                {
149
                                    dt.Load(dr);
150
                                    if (!dt.Columns.Contains("ISTEXT"))
151
                                    {
152
                                        cmd.CommandText = string.Format("ALTER TABLE {0} ADD COLUMN ISTEXT BOOLEAN", SPPID_ATTRIBUTE_MAPPING_TABLE);
153
                                        cmd.ExecuteNonQuery();
154
                                    }
155
                                }
156
157 8847ea67 gaqhf
                                cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_SYMBOL_MAPPING_TABLE);
158
                                using (SQLiteDataReader dr = cmd.ExecuteReader())
159
                                using (DataTable dt = new DataTable())
160
                                {
161
                                    dt.Load(dr);
162
                                    if (!dt.Columns.Contains("LEADERLINE"))
163
                                    {
164
                                        cmd.CommandText = string.Format("ALTER TABLE {0} ADD COLUMN LEADERLINE BOOLEAN", SPPID_SYMBOL_MAPPING_TABLE);
165
                                        cmd.ExecuteNonQuery();
166
                                    }
167
                                }
168
169
                                cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_SETTING_TABLE);
170
                                using (SQLiteDataReader dr = cmd.ExecuteReader())
171
                                using (DataTable dt = new DataTable())
172
                                {
173
                                    dt.Load(dr);
174
                                    if (!dt.Columns.Contains("SettingType"))
175
                                    {
176
                                        cmd.CommandText = string.Format("ALTER TABLE {0} ADD COLUMN SettingType Text", SPPID_SETTING_TABLE);
177
                                        cmd.ExecuteNonQuery();
178
                                    }
179
                                }
180 fab4f207 gaqhf
181 8847ea67 gaqhf
                                cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_DRAWING_INFO);
182
                                using (SQLiteDataReader dr = cmd.ExecuteReader())
183
                                using (DataTable dt = new DataTable())
184
                                {
185
                                    dt.Load(dr);
186
                                    if (dt.Columns.Contains("DOCUMENT"))
187
                                    {
188
                                        cmd.CommandText = string.Format("DROP TABLE {0}", SPPID_DRAWING_INFO);
189
                                        cmd.ExecuteNonQuery();
190
191
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_DRAWING_UID Text PRIMARY KEY, PATH TEXT, DRAWINGNUMBER TEXT, DRAWINGNAME TEXT)", SPPID_DRAWING_INFO);
192
                                        cmd.ExecuteNonQuery();
193
                                    }
194
                                }
195
                                #endregion
196
                            }
197
                            result = true;
198
                        }
199
                        connection.Close();
200
                    }
201
                    catch (Exception ex)
202
                    {
203 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
204 8847ea67 gaqhf
                    }
205
                    finally
206
                    {
207
                        connection.Dispose();
208 fab4f207 gaqhf
                    }
209
                }
210
            }
211 8847ea67 gaqhf
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
212 fab4f207 gaqhf
            {
213 8847ea67 gaqhf
                using (SqlConnection connection = GetSqlConnection())
214 fab4f207 gaqhf
                {
215 8847ea67 gaqhf
                    try
216 fab4f207 gaqhf
                    {
217 8847ea67 gaqhf
                        if (connection != null && connection.State == ConnectionState.Open)
218
                        {
219
                            using (SqlCommand cmd = connection.CreateCommand())
220
                            {
221
                                cmd.CommandText = "SELECT TABLE_NAME AS NAME FROM INFORMATION_SCHEMA.TABLES";
222
                                using (SqlDataReader dr = cmd.ExecuteReader())
223
                                using (DataTable dt = new DataTable())
224
                                {
225
                                    dt.Load(dr);
226
227
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_DB_INFO_TABLE)).Length == 0)
228
                                    {
229 d2a7bef1 gaqhf
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (JsonString varchar(MAX))", SPPID_DB_INFO_TABLE);
230 8847ea67 gaqhf
                                        cmd.ExecuteNonQuery();
231
                                    }
232
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_SETTING_TABLE)).Length == 0)
233
                                    {
234 d2a7bef1 gaqhf
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (JsonString varchar(MAX), SettingType varchar(MAX))", SPPID_SETTING_TABLE);
235 8847ea67 gaqhf
                                        cmd.ExecuteNonQuery();
236
                                    }
237
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_SYMBOL_MAPPING_TABLE)).Length == 0)
238
                                    {
239 d2a7bef1 gaqhf
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID varchar(255) PRIMARY KEY, NAME varchar(MAX), SPPID_SYMBOL_PATH varchar(MAX), LEADERLINE BIT)", SPPID_SYMBOL_MAPPING_TABLE);
240 8847ea67 gaqhf
                                        cmd.ExecuteNonQuery();
241
                                    }
242
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_ATTRIBUTE_MAPPING_TABLE)).Length == 0)
243
                                    {
244 d2a7bef1 gaqhf
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID varchar(255) PRIMARY KEY, SPPID_ATTRIBUTE varchar(MAX))", SPPID_ATTRIBUTE_MAPPING_TABLE);
245 8847ea67 gaqhf
                                        cmd.ExecuteNonQuery();
246
                                    }
247
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_LABEL_INFO_TABLE)).Length == 0)
248
                                    {
249
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID varchar(255) PRIMARY KEY, LOCATION INT DEFAULT 0, LEADERLINE BIT)", SPPID_LABEL_INFO_TABLE);
250
                                        cmd.ExecuteNonQuery();
251
                                    }
252
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_DRAWING_INFO)).Length == 0)
253
                                    {
254 d2a7bef1 gaqhf
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_DRAWING_UID varchar(255) PRIMARY KEY, PATH varchar(MAX), DRAWINGNUMBER varchar(MAX), DRAWINGNAME varchar(MAX))", SPPID_DRAWING_INFO);
255 8847ea67 gaqhf
                                        cmd.ExecuteNonQuery();
256
                                    }
257
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_OPC_INFO)).Length == 0)
258
                                    {
259 d2a7bef1 gaqhf
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_OPC_UID varchar(255) PRIMARY KEY, SPPID_OPC_MODELITEM_ID varchar(MAX), ID2_DRAWING_UID varchar(MAX), ATTRIBUTES varchar(MAX), PAIRED BIT)", SPPID_OPC_INFO);
260 8847ea67 gaqhf
                                        cmd.ExecuteNonQuery();
261
                                    }
262 6b60e542 Denny
                                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_PIPERUN_PROP_SETTING)).Length == 0)
263
                                    {
264
                                        cmd.CommandText = string.Format(@"CREATE TABLE {0} (UID nvarchar(36) NOT NULL PRIMARY KEY,
265
                                                                          ShowType int NOT NULL,Name nvarchar(255) NOT NULL,DisplayName nvarchar(255) NOT NULL,TableName nvarchar(255) NOT NULL,DataType nvarchar(6) NOT NULL,Value nvarchar(255) NOT NULL,
266
                                                                          Cond1_Name nvarchar(255) NOT NULL,Cond1_DisplayName nvarchar(255) NOT NULL,Cond1_TableName nvarchar(255) NOT NULL,Cond1_DataType nvarchar(6) NOT NULL,Cond1_Value nvarchar(255) NOT NULL,
267
                                                                          Cond2_Name nvarchar(255),Cond2_DisplayName nvarchar(255),Cond2_TableName nvarchar(255),Cond2_DataType nvarchar(6),Cond2_Value nvarchar(255),SortOrder int NOT NULL)", SPPID_PIPERUN_PROP_SETTING);
268
                                        cmd.ExecuteNonQuery();
269
                                    }
270 306a0af9 gaqhf
                                    if (dt.Select(string.Format("NAME = '{0}'", ID2_DRAWINGATTRIBUTE_TABLE)).Length == 0)
271
                                    {
272
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID varchar(255) PRIMARY KEY, NAME varchar(255))", ID2_DRAWINGATTRIBUTE_TABLE);
273
                                        cmd.ExecuteNonQuery();
274
275
                                        List<string> datas = new List<string>() { "Unit", "Rev No", "Drawing No" };
276
                                        foreach (var data in datas)
277
                                        {
278
                                            cmd.CommandText = string.Format("INSERT INTO {0} VALUES('{1}', '{1}')", ID2_DRAWINGATTRIBUTE_TABLE, data);
279
                                            cmd.ExecuteNonQuery();
280
                                        }
281
                                    }
282 8847ea67 gaqhf
                                }
283
284
                                #region Check Column 업데이트시 예비용
285 923501a9 gaqhf
                                cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_ATTRIBUTE_MAPPING_TABLE);
286
                                using (SqlDataReader dr = cmd.ExecuteReader())
287
                                using (DataTable dt = new DataTable())
288
                                {
289
                                    dt.Load(dr);
290
                                    if (!dt.Columns.Contains("ISTEXT"))
291
                                    {
292
                                        cmd.CommandText = string.Format("ALTER TABLE {0} ADD ISTEXT BIT", SPPID_ATTRIBUTE_MAPPING_TABLE);
293
                                        cmd.ExecuteNonQuery();
294
                                    }
295
                                }
296 8847ea67 gaqhf
                                #endregion
297
                            }
298
                            result = true;
299
                        }
300 fab4f207 gaqhf
                    }
301 8847ea67 gaqhf
                    catch (Exception ex)
302
                    {
303 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
304 8847ea67 gaqhf
                    }
305
                    finally
306
                    {
307
                        if (connection != null)
308
                            connection.Dispose();
309
                    }
310 fab4f207 gaqhf
                }
311
            }
312
313 8847ea67 gaqhf
            return result;
314 fab4f207 gaqhf
        }
315
316 8847ea67 gaqhf
        public static bool SaveSPPID_DB_INFO(string jsonString)
317 e00e891d gaqhf
        {
318
            Project_Info projectInfo = Project_Info.GetInstance();
319 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
320 e00e891d gaqhf
            {
321 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
322 e00e891d gaqhf
                {
323
324 8847ea67 gaqhf
                    try
325
                    {
326
                        connection.Open();
327
                        using (SQLiteCommand cmd = connection.CreateCommand())
328 7cbb1038 gaqhf
                        {
329 8847ea67 gaqhf
                            cmd.CommandText = string.Format("DELETE FROM {0}", SPPID_DB_INFO_TABLE);
330
                            cmd.ExecuteNonQuery();
331
332
                            cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@jsonString)", SPPID_DB_INFO_TABLE);
333
                            cmd.Parameters.AddWithValue("@jsonString", jsonString);
334 7cbb1038 gaqhf
                            cmd.ExecuteNonQuery();
335
                        }
336 8847ea67 gaqhf
                        connection.Close();
337
                    }
338
                    catch (Exception ex)
339
                    {
340 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
341 8847ea67 gaqhf
                        return false;
342
                    }
343
                    finally
344
                    {
345
                        connection.Dispose();
346 e00e891d gaqhf
                    }
347
                }
348 8847ea67 gaqhf
            }
349
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
350
            {
351
                using (SqlConnection connection = GetSqlConnection())
352 e00e891d gaqhf
                {
353 8847ea67 gaqhf
                    try
354
                    {
355
                        if (connection != null && connection.State == ConnectionState.Open)
356
                        {
357 d2a7bef1 gaqhf
                            using (SqlCommand cmd = connection.CreateCommand())
358
                            {
359
                                cmd.CommandText = string.Format("DELETE FROM {0}", SPPID_DB_INFO_TABLE);
360
                                cmd.ExecuteNonQuery();
361 8847ea67 gaqhf
362 d2a7bef1 gaqhf
                                cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@jsonString)", SPPID_DB_INFO_TABLE);
363
                                cmd.Parameters.AddWithValue("@jsonString", jsonString);
364
                                cmd.ExecuteNonQuery();
365
                            }
366
                            connection.Close();
367
                        }
368
                        else
369
                        {
370
                            return false;
371 8847ea67 gaqhf
                        }
372
                    }
373
                    catch (Exception ex)
374
                    {
375 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
376 d2a7bef1 gaqhf
                        return false;
377 8847ea67 gaqhf
                    }
378
                    finally
379
                    {
380
                        if (connection != null)
381
                            connection.Dispose();
382
                    }
383 e00e891d gaqhf
                }
384
            }
385
386 8847ea67 gaqhf
387 e00e891d gaqhf
            return true;
388
        }
389
390 8847ea67 gaqhf
        public static DataTable SelectSPPID_DB_INFO()
391 e00e891d gaqhf
        {
392
            DataTable dt = new DataTable();
393
            Project_Info projectInfo = Project_Info.GetInstance();
394 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
395 e00e891d gaqhf
            {
396 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
397 e00e891d gaqhf
                {
398 8847ea67 gaqhf
                    try
399 e00e891d gaqhf
                    {
400 8847ea67 gaqhf
                        connection.Open();
401
                        using (SQLiteCommand cmd = connection.CreateCommand())
402
                        {
403
                            cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_DB_INFO_TABLE);
404
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
405
                                dt.Load(dr);
406
                        }
407
                        connection.Close();
408 e00e891d gaqhf
                    }
409 8847ea67 gaqhf
                    catch (Exception ex)
410
                    {
411 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
412 8847ea67 gaqhf
                    }
413
                    finally
414
                    {
415
                        connection.Dispose();
416
                    }
417 e00e891d gaqhf
                }
418 8847ea67 gaqhf
            }
419
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
420
            {
421
                using (SqlConnection connection = GetSqlConnection())
422 e00e891d gaqhf
                {
423 8847ea67 gaqhf
                    try
424
                    {
425
                        if (connection != null && connection.State == ConnectionState.Open)
426
                        {
427 d2a7bef1 gaqhf
                            using (SqlCommand cmd = connection.CreateCommand())
428
                            {
429
                                cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_DB_INFO_TABLE);
430
                                using (SqlDataReader dr = cmd.ExecuteReader())
431
                                    dt.Load(dr);
432
                            }
433
                            connection.Close();
434 8847ea67 gaqhf
                        }
435
                    }
436
                    catch (Exception ex)
437
                    {
438 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
439 8847ea67 gaqhf
                    }
440
                    finally
441
                    {
442
                        if (connection != null)
443
                            connection.Dispose();
444
                    }
445 e00e891d gaqhf
                }
446
            }
447
448
            return dt;
449
        }
450
451 8847ea67 gaqhf
        public static bool SaveETCSetting(Dictionary<string,string> dicSetting)
452 fab4f207 gaqhf
        {
453 8847ea67 gaqhf
            Project_Info projectInfo = Project_Info.GetInstance();
454
            if (projectInfo.DBType == ID2DB_Type.SQLite)
455 fab4f207 gaqhf
            {
456 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
457 fab4f207 gaqhf
                {
458
459 8847ea67 gaqhf
                    try
460 e00e891d gaqhf
                    {
461 8847ea67 gaqhf
                        connection.Open();
462
                        using (SQLiteCommand cmd = connection.CreateCommand())
463
                        {
464
                            cmd.CommandText = string.Format("DELETE FROM {0}", SPPID_SETTING_TABLE);
465
                            cmd.ExecuteNonQuery();
466
467
                            foreach (var item in dicSetting)
468
                            {
469
                                cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@jsonString, @SettingType)", SPPID_SETTING_TABLE);
470 f4485671 gaqhf
                                cmd.Parameters.Clear();
471 8847ea67 gaqhf
                                cmd.Parameters.AddWithValue("@jsonString", item.Value);
472
                                cmd.Parameters.AddWithValue("@SettingType", item.Key);
473
                                cmd.ExecuteNonQuery();
474
                            }
475
                        }
476
                        connection.Close();
477 e00e891d gaqhf
                    }
478 8847ea67 gaqhf
                    catch (Exception ex)
479 bca86986 gaqhf
                    {
480 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
481 8847ea67 gaqhf
                        return false;
482 bca86986 gaqhf
                    }
483 8847ea67 gaqhf
                    finally
484 bca86986 gaqhf
                    {
485 8847ea67 gaqhf
                        connection.Dispose();
486 bca86986 gaqhf
                    }
487 8847ea67 gaqhf
                }
488
            }
489
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
490
            {
491
                using (SqlConnection connection = GetSqlConnection())
492
                {
493
                    try
494 1a3a74a8 gaqhf
                    {
495 8847ea67 gaqhf
                        if (connection != null && connection.State == ConnectionState.Open)
496
                        {
497 d2a7bef1 gaqhf
                            using (SqlCommand cmd = connection.CreateCommand())
498
                            {
499
                                cmd.CommandText = string.Format("DELETE FROM {0}", SPPID_SETTING_TABLE);
500
                                cmd.ExecuteNonQuery();
501 8847ea67 gaqhf
502 d2a7bef1 gaqhf
                                foreach (var item in dicSetting)
503
                                {
504
                                    cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@jsonString, @SettingType)", SPPID_SETTING_TABLE);
505 f4485671 gaqhf
                                    cmd.Parameters.Clear();
506 d2a7bef1 gaqhf
                                    cmd.Parameters.AddWithValue("@jsonString", item.Value);
507
                                    cmd.Parameters.AddWithValue("@SettingType", item.Key);
508
                                    cmd.ExecuteNonQuery();
509
                                }
510
                            }
511
                            connection.Close();
512 8847ea67 gaqhf
                        }
513 d2a7bef1 gaqhf
                        else
514
                            return false;
515 1a3a74a8 gaqhf
                    }
516 8847ea67 gaqhf
                    catch (Exception ex)
517 e8536f2b gaqhf
                    {
518 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
519 d2a7bef1 gaqhf
                        return false;
520 154d8f43 gaqhf
                    }
521 8847ea67 gaqhf
                    finally
522 154d8f43 gaqhf
                    {
523 8847ea67 gaqhf
                        if (connection != null)
524
                            connection.Dispose();
525 e8536f2b gaqhf
                    }
526 fab4f207 gaqhf
                }
527 8847ea67 gaqhf
            }
528 cf924377 gaqhf
529 8847ea67 gaqhf
            return true;
530
        }
531 6b60e542 Denny
        public static bool SavePipeRunPropSetting(List<SPPID_PipeRunPropSetting> setting)
532
        {
533
            Project_Info projectInfo = Project_Info.GetInstance();
534
            if (projectInfo.DBType == ID2DB_Type.SQLite)
535
            {
536
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
537
                {
538
                    try
539
                    {
540
                        connection.Open();
541
                        using (SQLiteCommand cmd = connection.CreateCommand())
542
                        {
543
                            cmd.CommandText = string.Format("DELETE FROM {0}", SPPID_PIPERUN_PROP_SETTING);
544
                            cmd.ExecuteNonQuery();
545
546
                            foreach (var item in setting)
547
                            {
548
                                cmd.CommandText = string.Format(@"INSERT INTO {0} 
549
                                                  (UID,ShowType,Name,DisplayName,TableName,DataType,Value,Cond1_Name,Cond1_DisplayName,Cond1_TableName,Cond1_DataType,Cond1_Value,Cond2_Name,Cond2_DisplayName,Cond2_TableName,Cond2_DataType,Cond2_Value,SortOrder)
550
                                                  VALUES
551
                                                  (@UID,@ShowType,@Name,@DisplayName,@TableName,@DataType,@Value,@Cond1_Name,@Cond1_DisplayName,@Cond1_TableName,@Cond1_DataType,@Cond1_Value,@Cond2_Name,@Cond2_DisplayName,@Cond2_TableName,@Cond2_DataType,@Cond2_Value,@SortOrder)"
552
                                                   , SPPID_PIPERUN_PROP_SETTING);
553
                                cmd.Parameters.Clear();
554
                                cmd.Parameters.AddWithValue("@UID"                  , item.UID);
555
                                cmd.Parameters.AddWithValue("@ShowType"             , item.ShowType);
556
                                cmd.Parameters.AddWithValue("@Name"                 , item.Name);
557
                                cmd.Parameters.AddWithValue("@DisplayName"          , item.DisplayName);
558
                                cmd.Parameters.AddWithValue("@TableName"            , item.TableName);
559
                                cmd.Parameters.AddWithValue("@DataType"             , item.DataType);
560
                                cmd.Parameters.AddWithValue("@Value"                , item.Value);
561
                                cmd.Parameters.AddWithValue("@Cond1_Name"           , item.Cond1_Name);
562
                                cmd.Parameters.AddWithValue("@Cond1_DisplayName"    , item.Cond1_DisplayName);
563
                                cmd.Parameters.AddWithValue("@Cond1_TableName"      , item.Cond1_TableName);
564
                                cmd.Parameters.AddWithValue("@Cond1_DataType"       , item.Cond1_DataType);
565
                                cmd.Parameters.AddWithValue("@Cond1_Value"          , item.Cond1_Value);
566
                                cmd.Parameters.AddWithValue("@Cond2_Name"           , item.Cond2_Name);
567
                                cmd.Parameters.AddWithValue("@Cond2_DisplayName"    , item.Cond2_DisplayName);
568
                                cmd.Parameters.AddWithValue("@Cond2_TableName"      , item.Cond2_TableName);
569
                                cmd.Parameters.AddWithValue("@Cond2_DataType"       , item.Cond2_DataType);
570
                                cmd.Parameters.AddWithValue("@Cond2_Value"          , item.Cond2_Value);
571
                                cmd.Parameters.AddWithValue("@SortOrder"            , item.SortOrder);
572
                                cmd.ExecuteNonQuery();
573
                            }
574
                        }
575
                        connection.Close();
576
                    }
577
                    catch (Exception ex)
578
                    {
579
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
580
                        return false;
581
                    }
582
                    finally
583
                    {
584
                        connection.Dispose();
585
                    }
586
                }
587
            }
588
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
589
            {
590
                using (SqlConnection connection = GetSqlConnection())
591
                {
592
                    try
593
                    {
594
                        if (connection != null && connection.State == ConnectionState.Open)
595
                        {
596
                            using (SqlCommand cmd = connection.CreateCommand())
597
                            {
598
                                cmd.CommandText = string.Format("DELETE FROM {0}", SPPID_PIPERUN_PROP_SETTING);
599
                                cmd.ExecuteNonQuery();
600
601
                                foreach (var item in setting)
602
                                {
603
                                    cmd.CommandText = string.Format(@"INSERT INTO {0} 
604
                                                  (UID,ShowType,Name,DisplayName,TableName,DataType,Value,Cond1_Name,Cond1_DisplayName,Cond1_TableName,Cond1_DataType,Cond1_Value,Cond2_Name,Cond2_DisplayName,Cond2_TableName,Cond2_DataType,Cond2_Value,SortOrder)
605
                                                  VALUES
606
                                                  (@UID,@ShowType,@Name,@DisplayName,@TableName,@DataType,@Value,@Cond1_Name,@Cond1_DisplayName,@Cond1_TableName,@Cond1_DataType,@Cond1_Value,@Cond2_Name,@Cond2_DisplayName,@Cond2_TableName,@Cond2_DataType,@Cond2_Value,@SortOrder)"
607
                                                   , SPPID_PIPERUN_PROP_SETTING);
608
                                    cmd.Parameters.Clear();
609
                                    cmd.Parameters.AddWithValue("@UID"                  , item.UID);
610
                                    cmd.Parameters.AddWithValue("@ShowType"             , item.ShowType);
611
                                    cmd.Parameters.AddWithValue("@Name"                 , item.Name);
612
                                    cmd.Parameters.AddWithValue("@DisplayName"          , item.DisplayName);
613
                                    cmd.Parameters.AddWithValue("@TableName"            , item.TableName);
614
                                    cmd.Parameters.AddWithValue("@DataType"             , item.DataType);
615
                                    cmd.Parameters.AddWithValue("@Value"                , item.Value);
616
                                    cmd.Parameters.AddWithValue("@Cond1_Name"           , item.Cond1_Name);
617
                                    cmd.Parameters.AddWithValue("@Cond1_DisplayName"    , item.Cond1_DisplayName);
618
                                    cmd.Parameters.AddWithValue("@Cond1_TableName"      , item.Cond1_TableName);
619
                                    cmd.Parameters.AddWithValue("@Cond1_DataType"       , item.Cond1_DataType);
620
                                    cmd.Parameters.AddWithValue("@Cond1_Value"          , item.Cond1_Value);
621
                                    cmd.Parameters.AddWithValue("@Cond2_Name"           , item.Cond2_Name);
622
                                    cmd.Parameters.AddWithValue("@Cond2_DisplayName"    , item.Cond2_DisplayName);
623
                                    cmd.Parameters.AddWithValue("@Cond2_TableName"      , item.Cond2_TableName);
624
                                    cmd.Parameters.AddWithValue("@Cond2_DataType"       , item.Cond2_DataType);
625
                                    cmd.Parameters.AddWithValue("@Cond2_Value"          , item.Cond2_Value);
626
                                    cmd.Parameters.AddWithValue("@SortOrder"            , item.SortOrder);
627
                                cmd.ExecuteNonQuery();
628
                                }
629
                            }
630
                            connection.Close();
631
                        }
632
                        else
633
                            return false;
634
                    }
635
                    catch (Exception ex)
636
                    {
637
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
638
                        return false;
639
                    }
640
                    finally
641
                    {
642
                        if (connection != null)
643
                            connection.Dispose();
644
                    }
645
                }
646
            }
647
648
            return true;
649
        }
650 8847ea67 gaqhf
651
        public static DataTable SelectSetting()
652
        {
653
            DataTable dt = new DataTable();
654
            Project_Info projectInfo = Project_Info.GetInstance();
655
            if (projectInfo.DBType == ID2DB_Type.SQLite)
656
            {
657 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
658 cf924377 gaqhf
                {
659 8847ea67 gaqhf
                    try
660 cf924377 gaqhf
                    {
661 8847ea67 gaqhf
                        connection.Open();
662
                        using (SQLiteCommand cmd = connection.CreateCommand())
663
                        {
664
                            cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_SETTING_TABLE);
665
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
666
                                dt.Load(dr);
667
                        }
668
                        connection.Close();
669 cf924377 gaqhf
                    }
670 8847ea67 gaqhf
                    catch (Exception ex)
671
                    {
672 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
673 8847ea67 gaqhf
                    }
674
                    finally
675 7cbb1038 gaqhf
                    {
676 8847ea67 gaqhf
                        connection.Dispose();
677 7cbb1038 gaqhf
                    }
678
                }
679 8847ea67 gaqhf
            }
680
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
681
            {
682
                using (SqlConnection connection = GetSqlConnection())
683 224535bb gaqhf
                {
684 8847ea67 gaqhf
                    try
685
                    {
686
                        if (connection != null && connection.State == ConnectionState.Open)
687
                        {
688 d2a7bef1 gaqhf
                            using (SqlCommand cmd = connection.CreateCommand())
689
                            {
690
                                cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_SETTING_TABLE);
691
                                using (SqlDataReader dr = cmd.ExecuteReader())
692
                                    dt.Load(dr);
693
                            }
694
                            connection.Close();
695 8847ea67 gaqhf
                        }
696
                    }
697
                    catch (Exception ex)
698 224535bb gaqhf
                    {
699 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
700 8847ea67 gaqhf
                    }
701
                    finally
702
                    {
703
                        if (connection != null)
704
                            connection.Dispose();
705 224535bb gaqhf
                    }
706
                }
707 fab4f207 gaqhf
            }
708 8847ea67 gaqhf
709
            return dt;
710 fab4f207 gaqhf
        }
711 bca86986 gaqhf
712
        public static DataTable SelectProjectSymbol()
713
        {
714
            DataTable dt = new DataTable();
715
            Project_Info projectInfo = Project_Info.GetInstance();
716 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
717 bca86986 gaqhf
            {
718 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
719 bca86986 gaqhf
                {
720 8847ea67 gaqhf
                    try
721 bca86986 gaqhf
                    {
722 8847ea67 gaqhf
                        connection.Open();
723
                        using (SQLiteCommand cmd = connection.CreateCommand())
724
                        {
725
                            cmd.CommandText = string.Format(@"
726 cf924377 gaqhf
                            SELECT s.UID, s.Name, st.Type, sp.SPPID_SYMBOL_PATH, sp.LEADERLINE FROM {1} as st, {0} as s 
727 bca86986 gaqhf
                                LEFT OUTER JOIN {2} as sp 
728
                                    ON s.UID = SP.UID 
729
                            WHERE s.SymbolType_UID = st.UID 
730
                            ORDER BY st.TYPE ASC;", Symbol_TABLE, SymbolType_TABLE, SPPID_SYMBOL_MAPPING_TABLE);
731 8847ea67 gaqhf
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
732
                                dt.Load(dr);
733 310aeb31 gaqhf
734 8847ea67 gaqhf
                            DataTable dtClone = dt.Clone();
735
                            dtClone.Columns["UID"].DataType = typeof(string);
736
                            foreach (DataRow row in dt.Rows)
737
                            {
738
                                dtClone.ImportRow(row);
739
                            }
740
                            dt.Dispose();
741
                            dt = dtClone;
742 310aeb31 gaqhf
                        }
743 8847ea67 gaqhf
                        connection.Close();
744 bca86986 gaqhf
                    }
745 8847ea67 gaqhf
                    catch (Exception ex)
746
                    {
747 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
748 8847ea67 gaqhf
                    }
749
                    finally
750
                    {
751
                        connection.Dispose();
752
                    }
753 bca86986 gaqhf
                }
754 8847ea67 gaqhf
            }
755
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
756
            {
757
                using (SqlConnection connection = GetSqlConnection())
758 bca86986 gaqhf
                {
759 8847ea67 gaqhf
                    try
760
                    {
761
                        if (connection != null && connection.State == ConnectionState.Open)
762
                        {
763 d2a7bef1 gaqhf
                            using (SqlCommand cmd = connection.CreateCommand())
764
                            {
765
                                cmd.CommandText = string.Format(@"
766 a2c803a0 gaqhf
                            SELECT CONVERT(VARCHAR(255), s.UID) AS UID, s.Name, st.Type, sp.SPPID_SYMBOL_PATH, sp.LEADERLINE FROM {1} as st, {0} as s 
767 d2a7bef1 gaqhf
                                LEFT OUTER JOIN {2} as sp 
768 a2c803a0 gaqhf
                                    ON CONVERT(VARCHAR(255), s.UID) = CONVERT(VARCHAR(255), SP.UID)
769 d2a7bef1 gaqhf
                            WHERE s.SymbolType_UID = st.UID 
770
                            ORDER BY st.TYPE ASC;", Symbol_TABLE, SymbolType_TABLE, SPPID_SYMBOL_MAPPING_TABLE);
771
                                using (SqlDataReader dr = cmd.ExecuteReader())
772
                                    dt.Load(dr);
773
                            }
774
                            connection.Close();
775 8847ea67 gaqhf
                        }
776
                    }
777
                    catch (Exception ex)
778
                    {
779 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
780 8847ea67 gaqhf
                    }
781
                    finally
782
                    {
783
                        if (connection != null)
784
                            connection.Dispose();
785
                    }
786 bca86986 gaqhf
                }
787
            }
788
789
            return dt;
790
        }
791
792 4b4dbca9 gaqhf
        public static DataTable SelectProjectChildSymbol()
793
        {
794
            DataTable result = new DataTable();
795
            result.Columns.Add("UID");
796
            result.Columns.Add("Name");
797
            result.Columns.Add("Type");
798
            result.Columns.Add("SPPID_SYMBOL_PATH");
799
            
800
            Project_Info projectInfo = Project_Info.GetInstance();
801 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
802 4b4dbca9 gaqhf
            {
803 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
804 8847ea67 gaqhf
                using (DataTable dt = new DataTable())
805 4b4dbca9 gaqhf
                {
806 8847ea67 gaqhf
                    try
807 4b4dbca9 gaqhf
                    {
808 8847ea67 gaqhf
                        connection.Open();
809
                        using (SQLiteCommand cmd = connection.CreateCommand())
810
                        {
811
                            cmd.CommandText = string.Format(@"
812 4b4dbca9 gaqhf
                            SELECT AdditionalSymbol FROM Symbol");
813 8847ea67 gaqhf
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
814
                                dt.Load(dr);
815
                            List<string> childList = new List<string>();
816
                            foreach (DataRow row in dt.Rows)
817 4b4dbca9 gaqhf
                            {
818 8847ea67 gaqhf
                                if (row["AdditionalSymbol"] != null && !DBNull.Value.Equals(row["AdditionalSymbol"]) && !string.IsNullOrEmpty((string)row["AdditionalSymbol"]))
819 4b4dbca9 gaqhf
                                {
820 8847ea67 gaqhf
                                    string[] array = row["AdditionalSymbol"].ToString().Split(new char[] { '/' });
821
                                    foreach (var childString in array)
822
                                    {
823
                                        childList.Add(childString.Split(new char[] { ',' })[2]);
824
                                    }
825 4b4dbca9 gaqhf
                                }
826
827 8847ea67 gaqhf
                            }
828 4b4dbca9 gaqhf
829 8847ea67 gaqhf
                            dt.Clear();
830
                            cmd.Reset();
831
                            cmd.CommandText = string.Format(@"
832 4b4dbca9 gaqhf
                            SELECT * FROM {0}", SPPID_SYMBOL_MAPPING_TABLE);
833 8847ea67 gaqhf
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
834
                                dt.Load(dr);
835 4b4dbca9 gaqhf
836 8847ea67 gaqhf
                            childList = childList.Distinct().ToList();
837
                            foreach (var child in childList)
838
                            {
839
                                string mappingPath = string.Empty;
840
                                DataRow[] rows = dt.Select(string.Format("UID = '{0}'", child));
841
                                if (rows.Length == 1)
842
                                    mappingPath = !DBNull.Value.Equals(rows[0]["SPPID_SYMBOL_PATH"]) ? (string)rows[0]["SPPID_SYMBOL_PATH"] : null;
843
844
                                DataRow newRow = result.NewRow();
845
                                newRow["UID"] = child;
846
                                newRow["Name"] = child;
847
                                newRow["Type"] = "Child Symbol";
848
                                newRow["SPPID_SYMBOL_PATH"] = mappingPath;
849
                                result.Rows.Add(newRow);
850
                            }
851 4b4dbca9 gaqhf
                        }
852 8847ea67 gaqhf
                        connection.Close();
853 4b4dbca9 gaqhf
                    }
854 8847ea67 gaqhf
                    catch (Exception ex)
855
                    {
856 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
857 8847ea67 gaqhf
                    }
858
                    finally
859
                    {
860
                        connection.Dispose();
861
                    }
862 4b4dbca9 gaqhf
                }
863 8847ea67 gaqhf
            }
864
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
865
            {
866
                using (SqlConnection connection = GetSqlConnection())
867 d2a7bef1 gaqhf
                using (DataTable dt = new DataTable())
868 4b4dbca9 gaqhf
                {
869 8847ea67 gaqhf
                    try
870
                    {
871
                        if (connection != null && connection.State == ConnectionState.Open)
872
                        {
873 d2a7bef1 gaqhf
                            using (SqlCommand cmd = connection.CreateCommand())
874
                            {
875
                                cmd.CommandText = string.Format(@"
876
                            SELECT AdditionalSymbol FROM Symbol");
877
                                using (SqlDataReader dr = cmd.ExecuteReader())
878
                                    dt.Load(dr);
879
                                List<string> childList = new List<string>();
880
                                foreach (DataRow row in dt.Rows)
881
                                {
882
                                    if (row["AdditionalSymbol"] != null && !DBNull.Value.Equals(row["AdditionalSymbol"]) && !string.IsNullOrEmpty((string)row["AdditionalSymbol"]))
883
                                    {
884
                                        string[] array = row["AdditionalSymbol"].ToString().Split(new char[] { '/' });
885
                                        foreach (var childString in array)
886
                                        {
887
                                            childList.Add(childString.Split(new char[] { ',' })[2]);
888
                                        }
889
                                    }
890
891
                                }
892
893
                                dt.Clear();
894
                                cmd.CommandText = string.Format(@"
895
                            SELECT * FROM {0}", SPPID_SYMBOL_MAPPING_TABLE);
896
                                using (SqlDataReader dr = cmd.ExecuteReader())
897
                                    dt.Load(dr);
898 8847ea67 gaqhf
899 d2a7bef1 gaqhf
                                childList = childList.Distinct().ToList();
900
                                foreach (var child in childList)
901
                                {
902
                                    string mappingPath = string.Empty;
903
                                    DataRow[] rows = dt.Select(string.Format("UID = '{0}'", child));
904
                                    if (rows.Length == 1)
905
                                        mappingPath = !DBNull.Value.Equals(rows[0]["SPPID_SYMBOL_PATH"]) ? (string)rows[0]["SPPID_SYMBOL_PATH"] : null;
906
907
                                    DataRow newRow = result.NewRow();
908
                                    newRow["UID"] = child;
909
                                    newRow["Name"] = child;
910
                                    newRow["Type"] = "Child Symbol";
911
                                    newRow["SPPID_SYMBOL_PATH"] = mappingPath;
912
                                    result.Rows.Add(newRow);
913
                                }
914
                            }
915
                            connection.Close();
916 8847ea67 gaqhf
                        }
917
                    }
918
                    catch (Exception ex)
919
                    {
920 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
921 8847ea67 gaqhf
                    }
922
                    finally
923
                    {
924
                        if (connection != null)
925
                            connection.Dispose();
926
                    }
927 4b4dbca9 gaqhf
                }
928
            }
929
            return result;
930
        }
931
932 bca86986 gaqhf
        public static DataTable SelectProjectLine()
933
        {
934
            DataTable dt = new DataTable();
935
            Project_Info projectInfo = Project_Info.GetInstance();
936 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
937 bca86986 gaqhf
            {
938 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
939 bca86986 gaqhf
                {
940 8847ea67 gaqhf
                    try
941 bca86986 gaqhf
                    {
942 8847ea67 gaqhf
                        connection.Open();
943
                        using (SQLiteCommand cmd = connection.CreateCommand())
944
                        {
945
                            cmd.CommandText = string.Format(@"
946 bca86986 gaqhf
                            SELECT l.UID, l.Name, sp.SPPID_SYMBOL_PATH FROM {0} as l 
947
                                LEFT OUTER JOIN {1} as sp 
948
                                    ON l.UID = SP.UID ;", LineTypes_TABLE, SPPID_SYMBOL_MAPPING_TABLE);
949 8847ea67 gaqhf
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
950
                                dt.Load(dr);
951
                        }
952
                        connection.Close();
953 bca86986 gaqhf
                    }
954 8847ea67 gaqhf
                    catch (Exception ex)
955
                    {
956 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
957 8847ea67 gaqhf
                    }
958
                    finally
959
                    {
960
                        connection.Dispose();
961
                    }
962 bca86986 gaqhf
                }
963 8847ea67 gaqhf
            }
964
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
965
            {
966
                using (SqlConnection connection = GetSqlConnection())
967 bca86986 gaqhf
                {
968 8847ea67 gaqhf
                    try
969
                    {
970
                        if (connection != null && connection.State == ConnectionState.Open)
971
                        {
972 d2a7bef1 gaqhf
                            using (SqlCommand cmd = connection.CreateCommand())
973
                            {
974
                                cmd.CommandText = string.Format(@"
975
                            SELECT l.UID, l.Name, sp.SPPID_SYMBOL_PATH FROM {0} as l 
976
                                LEFT OUTER JOIN {1} as sp 
977
                                    ON l.UID = SP.UID ;", LineTypes_TABLE, SPPID_SYMBOL_MAPPING_TABLE);
978
                                using (SqlDataReader dr = cmd.ExecuteReader())
979
                                    dt.Load(dr);
980
                            }
981
                            connection.Close();
982 8847ea67 gaqhf
                        }
983
                    }
984
                    catch (Exception ex)
985
                    {
986 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
987 8847ea67 gaqhf
                    }
988
                    finally
989
                    {
990
                        if (connection != null)
991
                            connection.Dispose();
992
                    }
993 bca86986 gaqhf
                }
994
            }
995
996
            return dt;
997
        }
998
999
        public static DataTable SelectProjectLineProperties()
1000
        {
1001
            DataTable dt = new DataTable();
1002
            Project_Info projectInfo = Project_Info.GetInstance();
1003 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
1004 bca86986 gaqhf
            {
1005 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
1006 bca86986 gaqhf
                {
1007 8847ea67 gaqhf
                    try
1008 bca86986 gaqhf
                    {
1009 8847ea67 gaqhf
                        connection.Open();
1010
                        using (SQLiteCommand cmd = connection.CreateCommand())
1011
                        {
1012
                            cmd.CommandText = string.Format(@"
1013 bca86986 gaqhf
                            SELECT lp.UID, lp.DisplayName, sp.SPPID_SYMBOL_PATH, spa.SPPID_ATTRIBUTE
1014
                            FROM {0} as lp 
1015
                                 LEFT OUTER JOIN {1} as sp 
1016
                                      ON lp.UID = sp.UID
1017
                                 LEFT OUTER JOIN {2} as spa 
1018
                                      ON lp.UID = spa.UID;", LineProperties_TABLE, SPPID_SYMBOL_MAPPING_TABLE, SPPID_ATTRIBUTE_MAPPING_TABLE);
1019 8847ea67 gaqhf
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
1020
                                dt.Load(dr);
1021
                        }
1022
                        connection.Close();
1023 bca86986 gaqhf
                    }
1024 8847ea67 gaqhf
                    catch (Exception ex)
1025
                    {
1026 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1027 8847ea67 gaqhf
                    }
1028
                    finally
1029
                    {
1030
                        connection.Dispose();
1031
                    }
1032 bca86986 gaqhf
                }
1033 8847ea67 gaqhf
            }
1034
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1035
            {
1036
                using (SqlConnection connection = GetSqlConnection())
1037 bca86986 gaqhf
                {
1038 8847ea67 gaqhf
                    try
1039
                    {
1040
                        if (connection != null && connection.State == ConnectionState.Open)
1041
                        {
1042 d2a7bef1 gaqhf
                            using (SqlCommand cmd = connection.CreateCommand())
1043
                            {
1044
                                cmd.CommandText = string.Format(@"
1045
                            SELECT lp.UID, lp.DisplayName, sp.SPPID_SYMBOL_PATH, spa.SPPID_ATTRIBUTE
1046
                            FROM {0} as lp 
1047
                                 LEFT OUTER JOIN {1} as sp 
1048
                                      ON lp.UID = sp.UID
1049
                                 LEFT OUTER JOIN {2} as spa 
1050
                                      ON lp.UID = spa.UID;", LineProperties_TABLE, SPPID_SYMBOL_MAPPING_TABLE, SPPID_ATTRIBUTE_MAPPING_TABLE);
1051
                                using (SqlDataReader dr = cmd.ExecuteReader())
1052
                                    dt.Load(dr);
1053
                            }
1054
                            connection.Close();
1055 8847ea67 gaqhf
                        }
1056
                    }
1057
                    catch (Exception ex)
1058
                    {
1059 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1060 8847ea67 gaqhf
                    }
1061
                    finally
1062
                    {
1063
                        if (connection != null)
1064
                            connection.Dispose();
1065
                    }
1066 bca86986 gaqhf
                }
1067
            }
1068
1069
            return dt;
1070
        }
1071 c9264d17 gaqhf
        public static DataTable SelectProjectNominalDiameter()
1072
        {
1073
            DataTable dt = new DataTable();
1074
            Project_Info projectInfo = Project_Info.GetInstance();
1075
            if (projectInfo.DBType == ID2DB_Type.SQLite)
1076
            {
1077 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
1078 c9264d17 gaqhf
                {
1079
                    try
1080
                    {
1081
                        connection.Open();
1082
                        using (SQLiteCommand cmd = connection.CreateCommand())
1083
                        {
1084
                            cmd.CommandText = string.Format(@"SELECT * FROM {0};", ID2_NOMINALDIAMETER_TABLE);
1085
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
1086
                                dt.Load(dr);
1087
                        }
1088
                        connection.Close();
1089
                    }
1090
                    catch (Exception ex)
1091
                    {
1092
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1093
                    }
1094
                    finally
1095
                    {
1096
                        connection.Dispose();
1097
                    }
1098
                }
1099
            }
1100
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1101
            {
1102
                using (SqlConnection connection = GetSqlConnection())
1103
                {
1104
                    try
1105
                    {
1106
                        if (connection != null && connection.State == ConnectionState.Open)
1107
                        {
1108
                            using (SqlCommand cmd = connection.CreateCommand())
1109
                            {
1110
                                cmd.CommandText = string.Format(@"SELECT * FROM {0};", ID2_NOMINALDIAMETER_TABLE);
1111
                                using (SqlDataReader dr = cmd.ExecuteReader())
1112
                                    dt.Load(dr);
1113
                            }
1114
                            connection.Close();
1115
                        }
1116
                    }
1117
                    catch (Exception ex)
1118
                    {
1119
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1120
                    }
1121
                    finally
1122
                    {
1123
                        if (connection != null)
1124
                            connection.Dispose();
1125
                    }
1126
                }
1127
            }
1128 bca86986 gaqhf
1129 c9264d17 gaqhf
            return dt;
1130
        }
1131 1efc25a3 gaqhf
        public static DataTable SelectProjectAttribute()
1132 bca86986 gaqhf
        {
1133
            DataTable dt = new DataTable();
1134
            Project_Info projectInfo = Project_Info.GetInstance();
1135 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
1136 bca86986 gaqhf
            {
1137 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
1138 bca86986 gaqhf
                {
1139 8847ea67 gaqhf
                    try
1140 bca86986 gaqhf
                    {
1141 8847ea67 gaqhf
                        connection.Open();
1142
                        using (SQLiteCommand cmd = connection.CreateCommand())
1143
                        {
1144
                            cmd.CommandText = string.Format(@"
1145 923501a9 gaqhf
                            SELECT sa.UID, sa.DisplayAttribute, st.TYPE, spa.SPPID_ATTRIBUTE, sp.SPPID_SYMBOL_PATH, spa.ISTEXT, spl.LOCATION, spl.LEADERLINE, sa.Property
1146 bca86986 gaqhf
                            FROM {1} as sa, {0} as st 
1147
                                 LEFT OUTER JOIN {2} as sp 
1148
                                      ON sa.UID = SP.UID 
1149
                                LEFT OUTER JOIN {3} as spa 
1150
                                     ON sa.UID = spa.UID
1151 1a3a74a8 gaqhf
                                LEFT OUTER JOIN {4} as spl 
1152
                                     ON sa.UID = spl.UID
1153 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);
1154 8847ea67 gaqhf
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
1155
                                dt.Load(dr);
1156
                        }
1157
                        connection.Close();
1158 bca86986 gaqhf
                    }
1159 8847ea67 gaqhf
                    catch (Exception ex)
1160
                    {
1161 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1162 8847ea67 gaqhf
                    }
1163
                    finally
1164
                    {
1165
                        connection.Dispose();
1166
                    }
1167
                }
1168
            }
1169
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1170
            {
1171
                using (SqlConnection connection = GetSqlConnection())
1172 bca86986 gaqhf
                {
1173 8847ea67 gaqhf
                    try
1174
                    {
1175
                        if (connection != null && connection.State == ConnectionState.Open)
1176
                        {
1177 d2a7bef1 gaqhf
                            using (SqlCommand cmd = connection.CreateCommand())
1178
                            {
1179
                                cmd.CommandText = string.Format(@"
1180 923501a9 gaqhf
                            SELECT sa.UID, sa.DisplayAttribute, st.Type, spa.SPPID_ATTRIBUTE, sp.SPPID_SYMBOL_PATH, spa.ISTEXT, spl.LOCATION, spl.LEADERLINE, sa.Property
1181 d2a7bef1 gaqhf
                            FROM {1} as sa
1182
                                 LEFT OUTER JOIN {2} as sp 
1183
                                      ON sa.UID = SP.UID 
1184
                                LEFT OUTER JOIN {3} as spa 
1185
                                     ON sa.UID = spa.UID
1186
                                LEFT OUTER JOIN {4} as spl 
1187
                                     ON sa.UID = spl.UID
1188
                                LEFT OUTER JOIN {0} as st 
1189
                                     ON sa.SymbolType_UID = st.UID 
1190
                            WHERE (sa.Property != 2 OR sa.Property IS NULL);", SymbolType_TABLE, SymbolAttribute_TABLE, SPPID_SYMBOL_MAPPING_TABLE, SPPID_ATTRIBUTE_MAPPING_TABLE, SPPID_LABEL_INFO_TABLE);
1191
                                using (SqlDataReader dr = cmd.ExecuteReader())
1192
                                    dt.Load(dr);
1193
                            }
1194
                            connection.Close();
1195 8847ea67 gaqhf
                        }
1196
                    }
1197
                    catch (Exception ex)
1198
                    {
1199 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1200 8847ea67 gaqhf
                    }
1201
                    finally
1202
                    {
1203
                        if (connection != null)
1204
                            connection.Dispose();
1205
                    }
1206 bca86986 gaqhf
                }
1207
            }
1208
1209 8847ea67 gaqhf
1210 bca86986 gaqhf
            return dt;
1211
        }
1212
1213 306a0af9 gaqhf
        public static DataTable SelectDrawingProjectAttribute()
1214
        {
1215
            DataTable dt = new DataTable();
1216
            Project_Info projectInfo = Project_Info.GetInstance();
1217
            if (projectInfo.DBType == ID2DB_Type.SQLite)
1218
            {
1219 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
1220 306a0af9 gaqhf
                {
1221
                    try
1222
                    {
1223
                        connection.Open();
1224
                        using (SQLiteCommand cmd = connection.CreateCommand())
1225
                        {
1226
                            cmd.CommandText = string.Format(@"
1227
                            SELECT da.UID, da.NAME, sam.SPPID_ATTRIBUTE 
1228
                            FROM {0} as da 
1229
                                 LEFT OUTER JOIN {1} as sam 
1230
                                      ON da.UID = sam.UID;
1231
                            ", DrawingAttribute_Table, SPPID_ATTRIBUTE_MAPPING_TABLE);
1232
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
1233
                                dt.Load(dr);
1234
                        }
1235
                        connection.Close();
1236
                    }
1237
                    catch (Exception ex)
1238
                    {
1239
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1240
                    }
1241
                    finally
1242
                    {
1243
                        connection.Dispose();
1244
                    }
1245
                }
1246
            }
1247
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1248
            {
1249
                using (SqlConnection connection = GetSqlConnection())
1250
                {
1251
                    try
1252
                    {
1253
                        if (connection != null && connection.State == ConnectionState.Open)
1254
                        {
1255
                            using (SqlCommand cmd = connection.CreateCommand())
1256
                            {
1257
                                cmd.CommandText = string.Format(@"
1258
                            SELECT da.UID, da.NAME, sam.SPPID_ATTRIBUTE 
1259
                            FROM {0} as da
1260
                                 LEFT OUTER JOIN {1} as sam 
1261
                                      ON da.UID = sam.UID;
1262
                            ", DrawingAttribute_Table, SPPID_ATTRIBUTE_MAPPING_TABLE);
1263
                                using (SqlDataReader dr = cmd.ExecuteReader())
1264
                                    dt.Load(dr);
1265
                            }
1266
                            connection.Close();
1267
                        }
1268
                    }
1269
                    catch (Exception ex)
1270
                    {
1271
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1272
                    }
1273
                    finally
1274
                    {
1275
                        if (connection != null)
1276
                            connection.Dispose();
1277
                    }
1278
                }
1279
            }
1280
1281
            dt.Merge(SelectDrawingProjectAttribute2());
1282
1283
            return dt;
1284
        }
1285 923501a9 gaqhf
1286 306a0af9 gaqhf
        private static DataTable SelectDrawingProjectAttribute2()
1287
        {
1288
            DataTable dt = new DataTable();
1289
            Project_Info projectInfo = Project_Info.GetInstance();
1290
            if (projectInfo.DBType == ID2DB_Type.SQLite)
1291
            {
1292 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
1293 306a0af9 gaqhf
                {
1294
                    try
1295
                    {
1296
                        connection.Open();
1297
                        using (SQLiteCommand cmd = connection.CreateCommand())
1298
                        {
1299
                            cmd.CommandText = string.Format(@"
1300
                            SELECT da.UID, da.NAME, sam.SPPID_ATTRIBUTE 
1301
                            FROM {0} as da 
1302
                                 LEFT OUTER JOIN {1} as sam 
1303
                                      ON da.UID = sam.UID;
1304
                            ", ID2_DRAWINGATTRIBUTE_TABLE, SPPID_ATTRIBUTE_MAPPING_TABLE);
1305
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
1306
                                dt.Load(dr);
1307
                        }
1308
                        connection.Close();
1309
                    }
1310
                    catch (Exception ex)
1311
                    {
1312
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1313
                    }
1314
                    finally
1315
                    {
1316
                        connection.Dispose();
1317
                    }
1318
                }
1319
            }
1320
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1321
            {
1322
                using (SqlConnection connection = GetSqlConnection())
1323
                {
1324
                    try
1325
                    {
1326
                        if (connection != null && connection.State == ConnectionState.Open)
1327
                        {
1328
                            using (SqlCommand cmd = connection.CreateCommand())
1329
                            {
1330
                                cmd.CommandText = string.Format(@"
1331
                            SELECT da.UID, da.NAME, sam.SPPID_ATTRIBUTE 
1332
                            FROM {0} as da
1333
                                 LEFT OUTER JOIN {1} as sam 
1334
                                      ON da.UID = sam.UID;
1335
                            ", ID2_DRAWINGATTRIBUTE_TABLE, SPPID_ATTRIBUTE_MAPPING_TABLE);
1336
                                using (SqlDataReader dr = cmd.ExecuteReader())
1337
                                    dt.Load(dr);
1338
                            }
1339
                            connection.Close();
1340
                        }
1341
                    }
1342
                    catch (Exception ex)
1343
                    {
1344
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1345
                    }
1346
                    finally
1347
                    {
1348
                        if (connection != null)
1349
                            connection.Dispose();
1350
                    }
1351
                }
1352
            }
1353
1354
            return dt;
1355
        }
1356
1357 4d2571ab gaqhf
        public static DataTable SelectID2SymbolTable()
1358
        {
1359
            DataTable dt = new DataTable();
1360
            Project_Info projectInfo = Project_Info.GetInstance();
1361 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
1362 4d2571ab gaqhf
            {
1363 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
1364 4d2571ab gaqhf
                {
1365 8847ea67 gaqhf
                    try
1366 4d2571ab gaqhf
                    {
1367 8847ea67 gaqhf
                        connection.Open();
1368
                        using (SQLiteCommand cmd = connection.CreateCommand())
1369
                        {
1370
                            cmd.CommandText = @"SELECT * FROM Symbol";
1371
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
1372
                                dt.Load(dr);
1373
                        }
1374
                        connection.Close();
1375 4d2571ab gaqhf
                    }
1376 8847ea67 gaqhf
                    catch (Exception ex)
1377
                    {
1378 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1379 8847ea67 gaqhf
                    }
1380
                    finally
1381
                    {
1382
                        connection.Dispose();
1383
                    }
1384 4d2571ab gaqhf
                }
1385 8847ea67 gaqhf
            }
1386
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1387
            {
1388
                using (SqlConnection connection = GetSqlConnection())
1389 4d2571ab gaqhf
                {
1390 8847ea67 gaqhf
                    try
1391
                    {
1392
                        if (connection != null && connection.State == ConnectionState.Open)
1393
                        {
1394 d2a7bef1 gaqhf
                            using (SqlCommand cmd = connection.CreateCommand())
1395
                            {
1396
                                cmd.CommandText = @"SELECT * FROM Symbol";
1397
                                using (SqlDataReader dr = cmd.ExecuteReader())
1398
                                    dt.Load(dr);
1399
                            }
1400
                            connection.Close();
1401 8847ea67 gaqhf
                        }
1402
                    }
1403
                    catch (Exception ex)
1404
                    {
1405 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1406 8847ea67 gaqhf
                    }
1407
                    finally
1408
                    {
1409
                        if (connection != null)
1410
                            connection.Dispose();
1411
                    }
1412 4d2571ab gaqhf
                }
1413
            }
1414
1415
            return dt;
1416
        }
1417
1418 154d8f43 gaqhf
        public static DataTable SelectOPCRelations()
1419
        {
1420
            DataTable dt = new DataTable();
1421
            Project_Info projectInfo = Project_Info.GetInstance();
1422 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
1423 154d8f43 gaqhf
            {
1424 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
1425 154d8f43 gaqhf
                {
1426 8847ea67 gaqhf
                    try
1427 154d8f43 gaqhf
                    {
1428 8847ea67 gaqhf
                        connection.Open();
1429
                        using (SQLiteCommand cmd = connection.CreateCommand())
1430
                        {
1431
                            cmd.CommandText = string.Format("SELECT * FROM {0}", OPCRelations_TABLE);
1432
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
1433
                                dt.Load(dr);
1434
                        }
1435
                        connection.Close();
1436 154d8f43 gaqhf
                    }
1437 8847ea67 gaqhf
                    catch (Exception ex)
1438
                    {
1439 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1440 8847ea67 gaqhf
                    }
1441
                    finally
1442
                    {
1443
                        connection.Dispose();
1444
                    }
1445 154d8f43 gaqhf
                }
1446 8847ea67 gaqhf
            }
1447
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1448
            {
1449
                using (SqlConnection connection = GetSqlConnection())
1450 154d8f43 gaqhf
                {
1451 8847ea67 gaqhf
                    try
1452
                    {
1453
                        if (connection != null && connection.State == ConnectionState.Open)
1454
                        {
1455 d2a7bef1 gaqhf
                            using (SqlCommand cmd = connection.CreateCommand())
1456
                            {
1457
                                cmd.CommandText = string.Format("SELECT * FROM {0}", OPCRelations_TABLE);
1458
                                using (SqlDataReader dr = cmd.ExecuteReader())
1459
                                    dt.Load(dr);
1460
                            }
1461
                            connection.Close();
1462 8847ea67 gaqhf
                        }
1463
                    }
1464
                    catch (Exception ex)
1465
                    {
1466 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1467 8847ea67 gaqhf
                    }
1468
                    finally
1469
                    {
1470
                        if (connection != null)
1471
                            connection.Dispose();
1472
                    }
1473 154d8f43 gaqhf
                }
1474
            }
1475
1476
            return dt;
1477
        }
1478
1479
        public static DataTable SelectDrawings()
1480
        {
1481
            DataTable dt = new DataTable();
1482
            Project_Info projectInfo = Project_Info.GetInstance();
1483 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
1484 154d8f43 gaqhf
            {
1485 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
1486 154d8f43 gaqhf
                {
1487 8847ea67 gaqhf
                    try
1488 154d8f43 gaqhf
                    {
1489 8847ea67 gaqhf
                        connection.Open();
1490
                        using (SQLiteCommand cmd = connection.CreateCommand())
1491
                        {
1492
                            cmd.CommandText = string.Format("SELECT * FROM {0}", "Drawings");
1493
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
1494
                                dt.Load(dr);
1495
                        }
1496
                        connection.Close();
1497 154d8f43 gaqhf
                    }
1498 8847ea67 gaqhf
                    catch (Exception ex)
1499
                    {
1500 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1501 8847ea67 gaqhf
                    }
1502
                    finally
1503
                    {
1504
                        connection.Dispose();
1505
                    }
1506 154d8f43 gaqhf
                }
1507 8847ea67 gaqhf
            }
1508
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1509
            {
1510
                using (SqlConnection connection = GetSqlConnection())
1511 154d8f43 gaqhf
                {
1512 8847ea67 gaqhf
                    try
1513
                    {
1514
                        if (connection != null && connection.State == ConnectionState.Open)
1515
                        {
1516 d2a7bef1 gaqhf
                            using (SqlCommand cmd = connection.CreateCommand())
1517
                            {
1518
                                cmd.CommandText = string.Format("SELECT * FROM {0}", "Drawings");
1519
                                using (SqlDataReader dr = cmd.ExecuteReader())
1520
                                    dt.Load(dr);
1521
                            }
1522
                            connection.Close();
1523 8847ea67 gaqhf
                        }
1524
                    }
1525
                    catch (Exception ex)
1526
                    {
1527 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1528 8847ea67 gaqhf
                    }
1529
                    finally
1530
                    {
1531
                        if (connection != null)
1532
                            connection.Dispose();
1533
                    }
1534 154d8f43 gaqhf
                }
1535
            }
1536
1537
            return dt;
1538
        }
1539
1540
        public static DataTable SelectOPCInfo()
1541
        {
1542
            DataTable dt = new DataTable();
1543
            Project_Info projectInfo = Project_Info.GetInstance();
1544 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
1545 154d8f43 gaqhf
            {
1546 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
1547 154d8f43 gaqhf
                {
1548 8847ea67 gaqhf
                    try
1549 154d8f43 gaqhf
                    {
1550 8847ea67 gaqhf
                        connection.Open();
1551
                        using (SQLiteCommand cmd = connection.CreateCommand())
1552
                        {
1553
                            cmd.CommandText = string.Format("SELECT * FROM {0} WHERE SPPID_OPC_MODELITEM_ID IS NOT NULL AND PAIRED = False", SPPID_OPC_INFO);
1554
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
1555
                                dt.Load(dr);
1556
                        }
1557
                        connection.Close();
1558 154d8f43 gaqhf
                    }
1559 8847ea67 gaqhf
                    catch (Exception ex)
1560
                    {
1561 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1562 8847ea67 gaqhf
                    }
1563
                    finally
1564
                    {
1565
                        connection.Dispose();
1566
                    }
1567 154d8f43 gaqhf
                }
1568 8847ea67 gaqhf
            }
1569
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1570
            {
1571
                using (SqlConnection connection = GetSqlConnection())
1572 154d8f43 gaqhf
                {
1573 8847ea67 gaqhf
                    try
1574
                    {
1575
                        if (connection != null && connection.State == ConnectionState.Open)
1576
                        {
1577 d2a7bef1 gaqhf
                            using (SqlCommand cmd = connection.CreateCommand())
1578
                            {
1579 0cab8feb gaqhf
                                cmd.CommandText = string.Format("SELECT * FROM {0} WHERE SPPID_OPC_MODELITEM_ID IS NOT NULL AND PAIRED = 0", SPPID_OPC_INFO);
1580 d2a7bef1 gaqhf
                                using (SqlDataReader dr = cmd.ExecuteReader())
1581
                                    dt.Load(dr);
1582
                            }
1583
                            connection.Close();
1584 8847ea67 gaqhf
                        }
1585
                    }
1586
                    catch (Exception ex)
1587
                    {
1588 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1589 8847ea67 gaqhf
                    }
1590
                    finally
1591
                    {
1592
                        if (connection != null)
1593
                            connection.Dispose();
1594
                    }
1595 154d8f43 gaqhf
                }
1596
            }
1597
1598
            return dt;
1599
        }
1600 7e680366 gaqhf
1601 6b60e542 Denny
        public static DataTable SelectPipeRunPropSetting()
1602
        {
1603
            DataTable dt = new DataTable();
1604
            Project_Info projectInfo = Project_Info.GetInstance();
1605
            if (projectInfo.DBType == ID2DB_Type.SQLite)
1606
            {
1607
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
1608
                {
1609
                    try
1610
                    {
1611
                        connection.Open();
1612
                        using (SQLiteCommand cmd = connection.CreateCommand())
1613
                        {
1614
                            cmd.CommandText = string.Format(@"
1615
                            SELECT s.UID, s.ShowType, s.Name, s.DisplayName, s.TableName, s.DataType, s.Value, s.Cond1_Name, s.Cond1_DisplayName, s.Cond1_TableName, s.Cond1_DataType, s.Cond1_Value, s.Cond2_Name, s.Cond2_DisplayName, s.Cond2_TableName, s.Cond2_DataType, s.Cond2_Value, s.SortOrder
1616
                              FROM {0} as s
1617
                              ORDER BY s.SortOrder ASC;", SPPID_PIPERUN_PROP_SETTING);
1618
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
1619
                                dt.Load(dr);
1620
                        }
1621
                        connection.Close();
1622
                    }
1623
                    catch (Exception ex)
1624
                    {
1625
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1626
                    }
1627
                    finally
1628
                    {
1629
                        connection.Dispose();
1630
                    }
1631
                }
1632
            }
1633
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1634
            {
1635
                using (SqlConnection connection = GetSqlConnection())
1636
                {
1637
                    try
1638
                    {
1639
                        if (connection != null && connection.State == ConnectionState.Open)
1640
                        {
1641
                            using (SqlCommand cmd = connection.CreateCommand())
1642
                            {
1643
                                cmd.CommandText = string.Format(@"
1644
                            SELECT s.UID, s.ShowType, s.Name, s.DisplayName, s.TableName, s.DataType, s.Value, s.Cond1_Name, s.Cond1_DisplayName, s.Cond1_TableName, s.Cond1_DataType, s.Cond1_Value, s.Cond2Name, s.Cond2_DisplayName, s.Cond2_TableName, s.Cond2_DataType, s.Cond2_Value, s.SortOrder
1645
                              FROM {0} as s
1646
                              ORDER BY s.SortOrder ASC;", SPPID_PIPERUN_PROP_SETTING);
1647
                                using (SqlDataReader dr = cmd.ExecuteReader())
1648
                                    dt.Load(dr);
1649
                            }
1650
                            connection.Close();
1651
                        }
1652
                    }
1653
                    catch (Exception ex)
1654
                    {
1655
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1656
                    }
1657
                    finally
1658
                    {
1659
                        if (connection != null)
1660
                            connection.Dispose();
1661
                    }
1662
                }
1663
            }
1664
1665
            return dt;
1666
        }
1667
1668
        public static DataTable SelectMappedPipeProperties()
1669
        {
1670
            DataTable dt = new DataTable();
1671
            Project_Info projectInfo = Project_Info.GetInstance();
1672
            if (projectInfo.DBType == ID2DB_Type.SQLite)
1673
            {
1674
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
1675
                {
1676
                    try
1677
                    {
1678
                        connection.Open();
1679
                        using (SQLiteCommand cmd = connection.CreateCommand())
1680
                        {
1681
                            cmd.CommandText = string.Format(@"
1682
                            SELECT DISTINCT sam.SPPID_ATTRIBUTE
1683
                              FROM {0} sam
1684
                              LEFT JOIN {1} sa 
1685
                              ON sam.UID = sa.UID 
1686
                              LEFT JOIN {2} st
1687
                              ON sa.SymbolType_UID = st.UID 
1688
                              LEFT JOIN {3} as lp
1689
                              ON sam.UID = lp.UID 
1690
                            WHERE sam.SPPID_ATTRIBUTE is not null 
1691
                            AND (st.Category = 'Line' or lp.UID is not null);", SPPID_ATTRIBUTE_MAPPING_TABLE, SymbolAttribute_TABLE, SymbolType_TABLE, LineProperties_TABLE);
1692
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
1693
                                dt.Load(dr);
1694
                        }
1695
                        connection.Close();
1696
                    }
1697
                    catch (Exception ex)
1698
                    {
1699
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1700
                    }
1701
                    finally
1702
                    {
1703
                        connection.Dispose();
1704
                    }
1705
                }
1706
            }
1707
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1708
            {
1709
                using (SqlConnection connection = GetSqlConnection())
1710
                {
1711
                    try
1712
                    {
1713
                        if (connection != null && connection.State == ConnectionState.Open)
1714
                        {
1715
                            using (SqlCommand cmd = connection.CreateCommand())
1716
                            {
1717
                                cmd.CommandText = string.Format(@"
1718
                            SELECT DISTINCT sam.SPPID_ATTRIBUTE
1719
                              FROM {0} sam
1720
                              LEFT JOIN {1} sa 
1721
                              ON sam.UID = sa.UID 
1722
                              LEFT JOIN {2} st
1723
                              ON sa.SymbolType_UID = st.UID 
1724
                              LEFT JOIN {3} as lp
1725
                              ON sam.UID = lp.UID 
1726
                            WHERE sam.SPPID_ATTRIBUTE is not null 
1727
                            AND (st.Category = 'Line' or lp.UID is not null);", SPPID_ATTRIBUTE_MAPPING_TABLE, SymbolAttribute_TABLE, SymbolType_TABLE, LineProperties_TABLE);
1728
                            using (SqlDataReader dr = cmd.ExecuteReader())
1729
                                    dt.Load(dr);
1730
                            }
1731
                            connection.Close();
1732
                        }
1733
                    }
1734
                    catch (Exception ex)
1735
                    {
1736
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1737
                    }
1738
                    finally
1739
                    {
1740
                        if (connection != null)
1741
                            connection.Dispose();
1742
                    }
1743
                }
1744
            }
1745
1746
            DataTable dtPipeRun = SPPID_DB.GetPipeRunProperties(false, true);
1747
            DataTable resultDT = dtPipeRun.Clone();
1748
            if (dt != null)
1749
            {
1750
                List<string> filterList = new List<string>();
1751
                foreach (DataRow dr in dt.Rows)
1752
                {
1753
                    filterList.Add("'" + dr["SPPID_ATTRIBUTE"].ToString() + "'");
1754
                }
1755
                string filter = string.Join(",", filterList.ToArray());
1756
                DataRow[] dataRows = dtPipeRun.Select(string.Format("NAME IN ({0})", filter));
1757
1758
                resultDT.Rows.Add(resultDT.NewRow());
1759
                foreach (DataRow dr in dataRows)
1760
                {
1761
                    resultDT.Rows.Add(dr.ItemArray);
1762
                }
1763
            }
1764
            return resultDT;
1765
        }
1766
1767 7e680366 gaqhf
        public static DataTable SelectSymbolType()
1768
        {
1769
            DataTable dt = new DataTable();
1770
            Project_Info projectInfo = Project_Info.GetInstance();
1771 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
1772 7e680366 gaqhf
            {
1773 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
1774 7e680366 gaqhf
                {
1775 8847ea67 gaqhf
                    try
1776 7e680366 gaqhf
                    {
1777 8847ea67 gaqhf
                        connection.Open();
1778
                        using (SQLiteCommand cmd = connection.CreateCommand())
1779
                        {
1780
                            cmd.CommandText = string.Format("SELECT * FROM {0}", SymbolType_TABLE);
1781
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
1782
                                dt.Load(dr);
1783
                        }
1784
                        connection.Close();
1785 7e680366 gaqhf
                    }
1786 8847ea67 gaqhf
                    catch (Exception ex)
1787
                    {
1788 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1789 8847ea67 gaqhf
                    }
1790
                    finally
1791
                    {
1792
                        connection.Dispose();
1793
                    }
1794 7e680366 gaqhf
                }
1795 8847ea67 gaqhf
            }
1796
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1797
            {
1798
                using (SqlConnection connection = GetSqlConnection())
1799 7e680366 gaqhf
                {
1800 8847ea67 gaqhf
                    try
1801
                    {
1802
                        if (connection != null && connection.State == ConnectionState.Open)
1803
                        {
1804 d2a7bef1 gaqhf
                            using (SqlCommand cmd = connection.CreateCommand())
1805
                            {
1806
                                cmd.CommandText = string.Format("SELECT * FROM {0}", SymbolType_TABLE);
1807
                                using (SqlDataReader dr = cmd.ExecuteReader())
1808
                                    dt.Load(dr);
1809
                            }
1810
                            connection.Close();
1811 8847ea67 gaqhf
                        }
1812
                    }
1813
                    catch (Exception ex)
1814
                    {
1815 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1816 8847ea67 gaqhf
                    }
1817
                    finally
1818
                    {
1819
                        if (connection != null)
1820
                            connection.Dispose();
1821
                    }
1822 7e680366 gaqhf
                }
1823
            }
1824
1825
            return dt;
1826
        }
1827
1828 4fb0f8d5 gaqhf
        public static DataTable SelectDrawingInfo()
1829
        {
1830 154d8f43 gaqhf
            DataTable dt = new DataTable();
1831 4fb0f8d5 gaqhf
            Project_Info projectInfo = Project_Info.GetInstance();
1832 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
1833 4fb0f8d5 gaqhf
            {
1834 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
1835 4fb0f8d5 gaqhf
                {
1836 8847ea67 gaqhf
                    try
1837 4fb0f8d5 gaqhf
                    {
1838 8847ea67 gaqhf
                        connection.Open();
1839
                        using (SQLiteCommand cmd = connection.CreateCommand())
1840
                        {
1841
                            cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_DRAWING_INFO);
1842
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
1843
                                dt.Load(dr);
1844
                        }
1845
                        connection.Close();
1846 4fb0f8d5 gaqhf
                    }
1847 8847ea67 gaqhf
                    catch (Exception ex)
1848
                    {
1849 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1850 8847ea67 gaqhf
                    }
1851
                    finally
1852
                    {
1853
                        connection.Dispose();
1854
                    }
1855 4fb0f8d5 gaqhf
                }
1856 8847ea67 gaqhf
            }
1857
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1858
            {
1859
                using (SqlConnection connection = GetSqlConnection())
1860 4fb0f8d5 gaqhf
                {
1861 8847ea67 gaqhf
                    try
1862
                    {
1863
                        if (connection != null && connection.State == ConnectionState.Open)
1864
                        {
1865 d2a7bef1 gaqhf
                            using (SqlCommand cmd = connection.CreateCommand())
1866
                            {
1867
                                cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_DRAWING_INFO);
1868
                                using (SqlDataReader dr = cmd.ExecuteReader())
1869
                                    dt.Load(dr);
1870
                            }
1871
                            connection.Close();
1872 8847ea67 gaqhf
                        }
1873
                    }
1874
                    catch (Exception ex)
1875
                    {
1876 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1877 8847ea67 gaqhf
                    }
1878
                    finally
1879
                    {
1880
                        if (connection != null)
1881
                            connection.Dispose();
1882
                    }
1883 4fb0f8d5 gaqhf
                }
1884
            }
1885
1886
            return dt;
1887
        }
1888
1889 cf924377 gaqhf
        public static bool InsertSymbolMapping(List<Tuple<string, string, string, bool>> datas)
1890 bca86986 gaqhf
        {
1891
            Project_Info projectInfo = Project_Info.GetInstance();
1892 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
1893 bca86986 gaqhf
            {
1894 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
1895 bca86986 gaqhf
                {
1896 8847ea67 gaqhf
                    try
1897 bca86986 gaqhf
                    {
1898 8847ea67 gaqhf
                        connection.Open();
1899
                        using (SQLiteTransaction transaction = connection.BeginTransaction())
1900 1421f1d6 gaqhf
                        {
1901 8847ea67 gaqhf
                            try
1902 1421f1d6 gaqhf
                            {
1903 8847ea67 gaqhf
                                using (SQLiteCommand cmd = connection.CreateCommand())
1904 1421f1d6 gaqhf
                                {
1905 8847ea67 gaqhf
                                    foreach (var item in datas)
1906
                                    {
1907
                                        cmd.Parameters.Clear();
1908
                                        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);
1909
                                        cmd.Parameters.AddWithValue("@UID", item.Item1);
1910
                                        cmd.Parameters.AddWithValue("@NAME", item.Item2);
1911
                                        cmd.Parameters.AddWithValue("@SPPID_SYMBOL_PATH", item.Item3);
1912
                                        cmd.Parameters.AddWithValue("@LEADERLINE", item.Item4);
1913
                                        cmd.ExecuteNonQuery();
1914
                                    }
1915 1421f1d6 gaqhf
                                }
1916 8847ea67 gaqhf
                                transaction.Commit();
1917
                                connection.Close();
1918
                            }
1919
                            catch (Exception ex)
1920
                            {
1921 2425d530 gaqhf
                                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1922 8847ea67 gaqhf
                                transaction.Rollback();
1923 a2c803a0 gaqhf
                                return false;
1924 8847ea67 gaqhf
                            }
1925
                            finally
1926
                            {
1927
                                transaction.Dispose();
1928 1421f1d6 gaqhf
                            }
1929 bca86986 gaqhf
                        }
1930
                    }
1931 8847ea67 gaqhf
                    catch (Exception ex)
1932
                    {
1933 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1934 8847ea67 gaqhf
                        return false;
1935
                    }
1936
                    finally
1937
                    {
1938
                        connection.Dispose();
1939
                    }
1940 bca86986 gaqhf
                }
1941 8847ea67 gaqhf
            }
1942
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
1943
            {
1944
                using (SqlConnection connection = GetSqlConnection())
1945 bca86986 gaqhf
                {
1946 8847ea67 gaqhf
                    try
1947
                    {
1948
                        if (connection != null && connection.State == ConnectionState.Open)
1949
                        {
1950 a2c803a0 gaqhf
                            using (SqlCommand cmd = connection.CreateCommand())
1951
                            {
1952
                                foreach (var item in datas)
1953
                                {
1954
                                    cmd.Parameters.Clear();
1955
                                    cmd.CommandText = string.Format(@"
1956
                                    IF EXISTS (SELECT * FROM {0} WHERE UID = '{1}')
1957
                                        UPDATE {0} SET NAME = @NAME, SPPID_SYMBOL_PATH = @SPPID_SYMBOL_PATH, LEADERLINE = @LEADERLINE WHERE UID = @UID
1958
                                    ELSE
1959
                                        INSERT INTO {0} (UID, NAME, SPPID_SYMBOL_PATH, LEADERLINE) VALUES (@UID, @NAME, @SPPID_SYMBOL_PATH, @LEADERLINE)", SPPID_SYMBOL_MAPPING_TABLE, item.Item1);
1960
                                    cmd.Parameters.AddWithValue("@UID", item.Item1);
1961 f4485671 gaqhf
                                    if (string.IsNullOrEmpty(item.Item2))
1962
                                        cmd.Parameters.AddWithValue("@NAME", DBNull.Value);
1963
                                    else
1964
                                        cmd.Parameters.AddWithValue("@NAME", item.Item2);
1965 a2c803a0 gaqhf
                                    if (string.IsNullOrEmpty(item.Item3))
1966
                                        cmd.Parameters.AddWithValue("@SPPID_SYMBOL_PATH", DBNull.Value);
1967
                                    else
1968
                                        cmd.Parameters.AddWithValue("@SPPID_SYMBOL_PATH", item.Item3);
1969
                                    cmd.Parameters.AddWithValue("@LEADERLINE", item.Item4);
1970
                                    cmd.ExecuteNonQuery();
1971
                                }
1972
                            }
1973
                            connection.Close();
1974 8847ea67 gaqhf
                        }
1975
                    }
1976
                    catch (Exception ex)
1977
                    {
1978 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
1979 a2c803a0 gaqhf
                        return false;
1980 8847ea67 gaqhf
                    }
1981
                    finally
1982
                    {
1983
                        if (connection != null)
1984
                            connection.Dispose();
1985
                    }
1986 bca86986 gaqhf
                }
1987
            }
1988
1989
            return true;
1990
        }
1991
1992 923501a9 gaqhf
        public static bool InsertAttributeMapping(List<Tuple<string, string, bool>> datas)
1993 bca86986 gaqhf
        {
1994
            Project_Info projectInfo = Project_Info.GetInstance();
1995 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
1996 bca86986 gaqhf
            {
1997 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
1998 bca86986 gaqhf
                {
1999 8847ea67 gaqhf
                    try
2000 bca86986 gaqhf
                    {
2001 8847ea67 gaqhf
                        connection.Open();
2002
                        using (SQLiteTransaction transaction = connection.BeginTransaction())
2003 1421f1d6 gaqhf
                        {
2004 8847ea67 gaqhf
                            try
2005 1421f1d6 gaqhf
                            {
2006 8847ea67 gaqhf
                                using (SQLiteCommand cmd = connection.CreateCommand())
2007 1421f1d6 gaqhf
                                {
2008 8847ea67 gaqhf
                                    foreach (var item in datas)
2009
                                    {
2010
                                        cmd.Parameters.Clear();
2011 923501a9 gaqhf
                                        cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, SPPID_ATTRIBUTE, ISTEXT) VALUES (@UID, @SPPID_ATTRIBUTE, @ISTEXT)", SPPID_ATTRIBUTE_MAPPING_TABLE);
2012 8847ea67 gaqhf
                                        cmd.Parameters.AddWithValue("@UID", item.Item1);
2013
                                        cmd.Parameters.AddWithValue("@SPPID_ATTRIBUTE", item.Item2);
2014 923501a9 gaqhf
                                        cmd.Parameters.AddWithValue("@ISTEXT", item.Item3);
2015 8847ea67 gaqhf
                                        cmd.ExecuteNonQuery();
2016
                                    }
2017 1421f1d6 gaqhf
                                }
2018 8847ea67 gaqhf
                                transaction.Commit();
2019
                                connection.Close();
2020
                            }
2021
                            catch (Exception ex)
2022
                            {
2023 2425d530 gaqhf
                                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2024 8847ea67 gaqhf
                                transaction.Rollback();
2025
                            }
2026
                            finally
2027
                            {
2028
                                transaction.Dispose();
2029 1421f1d6 gaqhf
                            }
2030 bca86986 gaqhf
                        }
2031
                    }
2032 8847ea67 gaqhf
                    catch (Exception ex)
2033
                    {
2034 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2035 8847ea67 gaqhf
                        return false;
2036
                    }
2037
                    finally
2038
                    {
2039
                        connection.Dispose();
2040
                    }
2041 bca86986 gaqhf
                }
2042 8847ea67 gaqhf
            }
2043
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
2044
            {
2045
                using (SqlConnection connection = GetSqlConnection())
2046 bca86986 gaqhf
                {
2047 8847ea67 gaqhf
                    try
2048
                    {
2049
                        if (connection != null && connection.State == ConnectionState.Open)
2050
                        {
2051 f4485671 gaqhf
                            using (SqlCommand cmd = connection.CreateCommand())
2052 a2c803a0 gaqhf
                            {
2053 f4485671 gaqhf
                                foreach (var item in datas)
2054 a2c803a0 gaqhf
                                {
2055 f4485671 gaqhf
                                    cmd.Parameters.Clear();
2056
                                    cmd.CommandText = string.Format(@"
2057
                                    IF EXISTS (SELECT * FROM {0} WHERE UID = '{1}')
2058 923501a9 gaqhf
                                        UPDATE {0} SET SPPID_ATTRIBUTE = @SPPID_ATTRIBUTE, ISTEXT = @ISTEXT WHERE UID = @UID
2059 f4485671 gaqhf
                                    ELSE
2060 923501a9 gaqhf
                                        INSERT INTO {0} (UID, SPPID_ATTRIBUTE, ISTEXT) VALUES (@UID, @SPPID_ATTRIBUTE, @ISTEXT)", SPPID_ATTRIBUTE_MAPPING_TABLE, item.Item1);
2061 f4485671 gaqhf
2062
                                    cmd.Parameters.AddWithValue("@UID", item.Item1);
2063
                                    if (string.IsNullOrEmpty(item.Item2))
2064
                                        cmd.Parameters.AddWithValue("@SPPID_ATTRIBUTE", DBNull.Value);
2065
                                    else
2066 a2c803a0 gaqhf
                                        cmd.Parameters.AddWithValue("@SPPID_ATTRIBUTE", item.Item2);
2067 923501a9 gaqhf
                                    cmd.Parameters.AddWithValue("@ISTEXT", item.Item3);
2068 f4485671 gaqhf
                                    cmd.ExecuteNonQuery();
2069 a2c803a0 gaqhf
                                }
2070
                            }
2071 f4485671 gaqhf
                            connection.Close();
2072 8847ea67 gaqhf
                        }
2073
                    }
2074
                    catch (Exception ex)
2075
                    {
2076 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2077 a2c803a0 gaqhf
                        return false;
2078 8847ea67 gaqhf
                    }
2079
                    finally
2080
                    {
2081
                        if (connection != null)
2082
                            connection.Dispose();
2083
                    }
2084 bca86986 gaqhf
                }
2085
            }
2086
            return true;
2087
        }
2088 1a3a74a8 gaqhf
2089 cf924377 gaqhf
        public static bool InsertLabelInfoMapping(List<Tuple<string, int, bool>> datas)
2090 1a3a74a8 gaqhf
        {
2091
            Project_Info projectInfo = Project_Info.GetInstance();
2092 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
2093 1a3a74a8 gaqhf
            {
2094 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
2095 1a3a74a8 gaqhf
                {
2096 8847ea67 gaqhf
                    try
2097 1a3a74a8 gaqhf
                    {
2098 8847ea67 gaqhf
                        connection.Open();
2099
                        using (SQLiteTransaction transaction = connection.BeginTransaction())
2100 1a3a74a8 gaqhf
                        {
2101 8847ea67 gaqhf
                            try
2102 1a3a74a8 gaqhf
                            {
2103 8847ea67 gaqhf
                                using (SQLiteCommand cmd = connection.CreateCommand())
2104 1a3a74a8 gaqhf
                                {
2105 8847ea67 gaqhf
                                    foreach (var item in datas)
2106
                                    {
2107
                                        cmd.Parameters.Clear();
2108
                                        cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, LOCATION, LEADERLINE) VALUES (@UID, @LOCATION, @LEADERLINE)", SPPID_LABEL_INFO_TABLE);
2109
                                        cmd.Parameters.AddWithValue("@UID", item.Item1);
2110
                                        cmd.Parameters.AddWithValue("@LOCATION", item.Item2);
2111
                                        cmd.Parameters.AddWithValue("@LEADERLINE", item.Item3);
2112
                                        cmd.ExecuteNonQuery();
2113
                                    }
2114 1a3a74a8 gaqhf
                                }
2115 8847ea67 gaqhf
                                transaction.Commit();
2116
                                connection.Close();
2117
                            }
2118
                            catch (Exception ex)
2119
                            {
2120 2425d530 gaqhf
                                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2121 8847ea67 gaqhf
                                transaction.Rollback();
2122 a2c803a0 gaqhf
                                return false;
2123 8847ea67 gaqhf
                            }
2124
                            finally
2125
                            {
2126
                                transaction.Dispose();
2127 1a3a74a8 gaqhf
                            }
2128
                        }
2129
                    }
2130 8847ea67 gaqhf
                    catch (Exception ex)
2131
                    {
2132 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2133 8847ea67 gaqhf
                        return false;
2134
                    }
2135
                    finally
2136
                    {
2137
                        connection.Dispose();
2138
                    }
2139 1a3a74a8 gaqhf
                }
2140 8847ea67 gaqhf
            }
2141
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
2142
            {
2143
                using (SqlConnection connection = GetSqlConnection())
2144 1a3a74a8 gaqhf
                {
2145 8847ea67 gaqhf
                    try
2146
                    {
2147
                        if (connection != null && connection.State == ConnectionState.Open)
2148
                        {
2149 a2c803a0 gaqhf
                            using (SqlCommand cmd = connection.CreateCommand())
2150
                            {
2151
                                foreach (var item in datas)
2152
                                {
2153
                                    cmd.Parameters.Clear();
2154 f4485671 gaqhf
                                    cmd.CommandText = string.Format(@"
2155
                                    IF EXISTS (SELECT * FROM {0} WHERE UID = '{1}')
2156
                                        UPDATE {0} SET LOCATION = @LOCATION, LEADERLINE = @LEADERLINE WHERE UID = @UID
2157
                                    ELSE
2158
                                        INSERT INTO {0} (UID, LOCATION, LEADERLINE) VALUES (@UID, @LOCATION, @LEADERLINE)", SPPID_LABEL_INFO_TABLE, item.Item1);
2159
2160 a2c803a0 gaqhf
                                    cmd.Parameters.AddWithValue("@UID", item.Item1);
2161
                                    cmd.Parameters.AddWithValue("@LOCATION", item.Item2);
2162
                                    cmd.Parameters.AddWithValue("@LEADERLINE", item.Item3);
2163
                                    cmd.ExecuteNonQuery();
2164
                                }
2165
                            }
2166
                            connection.Close();
2167 8847ea67 gaqhf
                        }
2168
                    }
2169
                    catch (Exception ex)
2170
                    {
2171 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2172 a2c803a0 gaqhf
                        return false;
2173 8847ea67 gaqhf
                    }
2174
                    finally
2175
                    {
2176
                        if (connection != null)
2177
                            connection.Dispose();
2178
                    }
2179 1a3a74a8 gaqhf
                }
2180
            }
2181
            return true;
2182
        }
2183 69b7387a gaqhf
2184 154d8f43 gaqhf
        public static bool InsertDrawingInfoAndOPCInfo(string path, string drawingNumber, string drawingName, SPPID.Model.SPPID_Document document)
2185 69b7387a gaqhf
        {
2186
            Project_Info projectInfo = Project_Info.GetInstance();
2187 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
2188 69b7387a gaqhf
            {
2189 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
2190 69b7387a gaqhf
                {
2191 8847ea67 gaqhf
                    try
2192 69b7387a gaqhf
                    {
2193 8847ea67 gaqhf
                        connection.Open();
2194
                        using (SQLiteTransaction transaction = connection.BeginTransaction())
2195 69b7387a gaqhf
                        {
2196 8847ea67 gaqhf
                            try
2197 154d8f43 gaqhf
                            {
2198
                                using (SQLiteCommand cmd = connection.CreateCommand())
2199
                                {
2200 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);
2201 154d8f43 gaqhf
                                    cmd.Parameters.AddWithValue("@ID2_DRAWING_UID", document.UID);
2202 8847ea67 gaqhf
                                    cmd.Parameters.AddWithValue("@PATH", path);
2203
                                    cmd.Parameters.AddWithValue("@DRAWINGNUMBER", drawingNumber);
2204
                                    cmd.Parameters.AddWithValue("@DRAWINGNAME", drawingName);
2205 154d8f43 gaqhf
                                    cmd.ExecuteNonQuery();
2206
                                }
2207
2208 8847ea67 gaqhf
                                List<Symbol> OPCs = document.SYMBOLS.FindAll(x => x.TYPE == "Piping OPC's" || x.TYPE == "Instrument OPC's");
2209
                                foreach (var item in OPCs)
2210
                                {
2211
                                    using (SQLiteCommand cmd = connection.CreateCommand())
2212
                                    {
2213
                                        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);
2214
                                        cmd.Parameters.AddWithValue("@ID2_OPC_UID", item.UID);
2215
                                        cmd.Parameters.AddWithValue("@SPPID_OPC_MODELITEM_ID", item.SPPID.ModelItemID);
2216
                                        cmd.Parameters.AddWithValue("@ID2_DRAWING_UID", document.UID);
2217
                                        cmd.Parameters.AddWithValue("@ATTRIBUTES", JsonConvert.SerializeObject(item.SPPID.Attributes));
2218
                                        cmd.Parameters.AddWithValue("@PAIRED", false);
2219
                                        cmd.ExecuteNonQuery();
2220
                                    }
2221
                                }
2222
2223
                                transaction.Commit();
2224
                                connection.Close();
2225
                            }
2226
                            catch (Exception ex)
2227
                            {
2228 2425d530 gaqhf
                                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2229 8847ea67 gaqhf
                                transaction.Rollback();
2230 a2c803a0 gaqhf
                                return false;
2231 8847ea67 gaqhf
                            }
2232
                            finally
2233
                            {
2234
                                transaction.Dispose();
2235
                            }
2236 154d8f43 gaqhf
                        }
2237
                    }
2238 8847ea67 gaqhf
                    catch (Exception ex)
2239
                    {
2240 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2241 8847ea67 gaqhf
                        return false;
2242
                    }
2243
                    finally
2244
                    {
2245
                        connection.Dispose();
2246
                    }
2247 154d8f43 gaqhf
                }
2248 8847ea67 gaqhf
            }
2249
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
2250
            {
2251
                using (SqlConnection connection = GetSqlConnection())
2252 154d8f43 gaqhf
                {
2253 8847ea67 gaqhf
                    try
2254
                    {
2255
                        if (connection != null && connection.State == ConnectionState.Open)
2256
                        {
2257 a2c803a0 gaqhf
                            using (SqlCommand cmd = connection.CreateCommand())
2258
                            {
2259 2425d530 gaqhf
                                cmd.Parameters.Clear();
2260
                                cmd.CommandText = string.Format(@"
2261 fb2d9638 gaqhf
                                    IF EXISTS (SELECT * FROM {0} WHERE ID2_DRAWING_UID = '{1}')
2262 2425d530 gaqhf
                                        UPDATE {0} SET PATH = @PATH, DRAWINGNUMBER = @DRAWINGNUMBER, DRAWINGNAME = @DRAWINGNAME WHERE ID2_DRAWING_UID = @ID2_DRAWING_UID
2263
                                    ELSE
2264
                                        INSERT INTO {0} (ID2_DRAWING_UID, PATH, DRAWINGNUMBER, DRAWINGNAME) VALUES (@ID2_DRAWING_UID, @PATH, @DRAWINGNUMBER, @DRAWINGNAME)", SPPID_DRAWING_INFO, document.UID);
2265
2266 a2c803a0 gaqhf
                                cmd.Parameters.AddWithValue("@ID2_DRAWING_UID", document.UID);
2267
                                cmd.Parameters.AddWithValue("@PATH", path);
2268
                                cmd.Parameters.AddWithValue("@DRAWINGNUMBER", drawingNumber);
2269
                                cmd.Parameters.AddWithValue("@DRAWINGNAME", drawingName);
2270
                                cmd.ExecuteNonQuery();
2271
                            }
2272 8847ea67 gaqhf
2273 a2c803a0 gaqhf
                            List<Symbol> OPCs = document.SYMBOLS.FindAll(x => x.TYPE == "Piping OPC's" || x.TYPE == "Instrument OPC's");
2274
                            foreach (var item in OPCs)
2275
                            {
2276
                                using (SqlCommand cmd = connection.CreateCommand())
2277
                                {
2278 2425d530 gaqhf
                                    cmd.Parameters.Clear();
2279
                                    cmd.CommandText = string.Format(@"
2280 c5bc0767 gaqhf
                                    IF EXISTS (SELECT * FROM {0} WHERE ID2_OPC_UID = '{1}')
2281 2425d530 gaqhf
                                        UPDATE {0} SET SPPID_OPC_MODELITEM_ID = @SPPID_OPC_MODELITEM_ID, ID2_DRAWING_UID = @ID2_DRAWING_UID, ATTRIBUTES = @ATTRIBUTES, PAIRED = @PAIRED WHERE ID2_OPC_UID = @ID2_OPC_UID
2282
                                    ELSE
2283
                                        INSERT 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, item.UID);
2284
2285 a2c803a0 gaqhf
                                    cmd.Parameters.AddWithValue("@ID2_OPC_UID", item.UID);
2286 2425d530 gaqhf
                                    if (string.IsNullOrEmpty(item.SPPID.ModelItemID))
2287
                                        cmd.Parameters.AddWithValue("@SPPID_OPC_MODELITEM_ID", DBNull.Value);
2288
                                    else
2289
                                        cmd.Parameters.AddWithValue("@SPPID_OPC_MODELITEM_ID", item.SPPID.ModelItemID);
2290 a2c803a0 gaqhf
                                    cmd.Parameters.AddWithValue("@ID2_DRAWING_UID", document.UID);
2291
                                    cmd.Parameters.AddWithValue("@ATTRIBUTES", JsonConvert.SerializeObject(item.SPPID.Attributes));
2292
                                    cmd.Parameters.AddWithValue("@PAIRED", false);
2293
                                    cmd.ExecuteNonQuery();
2294
                                }
2295
                            }
2296
                            connection.Close();
2297 8847ea67 gaqhf
                        }
2298
                    }
2299
                    catch (Exception ex)
2300
                    {
2301 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2302 a2c803a0 gaqhf
                        return false;
2303 8847ea67 gaqhf
                    }
2304
                    finally
2305
                    {
2306
                        if (connection != null)
2307
                            connection.Dispose();
2308
                    }
2309 154d8f43 gaqhf
                }
2310
            }
2311
            return true;
2312
        }
2313
2314 82ab5276 gaqhf
        public static bool InsertLineNumberInfo(string path, string drawingNumber, string drawingName, SPPID_Document document)
2315 da1aeb27 gaqhf
        {
2316 82ab5276 gaqhf
            Project_Info projectInfo = Project_Info.GetInstance();
2317
            if (projectInfo.DBType == ID2DB_Type.SQLite)
2318
            {
2319 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
2320 82ab5276 gaqhf
                {
2321
                    try
2322
                    {
2323
                        connection.Open();
2324
                        using (SQLiteTransaction transaction = connection.BeginTransaction())
2325
                        {
2326
                            try
2327
                            {
2328
                                using (SQLiteCommand cmd = connection.CreateCommand())
2329
                                {
2330
                                    foreach (var lineNumber in document.LINENUMBERS)
2331
                                    {
2332
                                        foreach (var attribute in lineNumber.ATTRIBUTES)
2333
                                        {
2334
                                            LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
2335
                                            if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
2336
                                            {
2337
                                                if (mapping.SPPIDATTRIBUTENAME == "PlantGroup.Name")
2338
                                                {
2339
                                                    cmd.Parameters.Clear();
2340
2341
2342
2343
                                                    cmd.ExecuteNonQuery();
2344
                                                }
2345
                                            }
2346
                                        }
2347
                                    }
2348
                                }
2349
2350
                                transaction.Commit();
2351
                                connection.Close();
2352
                            }
2353
                            catch (Exception ex)
2354
                            {
2355
                                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2356
                                transaction.Rollback();
2357
                                return false;
2358
                            }
2359
                            finally
2360
                            {
2361
                                transaction.Dispose();
2362
                            }
2363
                        }
2364
                    }
2365
                    catch (Exception ex)
2366
                    {
2367
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2368
                        return false;
2369
                    }
2370
                    finally
2371
                    {
2372
                        connection.Dispose();
2373
                    }
2374
                }
2375
            }
2376
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
2377
            {
2378
                using (SqlConnection connection = GetSqlConnection())
2379
                {
2380
                    try
2381
                    {
2382
                        if (connection != null && connection.State == ConnectionState.Open)
2383
                        {
2384
                            using (SqlCommand cmd = connection.CreateCommand())
2385
                            {
2386
                                foreach (var lineNumber in document.LINENUMBERS)
2387
                                {
2388
                                    foreach (var attribute in lineNumber.ATTRIBUTES)
2389
                                    {
2390
                                        LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
2391
                                        if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
2392
                                        {
2393
                                            if (mapping.SPPIDATTRIBUTENAME == "PlantGroup.Name")
2394
                                            {
2395
                                                cmd.Parameters.Clear();
2396
2397
                                                cmd.ExecuteNonQuery();
2398
                                            }
2399
                                        }
2400
                                    }
2401
                                }
2402
                            }
2403
                            connection.Close();
2404
                        }
2405
                    }
2406
                    catch (Exception ex)
2407
                    {
2408
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2409
                        return false;
2410
                    }
2411
                    finally
2412
                    {
2413
                        if (connection != null)
2414
                            connection.Dispose();
2415
                    }
2416
                }
2417
            }
2418
            return true;
2419 da1aeb27 gaqhf
        }
2420 154d8f43 gaqhf
        public static bool InsertOPCInfo(string UID, string ModelItemID, string drawingUID, bool Paired)
2421
        {
2422
            Project_Info projectInfo = Project_Info.GetInstance();
2423 8847ea67 gaqhf
            if (projectInfo.DBType == ID2DB_Type.SQLite)
2424 154d8f43 gaqhf
            {
2425 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
2426 154d8f43 gaqhf
                {
2427 8847ea67 gaqhf
                    try
2428 154d8f43 gaqhf
                    {
2429 8847ea67 gaqhf
                        connection.Open();
2430
                        using (SQLiteTransaction transaction = connection.BeginTransaction())
2431 154d8f43 gaqhf
                        {
2432 8847ea67 gaqhf
                            try
2433 154d8f43 gaqhf
                            {
2434 8847ea67 gaqhf
                                using (SQLiteCommand cmd = connection.CreateCommand())
2435
                                {
2436
                                    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);
2437
                                    cmd.Parameters.AddWithValue("@ID2_OPC_UID", UID);
2438
                                    cmd.Parameters.AddWithValue("@SPPID_OPC_MODELITEM_ID", ModelItemID);
2439
                                    cmd.Parameters.AddWithValue("@ID2_DRAWING_UID", drawingUID);
2440
                                    cmd.Parameters.AddWithValue("@PAIRED", Paired);
2441
                                    cmd.ExecuteNonQuery();
2442
                                }
2443 154d8f43 gaqhf
2444 8847ea67 gaqhf
                                transaction.Commit();
2445
                                connection.Close();
2446
                            }
2447
                            catch (Exception ex)
2448
                            {
2449 2425d530 gaqhf
                                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2450 8847ea67 gaqhf
                                transaction.Rollback();
2451 a2c803a0 gaqhf
                                return false;
2452 8847ea67 gaqhf
                            }
2453
                            finally
2454
                            {
2455
                                transaction.Dispose();
2456
                            }
2457 69b7387a gaqhf
                        }
2458
                    }
2459 8847ea67 gaqhf
                    catch (Exception ex)
2460
                    {
2461 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2462 8847ea67 gaqhf
                        return false;
2463
                    }
2464
                    finally
2465
                    {
2466
                        connection.Dispose();
2467
                    }
2468 69b7387a gaqhf
                }
2469 8847ea67 gaqhf
            }
2470
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
2471
            {
2472
                using (SqlConnection connection = GetSqlConnection())
2473 69b7387a gaqhf
                {
2474 8847ea67 gaqhf
                    try
2475
                    {
2476
                        if (connection != null && connection.State == ConnectionState.Open)
2477
                        {
2478 a2c803a0 gaqhf
                            using (SqlCommand cmd = connection.CreateCommand())
2479
                            {
2480 2425d530 gaqhf
                                cmd.Parameters.Clear();
2481
                                cmd.CommandText = string.Format(@"
2482
                                    UPDATE {0} SET SPPID_OPC_MODELITEM_ID = @SPPID_OPC_MODELITEM_ID, ID2_DRAWING_UID = @ID2_DRAWING_UID, PAIRED = @PAIRED WHERE ID2_OPC_UID = @ID2_OPC_UID", SPPID_OPC_INFO);
2483 a2c803a0 gaqhf
                                cmd.Parameters.AddWithValue("@ID2_OPC_UID", UID);
2484 2425d530 gaqhf
                                if (string.IsNullOrEmpty(ModelItemID))
2485
                                    cmd.Parameters.AddWithValue("@SPPID_OPC_MODELITEM_ID", DBNull.Value);
2486
                                else
2487
                                    cmd.Parameters.AddWithValue("@SPPID_OPC_MODELITEM_ID", ModelItemID);
2488 a2c803a0 gaqhf
                                cmd.Parameters.AddWithValue("@ID2_DRAWING_UID", drawingUID);
2489
                                cmd.Parameters.AddWithValue("@PAIRED", Paired);
2490
                                cmd.ExecuteNonQuery();
2491
                            }
2492
                            connection.Close();
2493 8847ea67 gaqhf
                        }
2494
                    }
2495
                    catch (Exception ex)
2496
                    {
2497 2425d530 gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2498 a2c803a0 gaqhf
                        return false;
2499 8847ea67 gaqhf
                    }
2500
                    finally
2501
                    {
2502
                        if (connection != null)
2503
                            connection.Dispose();
2504
                    }
2505 69b7387a gaqhf
                }
2506
            }
2507
            return true;
2508
        }
2509 2425d530 gaqhf
2510
        public static bool ExportMappingData()
2511
        {
2512
            bool result = true;
2513
            try
2514
            {
2515
                DataSet dataSet = new DataSet();
2516
                DataTable symbolMappingDT = GetTable(SPPID_SYMBOL_MAPPING_TABLE);
2517
                if (symbolMappingDT != null)
2518
                {
2519
                    symbolMappingDT.TableName = SPPID_SYMBOL_MAPPING_TABLE;
2520
                    dataSet.Tables.Add(symbolMappingDT);
2521
                }
2522
                else
2523
                    result = false;
2524
2525
                DataTable attributeMappingDT = GetTable(SPPID_ATTRIBUTE_MAPPING_TABLE);
2526
                if (attributeMappingDT != null)
2527
                {
2528
                    attributeMappingDT.TableName = SPPID_ATTRIBUTE_MAPPING_TABLE;
2529
                    dataSet.Tables.Add(attributeMappingDT);
2530
                }
2531
                else
2532
                    result = false;
2533
2534
                if (result)
2535
                {
2536
                    string text = JsonConvert.SerializeObject(dataSet);
2537
                    using (StreamWriter sw = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\ExportFile.mapf", false))
2538
                    {
2539
                        sw.Write(text);
2540
                        sw.Close();
2541
                        sw.Dispose();
2542
                    }
2543
                }
2544
            }
2545
            catch (Exception ex)
2546
            {
2547
                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2548
                result = false;
2549
            }
2550
2551
            return result;
2552
        }
2553
2554
        public static bool ImportMappingData()
2555
        {
2556
            bool result = true;
2557
            try
2558
            {
2559
                string sJson = string.Empty;
2560
                using (StreamReader sw = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\ExportFile.mapf"))
2561
                {
2562
                    sJson = sw.ReadToEnd();
2563
                    sw.Close();
2564
                    sw.Dispose();
2565
                }
2566
2567
                DataSet dataSet = JsonConvert.DeserializeObject<DataSet>(sJson);
2568
                DataTable symbolMappingDT = dataSet.Tables[SPPID_SYMBOL_MAPPING_TABLE];
2569
                if (symbolMappingDT == null || !ImportSymbolMappingTable(symbolMappingDT))
2570
                    result = false;
2571
2572
                DataTable attributeMappingDT = dataSet.Tables[SPPID_ATTRIBUTE_MAPPING_TABLE];
2573
                if (attributeMappingDT == null || !ImportAttributeMappingTable(attributeMappingDT))
2574
                    result = false;
2575
            }
2576
            catch (Exception ex)
2577
            {
2578
                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2579
                result = false;
2580
            }
2581
2582
            return result;
2583
        }
2584
2585
        private static DataTable GetTable(string tableName)
2586
        {
2587
            DataTable dt = new DataTable();
2588
            Project_Info projectInfo = Project_Info.GetInstance();
2589
            if (projectInfo.DBType == ID2DB_Type.SQLite)
2590
            {
2591 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
2592 2425d530 gaqhf
                {
2593
                    try
2594
                    {
2595
                        connection.Open();
2596
                        using (SQLiteCommand cmd = connection.CreateCommand())
2597
                        {
2598
                            cmd.CommandText = string.Format("SELECT * FROM {0}", tableName);
2599
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
2600
                                dt.Load(dr);
2601
                        }
2602
                        connection.Close();
2603
                    }
2604
                    catch (Exception ex)
2605
                    {
2606
                        dt = null;
2607
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2608
                    }
2609
                    finally
2610
                    {
2611
                        connection.Dispose();
2612
                    }
2613
                }
2614
            }
2615
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
2616
            {
2617
                using (SqlConnection connection = GetSqlConnection())
2618
                {
2619
                    try
2620
                    {
2621
                        if (connection != null && connection.State == ConnectionState.Open)
2622
                        {
2623
                            using (SqlCommand cmd = connection.CreateCommand())
2624
                            {
2625
                                cmd.CommandText = string.Format("SELECT * FROM {0}", tableName);
2626
                                using (SqlDataReader dr = cmd.ExecuteReader())
2627
                                    dt.Load(dr);
2628
                            }
2629
                            connection.Close();
2630
                        }
2631
                    }
2632
                    catch (Exception ex)
2633
                    {
2634
                        dt = null;
2635
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2636
                    }
2637
                    finally
2638
                    {
2639
                        if (connection != null)
2640
                            connection.Dispose();
2641
                    }
2642
                }
2643
            }
2644
2645
            return dt;
2646
        }
2647
2648
        private static bool ImportSymbolMappingTable(DataTable dt)
2649
        {
2650
            bool result = false;
2651
2652
            Project_Info projectInfo = Project_Info.GetInstance();
2653
            if (projectInfo.DBType == ID2DB_Type.SQLite)
2654
            {
2655 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
2656 2425d530 gaqhf
                {
2657
                    try
2658
                    {
2659
                        connection.Open();
2660
                        using (SQLiteTransaction transaction = connection.BeginTransaction())
2661
                        {
2662
                            try
2663
                            {
2664
                                using (SQLiteCommand cmd = connection.CreateCommand())
2665
                                {
2666
                                    foreach (DataRow item in dt.Rows)
2667
                                    {
2668
                                        string UID = DBNull.Value.Equals(item["UID"]) ? null : (string)item["UID"];
2669
                                        string NAME = DBNull.Value.Equals(item["NAME"]) ? null : (string)item["NAME"];
2670
                                        string SPPID_SYMBOL_PATH = DBNull.Value.Equals(item["SPPID_SYMBOL_PATH"]) ? null : (string)item["SPPID_SYMBOL_PATH"];
2671
                                        bool LEADERLINE = Convert.ToBoolean(item["LEADERLINE"]);
2672
2673
                                        cmd.Parameters.Clear();
2674
                                        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);
2675
                                        cmd.Parameters.AddWithValue("@UID", UID);
2676
                                        cmd.Parameters.AddWithValue("@NAME", NAME);
2677
                                        cmd.Parameters.AddWithValue("@SPPID_SYMBOL_PATH", SPPID_SYMBOL_PATH);
2678
                                        cmd.Parameters.AddWithValue("@LEADERLINE", LEADERLINE);
2679
                                        cmd.ExecuteNonQuery();
2680
                                    }
2681
                                }
2682
                                transaction.Commit();
2683
                                connection.Close();
2684
                                result = true;
2685
                            }
2686
                            catch (Exception ex)
2687
                            {
2688
                                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2689
                                transaction.Rollback();
2690
                            }
2691
                            finally
2692
                            {
2693
                                transaction.Dispose();
2694
                            }
2695
                        }
2696
                    }
2697
                    catch (Exception ex)
2698
                    {
2699
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2700
                    }
2701
                    finally
2702
                    {
2703
                        connection.Dispose();
2704
                    }
2705
                }
2706
            }
2707
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
2708
            {
2709
                using (SqlConnection connection = GetSqlConnection())
2710
                {
2711
                    try
2712
                    {
2713
                        if (connection != null && connection.State == ConnectionState.Open)
2714
                        {
2715
                            using (SqlCommand cmd = connection.CreateCommand())
2716
                            {
2717
                                foreach (DataRow item in dt.Rows)
2718
                                {
2719
                                    string UID = DBNull.Value.Equals(item["UID"]) ? null : (string)item["UID"];
2720
                                    string NAME = DBNull.Value.Equals(item["NAME"]) ? null : (string)item["NAME"];
2721
                                    string SPPID_SYMBOL_PATH = DBNull.Value.Equals(item["SPPID_SYMBOL_PATH"]) ? null : (string)item["SPPID_SYMBOL_PATH"];
2722
                                    bool LEADERLINE = DBNull.Value.Equals(item["LEADERLINE"]) ? false : Convert.ToBoolean(item["LEADERLINE"]);
2723
2724
                                    cmd.Parameters.Clear();
2725
                                    cmd.CommandText = string.Format(@"
2726
                                    IF EXISTS (SELECT * FROM {0} WHERE UID = '{1}')
2727
                                        UPDATE {0} SET NAME = @NAME, SPPID_SYMBOL_PATH = @SPPID_SYMBOL_PATH, LEADERLINE = @LEADERLINE WHERE UID = @UID
2728
                                    ELSE
2729
                                        INSERT INTO {0} (UID, NAME, SPPID_SYMBOL_PATH, LEADERLINE) VALUES (@UID, @NAME, @SPPID_SYMBOL_PATH, @LEADERLINE)", SPPID_SYMBOL_MAPPING_TABLE, UID);
2730
                                    cmd.Parameters.AddWithValue("@UID", UID);
2731
                                    if (string.IsNullOrEmpty(NAME))
2732
                                        cmd.Parameters.AddWithValue("@NAME", DBNull.Value);
2733
                                    else
2734
                                        cmd.Parameters.AddWithValue("@NAME", NAME);
2735
                                    if (string.IsNullOrEmpty(SPPID_SYMBOL_PATH))
2736
                                        cmd.Parameters.AddWithValue("@SPPID_SYMBOL_PATH", DBNull.Value);
2737
                                    else
2738
                                        cmd.Parameters.AddWithValue("@SPPID_SYMBOL_PATH", SPPID_SYMBOL_PATH);
2739
                                    cmd.Parameters.AddWithValue("@LEADERLINE", LEADERLINE);
2740
                                    cmd.ExecuteNonQuery();
2741
                                }
2742
                            }
2743
                            connection.Close();
2744
                            result = true;
2745
                        }
2746
                    }
2747
                    catch (Exception ex)
2748
                    {
2749
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2750
                    }
2751
                    finally
2752
                    {
2753
                        if (connection != null)
2754
                            connection.Dispose();
2755
                    }
2756
                }
2757
            }
2758
2759
            return result;
2760
        }
2761
2762
        private static bool ImportAttributeMappingTable(DataTable dt)
2763
        {
2764
            bool result = false;
2765
2766
            Project_Info projectInfo = Project_Info.GetInstance();
2767
            if (projectInfo.DBType == ID2DB_Type.SQLite)
2768
            {
2769 8770bd0a gaqhf
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath), true))
2770 2425d530 gaqhf
                {
2771
                    try
2772
                    {
2773
                        connection.Open();
2774
                        using (SQLiteTransaction transaction = connection.BeginTransaction())
2775
                        {
2776
                            try
2777
                            {
2778
                                using (SQLiteCommand cmd = connection.CreateCommand())
2779
                                {
2780
                                    foreach (DataRow item in dt.Rows)
2781
                                    {
2782
                                        string UID = DBNull.Value.Equals(item["UID"]) ? null : (string)item["UID"];
2783
                                        string SPPID_ATTRIBUTE = DBNull.Value.Equals(item["SPPID_ATTRIBUTE"]) ? null : (string)item["SPPID_ATTRIBUTE"];
2784
2785
                                        cmd.Parameters.Clear();
2786
                                        cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, SPPID_ATTRIBUTE) VALUES (@UID, @SPPID_ATTRIBUTE)", SPPID_ATTRIBUTE_MAPPING_TABLE);
2787
                                        cmd.Parameters.AddWithValue("@UID", UID);
2788
                                        cmd.Parameters.AddWithValue("@SPPID_ATTRIBUTE", SPPID_ATTRIBUTE);
2789
                                        cmd.ExecuteNonQuery();
2790
                                    }
2791
                                }
2792
                                transaction.Commit();
2793
                                connection.Close();
2794
                                result = true;
2795
                            }
2796
                            catch (Exception ex)
2797
                            {
2798
                                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2799
                                transaction.Rollback();
2800
                            }
2801
                            finally
2802
                            {
2803
                                transaction.Dispose();
2804
                            }
2805
                        }
2806
                    }
2807
                    catch (Exception ex)
2808
                    {
2809
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2810
                    }
2811
                    finally
2812
                    {
2813
                        connection.Dispose();
2814
                    }
2815
                }
2816
            }
2817
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
2818
            {
2819
                using (SqlConnection connection = GetSqlConnection())
2820
                {
2821
                    try
2822
                    {
2823
                        if (connection != null && connection.State == ConnectionState.Open)
2824
                        {
2825
                            using (SqlCommand cmd = connection.CreateCommand())
2826
                            {
2827
                                foreach (DataRow item in dt.Rows)
2828
                                {
2829
                                    string UID = DBNull.Value.Equals(item["UID"]) ? null : (string)item["UID"];
2830
                                    string SPPID_ATTRIBUTE = DBNull.Value.Equals(item["SPPID_ATTRIBUTE"]) ? null : (string)item["SPPID_ATTRIBUTE"];
2831
2832
                                    cmd.Parameters.Clear();
2833
                                    cmd.CommandText = string.Format(@"
2834
                                    IF EXISTS (SELECT * FROM {0} WHERE UID = '{1}')
2835
                                        UPDATE {0} SET SPPID_ATTRIBUTE = @SPPID_ATTRIBUTE WHERE UID = @UID
2836
                                    ELSE
2837
                                        INSERT INTO {0} (UID, SPPID_ATTRIBUTE) VALUES (@UID, @SPPID_ATTRIBUTE)", SPPID_ATTRIBUTE_MAPPING_TABLE, UID);
2838
2839
                                    cmd.Parameters.AddWithValue("@UID", UID);
2840
                                    if (string.IsNullOrEmpty(SPPID_ATTRIBUTE))
2841
                                        cmd.Parameters.AddWithValue("@SPPID_ATTRIBUTE", DBNull.Value);
2842
                                    else
2843
                                        cmd.Parameters.AddWithValue("@SPPID_ATTRIBUTE", SPPID_ATTRIBUTE);
2844
                                    cmd.ExecuteNonQuery();
2845
                                }
2846
                            }
2847
                            connection.Close();
2848
                            result = true;
2849
                        }
2850
                    }
2851
                    catch (Exception ex)
2852
                    {
2853
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
2854
                    }
2855
                    finally
2856
                    {
2857
                        if (connection != null)
2858
                            connection.Dispose();
2859
                    }
2860
                }
2861
            }
2862
2863
2864
2865
            return result;
2866
        }
2867 b18dc619 gaqhf
    }
2868
}
클립보드 이미지 추가 (최대 크기: 500 MB)