hytos / DTI_PID / APIDConverter / DB / Project_DB.cs @ 5598104a
이력 | 보기 | 이력해설 | 다운로드 (4.35 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 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 |
//Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
53 |
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 |
//Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
85 |
} |
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 |
//Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
110 |
} |
111 |
finally |
112 |
{ |
113 |
if (connection != null) |
114 |
connection.Dispose(); |
115 |
} |
116 |
} |
117 |
} |
118 |
|
119 |
return result; |
120 |
} |
121 |
|
122 |
} |
123 |
} |