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