프로젝트

일반

사용자정보

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

hytos / DTI_PID / APIDConverter / DB / Project_DB.cs @ 4aba6868

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

1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
using System.Globalization;
7
using System.Data.SQLite;
8
using System.Data;
9
using System.Data.SqlClient;
10
using System.IO;
11
using Newtonsoft.Json;
12
using AVEVA.PID.CustomizationUtility;
13
using AVEVA.PID.CustomizationUtility.Model;
14

    
15
namespace AVEVA.PID.CustomizationUtility.DB
16
{
17
    public class Project_DB
18
    {
19
        const string APID_SYMBOL_MAPPING_TABLE = "T_APID_SYMBOL_MAPPING";
20

    
21
        const string LineProperties_TABLE = "LineProperties";
22
        const string LineTypes_TABLE = "LineTypes";
23
        const string SymbolType_TABLE = "SymbolType";
24
        const string SymbolAttribute_TABLE = "SymbolAttribute";
25
        const string Symbol_TABLE = "Symbol";
26
        const string OPCRelations_TABLE = "OPCRelations";
27

    
28
        #region Only ID2 DB
29
        private static SqlConnection GetSqlConnection()
30
        {
31
            Project_Info projectInfo = Project_Info.GetInstance();
32
            SqlConnection connection = null;
33
            try
34
            {
35
                connection = new SqlConnection(string.Format(CultureInfo.CurrentCulture,
36
                    @"Data Source = {0},{1}; Initial CataLog = {2}; User ID = {3}; Password = {4};",
37
                    projectInfo.ServerIP,
38
                    projectInfo.Port,
39
                    System.IO.Path.GetFileName(projectInfo.DefaultPath),
40
                    projectInfo.DBUser,
41
                    projectInfo.DBPassword));
42

    
43
                connection.Open();
44
            }
45
            catch (Exception ex)
46
            {
47
                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
48
                if (connection != null)
49
                    connection.Dispose();
50
                connection = null;
51
            }
52

    
53
            return connection;
54
        }
55
        public static bool ConnTestAndCreateTable()
56
        {
57
            bool result = false;
58
            Project_Info projectInfo = Project_Info.GetInstance();
59
            if (projectInfo.DBType == ID2DB_Type.SQLite)
60
            {
61
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, @"Data Source = {0}", projectInfo.DBFilePath)))
62
                {
63
                    try
64
                    {
65
                        connection.Open();
66
                        if (connection.State == ConnectionState.Open)
67
                        {
68
                            using (SQLiteCommand cmd = connection.CreateCommand())
69
                            {
70
                                cmd.CommandText = "SELECT NAME FROM sqlite_master WHERE type='table'";
71
                                using (SQLiteDataReader dr = cmd.ExecuteReader())
72
                                using (DataTable dt = new DataTable())
73
                                {
74
                                    dt.Load(dr);
75

    
76
                                    if (dt.Select(string.Format("NAME = '{0}'", APID_SYMBOL_MAPPING_TABLE)).Length == 0)
77
                                    {
78
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, NAME TEXT, APID_SYMBOL TEXT, DATA1 TEXT)", APID_SYMBOL_MAPPING_TABLE);
79
                                        cmd.ExecuteNonQuery();
80
                                    }
81
                                }
82
                            }
83
                            result = true;
84
                        }
85
                        connection.Close();
86
                    }
87
                    catch (Exception ex)
88
                    {
89
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
90
                    }
91
                    finally
92
                    {
93
                        connection.Dispose();
94
                    }
95
                }
96
            }
97
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
98
            {
99
                using (SqlConnection connection = GetSqlConnection())
100
                {
101
                    try
102
                    {
103
                        if (connection != null && connection.State == ConnectionState.Open)
104
                        {
105
                            using (SqlCommand cmd = connection.CreateCommand())
106
                            {
107
                                cmd.CommandText = "SELECT TABLE_NAME AS NAME FROM INFORMATION_SCHEMA.TABLES";
108
                                using (SqlDataReader dr = cmd.ExecuteReader())
109
                                using (DataTable dt = new DataTable())
110
                                {
111
                                    dt.Load(dr);
112

    
113
                                    if (dt.Select(string.Format("NAME = '{0}'", APID_SYMBOL_MAPPING_TABLE)).Length == 0)
114
                                    {
115
                                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID varchar(255) PRIMARY KEY, NAME varchar(MAX), APID_SYMBOL varchar(MAX), DATA1 varchar(255))", APID_SYMBOL_MAPPING_TABLE);
116
                                        cmd.ExecuteNonQuery();
117
                                    }
118
                                    
119
                                }
120
                            }
121
                            result = true;
122
                        }
123
                    }
124
                    catch (Exception ex)
125
                    {
126
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
127
                    }
128
                    finally
129
                    {
130
                        if (connection != null)
131
                            connection.Dispose();
132
                    }
133
                }
134
            }
135

    
136
            return result;
137
        }
138
        public static DataTable GetSymbolMappingTable()
139
        {
140
            DataTable dt = new DataTable();
141
            Project_Info projectInfo = Project_Info.GetInstance();
142
            if (projectInfo.DBType == ID2DB_Type.SQLite)
143
            {
144
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
145
                {
146
                    try
147
                    {
148
                        connection.Open();
149
                        using (SQLiteCommand cmd = connection.CreateCommand())
150
                        {
151
                            cmd.CommandText = string.Format(@"
152
                            SELECT s.UID, s.Name, st.Type, sp.APID_SYMBOL, sp.DATA1 FROM {1} as st, {0} as s 
153
                                LEFT OUTER JOIN {2} as sp 
154
                                    ON s.UID = SP.UID 
155
                            WHERE s.SymbolType_UID = st.UID 
156
                            AND st.Type != 'Instrument OPC''s' AND st.Type != 'Piping OPC''s' 
157
                            ORDER BY st.TYPE ASC;", Symbol_TABLE, SymbolType_TABLE, APID_SYMBOL_MAPPING_TABLE);
158
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
159
                                dt.Load(dr);
160

    
161
                            DataTable dtClone = dt.Clone();
162
                            dtClone.Columns["UID"].DataType = typeof(string);
163
                            foreach (DataRow row in dt.Rows)
164
                            {
165
                                dtClone.ImportRow(row);
166
                            }
167
                            dt.Dispose();
168
                            dt = dtClone;
169
                        }
170
                        connection.Close();
171
                    }
172
                    catch (Exception ex)
173
                    {
174
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
175
                    }
176
                    finally
177
                    {
178
                        connection.Dispose();
179
                    }
180
                }
181
            }
182
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
183
            {
184
                using (SqlConnection connection = GetSqlConnection())
185
                {
186
                    try
187
                    {
188
                        if (connection != null && connection.State == ConnectionState.Open)
189
                        {
190
                            using (SqlCommand cmd = connection.CreateCommand())
191
                            {
192
                                cmd.CommandText = string.Format(@"
193
                            SELECT CONVERT(VARCHAR(255), s.UID) AS UID, s.Name, st.Type, sp.APID_SYMBOL, sp.DATA1 FROM {1} as st, {0} as s 
194
                                LEFT OUTER JOIN {2} as sp 
195
                                    ON CONVERT(VARCHAR(255), s.UID) = CONVERT(VARCHAR(255), SP.UID)
196
                            WHERE s.SymbolType_UID = st.UID 
197
                            AND st.Type != 'Instrument OPC''s' AND st.Type != 'Piping OPC''s' 
198
                            ORDER BY st.TYPE ASC;", Symbol_TABLE, SymbolType_TABLE, APID_SYMBOL_MAPPING_TABLE);
199
                                using (SqlDataReader dr = cmd.ExecuteReader())
200
                                    dt.Load(dr);
201
                            }
202
                            connection.Close();
203
                        }
204
                    }
205
                    catch (Exception ex)
206
                    {
207
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
208
                    }
209
                    finally
210
                    {
211
                        if (connection != null)
212
                            connection.Dispose();
213
                    }
214
                }
215
            }
216

    
217
            return dt;
218
        }
219
        public static DataTable GetLineMappingTable()
220
        {
221
            DataTable dt = new DataTable();
222
            Project_Info projectInfo = Project_Info.GetInstance();
223
            if (projectInfo.DBType == ID2DB_Type.SQLite)
224
            {
225
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
226
                {
227
                    try
228
                    {
229
                        connection.Open();
230
                        using (SQLiteCommand cmd = connection.CreateCommand())
231
                        {
232
                            cmd.CommandText = string.Format(@"
233
                            SELECT l.UID, l.Name, sp.APID_SYMBOL, sp.DATA1 FROM {0} as l 
234
                                LEFT OUTER JOIN {1} as sp 
235
                                    ON l.UID = SP.UID ;", LineTypes_TABLE, APID_SYMBOL_MAPPING_TABLE);
236
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
237
                                dt.Load(dr);
238
                        }
239
                        connection.Close();
240
                    }
241
                    catch (Exception ex)
242
                    {
243
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
244
                    }
245
                    finally
246
                    {
247
                        connection.Dispose();
248
                    }
249
                }
250
            }
251
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
252
            {
253
                using (SqlConnection connection = GetSqlConnection())
254
                {
255
                    try
256
                    {
257
                        if (connection != null && connection.State == ConnectionState.Open)
258
                        {
259
                            using (SqlCommand cmd = connection.CreateCommand())
260
                            {
261
                                cmd.CommandText = string.Format(@"
262
                            SELECT l.UID, l.Name, sp.APID_SYMBOL, sp.DATA1 FROM {0} as l 
263
                                LEFT OUTER JOIN {1} as sp 
264
                                    ON l.UID = SP.UID ;", LineTypes_TABLE, APID_SYMBOL_MAPPING_TABLE);
265
                                using (SqlDataReader dr = cmd.ExecuteReader())
266
                                    dt.Load(dr);
267
                            }
268
                            connection.Close();
269
                        }
270
                    }
271
                    catch (Exception ex)
272
                    {
273
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
274
                    }
275
                    finally
276
                    {
277
                        if (connection != null)
278
                            connection.Dispose();
279
                    }
280
                }
281
            }
282

    
283
            return dt;
284
        }
285
        public static DataTable SelectID2SymbolTable()
286
        {
287
            DataTable dt = new DataTable();
288
            Project_Info projectInfo = Project_Info.GetInstance();
289
            if (projectInfo.DBType == ID2DB_Type.SQLite)
290
            {
291
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
292
                {
293
                    try
294
                    {
295
                        connection.Open();
296
                        using (SQLiteCommand cmd = connection.CreateCommand())
297
                        {
298
                            cmd.CommandText = @"SELECT * FROM Symbol";
299
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
300
                                dt.Load(dr);
301
                        }
302
                        connection.Close();
303
                    }
304
                    catch (Exception ex)
305
                    {
306
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
307
                    }
308
                    finally
309
                    {
310
                        connection.Dispose();
311
                    }
312
                }
313
            }
314
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
315
            {
316
                using (SqlConnection connection = GetSqlConnection())
317
                {
318
                    try
319
                    {
320
                        if (connection != null && connection.State == ConnectionState.Open)
321
                        {
322
                            using (SqlCommand cmd = connection.CreateCommand())
323
                            {
324
                                cmd.CommandText = @"SELECT * FROM Symbol";
325
                                using (SqlDataReader dr = cmd.ExecuteReader())
326
                                    dt.Load(dr);
327
                            }
328
                            connection.Close();
329
                        }
330
                    }
331
                    catch (Exception ex)
332
                    {
333
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
334
                    }
335
                    finally
336
                    {
337
                        if (connection != null)
338
                            connection.Dispose();
339
                    }
340
                }
341
            }
342

    
343
            return dt;
344
        }
345
        public static DataTable SelectSymbolType()
346
        {
347
            DataTable dt = new DataTable();
348
            Project_Info projectInfo = Project_Info.GetInstance();
349
            if (projectInfo.DBType == ID2DB_Type.SQLite)
350
            {
351
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
352
                {
353
                    try
354
                    {
355
                        connection.Open();
356
                        using (SQLiteCommand cmd = connection.CreateCommand())
357
                        {
358
                            cmd.CommandText = string.Format("SELECT * FROM {0}", SymbolType_TABLE);
359
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
360
                                dt.Load(dr);
361
                        }
362
                        connection.Close();
363
                    }
364
                    catch (Exception ex)
365
                    {
366
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
367
                    }
368
                    finally
369
                    {
370
                        connection.Dispose();
371
                    }
372
                }
373
            }
374
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
375
            {
376
                using (SqlConnection connection = GetSqlConnection())
377
                {
378
                    try
379
                    {
380
                        if (connection != null && connection.State == ConnectionState.Open)
381
                        {
382
                            using (SqlCommand cmd = connection.CreateCommand())
383
                            {
384
                                cmd.CommandText = string.Format("SELECT * FROM {0}", SymbolType_TABLE);
385
                                using (SqlDataReader dr = cmd.ExecuteReader())
386
                                    dt.Load(dr);
387
                            }
388
                            connection.Close();
389
                        }
390
                    }
391
                    catch (Exception ex)
392
                    {
393
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
394
                    }
395
                    finally
396
                    {
397
                        if (connection != null)
398
                            connection.Dispose();
399
                    }
400
                }
401
            }
402

    
403
            return dt;
404
        }
405
        public static DataTable SelectDrawings()
406
        {
407
            DataTable dt = new DataTable();
408
            Project_Info projectInfo = Project_Info.GetInstance();
409
            if (projectInfo.DBType == ID2DB_Type.SQLite)
410
            {
411
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
412
                {
413
                    try
414
                    {
415
                        connection.Open();
416
                        using (SQLiteCommand cmd = connection.CreateCommand())
417
                        {
418
                            cmd.CommandText = string.Format("SELECT * FROM {0}", "Drawings");
419
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
420
                                dt.Load(dr);
421
                        }
422
                        connection.Close();
423
                    }
424
                    catch (Exception ex)
425
                    {
426
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
427
                    }
428
                    finally
429
                    {
430
                        connection.Dispose();
431
                    }
432
                }
433
            }
434
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
435
            {
436
                using (SqlConnection connection = GetSqlConnection())
437
                {
438
                    try
439
                    {
440
                        if (connection != null && connection.State == ConnectionState.Open)
441
                        {
442
                            using (SqlCommand cmd = connection.CreateCommand())
443
                            {
444
                                cmd.CommandText = string.Format("SELECT * FROM {0}", "Drawings");
445
                                using (SqlDataReader dr = cmd.ExecuteReader())
446
                                    dt.Load(dr);
447
                            }
448
                            connection.Close();
449
                        }
450
                    }
451
                    catch (Exception ex)
452
                    {
453
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
454
                    }
455
                    finally
456
                    {
457
                        if (connection != null)
458
                            connection.Dispose();
459
                    }
460
                }
461
            }
462

    
463
            return dt;
464
        }
465
        public static bool InsertSymbolMapping(List<Tuple<string, string, string, string>> datas)
466
        {
467
            Project_Info projectInfo = Project_Info.GetInstance();
468
            if (projectInfo.DBType == ID2DB_Type.SQLite)
469
            {
470
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
471
                {
472
                    try
473
                    {
474
                        connection.Open();
475
                        using (SQLiteTransaction transaction = connection.BeginTransaction())
476
                        {
477
                            try
478
                            {
479
                                using (SQLiteCommand cmd = connection.CreateCommand())
480
                                {
481
                                    foreach (var item in datas)
482
                                    {
483
                                        cmd.Parameters.Clear();
484
                                        cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, NAME, APID_SYMBOL, DATA1) VALUES (@UID, @NAME, @APID_SYMBOL, @DATA1)", APID_SYMBOL_MAPPING_TABLE);
485
                                        cmd.Parameters.AddWithValue("@UID", item.Item1);
486
                                        cmd.Parameters.AddWithValue("@NAME", item.Item2);
487
                                        cmd.Parameters.AddWithValue("@APID_SYMBOL", item.Item3);
488
                                        cmd.Parameters.AddWithValue("@DATA1", item.Item4);
489
                                        cmd.ExecuteNonQuery();
490
                                    }
491
                                }
492
                                transaction.Commit();
493
                                connection.Close();
494
                            }
495
                            catch (Exception ex)
496
                            {
497
                                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
498
                                transaction.Rollback();
499
                                return false;
500
                            }
501
                            finally
502
                            {
503
                                transaction.Dispose();
504
                            }
505
                        }
506
                    }
507
                    catch (Exception ex)
508
                    {
509
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
510
                        return false;
511
                    }
512
                    finally
513
                    {
514
                        connection.Dispose();
515
                    }
516
                }
517
            }
518
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
519
            {
520
                using (SqlConnection connection = GetSqlConnection())
521
                {
522
                    try
523
                    {
524
                        if (connection != null && connection.State == ConnectionState.Open)
525
                        {
526
                            using (SqlCommand cmd = connection.CreateCommand())
527
                            {
528
                                foreach (var item in datas)
529
                                {
530
                                    cmd.Parameters.Clear();
531
                                    cmd.CommandText = string.Format(@"
532
                                    IF EXISTS (SELECT * FROM {0} WHERE UID = '{1}')
533
                                        UPDATE {0} SET NAME = @NAME, APID_SYMBOL = @APID_SYMBOL, DATA1 = @DATA1 WHERE UID = @UID
534
                                    ELSE
535
                                        INSERT INTO {0} (UID, NAME, APID_SYMBOL, DATA1) VALUES (@UID, @NAME, @APID_SYMBOL, @DATA1)", APID_SYMBOL_MAPPING_TABLE, item.Item1);
536
                                    cmd.Parameters.AddWithValue("@UID", item.Item1);
537
                                    if (string.IsNullOrEmpty(item.Item2))
538
                                        cmd.Parameters.AddWithValue("@NAME", DBNull.Value);
539
                                    else
540
                                        cmd.Parameters.AddWithValue("@NAME", item.Item2);
541
                                    if (string.IsNullOrEmpty(item.Item3))
542
                                        cmd.Parameters.AddWithValue("@APID_SYMBOL", DBNull.Value);
543
                                    else
544
                                        cmd.Parameters.AddWithValue("@APID_SYMBOL", item.Item3);
545
                                    if (string.IsNullOrEmpty(item.Item4))
546
                                        cmd.Parameters.AddWithValue("@DATA1", DBNull.Value);
547
                                    else
548
                                        cmd.Parameters.AddWithValue("@DATA1", item.Item4);
549

    
550
                                    cmd.ExecuteNonQuery();
551
                                }
552
                            }
553
                            connection.Close();
554
                        }
555
                    }
556
                    catch (Exception ex)
557
                    {
558
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
559
                        return false;
560
                    }
561
                    finally
562
                    {
563
                        if (connection != null)
564
                            connection.Dispose();
565
                    }
566
                }
567
            }
568

    
569
            return true;
570
        }
571
        #endregion
572

    
573
        #region AVEVA
574
        public static string GetAvevaConnectionString()
575
        {
576
            string strConn = string.Empty;
577
            if (Utilities.strSQLWinAuthentication.ToUpper() == "YES")
578
            {
579
                strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Integrated Security=SSPI;Initial Catalog={0};", Utilities.strSQLDatabaseName);
580
            }
581
            else if (Utilities.strSQLWinAuthentication.ToUpper() == "NO")
582
            {
583
                string strAccessString = "User ID=" + Utilities.strSQLUserName + ";Password=" + Utilities.strSQLPassword;
584
                strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Initial Catalog=" + Utilities.strSQLDatabaseName + ";" + strAccessString);
585
            }
586

    
587
            return strConn;
588
        }
589
        public static string GetAvevaConnectionString_Reports()
590
        {
591
            string strConn = string.Empty;
592
            if (Utilities.strSQLWinAuthentication.ToUpper() == "YES")
593
            {
594
                strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Integrated Security=SSPI;Initial Catalog={0};", Utilities.strSQLReportsDatabaseName);
595
            }
596
            else if (Utilities.strSQLWinAuthentication.ToUpper() == "NO")
597
            {
598
                string strAccessString = "User ID=" + Utilities.strSQLUserName + ";Password=" + Utilities.strSQLPassword;
599
                strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Initial Catalog=" + Utilities.strSQLReportsDatabaseName + ";" + strAccessString);
600
            }
601

    
602
            return strConn;
603
        }
604
        public static string GetAvevaConnectionString_Admin()
605
        {
606
            string strConn = string.Empty;
607
            if (Utilities.strSQLWinAuthentication.ToUpper() == "YES")
608
            {
609
                strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Integrated Security=SSPI;Initial Catalog={0};", Utilities.strSQLAdminDatabaseName);
610
            }
611
            else if (Utilities.strSQLWinAuthentication.ToUpper() == "NO")
612
            {
613
                string strAccessString = "User ID=" + Utilities.strSQLUserName + ";Password=" + Utilities.strSQLPassword;
614
                strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Initial Catalog=" + Utilities.strSQLAdminDatabaseName + ";" + strAccessString);
615
            }
616

    
617
            return strConn;
618
        }
619
        public static string GetDirectiveValue(string name)
620
        {
621
            string result = null;
622

    
623
            using (SqlConnection connection = new SqlConnection())
624
            {
625
                connection.ConnectionString = GetAvevaConnectionString_Admin();
626
                connection.Open();
627
                using (SqlCommand cmd = connection.CreateCommand())
628
                {
629
                    cmd.CommandText = string.Format("select DirectiveValue from ProjectDirectives where DirectiveName = '{0}'", name);
630
                    using (SqlDataReader dr = cmd.ExecuteReader())
631
                    {
632
                        if (dr.Read())
633
                            result = dr.GetString(0);
634
                    }
635
                }
636
                connection.Close();
637
            }
638

    
639
            return result;
640
        }
641
        public static DataTable GetDrawingTemplate()
642
        {
643
            DataTable dt = new DataTable();
644

    
645
            using (SqlConnection connection = new SqlConnection())
646
            {
647
                connection.ConnectionString = GetAvevaConnectionString_Reports();
648
                connection.Open();
649
                using (SqlCommand cmd = connection.CreateCommand())
650
                {
651
                    cmd.CommandText = "select ID, Name,IsDWG,DateCreation,MachineName,FutureUse1,FutureUse2 from DrawingTemplates where IsDWG=0";
652
                    using (SqlDataReader dr = cmd.ExecuteReader())
653
                        dt.Load(dr);
654
                }
655
                connection.Close();
656
            }
657

    
658
            return dt;
659
        }
660
        public static DataTable SelectStandardSymbolTable()
661
        {
662
            DataTable dt = new DataTable();
663

    
664
            using (SqlConnection connection = new SqlConnection())
665
            {
666
                connection.ConnectionString = GetAvevaConnectionString_Admin();
667
                connection.Open();
668
                using (SqlCommand cmd = connection.CreateCommand())
669
                {
670
                    cmd.CommandText = string.Format(@"
671
                    SELECT ss.ID, ss.Symbol_Name, sps.Relative_Path FROM {0} as ss
672
                    LEFT OUTER JOIN {1} as sps
673
                    ON ss.Relative_Path = sps.ID
674
                    ORDER BY sps.ID ASC
675
                    ;", "stdSymbols", "StdPrjFolStructure");
676

    
677
                    using (SqlDataReader dr = cmd.ExecuteReader())
678
                        dt.Load(dr);
679
                }
680
                connection.Close();
681
            }
682

    
683
            return dt;
684
        }
685
        public static DataTable SelectStandardSymbolStructureTable()
686
        {
687
            DataTable dt = new DataTable();
688

    
689
            using (SqlConnection connection = new SqlConnection())
690
            {
691
                connection.ConnectionString = GetAvevaConnectionString_Admin();
692
                connection.Open();
693
                using (SqlCommand cmd = connection.CreateCommand())
694
                {
695
                    cmd.CommandText = string.Format(@"
696
                    SELECT * FROM {0}
697
                    ;", "StdPrjFolStructure");
698

    
699
                    using (SqlDataReader dr = cmd.ExecuteReader())
700
                        dt.Load(dr);
701
                }
702
                connection.Close();
703
            }
704

    
705
            return dt;
706
        }
707
        public static DataTable SelectStandardSymbolImageTable()
708
        {
709
            DataTable dt = new DataTable();
710

    
711
            using (SqlConnection connection = new SqlConnection())
712
            {
713
                connection.ConnectionString = GetAvevaConnectionString_Admin();
714
                connection.Open();
715
                using (SqlCommand cmd = connection.CreateCommand())
716
                {
717
                    cmd.CommandText = string.Format(@"
718
                    SELECT ss.Symbol_Name, ss.Pic_Binary, sps.Relative_Path FROM {0} as ss
719
                    LEFT OUTER JOIN {1} as sps
720
                    ON ss.Relative_Path = sps.ID
721
                    ORDER BY sps.ID ASC
722
                    ;", "stdSymbols", "StdPrjFolStructure");
723

    
724
                    using (SqlDataReader dr = cmd.ExecuteReader())
725
                        dt.Load(dr);
726
                }
727
                connection.Close();
728
            }
729

    
730
            return dt;
731
        }
732
        public static DataTable SelectDrawingTable()
733
        {
734
            DataTable dt = new DataTable();
735

    
736
            using (SqlConnection connection = new SqlConnection())
737
            {
738
                connection.ConnectionString = GetAvevaConnectionString_Reports();
739
                connection.Open();
740
                using (SqlCommand cmd = connection.CreateCommand())
741
                {
742
                    cmd.CommandText = string.Format(@"
743
                    SELECT DrawingId, XDNLABEL, XDSLABEL FROM {0}
744
                    ;", "SynchroniseDetails");
745

    
746
                    using (SqlDataReader dr = cmd.ExecuteReader())
747
                        dt.Load(dr);
748
                }
749
                connection.Close();
750
            }
751

    
752
            return dt;
753
        }
754
        public static DataTable SelectSymbolTable()
755
        {
756
            DataTable dt = new DataTable();
757

    
758
            using (SqlConnection connection = new SqlConnection())
759
            {
760
                connection.ConnectionString = GetAvevaConnectionString_Admin();
761
                connection.Open();
762
                using (SqlCommand cmd = connection.CreateCommand())
763
                {
764
                    cmd.CommandText = string.Format(@"
765
                    SELECT * FROM {0}
766
                    ;", "SYMBOLS");
767

    
768
                    using (SqlDataReader dr = cmd.ExecuteReader())
769
                        dt.Load(dr);
770
                }
771
                connection.Close();
772
            }
773

    
774
            return dt;
775
        }
776
        #endregion
777

    
778
    }
779
}
클립보드 이미지 추가 (최대 크기: 500 MB)