hytos / DTI_PID / APIDConverter / DB / Project_DB.cs @ 4622d687
이력 | 보기 | 이력해설 | 다운로드 (59.9 KB)
1 | 53a4ebb8 | gaqhf | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.Linq; |
||
4 | using System.Text; |
||
5 | using System.Threading.Tasks; |
||
6 | using System.Globalization; |
||
7 | using System.Data.SQLite; |
||
8 | using System.Data; |
||
9 | using System.Data.SqlClient; |
||
10 | using System.IO; |
||
11 | using Newtonsoft.Json; |
||
12 | using AVEVA.PID.CustomizationUtility; |
||
13 | using AVEVA.PID.CustomizationUtility.Model; |
||
14 | |||
15 | namespace AVEVA.PID.CustomizationUtility.DB |
||
16 | { |
||
17 | public class Project_DB |
||
18 | { |
||
19 | a77303ca | gaqhf | const string APID_SYMBOL_MAPPING_TABLE = "T_APID_SYMBOL_MAPPING"; |
20 | a03cde1e | gaqhf | const string APID_OPC_MAPPING_TABLE = "T_APID_OPC_MAPPING"; |
21 | 7a56b228 | gaqhf | const string APID_ATTRIBUTE_MAPPING_TABLE = "T_APID_ATTRIBUTE_MAPPING"; |
22 | 53a4ebb8 | gaqhf | |
23 | const string LineProperties_TABLE = "LineProperties"; |
||
24 | const string LineTypes_TABLE = "LineTypes"; |
||
25 | const string SymbolType_TABLE = "SymbolType"; |
||
26 | const string SymbolAttribute_TABLE = "SymbolAttribute"; |
||
27 | const string Symbol_TABLE = "Symbol"; |
||
28 | const string OPCRelations_TABLE = "OPCRelations"; |
||
29 | |||
30 | 9ee9b61d | gaqhf | #region Only ID2 DB |
31 | 53a4ebb8 | gaqhf | private static SqlConnection GetSqlConnection() |
32 | { |
||
33 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
34 | SqlConnection connection = null; |
||
35 | try |
||
36 | { |
||
37 | connection = new SqlConnection(string.Format(CultureInfo.CurrentCulture, |
||
38 | @"Data Source = {0},{1}; Initial CataLog = {2}; User ID = {3}; Password = {4};", |
||
39 | projectInfo.ServerIP, |
||
40 | projectInfo.Port, |
||
41 | System.IO.Path.GetFileName(projectInfo.DefaultPath), |
||
42 | projectInfo.DBUser, |
||
43 | projectInfo.DBPassword)); |
||
44 | |||
45 | connection.Open(); |
||
46 | } |
||
47 | catch (Exception ex) |
||
48 | { |
||
49 | 465c8b6e | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
50 | 53a4ebb8 | gaqhf | if (connection != null) |
51 | connection.Dispose(); |
||
52 | connection = null; |
||
53 | } |
||
54 | |||
55 | return connection; |
||
56 | } |
||
57 | public static bool ConnTestAndCreateTable() |
||
58 | { |
||
59 | bool result = false; |
||
60 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
61 | if (projectInfo.DBType == ID2DB_Type.SQLite) |
||
62 | { |
||
63 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, @"Data Source = {0}", projectInfo.DBFilePath))) |
||
64 | { |
||
65 | try |
||
66 | { |
||
67 | connection.Open(); |
||
68 | if (connection.State == ConnectionState.Open) |
||
69 | { |
||
70 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
71 | { |
||
72 | a77303ca | gaqhf | cmd.CommandText = "SELECT NAME FROM sqlite_master WHERE type='table'"; |
73 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
74 | using (DataTable dt = new DataTable()) |
||
75 | { |
||
76 | dt.Load(dr); |
||
77 | |||
78 | if (dt.Select(string.Format("NAME = '{0}'", APID_SYMBOL_MAPPING_TABLE)).Length == 0) |
||
79 | { |
||
80 | 9dab7146 | gaqhf | cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, NAME TEXT, APID_SYMBOL TEXT, DATA1 TEXT)", APID_SYMBOL_MAPPING_TABLE); |
81 | a77303ca | gaqhf | cmd.ExecuteNonQuery(); |
82 | } |
||
83 | a03cde1e | gaqhf | if (dt.Select(string.Format("NAME = '{0}'", APID_OPC_MAPPING_TABLE)).Length == 0) |
84 | { |
||
85 | 0c281fe6 | gaqhf | cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, IN_SYMBOL TEXT, OUT_SYMBOL TEXT)", APID_OPC_MAPPING_TABLE); |
86 | a03cde1e | gaqhf | cmd.ExecuteNonQuery(); |
87 | } |
||
88 | 7a56b228 | gaqhf | if (dt.Select(string.Format("NAME = '{0}'", APID_ATTRIBUTE_MAPPING_TABLE)).Length == 0) |
89 | { |
||
90 | cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, APID_ATTRIBUTE TEXT, APID_ATTRIBUTE_TYPE)", APID_ATTRIBUTE_MAPPING_TABLE); |
||
91 | cmd.ExecuteNonQuery(); |
||
92 | } |
||
93 | a77303ca | gaqhf | } |
94 | 53a4ebb8 | gaqhf | } |
95 | result = true; |
||
96 | } |
||
97 | connection.Close(); |
||
98 | } |
||
99 | catch (Exception ex) |
||
100 | { |
||
101 | 465c8b6e | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
102 | 53a4ebb8 | gaqhf | } |
103 | finally |
||
104 | { |
||
105 | connection.Dispose(); |
||
106 | } |
||
107 | } |
||
108 | } |
||
109 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
110 | { |
||
111 | using (SqlConnection connection = GetSqlConnection()) |
||
112 | { |
||
113 | try |
||
114 | { |
||
115 | if (connection != null && connection.State == ConnectionState.Open) |
||
116 | { |
||
117 | using (SqlCommand cmd = connection.CreateCommand()) |
||
118 | { |
||
119 | a77303ca | gaqhf | cmd.CommandText = "SELECT TABLE_NAME AS NAME FROM INFORMATION_SCHEMA.TABLES"; |
120 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
121 | using (DataTable dt = new DataTable()) |
||
122 | { |
||
123 | dt.Load(dr); |
||
124 | |||
125 | if (dt.Select(string.Format("NAME = '{0}'", APID_SYMBOL_MAPPING_TABLE)).Length == 0) |
||
126 | { |
||
127 | 9dab7146 | gaqhf | cmd.CommandText = string.Format("CREATE TABLE {0} (UID varchar(255) PRIMARY KEY, NAME varchar(MAX), APID_SYMBOL varchar(MAX), DATA1 varchar(255))", APID_SYMBOL_MAPPING_TABLE); |
128 | a77303ca | gaqhf | cmd.ExecuteNonQuery(); |
129 | } |
||
130 | a03cde1e | gaqhf | if (dt.Select(string.Format("NAME = '{0}'", APID_OPC_MAPPING_TABLE)).Length == 0) |
131 | { |
||
132 | 0c281fe6 | gaqhf | cmd.CommandText = string.Format("CREATE TABLE {0} (UID varchar(255) PRIMARY KEY, IN_SYMBOL varchar(MAX), OUT_SYMBOL varchar(MAX))", APID_OPC_MAPPING_TABLE); |
133 | a03cde1e | gaqhf | cmd.ExecuteNonQuery(); |
134 | } |
||
135 | 7a56b228 | gaqhf | if (dt.Select(string.Format("NAME = '{0}'", APID_ATTRIBUTE_MAPPING_TABLE)).Length == 0) |
136 | { |
||
137 | cmd.CommandText = string.Format("CREATE TABLE {0} (UID varchar(255) PRIMARY KEY, APID_ATTRIBUTE varchar(MAX), APID_ATTRIBUTE_TYPE varchar(MAX))", APID_ATTRIBUTE_MAPPING_TABLE); |
||
138 | cmd.ExecuteNonQuery(); |
||
139 | } |
||
140 | a77303ca | gaqhf | } |
141 | 53a4ebb8 | gaqhf | } |
142 | result = true; |
||
143 | } |
||
144 | } |
||
145 | catch (Exception ex) |
||
146 | { |
||
147 | 465c8b6e | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
148 | 53a4ebb8 | gaqhf | } |
149 | finally |
||
150 | { |
||
151 | if (connection != null) |
||
152 | connection.Dispose(); |
||
153 | } |
||
154 | } |
||
155 | } |
||
156 | |||
157 | return result; |
||
158 | } |
||
159 | a77303ca | gaqhf | public static DataTable GetSymbolMappingTable() |
160 | { |
||
161 | DataTable dt = new DataTable(); |
||
162 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
163 | if (projectInfo.DBType == ID2DB_Type.SQLite) |
||
164 | { |
||
165 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
||
166 | { |
||
167 | try |
||
168 | { |
||
169 | connection.Open(); |
||
170 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
171 | { |
||
172 | cmd.CommandText = string.Format(@" |
||
173 | 9dab7146 | gaqhf | SELECT s.UID, s.Name, st.Type, sp.APID_SYMBOL, sp.DATA1 FROM {1} as st, {0} as s |
174 | a77303ca | gaqhf | LEFT OUTER JOIN {2} as sp |
175 | ON s.UID = SP.UID |
||
176 | WHERE s.SymbolType_UID = st.UID |
||
177 | 4aba6868 | gaqhf | AND st.Type != 'Instrument OPC''s' AND st.Type != 'Piping OPC''s' |
178 | a77303ca | gaqhf | ORDER BY st.TYPE ASC;", Symbol_TABLE, SymbolType_TABLE, APID_SYMBOL_MAPPING_TABLE); |
179 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
180 | dt.Load(dr); |
||
181 | |||
182 | DataTable dtClone = dt.Clone(); |
||
183 | dtClone.Columns["UID"].DataType = typeof(string); |
||
184 | foreach (DataRow row in dt.Rows) |
||
185 | { |
||
186 | dtClone.ImportRow(row); |
||
187 | } |
||
188 | dt.Dispose(); |
||
189 | dt = dtClone; |
||
190 | } |
||
191 | connection.Close(); |
||
192 | } |
||
193 | catch (Exception ex) |
||
194 | { |
||
195 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
196 | } |
||
197 | finally |
||
198 | { |
||
199 | connection.Dispose(); |
||
200 | } |
||
201 | } |
||
202 | } |
||
203 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
204 | { |
||
205 | using (SqlConnection connection = GetSqlConnection()) |
||
206 | { |
||
207 | try |
||
208 | { |
||
209 | if (connection != null && connection.State == ConnectionState.Open) |
||
210 | { |
||
211 | using (SqlCommand cmd = connection.CreateCommand()) |
||
212 | { |
||
213 | cmd.CommandText = string.Format(@" |
||
214 | 9dab7146 | gaqhf | SELECT CONVERT(VARCHAR(255), s.UID) AS UID, s.Name, st.Type, sp.APID_SYMBOL, sp.DATA1 FROM {1} as st, {0} as s |
215 | a77303ca | gaqhf | LEFT OUTER JOIN {2} as sp |
216 | ON CONVERT(VARCHAR(255), s.UID) = CONVERT(VARCHAR(255), SP.UID) |
||
217 | WHERE s.SymbolType_UID = st.UID |
||
218 | 4aba6868 | gaqhf | AND st.Type != 'Instrument OPC''s' AND st.Type != 'Piping OPC''s' |
219 | a77303ca | gaqhf | ORDER BY st.TYPE ASC;", Symbol_TABLE, SymbolType_TABLE, APID_SYMBOL_MAPPING_TABLE); |
220 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
221 | dt.Load(dr); |
||
222 | } |
||
223 | connection.Close(); |
||
224 | } |
||
225 | } |
||
226 | catch (Exception ex) |
||
227 | { |
||
228 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
229 | } |
||
230 | finally |
||
231 | { |
||
232 | if (connection != null) |
||
233 | connection.Dispose(); |
||
234 | } |
||
235 | } |
||
236 | } |
||
237 | |||
238 | return dt; |
||
239 | } |
||
240 | dd624cbd | gaqhf | public static DataTable GetOPCMappingTable() |
241 | { |
||
242 | DataTable dt = new DataTable(); |
||
243 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
244 | if (projectInfo.DBType == ID2DB_Type.SQLite) |
||
245 | { |
||
246 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
||
247 | { |
||
248 | try |
||
249 | { |
||
250 | connection.Open(); |
||
251 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
252 | { |
||
253 | cmd.CommandText = string.Format(@" |
||
254 | 0c281fe6 | gaqhf | SELECT s.UID, s.Name, st.Type, sp.IN_SYMBOL, sp.OUT_SYMBOL FROM {1} as st, {0} as s |
255 | dd624cbd | gaqhf | LEFT OUTER JOIN {2} as sp |
256 | ON s.UID = SP.UID |
||
257 | WHERE s.SymbolType_UID = st.UID |
||
258 | AND (st.Type = 'Instrument OPC''s' OR st.Type = 'Piping OPC''s') |
||
259 | ORDER BY st.TYPE ASC;", Symbol_TABLE, SymbolType_TABLE, APID_OPC_MAPPING_TABLE); |
||
260 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
261 | dt.Load(dr); |
||
262 | } |
||
263 | connection.Close(); |
||
264 | } |
||
265 | catch (Exception ex) |
||
266 | { |
||
267 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
268 | } |
||
269 | finally |
||
270 | { |
||
271 | connection.Dispose(); |
||
272 | } |
||
273 | } |
||
274 | } |
||
275 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
276 | { |
||
277 | using (SqlConnection connection = GetSqlConnection()) |
||
278 | { |
||
279 | try |
||
280 | { |
||
281 | if (connection != null && connection.State == ConnectionState.Open) |
||
282 | { |
||
283 | using (SqlCommand cmd = connection.CreateCommand()) |
||
284 | { |
||
285 | cmd.CommandText = string.Format(@" |
||
286 | 0c281fe6 | gaqhf | SELECT CONVERT(VARCHAR(255), s.UID) AS UID, s.Name, st.Type, sp.IN_SYMBOL, sp.OUT_SYMBOL FROM {1} as st, {0} as s |
287 | dd624cbd | gaqhf | LEFT OUTER JOIN {2} as sp |
288 | ON CONVERT(VARCHAR(255), s.UID) = CONVERT(VARCHAR(255), SP.UID) |
||
289 | WHERE s.SymbolType_UID = st.UID |
||
290 | AND (st.Type = 'Instrument OPC''s' OR st.Type = 'Piping OPC''s') |
||
291 | ORDER BY st.TYPE ASC;", Symbol_TABLE, SymbolType_TABLE, APID_OPC_MAPPING_TABLE); |
||
292 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
293 | dt.Load(dr); |
||
294 | } |
||
295 | connection.Close(); |
||
296 | } |
||
297 | } |
||
298 | catch (Exception ex) |
||
299 | { |
||
300 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
301 | } |
||
302 | finally |
||
303 | { |
||
304 | if (connection != null) |
||
305 | connection.Dispose(); |
||
306 | } |
||
307 | } |
||
308 | } |
||
309 | |||
310 | return dt; |
||
311 | } |
||
312 | 9ee9b61d | gaqhf | public static DataTable GetLineMappingTable() |
313 | { |
||
314 | DataTable dt = new DataTable(); |
||
315 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
316 | if (projectInfo.DBType == ID2DB_Type.SQLite) |
||
317 | { |
||
318 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
||
319 | { |
||
320 | try |
||
321 | { |
||
322 | connection.Open(); |
||
323 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
324 | { |
||
325 | cmd.CommandText = string.Format(@" |
||
326 | 9dab7146 | gaqhf | SELECT l.UID, l.Name, sp.APID_SYMBOL, sp.DATA1 FROM {0} as l |
327 | 9ee9b61d | gaqhf | LEFT OUTER JOIN {1} as sp |
328 | ON l.UID = SP.UID ;", LineTypes_TABLE, APID_SYMBOL_MAPPING_TABLE); |
||
329 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
330 | dt.Load(dr); |
||
331 | } |
||
332 | connection.Close(); |
||
333 | } |
||
334 | catch (Exception ex) |
||
335 | { |
||
336 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
337 | } |
||
338 | finally |
||
339 | { |
||
340 | connection.Dispose(); |
||
341 | } |
||
342 | } |
||
343 | } |
||
344 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
345 | { |
||
346 | using (SqlConnection connection = GetSqlConnection()) |
||
347 | { |
||
348 | try |
||
349 | { |
||
350 | if (connection != null && connection.State == ConnectionState.Open) |
||
351 | { |
||
352 | using (SqlCommand cmd = connection.CreateCommand()) |
||
353 | { |
||
354 | cmd.CommandText = string.Format(@" |
||
355 | 9dab7146 | gaqhf | SELECT l.UID, l.Name, sp.APID_SYMBOL, sp.DATA1 FROM {0} as l |
356 | 9ee9b61d | gaqhf | LEFT OUTER JOIN {1} as sp |
357 | ON l.UID = SP.UID ;", LineTypes_TABLE, APID_SYMBOL_MAPPING_TABLE); |
||
358 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
359 | dt.Load(dr); |
||
360 | } |
||
361 | connection.Close(); |
||
362 | } |
||
363 | } |
||
364 | catch (Exception ex) |
||
365 | { |
||
366 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
367 | } |
||
368 | finally |
||
369 | { |
||
370 | if (connection != null) |
||
371 | connection.Dispose(); |
||
372 | } |
||
373 | } |
||
374 | } |
||
375 | 465c8b6e | gaqhf | |
376 | 9ee9b61d | gaqhf | return dt; |
377 | } |
||
378 | 4622d687 | gaqhf | public static DataTable GetID2SymbolTable() |
379 | 465c8b6e | gaqhf | { |
380 | DataTable dt = new DataTable(); |
||
381 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
382 | if (projectInfo.DBType == ID2DB_Type.SQLite) |
||
383 | { |
||
384 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
||
385 | { |
||
386 | try |
||
387 | { |
||
388 | connection.Open(); |
||
389 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
390 | { |
||
391 | cmd.CommandText = @"SELECT * FROM Symbol"; |
||
392 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
393 | dt.Load(dr); |
||
394 | } |
||
395 | connection.Close(); |
||
396 | } |
||
397 | catch (Exception ex) |
||
398 | { |
||
399 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
400 | } |
||
401 | finally |
||
402 | { |
||
403 | connection.Dispose(); |
||
404 | } |
||
405 | } |
||
406 | } |
||
407 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
408 | { |
||
409 | using (SqlConnection connection = GetSqlConnection()) |
||
410 | { |
||
411 | try |
||
412 | { |
||
413 | if (connection != null && connection.State == ConnectionState.Open) |
||
414 | { |
||
415 | using (SqlCommand cmd = connection.CreateCommand()) |
||
416 | { |
||
417 | cmd.CommandText = @"SELECT * FROM Symbol"; |
||
418 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
419 | dt.Load(dr); |
||
420 | } |
||
421 | connection.Close(); |
||
422 | } |
||
423 | } |
||
424 | catch (Exception ex) |
||
425 | { |
||
426 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
427 | } |
||
428 | finally |
||
429 | { |
||
430 | if (connection != null) |
||
431 | connection.Dispose(); |
||
432 | } |
||
433 | } |
||
434 | } |
||
435 | |||
436 | return dt; |
||
437 | } |
||
438 | 4622d687 | gaqhf | public static DataTable GetSymbolType() |
439 | d327a608 | gaqhf | { |
440 | DataTable dt = new DataTable(); |
||
441 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
442 | if (projectInfo.DBType == ID2DB_Type.SQLite) |
||
443 | { |
||
444 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
||
445 | { |
||
446 | try |
||
447 | { |
||
448 | connection.Open(); |
||
449 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
450 | { |
||
451 | cmd.CommandText = string.Format("SELECT * FROM {0}", SymbolType_TABLE); |
||
452 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
453 | dt.Load(dr); |
||
454 | } |
||
455 | connection.Close(); |
||
456 | } |
||
457 | catch (Exception ex) |
||
458 | { |
||
459 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
460 | } |
||
461 | finally |
||
462 | { |
||
463 | connection.Dispose(); |
||
464 | } |
||
465 | } |
||
466 | } |
||
467 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
468 | { |
||
469 | using (SqlConnection connection = GetSqlConnection()) |
||
470 | { |
||
471 | try |
||
472 | { |
||
473 | if (connection != null && connection.State == ConnectionState.Open) |
||
474 | { |
||
475 | using (SqlCommand cmd = connection.CreateCommand()) |
||
476 | { |
||
477 | cmd.CommandText = string.Format("SELECT * FROM {0}", SymbolType_TABLE); |
||
478 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
479 | dt.Load(dr); |
||
480 | } |
||
481 | connection.Close(); |
||
482 | } |
||
483 | } |
||
484 | catch (Exception ex) |
||
485 | { |
||
486 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
487 | } |
||
488 | finally |
||
489 | { |
||
490 | if (connection != null) |
||
491 | connection.Dispose(); |
||
492 | } |
||
493 | } |
||
494 | } |
||
495 | 465c8b6e | gaqhf | |
496 | d327a608 | gaqhf | return dt; |
497 | } |
||
498 | 4622d687 | gaqhf | public static DataTable GetDrawings() |
499 | c7db500b | gaqhf | { |
500 | DataTable dt = new DataTable(); |
||
501 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
502 | if (projectInfo.DBType == ID2DB_Type.SQLite) |
||
503 | { |
||
504 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
||
505 | { |
||
506 | try |
||
507 | { |
||
508 | connection.Open(); |
||
509 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
510 | { |
||
511 | cmd.CommandText = string.Format("SELECT * FROM {0}", "Drawings"); |
||
512 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
513 | dt.Load(dr); |
||
514 | } |
||
515 | connection.Close(); |
||
516 | } |
||
517 | catch (Exception ex) |
||
518 | { |
||
519 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
520 | } |
||
521 | finally |
||
522 | { |
||
523 | connection.Dispose(); |
||
524 | } |
||
525 | } |
||
526 | } |
||
527 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
528 | { |
||
529 | using (SqlConnection connection = GetSqlConnection()) |
||
530 | { |
||
531 | try |
||
532 | { |
||
533 | if (connection != null && connection.State == ConnectionState.Open) |
||
534 | { |
||
535 | using (SqlCommand cmd = connection.CreateCommand()) |
||
536 | { |
||
537 | cmd.CommandText = string.Format("SELECT * FROM {0}", "Drawings"); |
||
538 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
539 | dt.Load(dr); |
||
540 | } |
||
541 | connection.Close(); |
||
542 | } |
||
543 | } |
||
544 | catch (Exception ex) |
||
545 | { |
||
546 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
547 | } |
||
548 | finally |
||
549 | { |
||
550 | if (connection != null) |
||
551 | connection.Dispose(); |
||
552 | } |
||
553 | } |
||
554 | } |
||
555 | |||
556 | return dt; |
||
557 | } |
||
558 | 9dab7146 | gaqhf | public static bool InsertSymbolMapping(List<Tuple<string, string, string, string>> datas) |
559 | c8da68ce | gaqhf | { |
560 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
561 | if (projectInfo.DBType == ID2DB_Type.SQLite) |
||
562 | { |
||
563 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
||
564 | { |
||
565 | try |
||
566 | { |
||
567 | connection.Open(); |
||
568 | using (SQLiteTransaction transaction = connection.BeginTransaction()) |
||
569 | { |
||
570 | try |
||
571 | { |
||
572 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
573 | { |
||
574 | foreach (var item in datas) |
||
575 | { |
||
576 | cmd.Parameters.Clear(); |
||
577 | 9dab7146 | gaqhf | cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, NAME, APID_SYMBOL, DATA1) VALUES (@UID, @NAME, @APID_SYMBOL, @DATA1)", APID_SYMBOL_MAPPING_TABLE); |
578 | c8da68ce | gaqhf | cmd.Parameters.AddWithValue("@UID", item.Item1); |
579 | cmd.Parameters.AddWithValue("@NAME", item.Item2); |
||
580 | cmd.Parameters.AddWithValue("@APID_SYMBOL", item.Item3); |
||
581 | 9dab7146 | gaqhf | cmd.Parameters.AddWithValue("@DATA1", item.Item4); |
582 | c8da68ce | gaqhf | cmd.ExecuteNonQuery(); |
583 | } |
||
584 | } |
||
585 | transaction.Commit(); |
||
586 | connection.Close(); |
||
587 | } |
||
588 | catch (Exception ex) |
||
589 | { |
||
590 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
591 | transaction.Rollback(); |
||
592 | return false; |
||
593 | } |
||
594 | finally |
||
595 | { |
||
596 | transaction.Dispose(); |
||
597 | } |
||
598 | } |
||
599 | } |
||
600 | catch (Exception ex) |
||
601 | { |
||
602 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
603 | return false; |
||
604 | } |
||
605 | finally |
||
606 | { |
||
607 | connection.Dispose(); |
||
608 | } |
||
609 | } |
||
610 | } |
||
611 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
612 | { |
||
613 | using (SqlConnection connection = GetSqlConnection()) |
||
614 | { |
||
615 | try |
||
616 | { |
||
617 | if (connection != null && connection.State == ConnectionState.Open) |
||
618 | { |
||
619 | using (SqlCommand cmd = connection.CreateCommand()) |
||
620 | { |
||
621 | foreach (var item in datas) |
||
622 | { |
||
623 | cmd.Parameters.Clear(); |
||
624 | cmd.CommandText = string.Format(@" |
||
625 | IF EXISTS (SELECT * FROM {0} WHERE UID = '{1}') |
||
626 | 9dab7146 | gaqhf | UPDATE {0} SET NAME = @NAME, APID_SYMBOL = @APID_SYMBOL, DATA1 = @DATA1 WHERE UID = @UID |
627 | c8da68ce | gaqhf | ELSE |
628 | 9dab7146 | gaqhf | INSERT INTO {0} (UID, NAME, APID_SYMBOL, DATA1) VALUES (@UID, @NAME, @APID_SYMBOL, @DATA1)", APID_SYMBOL_MAPPING_TABLE, item.Item1); |
629 | c8da68ce | gaqhf | cmd.Parameters.AddWithValue("@UID", item.Item1); |
630 | if (string.IsNullOrEmpty(item.Item2)) |
||
631 | cmd.Parameters.AddWithValue("@NAME", DBNull.Value); |
||
632 | else |
||
633 | cmd.Parameters.AddWithValue("@NAME", item.Item2); |
||
634 | if (string.IsNullOrEmpty(item.Item3)) |
||
635 | cmd.Parameters.AddWithValue("@APID_SYMBOL", DBNull.Value); |
||
636 | else |
||
637 | cmd.Parameters.AddWithValue("@APID_SYMBOL", item.Item3); |
||
638 | 9dab7146 | gaqhf | if (string.IsNullOrEmpty(item.Item4)) |
639 | cmd.Parameters.AddWithValue("@DATA1", DBNull.Value); |
||
640 | else |
||
641 | cmd.Parameters.AddWithValue("@DATA1", item.Item4); |
||
642 | |||
643 | c8da68ce | gaqhf | cmd.ExecuteNonQuery(); |
644 | } |
||
645 | } |
||
646 | connection.Close(); |
||
647 | } |
||
648 | } |
||
649 | catch (Exception ex) |
||
650 | { |
||
651 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
652 | return false; |
||
653 | } |
||
654 | finally |
||
655 | { |
||
656 | if (connection != null) |
||
657 | connection.Dispose(); |
||
658 | } |
||
659 | } |
||
660 | } |
||
661 | |||
662 | return true; |
||
663 | } |
||
664 | 0c281fe6 | gaqhf | public static bool InsertOPCMapping(List<Tuple<string, string, string>> datas) |
665 | { |
||
666 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
667 | if (projectInfo.DBType == ID2DB_Type.SQLite) |
||
668 | { |
||
669 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
||
670 | { |
||
671 | try |
||
672 | { |
||
673 | connection.Open(); |
||
674 | using (SQLiteTransaction transaction = connection.BeginTransaction()) |
||
675 | { |
||
676 | try |
||
677 | { |
||
678 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
679 | { |
||
680 | foreach (var item in datas) |
||
681 | { |
||
682 | cmd.Parameters.Clear(); |
||
683 | cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, IN_SYMBOL, OUT_SYMBOL) VALUES (@UID, @IN_SYMBOL, @OUT_SYMBOL)", APID_OPC_MAPPING_TABLE); |
||
684 | cmd.Parameters.AddWithValue("@UID", item.Item1); |
||
685 | cmd.Parameters.AddWithValue("@IN_SYMBOL", item.Item2); |
||
686 | cmd.Parameters.AddWithValue("@OUT_SYMBOL", item.Item3); |
||
687 | cmd.ExecuteNonQuery(); |
||
688 | } |
||
689 | } |
||
690 | transaction.Commit(); |
||
691 | connection.Close(); |
||
692 | } |
||
693 | catch (Exception ex) |
||
694 | { |
||
695 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
696 | transaction.Rollback(); |
||
697 | return false; |
||
698 | } |
||
699 | finally |
||
700 | { |
||
701 | transaction.Dispose(); |
||
702 | } |
||
703 | } |
||
704 | } |
||
705 | catch (Exception ex) |
||
706 | { |
||
707 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
708 | return false; |
||
709 | } |
||
710 | finally |
||
711 | { |
||
712 | connection.Dispose(); |
||
713 | } |
||
714 | } |
||
715 | } |
||
716 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
717 | { |
||
718 | using (SqlConnection connection = GetSqlConnection()) |
||
719 | { |
||
720 | try |
||
721 | { |
||
722 | if (connection != null && connection.State == ConnectionState.Open) |
||
723 | { |
||
724 | using (SqlCommand cmd = connection.CreateCommand()) |
||
725 | { |
||
726 | foreach (var item in datas) |
||
727 | { |
||
728 | cmd.Parameters.Clear(); |
||
729 | cmd.CommandText = string.Format(@" |
||
730 | IF EXISTS (SELECT * FROM {0} WHERE UID = '{1}') |
||
731 | UPDATE {0} SET IN_SYMBOL = @IN_SYMBOL, OUT_SYMBOL = @OUT_SYMBOL WHERE UID = @UID |
||
732 | ELSE |
||
733 | INSERT INTO {0} (UID, IN_SYMBOL, OUT_SYMBOL) VALUES (@UID, @IN_SYMBOL, @OUT_SYMBOL)", APID_OPC_MAPPING_TABLE, item.Item1); |
||
734 | cmd.Parameters.AddWithValue("@UID", item.Item1); |
||
735 | if (string.IsNullOrEmpty(item.Item2)) |
||
736 | cmd.Parameters.AddWithValue("@IN_SYMBOL", DBNull.Value); |
||
737 | else |
||
738 | cmd.Parameters.AddWithValue("@IN_SYMBOL", item.Item2); |
||
739 | if (string.IsNullOrEmpty(item.Item3)) |
||
740 | cmd.Parameters.AddWithValue("@OUT_SYMBOL", DBNull.Value); |
||
741 | else |
||
742 | cmd.Parameters.AddWithValue("@OUT_SYMBOL", item.Item3); |
||
743 | |||
744 | cmd.ExecuteNonQuery(); |
||
745 | ee781888 | gaqhf | } |
746 | } |
||
747 | connection.Close(); |
||
748 | } |
||
749 | } |
||
750 | catch (Exception ex) |
||
751 | { |
||
752 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
753 | return false; |
||
754 | } |
||
755 | finally |
||
756 | { |
||
757 | if (connection != null) |
||
758 | connection.Dispose(); |
||
759 | } |
||
760 | } |
||
761 | } |
||
762 | |||
763 | return true; |
||
764 | } |
||
765 | public static bool InsertAttributeMapping(List<Tuple<string, string, string>> datas) |
||
766 | { |
||
767 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
768 | if (projectInfo.DBType == ID2DB_Type.SQLite) |
||
769 | { |
||
770 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
||
771 | { |
||
772 | try |
||
773 | { |
||
774 | connection.Open(); |
||
775 | using (SQLiteTransaction transaction = connection.BeginTransaction()) |
||
776 | { |
||
777 | try |
||
778 | { |
||
779 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
780 | { |
||
781 | foreach (var item in datas) |
||
782 | { |
||
783 | cmd.Parameters.Clear(); |
||
784 | cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, APID_ATTRIBUTE, APID_ATTRIBUTE_TYPE) VALUES (@UID, @APID_ATTRIBUTE, @APID_ATTRIBUTE_TYPE)", APID_ATTRIBUTE_MAPPING_TABLE); |
||
785 | cmd.Parameters.AddWithValue("@UID", item.Item1); |
||
786 | cmd.Parameters.AddWithValue("@APID_ATTRIBUTE", item.Item2); |
||
787 | cmd.Parameters.AddWithValue("@APID_ATTRIBUTE_TYPE", item.Item3); |
||
788 | cmd.ExecuteNonQuery(); |
||
789 | } |
||
790 | } |
||
791 | transaction.Commit(); |
||
792 | connection.Close(); |
||
793 | } |
||
794 | catch (Exception ex) |
||
795 | { |
||
796 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
797 | transaction.Rollback(); |
||
798 | return false; |
||
799 | } |
||
800 | finally |
||
801 | { |
||
802 | transaction.Dispose(); |
||
803 | } |
||
804 | } |
||
805 | } |
||
806 | catch (Exception ex) |
||
807 | { |
||
808 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
809 | return false; |
||
810 | } |
||
811 | finally |
||
812 | { |
||
813 | connection.Dispose(); |
||
814 | } |
||
815 | } |
||
816 | } |
||
817 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
818 | { |
||
819 | using (SqlConnection connection = GetSqlConnection()) |
||
820 | { |
||
821 | try |
||
822 | { |
||
823 | if (connection != null && connection.State == ConnectionState.Open) |
||
824 | { |
||
825 | using (SqlCommand cmd = connection.CreateCommand()) |
||
826 | { |
||
827 | foreach (var item in datas) |
||
828 | { |
||
829 | cmd.Parameters.Clear(); |
||
830 | cmd.CommandText = string.Format(@" |
||
831 | IF EXISTS (SELECT * FROM {0} WHERE UID = '{1}') |
||
832 | UPDATE {0} SET APID_ATTRIBUTE = @APID_ATTRIBUTE, APID_ATTRIBUTE_TYPE = @APID_ATTRIBUTE_TYPE WHERE UID = @UID |
||
833 | ELSE |
||
834 | INSERT INTO {0} (UID, APID_ATTRIBUTE, APID_ATTRIBUTE_TYPE) VALUES (@UID, @APID_ATTRIBUTE, @APID_ATTRIBUTE_TYPE)", APID_ATTRIBUTE_MAPPING_TABLE, item.Item1); |
||
835 | cmd.Parameters.AddWithValue("@UID", item.Item1); |
||
836 | if (string.IsNullOrEmpty(item.Item2)) |
||
837 | cmd.Parameters.AddWithValue("@APID_ATTRIBUTE", DBNull.Value); |
||
838 | else |
||
839 | cmd.Parameters.AddWithValue("@APID_ATTRIBUTE", item.Item2); |
||
840 | if (string.IsNullOrEmpty(item.Item3)) |
||
841 | cmd.Parameters.AddWithValue("@APID_ATTRIBUTE_TYPE", DBNull.Value); |
||
842 | else |
||
843 | cmd.Parameters.AddWithValue("@APID_ATTRIBUTE_TYPE", item.Item3); |
||
844 | |||
845 | cmd.ExecuteNonQuery(); |
||
846 | 0c281fe6 | gaqhf | } |
847 | } |
||
848 | connection.Close(); |
||
849 | } |
||
850 | } |
||
851 | catch (Exception ex) |
||
852 | { |
||
853 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
854 | return false; |
||
855 | } |
||
856 | finally |
||
857 | { |
||
858 | if (connection != null) |
||
859 | connection.Dispose(); |
||
860 | } |
||
861 | } |
||
862 | } |
||
863 | |||
864 | return true; |
||
865 | } |
||
866 | 4622d687 | gaqhf | public static DataTable GetProjectAttribute() |
867 | 7a56b228 | gaqhf | { |
868 | DataTable dt = new DataTable(); |
||
869 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
870 | if (projectInfo.DBType == ID2DB_Type.SQLite) |
||
871 | { |
||
872 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
||
873 | { |
||
874 | try |
||
875 | { |
||
876 | connection.Open(); |
||
877 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
878 | { |
||
879 | cmd.CommandText = string.Format(@" |
||
880 | SELECT sa.UID, sa.DisplayAttribute, st.TYPE, spa.APID_ATTRIBUTE, spa.APID_ATTRIBUTE_TYPE, sp.APID_SYMBOL, sa.Property |
||
881 | FROM {1} as sa, {0} as st |
||
882 | LEFT OUTER JOIN {2} as sp |
||
883 | ON sa.UID = SP.UID |
||
884 | LEFT OUTER JOIN {3} as spa |
||
885 | ON sa.UID = spa.UID |
||
886 | WHERE sa.SymbolType_UID = st.UID AND (sa.Property != 2 OR sa.Property IS NULL);", SymbolType_TABLE, SymbolAttribute_TABLE, APID_SYMBOL_MAPPING_TABLE, APID_ATTRIBUTE_MAPPING_TABLE); |
||
887 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
888 | dt.Load(dr); |
||
889 | } |
||
890 | connection.Close(); |
||
891 | } |
||
892 | catch (Exception ex) |
||
893 | { |
||
894 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
895 | } |
||
896 | finally |
||
897 | { |
||
898 | connection.Dispose(); |
||
899 | } |
||
900 | } |
||
901 | } |
||
902 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
903 | { |
||
904 | using (SqlConnection connection = GetSqlConnection()) |
||
905 | { |
||
906 | try |
||
907 | { |
||
908 | if (connection != null && connection.State == ConnectionState.Open) |
||
909 | { |
||
910 | using (SqlCommand cmd = connection.CreateCommand()) |
||
911 | { |
||
912 | cmd.CommandText = string.Format(@" |
||
913 | SELECT sa.UID, sa.DisplayAttribute, st.Type, spa.APID_ATTRIBUTE, spa.APID_ATTRIBUTE_TYPE, sp.APID_SYMBOL, sa.Property |
||
914 | FROM {1} as sa |
||
915 | LEFT OUTER JOIN {2} as sp |
||
916 | ON sa.UID = SP.UID |
||
917 | LEFT OUTER JOIN {3} as spa |
||
918 | ON sa.UID = spa.UID |
||
919 | LEFT OUTER JOIN {0} as st |
||
920 | ON sa.SymbolType_UID = st.UID |
||
921 | WHERE (sa.Property != 2 OR sa.Property IS NULL);", SymbolType_TABLE, SymbolAttribute_TABLE, APID_SYMBOL_MAPPING_TABLE, APID_ATTRIBUTE_MAPPING_TABLE); |
||
922 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
923 | dt.Load(dr); |
||
924 | } |
||
925 | connection.Close(); |
||
926 | } |
||
927 | } |
||
928 | catch (Exception ex) |
||
929 | { |
||
930 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
931 | } |
||
932 | finally |
||
933 | { |
||
934 | if (connection != null) |
||
935 | connection.Dispose(); |
||
936 | } |
||
937 | } |
||
938 | } |
||
939 | |||
940 | |||
941 | return dt; |
||
942 | } |
||
943 | 4622d687 | gaqhf | public static DataTable GetProjectLineProperties() |
944 | 2b02c914 | gaqhf | { |
945 | DataTable dt = new DataTable(); |
||
946 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
947 | if (projectInfo.DBType == ID2DB_Type.SQLite) |
||
948 | { |
||
949 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
||
950 | { |
||
951 | try |
||
952 | { |
||
953 | connection.Open(); |
||
954 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
955 | { |
||
956 | cmd.CommandText = string.Format(@" |
||
957 | SELECT lp.UID, lp.DisplayName, sp.APID_SYMBOL, spa.APID_ATTRIBUTE |
||
958 | FROM {0} as lp |
||
959 | LEFT OUTER JOIN {1} as sp |
||
960 | ON lp.UID = sp.UID |
||
961 | LEFT OUTER JOIN {2} as spa |
||
962 | ON lp.UID = spa.UID;", LineProperties_TABLE, APID_SYMBOL_MAPPING_TABLE, APID_ATTRIBUTE_MAPPING_TABLE); |
||
963 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
964 | dt.Load(dr); |
||
965 | } |
||
966 | connection.Close(); |
||
967 | } |
||
968 | catch (Exception ex) |
||
969 | { |
||
970 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
971 | } |
||
972 | finally |
||
973 | { |
||
974 | connection.Dispose(); |
||
975 | } |
||
976 | } |
||
977 | } |
||
978 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
979 | { |
||
980 | using (SqlConnection connection = GetSqlConnection()) |
||
981 | { |
||
982 | try |
||
983 | { |
||
984 | if (connection != null && connection.State == ConnectionState.Open) |
||
985 | { |
||
986 | using (SqlCommand cmd = connection.CreateCommand()) |
||
987 | { |
||
988 | cmd.CommandText = string.Format(@" |
||
989 | SELECT lp.UID, lp.DisplayName, sp.APID_SYMBOL, spa.APID_ATTRIBUTE |
||
990 | FROM {0} as lp |
||
991 | LEFT OUTER JOIN {1} as sp |
||
992 | ON lp.UID = sp.UID |
||
993 | LEFT OUTER JOIN {2} as spa |
||
994 | ON lp.UID = spa.UID;", LineProperties_TABLE, APID_SYMBOL_MAPPING_TABLE, APID_ATTRIBUTE_MAPPING_TABLE); |
||
995 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
996 | dt.Load(dr); |
||
997 | } |
||
998 | connection.Close(); |
||
999 | } |
||
1000 | } |
||
1001 | catch (Exception ex) |
||
1002 | { |
||
1003 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
1004 | 4622d687 | gaqhf | } |
1005 | finally |
||
1006 | { |
||
1007 | if (connection != null) |
||
1008 | connection.Dispose(); |
||
1009 | } |
||
1010 | } |
||
1011 | } |
||
1012 | |||
1013 | return dt; |
||
1014 | } |
||
1015 | public static DataTable GetSymbolMappingTableOnlySymbol() |
||
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("SELECT * FROM {0}", APID_SYMBOL_MAPPING_TABLE); |
||
1029 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
1030 | dt.Load(dr); |
||
1031 | } |
||
1032 | connection.Close(); |
||
1033 | } |
||
1034 | catch (Exception ex) |
||
1035 | { |
||
1036 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
1037 | } |
||
1038 | finally |
||
1039 | { |
||
1040 | connection.Dispose(); |
||
1041 | } |
||
1042 | } |
||
1043 | } |
||
1044 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
1045 | { |
||
1046 | using (SqlConnection connection = GetSqlConnection()) |
||
1047 | { |
||
1048 | try |
||
1049 | { |
||
1050 | if (connection != null && connection.State == ConnectionState.Open) |
||
1051 | { |
||
1052 | using (SqlCommand cmd = connection.CreateCommand()) |
||
1053 | { |
||
1054 | cmd.CommandText = string.Format("SELECT * FROM {0}", APID_SYMBOL_MAPPING_TABLE); |
||
1055 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
1056 | dt.Load(dr); |
||
1057 | } |
||
1058 | connection.Close(); |
||
1059 | } |
||
1060 | } |
||
1061 | catch (Exception ex) |
||
1062 | { |
||
1063 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
1064 | } |
||
1065 | finally |
||
1066 | { |
||
1067 | if (connection != null) |
||
1068 | connection.Dispose(); |
||
1069 | } |
||
1070 | } |
||
1071 | } |
||
1072 | |||
1073 | return dt; |
||
1074 | } |
||
1075 | public static DataTable GetAttributeMappingTableOnlyAttribute() |
||
1076 | { |
||
1077 | DataTable dt = new DataTable(); |
||
1078 | Project_Info projectInfo = Project_Info.GetInstance(); |
||
1079 | if (projectInfo.DBType == ID2DB_Type.SQLite) |
||
1080 | { |
||
1081 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath))) |
||
1082 | { |
||
1083 | try |
||
1084 | { |
||
1085 | connection.Open(); |
||
1086 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
1087 | { |
||
1088 | cmd.CommandText = string.Format("SELECT * FROM {0}", APID_ATTRIBUTE_MAPPING_TABLE); |
||
1089 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
1090 | dt.Load(dr); |
||
1091 | } |
||
1092 | connection.Close(); |
||
1093 | } |
||
1094 | catch (Exception ex) |
||
1095 | { |
||
1096 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
1097 | } |
||
1098 | finally |
||
1099 | { |
||
1100 | connection.Dispose(); |
||
1101 | } |
||
1102 | } |
||
1103 | } |
||
1104 | else if (projectInfo.DBType == ID2DB_Type.MSSQL) |
||
1105 | { |
||
1106 | using (SqlConnection connection = GetSqlConnection()) |
||
1107 | { |
||
1108 | try |
||
1109 | { |
||
1110 | if (connection != null && connection.State == ConnectionState.Open) |
||
1111 | { |
||
1112 | using (SqlCommand cmd = connection.CreateCommand()) |
||
1113 | { |
||
1114 | cmd.CommandText = string.Format("SELECT * FROM {0}", APID_ATTRIBUTE_MAPPING_TABLE); |
||
1115 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
1116 | dt.Load(dr); |
||
1117 | } |
||
1118 | connection.Close(); |
||
1119 | } |
||
1120 | } |
||
1121 | catch (Exception ex) |
||
1122 | { |
||
1123 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
1124 | 2b02c914 | gaqhf | } |
1125 | finally |
||
1126 | { |
||
1127 | if (connection != null) |
||
1128 | connection.Dispose(); |
||
1129 | } |
||
1130 | } |
||
1131 | } |
||
1132 | |||
1133 | return dt; |
||
1134 | } |
||
1135 | a77303ca | gaqhf | #endregion |
1136 | e9ed6b7b | gaqhf | |
1137 | #region AVEVA |
||
1138 | 534ca9c5 | gaqhf | public static string GetAvevaConnectionString() |
1139 | e9ed6b7b | gaqhf | { |
1140 | string strConn = string.Empty; |
||
1141 | if (Utilities.strSQLWinAuthentication.ToUpper() == "YES") |
||
1142 | { |
||
1143 | strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Integrated Security=SSPI;Initial Catalog={0};", Utilities.strSQLDatabaseName); |
||
1144 | } |
||
1145 | else if (Utilities.strSQLWinAuthentication.ToUpper() == "NO") |
||
1146 | { |
||
1147 | string strAccessString = "User ID=" + Utilities.strSQLUserName + ";Password=" + Utilities.strSQLPassword; |
||
1148 | strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Initial Catalog=" + Utilities.strSQLDatabaseName + ";" + strAccessString); |
||
1149 | } |
||
1150 | |||
1151 | return strConn; |
||
1152 | } |
||
1153 | 534ca9c5 | gaqhf | public static string GetAvevaConnectionString_Reports() |
1154 | e9ed6b7b | gaqhf | { |
1155 | string strConn = string.Empty; |
||
1156 | if (Utilities.strSQLWinAuthentication.ToUpper() == "YES") |
||
1157 | { |
||
1158 | strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Integrated Security=SSPI;Initial Catalog={0};", Utilities.strSQLReportsDatabaseName); |
||
1159 | } |
||
1160 | else if (Utilities.strSQLWinAuthentication.ToUpper() == "NO") |
||
1161 | { |
||
1162 | string strAccessString = "User ID=" + Utilities.strSQLUserName + ";Password=" + Utilities.strSQLPassword; |
||
1163 | strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Initial Catalog=" + Utilities.strSQLReportsDatabaseName + ";" + strAccessString); |
||
1164 | } |
||
1165 | |||
1166 | return strConn; |
||
1167 | } |
||
1168 | 534ca9c5 | gaqhf | public static string GetAvevaConnectionString_Admin() |
1169 | e9ed6b7b | gaqhf | { |
1170 | string strConn = string.Empty; |
||
1171 | if (Utilities.strSQLWinAuthentication.ToUpper() == "YES") |
||
1172 | { |
||
1173 | strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Integrated Security=SSPI;Initial Catalog={0};", Utilities.strSQLAdminDatabaseName); |
||
1174 | } |
||
1175 | else if (Utilities.strSQLWinAuthentication.ToUpper() == "NO") |
||
1176 | { |
||
1177 | string strAccessString = "User ID=" + Utilities.strSQLUserName + ";Password=" + Utilities.strSQLPassword; |
||
1178 | strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Initial Catalog=" + Utilities.strSQLAdminDatabaseName + ";" + strAccessString); |
||
1179 | } |
||
1180 | |||
1181 | return strConn; |
||
1182 | } |
||
1183 | 59184d1b | gaqhf | public static string GetDirectiveValue(string name) |
1184 | { |
||
1185 | string result = null; |
||
1186 | |||
1187 | using (SqlConnection connection = new SqlConnection()) |
||
1188 | { |
||
1189 | connection.ConnectionString = GetAvevaConnectionString_Admin(); |
||
1190 | connection.Open(); |
||
1191 | using (SqlCommand cmd = connection.CreateCommand()) |
||
1192 | { |
||
1193 | cmd.CommandText = string.Format("select DirectiveValue from ProjectDirectives where DirectiveName = '{0}'", name); |
||
1194 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
1195 | { |
||
1196 | if (dr.Read()) |
||
1197 | result = dr.GetString(0); |
||
1198 | } |
||
1199 | } |
||
1200 | connection.Close(); |
||
1201 | } |
||
1202 | |||
1203 | return result; |
||
1204 | } |
||
1205 | public static DataTable GetDrawingTemplate() |
||
1206 | { |
||
1207 | DataTable dt = new DataTable(); |
||
1208 | |||
1209 | using (SqlConnection connection = new SqlConnection()) |
||
1210 | { |
||
1211 | connection.ConnectionString = GetAvevaConnectionString_Reports(); |
||
1212 | connection.Open(); |
||
1213 | using (SqlCommand cmd = connection.CreateCommand()) |
||
1214 | { |
||
1215 | cmd.CommandText = "select ID, Name,IsDWG,DateCreation,MachineName,FutureUse1,FutureUse2 from DrawingTemplates where IsDWG=0"; |
||
1216 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
1217 | dt.Load(dr); |
||
1218 | } |
||
1219 | connection.Close(); |
||
1220 | } |
||
1221 | |||
1222 | return dt; |
||
1223 | } |
||
1224 | 56cd4954 | gaqhf | public static DataTable SelectStandardSymbolTable() |
1225 | e9ed6b7b | gaqhf | { |
1226 | DataTable dt = new DataTable(); |
||
1227 | |||
1228 | using (SqlConnection connection = new SqlConnection()) |
||
1229 | { |
||
1230 | connection.ConnectionString = GetAvevaConnectionString_Admin(); |
||
1231 | connection.Open(); |
||
1232 | using (SqlCommand cmd = connection.CreateCommand()) |
||
1233 | { |
||
1234 | 56cd4954 | gaqhf | cmd.CommandText = string.Format(@" |
1235 | SELECT ss.ID, ss.Symbol_Name, sps.Relative_Path FROM {0} as ss |
||
1236 | LEFT OUTER JOIN {1} as sps |
||
1237 | ON ss.Relative_Path = sps.ID |
||
1238 | ORDER BY sps.ID ASC |
||
1239 | ;", "stdSymbols", "StdPrjFolStructure"); |
||
1240 | |||
1241 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
1242 | dt.Load(dr); |
||
1243 | } |
||
1244 | connection.Close(); |
||
1245 | } |
||
1246 | |||
1247 | return dt; |
||
1248 | } |
||
1249 | public static DataTable SelectStandardSymbolStructureTable() |
||
1250 | { |
||
1251 | DataTable dt = new DataTable(); |
||
1252 | |||
1253 | using (SqlConnection connection = new SqlConnection()) |
||
1254 | { |
||
1255 | connection.ConnectionString = GetAvevaConnectionString_Admin(); |
||
1256 | connection.Open(); |
||
1257 | using (SqlCommand cmd = connection.CreateCommand()) |
||
1258 | { |
||
1259 | cmd.CommandText = string.Format(@" |
||
1260 | SELECT * FROM {0} |
||
1261 | ;", "StdPrjFolStructure"); |
||
1262 | |||
1263 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
1264 | dt.Load(dr); |
||
1265 | } |
||
1266 | connection.Close(); |
||
1267 | } |
||
1268 | |||
1269 | return dt; |
||
1270 | } |
||
1271 | public static DataTable SelectStandardSymbolImageTable() |
||
1272 | { |
||
1273 | DataTable dt = new DataTable(); |
||
1274 | |||
1275 | using (SqlConnection connection = new SqlConnection()) |
||
1276 | { |
||
1277 | connection.ConnectionString = GetAvevaConnectionString_Admin(); |
||
1278 | connection.Open(); |
||
1279 | using (SqlCommand cmd = connection.CreateCommand()) |
||
1280 | { |
||
1281 | cmd.CommandText = string.Format(@" |
||
1282 | SELECT ss.Symbol_Name, ss.Pic_Binary, sps.Relative_Path FROM {0} as ss |
||
1283 | LEFT OUTER JOIN {1} as sps |
||
1284 | ON ss.Relative_Path = sps.ID |
||
1285 | ORDER BY sps.ID ASC |
||
1286 | ;", "stdSymbols", "StdPrjFolStructure"); |
||
1287 | |||
1288 | e9ed6b7b | gaqhf | using (SqlDataReader dr = cmd.ExecuteReader()) |
1289 | dt.Load(dr); |
||
1290 | } |
||
1291 | connection.Close(); |
||
1292 | } |
||
1293 | |||
1294 | return dt; |
||
1295 | } |
||
1296 | 128c844f | gaqhf | public static DataTable SelectDrawingTable() |
1297 | { |
||
1298 | DataTable dt = new DataTable(); |
||
1299 | e9ed6b7b | gaqhf | |
1300 | 128c844f | gaqhf | using (SqlConnection connection = new SqlConnection()) |
1301 | { |
||
1302 | connection.ConnectionString = GetAvevaConnectionString_Reports(); |
||
1303 | connection.Open(); |
||
1304 | using (SqlCommand cmd = connection.CreateCommand()) |
||
1305 | { |
||
1306 | cmd.CommandText = string.Format(@" |
||
1307 | SELECT DrawingId, XDNLABEL, XDSLABEL FROM {0} |
||
1308 | ;", "SynchroniseDetails"); |
||
1309 | |||
1310 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
1311 | dt.Load(dr); |
||
1312 | } |
||
1313 | connection.Close(); |
||
1314 | } |
||
1315 | |||
1316 | return dt; |
||
1317 | } |
||
1318 | 495bb8f5 | gaqhf | public static DataTable SelectSymbolTable() |
1319 | { |
||
1320 | DataTable dt = new DataTable(); |
||
1321 | |||
1322 | using (SqlConnection connection = new SqlConnection()) |
||
1323 | { |
||
1324 | connection.ConnectionString = GetAvevaConnectionString_Admin(); |
||
1325 | connection.Open(); |
||
1326 | using (SqlCommand cmd = connection.CreateCommand()) |
||
1327 | { |
||
1328 | cmd.CommandText = string.Format(@" |
||
1329 | SELECT * FROM {0} |
||
1330 | ;", "SYMBOLS"); |
||
1331 | |||
1332 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
1333 | dt.Load(dr); |
||
1334 | } |
||
1335 | connection.Close(); |
||
1336 | } |
||
1337 | |||
1338 | return dt; |
||
1339 | } |
||
1340 | 77a33d5f | gaqhf | public static DataTable SelectUDADetails() |
1341 | { |
||
1342 | DataTable dt = new DataTable(); |
||
1343 | |||
1344 | using (SqlConnection connection = new SqlConnection()) |
||
1345 | { |
||
1346 | connection.ConnectionString = GetAvevaConnectionString_Admin(); |
||
1347 | connection.Open(); |
||
1348 | using (SqlCommand cmd = connection.CreateCommand()) |
||
1349 | { |
||
1350 | cmd.CommandText = string.Format(@" |
||
1351 | SELECT * FROM {0} |
||
1352 | ;", "UDADetails"); |
||
1353 | |||
1354 | using (SqlDataReader dr = cmd.ExecuteReader()) |
||
1355 | dt.Load(dr); |
||
1356 | } |
||
1357 | connection.Close(); |
||
1358 | } |
||
1359 | |||
1360 | return dt; |
||
1361 | } |
||
1362 | e9ed6b7b | gaqhf | #endregion |
1363 | |||
1364 | 53a4ebb8 | gaqhf | } |
1365 | } |