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