프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / APIDConverter / DB / Project_DB.cs @ 465c8b6e

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

1 53a4ebb8 gaqhf
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 SPPID_DB_INFO_TABLE = "T_SPPID_CONNECTION_INFO";
20
        const string SPPID_SYMBOL_MAPPING_TABLE = "T_SPPID_SYMBOL_MAPPING";
21
        const string SPPID_ATTRIBUTE_MAPPING_TABLE = "T_SPPID_ATTRIBUTE_MAPPING";
22
        const string SPPID_SETTING_TABLE = "T_SPPID_SETTING_TABLE";
23
        const string SPPID_LABEL_INFO_TABLE = "T_SPPID_LABEL_INFO";
24
        const string SPPID_DRAWING_INFO = "T_SPPID_DRAWING_INFO";
25
        const string SPPID_OPC_INFO = "T_SPPID_OPC_INFO";
26
27
        const string LineProperties_TABLE = "LineProperties";
28
        const string LineTypes_TABLE = "LineTypes";
29
        const string SymbolType_TABLE = "SymbolType";
30
        const string SymbolAttribute_TABLE = "SymbolAttribute";
31
        const string Symbol_TABLE = "Symbol";
32
        const string OPCRelations_TABLE = "OPCRelations";
33
34
        private static SqlConnection GetSqlConnection()
35
        {
36
            Project_Info projectInfo = Project_Info.GetInstance();
37
            SqlConnection connection = null;
38
            try
39
            {
40
                connection = new SqlConnection(string.Format(CultureInfo.CurrentCulture,
41
                    @"Data Source = {0},{1}; Initial CataLog = {2}; User ID = {3}; Password = {4};",
42
                    projectInfo.ServerIP,
43
                    projectInfo.Port,
44
                    System.IO.Path.GetFileName(projectInfo.DefaultPath),
45
                    projectInfo.DBUser,
46
                    projectInfo.DBPassword));
47
48
                connection.Open();
49
            }
50
            catch (Exception ex)
51
            {
52 465c8b6e gaqhf
                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
53 53a4ebb8 gaqhf
                if (connection != null)
54
                    connection.Dispose();
55
                connection = null;
56
            }
57
58
            return connection;
59
        }
60
61
        public static bool ConnTestAndCreateTable()
62
        {
63
            bool result = false;
64
            Project_Info projectInfo = Project_Info.GetInstance();
65
            if (projectInfo.DBType == ID2DB_Type.SQLite)
66
            {
67
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, @"Data Source = {0}", projectInfo.DBFilePath)))
68
                {
69
                    try
70
                    {
71
                        connection.Open();
72
                        if (connection.State == ConnectionState.Open)
73
                        {
74
                            using (SQLiteCommand cmd = connection.CreateCommand())
75
                            {
76
                                
77
                            }
78
                            result = true;
79
                        }
80
                        connection.Close();
81
                    }
82
                    catch (Exception ex)
83
                    {
84 465c8b6e gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
85 53a4ebb8 gaqhf
                    }
86
                    finally
87
                    {
88
                        connection.Dispose();
89
                    }
90
                }
91
            }
92
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
93
            {
94
                using (SqlConnection connection = GetSqlConnection())
95
                {
96
                    try
97
                    {
98
                        if (connection != null && connection.State == ConnectionState.Open)
99
                        {
100
                            using (SqlCommand cmd = connection.CreateCommand())
101
                            {
102
                                
103
                            }
104
                            result = true;
105
                        }
106
                    }
107
                    catch (Exception ex)
108
                    {
109 465c8b6e gaqhf
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
110 53a4ebb8 gaqhf
                    }
111
                    finally
112
                    {
113
                        if (connection != null)
114
                            connection.Dispose();
115
                    }
116
                }
117
            }
118
119
            return result;
120
        }
121 465c8b6e gaqhf
122
        public static DataTable SelectID2SymbolTable()
123
        {
124
            DataTable dt = new DataTable();
125
            Project_Info projectInfo = Project_Info.GetInstance();
126
            if (projectInfo.DBType == ID2DB_Type.SQLite)
127
            {
128
                using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
129
                {
130
                    try
131
                    {
132
                        connection.Open();
133
                        using (SQLiteCommand cmd = connection.CreateCommand())
134
                        {
135
                            cmd.CommandText = @"SELECT * FROM Symbol";
136
                            using (SQLiteDataReader dr = cmd.ExecuteReader())
137
                                dt.Load(dr);
138
                        }
139
                        connection.Close();
140
                    }
141
                    catch (Exception ex)
142
                    {
143
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
144
                    }
145
                    finally
146
                    {
147
                        connection.Dispose();
148
                    }
149
                }
150
            }
151
            else if (projectInfo.DBType == ID2DB_Type.MSSQL)
152
            {
153
                using (SqlConnection connection = GetSqlConnection())
154
                {
155
                    try
156
                    {
157
                        if (connection != null && connection.State == ConnectionState.Open)
158
                        {
159
                            using (SqlCommand cmd = connection.CreateCommand())
160
                            {
161
                                cmd.CommandText = @"SELECT * FROM Symbol";
162
                                using (SqlDataReader dr = cmd.ExecuteReader())
163
                                    dt.Load(dr);
164
                            }
165
                            connection.Close();
166
                        }
167
                    }
168
                    catch (Exception ex)
169
                    {
170
                        Log.Write(ex.Message + "\r\n" + ex.StackTrace);
171
                    }
172
                    finally
173
                    {
174
                        if (connection != null)
175
                            connection.Dispose();
176
                    }
177
                }
178
            }
179
180
            return dt;
181
        }
182
183 53a4ebb8 gaqhf
    }
184
}
클립보드 이미지 추가 (최대 크기: 500 MB)