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