프로젝트

일반

사용자정보

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

hytos / DTI_PID / APIDConverter / DB / Project_DB.cs @ a999464f

이력 | 보기 | 이력해설 | 다운로드 (30.3 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)", 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))", 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 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
                            ORDER BY st.TYPE ASC;", Symbol_TABLE, SymbolType_TABLE, APID_SYMBOL_MAPPING_TABLE);
157
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
158
                                dt.Load(dr);
159

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

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

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

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

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

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

    
561
            return true;
562
        }
563
        #endregion
564

    
565
        #region AVEVA
566
        public static string GetAvevaConnectionString()
567
        {
568
            string strConn = string.Empty;
569
            if (Utilities.strSQLWinAuthentication.ToUpper() == "YES")
570
            {
571
                strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Integrated Security=SSPI;Initial Catalog={0};", Utilities.strSQLDatabaseName);
572
            }
573
            else if (Utilities.strSQLWinAuthentication.ToUpper() == "NO")
574
            {
575
                string strAccessString = "User ID=" + Utilities.strSQLUserName + ";Password=" + Utilities.strSQLPassword;
576
                strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Initial Catalog=" + Utilities.strSQLDatabaseName + ";" + strAccessString);
577
            }
578

    
579
            return strConn;
580
        }
581

    
582
        public static string GetAvevaConnectionString_Reports()
583
        {
584
            string strConn = string.Empty;
585
            if (Utilities.strSQLWinAuthentication.ToUpper() == "YES")
586
            {
587
                strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Integrated Security=SSPI;Initial Catalog={0};", Utilities.strSQLReportsDatabaseName);
588
            }
589
            else if (Utilities.strSQLWinAuthentication.ToUpper() == "NO")
590
            {
591
                string strAccessString = "User ID=" + Utilities.strSQLUserName + ";Password=" + Utilities.strSQLPassword;
592
                strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Initial Catalog=" + Utilities.strSQLReportsDatabaseName + ";" + strAccessString);
593
            }
594

    
595
            return strConn;
596
        }
597

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

    
611
            return strConn;
612
        }
613

    
614
        public static string GetDirectiveValue(string name)
615
        {
616
            string result = null;
617

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

    
634
            return result;
635
        }
636

    
637
        public static DataTable GetDrawingTemplate()
638
        {
639
            DataTable dt = new DataTable();
640

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

    
654
            return dt;
655
        }
656

    
657
        public static DataTable SelectStandardSymbolTable()
658
        {
659
            DataTable dt = new DataTable();
660

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

    
674
                    using (SqlDataReader dr = cmd.ExecuteReader())
675
                        dt.Load(dr);
676
                }
677
                connection.Close();
678
            }
679

    
680
            return dt;
681
        }
682
        public static DataTable SelectStandardSymbolStructureTable()
683
        {
684
            DataTable dt = new DataTable();
685

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

    
696
                    using (SqlDataReader dr = cmd.ExecuteReader())
697
                        dt.Load(dr);
698
                }
699
                connection.Close();
700
            }
701

    
702
            return dt;
703
        }
704
        public static DataTable SelectStandardSymbolImageTable()
705
        {
706
            DataTable dt = new DataTable();
707

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

    
721
                    using (SqlDataReader dr = cmd.ExecuteReader())
722
                        dt.Load(dr);
723
                }
724
                connection.Close();
725
            }
726

    
727
            return dt;
728
        }
729

    
730
        #endregion
731

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