hytos / DTI_PID / ID2PSN / DB.cs @ 8487ecb2
이력 | 보기 | 이력해설 | 다운로드 (51.8 KB)
1 | 0dae5645 | gaqhf | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.Linq; |
||
4 | using System.Text; |
||
5 | using System.Threading.Tasks; |
||
6 | 6b9e7a56 | gaqhf | using System.Data.SQLite; |
7 | using System.Data; |
||
8 | using System.Globalization; |
||
9 | using System.Data.SQLite; |
||
10 | using System.Data; |
||
11 | 8f24b438 | gaqhf | using System.Text.RegularExpressions; |
12 | 0dae5645 | gaqhf | |
13 | namespace ID2PSN |
||
14 | { |
||
15 | 6b9e7a56 | gaqhf | public static class DB |
16 | 0dae5645 | gaqhf | { |
17 | 6b9e7a56 | gaqhf | const string PSN_TOPOLOGY_RULE = "T_PSN_TOPOLOGY_RULE"; |
18 | const string PSN_HEADER_SETTING = "T_PSN_HEADER_SETTING"; |
||
19 | 8f24b438 | gaqhf | const string PSN_PATHITEMS = "SPPIDPathItem"; |
20 | const string PSN_SEQUENCEDATA = "SPPIDSequenceData"; |
||
21 | const string PSN_PIPESYSTEMNETWORK = "SPPIDPipeSystemNetwork"; |
||
22 | const string PSN_EQUIPMENT = "SPPIDEquipment"; |
||
23 | const string PSN_NOZZLE = "SPPIDNozzle"; |
||
24 | const string PSN_FLUIDCODE = "SPPIDFluidCode"; |
||
25 | const string PSN_PIPINGMATLCLASS = "SPPIDPipingMatClass"; |
||
26 | 5c248ee3 | gaqhf | const string PSN_VIEW = "T_PSN_VIEW"; |
27 | 6b9e7a56 | gaqhf | public static bool ConnTestAndCreateTable() |
28 | { |
||
29 | bool result = false; |
||
30 | ID2Info id2Info = ID2Info.GetInstance(); |
||
31 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, @"Data Source = {0}", id2Info.DBFilePath), true)) |
||
32 | { |
||
33 | try |
||
34 | { |
||
35 | connection.Open(); |
||
36 | if (connection.State == ConnectionState.Open) |
||
37 | { |
||
38 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
39 | { |
||
40 | cmd.CommandText = "SELECT NAME FROM sqlite_master WHERE type='table'"; |
||
41 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
42 | using (DataTable dt = new DataTable()) |
||
43 | { |
||
44 | dt.Load(dr); |
||
45 | 0dae5645 | gaqhf | |
46 | 6b9e7a56 | gaqhf | if (dt.Select(string.Format("NAME = '{0}'", PSN_HEADER_SETTING)).Length == 0) |
47 | { |
||
48 | cmd.CommandText = string.Format("CREATE TABLE {0} (GROUP_ID TEXT, DESCRIPTION TEXT, [INDEX] INTEGER, NAME TEXT)", PSN_HEADER_SETTING); |
||
49 | cmd.ExecuteNonQuery(); |
||
50 | } |
||
51 | if (dt.Select(string.Format("NAME = '{0}'", PSN_TOPOLOGY_RULE)).Length == 0) |
||
52 | { |
||
53 | cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT)", PSN_TOPOLOGY_RULE); |
||
54 | cmd.ExecuteNonQuery(); |
||
55 | 721b754d | gaqhf | |
56 | DataTable topologyRule = new DataTable(); |
||
57 | topologyRule.Columns.Add("NAME", typeof(string)); |
||
58 | |||
59 | topologyRule.Rows.Add("FluidCode"); |
||
60 | topologyRule.Rows.Add("-"); |
||
61 | topologyRule.Rows.Add("PipingMaterialsClass"); |
||
62 | topologyRule.Rows.Add("-"); |
||
63 | topologyRule.Rows.Add("Tag Seq No"); |
||
64 | |||
65 | SaveTopologyRule(topologyRule); |
||
66 | 6b9e7a56 | gaqhf | } |
67 | if (dt.Select(string.Format("NAME = '{0}'", PSN_PATHITEMS)).Length == 0) |
||
68 | { |
||
69 | cmd.CommandText = string.Format("CREATE TABLE {0} (OID TEXT, SequenceData_OID TEXT, TopologySet_OID TEXT, BranchTopologySet_OID TEXT, PipeLine_OID TEXT, ITEMNAME TEXT, ITEMTAG TEXT, TYPE TEXT, PIDNAME TEXT, NPD TEXT, PipeSystemNetwork_OID TEXT, PipeRun_OID TEXT)", PSN_PATHITEMS); |
||
70 | cmd.ExecuteNonQuery(); |
||
71 | } |
||
72 | if (dt.Select(string.Format("NAME = '{0}'", PSN_SEQUENCEDATA)).Length == 0) |
||
73 | { |
||
74 | cmd.CommandText = string.Format("CREATE TABLE {0} (OID TEXT, SERIALNUMBER TEXT, PathItem_OID TEXT, TopologySet_OID_Key TEXT)", PSN_SEQUENCEDATA); |
||
75 | cmd.ExecuteNonQuery(); |
||
76 | } |
||
77 | if (dt.Select(string.Format("NAME = '{0}'", PSN_PIPESYSTEMNETWORK)).Length == 0) |
||
78 | { |
||
79 | cmd.CommandText = string.Format("CREATE TABLE {0} (OID TEXT, Type TEXT, OrderNumber TEXT, Pipeline_OID TEXT, FROM_DATA TEXT, TO_DATA TEXT, TopologySet_OID_Key TEXT, PSNRevisionNumber TEXT, PathOID TEXT, PBS TEXT, PIDDrawings TEXT)", PSN_PIPESYSTEMNETWORK); |
||
80 | cmd.ExecuteNonQuery(); |
||
81 | } |
||
82 | |||
83 | if (dt.Select(string.Format("NAME = '{0}'", PSN_EQUIPMENT)).Length == 0) |
||
84 | { |
||
85 | cmd.CommandText = string.Format("CREATE TABLE {0} (OID TEXT, ITEMTAG TEXT, XCOORDS TEXT, YCOORDS TEXT)", PSN_EQUIPMENT); |
||
86 | cmd.ExecuteNonQuery(); |
||
87 | } |
||
88 | if (dt.Select(string.Format("NAME = '{0}'", PSN_NOZZLE)).Length == 0) |
||
89 | { |
||
90 | cmd.CommandText = string.Format("CREATE TABLE {0} (OID TEXT, ITEMTAG TEXT, XCOORDS TEXT, YCOORDS TEXT, Equipment_OID TEXT, FLUID TEXT, NPD TEXT, ROTATION TEXT, FlowDirection TEXT)", PSN_NOZZLE); |
||
91 | cmd.ExecuteNonQuery(); |
||
92 | } |
||
93 | if (dt.Select(string.Format("NAME = '{0}'", PSN_FLUIDCODE)).Length == 0) |
||
94 | { |
||
95 | 8f24b438 | gaqhf | cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT, Code TEXT, Description TEXT, Condition TEXT, Remarks TEXT, GroundLevel TEXT)", PSN_FLUIDCODE); |
96 | 6b9e7a56 | gaqhf | cmd.ExecuteNonQuery(); |
97 | } |
||
98 | if (dt.Select(string.Format("NAME = '{0}'", PSN_PIPINGMATLCLASS)).Length == 0) |
||
99 | { |
||
100 | 8f24b438 | gaqhf | cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT, Priority TEXT, Code TEXT, Description TEXT, Condition TEXT, Remarks TEXT, GroundLevel TEXT)", PSN_PIPINGMATLCLASS); |
101 | 6b9e7a56 | gaqhf | cmd.ExecuteNonQuery(); |
102 | } |
||
103 | 5c248ee3 | gaqhf | if (dt.Select(string.Format("NAME = '{0}'", PSN_VIEW)).Length == 0) |
104 | { |
||
105 | cmd.CommandText = string.Format("CREATE TABLE {0} (OID TEXT)", PSN_VIEW); |
||
106 | cmd.ExecuteNonQuery(); |
||
107 | } |
||
108 | 6b9e7a56 | gaqhf | } |
109 | } |
||
110 | result = true; |
||
111 | } |
||
112 | connection.Close(); |
||
113 | } |
||
114 | catch (Exception ex) |
||
115 | { |
||
116 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
117 | } |
||
118 | finally |
||
119 | { |
||
120 | connection.Dispose(); |
||
121 | } |
||
122 | } |
||
123 | return result; |
||
124 | } |
||
125 | |||
126 | public static DataTable SelectHeaderSetting() |
||
127 | { |
||
128 | DataTable dt = new DataTable(); |
||
129 | ID2Info id2Info = ID2Info.GetInstance(); |
||
130 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
131 | { |
||
132 | try |
||
133 | { |
||
134 | connection.Open(); |
||
135 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
136 | { |
||
137 | cmd.CommandText = string.Format(@"SELECT GROUP_ID, DESCRIPTION, [INDEX], NAME FROM {0};", PSN_HEADER_SETTING); |
||
138 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
139 | dt.Load(dr); |
||
140 | } |
||
141 | connection.Close(); |
||
142 | } |
||
143 | catch (Exception ex) |
||
144 | { |
||
145 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
146 | } |
||
147 | finally |
||
148 | { |
||
149 | connection.Dispose(); |
||
150 | } |
||
151 | } |
||
152 | return dt; |
||
153 | } |
||
154 | |||
155 | public static bool SaveHeaderSetting(List<HeaderInfo> headerInfos) |
||
156 | { |
||
157 | ID2Info id2Info = ID2Info.GetInstance(); |
||
158 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
159 | { |
||
160 | try |
||
161 | { |
||
162 | connection.Open(); |
||
163 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
164 | { |
||
165 | cmd.CommandText = string.Format("DELETE FROM {0}", PSN_HEADER_SETTING); |
||
166 | cmd.ExecuteNonQuery(); |
||
167 | |||
168 | foreach (HeaderInfo headerInfo in headerInfos) |
||
169 | { |
||
170 | foreach (HeaderItem item in headerInfo.HeaderItems) |
||
171 | { |
||
172 | cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@GROUP_ID, @DESCRIPTION, @INDEX, @NAME)", PSN_HEADER_SETTING); |
||
173 | cmd.Parameters.Clear(); |
||
174 | cmd.Parameters.AddWithValue("@GROUP_ID", headerInfo.UID); |
||
175 | cmd.Parameters.AddWithValue("@DESCRIPTION", headerInfo.Description); |
||
176 | cmd.Parameters.AddWithValue("@INDEX", item.Index); |
||
177 | cmd.Parameters.AddWithValue("@NAME", item.Name); |
||
178 | cmd.ExecuteNonQuery(); |
||
179 | } |
||
180 | } |
||
181 | } |
||
182 | connection.Close(); |
||
183 | } |
||
184 | catch (Exception ex) |
||
185 | { |
||
186 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
187 | return false; |
||
188 | } |
||
189 | finally |
||
190 | { |
||
191 | connection.Dispose(); |
||
192 | } |
||
193 | } |
||
194 | return true; |
||
195 | } |
||
196 | |||
197 | public static DataTable SelectOPCRelations() |
||
198 | { |
||
199 | DataTable dt = new DataTable(); |
||
200 | ID2Info id2Info = ID2Info.GetInstance(); |
||
201 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
202 | { |
||
203 | try |
||
204 | { |
||
205 | connection.Open(); |
||
206 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
207 | { |
||
208 | cmd.CommandText = "SELECT * FROM OPCRelations;"; |
||
209 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
210 | dt.Load(dr); |
||
211 | } |
||
212 | connection.Close(); |
||
213 | } |
||
214 | catch (Exception ex) |
||
215 | { |
||
216 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
217 | } |
||
218 | finally |
||
219 | { |
||
220 | connection.Dispose(); |
||
221 | } |
||
222 | } |
||
223 | return dt; |
||
224 | } |
||
225 | |||
226 | public static DataTable SelectDrawings() |
||
227 | { |
||
228 | DataTable dt = new DataTable(); |
||
229 | ID2Info id2Info = ID2Info.GetInstance(); |
||
230 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
231 | { |
||
232 | try |
||
233 | { |
||
234 | connection.Open(); |
||
235 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
236 | { |
||
237 | cmd.CommandText = "SELECT * FROM Drawings;"; |
||
238 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
239 | dt.Load(dr); |
||
240 | } |
||
241 | connection.Close(); |
||
242 | } |
||
243 | catch (Exception ex) |
||
244 | { |
||
245 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
246 | } |
||
247 | finally |
||
248 | { |
||
249 | connection.Dispose(); |
||
250 | } |
||
251 | } |
||
252 | return dt; |
||
253 | } |
||
254 | |||
255 | public static DataTable SelectLineProperties() |
||
256 | { |
||
257 | DataTable dt = new DataTable(); |
||
258 | ID2Info id2Info = ID2Info.GetInstance(); |
||
259 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
260 | { |
||
261 | try |
||
262 | { |
||
263 | connection.Open(); |
||
264 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
265 | { |
||
266 | cmd.CommandText = "SELECT * FROM LineProperties;"; |
||
267 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
268 | dt.Load(dr); |
||
269 | } |
||
270 | connection.Close(); |
||
271 | } |
||
272 | catch (Exception ex) |
||
273 | { |
||
274 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
275 | } |
||
276 | finally |
||
277 | { |
||
278 | connection.Dispose(); |
||
279 | } |
||
280 | } |
||
281 | return dt; |
||
282 | } |
||
283 | public static DataTable SelectTopologyRule() |
||
284 | { |
||
285 | DataTable dt = new DataTable(); |
||
286 | ID2Info id2Info = ID2Info.GetInstance(); |
||
287 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
288 | { |
||
289 | try |
||
290 | { |
||
291 | connection.Open(); |
||
292 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
293 | { |
||
294 | cmd.CommandText = string.Format(@"SELECT * FROM {0};", PSN_TOPOLOGY_RULE); |
||
295 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
296 | dt.Load(dr); |
||
297 | } |
||
298 | connection.Close(); |
||
299 | } |
||
300 | catch (Exception ex) |
||
301 | { |
||
302 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
303 | } |
||
304 | finally |
||
305 | { |
||
306 | connection.Dispose(); |
||
307 | } |
||
308 | } |
||
309 | return dt; |
||
310 | } |
||
311 | public static bool SaveTopologyRule(DataTable dt) |
||
312 | { |
||
313 | ID2Info id2Info = ID2Info.GetInstance(); |
||
314 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
315 | { |
||
316 | try |
||
317 | { |
||
318 | connection.Open(); |
||
319 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
320 | { |
||
321 | cmd.CommandText = string.Format("DELETE FROM {0}", PSN_TOPOLOGY_RULE); |
||
322 | cmd.ExecuteNonQuery(); |
||
323 | |||
324 | foreach (DataRow row in dt.Rows) |
||
325 | { |
||
326 | cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@UID)", PSN_TOPOLOGY_RULE); |
||
327 | cmd.Parameters.Clear(); |
||
328 | cmd.Parameters.AddWithValue("@UID", row["NAME"].ToString()); |
||
329 | cmd.ExecuteNonQuery(); |
||
330 | } |
||
331 | } |
||
332 | connection.Close(); |
||
333 | } |
||
334 | catch (Exception ex) |
||
335 | { |
||
336 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
337 | return false; |
||
338 | } |
||
339 | finally |
||
340 | { |
||
341 | connection.Dispose(); |
||
342 | } |
||
343 | } |
||
344 | return true; |
||
345 | } |
||
346 | |||
347 | public static DataTable SelectFluidCode() |
||
348 | { |
||
349 | DataTable dt = new DataTable(); |
||
350 | ID2Info id2Info = ID2Info.GetInstance(); |
||
351 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
352 | { |
||
353 | try |
||
354 | { |
||
355 | connection.Open(); |
||
356 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
357 | { |
||
358 | cmd.CommandText = "SELECT * FROM FluidCode;"; |
||
359 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
360 | dt.Load(dr); |
||
361 | } |
||
362 | connection.Close(); |
||
363 | } |
||
364 | catch (Exception ex) |
||
365 | { |
||
366 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
367 | } |
||
368 | finally |
||
369 | { |
||
370 | connection.Dispose(); |
||
371 | } |
||
372 | } |
||
373 | return dt; |
||
374 | } |
||
375 | public static DataTable SelectPipingMaterialsClass() |
||
376 | { |
||
377 | DataTable dt = new DataTable(); |
||
378 | ID2Info id2Info = ID2Info.GetInstance(); |
||
379 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
380 | { |
||
381 | try |
||
382 | { |
||
383 | connection.Open(); |
||
384 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
385 | { |
||
386 | cmd.CommandText = "SELECT * FROM PipingMaterialsClass;"; |
||
387 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
388 | dt.Load(dr); |
||
389 | } |
||
390 | connection.Close(); |
||
391 | } |
||
392 | catch (Exception ex) |
||
393 | { |
||
394 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
395 | } |
||
396 | finally |
||
397 | { |
||
398 | connection.Dispose(); |
||
399 | } |
||
400 | } |
||
401 | return dt; |
||
402 | } |
||
403 | |||
404 | public static DataTable SelectPSNFluidCode() |
||
405 | { |
||
406 | DataTable dt = new DataTable(); |
||
407 | ID2Info id2Info = ID2Info.GetInstance(); |
||
408 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
409 | { |
||
410 | try |
||
411 | { |
||
412 | connection.Open(); |
||
413 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
414 | { |
||
415 | cmd.CommandText = string.Format("SELECT * FROM {0}", PSN_FLUIDCODE); |
||
416 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
417 | dt.Load(dr); |
||
418 | } |
||
419 | connection.Close(); |
||
420 | } |
||
421 | catch (Exception ex) |
||
422 | { |
||
423 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
424 | } |
||
425 | finally |
||
426 | { |
||
427 | connection.Dispose(); |
||
428 | } |
||
429 | } |
||
430 | return dt; |
||
431 | } |
||
432 | public static DataTable SelectPSNPIPINGMATLCLASS() |
||
433 | { |
||
434 | DataTable dt = new DataTable(); |
||
435 | ID2Info id2Info = ID2Info.GetInstance(); |
||
436 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
437 | { |
||
438 | try |
||
439 | { |
||
440 | connection.Open(); |
||
441 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
442 | { |
||
443 | cmd.CommandText = string.Format("SELECT * FROM {0}", PSN_PIPINGMATLCLASS); |
||
444 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
445 | dt.Load(dr); |
||
446 | } |
||
447 | connection.Close(); |
||
448 | } |
||
449 | catch (Exception ex) |
||
450 | { |
||
451 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
452 | } |
||
453 | finally |
||
454 | { |
||
455 | connection.Dispose(); |
||
456 | } |
||
457 | } |
||
458 | return dt; |
||
459 | } |
||
460 | public static DataTable SelectNominalDiameter() |
||
461 | { |
||
462 | DataTable dt = new DataTable(); |
||
463 | ID2Info id2Info = ID2Info.GetInstance(); |
||
464 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
465 | { |
||
466 | try |
||
467 | { |
||
468 | connection.Open(); |
||
469 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
470 | { |
||
471 | 678760c6 | gaqhf | cmd.CommandText = "SELECT * FROM NominalDiameter ORDER BY Metric DESC;"; |
472 | 6b9e7a56 | gaqhf | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
473 | dt.Load(dr); |
||
474 | } |
||
475 | connection.Close(); |
||
476 | } |
||
477 | catch (Exception ex) |
||
478 | { |
||
479 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
480 | } |
||
481 | finally |
||
482 | { |
||
483 | connection.Dispose(); |
||
484 | } |
||
485 | } |
||
486 | 678760c6 | gaqhf | |
487 | dt.Rows.RemoveAt(0); |
||
488 | dt.Rows.RemoveAt(0); |
||
489 | dt.Rows.RemoveAt(0); |
||
490 | dt.Rows.RemoveAt(0); |
||
491 | |||
492 | 6b9e7a56 | gaqhf | return dt; |
493 | } |
||
494 | |||
495 | 5c248ee3 | gaqhf | public static bool SavePSNData(PSN item) |
496 | 6b9e7a56 | gaqhf | { |
497 | ID2Info id2Info = ID2Info.GetInstance(); |
||
498 | |||
499 | bool result = true; |
||
500 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
501 | { |
||
502 | try |
||
503 | { |
||
504 | connection.Open(); |
||
505 | |||
506 | using (SQLiteTransaction transaction = connection.BeginTransaction()) |
||
507 | { |
||
508 | try |
||
509 | { |
||
510 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
511 | { |
||
512 | 5c248ee3 | gaqhf | // Path Items |
513 | cmd.CommandText = string.Format("DELETE FROM {0}", PSN_PATHITEMS); |
||
514 | 6b9e7a56 | gaqhf | cmd.ExecuteNonQuery(); |
515 | 5c248ee3 | gaqhf | foreach (DataRow row in item.PathItems.Rows) |
516 | { |
||
517 | cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@OID, @SequenceData_OID, @TopologySet_OID, @BranchTopologySet_OID, @PipeLine_OID, @ITEMNAME, @ITEMTAG, @TYPE, @PIDNAME, @NPD, @PipeSystemNetwork_OID, @PipeRun_OID)", PSN_PATHITEMS); |
||
518 | cmd.Parameters.Clear(); |
||
519 | cmd.Parameters.AddWithValue("@OID", row["OID"].ToString()); |
||
520 | cmd.Parameters.AddWithValue("@SequenceData_OID", row["SequenceData_OID"].ToString()); |
||
521 | cmd.Parameters.AddWithValue("@TopologySet_OID", row["TopologySet_OID"].ToString()); |
||
522 | cmd.Parameters.AddWithValue("@BranchTopologySet_OID", row["BranchTopologySet_OID"].ToString()); |
||
523 | cmd.Parameters.AddWithValue("@PipeLine_OID", row["PipeLine_OID"].ToString()); |
||
524 | cmd.Parameters.AddWithValue("@ITEMNAME", row["ITEMNAME"].ToString()); |
||
525 | cmd.Parameters.AddWithValue("@ITEMTAG", row["ITEMTAG"].ToString()); |
||
526 | cmd.Parameters.AddWithValue("@TYPE", row["TYPE"].ToString()); |
||
527 | cmd.Parameters.AddWithValue("@PIDNAME", row["PIDNAME"].ToString()); |
||
528 | cmd.Parameters.AddWithValue("@NPD", row["NPD"].ToString()); |
||
529 | cmd.Parameters.AddWithValue("@PipeSystemNetwork_OID", row["PipeSystemNetwork_OID"].ToString()); |
||
530 | cmd.Parameters.AddWithValue("@PipeRun_OID", row["PipeRun_OID"].ToString()); |
||
531 | cmd.ExecuteNonQuery(); |
||
532 | } |
||
533 | 6b9e7a56 | gaqhf | |
534 | 5c248ee3 | gaqhf | // Sequence |
535 | cmd.CommandText = string.Format("DELETE FROM {0}", PSN_SEQUENCEDATA); |
||
536 | cmd.ExecuteNonQuery(); |
||
537 | foreach (DataRow row in item.SequenceData.Rows) |
||
538 | 6b9e7a56 | gaqhf | { |
539 | 5c248ee3 | gaqhf | cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@OID, @SERIALNUMBER, @PathItem_OID, @TopologySet_OID_Key)", PSN_SEQUENCEDATA); |
540 | 6b9e7a56 | gaqhf | cmd.Parameters.Clear(); |
541 | 5c248ee3 | gaqhf | cmd.Parameters.AddWithValue("@OID", row["OID"].ToString()); |
542 | cmd.Parameters.AddWithValue("@SERIALNUMBER", row["SERIALNUMBER"].ToString()); |
||
543 | cmd.Parameters.AddWithValue("@PathItem_OID", row["PathItem_OID"].ToString()); |
||
544 | cmd.Parameters.AddWithValue("@TopologySet_OID_Key", row["TopologySet_OID_Key"].ToString()); |
||
545 | cmd.ExecuteNonQuery(); |
||
546 | } |
||
547 | |||
548 | // Nozzle |
||
549 | cmd.CommandText = string.Format("DELETE FROM {0}", PSN_NOZZLE); |
||
550 | cmd.ExecuteNonQuery(); |
||
551 | foreach (DataRow row in item.Nozzle.Rows) |
||
552 | { |
||
553 | cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@OID, @ITEMTAG, @XCOORDS, @YCOORDS, @Equipment_OID, @FLUID, @NPD, @ROTATION, @FlowDirection)", PSN_NOZZLE); |
||
554 | cmd.Parameters.Clear(); |
||
555 | cmd.Parameters.AddWithValue("@OID", row["OID"].ToString()); |
||
556 | cmd.Parameters.AddWithValue("@ITEMTAG", row["ITEMTAG"].ToString()); |
||
557 | cmd.Parameters.AddWithValue("@XCOORDS", row["XCOORDS"].ToString()); |
||
558 | cmd.Parameters.AddWithValue("@YCOORDS", row["YCOORDS"].ToString()); |
||
559 | cmd.Parameters.AddWithValue("@Equipment_OID", row["Equipment_OID"].ToString()); |
||
560 | cmd.Parameters.AddWithValue("@FLUID", row["FLUID"].ToString()); |
||
561 | cmd.Parameters.AddWithValue("@NPD", row["NPD"].ToString()); |
||
562 | cmd.Parameters.AddWithValue("@ROTATION", row["ROTATION"].ToString()); |
||
563 | cmd.Parameters.AddWithValue("@FlowDirection", row["FlowDirection"].ToString()); |
||
564 | cmd.ExecuteNonQuery(); |
||
565 | } |
||
566 | |||
567 | //Equipment |
||
568 | cmd.CommandText = string.Format("DELETE FROM {0}", PSN_EQUIPMENT); |
||
569 | cmd.ExecuteNonQuery(); |
||
570 | foreach (DataRow row in item.Equipment.Rows) |
||
571 | { |
||
572 | cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@OID, @ITEMTAG, @XCOORDS, @YCOORDS)", PSN_EQUIPMENT); |
||
573 | cmd.Parameters.Clear(); |
||
574 | cmd.Parameters.AddWithValue("@OID", row["OID"].ToString()); |
||
575 | cmd.Parameters.AddWithValue("@ITEMTAG", row["ITEMTAG"].ToString()); |
||
576 | cmd.Parameters.AddWithValue("@XCOORDS", row["XCOORDS"].ToString()); |
||
577 | cmd.Parameters.AddWithValue("@YCOORDS", row["YCOORDS"].ToString()); |
||
578 | cmd.ExecuteNonQuery(); |
||
579 | } |
||
580 | |||
581 | // PSN |
||
582 | cmd.CommandText = string.Format("DELETE FROM {0} WHERE PSNRevisionNumber = '{1}'", PSN_PIPESYSTEMNETWORK, string.Format("{0:D3}", item.Revision)); |
||
583 | cmd.ExecuteNonQuery(); |
||
584 | foreach (DataRow row in item.PipeSystemNetwork.Rows) |
||
585 | { |
||
586 | cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@OID, @Type, @OrderNumber, @Pipeline_OID, @FROM_DATA, @TO_DATA, @TopologySet_OID_Key, @PSNRevisionNumber, @PathOID, @PBS, @PIDDrawings)", PSN_PIPESYSTEMNETWORK); |
||
587 | cmd.Parameters.Clear(); |
||
588 | cmd.Parameters.AddWithValue("@OID", row["OID"].ToString()); |
||
589 | cmd.Parameters.AddWithValue("@Type", row["Type"].ToString()); |
||
590 | cmd.Parameters.AddWithValue("@OrderNumber", row["OrderNumber"].ToString()); |
||
591 | cmd.Parameters.AddWithValue("@Pipeline_OID", row["Pipeline_OID"].ToString()); |
||
592 | cmd.Parameters.AddWithValue("@FROM_DATA", row["FROM_DATA"].ToString()); |
||
593 | cmd.Parameters.AddWithValue("@TO_DATA", row["TO_DATA"].ToString()); |
||
594 | cmd.Parameters.AddWithValue("@TopologySet_OID_Key", row["TopologySet_OID_Key"].ToString()); |
||
595 | cmd.Parameters.AddWithValue("@PSNRevisionNumber", row["PSNRevisionNumber"].ToString()); |
||
596 | cmd.Parameters.AddWithValue("@PathOID", row["PathOID"].ToString()); |
||
597 | cmd.Parameters.AddWithValue("@PBS", row["PBS"].ToString()); |
||
598 | cmd.Parameters.AddWithValue("@PIDDrawings", row["PIDDrawings"].ToString()); |
||
599 | 6b9e7a56 | gaqhf | cmd.ExecuteNonQuery(); |
600 | } |
||
601 | 5c248ee3 | gaqhf | |
602 | 6b9e7a56 | gaqhf | } |
603 | transaction.Commit(); |
||
604 | connection.Close(); |
||
605 | } |
||
606 | catch (Exception ex) |
||
607 | { |
||
608 | transaction.Rollback(); |
||
609 | result = false; |
||
610 | } |
||
611 | finally |
||
612 | { |
||
613 | transaction.Dispose(); |
||
614 | } |
||
615 | } |
||
616 | } |
||
617 | catch (Exception ex) |
||
618 | { |
||
619 | System.Windows.Forms.MessageBox.Show(ex.Message); |
||
620 | result = false; |
||
621 | } |
||
622 | finally |
||
623 | { |
||
624 | connection.Dispose(); |
||
625 | } |
||
626 | } |
||
627 | |||
628 | return result; |
||
629 | } |
||
630 | |||
631 | 5c248ee3 | gaqhf | public static bool SavePSNFluidCode(DataTable dt) |
632 | 6b9e7a56 | gaqhf | { |
633 | ID2Info id2Info = ID2Info.GetInstance(); |
||
634 | |||
635 | bool result = true; |
||
636 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
637 | { |
||
638 | try |
||
639 | { |
||
640 | connection.Open(); |
||
641 | |||
642 | using (SQLiteTransaction transaction = connection.BeginTransaction()) |
||
643 | { |
||
644 | try |
||
645 | { |
||
646 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
647 | { |
||
648 | 5c248ee3 | gaqhf | cmd.CommandText = string.Format("DELETE FROM {0}", PSN_FLUIDCODE); |
649 | 6b9e7a56 | gaqhf | cmd.ExecuteNonQuery(); |
650 | |||
651 | foreach (DataRow row in dt.Rows) |
||
652 | { |
||
653 | 5c248ee3 | gaqhf | cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@UID, @Code, @Description, @Condition, @Remarks, @GroundLevel)", PSN_FLUIDCODE); |
654 | 6b9e7a56 | gaqhf | cmd.Parameters.Clear(); |
655 | cmd.Parameters.AddWithValue("@UID", row["UID"].ToString()); |
||
656 | cmd.Parameters.AddWithValue("@Code", row["Code"].ToString()); |
||
657 | cmd.Parameters.AddWithValue("@Description", row["Description"].ToString()); |
||
658 | cmd.Parameters.AddWithValue("@Condition", row["Condition"].ToString()); |
||
659 | 8f24b438 | gaqhf | cmd.Parameters.AddWithValue("@Remarks", row["Remarks"].ToString()); |
660 | 6b9e7a56 | gaqhf | cmd.Parameters.AddWithValue("@GroundLevel", row["GroundLevel"].ToString()); |
661 | cmd.ExecuteNonQuery(); |
||
662 | } |
||
663 | } |
||
664 | transaction.Commit(); |
||
665 | connection.Close(); |
||
666 | } |
||
667 | catch (Exception ex) |
||
668 | { |
||
669 | transaction.Rollback(); |
||
670 | result = false; |
||
671 | } |
||
672 | finally |
||
673 | { |
||
674 | transaction.Dispose(); |
||
675 | } |
||
676 | } |
||
677 | } |
||
678 | catch (Exception ex) |
||
679 | { |
||
680 | System.Windows.Forms.MessageBox.Show(ex.Message); |
||
681 | result = false; |
||
682 | } |
||
683 | finally |
||
684 | { |
||
685 | connection.Dispose(); |
||
686 | } |
||
687 | } |
||
688 | |||
689 | return result; |
||
690 | } |
||
691 | |||
692 | 5c248ee3 | gaqhf | public static bool SavePSNPMC(DataTable dt) |
693 | 6b9e7a56 | gaqhf | { |
694 | ID2Info id2Info = ID2Info.GetInstance(); |
||
695 | |||
696 | bool result = true; |
||
697 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
698 | { |
||
699 | try |
||
700 | { |
||
701 | connection.Open(); |
||
702 | |||
703 | using (SQLiteTransaction transaction = connection.BeginTransaction()) |
||
704 | { |
||
705 | try |
||
706 | { |
||
707 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
708 | { |
||
709 | 5c248ee3 | gaqhf | cmd.CommandText = string.Format("DELETE FROM {0}", PSN_PIPINGMATLCLASS); |
710 | 6b9e7a56 | gaqhf | cmd.ExecuteNonQuery(); |
711 | |||
712 | foreach (DataRow row in dt.Rows) |
||
713 | { |
||
714 | 5c248ee3 | gaqhf | cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@UID, @Priority, @Code, @Description, @Condition, @Remarks, @GroundLevel)", PSN_PIPINGMATLCLASS); |
715 | 6b9e7a56 | gaqhf | cmd.Parameters.Clear(); |
716 | 5c248ee3 | gaqhf | cmd.Parameters.AddWithValue("@UID", row["UID"].ToString()); |
717 | cmd.Parameters.AddWithValue("@Priority", row["Priority"].ToString()); |
||
718 | cmd.Parameters.AddWithValue("@Code", row["Code"].ToString()); |
||
719 | cmd.Parameters.AddWithValue("@Description", row["Description"].ToString()); |
||
720 | cmd.Parameters.AddWithValue("@Condition", row["Condition"].ToString()); |
||
721 | cmd.Parameters.AddWithValue("@Remarks", row["Remarks"].ToString()); |
||
722 | cmd.Parameters.AddWithValue("@GroundLevel", row["GroundLevel"].ToString()); |
||
723 | 6b9e7a56 | gaqhf | cmd.ExecuteNonQuery(); |
724 | } |
||
725 | } |
||
726 | transaction.Commit(); |
||
727 | connection.Close(); |
||
728 | } |
||
729 | catch (Exception ex) |
||
730 | { |
||
731 | transaction.Rollback(); |
||
732 | result = false; |
||
733 | } |
||
734 | finally |
||
735 | { |
||
736 | transaction.Dispose(); |
||
737 | } |
||
738 | } |
||
739 | } |
||
740 | catch (Exception ex) |
||
741 | { |
||
742 | System.Windows.Forms.MessageBox.Show(ex.Message); |
||
743 | result = false; |
||
744 | } |
||
745 | finally |
||
746 | { |
||
747 | connection.Dispose(); |
||
748 | } |
||
749 | } |
||
750 | |||
751 | return result; |
||
752 | } |
||
753 | |||
754 | 5c248ee3 | gaqhf | public static bool SaveView(List<string> values) |
755 | 6b9e7a56 | gaqhf | { |
756 | ID2Info id2Info = ID2Info.GetInstance(); |
||
757 | |||
758 | bool result = true; |
||
759 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
760 | { |
||
761 | try |
||
762 | { |
||
763 | connection.Open(); |
||
764 | |||
765 | using (SQLiteTransaction transaction = connection.BeginTransaction()) |
||
766 | { |
||
767 | try |
||
768 | { |
||
769 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
770 | { |
||
771 | 5c248ee3 | gaqhf | cmd.CommandText = string.Format("DELETE FROM {0}", PSN_VIEW); |
772 | 6b9e7a56 | gaqhf | cmd.ExecuteNonQuery(); |
773 | |||
774 | 5c248ee3 | gaqhf | foreach (string value in values) |
775 | 6b9e7a56 | gaqhf | { |
776 | 5c248ee3 | gaqhf | cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@OID)", PSN_VIEW); |
777 | 6b9e7a56 | gaqhf | cmd.Parameters.Clear(); |
778 | 5c248ee3 | gaqhf | cmd.Parameters.AddWithValue("@OID", value); |
779 | 6b9e7a56 | gaqhf | cmd.ExecuteNonQuery(); |
780 | } |
||
781 | } |
||
782 | transaction.Commit(); |
||
783 | connection.Close(); |
||
784 | } |
||
785 | catch (Exception ex) |
||
786 | { |
||
787 | transaction.Rollback(); |
||
788 | result = false; |
||
789 | } |
||
790 | finally |
||
791 | { |
||
792 | transaction.Dispose(); |
||
793 | } |
||
794 | } |
||
795 | } |
||
796 | catch (Exception ex) |
||
797 | { |
||
798 | System.Windows.Forms.MessageBox.Show(ex.Message); |
||
799 | result = false; |
||
800 | } |
||
801 | finally |
||
802 | { |
||
803 | connection.Dispose(); |
||
804 | } |
||
805 | } |
||
806 | |||
807 | return result; |
||
808 | } |
||
809 | 5c248ee3 | gaqhf | public static bool DeleteView() |
810 | 6b9e7a56 | gaqhf | { |
811 | ID2Info id2Info = ID2Info.GetInstance(); |
||
812 | |||
813 | bool result = true; |
||
814 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
815 | { |
||
816 | try |
||
817 | { |
||
818 | connection.Open(); |
||
819 | |||
820 | using (SQLiteTransaction transaction = connection.BeginTransaction()) |
||
821 | { |
||
822 | try |
||
823 | { |
||
824 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
825 | { |
||
826 | 5c248ee3 | gaqhf | cmd.CommandText = string.Format("DELETE FROM {0}", PSN_VIEW); |
827 | 6b9e7a56 | gaqhf | cmd.ExecuteNonQuery(); |
828 | } |
||
829 | transaction.Commit(); |
||
830 | connection.Close(); |
||
831 | } |
||
832 | catch (Exception ex) |
||
833 | { |
||
834 | transaction.Rollback(); |
||
835 | result = false; |
||
836 | } |
||
837 | finally |
||
838 | { |
||
839 | transaction.Dispose(); |
||
840 | } |
||
841 | } |
||
842 | } |
||
843 | catch (Exception ex) |
||
844 | { |
||
845 | System.Windows.Forms.MessageBox.Show(ex.Message); |
||
846 | result = false; |
||
847 | } |
||
848 | finally |
||
849 | { |
||
850 | connection.Dispose(); |
||
851 | } |
||
852 | } |
||
853 | |||
854 | return result; |
||
855 | } |
||
856 | |||
857 | 5c248ee3 | gaqhf | public static PSN GetDBPSN() |
858 | 6b9e7a56 | gaqhf | { |
859 | 5c248ee3 | gaqhf | PSN result = new PSN(); |
860 | 6b9e7a56 | gaqhf | ID2Info id2Info = ID2Info.GetInstance(); |
861 | |||
862 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
863 | { |
||
864 | try |
||
865 | { |
||
866 | connection.Open(); |
||
867 | |||
868 | using (SQLiteTransaction transaction = connection.BeginTransaction()) |
||
869 | { |
||
870 | try |
||
871 | { |
||
872 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
873 | { |
||
874 | 5c248ee3 | gaqhf | DataTable psnDT = new DataTable(); |
875 | cmd.CommandText = string.Format("SELECT * FROM {0} WHERE PSNRevisionNumber = '{1}'", PSN_PIPESYSTEMNETWORK, string.Format("{0:D3}", GetRevision())); |
||
876 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
877 | psnDT.Load(dr); |
||
878 | result.PipeSystemNetwork = psnDT; |
||
879 | 6b9e7a56 | gaqhf | |
880 | 5c248ee3 | gaqhf | DataTable equipDT = new DataTable(); |
881 | cmd.CommandText = string.Format("SELECT * FROM {0}", PSN_EQUIPMENT); |
||
882 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
883 | equipDT.Load(dr); |
||
884 | result.Equipment = equipDT; |
||
885 | 6b9e7a56 | gaqhf | |
886 | 5c248ee3 | gaqhf | DataTable nozzleDT = new DataTable(); |
887 | cmd.CommandText = string.Format("SELECT * FROM {0}", PSN_NOZZLE); |
||
888 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
889 | nozzleDT.Load(dr); |
||
890 | result.Nozzle = nozzleDT; |
||
891 | 6b9e7a56 | gaqhf | |
892 | 5c248ee3 | gaqhf | DataTable pathItemDT = new DataTable(); |
893 | cmd.CommandText = string.Format("SELECT * FROM {0}", PSN_PATHITEMS); |
||
894 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
895 | pathItemDT.Load(dr); |
||
896 | result.PathItems = pathItemDT; |
||
897 | 6b9e7a56 | gaqhf | |
898 | 5c248ee3 | gaqhf | DataTable seqDT = new DataTable(); |
899 | cmd.CommandText = string.Format("SELECT * FROM {0}", PSN_SEQUENCEDATA); |
||
900 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
901 | seqDT.Load(dr); |
||
902 | result.SequenceData = seqDT; |
||
903 | 6b9e7a56 | gaqhf | |
904 | 5c248ee3 | gaqhf | result.Revision = GetRevision(); |
905 | 6b9e7a56 | gaqhf | } |
906 | transaction.Commit(); |
||
907 | connection.Close(); |
||
908 | } |
||
909 | catch (Exception ex) |
||
910 | { |
||
911 | transaction.Rollback(); |
||
912 | 5c248ee3 | gaqhf | result = null; |
913 | 6b9e7a56 | gaqhf | } |
914 | finally |
||
915 | { |
||
916 | transaction.Dispose(); |
||
917 | } |
||
918 | } |
||
919 | } |
||
920 | catch (Exception ex) |
||
921 | { |
||
922 | System.Windows.Forms.MessageBox.Show(ex.Message); |
||
923 | 5c248ee3 | gaqhf | result = null; |
924 | 6b9e7a56 | gaqhf | } |
925 | finally |
||
926 | { |
||
927 | connection.Dispose(); |
||
928 | } |
||
929 | } |
||
930 | return result; |
||
931 | } |
||
932 | 8f24b438 | gaqhf | |
933 | public static int GetRevision() |
||
934 | { |
||
935 | int result = 0; |
||
936 | DataTable dt = new DataTable(); |
||
937 | ID2Info id2Info = ID2Info.GetInstance(); |
||
938 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
939 | { |
||
940 | try |
||
941 | { |
||
942 | connection.Open(); |
||
943 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
944 | { |
||
945 | cmd.CommandText = string.Format("SELECT DISTINCT PSNRevisionNumber FROM {0};", PSN_PIPESYSTEMNETWORK); |
||
946 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
947 | dt.Load(dr); |
||
948 | |||
949 | foreach (DataRow row in dt.Rows) |
||
950 | { |
||
951 | int revisionNumber = Convert.ToInt32(row["PSNRevisionNumber"]); |
||
952 | if (result < revisionNumber) |
||
953 | result = revisionNumber; |
||
954 | } |
||
955 | } |
||
956 | connection.Close(); |
||
957 | } |
||
958 | catch (Exception ex) |
||
959 | { |
||
960 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
961 | result = -1; |
||
962 | } |
||
963 | finally |
||
964 | { |
||
965 | connection.Dispose(); |
||
966 | } |
||
967 | } |
||
968 | |||
969 | return result; |
||
970 | } |
||
971 | |||
972 | public static double[] GetDrawingSize() |
||
973 | { |
||
974 | double[] result = null; |
||
975 | |||
976 | DataTable dt = new DataTable(); |
||
977 | ID2Info id2Info = ID2Info.GetInstance(); |
||
978 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
979 | { |
||
980 | try |
||
981 | { |
||
982 | connection.Open(); |
||
983 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
984 | { |
||
985 | cmd.CommandText = "SELECT value FROM Configuration WHERE Section = 'Area' AND Key = 'Drawing';"; |
||
986 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
987 | dt.Load(dr); |
||
988 | |||
989 | if (dt.Rows.Count == 1) |
||
990 | { |
||
991 | string value = dt.Rows[0][0].ToString(); |
||
992 | string[] split = value.Split(new char[] { ',' }); |
||
993 | result = new double[] { |
||
994 | Convert.ToDouble(Regex.Replace(split[0], @"[^0-9]", "")), |
||
995 | Convert.ToDouble(Regex.Replace(split[1], @"[^0-9]", "")), |
||
996 | Convert.ToDouble(Regex.Replace(split[2], @"[^0-9]", "")), |
||
997 | Convert.ToDouble(Regex.Replace(split[3], @"[^0-9]", "")) |
||
998 | }; |
||
999 | result = new double[] { |
||
1000 | Math.Min(result[0], result[2]), |
||
1001 | Math.Min(result[1], result[3]), |
||
1002 | Math.Max(result[0], result[2]), |
||
1003 | Math.Max(result[1], result[3]) |
||
1004 | }; |
||
1005 | } |
||
1006 | } |
||
1007 | connection.Close(); |
||
1008 | } |
||
1009 | catch (Exception ex) |
||
1010 | { |
||
1011 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
1012 | } |
||
1013 | finally |
||
1014 | { |
||
1015 | connection.Dispose(); |
||
1016 | } |
||
1017 | } |
||
1018 | |||
1019 | return result; |
||
1020 | } |
||
1021 | 4c76a67a | gaqhf | |
1022 | public static DataTable GetEquipmentType() |
||
1023 | { |
||
1024 | DataTable dt = new DataTable(); |
||
1025 | ID2Info id2Info = ID2Info.GetInstance(); |
||
1026 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
1027 | { |
||
1028 | try |
||
1029 | { |
||
1030 | connection.Open(); |
||
1031 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
1032 | { |
||
1033 | cmd.CommandText = "SELECT Type FROM SymbolType WHERE Category = 'Equipment';"; |
||
1034 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
1035 | dt.Load(dr); |
||
1036 | } |
||
1037 | connection.Close(); |
||
1038 | } |
||
1039 | catch (Exception ex) |
||
1040 | { |
||
1041 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
1042 | } |
||
1043 | finally |
||
1044 | { |
||
1045 | connection.Dispose(); |
||
1046 | } |
||
1047 | } |
||
1048 | |||
1049 | return dt; |
||
1050 | } |
||
1051 | 5c248ee3 | gaqhf | public static DataTable GetPathItem() |
1052 | { |
||
1053 | DataTable dt = new DataTable(); |
||
1054 | ID2Info id2Info = ID2Info.GetInstance(); |
||
1055 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
1056 | { |
||
1057 | try |
||
1058 | { |
||
1059 | connection.Open(); |
||
1060 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
1061 | { |
||
1062 | cmd.CommandText = string.Format("SELECT * FROM {0}", PSN_PATHITEMS); |
||
1063 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
1064 | dt.Load(dr); |
||
1065 | } |
||
1066 | connection.Close(); |
||
1067 | } |
||
1068 | catch (Exception ex) |
||
1069 | { |
||
1070 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
1071 | } |
||
1072 | finally |
||
1073 | { |
||
1074 | connection.Dispose(); |
||
1075 | } |
||
1076 | } |
||
1077 | return dt; |
||
1078 | } |
||
1079 | public static DataTable GetTopologySet_OID() |
||
1080 | { |
||
1081 | DataTable dt = new DataTable(); |
||
1082 | ID2Info id2Info = ID2Info.GetInstance(); |
||
1083 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
1084 | { |
||
1085 | try |
||
1086 | { |
||
1087 | connection.Open(); |
||
1088 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
1089 | { |
||
1090 | cmd.CommandText = string.Format("SELECT DISTINCT(TopologySet_OID) FROM {0}", PSN_PATHITEMS); |
||
1091 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
1092 | dt.Load(dr); |
||
1093 | } |
||
1094 | connection.Close(); |
||
1095 | } |
||
1096 | catch (Exception ex) |
||
1097 | { |
||
1098 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
1099 | } |
||
1100 | finally |
||
1101 | { |
||
1102 | connection.Dispose(); |
||
1103 | } |
||
1104 | } |
||
1105 | return dt; |
||
1106 | } |
||
1107 | public static DataTable GetPipeSystemNetwork() |
||
1108 | { |
||
1109 | DataTable dt = new DataTable(); |
||
1110 | ID2Info id2Info = ID2Info.GetInstance(); |
||
1111 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
1112 | { |
||
1113 | try |
||
1114 | { |
||
1115 | connection.Open(); |
||
1116 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
1117 | { |
||
1118 | cmd.CommandText = string.Format("SELECT * FROM {0} WHERE PSNRevisionNumber = '{1}'", PSN_PIPESYSTEMNETWORK, string.Format("{0:D3}", GetRevision())); |
||
1119 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
1120 | dt.Load(dr); |
||
1121 | } |
||
1122 | connection.Close(); |
||
1123 | } |
||
1124 | catch (Exception ex) |
||
1125 | { |
||
1126 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
1127 | } |
||
1128 | finally |
||
1129 | { |
||
1130 | connection.Dispose(); |
||
1131 | } |
||
1132 | } |
||
1133 | return dt; |
||
1134 | } |
||
1135 | public static DataTable GetSequenceData() |
||
1136 | { |
||
1137 | DataTable dt = new DataTable(); |
||
1138 | ID2Info id2Info = ID2Info.GetInstance(); |
||
1139 | using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
||
1140 | { |
||
1141 | try |
||
1142 | { |
||
1143 | connection.Open(); |
||
1144 | using (SQLiteCommand cmd = connection.CreateCommand()) |
||
1145 | { |
||
1146 | cmd.CommandText = string.Format("SELECT * FROM {0}", PSN_SEQUENCEDATA); |
||
1147 | using (SQLiteDataReader dr = cmd.ExecuteReader()) |
||
1148 | dt.Load(dr); |
||
1149 | } |
||
1150 | connection.Close(); |
||
1151 | } |
||
1152 | catch (Exception ex) |
||
1153 | { |
||
1154 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
1155 | } |
||
1156 | finally |
||
1157 | { |
||
1158 | connection.Dispose(); |
||
1159 | } |
||
1160 | } |
||
1161 | return dt; |
||
1162 | } |
||
1163 | 0dae5645 | gaqhf | } |
1164 | } |