프로젝트

일반

사용자정보

통계
| 개정판:

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

이력 | 보기 | 이력해설 | 다운로드 (30.8 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
                            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, sp.DATA1 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, sp.DATA1 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, sp.DATA1 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, 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, DATA1) VALUES (@UID, @NAME, @APID_SYMBOL, @DATA1)", 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.Parameters.AddWithValue("@DATA1", item.Item4);
487
                                        cmd.ExecuteNonQuery();
488
                                    }
489
                                }
490
                                transaction.Commit();
491
                                connection.Close();
492
                            }
493
                            catch (Exception ex)
494
                            {
495
                                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
496
                                transaction.Rollback();
497
                                return false;
498
                            }
499
                            finally
500
                            {
501
                                transaction.Dispose();
502
                            }
503
                        }
504
                    }
505
                    catch (Exception ex)
506
                    {
507
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
508
                        return false;
509
                    }
510
                    finally
511
                    {
512
                        connection.Dispose();
513
                    }
514
                }
515
            }
516
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
517
            {
518
                using (SqlConnection connection = GetSqlConnection())
519
                {
520
                    try
521
                    {
522
                        if (connection != null && connection.State == ConnectionState.Open)
523
                        {
524
                            using (SqlCommand cmd = connection.CreateCommand())
525
                            {
526
                                foreach (var item in datas)
527
                                {
528
                                    cmd.Parameters.Clear();
529
                                    cmd.CommandText = string.Format(@"
530
                                    IF EXISTS (SELECT * FROM {0} WHERE UID = '{1}')
531
                                        UPDATE {0} SET NAME = @NAME, APID_SYMBOL = @APID_SYMBOL, DATA1 = @DATA1 WHERE UID = @UID
532
                                    ELSE
533
                                        INSERT INTO {0} (UID, NAME, APID_SYMBOL, DATA1) VALUES (@UID, @NAME, @APID_SYMBOL, @DATA1)", APID_SYMBOL_MAPPING_TABLE, item.Item1);
534
                                    cmd.Parameters.AddWithValue("@UID", item.Item1);
535
                                    if (string.IsNullOrEmpty(item.Item2))
536
                                        cmd.Parameters.AddWithValue("@NAME", DBNull.Value);
537
                                    else
538
                                        cmd.Parameters.AddWithValue("@NAME", item.Item2);
539
                                    if (string.IsNullOrEmpty(item.Item3))
540
                                        cmd.Parameters.AddWithValue("@APID_SYMBOL", DBNull.Value);
541
                                    else
542
                                        cmd.Parameters.AddWithValue("@APID_SYMBOL", item.Item3);
543
                                    if (string.IsNullOrEmpty(item.Item4))
544
                                        cmd.Parameters.AddWithValue("@DATA1", DBNull.Value);
545
                                    else
546
                                        cmd.Parameters.AddWithValue("@DATA1", item.Item4);
547

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

    
567
            return true;
568
        }
569
        #endregion
570

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

    
585
            return strConn;
586
        }
587

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

    
601
            return strConn;
602
        }
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

    
620
        public static string GetDirectiveValue(string name)
621
        {
622
            string result = null;
623

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

    
640
            return result;
641
        }
642

    
643
        public static DataTable GetDrawingTemplate()
644
        {
645
            DataTable dt = new DataTable();
646

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

    
660
            return dt;
661
        }
662

    
663
        public static DataTable SelectStandardSymbolTable()
664
        {
665
            DataTable dt = new DataTable();
666

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

    
680
                    using (SqlDataReader dr = cmd.ExecuteReader())
681
                        dt.Load(dr);
682
                }
683
                connection.Close();
684
            }
685

    
686
            return dt;
687
        }
688
        public static DataTable SelectStandardSymbolStructureTable()
689
        {
690
            DataTable dt = new DataTable();
691

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

    
702
                    using (SqlDataReader dr = cmd.ExecuteReader())
703
                        dt.Load(dr);
704
                }
705
                connection.Close();
706
            }
707

    
708
            return dt;
709
        }
710
        public static DataTable SelectStandardSymbolImageTable()
711
        {
712
            DataTable dt = new DataTable();
713

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

    
727
                    using (SqlDataReader dr = cmd.ExecuteReader())
728
                        dt.Load(dr);
729
                }
730
                connection.Close();
731
            }
732

    
733
            return dt;
734
        }
735

    
736
        #endregion
737

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