hytos / DTI_PID / SPPIDConverter / DB / Project_DB.cs @ 923501a9
이력 | 보기 | 이력해설 | 다운로드 (111 KB)
1 | b18dc619 | gaqhf | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.Linq; |
||
4 | using System.Text; |
||
5 | using System.Threading.Tasks; |
||
6 | fab4f207 | gaqhf | using System.Globalization; |
7 | using System.Data.SQLite; |
||
8 | using System.Data; |
||
9 | 8847ea67 | gaqhf | using System.Data.SqlClient; |
10 | 2425d530 | gaqhf | using Converter.SPPID; |
11 | using System.IO; |
||
12 | 224535bb | gaqhf | using Newtonsoft.Json; |
13 | b18dc619 | gaqhf | |
14 | 171142c5 | gaqhf | namespace Converter.BaseModel |
15 | b18dc619 | gaqhf | { |
16 | 171142c5 | gaqhf | public class Project_DB |
17 | b18dc619 | gaqhf | { |
18 | bca86986 | gaqhf | const string SPPID_DB_INFO_TABLE = "T_SPPID_CONNECTION_INFO"; |
19 | const string SPPID_SYMBOL_MAPPING_TABLE = "T_SPPID_SYMBOL_MAPPING"; |
||
20 | const string SPPID_ATTRIBUTE_MAPPING_TABLE = "T_SPPID_ATTRIBUTE_MAPPING"; |
||
21 | 7cbb1038 | gaqhf | const string SPPID_SETTING_TABLE = "T_SPPID_SETTING_TABLE"; |
22 | b8bd98aa | gaqhf | const string SPPID_LABEL_INFO_TABLE = "T_SPPID_LABEL_INFO"; |
23 | e8536f2b | gaqhf | const string SPPID_DRAWING_INFO = "T_SPPID_DRAWING_INFO"; |
24 | 154d8f43 | gaqhf | const string SPPID_OPC_INFO = "T_SPPID_OPC_INFO"; |
25 | 306a0af9 | gaqhf | const string ID2_DRAWINGATTRIBUTE_TABLE = "T_ID2_DRAWINGATTRIBUTE"; |
26 | 171142c5 | gaqhf | |
27 | bca86986 | gaqhf | 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 | 154d8f43 | gaqhf | const string OPCRelations_TABLE = "OPCRelations"; |
33 | 306a0af9 | gaqhf | const string DrawingAttribute_Table = "TitleBlockProperties"; |
34 | 171142c5 | gaqhf | |
35 | 8847ea67 | gaqhf | private static SqlConnection GetSqlConnection() |
36 | fab4f207 | gaqhf | { |
37 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
38 | 8847ea67 | gaqhf | SqlConnection connection = null; |
39 | fab4f207 | gaqhf | try |
40 | { |
||
41 | 8847ea67 | gaqhf | connection = new SqlConnection(string.Format(CultureInfo.CurrentCulture, |
42 | @"Data Source = {0},{1}; Initial Catalog = {2}; User ID = {3}; Password = {4};", |
||
43 | projectInfo.ServerIP, |
||
44 | projectInfo.Port, |
||
45 | System.IO.Path.GetFileName(projectInfo.DefaultPath), |
||
46 | projectInfo.DBUser, |
||
47 | projectInfo.DBPassword)); |
||
48 | |||
49 | fab4f207 | gaqhf | connection.Open(); |
50 | } |
||
51 | catch (Exception ex) |
||
52 | { |
||
53 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
54 | da84b14b | gaqhf | if (connection != null) |
55 | connection.Dispose(); |
||
56 | 8847ea67 | gaqhf | connection = null; |
57 | fab4f207 | gaqhf | } |
58 | |||
59 | 8847ea67 | gaqhf | return connection; |
60 | fab4f207 | gaqhf | } |
61 | |||
62 | 8847ea67 | gaqhf | public static bool ConnTestAndCreateTable() |
63 | fab4f207 | gaqhf | { |
64 | 8847ea67 | gaqhf | bool result = false; |
65 | fab4f207 | gaqhf | Project_Info projectInfo = Project_Info.GetInstance(); |
66 | 8847ea67 | gaqhf | if (projectInfo.DBType == ID2DB_Type.SQLite) |
67 | fab4f207 | gaqhf | { |
68 | 8847ea67 | gaqhf | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, @"Data Source = {0}", projectInfo.DBFilePath))) |
69 | fab4f207 | gaqhf | { |
70 | 8847ea67 | gaqhf | try |
71 | fab4f207 | gaqhf | { |
72 | 8847ea67 | gaqhf | connection.Open(); |
73 | if (connection.State == ConnectionState.Open) |
||
74 | { |
||
75 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
76 | { |
||
77 | cmd.CommandText = "SELECT NAME FROM sqlite_master WHERE type='table'"; |
||
78 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
79 | using (DataTable dt = new DataTable()) |
||
80 | { |
||
81 | dt.Load(dr); |
||
82 | |||
83 | if (dt.Select(string.Format("NAME = '{0}'", SPPID_DB_INFO_TABLE)).Length == 0) |
||
84 | { |
||
85 | cmd.CommandText = string.Format("CREATE TABLE {0} (JsonString TEXT)", SPPID_DB_INFO_TABLE); |
||
86 | cmd.ExecuteNonQuery(); |
||
87 | } |
||
88 | if (dt.Select(string.Format("NAME = '{0}'", SPPID_SETTING_TABLE)).Length == 0) |
||
89 | { |
||
90 | cmd.CommandText = string.Format("CREATE TABLE {0} (JsonString TEXT, SettingType TEXT)", SPPID_SETTING_TABLE); |
||
91 | cmd.ExecuteNonQuery(); |
||
92 | } |
||
93 | if (dt.Select(string.Format("NAME = '{0}'", SPPID_SYMBOL_MAPPING_TABLE)).Length == 0) |
||
94 | { |
||
95 | cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, NAME TEXT, SPPID_SYMBOL_PATH TEXT, LEADERLINE BOOLEAN)", SPPID_SYMBOL_MAPPING_TABLE); |
||
96 | cmd.ExecuteNonQuery(); |
||
97 | } |
||
98 | if (dt.Select(string.Format("NAME = '{0}'", SPPID_ATTRIBUTE_MAPPING_TABLE)).Length == 0) |
||
99 | { |
||
100 | cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, SPPID_ATTRIBUTE TEXT)", SPPID_ATTRIBUTE_MAPPING_TABLE); |
||
101 | cmd.ExecuteNonQuery(); |
||
102 | } |
||
103 | if (dt.Select(string.Format("NAME = '{0}'", SPPID_LABEL_INFO_TABLE)).Length == 0) |
||
104 | { |
||
105 | cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, LOCATION INT DEFAULT 0, LEADERLINE BOOLEAN)", SPPID_LABEL_INFO_TABLE); |
||
106 | cmd.ExecuteNonQuery(); |
||
107 | } |
||
108 | if (dt.Select(string.Format("NAME = '{0}'", SPPID_DRAWING_INFO)).Length == 0) |
||
109 | { |
||
110 | cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_DRAWING_UID Text PRIMARY KEY, PATH TEXT, DRAWINGNUMBER TEXT, DRAWINGNAME TEXT)", SPPID_DRAWING_INFO); |
||
111 | cmd.ExecuteNonQuery(); |
||
112 | } |
||
113 | if (dt.Select(string.Format("NAME = '{0}'", SPPID_OPC_INFO)).Length == 0) |
||
114 | { |
||
115 | cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_OPC_UID TEXT PRIMARY KEY, SPPID_OPC_MODELITEM_ID TEXT, ID2_DRAWING_UID TEXT, ATTRIBUTES TEXT, PAIRED BOOL)", SPPID_OPC_INFO); |
||
116 | cmd.ExecuteNonQuery(); |
||
117 | } |
||
118 | 306a0af9 | gaqhf | if (dt.Select(string.Format("NAME = '{0}'", ID2_DRAWINGATTRIBUTE_TABLE)).Length == 0) |
119 | { |
||
120 | cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, NAME TEXT)", ID2_DRAWINGATTRIBUTE_TABLE); |
||
121 | cmd.ExecuteNonQuery(); |
||
122 | |||
123 | List<string> datas = new List<string>() { "Unit", "Rev No", "Drawing No" }; |
||
124 | foreach (var data in datas) |
||
125 | { |
||
126 | cmd.CommandText = string.Format("INSERT INTO {0} VALUES('{1}', '{1}')", ID2_DRAWINGATTRIBUTE_TABLE, data); |
||
127 | cmd.ExecuteNonQuery(); |
||
128 | } |
||
129 | } |
||
130 | 8847ea67 | gaqhf | } |
131 | |||
132 | #region Check Column 업데이트시 예비용 |
||
133 | 93c417a9 | gaqhf | cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_ATTRIBUTE_MAPPING_TABLE); |
134 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
135 | using (DataTable dt = new DataTable()) |
||
136 | { |
||
137 | dt.Load(dr); |
||
138 | if (!dt.Columns.Contains("ISTEXT")) |
||
139 | { |
||
140 | cmd.CommandText = string.Format("ALTER TABLE {0} ADD COLUMN ISTEXT BOOLEAN", SPPID_ATTRIBUTE_MAPPING_TABLE); |
||
141 | cmd.ExecuteNonQuery(); |
||
142 | } |
||
143 | } |
||
144 | |||
145 | 8847ea67 | gaqhf | cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_SYMBOL_MAPPING_TABLE); |
146 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
147 | using (DataTable dt = new DataTable()) |
||
148 | { |
||
149 | dt.Load(dr); |
||
150 | if (!dt.Columns.Contains("LEADERLINE")) |
||
151 | { |
||
152 | cmd.CommandText = string.Format("ALTER TABLE {0} ADD COLUMN LEADERLINE BOOLEAN", SPPID_SYMBOL_MAPPING_TABLE); |
||
153 | cmd.ExecuteNonQuery(); |
||
154 | } |
||
155 | } |
||
156 | |||
157 | cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_SETTING_TABLE); |
||
158 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
159 | using (DataTable dt = new DataTable()) |
||
160 | { |
||
161 | dt.Load(dr); |
||
162 | if (!dt.Columns.Contains("SettingType")) |
||
163 | { |
||
164 | cmd.CommandText = string.Format("ALTER TABLE {0} ADD COLUMN SettingType Text", SPPID_SETTING_TABLE); |
||
165 | cmd.ExecuteNonQuery(); |
||
166 | } |
||
167 | } |
||
168 | fab4f207 | gaqhf | |
169 | 8847ea67 | gaqhf | cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_DRAWING_INFO); |
170 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
171 | using (DataTable dt = new DataTable()) |
||
172 | { |
||
173 | dt.Load(dr); |
||
174 | if (dt.Columns.Contains("DOCUMENT")) |
||
175 | { |
||
176 | cmd.CommandText = string.Format("DROP TABLE {0}", SPPID_DRAWING_INFO); |
||
177 | cmd.ExecuteNonQuery(); |
||
178 | |||
179 | cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_DRAWING_UID Text PRIMARY KEY, PATH TEXT, DRAWINGNUMBER TEXT, DRAWINGNAME TEXT)", SPPID_DRAWING_INFO); |
||
180 | cmd.ExecuteNonQuery(); |
||
181 | } |
||
182 | } |
||
183 | #endregion |
||
184 | } |
||
185 | result = true; |
||
186 | } |
||
187 | connection.Close(); |
||
188 | } |
||
189 | catch (Exception ex) |
||
190 | { |
||
191 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
192 | 8847ea67 | gaqhf | } |
193 | finally |
||
194 | { |
||
195 | connection.Dispose(); |
||
196 | fab4f207 | gaqhf | } |
197 | } |
||
198 | } |
||
199 | 8847ea67 | gaqhf | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
200 | fab4f207 | gaqhf | { |
201 | 8847ea67 | gaqhf | using (SqlConnection connection = GetSqlConnection()) |
202 | fab4f207 | gaqhf | { |
203 | 8847ea67 | gaqhf | try |
204 | fab4f207 | gaqhf | { |
205 | 8847ea67 | gaqhf | if (connection != null && connection.State == ConnectionState.Open) |
206 | { |
||
207 | using (SqlCommand cmd = connection.CreateCommand()) |
||
208 | { |
||
209 | cmd.CommandText = "SELECT TABLE_NAME AS NAME FROM INFORMATION_SCHEMA.TABLES"; |
||
210 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
211 | using (DataTable dt = new DataTable()) |
||
212 | { |
||
213 | dt.Load(dr); |
||
214 | |||
215 | if (dt.Select(string.Format("NAME = '{0}'", SPPID_DB_INFO_TABLE)).Length == 0) |
||
216 | { |
||
217 | d2a7bef1 | gaqhf | cmd.CommandText = string.Format("CREATE TABLE {0} (JsonString varchar(MAX))", SPPID_DB_INFO_TABLE); |
218 | 8847ea67 | gaqhf | cmd.ExecuteNonQuery(); |
219 | } |
||
220 | if (dt.Select(string.Format("NAME = '{0}'", SPPID_SETTING_TABLE)).Length == 0) |
||
221 | { |
||
222 | d2a7bef1 | gaqhf | cmd.CommandText = string.Format("CREATE TABLE {0} (JsonString varchar(MAX), SettingType varchar(MAX))", SPPID_SETTING_TABLE); |
223 | 8847ea67 | gaqhf | cmd.ExecuteNonQuery(); |
224 | } |
||
225 | if (dt.Select(string.Format("NAME = '{0}'", SPPID_SYMBOL_MAPPING_TABLE)).Length == 0) |
||
226 | { |
||
227 | d2a7bef1 | gaqhf | cmd.CommandText = string.Format("CREATE TABLE {0} (UID varchar(255) PRIMARY KEY, NAME varchar(MAX), SPPID_SYMBOL_PATH varchar(MAX), LEADERLINE BIT)", SPPID_SYMBOL_MAPPING_TABLE); |
228 | 8847ea67 | gaqhf | cmd.ExecuteNonQuery(); |
229 | } |
||
230 | if (dt.Select(string.Format("NAME = '{0}'", SPPID_ATTRIBUTE_MAPPING_TABLE)).Length == 0) |
||
231 | { |
||
232 | d2a7bef1 | gaqhf | cmd.CommandText = string.Format("CREATE TABLE {0} (UID varchar(255) PRIMARY KEY, SPPID_ATTRIBUTE varchar(MAX))", SPPID_ATTRIBUTE_MAPPING_TABLE); |
233 | 8847ea67 | gaqhf | cmd.ExecuteNonQuery(); |
234 | } |
||
235 | if (dt.Select(string.Format("NAME = '{0}'", SPPID_LABEL_INFO_TABLE)).Length == 0) |
||
236 | { |
||
237 | cmd.CommandText = string.Format("CREATE TABLE {0} (UID varchar(255) PRIMARY KEY, LOCATION INT DEFAULT 0, LEADERLINE BIT)", SPPID_LABEL_INFO_TABLE); |
||
238 | cmd.ExecuteNonQuery(); |
||
239 | } |
||
240 | if (dt.Select(string.Format("NAME = '{0}'", SPPID_DRAWING_INFO)).Length == 0) |
||
241 | { |
||
242 | d2a7bef1 | gaqhf | cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_DRAWING_UID varchar(255) PRIMARY KEY, PATH varchar(MAX), DRAWINGNUMBER varchar(MAX), DRAWINGNAME varchar(MAX))", SPPID_DRAWING_INFO); |
243 | 8847ea67 | gaqhf | cmd.ExecuteNonQuery(); |
244 | } |
||
245 | if (dt.Select(string.Format("NAME = '{0}'", SPPID_OPC_INFO)).Length == 0) |
||
246 | { |
||
247 | d2a7bef1 | gaqhf | cmd.CommandText = string.Format("CREATE TABLE {0} (ID2_OPC_UID varchar(255) PRIMARY KEY, SPPID_OPC_MODELITEM_ID varchar(MAX), ID2_DRAWING_UID varchar(MAX), ATTRIBUTES varchar(MAX), PAIRED BIT)", SPPID_OPC_INFO); |
248 | 8847ea67 | gaqhf | cmd.ExecuteNonQuery(); |
249 | } |
||
250 | 306a0af9 | gaqhf | if (dt.Select(string.Format("NAME = '{0}'", ID2_DRAWINGATTRIBUTE_TABLE)).Length == 0) |
251 | { |
||
252 | cmd.CommandText = string.Format("CREATE TABLE {0} (UID varchar(255) PRIMARY KEY, NAME varchar(255))", ID2_DRAWINGATTRIBUTE_TABLE); |
||
253 | cmd.ExecuteNonQuery(); |
||
254 | |||
255 | List<string> datas = new List<string>() { "Unit", "Rev No", "Drawing No" }; |
||
256 | foreach (var data in datas) |
||
257 | { |
||
258 | cmd.CommandText = string.Format("INSERT INTO {0} VALUES('{1}', '{1}')", ID2_DRAWINGATTRIBUTE_TABLE, data); |
||
259 | cmd.ExecuteNonQuery(); |
||
260 | } |
||
261 | } |
||
262 | 8847ea67 | gaqhf | } |
263 | |||
264 | #region Check Column 업데이트시 예비용 |
||
265 | 923501a9 | gaqhf | cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_ATTRIBUTE_MAPPING_TABLE); |
266 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
267 | using (DataTable dt = new DataTable()) |
||
268 | { |
||
269 | dt.Load(dr); |
||
270 | if (!dt.Columns.Contains("ISTEXT")) |
||
271 | { |
||
272 | cmd.CommandText = string.Format("ALTER TABLE {0} ADD ISTEXT BIT", SPPID_ATTRIBUTE_MAPPING_TABLE); |
||
273 | cmd.ExecuteNonQuery(); |
||
274 | } |
||
275 | } |
||
276 | 8847ea67 | gaqhf | #endregion |
277 | } |
||
278 | result = true; |
||
279 | } |
||
280 | fab4f207 | gaqhf | } |
281 | 8847ea67 | gaqhf | catch (Exception ex) |
282 | { |
||
283 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
284 | 8847ea67 | gaqhf | } |
285 | finally |
||
286 | { |
||
287 | if (connection != null) |
||
288 | connection.Dispose(); |
||
289 | } |
||
290 | fab4f207 | gaqhf | } |
291 | } |
||
292 | |||
293 | 8847ea67 | gaqhf | return result; |
294 | fab4f207 | gaqhf | } |
295 | |||
296 | 8847ea67 | gaqhf | public static bool SaveSPPID_DB_INFO(string jsonString) |
297 | e00e891d | gaqhf | { |
298 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
299 | 8847ea67 | gaqhf | if (projectInfo.DBType == ID2DB_Type.SQLite) |
300 | e00e891d | gaqhf | { |
301 | 8847ea67 | gaqhf | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
302 | e00e891d | gaqhf | { |
303 | |||
304 | 8847ea67 | gaqhf | try |
305 | { |
||
306 | connection.Open(); |
||
307 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
308 | 7cbb1038 | gaqhf | { |
309 | 8847ea67 | gaqhf | cmd.CommandText = string.Format("DELETE FROM {0}", SPPID_DB_INFO_TABLE); |
310 | cmd.ExecuteNonQuery(); |
||
311 | |||
312 | cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@jsonString)", SPPID_DB_INFO_TABLE); |
||
313 | cmd.Parameters.AddWithValue("@jsonString", jsonString); |
||
314 | 7cbb1038 | gaqhf | cmd.ExecuteNonQuery(); |
315 | } |
||
316 | 8847ea67 | gaqhf | connection.Close(); |
317 | } |
||
318 | catch (Exception ex) |
||
319 | { |
||
320 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
321 | 8847ea67 | gaqhf | return false; |
322 | } |
||
323 | finally |
||
324 | { |
||
325 | connection.Dispose(); |
||
326 | e00e891d | gaqhf | } |
327 | } |
||
328 | 8847ea67 | gaqhf | } |
329 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
330 | { |
||
331 | using (SqlConnection connection = GetSqlConnection()) |
||
332 | e00e891d | gaqhf | { |
333 | 8847ea67 | gaqhf | try |
334 | { |
||
335 | if (connection != null && connection.State == ConnectionState.Open) |
||
336 | { |
||
337 | d2a7bef1 | gaqhf | using (SqlCommand cmd = connection.CreateCommand()) |
338 | { |
||
339 | cmd.CommandText = string.Format("DELETE FROM {0}", SPPID_DB_INFO_TABLE); |
||
340 | cmd.ExecuteNonQuery(); |
||
341 | 8847ea67 | gaqhf | |
342 | d2a7bef1 | gaqhf | cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@jsonString)", SPPID_DB_INFO_TABLE); |
343 | cmd.Parameters.AddWithValue("@jsonString", jsonString); |
||
344 | cmd.ExecuteNonQuery(); |
||
345 | } |
||
346 | connection.Close(); |
||
347 | } |
||
348 | else |
||
349 | { |
||
350 | return false; |
||
351 | 8847ea67 | gaqhf | } |
352 | } |
||
353 | catch (Exception ex) |
||
354 | { |
||
355 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
356 | d2a7bef1 | gaqhf | return false; |
357 | 8847ea67 | gaqhf | } |
358 | finally |
||
359 | { |
||
360 | if (connection != null) |
||
361 | connection.Dispose(); |
||
362 | } |
||
363 | e00e891d | gaqhf | } |
364 | } |
||
365 | |||
366 | 8847ea67 | gaqhf | |
367 | e00e891d | gaqhf | return true; |
368 | } |
||
369 | |||
370 | 8847ea67 | gaqhf | public static DataTable SelectSPPID_DB_INFO() |
371 | e00e891d | gaqhf | { |
372 | DataTable dt = new DataTable(); |
||
373 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
374 | 8847ea67 | gaqhf | if (projectInfo.DBType == ID2DB_Type.SQLite) |
375 | e00e891d | gaqhf | { |
376 | 8847ea67 | gaqhf | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
377 | e00e891d | gaqhf | { |
378 | 8847ea67 | gaqhf | try |
379 | e00e891d | gaqhf | { |
380 | 8847ea67 | gaqhf | connection.Open(); |
381 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
382 | { |
||
383 | cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_DB_INFO_TABLE); |
||
384 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
385 | dt.Load(dr); |
||
386 | } |
||
387 | connection.Close(); |
||
388 | e00e891d | gaqhf | } |
389 | 8847ea67 | gaqhf | catch (Exception ex) |
390 | { |
||
391 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
392 | 8847ea67 | gaqhf | } |
393 | finally |
||
394 | { |
||
395 | connection.Dispose(); |
||
396 | } |
||
397 | e00e891d | gaqhf | } |
398 | 8847ea67 | gaqhf | } |
399 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
400 | { |
||
401 | using (SqlConnection connection = GetSqlConnection()) |
||
402 | e00e891d | gaqhf | { |
403 | 8847ea67 | gaqhf | try |
404 | { |
||
405 | if (connection != null && connection.State == ConnectionState.Open) |
||
406 | { |
||
407 | d2a7bef1 | gaqhf | using (SqlCommand cmd = connection.CreateCommand()) |
408 | { |
||
409 | cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_DB_INFO_TABLE); |
||
410 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
411 | dt.Load(dr); |
||
412 | } |
||
413 | connection.Close(); |
||
414 | 8847ea67 | gaqhf | } |
415 | } |
||
416 | catch (Exception ex) |
||
417 | { |
||
418 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
419 | 8847ea67 | gaqhf | } |
420 | finally |
||
421 | { |
||
422 | if (connection != null) |
||
423 | connection.Dispose(); |
||
424 | } |
||
425 | e00e891d | gaqhf | } |
426 | } |
||
427 | |||
428 | return dt; |
||
429 | } |
||
430 | |||
431 | 8847ea67 | gaqhf | public static bool SaveETCSetting(Dictionary<string,string> dicSetting) |
432 | fab4f207 | gaqhf | { |
433 | 8847ea67 | gaqhf | Project_Info projectInfo = Project_Info.GetInstance(); |
434 | if (projectInfo.DBType == ID2DB_Type.SQLite) |
||
435 | fab4f207 | gaqhf | { |
436 | 8847ea67 | gaqhf | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
437 | fab4f207 | gaqhf | { |
438 | |||
439 | 8847ea67 | gaqhf | try |
440 | e00e891d | gaqhf | { |
441 | 8847ea67 | gaqhf | connection.Open(); |
442 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
443 | { |
||
444 | cmd.CommandText = string.Format("DELETE FROM {0}", SPPID_SETTING_TABLE); |
||
445 | cmd.ExecuteNonQuery(); |
||
446 | |||
447 | foreach (var item in dicSetting) |
||
448 | { |
||
449 | cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@jsonString, @SettingType)", SPPID_SETTING_TABLE); |
||
450 | f4485671 | gaqhf | cmd.Parameters.Clear(); |
451 | 8847ea67 | gaqhf | cmd.Parameters.AddWithValue("@jsonString", item.Value); |
452 | cmd.Parameters.AddWithValue("@SettingType", item.Key); |
||
453 | cmd.ExecuteNonQuery(); |
||
454 | } |
||
455 | } |
||
456 | connection.Close(); |
||
457 | e00e891d | gaqhf | } |
458 | 8847ea67 | gaqhf | catch (Exception ex) |
459 | bca86986 | gaqhf | { |
460 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
461 | 8847ea67 | gaqhf | return false; |
462 | bca86986 | gaqhf | } |
463 | 8847ea67 | gaqhf | finally |
464 | bca86986 | gaqhf | { |
465 | 8847ea67 | gaqhf | connection.Dispose(); |
466 | bca86986 | gaqhf | } |
467 | 8847ea67 | gaqhf | } |
468 | } |
||
469 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
470 | { |
||
471 | using (SqlConnection connection = GetSqlConnection()) |
||
472 | { |
||
473 | try |
||
474 | 1a3a74a8 | gaqhf | { |
475 | 8847ea67 | gaqhf | if (connection != null && connection.State == ConnectionState.Open) |
476 | { |
||
477 | d2a7bef1 | gaqhf | using (SqlCommand cmd = connection.CreateCommand()) |
478 | { |
||
479 | cmd.CommandText = string.Format("DELETE FROM {0}", SPPID_SETTING_TABLE); |
||
480 | cmd.ExecuteNonQuery(); |
||
481 | 8847ea67 | gaqhf | |
482 | d2a7bef1 | gaqhf | foreach (var item in dicSetting) |
483 | { |
||
484 | cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@jsonString, @SettingType)", SPPID_SETTING_TABLE); |
||
485 | f4485671 | gaqhf | cmd.Parameters.Clear(); |
486 | d2a7bef1 | gaqhf | cmd.Parameters.AddWithValue("@jsonString", item.Value); |
487 | cmd.Parameters.AddWithValue("@SettingType", item.Key); |
||
488 | cmd.ExecuteNonQuery(); |
||
489 | } |
||
490 | } |
||
491 | connection.Close(); |
||
492 | 8847ea67 | gaqhf | } |
493 | d2a7bef1 | gaqhf | else |
494 | return false; |
||
495 | 1a3a74a8 | gaqhf | } |
496 | 8847ea67 | gaqhf | catch (Exception ex) |
497 | e8536f2b | gaqhf | { |
498 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
499 | d2a7bef1 | gaqhf | return false; |
500 | 154d8f43 | gaqhf | } |
501 | 8847ea67 | gaqhf | finally |
502 | 154d8f43 | gaqhf | { |
503 | 8847ea67 | gaqhf | if (connection != null) |
504 | connection.Dispose(); |
||
505 | e8536f2b | gaqhf | } |
506 | fab4f207 | gaqhf | } |
507 | 8847ea67 | gaqhf | } |
508 | cf924377 | gaqhf | |
509 | 8847ea67 | gaqhf | return true; |
510 | } |
||
511 | |||
512 | public static DataTable SelectSetting() |
||
513 | { |
||
514 | DataTable dt = new DataTable(); |
||
515 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
516 | if (projectInfo.DBType == ID2DB_Type.SQLite) |
||
517 | { |
||
518 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
||
519 | cf924377 | gaqhf | { |
520 | 8847ea67 | gaqhf | try |
521 | cf924377 | gaqhf | { |
522 | 8847ea67 | gaqhf | connection.Open(); |
523 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
524 | { |
||
525 | cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_SETTING_TABLE); |
||
526 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
527 | dt.Load(dr); |
||
528 | } |
||
529 | connection.Close(); |
||
530 | cf924377 | gaqhf | } |
531 | 8847ea67 | gaqhf | catch (Exception ex) |
532 | { |
||
533 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
534 | 8847ea67 | gaqhf | } |
535 | finally |
||
536 | 7cbb1038 | gaqhf | { |
537 | 8847ea67 | gaqhf | connection.Dispose(); |
538 | 7cbb1038 | gaqhf | } |
539 | } |
||
540 | 8847ea67 | gaqhf | } |
541 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
542 | { |
||
543 | using (SqlConnection connection = GetSqlConnection()) |
||
544 | 224535bb | gaqhf | { |
545 | 8847ea67 | gaqhf | try |
546 | { |
||
547 | if (connection != null && connection.State == ConnectionState.Open) |
||
548 | { |
||
549 | d2a7bef1 | gaqhf | using (SqlCommand cmd = connection.CreateCommand()) |
550 | { |
||
551 | cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_SETTING_TABLE); |
||
552 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
553 | dt.Load(dr); |
||
554 | } |
||
555 | connection.Close(); |
||
556 | 8847ea67 | gaqhf | } |
557 | } |
||
558 | catch (Exception ex) |
||
559 | 224535bb | gaqhf | { |
560 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
561 | 8847ea67 | gaqhf | } |
562 | finally |
||
563 | { |
||
564 | if (connection != null) |
||
565 | connection.Dispose(); |
||
566 | 224535bb | gaqhf | } |
567 | } |
||
568 | fab4f207 | gaqhf | } |
569 | 8847ea67 | gaqhf | |
570 | return dt; |
||
571 | fab4f207 | gaqhf | } |
572 | bca86986 | gaqhf | |
573 | public static DataTable SelectProjectSymbol() |
||
574 | { |
||
575 | DataTable dt = new DataTable(); |
||
576 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
577 | 8847ea67 | gaqhf | if (projectInfo.DBType == ID2DB_Type.SQLite) |
578 | bca86986 | gaqhf | { |
579 | 8847ea67 | gaqhf | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
580 | bca86986 | gaqhf | { |
581 | 8847ea67 | gaqhf | try |
582 | bca86986 | gaqhf | { |
583 | 8847ea67 | gaqhf | connection.Open(); |
584 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
585 | { |
||
586 | cmd.CommandText = string.Format(@" |
||
587 | cf924377 | gaqhf | SELECT s.UID, s.Name, st.Type, sp.SPPID_SYMBOL_PATH, sp.LEADERLINE FROM {1} as st, {0} as s |
588 | bca86986 | gaqhf | LEFT OUTER JOIN {2} as sp |
589 | ON s.UID = SP.UID |
||
590 | WHERE s.SymbolType_UID = st.UID |
||
591 | ORDER BY st.TYPE ASC;", Symbol_TABLE, SymbolType_TABLE, SPPID_SYMBOL_MAPPING_TABLE); |
||
592 | 8847ea67 | gaqhf | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
593 | dt.Load(dr); |
||
594 | 310aeb31 | gaqhf | |
595 | 8847ea67 | gaqhf | DataTable dtClone = dt.Clone(); |
596 | dtClone.Columns["UID"].DataType = typeof(string); |
||
597 | foreach (DataRow row in dt.Rows) |
||
598 | { |
||
599 | dtClone.ImportRow(row); |
||
600 | } |
||
601 | dt.Dispose(); |
||
602 | dt = dtClone; |
||
603 | 310aeb31 | gaqhf | } |
604 | 8847ea67 | gaqhf | connection.Close(); |
605 | bca86986 | gaqhf | } |
606 | 8847ea67 | gaqhf | catch (Exception ex) |
607 | { |
||
608 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
609 | 8847ea67 | gaqhf | } |
610 | finally |
||
611 | { |
||
612 | connection.Dispose(); |
||
613 | } |
||
614 | bca86986 | gaqhf | } |
615 | 8847ea67 | gaqhf | } |
616 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
617 | { |
||
618 | using (SqlConnection connection = GetSqlConnection()) |
||
619 | bca86986 | gaqhf | { |
620 | 8847ea67 | gaqhf | try |
621 | { |
||
622 | if (connection != null && connection.State == ConnectionState.Open) |
||
623 | { |
||
624 | d2a7bef1 | gaqhf | using (SqlCommand cmd = connection.CreateCommand()) |
625 | { |
||
626 | cmd.CommandText = string.Format(@" |
||
627 | a2c803a0 | gaqhf | SELECT CONVERT(VARCHAR(255), s.UID) AS UID, s.Name, st.Type, sp.SPPID_SYMBOL_PATH, sp.LEADERLINE FROM {1} as st, {0} as s |
628 | d2a7bef1 | gaqhf | LEFT OUTER JOIN {2} as sp |
629 | a2c803a0 | gaqhf | ON CONVERT(VARCHAR(255), s.UID) = CONVERT(VARCHAR(255), SP.UID) |
630 | d2a7bef1 | gaqhf | WHERE s.SymbolType_UID = st.UID |
631 | ORDER BY st.TYPE ASC;", Symbol_TABLE, SymbolType_TABLE, SPPID_SYMBOL_MAPPING_TABLE); |
||
632 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
633 | dt.Load(dr); |
||
634 | } |
||
635 | connection.Close(); |
||
636 | 8847ea67 | gaqhf | } |
637 | } |
||
638 | catch (Exception ex) |
||
639 | { |
||
640 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
641 | 8847ea67 | gaqhf | } |
642 | finally |
||
643 | { |
||
644 | if (connection != null) |
||
645 | connection.Dispose(); |
||
646 | } |
||
647 | bca86986 | gaqhf | } |
648 | } |
||
649 | |||
650 | return dt; |
||
651 | } |
||
652 | |||
653 | 4b4dbca9 | gaqhf | public static DataTable SelectProjectChildSymbol() |
654 | { |
||
655 | DataTable result = new DataTable(); |
||
656 | result.Columns.Add("UID"); |
||
657 | result.Columns.Add("Name"); |
||
658 | result.Columns.Add("Type"); |
||
659 | result.Columns.Add("SPPID_SYMBOL_PATH"); |
||
660 | |||
661 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
662 | 8847ea67 | gaqhf | if (projectInfo.DBType == ID2DB_Type.SQLite) |
663 | 4b4dbca9 | gaqhf | { |
664 | 8847ea67 | gaqhf | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
665 | using (DataTable dt = new DataTable()) |
||
666 | 4b4dbca9 | gaqhf | { |
667 | 8847ea67 | gaqhf | try |
668 | 4b4dbca9 | gaqhf | { |
669 | 8847ea67 | gaqhf | connection.Open(); |
670 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
671 | { |
||
672 | cmd.CommandText = string.Format(@" |
||
673 | 4b4dbca9 | gaqhf | SELECT AdditionalSymbol FROM Symbol"); |
674 | 8847ea67 | gaqhf | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
675 | dt.Load(dr); |
||
676 | List<string> childList = new List<string>(); |
||
677 | foreach (DataRow row in dt.Rows) |
||
678 | 4b4dbca9 | gaqhf | { |
679 | 8847ea67 | gaqhf | if (row["AdditionalSymbol"] != null && !DBNull.Value.Equals(row["AdditionalSymbol"]) && !string.IsNullOrEmpty((string)row["AdditionalSymbol"])) |
680 | 4b4dbca9 | gaqhf | { |
681 | 8847ea67 | gaqhf | string[] array = row["AdditionalSymbol"].ToString().Split(new char[] { '/' }); |
682 | foreach (var childString in array) |
||
683 | { |
||
684 | childList.Add(childString.Split(new char[] { ',' })[2]); |
||
685 | } |
||
686 | 4b4dbca9 | gaqhf | } |
687 | |||
688 | 8847ea67 | gaqhf | } |
689 | 4b4dbca9 | gaqhf | |
690 | 8847ea67 | gaqhf | dt.Clear(); |
691 | cmd.Reset(); |
||
692 | cmd.CommandText = string.Format(@" |
||
693 | 4b4dbca9 | gaqhf | SELECT * FROM {0}", SPPID_SYMBOL_MAPPING_TABLE); |
694 | 8847ea67 | gaqhf | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
695 | dt.Load(dr); |
||
696 | 4b4dbca9 | gaqhf | |
697 | 8847ea67 | gaqhf | childList = childList.Distinct().ToList(); |
698 | foreach (var child in childList) |
||
699 | { |
||
700 | string mappingPath = string.Empty; |
||
701 | DataRow[] rows = dt.Select(string.Format("UID = '{0}'", child)); |
||
702 | if (rows.Length == 1) |
||
703 | mappingPath = !DBNull.Value.Equals(rows[0]["SPPID_SYMBOL_PATH"]) ? (string)rows[0]["SPPID_SYMBOL_PATH"] : null; |
||
704 | |||
705 | DataRow newRow = result.NewRow(); |
||
706 | newRow["UID"] = child; |
||
707 | newRow["Name"] = child; |
||
708 | newRow["Type"] = "Child Symbol"; |
||
709 | newRow["SPPID_SYMBOL_PATH"] = mappingPath; |
||
710 | result.Rows.Add(newRow); |
||
711 | } |
||
712 | 4b4dbca9 | gaqhf | } |
713 | 8847ea67 | gaqhf | connection.Close(); |
714 | 4b4dbca9 | gaqhf | } |
715 | 8847ea67 | gaqhf | catch (Exception ex) |
716 | { |
||
717 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
718 | 8847ea67 | gaqhf | } |
719 | finally |
||
720 | { |
||
721 | connection.Dispose(); |
||
722 | } |
||
723 | 4b4dbca9 | gaqhf | } |
724 | 8847ea67 | gaqhf | } |
725 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
726 | { |
||
727 | using (SqlConnection connection = GetSqlConnection()) |
||
728 | d2a7bef1 | gaqhf | using (DataTable dt = new DataTable()) |
729 | 4b4dbca9 | gaqhf | { |
730 | 8847ea67 | gaqhf | try |
731 | { |
||
732 | if (connection != null && connection.State == ConnectionState.Open) |
||
733 | { |
||
734 | d2a7bef1 | gaqhf | using (SqlCommand cmd = connection.CreateCommand()) |
735 | { |
||
736 | cmd.CommandText = string.Format(@" |
||
737 | SELECT AdditionalSymbol FROM Symbol"); |
||
738 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
739 | dt.Load(dr); |
||
740 | List<string> childList = new List<string>(); |
||
741 | foreach (DataRow row in dt.Rows) |
||
742 | { |
||
743 | if (row["AdditionalSymbol"] != null && !DBNull.Value.Equals(row["AdditionalSymbol"]) && !string.IsNullOrEmpty((string)row["AdditionalSymbol"])) |
||
744 | { |
||
745 | string[] array = row["AdditionalSymbol"].ToString().Split(new char[] { '/' }); |
||
746 | foreach (var childString in array) |
||
747 | { |
||
748 | childList.Add(childString.Split(new char[] { ',' })[2]); |
||
749 | } |
||
750 | } |
||
751 | |||
752 | } |
||
753 | |||
754 | dt.Clear(); |
||
755 | cmd.CommandText = string.Format(@" |
||
756 | SELECT * FROM {0}", SPPID_SYMBOL_MAPPING_TABLE); |
||
757 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
758 | dt.Load(dr); |
||
759 | 8847ea67 | gaqhf | |
760 | d2a7bef1 | gaqhf | childList = childList.Distinct().ToList(); |
761 | foreach (var child in childList) |
||
762 | { |
||
763 | string mappingPath = string.Empty; |
||
764 | DataRow[] rows = dt.Select(string.Format("UID = '{0}'", child)); |
||
765 | if (rows.Length == 1) |
||
766 | mappingPath = !DBNull.Value.Equals(rows[0]["SPPID_SYMBOL_PATH"]) ? (string)rows[0]["SPPID_SYMBOL_PATH"] : null; |
||
767 | |||
768 | DataRow newRow = result.NewRow(); |
||
769 | newRow["UID"] = child; |
||
770 | newRow["Name"] = child; |
||
771 | newRow["Type"] = "Child Symbol"; |
||
772 | newRow["SPPID_SYMBOL_PATH"] = mappingPath; |
||
773 | result.Rows.Add(newRow); |
||
774 | } |
||
775 | } |
||
776 | connection.Close(); |
||
777 | 8847ea67 | gaqhf | } |
778 | } |
||
779 | catch (Exception ex) |
||
780 | { |
||
781 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
782 | 8847ea67 | gaqhf | } |
783 | finally |
||
784 | { |
||
785 | if (connection != null) |
||
786 | connection.Dispose(); |
||
787 | } |
||
788 | 4b4dbca9 | gaqhf | } |
789 | } |
||
790 | return result; |
||
791 | } |
||
792 | |||
793 | bca86986 | gaqhf | public static DataTable SelectProjectLine() |
794 | { |
||
795 | DataTable dt = new DataTable(); |
||
796 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
797 | 8847ea67 | gaqhf | if (projectInfo.DBType == ID2DB_Type.SQLite) |
798 | bca86986 | gaqhf | { |
799 | 8847ea67 | gaqhf | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
800 | bca86986 | gaqhf | { |
801 | 8847ea67 | gaqhf | try |
802 | bca86986 | gaqhf | { |
803 | 8847ea67 | gaqhf | connection.Open(); |
804 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
805 | { |
||
806 | cmd.CommandText = string.Format(@" |
||
807 | bca86986 | gaqhf | SELECT l.UID, l.Name, sp.SPPID_SYMBOL_PATH FROM {0} as l |
808 | LEFT OUTER JOIN {1} as sp |
||
809 | ON l.UID = SP.UID ;", LineTypes_TABLE, SPPID_SYMBOL_MAPPING_TABLE); |
||
810 | 8847ea67 | gaqhf | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
811 | dt.Load(dr); |
||
812 | } |
||
813 | connection.Close(); |
||
814 | bca86986 | gaqhf | } |
815 | 8847ea67 | gaqhf | catch (Exception ex) |
816 | { |
||
817 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
818 | 8847ea67 | gaqhf | } |
819 | finally |
||
820 | { |
||
821 | connection.Dispose(); |
||
822 | } |
||
823 | bca86986 | gaqhf | } |
824 | 8847ea67 | gaqhf | } |
825 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
826 | { |
||
827 | using (SqlConnection connection = GetSqlConnection()) |
||
828 | bca86986 | gaqhf | { |
829 | 8847ea67 | gaqhf | try |
830 | { |
||
831 | if (connection != null && connection.State == ConnectionState.Open) |
||
832 | { |
||
833 | d2a7bef1 | gaqhf | using (SqlCommand cmd = connection.CreateCommand()) |
834 | { |
||
835 | cmd.CommandText = string.Format(@" |
||
836 | SELECT l.UID, l.Name, sp.SPPID_SYMBOL_PATH FROM {0} as l |
||
837 | LEFT OUTER JOIN {1} as sp |
||
838 | ON l.UID = SP.UID ;", LineTypes_TABLE, SPPID_SYMBOL_MAPPING_TABLE); |
||
839 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
840 | dt.Load(dr); |
||
841 | } |
||
842 | connection.Close(); |
||
843 | 8847ea67 | gaqhf | } |
844 | } |
||
845 | catch (Exception ex) |
||
846 | { |
||
847 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
848 | 8847ea67 | gaqhf | } |
849 | finally |
||
850 | { |
||
851 | if (connection != null) |
||
852 | connection.Dispose(); |
||
853 | } |
||
854 | bca86986 | gaqhf | } |
855 | } |
||
856 | |||
857 | return dt; |
||
858 | } |
||
859 | |||
860 | public static DataTable SelectProjectLineProperties() |
||
861 | { |
||
862 | DataTable dt = new DataTable(); |
||
863 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
864 | 8847ea67 | gaqhf | if (projectInfo.DBType == ID2DB_Type.SQLite) |
865 | bca86986 | gaqhf | { |
866 | 8847ea67 | gaqhf | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
867 | bca86986 | gaqhf | { |
868 | 8847ea67 | gaqhf | try |
869 | bca86986 | gaqhf | { |
870 | 8847ea67 | gaqhf | connection.Open(); |
871 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
872 | { |
||
873 | cmd.CommandText = string.Format(@" |
||
874 | bca86986 | gaqhf | SELECT lp.UID, lp.DisplayName, sp.SPPID_SYMBOL_PATH, spa.SPPID_ATTRIBUTE |
875 | FROM {0} as lp |
||
876 | LEFT OUTER JOIN {1} as sp |
||
877 | ON lp.UID = sp.UID |
||
878 | LEFT OUTER JOIN {2} as spa |
||
879 | ON lp.UID = spa.UID;", LineProperties_TABLE, SPPID_SYMBOL_MAPPING_TABLE, SPPID_ATTRIBUTE_MAPPING_TABLE); |
||
880 | 8847ea67 | gaqhf | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
881 | dt.Load(dr); |
||
882 | } |
||
883 | connection.Close(); |
||
884 | bca86986 | gaqhf | } |
885 | 8847ea67 | gaqhf | catch (Exception ex) |
886 | { |
||
887 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
888 | 8847ea67 | gaqhf | } |
889 | finally |
||
890 | { |
||
891 | connection.Dispose(); |
||
892 | } |
||
893 | bca86986 | gaqhf | } |
894 | 8847ea67 | gaqhf | } |
895 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
896 | { |
||
897 | using (SqlConnection connection = GetSqlConnection()) |
||
898 | bca86986 | gaqhf | { |
899 | 8847ea67 | gaqhf | try |
900 | { |
||
901 | if (connection != null && connection.State == ConnectionState.Open) |
||
902 | { |
||
903 | d2a7bef1 | gaqhf | using (SqlCommand cmd = connection.CreateCommand()) |
904 | { |
||
905 | cmd.CommandText = string.Format(@" |
||
906 | SELECT lp.UID, lp.DisplayName, sp.SPPID_SYMBOL_PATH, spa.SPPID_ATTRIBUTE |
||
907 | FROM {0} as lp |
||
908 | LEFT OUTER JOIN {1} as sp |
||
909 | ON lp.UID = sp.UID |
||
910 | LEFT OUTER JOIN {2} as spa |
||
911 | ON lp.UID = spa.UID;", LineProperties_TABLE, SPPID_SYMBOL_MAPPING_TABLE, SPPID_ATTRIBUTE_MAPPING_TABLE); |
||
912 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
913 | dt.Load(dr); |
||
914 | } |
||
915 | connection.Close(); |
||
916 | 8847ea67 | gaqhf | } |
917 | } |
||
918 | catch (Exception ex) |
||
919 | { |
||
920 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
921 | 8847ea67 | gaqhf | } |
922 | finally |
||
923 | { |
||
924 | if (connection != null) |
||
925 | connection.Dispose(); |
||
926 | } |
||
927 | bca86986 | gaqhf | } |
928 | } |
||
929 | |||
930 | return dt; |
||
931 | } |
||
932 | |||
933 | 1efc25a3 | gaqhf | public static DataTable SelectProjectAttribute() |
934 | bca86986 | gaqhf | { |
935 | DataTable dt = new DataTable(); |
||
936 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
937 | 8847ea67 | gaqhf | if (projectInfo.DBType == ID2DB_Type.SQLite) |
938 | bca86986 | gaqhf | { |
939 | 8847ea67 | gaqhf | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
940 | bca86986 | gaqhf | { |
941 | 8847ea67 | gaqhf | try |
942 | bca86986 | gaqhf | { |
943 | 8847ea67 | gaqhf | connection.Open(); |
944 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
945 | { |
||
946 | cmd.CommandText = string.Format(@" |
||
947 | 923501a9 | gaqhf | SELECT sa.UID, sa.DisplayAttribute, st.TYPE, spa.SPPID_ATTRIBUTE, sp.SPPID_SYMBOL_PATH, spa.ISTEXT, spl.LOCATION, spl.LEADERLINE, sa.Property |
948 | bca86986 | gaqhf | FROM {1} as sa, {0} as st |
949 | LEFT OUTER JOIN {2} as sp |
||
950 | ON sa.UID = SP.UID |
||
951 | LEFT OUTER JOIN {3} as spa |
||
952 | ON sa.UID = spa.UID |
||
953 | 1a3a74a8 | gaqhf | LEFT OUTER JOIN {4} as spl |
954 | ON sa.UID = spl.UID |
||
955 | 401efcff | gaqhf | WHERE sa.SymbolType_UID = st.UID AND (sa.Property != 2 OR sa.Property IS NULL);", SymbolType_TABLE, SymbolAttribute_TABLE, SPPID_SYMBOL_MAPPING_TABLE, SPPID_ATTRIBUTE_MAPPING_TABLE, SPPID_LABEL_INFO_TABLE); |
956 | 8847ea67 | gaqhf | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
957 | dt.Load(dr); |
||
958 | } |
||
959 | connection.Close(); |
||
960 | bca86986 | gaqhf | } |
961 | 8847ea67 | gaqhf | catch (Exception ex) |
962 | { |
||
963 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
964 | 8847ea67 | gaqhf | } |
965 | finally |
||
966 | { |
||
967 | connection.Dispose(); |
||
968 | } |
||
969 | } |
||
970 | } |
||
971 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
972 | { |
||
973 | using (SqlConnection connection = GetSqlConnection()) |
||
974 | bca86986 | gaqhf | { |
975 | 8847ea67 | gaqhf | try |
976 | { |
||
977 | if (connection != null && connection.State == ConnectionState.Open) |
||
978 | { |
||
979 | d2a7bef1 | gaqhf | using (SqlCommand cmd = connection.CreateCommand()) |
980 | { |
||
981 | cmd.CommandText = string.Format(@" |
||
982 | 923501a9 | gaqhf | SELECT sa.UID, sa.DisplayAttribute, st.Type, spa.SPPID_ATTRIBUTE, sp.SPPID_SYMBOL_PATH, spa.ISTEXT, spl.LOCATION, spl.LEADERLINE, sa.Property |
983 | d2a7bef1 | gaqhf | FROM {1} as sa |
984 | LEFT OUTER JOIN {2} as sp |
||
985 | ON sa.UID = SP.UID |
||
986 | LEFT OUTER JOIN {3} as spa |
||
987 | ON sa.UID = spa.UID |
||
988 | LEFT OUTER JOIN {4} as spl |
||
989 | ON sa.UID = spl.UID |
||
990 | LEFT OUTER JOIN {0} as st |
||
991 | ON sa.SymbolType_UID = st.UID |
||
992 | WHERE (sa.Property != 2 OR sa.Property IS NULL);", SymbolType_TABLE, SymbolAttribute_TABLE, SPPID_SYMBOL_MAPPING_TABLE, SPPID_ATTRIBUTE_MAPPING_TABLE, SPPID_LABEL_INFO_TABLE); |
||
993 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
994 | dt.Load(dr); |
||
995 | } |
||
996 | connection.Close(); |
||
997 | 8847ea67 | gaqhf | } |
998 | } |
||
999 | catch (Exception ex) |
||
1000 | { |
||
1001 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1002 | 8847ea67 | gaqhf | } |
1003 | finally |
||
1004 | { |
||
1005 | if (connection != null) |
||
1006 | connection.Dispose(); |
||
1007 | } |
||
1008 | bca86986 | gaqhf | } |
1009 | } |
||
1010 | |||
1011 | 8847ea67 | gaqhf | |
1012 | bca86986 | gaqhf | return dt; |
1013 | } |
||
1014 | |||
1015 | 306a0af9 | gaqhf | public static DataTable SelectDrawingProjectAttribute() |
1016 | { |
||
1017 | DataTable dt = new DataTable(); |
||
1018 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
1019 | if (projectInfo.DBType == ID2DB_Type.SQLite) |
||
1020 | { |
||
1021 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
||
1022 | { |
||
1023 | try |
||
1024 | { |
||
1025 | connection.Open(); |
||
1026 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
1027 | { |
||
1028 | cmd.CommandText = string.Format(@" |
||
1029 | SELECT da.UID, da.NAME, sam.SPPID_ATTRIBUTE |
||
1030 | FROM {0} as da |
||
1031 | LEFT OUTER JOIN {1} as sam |
||
1032 | ON da.UID = sam.UID; |
||
1033 | ", DrawingAttribute_Table, SPPID_ATTRIBUTE_MAPPING_TABLE); |
||
1034 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
1035 | dt.Load(dr); |
||
1036 | } |
||
1037 | connection.Close(); |
||
1038 | } |
||
1039 | catch (Exception ex) |
||
1040 | { |
||
1041 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
1042 | } |
||
1043 | finally |
||
1044 | { |
||
1045 | connection.Dispose(); |
||
1046 | } |
||
1047 | } |
||
1048 | } |
||
1049 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
1050 | { |
||
1051 | using (SqlConnection connection = GetSqlConnection()) |
||
1052 | { |
||
1053 | try |
||
1054 | { |
||
1055 | if (connection != null && connection.State == ConnectionState.Open) |
||
1056 | { |
||
1057 | using (SqlCommand cmd = connection.CreateCommand()) |
||
1058 | { |
||
1059 | cmd.CommandText = string.Format(@" |
||
1060 | SELECT da.UID, da.NAME, sam.SPPID_ATTRIBUTE |
||
1061 | FROM {0} as da |
||
1062 | LEFT OUTER JOIN {1} as sam |
||
1063 | ON da.UID = sam.UID; |
||
1064 | ", DrawingAttribute_Table, SPPID_ATTRIBUTE_MAPPING_TABLE); |
||
1065 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
1066 | dt.Load(dr); |
||
1067 | } |
||
1068 | connection.Close(); |
||
1069 | } |
||
1070 | } |
||
1071 | catch (Exception ex) |
||
1072 | { |
||
1073 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
1074 | } |
||
1075 | finally |
||
1076 | { |
||
1077 | if (connection != null) |
||
1078 | connection.Dispose(); |
||
1079 | } |
||
1080 | } |
||
1081 | } |
||
1082 | |||
1083 | dt.Merge(SelectDrawingProjectAttribute2()); |
||
1084 | |||
1085 | return dt; |
||
1086 | } |
||
1087 | 923501a9 | gaqhf | |
1088 | 306a0af9 | gaqhf | private static DataTable SelectDrawingProjectAttribute2() |
1089 | { |
||
1090 | DataTable dt = new DataTable(); |
||
1091 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
1092 | if (projectInfo.DBType == ID2DB_Type.SQLite) |
||
1093 | { |
||
1094 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
||
1095 | { |
||
1096 | try |
||
1097 | { |
||
1098 | connection.Open(); |
||
1099 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
1100 | { |
||
1101 | cmd.CommandText = string.Format(@" |
||
1102 | SELECT da.UID, da.NAME, sam.SPPID_ATTRIBUTE |
||
1103 | FROM {0} as da |
||
1104 | LEFT OUTER JOIN {1} as sam |
||
1105 | ON da.UID = sam.UID; |
||
1106 | ", ID2_DRAWINGATTRIBUTE_TABLE, SPPID_ATTRIBUTE_MAPPING_TABLE); |
||
1107 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
1108 | dt.Load(dr); |
||
1109 | } |
||
1110 | connection.Close(); |
||
1111 | } |
||
1112 | catch (Exception ex) |
||
1113 | { |
||
1114 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
1115 | } |
||
1116 | finally |
||
1117 | { |
||
1118 | connection.Dispose(); |
||
1119 | } |
||
1120 | } |
||
1121 | } |
||
1122 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
1123 | { |
||
1124 | using (SqlConnection connection = GetSqlConnection()) |
||
1125 | { |
||
1126 | try |
||
1127 | { |
||
1128 | if (connection != null && connection.State == ConnectionState.Open) |
||
1129 | { |
||
1130 | using (SqlCommand cmd = connection.CreateCommand()) |
||
1131 | { |
||
1132 | cmd.CommandText = string.Format(@" |
||
1133 | SELECT da.UID, da.NAME, sam.SPPID_ATTRIBUTE |
||
1134 | FROM {0} as da |
||
1135 | LEFT OUTER JOIN {1} as sam |
||
1136 | ON da.UID = sam.UID; |
||
1137 | ", ID2_DRAWINGATTRIBUTE_TABLE, SPPID_ATTRIBUTE_MAPPING_TABLE); |
||
1138 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
1139 | dt.Load(dr); |
||
1140 | } |
||
1141 | connection.Close(); |
||
1142 | } |
||
1143 | } |
||
1144 | catch (Exception ex) |
||
1145 | { |
||
1146 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
1147 | } |
||
1148 | finally |
||
1149 | { |
||
1150 | if (connection != null) |
||
1151 | connection.Dispose(); |
||
1152 | } |
||
1153 | } |
||
1154 | } |
||
1155 | |||
1156 | return dt; |
||
1157 | } |
||
1158 | |||
1159 | 4d2571ab | gaqhf | public static DataTable SelectID2SymbolTable() |
1160 | { |
||
1161 | DataTable dt = new DataTable(); |
||
1162 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
1163 | 8847ea67 | gaqhf | if (projectInfo.DBType == ID2DB_Type.SQLite) |
1164 | 4d2571ab | gaqhf | { |
1165 | 8847ea67 | gaqhf | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
1166 | 4d2571ab | gaqhf | { |
1167 | 8847ea67 | gaqhf | try |
1168 | 4d2571ab | gaqhf | { |
1169 | 8847ea67 | gaqhf | connection.Open(); |
1170 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
1171 | { |
||
1172 | cmd.CommandText = @"SELECT * FROM Symbol"; |
||
1173 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
1174 | dt.Load(dr); |
||
1175 | } |
||
1176 | connection.Close(); |
||
1177 | 4d2571ab | gaqhf | } |
1178 | 8847ea67 | gaqhf | catch (Exception ex) |
1179 | { |
||
1180 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1181 | 8847ea67 | gaqhf | } |
1182 | finally |
||
1183 | { |
||
1184 | connection.Dispose(); |
||
1185 | } |
||
1186 | 4d2571ab | gaqhf | } |
1187 | 8847ea67 | gaqhf | } |
1188 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
1189 | { |
||
1190 | using (SqlConnection connection = GetSqlConnection()) |
||
1191 | 4d2571ab | gaqhf | { |
1192 | 8847ea67 | gaqhf | try |
1193 | { |
||
1194 | if (connection != null && connection.State == ConnectionState.Open) |
||
1195 | { |
||
1196 | d2a7bef1 | gaqhf | using (SqlCommand cmd = connection.CreateCommand()) |
1197 | { |
||
1198 | cmd.CommandText = @"SELECT * FROM Symbol"; |
||
1199 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
1200 | dt.Load(dr); |
||
1201 | } |
||
1202 | connection.Close(); |
||
1203 | 8847ea67 | gaqhf | } |
1204 | } |
||
1205 | catch (Exception ex) |
||
1206 | { |
||
1207 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1208 | 8847ea67 | gaqhf | } |
1209 | finally |
||
1210 | { |
||
1211 | if (connection != null) |
||
1212 | connection.Dispose(); |
||
1213 | } |
||
1214 | 4d2571ab | gaqhf | } |
1215 | } |
||
1216 | |||
1217 | return dt; |
||
1218 | } |
||
1219 | |||
1220 | 154d8f43 | gaqhf | public static DataTable SelectOPCRelations() |
1221 | { |
||
1222 | DataTable dt = new DataTable(); |
||
1223 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
1224 | 8847ea67 | gaqhf | if (projectInfo.DBType == ID2DB_Type.SQLite) |
1225 | 154d8f43 | gaqhf | { |
1226 | 8847ea67 | gaqhf | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
1227 | 154d8f43 | gaqhf | { |
1228 | 8847ea67 | gaqhf | try |
1229 | 154d8f43 | gaqhf | { |
1230 | 8847ea67 | gaqhf | connection.Open(); |
1231 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
1232 | { |
||
1233 | cmd.CommandText = string.Format("SELECT * FROM {0}", OPCRelations_TABLE); |
||
1234 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
1235 | dt.Load(dr); |
||
1236 | } |
||
1237 | connection.Close(); |
||
1238 | 154d8f43 | gaqhf | } |
1239 | 8847ea67 | gaqhf | catch (Exception ex) |
1240 | { |
||
1241 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1242 | 8847ea67 | gaqhf | } |
1243 | finally |
||
1244 | { |
||
1245 | connection.Dispose(); |
||
1246 | } |
||
1247 | 154d8f43 | gaqhf | } |
1248 | 8847ea67 | gaqhf | } |
1249 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
1250 | { |
||
1251 | using (SqlConnection connection = GetSqlConnection()) |
||
1252 | 154d8f43 | gaqhf | { |
1253 | 8847ea67 | gaqhf | try |
1254 | { |
||
1255 | if (connection != null && connection.State == ConnectionState.Open) |
||
1256 | { |
||
1257 | d2a7bef1 | gaqhf | using (SqlCommand cmd = connection.CreateCommand()) |
1258 | { |
||
1259 | cmd.CommandText = string.Format("SELECT * FROM {0}", OPCRelations_TABLE); |
||
1260 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
1261 | dt.Load(dr); |
||
1262 | } |
||
1263 | connection.Close(); |
||
1264 | 8847ea67 | gaqhf | } |
1265 | } |
||
1266 | catch (Exception ex) |
||
1267 | { |
||
1268 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1269 | 8847ea67 | gaqhf | } |
1270 | finally |
||
1271 | { |
||
1272 | if (connection != null) |
||
1273 | connection.Dispose(); |
||
1274 | } |
||
1275 | 154d8f43 | gaqhf | } |
1276 | } |
||
1277 | |||
1278 | return dt; |
||
1279 | } |
||
1280 | |||
1281 | public static DataTable SelectDrawings() |
||
1282 | { |
||
1283 | DataTable dt = new DataTable(); |
||
1284 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
1285 | 8847ea67 | gaqhf | if (projectInfo.DBType == ID2DB_Type.SQLite) |
1286 | 154d8f43 | gaqhf | { |
1287 | 8847ea67 | gaqhf | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
1288 | 154d8f43 | gaqhf | { |
1289 | 8847ea67 | gaqhf | try |
1290 | 154d8f43 | gaqhf | { |
1291 | 8847ea67 | gaqhf | connection.Open(); |
1292 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
1293 | { |
||
1294 | cmd.CommandText = string.Format("SELECT * FROM {0}", "Drawings"); |
||
1295 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
1296 | dt.Load(dr); |
||
1297 | } |
||
1298 | connection.Close(); |
||
1299 | 154d8f43 | gaqhf | } |
1300 | 8847ea67 | gaqhf | catch (Exception ex) |
1301 | { |
||
1302 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1303 | 8847ea67 | gaqhf | } |
1304 | finally |
||
1305 | { |
||
1306 | connection.Dispose(); |
||
1307 | } |
||
1308 | 154d8f43 | gaqhf | } |
1309 | 8847ea67 | gaqhf | } |
1310 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
1311 | { |
||
1312 | using (SqlConnection connection = GetSqlConnection()) |
||
1313 | 154d8f43 | gaqhf | { |
1314 | 8847ea67 | gaqhf | try |
1315 | { |
||
1316 | if (connection != null && connection.State == ConnectionState.Open) |
||
1317 | { |
||
1318 | d2a7bef1 | gaqhf | using (SqlCommand cmd = connection.CreateCommand()) |
1319 | { |
||
1320 | cmd.CommandText = string.Format("SELECT * FROM {0}", "Drawings"); |
||
1321 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
1322 | dt.Load(dr); |
||
1323 | } |
||
1324 | connection.Close(); |
||
1325 | 8847ea67 | gaqhf | } |
1326 | } |
||
1327 | catch (Exception ex) |
||
1328 | { |
||
1329 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1330 | 8847ea67 | gaqhf | } |
1331 | finally |
||
1332 | { |
||
1333 | if (connection != null) |
||
1334 | connection.Dispose(); |
||
1335 | } |
||
1336 | 154d8f43 | gaqhf | } |
1337 | } |
||
1338 | |||
1339 | return dt; |
||
1340 | } |
||
1341 | |||
1342 | public static DataTable SelectOPCInfo() |
||
1343 | { |
||
1344 | DataTable dt = new DataTable(); |
||
1345 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
1346 | 8847ea67 | gaqhf | if (projectInfo.DBType == ID2DB_Type.SQLite) |
1347 | 154d8f43 | gaqhf | { |
1348 | 8847ea67 | gaqhf | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
1349 | 154d8f43 | gaqhf | { |
1350 | 8847ea67 | gaqhf | try |
1351 | 154d8f43 | gaqhf | { |
1352 | 8847ea67 | gaqhf | connection.Open(); |
1353 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
1354 | { |
||
1355 | cmd.CommandText = string.Format("SELECT * FROM {0} WHERE SPPID_OPC_MODELITEM_ID IS NOT NULL AND PAIRED = False", SPPID_OPC_INFO); |
||
1356 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
1357 | dt.Load(dr); |
||
1358 | } |
||
1359 | connection.Close(); |
||
1360 | 154d8f43 | gaqhf | } |
1361 | 8847ea67 | gaqhf | catch (Exception ex) |
1362 | { |
||
1363 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1364 | 8847ea67 | gaqhf | } |
1365 | finally |
||
1366 | { |
||
1367 | connection.Dispose(); |
||
1368 | } |
||
1369 | 154d8f43 | gaqhf | } |
1370 | 8847ea67 | gaqhf | } |
1371 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
1372 | { |
||
1373 | using (SqlConnection connection = GetSqlConnection()) |
||
1374 | 154d8f43 | gaqhf | { |
1375 | 8847ea67 | gaqhf | try |
1376 | { |
||
1377 | if (connection != null && connection.State == ConnectionState.Open) |
||
1378 | { |
||
1379 | d2a7bef1 | gaqhf | using (SqlCommand cmd = connection.CreateCommand()) |
1380 | { |
||
1381 | 0cab8feb | gaqhf | cmd.CommandText = string.Format("SELECT * FROM {0} WHERE SPPID_OPC_MODELITEM_ID IS NOT NULL AND PAIRED = 0", SPPID_OPC_INFO); |
1382 | d2a7bef1 | gaqhf | using (SqlDataReader dr = cmd.ExecuteReader()) |
1383 | dt.Load(dr); |
||
1384 | } |
||
1385 | connection.Close(); |
||
1386 | 8847ea67 | gaqhf | } |
1387 | } |
||
1388 | catch (Exception ex) |
||
1389 | { |
||
1390 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1391 | 8847ea67 | gaqhf | } |
1392 | finally |
||
1393 | { |
||
1394 | if (connection != null) |
||
1395 | connection.Dispose(); |
||
1396 | } |
||
1397 | 154d8f43 | gaqhf | } |
1398 | } |
||
1399 | |||
1400 | return dt; |
||
1401 | } |
||
1402 | 7e680366 | gaqhf | |
1403 | public static DataTable SelectSymbolType() |
||
1404 | { |
||
1405 | DataTable dt = new DataTable(); |
||
1406 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
1407 | 8847ea67 | gaqhf | if (projectInfo.DBType == ID2DB_Type.SQLite) |
1408 | 7e680366 | gaqhf | { |
1409 | 8847ea67 | gaqhf | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
1410 | 7e680366 | gaqhf | { |
1411 | 8847ea67 | gaqhf | try |
1412 | 7e680366 | gaqhf | { |
1413 | 8847ea67 | gaqhf | connection.Open(); |
1414 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
1415 | { |
||
1416 | cmd.CommandText = string.Format("SELECT * FROM {0}", SymbolType_TABLE); |
||
1417 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
1418 | dt.Load(dr); |
||
1419 | } |
||
1420 | connection.Close(); |
||
1421 | 7e680366 | gaqhf | } |
1422 | 8847ea67 | gaqhf | catch (Exception ex) |
1423 | { |
||
1424 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1425 | 8847ea67 | gaqhf | } |
1426 | finally |
||
1427 | { |
||
1428 | connection.Dispose(); |
||
1429 | } |
||
1430 | 7e680366 | gaqhf | } |
1431 | 8847ea67 | gaqhf | } |
1432 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
1433 | { |
||
1434 | using (SqlConnection connection = GetSqlConnection()) |
||
1435 | 7e680366 | gaqhf | { |
1436 | 8847ea67 | gaqhf | try |
1437 | { |
||
1438 | if (connection != null && connection.State == ConnectionState.Open) |
||
1439 | { |
||
1440 | d2a7bef1 | gaqhf | using (SqlCommand cmd = connection.CreateCommand()) |
1441 | { |
||
1442 | cmd.CommandText = string.Format("SELECT * FROM {0}", SymbolType_TABLE); |
||
1443 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
1444 | dt.Load(dr); |
||
1445 | } |
||
1446 | connection.Close(); |
||
1447 | 8847ea67 | gaqhf | } |
1448 | } |
||
1449 | catch (Exception ex) |
||
1450 | { |
||
1451 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1452 | 8847ea67 | gaqhf | } |
1453 | finally |
||
1454 | { |
||
1455 | if (connection != null) |
||
1456 | connection.Dispose(); |
||
1457 | } |
||
1458 | 7e680366 | gaqhf | } |
1459 | } |
||
1460 | |||
1461 | return dt; |
||
1462 | } |
||
1463 | |||
1464 | 4fb0f8d5 | gaqhf | public static DataTable SelectDrawingInfo() |
1465 | { |
||
1466 | 154d8f43 | gaqhf | DataTable dt = new DataTable(); |
1467 | 4fb0f8d5 | gaqhf | Project_Info projectInfo = Project_Info.GetInstance(); |
1468 | 8847ea67 | gaqhf | if (projectInfo.DBType == ID2DB_Type.SQLite) |
1469 | 4fb0f8d5 | gaqhf | { |
1470 | 8847ea67 | gaqhf | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
1471 | 4fb0f8d5 | gaqhf | { |
1472 | 8847ea67 | gaqhf | try |
1473 | 4fb0f8d5 | gaqhf | { |
1474 | 8847ea67 | gaqhf | connection.Open(); |
1475 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
1476 | { |
||
1477 | cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_DRAWING_INFO); |
||
1478 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
1479 | dt.Load(dr); |
||
1480 | } |
||
1481 | connection.Close(); |
||
1482 | 4fb0f8d5 | gaqhf | } |
1483 | 8847ea67 | gaqhf | catch (Exception ex) |
1484 | { |
||
1485 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1486 | 8847ea67 | gaqhf | } |
1487 | finally |
||
1488 | { |
||
1489 | connection.Dispose(); |
||
1490 | } |
||
1491 | 4fb0f8d5 | gaqhf | } |
1492 | 8847ea67 | gaqhf | } |
1493 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
1494 | { |
||
1495 | using (SqlConnection connection = GetSqlConnection()) |
||
1496 | 4fb0f8d5 | gaqhf | { |
1497 | 8847ea67 | gaqhf | try |
1498 | { |
||
1499 | if (connection != null && connection.State == ConnectionState.Open) |
||
1500 | { |
||
1501 | d2a7bef1 | gaqhf | using (SqlCommand cmd = connection.CreateCommand()) |
1502 | { |
||
1503 | cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_DRAWING_INFO); |
||
1504 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
1505 | dt.Load(dr); |
||
1506 | } |
||
1507 | connection.Close(); |
||
1508 | 8847ea67 | gaqhf | } |
1509 | } |
||
1510 | catch (Exception ex) |
||
1511 | { |
||
1512 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1513 | 8847ea67 | gaqhf | } |
1514 | finally |
||
1515 | { |
||
1516 | if (connection != null) |
||
1517 | connection.Dispose(); |
||
1518 | } |
||
1519 | 4fb0f8d5 | gaqhf | } |
1520 | } |
||
1521 | |||
1522 | return dt; |
||
1523 | } |
||
1524 | |||
1525 | cf924377 | gaqhf | public static bool InsertSymbolMapping(List<Tuple<string, string, string, bool>> datas) |
1526 | bca86986 | gaqhf | { |
1527 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
1528 | 8847ea67 | gaqhf | if (projectInfo.DBType == ID2DB_Type.SQLite) |
1529 | bca86986 | gaqhf | { |
1530 | 8847ea67 | gaqhf | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
1531 | bca86986 | gaqhf | { |
1532 | 8847ea67 | gaqhf | try |
1533 | bca86986 | gaqhf | { |
1534 | 8847ea67 | gaqhf | connection.Open(); |
1535 | using (SQLiteTransaction transaction = connection.BeginTransaction()) |
||
1536 | 1421f1d6 | gaqhf | { |
1537 | 8847ea67 | gaqhf | try |
1538 | 1421f1d6 | gaqhf | { |
1539 | 8847ea67 | gaqhf | using (SQLiteCommand cmd = connection.CreateCommand()) |
1540 | 1421f1d6 | gaqhf | { |
1541 | 8847ea67 | gaqhf | foreach (var item in datas) |
1542 | { |
||
1543 | cmd.Parameters.Clear(); |
||
1544 | cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, NAME, SPPID_SYMBOL_PATH, LEADERLINE) VALUES (@UID, @NAME, @SPPID_SYMBOL_PATH, @LEADERLINE)", SPPID_SYMBOL_MAPPING_TABLE); |
||
1545 | cmd.Parameters.AddWithValue("@UID", item.Item1); |
||
1546 | cmd.Parameters.AddWithValue("@NAME", item.Item2); |
||
1547 | cmd.Parameters.AddWithValue("@SPPID_SYMBOL_PATH", item.Item3); |
||
1548 | cmd.Parameters.AddWithValue("@LEADERLINE", item.Item4); |
||
1549 | cmd.ExecuteNonQuery(); |
||
1550 | } |
||
1551 | 1421f1d6 | gaqhf | } |
1552 | 8847ea67 | gaqhf | transaction.Commit(); |
1553 | connection.Close(); |
||
1554 | } |
||
1555 | catch (Exception ex) |
||
1556 | { |
||
1557 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1558 | 8847ea67 | gaqhf | transaction.Rollback(); |
1559 | a2c803a0 | gaqhf | return false; |
1560 | 8847ea67 | gaqhf | } |
1561 | finally |
||
1562 | { |
||
1563 | transaction.Dispose(); |
||
1564 | 1421f1d6 | gaqhf | } |
1565 | bca86986 | gaqhf | } |
1566 | } |
||
1567 | 8847ea67 | gaqhf | catch (Exception ex) |
1568 | { |
||
1569 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1570 | 8847ea67 | gaqhf | return false; |
1571 | } |
||
1572 | finally |
||
1573 | { |
||
1574 | connection.Dispose(); |
||
1575 | } |
||
1576 | bca86986 | gaqhf | } |
1577 | 8847ea67 | gaqhf | } |
1578 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
1579 | { |
||
1580 | using (SqlConnection connection = GetSqlConnection()) |
||
1581 | bca86986 | gaqhf | { |
1582 | 8847ea67 | gaqhf | try |
1583 | { |
||
1584 | if (connection != null && connection.State == ConnectionState.Open) |
||
1585 | { |
||
1586 | a2c803a0 | gaqhf | using (SqlCommand cmd = connection.CreateCommand()) |
1587 | { |
||
1588 | foreach (var item in datas) |
||
1589 | { |
||
1590 | cmd.Parameters.Clear(); |
||
1591 | cmd.CommandText = string.Format(@" |
||
1592 | IF EXISTS (SELECT * FROM {0} WHERE UID = '{1}') |
||
1593 | UPDATE {0} SET NAME = @NAME, SPPID_SYMBOL_PATH = @SPPID_SYMBOL_PATH, LEADERLINE = @LEADERLINE WHERE UID = @UID |
||
1594 | ELSE |
||
1595 | INSERT INTO {0} (UID, NAME, SPPID_SYMBOL_PATH, LEADERLINE) VALUES (@UID, @NAME, @SPPID_SYMBOL_PATH, @LEADERLINE)", SPPID_SYMBOL_MAPPING_TABLE, item.Item1); |
||
1596 | cmd.Parameters.AddWithValue("@UID", item.Item1); |
||
1597 | f4485671 | gaqhf | if (string.IsNullOrEmpty(item.Item2)) |
1598 | cmd.Parameters.AddWithValue("@NAME", DBNull.Value); |
||
1599 | else |
||
1600 | cmd.Parameters.AddWithValue("@NAME", item.Item2); |
||
1601 | a2c803a0 | gaqhf | if (string.IsNullOrEmpty(item.Item3)) |
1602 | cmd.Parameters.AddWithValue("@SPPID_SYMBOL_PATH", DBNull.Value); |
||
1603 | else |
||
1604 | cmd.Parameters.AddWithValue("@SPPID_SYMBOL_PATH", item.Item3); |
||
1605 | cmd.Parameters.AddWithValue("@LEADERLINE", item.Item4); |
||
1606 | cmd.ExecuteNonQuery(); |
||
1607 | } |
||
1608 | } |
||
1609 | connection.Close(); |
||
1610 | 8847ea67 | gaqhf | } |
1611 | } |
||
1612 | catch (Exception ex) |
||
1613 | { |
||
1614 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1615 | a2c803a0 | gaqhf | return false; |
1616 | 8847ea67 | gaqhf | } |
1617 | finally |
||
1618 | { |
||
1619 | if (connection != null) |
||
1620 | connection.Dispose(); |
||
1621 | } |
||
1622 | bca86986 | gaqhf | } |
1623 | } |
||
1624 | |||
1625 | return true; |
||
1626 | } |
||
1627 | |||
1628 | 923501a9 | gaqhf | public static bool InsertAttributeMapping(List<Tuple<string, string, bool>> datas) |
1629 | bca86986 | gaqhf | { |
1630 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
1631 | 8847ea67 | gaqhf | if (projectInfo.DBType == ID2DB_Type.SQLite) |
1632 | bca86986 | gaqhf | { |
1633 | 8847ea67 | gaqhf | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
1634 | bca86986 | gaqhf | { |
1635 | 8847ea67 | gaqhf | try |
1636 | bca86986 | gaqhf | { |
1637 | 8847ea67 | gaqhf | connection.Open(); |
1638 | using (SQLiteTransaction transaction = connection.BeginTransaction()) |
||
1639 | 1421f1d6 | gaqhf | { |
1640 | 8847ea67 | gaqhf | try |
1641 | 1421f1d6 | gaqhf | { |
1642 | 8847ea67 | gaqhf | using (SQLiteCommand cmd = connection.CreateCommand()) |
1643 | 1421f1d6 | gaqhf | { |
1644 | 8847ea67 | gaqhf | foreach (var item in datas) |
1645 | { |
||
1646 | cmd.Parameters.Clear(); |
||
1647 | 923501a9 | gaqhf | cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, SPPID_ATTRIBUTE, ISTEXT) VALUES (@UID, @SPPID_ATTRIBUTE, @ISTEXT)", SPPID_ATTRIBUTE_MAPPING_TABLE); |
1648 | 8847ea67 | gaqhf | cmd.Parameters.AddWithValue("@UID", item.Item1); |
1649 | cmd.Parameters.AddWithValue("@SPPID_ATTRIBUTE", item.Item2); |
||
1650 | 923501a9 | gaqhf | cmd.Parameters.AddWithValue("@ISTEXT", item.Item3); |
1651 | 8847ea67 | gaqhf | cmd.ExecuteNonQuery(); |
1652 | } |
||
1653 | 1421f1d6 | gaqhf | } |
1654 | 8847ea67 | gaqhf | transaction.Commit(); |
1655 | connection.Close(); |
||
1656 | } |
||
1657 | catch (Exception ex) |
||
1658 | { |
||
1659 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1660 | 8847ea67 | gaqhf | transaction.Rollback(); |
1661 | } |
||
1662 | finally |
||
1663 | { |
||
1664 | transaction.Dispose(); |
||
1665 | 1421f1d6 | gaqhf | } |
1666 | bca86986 | gaqhf | } |
1667 | } |
||
1668 | 8847ea67 | gaqhf | catch (Exception ex) |
1669 | { |
||
1670 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1671 | 8847ea67 | gaqhf | return false; |
1672 | } |
||
1673 | finally |
||
1674 | { |
||
1675 | connection.Dispose(); |
||
1676 | } |
||
1677 | bca86986 | gaqhf | } |
1678 | 8847ea67 | gaqhf | } |
1679 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
1680 | { |
||
1681 | using (SqlConnection connection = GetSqlConnection()) |
||
1682 | bca86986 | gaqhf | { |
1683 | 8847ea67 | gaqhf | try |
1684 | { |
||
1685 | if (connection != null && connection.State == ConnectionState.Open) |
||
1686 | { |
||
1687 | f4485671 | gaqhf | using (SqlCommand cmd = connection.CreateCommand()) |
1688 | a2c803a0 | gaqhf | { |
1689 | f4485671 | gaqhf | foreach (var item in datas) |
1690 | a2c803a0 | gaqhf | { |
1691 | f4485671 | gaqhf | cmd.Parameters.Clear(); |
1692 | cmd.CommandText = string.Format(@" |
||
1693 | IF EXISTS (SELECT * FROM {0} WHERE UID = '{1}') |
||
1694 | 923501a9 | gaqhf | UPDATE {0} SET SPPID_ATTRIBUTE = @SPPID_ATTRIBUTE, ISTEXT = @ISTEXT WHERE UID = @UID |
1695 | f4485671 | gaqhf | ELSE |
1696 | 923501a9 | gaqhf | INSERT INTO {0} (UID, SPPID_ATTRIBUTE, ISTEXT) VALUES (@UID, @SPPID_ATTRIBUTE, @ISTEXT)", SPPID_ATTRIBUTE_MAPPING_TABLE, item.Item1); |
1697 | f4485671 | gaqhf | |
1698 | cmd.Parameters.AddWithValue("@UID", item.Item1); |
||
1699 | if (string.IsNullOrEmpty(item.Item2)) |
||
1700 | cmd.Parameters.AddWithValue("@SPPID_ATTRIBUTE", DBNull.Value); |
||
1701 | else |
||
1702 | a2c803a0 | gaqhf | cmd.Parameters.AddWithValue("@SPPID_ATTRIBUTE", item.Item2); |
1703 | 923501a9 | gaqhf | cmd.Parameters.AddWithValue("@ISTEXT", item.Item3); |
1704 | f4485671 | gaqhf | cmd.ExecuteNonQuery(); |
1705 | a2c803a0 | gaqhf | } |
1706 | } |
||
1707 | f4485671 | gaqhf | connection.Close(); |
1708 | 8847ea67 | gaqhf | } |
1709 | } |
||
1710 | catch (Exception ex) |
||
1711 | { |
||
1712 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1713 | a2c803a0 | gaqhf | return false; |
1714 | 8847ea67 | gaqhf | } |
1715 | finally |
||
1716 | { |
||
1717 | if (connection != null) |
||
1718 | connection.Dispose(); |
||
1719 | } |
||
1720 | bca86986 | gaqhf | } |
1721 | } |
||
1722 | return true; |
||
1723 | } |
||
1724 | 1a3a74a8 | gaqhf | |
1725 | cf924377 | gaqhf | public static bool InsertLabelInfoMapping(List<Tuple<string, int, bool>> datas) |
1726 | 1a3a74a8 | gaqhf | { |
1727 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
1728 | 8847ea67 | gaqhf | if (projectInfo.DBType == ID2DB_Type.SQLite) |
1729 | 1a3a74a8 | gaqhf | { |
1730 | 8847ea67 | gaqhf | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
1731 | 1a3a74a8 | gaqhf | { |
1732 | 8847ea67 | gaqhf | try |
1733 | 1a3a74a8 | gaqhf | { |
1734 | 8847ea67 | gaqhf | connection.Open(); |
1735 | using (SQLiteTransaction transaction = connection.BeginTransaction()) |
||
1736 | 1a3a74a8 | gaqhf | { |
1737 | 8847ea67 | gaqhf | try |
1738 | 1a3a74a8 | gaqhf | { |
1739 | 8847ea67 | gaqhf | using (SQLiteCommand cmd = connection.CreateCommand()) |
1740 | 1a3a74a8 | gaqhf | { |
1741 | 8847ea67 | gaqhf | foreach (var item in datas) |
1742 | { |
||
1743 | cmd.Parameters.Clear(); |
||
1744 | cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, LOCATION, LEADERLINE) VALUES (@UID, @LOCATION, @LEADERLINE)", SPPID_LABEL_INFO_TABLE); |
||
1745 | cmd.Parameters.AddWithValue("@UID", item.Item1); |
||
1746 | cmd.Parameters.AddWithValue("@LOCATION", item.Item2); |
||
1747 | cmd.Parameters.AddWithValue("@LEADERLINE", item.Item3); |
||
1748 | cmd.ExecuteNonQuery(); |
||
1749 | } |
||
1750 | 1a3a74a8 | gaqhf | } |
1751 | 8847ea67 | gaqhf | transaction.Commit(); |
1752 | connection.Close(); |
||
1753 | } |
||
1754 | catch (Exception ex) |
||
1755 | { |
||
1756 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1757 | 8847ea67 | gaqhf | transaction.Rollback(); |
1758 | a2c803a0 | gaqhf | return false; |
1759 | 8847ea67 | gaqhf | } |
1760 | finally |
||
1761 | { |
||
1762 | transaction.Dispose(); |
||
1763 | 1a3a74a8 | gaqhf | } |
1764 | } |
||
1765 | } |
||
1766 | 8847ea67 | gaqhf | catch (Exception ex) |
1767 | { |
||
1768 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1769 | 8847ea67 | gaqhf | return false; |
1770 | } |
||
1771 | finally |
||
1772 | { |
||
1773 | connection.Dispose(); |
||
1774 | } |
||
1775 | 1a3a74a8 | gaqhf | } |
1776 | 8847ea67 | gaqhf | } |
1777 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
1778 | { |
||
1779 | using (SqlConnection connection = GetSqlConnection()) |
||
1780 | 1a3a74a8 | gaqhf | { |
1781 | 8847ea67 | gaqhf | try |
1782 | { |
||
1783 | if (connection != null && connection.State == ConnectionState.Open) |
||
1784 | { |
||
1785 | a2c803a0 | gaqhf | using (SqlCommand cmd = connection.CreateCommand()) |
1786 | { |
||
1787 | foreach (var item in datas) |
||
1788 | { |
||
1789 | cmd.Parameters.Clear(); |
||
1790 | f4485671 | gaqhf | cmd.CommandText = string.Format(@" |
1791 | IF EXISTS (SELECT * FROM {0} WHERE UID = '{1}') |
||
1792 | UPDATE {0} SET LOCATION = @LOCATION, LEADERLINE = @LEADERLINE WHERE UID = @UID |
||
1793 | ELSE |
||
1794 | INSERT INTO {0} (UID, LOCATION, LEADERLINE) VALUES (@UID, @LOCATION, @LEADERLINE)", SPPID_LABEL_INFO_TABLE, item.Item1); |
||
1795 | |||
1796 | a2c803a0 | gaqhf | cmd.Parameters.AddWithValue("@UID", item.Item1); |
1797 | cmd.Parameters.AddWithValue("@LOCATION", item.Item2); |
||
1798 | cmd.Parameters.AddWithValue("@LEADERLINE", item.Item3); |
||
1799 | cmd.ExecuteNonQuery(); |
||
1800 | } |
||
1801 | } |
||
1802 | connection.Close(); |
||
1803 | 8847ea67 | gaqhf | } |
1804 | } |
||
1805 | catch (Exception ex) |
||
1806 | { |
||
1807 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1808 | a2c803a0 | gaqhf | return false; |
1809 | 8847ea67 | gaqhf | } |
1810 | finally |
||
1811 | { |
||
1812 | if (connection != null) |
||
1813 | connection.Dispose(); |
||
1814 | } |
||
1815 | 1a3a74a8 | gaqhf | } |
1816 | } |
||
1817 | return true; |
||
1818 | } |
||
1819 | 69b7387a | gaqhf | |
1820 | 154d8f43 | gaqhf | public static bool InsertDrawingInfoAndOPCInfo(string path, string drawingNumber, string drawingName, SPPID.Model.SPPID_Document document) |
1821 | 69b7387a | gaqhf | { |
1822 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
1823 | 8847ea67 | gaqhf | if (projectInfo.DBType == ID2DB_Type.SQLite) |
1824 | 69b7387a | gaqhf | { |
1825 | 8847ea67 | gaqhf | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
1826 | 69b7387a | gaqhf | { |
1827 | 8847ea67 | gaqhf | try |
1828 | 69b7387a | gaqhf | { |
1829 | 8847ea67 | gaqhf | connection.Open(); |
1830 | using (SQLiteTransaction transaction = connection.BeginTransaction()) |
||
1831 | 69b7387a | gaqhf | { |
1832 | 8847ea67 | gaqhf | try |
1833 | 154d8f43 | gaqhf | { |
1834 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
1835 | { |
||
1836 | 8847ea67 | gaqhf | cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (ID2_DRAWING_UID, PATH, DRAWINGNUMBER, DRAWINGNAME) VALUES (@ID2_DRAWING_UID, @PATH, @DRAWINGNUMBER, @DRAWINGNAME)", SPPID_DRAWING_INFO); |
1837 | 154d8f43 | gaqhf | cmd.Parameters.AddWithValue("@ID2_DRAWING_UID", document.UID); |
1838 | 8847ea67 | gaqhf | cmd.Parameters.AddWithValue("@PATH", path); |
1839 | cmd.Parameters.AddWithValue("@DRAWINGNUMBER", drawingNumber); |
||
1840 | cmd.Parameters.AddWithValue("@DRAWINGNAME", drawingName); |
||
1841 | 154d8f43 | gaqhf | cmd.ExecuteNonQuery(); |
1842 | } |
||
1843 | |||
1844 | 8847ea67 | gaqhf | List<Symbol> OPCs = document.SYMBOLS.FindAll(x => x.TYPE == "Piping OPC's" || x.TYPE == "Instrument OPC's"); |
1845 | foreach (var item in OPCs) |
||
1846 | { |
||
1847 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
1848 | { |
||
1849 | cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (ID2_OPC_UID, SPPID_OPC_MODELITEM_ID, ID2_DRAWING_UID, ATTRIBUTES, PAIRED) VALUES (@ID2_OPC_UID, @SPPID_OPC_MODELITEM_ID, @ID2_DRAWING_UID, @ATTRIBUTES, @PAIRED)", SPPID_OPC_INFO); |
||
1850 | cmd.Parameters.AddWithValue("@ID2_OPC_UID", item.UID); |
||
1851 | cmd.Parameters.AddWithValue("@SPPID_OPC_MODELITEM_ID", item.SPPID.ModelItemID); |
||
1852 | cmd.Parameters.AddWithValue("@ID2_DRAWING_UID", document.UID); |
||
1853 | cmd.Parameters.AddWithValue("@ATTRIBUTES", JsonConvert.SerializeObject(item.SPPID.Attributes)); |
||
1854 | cmd.Parameters.AddWithValue("@PAIRED", false); |
||
1855 | cmd.ExecuteNonQuery(); |
||
1856 | } |
||
1857 | } |
||
1858 | |||
1859 | transaction.Commit(); |
||
1860 | connection.Close(); |
||
1861 | } |
||
1862 | catch (Exception ex) |
||
1863 | { |
||
1864 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1865 | 8847ea67 | gaqhf | transaction.Rollback(); |
1866 | a2c803a0 | gaqhf | return false; |
1867 | 8847ea67 | gaqhf | } |
1868 | finally |
||
1869 | { |
||
1870 | transaction.Dispose(); |
||
1871 | } |
||
1872 | 154d8f43 | gaqhf | } |
1873 | } |
||
1874 | 8847ea67 | gaqhf | catch (Exception ex) |
1875 | { |
||
1876 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1877 | 8847ea67 | gaqhf | return false; |
1878 | } |
||
1879 | finally |
||
1880 | { |
||
1881 | connection.Dispose(); |
||
1882 | } |
||
1883 | 154d8f43 | gaqhf | } |
1884 | 8847ea67 | gaqhf | } |
1885 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
1886 | { |
||
1887 | using (SqlConnection connection = GetSqlConnection()) |
||
1888 | 154d8f43 | gaqhf | { |
1889 | 8847ea67 | gaqhf | try |
1890 | { |
||
1891 | if (connection != null && connection.State == ConnectionState.Open) |
||
1892 | { |
||
1893 | a2c803a0 | gaqhf | using (SqlCommand cmd = connection.CreateCommand()) |
1894 | { |
||
1895 | 2425d530 | gaqhf | cmd.Parameters.Clear(); |
1896 | cmd.CommandText = string.Format(@" |
||
1897 | fb2d9638 | gaqhf | IF EXISTS (SELECT * FROM {0} WHERE ID2_DRAWING_UID = '{1}') |
1898 | 2425d530 | gaqhf | UPDATE {0} SET PATH = @PATH, DRAWINGNUMBER = @DRAWINGNUMBER, DRAWINGNAME = @DRAWINGNAME WHERE ID2_DRAWING_UID = @ID2_DRAWING_UID |
1899 | ELSE |
||
1900 | INSERT INTO {0} (ID2_DRAWING_UID, PATH, DRAWINGNUMBER, DRAWINGNAME) VALUES (@ID2_DRAWING_UID, @PATH, @DRAWINGNUMBER, @DRAWINGNAME)", SPPID_DRAWING_INFO, document.UID); |
||
1901 | |||
1902 | a2c803a0 | gaqhf | cmd.Parameters.AddWithValue("@ID2_DRAWING_UID", document.UID); |
1903 | cmd.Parameters.AddWithValue("@PATH", path); |
||
1904 | cmd.Parameters.AddWithValue("@DRAWINGNUMBER", drawingNumber); |
||
1905 | cmd.Parameters.AddWithValue("@DRAWINGNAME", drawingName); |
||
1906 | cmd.ExecuteNonQuery(); |
||
1907 | } |
||
1908 | 8847ea67 | gaqhf | |
1909 | a2c803a0 | gaqhf | List<Symbol> OPCs = document.SYMBOLS.FindAll(x => x.TYPE == "Piping OPC's" || x.TYPE == "Instrument OPC's"); |
1910 | foreach (var item in OPCs) |
||
1911 | { |
||
1912 | using (SqlCommand cmd = connection.CreateCommand()) |
||
1913 | { |
||
1914 | 2425d530 | gaqhf | cmd.Parameters.Clear(); |
1915 | cmd.CommandText = string.Format(@" |
||
1916 | c5bc0767 | gaqhf | IF EXISTS (SELECT * FROM {0} WHERE ID2_OPC_UID = '{1}') |
1917 | 2425d530 | gaqhf | UPDATE {0} SET SPPID_OPC_MODELITEM_ID = @SPPID_OPC_MODELITEM_ID, ID2_DRAWING_UID = @ID2_DRAWING_UID, ATTRIBUTES = @ATTRIBUTES, PAIRED = @PAIRED WHERE ID2_OPC_UID = @ID2_OPC_UID |
1918 | ELSE |
||
1919 | INSERT INTO {0} (ID2_OPC_UID, SPPID_OPC_MODELITEM_ID, ID2_DRAWING_UID, ATTRIBUTES, PAIRED) VALUES (@ID2_OPC_UID, @SPPID_OPC_MODELITEM_ID, @ID2_DRAWING_UID, @ATTRIBUTES, @PAIRED)", SPPID_OPC_INFO, item.UID); |
||
1920 | |||
1921 | a2c803a0 | gaqhf | cmd.Parameters.AddWithValue("@ID2_OPC_UID", item.UID); |
1922 | 2425d530 | gaqhf | if (string.IsNullOrEmpty(item.SPPID.ModelItemID)) |
1923 | cmd.Parameters.AddWithValue("@SPPID_OPC_MODELITEM_ID", DBNull.Value); |
||
1924 | else |
||
1925 | cmd.Parameters.AddWithValue("@SPPID_OPC_MODELITEM_ID", item.SPPID.ModelItemID); |
||
1926 | a2c803a0 | gaqhf | cmd.Parameters.AddWithValue("@ID2_DRAWING_UID", document.UID); |
1927 | cmd.Parameters.AddWithValue("@ATTRIBUTES", JsonConvert.SerializeObject(item.SPPID.Attributes)); |
||
1928 | cmd.Parameters.AddWithValue("@PAIRED", false); |
||
1929 | cmd.ExecuteNonQuery(); |
||
1930 | } |
||
1931 | } |
||
1932 | connection.Close(); |
||
1933 | 8847ea67 | gaqhf | } |
1934 | } |
||
1935 | catch (Exception ex) |
||
1936 | { |
||
1937 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1938 | a2c803a0 | gaqhf | return false; |
1939 | 8847ea67 | gaqhf | } |
1940 | finally |
||
1941 | { |
||
1942 | if (connection != null) |
||
1943 | connection.Dispose(); |
||
1944 | } |
||
1945 | 154d8f43 | gaqhf | } |
1946 | } |
||
1947 | return true; |
||
1948 | } |
||
1949 | |||
1950 | public static bool InsertOPCInfo(string UID, string ModelItemID, string drawingUID, bool Paired) |
||
1951 | { |
||
1952 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
1953 | 8847ea67 | gaqhf | if (projectInfo.DBType == ID2DB_Type.SQLite) |
1954 | 154d8f43 | gaqhf | { |
1955 | 8847ea67 | gaqhf | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
1956 | 154d8f43 | gaqhf | { |
1957 | 8847ea67 | gaqhf | try |
1958 | 154d8f43 | gaqhf | { |
1959 | 8847ea67 | gaqhf | connection.Open(); |
1960 | using (SQLiteTransaction transaction = connection.BeginTransaction()) |
||
1961 | 154d8f43 | gaqhf | { |
1962 | 8847ea67 | gaqhf | try |
1963 | 154d8f43 | gaqhf | { |
1964 | 8847ea67 | gaqhf | using (SQLiteCommand cmd = connection.CreateCommand()) |
1965 | { |
||
1966 | cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (ID2_OPC_UID, SPPID_OPC_MODELITEM_ID, ID2_DRAWING_UID, PAIRED) VALUES (@ID2_OPC_UID, @SPPID_OPC_MODELITEM_ID, @ID2_DRAWING_UID, @PAIRED)", SPPID_OPC_INFO); |
||
1967 | cmd.Parameters.AddWithValue("@ID2_OPC_UID", UID); |
||
1968 | cmd.Parameters.AddWithValue("@SPPID_OPC_MODELITEM_ID", ModelItemID); |
||
1969 | cmd.Parameters.AddWithValue("@ID2_DRAWING_UID", drawingUID); |
||
1970 | cmd.Parameters.AddWithValue("@PAIRED", Paired); |
||
1971 | cmd.ExecuteNonQuery(); |
||
1972 | } |
||
1973 | 154d8f43 | gaqhf | |
1974 | 8847ea67 | gaqhf | transaction.Commit(); |
1975 | connection.Close(); |
||
1976 | } |
||
1977 | catch (Exception ex) |
||
1978 | { |
||
1979 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1980 | 8847ea67 | gaqhf | transaction.Rollback(); |
1981 | a2c803a0 | gaqhf | return false; |
1982 | 8847ea67 | gaqhf | } |
1983 | finally |
||
1984 | { |
||
1985 | transaction.Dispose(); |
||
1986 | } |
||
1987 | 69b7387a | gaqhf | } |
1988 | } |
||
1989 | 8847ea67 | gaqhf | catch (Exception ex) |
1990 | { |
||
1991 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
1992 | 8847ea67 | gaqhf | return false; |
1993 | } |
||
1994 | finally |
||
1995 | { |
||
1996 | connection.Dispose(); |
||
1997 | } |
||
1998 | 69b7387a | gaqhf | } |
1999 | 8847ea67 | gaqhf | } |
2000 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
2001 | { |
||
2002 | using (SqlConnection connection = GetSqlConnection()) |
||
2003 | 69b7387a | gaqhf | { |
2004 | 8847ea67 | gaqhf | try |
2005 | { |
||
2006 | if (connection != null && connection.State == ConnectionState.Open) |
||
2007 | { |
||
2008 | a2c803a0 | gaqhf | using (SqlCommand cmd = connection.CreateCommand()) |
2009 | { |
||
2010 | 2425d530 | gaqhf | cmd.Parameters.Clear(); |
2011 | cmd.CommandText = string.Format(@" |
||
2012 | UPDATE {0} SET SPPID_OPC_MODELITEM_ID = @SPPID_OPC_MODELITEM_ID, ID2_DRAWING_UID = @ID2_DRAWING_UID, PAIRED = @PAIRED WHERE ID2_OPC_UID = @ID2_OPC_UID", SPPID_OPC_INFO); |
||
2013 | a2c803a0 | gaqhf | cmd.Parameters.AddWithValue("@ID2_OPC_UID", UID); |
2014 | 2425d530 | gaqhf | if (string.IsNullOrEmpty(ModelItemID)) |
2015 | cmd.Parameters.AddWithValue("@SPPID_OPC_MODELITEM_ID", DBNull.Value); |
||
2016 | else |
||
2017 | cmd.Parameters.AddWithValue("@SPPID_OPC_MODELITEM_ID", ModelItemID); |
||
2018 | a2c803a0 | gaqhf | cmd.Parameters.AddWithValue("@ID2_DRAWING_UID", drawingUID); |
2019 | cmd.Parameters.AddWithValue("@PAIRED", Paired); |
||
2020 | cmd.ExecuteNonQuery(); |
||
2021 | } |
||
2022 | connection.Close(); |
||
2023 | 8847ea67 | gaqhf | } |
2024 | } |
||
2025 | catch (Exception ex) |
||
2026 | { |
||
2027 | 2425d530 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
2028 | a2c803a0 | gaqhf | return false; |
2029 | 8847ea67 | gaqhf | } |
2030 | finally |
||
2031 | { |
||
2032 | if (connection != null) |
||
2033 | connection.Dispose(); |
||
2034 | } |
||
2035 | 69b7387a | gaqhf | } |
2036 | } |
||
2037 | return true; |
||
2038 | } |
||
2039 | 2425d530 | gaqhf | |
2040 | public static bool ExportMappingData() |
||
2041 | { |
||
2042 | bool result = true; |
||
2043 | try |
||
2044 | { |
||
2045 | DataSet dataSet = new DataSet(); |
||
2046 | DataTable symbolMappingDT = GetTable(SPPID_SYMBOL_MAPPING_TABLE); |
||
2047 | if (symbolMappingDT != null) |
||
2048 | { |
||
2049 | symbolMappingDT.TableName = SPPID_SYMBOL_MAPPING_TABLE; |
||
2050 | dataSet.Tables.Add(symbolMappingDT); |
||
2051 | } |
||
2052 | else |
||
2053 | result = false; |
||
2054 | |||
2055 | DataTable attributeMappingDT = GetTable(SPPID_ATTRIBUTE_MAPPING_TABLE); |
||
2056 | if (attributeMappingDT != null) |
||
2057 | { |
||
2058 | attributeMappingDT.TableName = SPPID_ATTRIBUTE_MAPPING_TABLE; |
||
2059 | dataSet.Tables.Add(attributeMappingDT); |
||
2060 | } |
||
2061 | else |
||
2062 | result = false; |
||
2063 | |||
2064 | if (result) |
||
2065 | { |
||
2066 | string text = JsonConvert.SerializeObject(dataSet); |
||
2067 | using (StreamWriter sw = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\ExportFile.mapf", false)) |
||
2068 | { |
||
2069 | sw.Write(text); |
||
2070 | sw.Close(); |
||
2071 | sw.Dispose(); |
||
2072 | } |
||
2073 | } |
||
2074 | } |
||
2075 | catch (Exception ex) |
||
2076 | { |
||
2077 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
2078 | result = false; |
||
2079 | } |
||
2080 | |||
2081 | return result; |
||
2082 | } |
||
2083 | |||
2084 | public static bool ImportMappingData() |
||
2085 | { |
||
2086 | bool result = true; |
||
2087 | try |
||
2088 | { |
||
2089 | string sJson = string.Empty; |
||
2090 | using (StreamReader sw = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\ExportFile.mapf")) |
||
2091 | { |
||
2092 | sJson = sw.ReadToEnd(); |
||
2093 | sw.Close(); |
||
2094 | sw.Dispose(); |
||
2095 | } |
||
2096 | |||
2097 | DataSet dataSet = JsonConvert.DeserializeObject<DataSet>(sJson); |
||
2098 | DataTable symbolMappingDT = dataSet.Tables[SPPID_SYMBOL_MAPPING_TABLE]; |
||
2099 | if (symbolMappingDT == null || !ImportSymbolMappingTable(symbolMappingDT)) |
||
2100 | result = false; |
||
2101 | |||
2102 | DataTable attributeMappingDT = dataSet.Tables[SPPID_ATTRIBUTE_MAPPING_TABLE]; |
||
2103 | if (attributeMappingDT == null || !ImportAttributeMappingTable(attributeMappingDT)) |
||
2104 | result = false; |
||
2105 | } |
||
2106 | catch (Exception ex) |
||
2107 | { |
||
2108 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
2109 | result = false; |
||
2110 | } |
||
2111 | |||
2112 | return result; |
||
2113 | } |
||
2114 | |||
2115 | private static DataTable GetTable(string tableName) |
||
2116 | { |
||
2117 | DataTable dt = new DataTable(); |
||
2118 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
2119 | if (projectInfo.DBType == ID2DB_Type.SQLite) |
||
2120 | { |
||
2121 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
||
2122 | { |
||
2123 | try |
||
2124 | { |
||
2125 | connection.Open(); |
||
2126 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
2127 | { |
||
2128 | cmd.CommandText = string.Format("SELECT * FROM {0}", tableName); |
||
2129 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
2130 | dt.Load(dr); |
||
2131 | } |
||
2132 | connection.Close(); |
||
2133 | } |
||
2134 | catch (Exception ex) |
||
2135 | { |
||
2136 | dt = null; |
||
2137 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
2138 | } |
||
2139 | finally |
||
2140 | { |
||
2141 | connection.Dispose(); |
||
2142 | } |
||
2143 | } |
||
2144 | } |
||
2145 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
2146 | { |
||
2147 | using (SqlConnection connection = GetSqlConnection()) |
||
2148 | { |
||
2149 | try |
||
2150 | { |
||
2151 | if (connection != null && connection.State == ConnectionState.Open) |
||
2152 | { |
||
2153 | using (SqlCommand cmd = connection.CreateCommand()) |
||
2154 | { |
||
2155 | cmd.CommandText = string.Format("SELECT * FROM {0}", tableName); |
||
2156 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
2157 | dt.Load(dr); |
||
2158 | } |
||
2159 | connection.Close(); |
||
2160 | } |
||
2161 | } |
||
2162 | catch (Exception ex) |
||
2163 | { |
||
2164 | dt = null; |
||
2165 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
2166 | } |
||
2167 | finally |
||
2168 | { |
||
2169 | if (connection != null) |
||
2170 | connection.Dispose(); |
||
2171 | } |
||
2172 | } |
||
2173 | } |
||
2174 | |||
2175 | return dt; |
||
2176 | } |
||
2177 | |||
2178 | private static bool ImportSymbolMappingTable(DataTable dt) |
||
2179 | { |
||
2180 | bool result = false; |
||
2181 | |||
2182 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
2183 | if (projectInfo.DBType == ID2DB_Type.SQLite) |
||
2184 | { |
||
2185 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
||
2186 | { |
||
2187 | try |
||
2188 | { |
||
2189 | connection.Open(); |
||
2190 | using (SQLiteTransaction transaction = connection.BeginTransaction()) |
||
2191 | { |
||
2192 | try |
||
2193 | { |
||
2194 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
2195 | { |
||
2196 | foreach (DataRow item in dt.Rows) |
||
2197 | { |
||
2198 | string UID = DBNull.Value.Equals(item["UID"]) ? null : (string)item["UID"]; |
||
2199 | string NAME = DBNull.Value.Equals(item["NAME"]) ? null : (string)item["NAME"]; |
||
2200 | string SPPID_SYMBOL_PATH = DBNull.Value.Equals(item["SPPID_SYMBOL_PATH"]) ? null : (string)item["SPPID_SYMBOL_PATH"]; |
||
2201 | bool LEADERLINE = Convert.ToBoolean(item["LEADERLINE"]); |
||
2202 | |||
2203 | cmd.Parameters.Clear(); |
||
2204 | cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, NAME, SPPID_SYMBOL_PATH, LEADERLINE) VALUES (@UID, @NAME, @SPPID_SYMBOL_PATH, @LEADERLINE)", SPPID_SYMBOL_MAPPING_TABLE); |
||
2205 | cmd.Parameters.AddWithValue("@UID", UID); |
||
2206 | cmd.Parameters.AddWithValue("@NAME", NAME); |
||
2207 | cmd.Parameters.AddWithValue("@SPPID_SYMBOL_PATH", SPPID_SYMBOL_PATH); |
||
2208 | cmd.Parameters.AddWithValue("@LEADERLINE", LEADERLINE); |
||
2209 | cmd.ExecuteNonQuery(); |
||
2210 | } |
||
2211 | } |
||
2212 | transaction.Commit(); |
||
2213 | connection.Close(); |
||
2214 | result = true; |
||
2215 | } |
||
2216 | catch (Exception ex) |
||
2217 | { |
||
2218 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
2219 | transaction.Rollback(); |
||
2220 | } |
||
2221 | finally |
||
2222 | { |
||
2223 | transaction.Dispose(); |
||
2224 | } |
||
2225 | } |
||
2226 | } |
||
2227 | catch (Exception ex) |
||
2228 | { |
||
2229 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
2230 | } |
||
2231 | finally |
||
2232 | { |
||
2233 | connection.Dispose(); |
||
2234 | } |
||
2235 | } |
||
2236 | } |
||
2237 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
2238 | { |
||
2239 | using (SqlConnection connection = GetSqlConnection()) |
||
2240 | { |
||
2241 | try |
||
2242 | { |
||
2243 | if (connection != null && connection.State == ConnectionState.Open) |
||
2244 | { |
||
2245 | using (SqlCommand cmd = connection.CreateCommand()) |
||
2246 | { |
||
2247 | foreach (DataRow item in dt.Rows) |
||
2248 | { |
||
2249 | string UID = DBNull.Value.Equals(item["UID"]) ? null : (string)item["UID"]; |
||
2250 | string NAME = DBNull.Value.Equals(item["NAME"]) ? null : (string)item["NAME"]; |
||
2251 | string SPPID_SYMBOL_PATH = DBNull.Value.Equals(item["SPPID_SYMBOL_PATH"]) ? null : (string)item["SPPID_SYMBOL_PATH"]; |
||
2252 | bool LEADERLINE = DBNull.Value.Equals(item["LEADERLINE"]) ? false : Convert.ToBoolean(item["LEADERLINE"]); |
||
2253 | |||
2254 | cmd.Parameters.Clear(); |
||
2255 | cmd.CommandText = string.Format(@" |
||
2256 | IF EXISTS (SELECT * FROM {0} WHERE UID = '{1}') |
||
2257 | UPDATE {0} SET NAME = @NAME, SPPID_SYMBOL_PATH = @SPPID_SYMBOL_PATH, LEADERLINE = @LEADERLINE WHERE UID = @UID |
||
2258 | ELSE |
||
2259 | INSERT INTO {0} (UID, NAME, SPPID_SYMBOL_PATH, LEADERLINE) VALUES (@UID, @NAME, @SPPID_SYMBOL_PATH, @LEADERLINE)", SPPID_SYMBOL_MAPPING_TABLE, UID); |
||
2260 | cmd.Parameters.AddWithValue("@UID", UID); |
||
2261 | if (string.IsNullOrEmpty(NAME)) |
||
2262 | cmd.Parameters.AddWithValue("@NAME", DBNull.Value); |
||
2263 | else |
||
2264 | cmd.Parameters.AddWithValue("@NAME", NAME); |
||
2265 | if (string.IsNullOrEmpty(SPPID_SYMBOL_PATH)) |
||
2266 | cmd.Parameters.AddWithValue("@SPPID_SYMBOL_PATH", DBNull.Value); |
||
2267 | else |
||
2268 | cmd.Parameters.AddWithValue("@SPPID_SYMBOL_PATH", SPPID_SYMBOL_PATH); |
||
2269 | cmd.Parameters.AddWithValue("@LEADERLINE", LEADERLINE); |
||
2270 | cmd.ExecuteNonQuery(); |
||
2271 | } |
||
2272 | } |
||
2273 | connection.Close(); |
||
2274 | result = true; |
||
2275 | } |
||
2276 | } |
||
2277 | catch (Exception ex) |
||
2278 | { |
||
2279 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
2280 | } |
||
2281 | finally |
||
2282 | { |
||
2283 | if (connection != null) |
||
2284 | connection.Dispose(); |
||
2285 | } |
||
2286 | } |
||
2287 | } |
||
2288 | |||
2289 | return result; |
||
2290 | } |
||
2291 | |||
2292 | private static bool ImportAttributeMappingTable(DataTable dt) |
||
2293 | { |
||
2294 | bool result = false; |
||
2295 | |||
2296 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
2297 | if (projectInfo.DBType == ID2DB_Type.SQLite) |
||
2298 | { |
||
2299 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
||
2300 | { |
||
2301 | try |
||
2302 | { |
||
2303 | connection.Open(); |
||
2304 | using (SQLiteTransaction transaction = connection.BeginTransaction()) |
||
2305 | { |
||
2306 | try |
||
2307 | { |
||
2308 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
2309 | { |
||
2310 | foreach (DataRow item in dt.Rows) |
||
2311 | { |
||
2312 | string UID = DBNull.Value.Equals(item["UID"]) ? null : (string)item["UID"]; |
||
2313 | string SPPID_ATTRIBUTE = DBNull.Value.Equals(item["SPPID_ATTRIBUTE"]) ? null : (string)item["SPPID_ATTRIBUTE"]; |
||
2314 | |||
2315 | cmd.Parameters.Clear(); |
||
2316 | cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, SPPID_ATTRIBUTE) VALUES (@UID, @SPPID_ATTRIBUTE)", SPPID_ATTRIBUTE_MAPPING_TABLE); |
||
2317 | cmd.Parameters.AddWithValue("@UID", UID); |
||
2318 | cmd.Parameters.AddWithValue("@SPPID_ATTRIBUTE", SPPID_ATTRIBUTE); |
||
2319 | cmd.ExecuteNonQuery(); |
||
2320 | } |
||
2321 | } |
||
2322 | transaction.Commit(); |
||
2323 | connection.Close(); |
||
2324 | result = true; |
||
2325 | } |
||
2326 | catch (Exception ex) |
||
2327 | { |
||
2328 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
2329 | transaction.Rollback(); |
||
2330 | } |
||
2331 | finally |
||
2332 | { |
||
2333 | transaction.Dispose(); |
||
2334 | } |
||
2335 | } |
||
2336 | } |
||
2337 | catch (Exception ex) |
||
2338 | { |
||
2339 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
2340 | } |
||
2341 | finally |
||
2342 | { |
||
2343 | connection.Dispose(); |
||
2344 | } |
||
2345 | } |
||
2346 | } |
||
2347 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
2348 | { |
||
2349 | using (SqlConnection connection = GetSqlConnection()) |
||
2350 | { |
||
2351 | try |
||
2352 | { |
||
2353 | if (connection != null && connection.State == ConnectionState.Open) |
||
2354 | { |
||
2355 | using (SqlCommand cmd = connection.CreateCommand()) |
||
2356 | { |
||
2357 | foreach (DataRow item in dt.Rows) |
||
2358 | { |
||
2359 | string UID = DBNull.Value.Equals(item["UID"]) ? null : (string)item["UID"]; |
||
2360 | string SPPID_ATTRIBUTE = DBNull.Value.Equals(item["SPPID_ATTRIBUTE"]) ? null : (string)item["SPPID_ATTRIBUTE"]; |
||
2361 | |||
2362 | cmd.Parameters.Clear(); |
||
2363 | cmd.CommandText = string.Format(@" |
||
2364 | IF EXISTS (SELECT * FROM {0} WHERE UID = '{1}') |
||
2365 | UPDATE {0} SET SPPID_ATTRIBUTE = @SPPID_ATTRIBUTE WHERE UID = @UID |
||
2366 | ELSE |
||
2367 | INSERT INTO {0} (UID, SPPID_ATTRIBUTE) VALUES (@UID, @SPPID_ATTRIBUTE)", SPPID_ATTRIBUTE_MAPPING_TABLE, UID); |
||
2368 | |||
2369 | cmd.Parameters.AddWithValue("@UID", UID); |
||
2370 | if (string.IsNullOrEmpty(SPPID_ATTRIBUTE)) |
||
2371 | cmd.Parameters.AddWithValue("@SPPID_ATTRIBUTE", DBNull.Value); |
||
2372 | else |
||
2373 | cmd.Parameters.AddWithValue("@SPPID_ATTRIBUTE", SPPID_ATTRIBUTE); |
||
2374 | cmd.ExecuteNonQuery(); |
||
2375 | } |
||
2376 | } |
||
2377 | connection.Close(); |
||
2378 | result = true; |
||
2379 | } |
||
2380 | } |
||
2381 | catch (Exception ex) |
||
2382 | { |
||
2383 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
2384 | } |
||
2385 | finally |
||
2386 | { |
||
2387 | if (connection != null) |
||
2388 | connection.Dispose(); |
||
2389 | } |
||
2390 | } |
||
2391 | } |
||
2392 | |||
2393 | |||
2394 | |||
2395 | return result; |
||
2396 | } |
||
2397 | b18dc619 | gaqhf | } |
2398 | } |