개정판 6b9e7a56
dev issue #000 : add
Change-Id: Id659aaa3347c5df582b157d90a8a2055d72d43a7
DTI_PID/ID2PSN/DB.cs | ||
---|---|---|
3 | 3 |
using System.Linq; |
4 | 4 |
using System.Text; |
5 | 5 |
using System.Threading.Tasks; |
6 |
using System.Data.SQLite; |
|
7 |
using System.Data; |
|
8 |
using System.Globalization; |
|
9 |
using System.Data.SQLite; |
|
10 |
using System.Data; |
|
6 | 11 |
|
7 | 12 |
namespace ID2PSN |
8 | 13 |
{ |
9 |
class DB |
|
14 |
public static class DB
|
|
10 | 15 |
{ |
16 |
const string PSN_TOPOLOGY_RULE = "T_PSN_TOPOLOGY_RULE"; |
|
17 |
const string PSN_HEADER_SETTING = "T_PSN_HEADER_SETTING"; |
|
18 |
const string PSN_PATHITEMS = "T_PSN_PATHITEMS"; |
|
19 |
const string PSN_SEQUENCEDATA = "T_PSN_SEQUENCEDATA"; |
|
20 |
const string PSN_PIPESYSTEMNETWORK = "T_PSN_PIPESYSTEMNETWORK"; |
|
21 |
const string PSN_EQUIPMENT = "T_PSN_EQUIPMENT"; |
|
22 |
const string PSN_NOZZLE = "T_PSN_NOZZLE"; |
|
23 |
const string PSN_FLUIDCODE = "T_PSN_FLUIDCODE"; |
|
24 |
const string PSN_PIPINGMATLCLASS = "T_PSN_PIPINGMATLCLASS"; |
|
25 |
public static bool ConnTestAndCreateTable() |
|
26 |
{ |
|
27 |
bool result = false; |
|
28 |
ID2Info id2Info = ID2Info.GetInstance(); |
|
29 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, @"Data Source = {0}", id2Info.DBFilePath), true)) |
|
30 |
{ |
|
31 |
try |
|
32 |
{ |
|
33 |
connection.Open(); |
|
34 |
if (connection.State == ConnectionState.Open) |
|
35 |
{ |
|
36 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
37 |
{ |
|
38 |
cmd.CommandText = "SELECT NAME FROM sqlite_master WHERE type='table'"; |
|
39 |
using (SQLiteDataReader dr = cmd.ExecuteReader()) |
|
40 |
using (DataTable dt = new DataTable()) |
|
41 |
{ |
|
42 |
dt.Load(dr); |
|
11 | 43 |
|
44 |
if (dt.Select(string.Format("NAME = '{0}'", PSN_HEADER_SETTING)).Length == 0) |
|
45 |
{ |
|
46 |
cmd.CommandText = string.Format("CREATE TABLE {0} (GROUP_ID TEXT, DESCRIPTION TEXT, [INDEX] INTEGER, NAME TEXT)", PSN_HEADER_SETTING); |
|
47 |
cmd.ExecuteNonQuery(); |
|
48 |
} |
|
49 |
if (dt.Select(string.Format("NAME = '{0}'", PSN_TOPOLOGY_RULE)).Length == 0) |
|
50 |
{ |
|
51 |
cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT)", PSN_TOPOLOGY_RULE); |
|
52 |
cmd.ExecuteNonQuery(); |
|
53 |
} |
|
54 |
if (dt.Select(string.Format("NAME = '{0}'", PSN_PATHITEMS)).Length == 0) |
|
55 |
{ |
|
56 |
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); |
|
57 |
cmd.ExecuteNonQuery(); |
|
58 |
} |
|
59 |
if (dt.Select(string.Format("NAME = '{0}'", PSN_SEQUENCEDATA)).Length == 0) |
|
60 |
{ |
|
61 |
cmd.CommandText = string.Format("CREATE TABLE {0} (OID TEXT, SERIALNUMBER TEXT, PathItem_OID TEXT, TopologySet_OID_Key TEXT)", PSN_SEQUENCEDATA); |
|
62 |
cmd.ExecuteNonQuery(); |
|
63 |
} |
|
64 |
if (dt.Select(string.Format("NAME = '{0}'", PSN_PIPESYSTEMNETWORK)).Length == 0) |
|
65 |
{ |
|
66 |
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); |
|
67 |
cmd.ExecuteNonQuery(); |
|
68 |
} |
|
69 |
|
|
70 |
if (dt.Select(string.Format("NAME = '{0}'", PSN_EQUIPMENT)).Length == 0) |
|
71 |
{ |
|
72 |
cmd.CommandText = string.Format("CREATE TABLE {0} (OID TEXT, ITEMTAG TEXT, XCOORDS TEXT, YCOORDS TEXT)", PSN_EQUIPMENT); |
|
73 |
cmd.ExecuteNonQuery(); |
|
74 |
} |
|
75 |
if (dt.Select(string.Format("NAME = '{0}'", PSN_NOZZLE)).Length == 0) |
|
76 |
{ |
|
77 |
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); |
|
78 |
cmd.ExecuteNonQuery(); |
|
79 |
} |
|
80 |
if (dt.Select(string.Format("NAME = '{0}'", PSN_FLUIDCODE)).Length == 0) |
|
81 |
{ |
|
82 |
cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT, Code TEXT, Description TEXT, Condition TEXT, GroundLevel TEXT)", PSN_FLUIDCODE); |
|
83 |
cmd.ExecuteNonQuery(); |
|
84 |
} |
|
85 |
if (dt.Select(string.Format("NAME = '{0}'", PSN_PIPINGMATLCLASS)).Length == 0) |
|
86 |
{ |
|
87 |
cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT, Priority TEXT, Code TEXT, Description TEXT, Condition TEXT, GroundLevel TEXT)", PSN_PIPINGMATLCLASS); |
|
88 |
cmd.ExecuteNonQuery(); |
|
89 |
} |
|
90 |
} |
|
91 |
} |
|
92 |
result = true; |
|
93 |
} |
|
94 |
connection.Close(); |
|
95 |
} |
|
96 |
catch (Exception ex) |
|
97 |
{ |
|
98 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
99 |
} |
|
100 |
finally |
|
101 |
{ |
|
102 |
connection.Dispose(); |
|
103 |
} |
|
104 |
} |
|
105 |
return result; |
|
106 |
} |
|
107 |
|
|
108 |
public static DataTable SelectHeaderSetting() |
|
109 |
{ |
|
110 |
DataTable dt = new DataTable(); |
|
111 |
ID2Info id2Info = ID2Info.GetInstance(); |
|
112 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
|
113 |
{ |
|
114 |
try |
|
115 |
{ |
|
116 |
connection.Open(); |
|
117 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
118 |
{ |
|
119 |
cmd.CommandText = string.Format(@"SELECT GROUP_ID, DESCRIPTION, [INDEX], NAME FROM {0};", PSN_HEADER_SETTING); |
|
120 |
using (SQLiteDataReader dr = cmd.ExecuteReader()) |
|
121 |
dt.Load(dr); |
|
122 |
} |
|
123 |
connection.Close(); |
|
124 |
} |
|
125 |
catch (Exception ex) |
|
126 |
{ |
|
127 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
128 |
} |
|
129 |
finally |
|
130 |
{ |
|
131 |
connection.Dispose(); |
|
132 |
} |
|
133 |
} |
|
134 |
return dt; |
|
135 |
} |
|
136 |
|
|
137 |
public static bool SaveHeaderSetting(List<HeaderInfo> headerInfos) |
|
138 |
{ |
|
139 |
ID2Info id2Info = ID2Info.GetInstance(); |
|
140 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
|
141 |
{ |
|
142 |
try |
|
143 |
{ |
|
144 |
connection.Open(); |
|
145 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
146 |
{ |
|
147 |
cmd.CommandText = string.Format("DELETE FROM {0}", PSN_HEADER_SETTING); |
|
148 |
cmd.ExecuteNonQuery(); |
|
149 |
|
|
150 |
foreach (HeaderInfo headerInfo in headerInfos) |
|
151 |
{ |
|
152 |
foreach (HeaderItem item in headerInfo.HeaderItems) |
|
153 |
{ |
|
154 |
cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@GROUP_ID, @DESCRIPTION, @INDEX, @NAME)", PSN_HEADER_SETTING); |
|
155 |
cmd.Parameters.Clear(); |
|
156 |
cmd.Parameters.AddWithValue("@GROUP_ID", headerInfo.UID); |
|
157 |
cmd.Parameters.AddWithValue("@DESCRIPTION", headerInfo.Description); |
|
158 |
cmd.Parameters.AddWithValue("@INDEX", item.Index); |
|
159 |
cmd.Parameters.AddWithValue("@NAME", item.Name); |
|
160 |
cmd.ExecuteNonQuery(); |
|
161 |
} |
|
162 |
} |
|
163 |
} |
|
164 |
connection.Close(); |
|
165 |
} |
|
166 |
catch (Exception ex) |
|
167 |
{ |
|
168 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
169 |
return false; |
|
170 |
} |
|
171 |
finally |
|
172 |
{ |
|
173 |
connection.Dispose(); |
|
174 |
} |
|
175 |
} |
|
176 |
return true; |
|
177 |
} |
|
178 |
|
|
179 |
public static DataTable SelectOPCRelations() |
|
180 |
{ |
|
181 |
DataTable dt = new DataTable(); |
|
182 |
ID2Info id2Info = ID2Info.GetInstance(); |
|
183 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
|
184 |
{ |
|
185 |
try |
|
186 |
{ |
|
187 |
connection.Open(); |
|
188 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
189 |
{ |
|
190 |
cmd.CommandText = "SELECT * FROM OPCRelations;"; |
|
191 |
using (SQLiteDataReader dr = cmd.ExecuteReader()) |
|
192 |
dt.Load(dr); |
|
193 |
} |
|
194 |
connection.Close(); |
|
195 |
} |
|
196 |
catch (Exception ex) |
|
197 |
{ |
|
198 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
199 |
} |
|
200 |
finally |
|
201 |
{ |
|
202 |
connection.Dispose(); |
|
203 |
} |
|
204 |
} |
|
205 |
return dt; |
|
206 |
} |
|
207 |
|
|
208 |
public static DataTable SelectDrawings() |
|
209 |
{ |
|
210 |
DataTable dt = new DataTable(); |
|
211 |
ID2Info id2Info = ID2Info.GetInstance(); |
|
212 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
|
213 |
{ |
|
214 |
try |
|
215 |
{ |
|
216 |
connection.Open(); |
|
217 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
218 |
{ |
|
219 |
cmd.CommandText = "SELECT * FROM Drawings;"; |
|
220 |
using (SQLiteDataReader dr = cmd.ExecuteReader()) |
|
221 |
dt.Load(dr); |
|
222 |
} |
|
223 |
connection.Close(); |
|
224 |
} |
|
225 |
catch (Exception ex) |
|
226 |
{ |
|
227 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
228 |
} |
|
229 |
finally |
|
230 |
{ |
|
231 |
connection.Dispose(); |
|
232 |
} |
|
233 |
} |
|
234 |
return dt; |
|
235 |
} |
|
236 |
|
|
237 |
public static DataTable SelectLineProperties() |
|
238 |
{ |
|
239 |
DataTable dt = new DataTable(); |
|
240 |
ID2Info id2Info = ID2Info.GetInstance(); |
|
241 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
|
242 |
{ |
|
243 |
try |
|
244 |
{ |
|
245 |
connection.Open(); |
|
246 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
247 |
{ |
|
248 |
cmd.CommandText = "SELECT * FROM LineProperties;"; |
|
249 |
using (SQLiteDataReader dr = cmd.ExecuteReader()) |
|
250 |
dt.Load(dr); |
|
251 |
} |
|
252 |
connection.Close(); |
|
253 |
} |
|
254 |
catch (Exception ex) |
|
255 |
{ |
|
256 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
257 |
} |
|
258 |
finally |
|
259 |
{ |
|
260 |
connection.Dispose(); |
|
261 |
} |
|
262 |
} |
|
263 |
return dt; |
|
264 |
} |
|
265 |
public static DataTable SelectTopologyRule() |
|
266 |
{ |
|
267 |
DataTable dt = new DataTable(); |
|
268 |
ID2Info id2Info = ID2Info.GetInstance(); |
|
269 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
|
270 |
{ |
|
271 |
try |
|
272 |
{ |
|
273 |
connection.Open(); |
|
274 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
275 |
{ |
|
276 |
cmd.CommandText = string.Format(@"SELECT * FROM {0};", PSN_TOPOLOGY_RULE); |
|
277 |
using (SQLiteDataReader dr = cmd.ExecuteReader()) |
|
278 |
dt.Load(dr); |
|
279 |
} |
|
280 |
connection.Close(); |
|
281 |
} |
|
282 |
catch (Exception ex) |
|
283 |
{ |
|
284 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
285 |
} |
|
286 |
finally |
|
287 |
{ |
|
288 |
connection.Dispose(); |
|
289 |
} |
|
290 |
} |
|
291 |
return dt; |
|
292 |
} |
|
293 |
public static bool SaveTopologyRule(DataTable dt) |
|
294 |
{ |
|
295 |
ID2Info id2Info = ID2Info.GetInstance(); |
|
296 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
|
297 |
{ |
|
298 |
try |
|
299 |
{ |
|
300 |
connection.Open(); |
|
301 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
302 |
{ |
|
303 |
cmd.CommandText = string.Format("DELETE FROM {0}", PSN_TOPOLOGY_RULE); |
|
304 |
cmd.ExecuteNonQuery(); |
|
305 |
|
|
306 |
foreach (DataRow row in dt.Rows) |
|
307 |
{ |
|
308 |
cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@UID)", PSN_TOPOLOGY_RULE); |
|
309 |
cmd.Parameters.Clear(); |
|
310 |
cmd.Parameters.AddWithValue("@UID", row["NAME"].ToString()); |
|
311 |
cmd.ExecuteNonQuery(); |
|
312 |
} |
|
313 |
} |
|
314 |
connection.Close(); |
|
315 |
} |
|
316 |
catch (Exception ex) |
|
317 |
{ |
|
318 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
319 |
return false; |
|
320 |
} |
|
321 |
finally |
|
322 |
{ |
|
323 |
connection.Dispose(); |
|
324 |
} |
|
325 |
} |
|
326 |
return true; |
|
327 |
} |
|
328 |
|
|
329 |
public static DataTable SelectFluidCode() |
|
330 |
{ |
|
331 |
DataTable dt = new DataTable(); |
|
332 |
ID2Info id2Info = ID2Info.GetInstance(); |
|
333 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
|
334 |
{ |
|
335 |
try |
|
336 |
{ |
|
337 |
connection.Open(); |
|
338 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
339 |
{ |
|
340 |
cmd.CommandText = "SELECT * FROM FluidCode;"; |
|
341 |
using (SQLiteDataReader dr = cmd.ExecuteReader()) |
|
342 |
dt.Load(dr); |
|
343 |
} |
|
344 |
connection.Close(); |
|
345 |
} |
|
346 |
catch (Exception ex) |
|
347 |
{ |
|
348 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
349 |
} |
|
350 |
finally |
|
351 |
{ |
|
352 |
connection.Dispose(); |
|
353 |
} |
|
354 |
} |
|
355 |
return dt; |
|
356 |
} |
|
357 |
public static DataTable SelectPipingMaterialsClass() |
|
358 |
{ |
|
359 |
DataTable dt = new DataTable(); |
|
360 |
ID2Info id2Info = ID2Info.GetInstance(); |
|
361 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
|
362 |
{ |
|
363 |
try |
|
364 |
{ |
|
365 |
connection.Open(); |
|
366 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
367 |
{ |
|
368 |
cmd.CommandText = "SELECT * FROM PipingMaterialsClass;"; |
|
369 |
using (SQLiteDataReader dr = cmd.ExecuteReader()) |
|
370 |
dt.Load(dr); |
|
371 |
} |
|
372 |
connection.Close(); |
|
373 |
} |
|
374 |
catch (Exception ex) |
|
375 |
{ |
|
376 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
377 |
} |
|
378 |
finally |
|
379 |
{ |
|
380 |
connection.Dispose(); |
|
381 |
} |
|
382 |
} |
|
383 |
return dt; |
|
384 |
} |
|
385 |
|
|
386 |
public static DataTable SelectPSNFluidCode() |
|
387 |
{ |
|
388 |
DataTable dt = new DataTable(); |
|
389 |
ID2Info id2Info = ID2Info.GetInstance(); |
|
390 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
|
391 |
{ |
|
392 |
try |
|
393 |
{ |
|
394 |
connection.Open(); |
|
395 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
396 |
{ |
|
397 |
cmd.CommandText = string.Format("SELECT * FROM {0}", PSN_FLUIDCODE); |
|
398 |
using (SQLiteDataReader dr = cmd.ExecuteReader()) |
|
399 |
dt.Load(dr); |
|
400 |
} |
|
401 |
connection.Close(); |
|
402 |
} |
|
403 |
catch (Exception ex) |
|
404 |
{ |
|
405 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
406 |
} |
|
407 |
finally |
|
408 |
{ |
|
409 |
connection.Dispose(); |
|
410 |
} |
|
411 |
} |
|
412 |
return dt; |
|
413 |
} |
|
414 |
public static DataTable SelectPSNPIPINGMATLCLASS() |
|
415 |
{ |
|
416 |
DataTable dt = new DataTable(); |
|
417 |
ID2Info id2Info = ID2Info.GetInstance(); |
|
418 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
|
419 |
{ |
|
420 |
try |
|
421 |
{ |
|
422 |
connection.Open(); |
|
423 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
424 |
{ |
|
425 |
cmd.CommandText = string.Format("SELECT * FROM {0}", PSN_PIPINGMATLCLASS); |
|
426 |
using (SQLiteDataReader dr = cmd.ExecuteReader()) |
|
427 |
dt.Load(dr); |
|
428 |
} |
|
429 |
connection.Close(); |
|
430 |
} |
|
431 |
catch (Exception ex) |
|
432 |
{ |
|
433 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
434 |
} |
|
435 |
finally |
|
436 |
{ |
|
437 |
connection.Dispose(); |
|
438 |
} |
|
439 |
} |
|
440 |
return dt; |
|
441 |
} |
|
442 |
public static DataTable SelectNominalDiameter() |
|
443 |
{ |
|
444 |
DataTable dt = new DataTable(); |
|
445 |
ID2Info id2Info = ID2Info.GetInstance(); |
|
446 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
|
447 |
{ |
|
448 |
try |
|
449 |
{ |
|
450 |
connection.Open(); |
|
451 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
452 |
{ |
|
453 |
cmd.CommandText = "SELECT * FROM NominalDiameter;"; |
|
454 |
using (SQLiteDataReader dr = cmd.ExecuteReader()) |
|
455 |
dt.Load(dr); |
|
456 |
} |
|
457 |
connection.Close(); |
|
458 |
} |
|
459 |
catch (Exception ex) |
|
460 |
{ |
|
461 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
462 |
} |
|
463 |
finally |
|
464 |
{ |
|
465 |
connection.Dispose(); |
|
466 |
} |
|
467 |
} |
|
468 |
return dt; |
|
469 |
} |
|
470 |
|
|
471 |
public static bool SavePSNFluidCode(DataTable dt) |
|
472 |
{ |
|
473 |
ID2Info id2Info = ID2Info.GetInstance(); |
|
474 |
|
|
475 |
bool result = true; |
|
476 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
|
477 |
{ |
|
478 |
try |
|
479 |
{ |
|
480 |
connection.Open(); |
|
481 |
|
|
482 |
using (SQLiteTransaction transaction = connection.BeginTransaction()) |
|
483 |
{ |
|
484 |
try |
|
485 |
{ |
|
486 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
487 |
{ |
|
488 |
cmd.CommandText = string.Format("DELETE FROM {0}", PSN_FLUIDCODE); |
|
489 |
cmd.ExecuteNonQuery(); |
|
490 |
|
|
491 |
foreach (DataRow row in dt.Rows) |
|
492 |
{ |
|
493 |
cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@UID, @Code, @Description, @Condition, @GroundLevel)", PSN_FLUIDCODE); |
|
494 |
cmd.Parameters.Clear(); |
|
495 |
cmd.Parameters.AddWithValue("@UID", row["UID"].ToString()); |
|
496 |
cmd.Parameters.AddWithValue("@Code", row["Code"].ToString()); |
|
497 |
cmd.Parameters.AddWithValue("@Description", row["Description"].ToString()); |
|
498 |
cmd.Parameters.AddWithValue("@Condition", row["Condition"].ToString()); |
|
499 |
cmd.Parameters.AddWithValue("@GroundLevel", row["GroundLevel"].ToString()); |
|
500 |
cmd.ExecuteNonQuery(); |
|
501 |
} |
|
502 |
} |
|
503 |
transaction.Commit(); |
|
504 |
connection.Close(); |
|
505 |
} |
|
506 |
catch (Exception ex) |
|
507 |
{ |
|
508 |
transaction.Rollback(); |
|
509 |
result = false; |
|
510 |
} |
|
511 |
finally |
|
512 |
{ |
|
513 |
transaction.Dispose(); |
|
514 |
} |
|
515 |
} |
|
516 |
} |
|
517 |
catch (Exception ex) |
|
518 |
{ |
|
519 |
System.Windows.Forms.MessageBox.Show(ex.Message); |
|
520 |
result = false; |
|
521 |
} |
|
522 |
finally |
|
523 |
{ |
|
524 |
connection.Dispose(); |
|
525 |
} |
|
526 |
} |
|
527 |
|
|
528 |
return result; |
|
529 |
} |
|
530 |
|
|
531 |
public static bool SavePSNPMC(DataTable dt) |
|
532 |
{ |
|
533 |
ID2Info id2Info = ID2Info.GetInstance(); |
|
534 |
|
|
535 |
bool result = true; |
|
536 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
|
537 |
{ |
|
538 |
try |
|
539 |
{ |
|
540 |
connection.Open(); |
|
541 |
|
|
542 |
using (SQLiteTransaction transaction = connection.BeginTransaction()) |
|
543 |
{ |
|
544 |
try |
|
545 |
{ |
|
546 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
547 |
{ |
|
548 |
cmd.CommandText = string.Format("DELETE FROM {0}", PSN_PIPINGMATLCLASS); |
|
549 |
cmd.ExecuteNonQuery(); |
|
550 |
|
|
551 |
foreach (DataRow row in dt.Rows) |
|
552 |
{ |
|
553 |
cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@UID, @Priority, @Code, @Description, @Condition, @GroundLevel)", PSN_PIPINGMATLCLASS); |
|
554 |
cmd.Parameters.Clear(); |
|
555 |
cmd.Parameters.AddWithValue("@UID", row["UID"].ToString()); |
|
556 |
cmd.Parameters.AddWithValue("@Priority", row["Priority"].ToString()); |
|
557 |
cmd.Parameters.AddWithValue("@Code", row["Code"].ToString()); |
|
558 |
cmd.Parameters.AddWithValue("@Description", row["Description"].ToString()); |
|
559 |
cmd.Parameters.AddWithValue("@Condition", row["Condition"].ToString()); |
|
560 |
cmd.Parameters.AddWithValue("@GroundLevel", row["GroundLevel"].ToString()); |
|
561 |
cmd.ExecuteNonQuery(); |
|
562 |
} |
|
563 |
} |
|
564 |
transaction.Commit(); |
|
565 |
connection.Close(); |
|
566 |
} |
|
567 |
catch (Exception ex) |
|
568 |
{ |
|
569 |
transaction.Rollback(); |
|
570 |
result = false; |
|
571 |
} |
|
572 |
finally |
|
573 |
{ |
|
574 |
transaction.Dispose(); |
|
575 |
} |
|
576 |
} |
|
577 |
} |
|
578 |
catch (Exception ex) |
|
579 |
{ |
|
580 |
System.Windows.Forms.MessageBox.Show(ex.Message); |
|
581 |
result = false; |
|
582 |
} |
|
583 |
finally |
|
584 |
{ |
|
585 |
connection.Dispose(); |
|
586 |
} |
|
587 |
} |
|
588 |
|
|
589 |
return result; |
|
590 |
} |
|
591 |
|
|
592 |
public static bool SavePathItems(DataTable dt) |
|
593 |
{ |
|
594 |
ID2Info id2Info = ID2Info.GetInstance(); |
|
595 |
|
|
596 |
bool result = true; |
|
597 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
|
598 |
{ |
|
599 |
try |
|
600 |
{ |
|
601 |
connection.Open(); |
|
602 |
|
|
603 |
using (SQLiteTransaction transaction = connection.BeginTransaction()) |
|
604 |
{ |
|
605 |
try |
|
606 |
{ |
|
607 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
608 |
{ |
|
609 |
cmd.CommandText = string.Format("DELETE FROM {0}", PSN_PATHITEMS); |
|
610 |
cmd.ExecuteNonQuery(); |
|
611 |
|
|
612 |
foreach (DataRow row in dt.Rows) |
|
613 |
{ |
|
614 |
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); |
|
615 |
cmd.Parameters.Clear(); |
|
616 |
cmd.Parameters.AddWithValue("@OID", row["OID"].ToString()); |
|
617 |
cmd.Parameters.AddWithValue("@SequenceData_OID", row["SequenceData_OID"].ToString()); |
|
618 |
cmd.Parameters.AddWithValue("@TopologySet_OID", row["TopologySet_OID"].ToString()); |
|
619 |
cmd.Parameters.AddWithValue("@BranchTopologySet_OID", row["BranchTopologySet_OID"].ToString()); |
|
620 |
cmd.Parameters.AddWithValue("@PipeLine_OID", row["PipeLine_OID"].ToString()); |
|
621 |
cmd.Parameters.AddWithValue("@ITEMNAME", row["ITEMNAME"].ToString()); |
|
622 |
cmd.Parameters.AddWithValue("@ITEMTAG", row["ITEMTAG"].ToString()); |
|
623 |
cmd.Parameters.AddWithValue("@TYPE", row["TYPE"].ToString()); |
|
624 |
cmd.Parameters.AddWithValue("@PIDNAME", row["PIDNAME"].ToString()); |
|
625 |
cmd.Parameters.AddWithValue("@NPD", row["NPD"].ToString()); |
|
626 |
cmd.Parameters.AddWithValue("@PipeSystemNetwork_OID", row["PipeSystemNetwork_OID"].ToString()); |
|
627 |
cmd.Parameters.AddWithValue("@PipeRun_OID", row["PipeRun_OID"].ToString()); |
|
628 |
cmd.ExecuteNonQuery(); |
|
629 |
} |
|
630 |
} |
|
631 |
transaction.Commit(); |
|
632 |
connection.Close(); |
|
633 |
} |
|
634 |
catch (Exception ex) |
|
635 |
{ |
|
636 |
transaction.Rollback(); |
|
637 |
result = false; |
|
638 |
} |
|
639 |
finally |
|
640 |
{ |
|
641 |
transaction.Dispose(); |
|
642 |
} |
|
643 |
} |
|
644 |
} |
|
645 |
catch (Exception ex) |
|
646 |
{ |
|
647 |
System.Windows.Forms.MessageBox.Show(ex.Message); |
|
648 |
result = false; |
|
649 |
} |
|
650 |
finally |
|
651 |
{ |
|
652 |
connection.Dispose(); |
|
653 |
} |
|
654 |
} |
|
655 |
|
|
656 |
return result; |
|
657 |
} |
|
658 |
|
|
659 |
public static bool SaveSequenceData(DataTable dt) |
|
660 |
{ |
|
661 |
ID2Info id2Info = ID2Info.GetInstance(); |
|
662 |
|
|
663 |
bool result = true; |
|
664 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
|
665 |
{ |
|
666 |
try |
|
667 |
{ |
|
668 |
connection.Open(); |
|
669 |
|
|
670 |
using (SQLiteTransaction transaction = connection.BeginTransaction()) |
|
671 |
{ |
|
672 |
try |
|
673 |
{ |
|
674 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
675 |
{ |
|
676 |
cmd.CommandText = string.Format("DELETE FROM {0}", PSN_SEQUENCEDATA); |
|
677 |
cmd.ExecuteNonQuery(); |
|
678 |
|
|
679 |
foreach (DataRow row in dt.Rows) |
|
680 |
{ |
|
681 |
cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@OID, @SERIALNUMBER, @PathItem_OID, @TopologySet_OID_Key)", PSN_SEQUENCEDATA); |
|
682 |
cmd.Parameters.Clear(); |
|
683 |
cmd.Parameters.AddWithValue("@OID", row["OID"].ToString()); |
|
684 |
cmd.Parameters.AddWithValue("@SERIALNUMBER", row["SERIALNUMBER"].ToString()); |
|
685 |
cmd.Parameters.AddWithValue("@PathItem_OID", row["PathItem_OID"].ToString()); |
|
686 |
cmd.Parameters.AddWithValue("@TopologySet_OID_Key", row["TopologySet_OID_Key"].ToString()); |
|
687 |
cmd.ExecuteNonQuery(); |
|
688 |
} |
|
689 |
} |
|
690 |
transaction.Commit(); |
|
691 |
connection.Close(); |
|
692 |
} |
|
693 |
catch (Exception ex) |
|
694 |
{ |
|
695 |
transaction.Rollback(); |
|
696 |
result = false; |
|
697 |
} |
|
698 |
finally |
|
699 |
{ |
|
700 |
transaction.Dispose(); |
|
701 |
} |
|
702 |
} |
|
703 |
} |
|
704 |
catch (Exception ex) |
|
705 |
{ |
|
706 |
System.Windows.Forms.MessageBox.Show(ex.Message); |
|
707 |
result = false; |
|
708 |
} |
|
709 |
finally |
|
710 |
{ |
|
711 |
connection.Dispose(); |
|
712 |
} |
|
713 |
} |
|
714 |
|
|
715 |
return result; |
|
716 |
} |
|
717 |
|
|
718 |
public static bool SavePipeSystemNetwork(DataTable dt) |
|
719 |
{ |
|
720 |
ID2Info id2Info = ID2Info.GetInstance(); |
|
721 |
|
|
722 |
bool result = true; |
|
723 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
|
724 |
{ |
|
725 |
try |
|
726 |
{ |
|
727 |
connection.Open(); |
|
728 |
|
|
729 |
using (SQLiteTransaction transaction = connection.BeginTransaction()) |
|
730 |
{ |
|
731 |
try |
|
732 |
{ |
|
733 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
734 |
{ |
|
735 |
cmd.CommandText = string.Format("DELETE FROM {0}", PSN_PIPESYSTEMNETWORK); |
|
736 |
cmd.ExecuteNonQuery(); |
|
737 |
|
|
738 |
foreach (DataRow row in dt.Rows) |
|
739 |
{ |
|
740 |
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); |
|
741 |
cmd.Parameters.Clear(); |
|
742 |
cmd.Parameters.AddWithValue("@OID", row["OID"].ToString()); |
|
743 |
cmd.Parameters.AddWithValue("@Type", row["Type"].ToString()); |
|
744 |
cmd.Parameters.AddWithValue("@OrderNumber", row["OrderNumber"].ToString()); |
|
745 |
cmd.Parameters.AddWithValue("@Pipeline_OID", row["Pipeline_OID"].ToString()); |
|
746 |
cmd.Parameters.AddWithValue("@FROM_DATA", row["FROM_DATA"].ToString()); |
|
747 |
cmd.Parameters.AddWithValue("@TO_DATA", row["TO_DATA"].ToString()); |
|
748 |
cmd.Parameters.AddWithValue("@TopologySet_OID_Key", row["TopologySet_OID_Key"].ToString()); |
|
749 |
cmd.Parameters.AddWithValue("@PSNRevisionNumber", row["PSNRevisionNumber"].ToString()); |
|
750 |
cmd.Parameters.AddWithValue("@PathOID", row["PathOID"].ToString()); |
|
751 |
cmd.Parameters.AddWithValue("@PBS", row["PBS"].ToString()); |
|
752 |
cmd.Parameters.AddWithValue("@PIDDrawings", row["PIDDrawings"].ToString()); |
|
753 |
cmd.ExecuteNonQuery(); |
|
754 |
} |
|
755 |
} |
|
756 |
transaction.Commit(); |
|
757 |
connection.Close(); |
|
758 |
} |
|
759 |
catch (Exception ex) |
|
760 |
{ |
|
761 |
transaction.Rollback(); |
|
762 |
result = false; |
|
763 |
} |
|
764 |
finally |
|
765 |
{ |
|
766 |
transaction.Dispose(); |
|
767 |
} |
|
768 |
} |
|
769 |
} |
|
770 |
catch (Exception ex) |
|
771 |
{ |
|
772 |
System.Windows.Forms.MessageBox.Show(ex.Message); |
|
773 |
result = false; |
|
774 |
} |
|
775 |
finally |
|
776 |
{ |
|
777 |
connection.Dispose(); |
|
778 |
} |
|
779 |
} |
|
780 |
|
|
781 |
return result; |
|
782 |
} |
|
783 |
|
|
784 |
public static bool SaveEquipment(DataTable dt) |
|
785 |
{ |
|
786 |
ID2Info id2Info = ID2Info.GetInstance(); |
|
787 |
|
|
788 |
bool result = true; |
|
789 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
|
790 |
{ |
|
791 |
try |
|
792 |
{ |
|
793 |
connection.Open(); |
|
794 |
|
|
795 |
using (SQLiteTransaction transaction = connection.BeginTransaction()) |
|
796 |
{ |
|
797 |
try |
|
798 |
{ |
|
799 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
800 |
{ |
|
801 |
cmd.CommandText = string.Format("DELETE FROM {0}", PSN_EQUIPMENT); |
|
802 |
cmd.ExecuteNonQuery(); |
|
803 |
|
|
804 |
foreach (DataRow row in dt.Rows) |
|
805 |
{ |
|
806 |
cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@OID, @ITEMTAG, @XCOORDS, @YCOORDS)", PSN_EQUIPMENT); |
|
807 |
cmd.Parameters.Clear(); |
|
808 |
cmd.Parameters.AddWithValue("@OID", row["OID"].ToString()); |
|
809 |
cmd.Parameters.AddWithValue("@ITEMTAG", row["ITEMTAG"].ToString()); |
|
810 |
cmd.Parameters.AddWithValue("@XCOORDS", row["XCOORDS"].ToString()); |
|
811 |
cmd.Parameters.AddWithValue("@YCOORDS", row["YCOORDS"].ToString()); |
|
812 |
cmd.ExecuteNonQuery(); |
|
813 |
} |
|
814 |
} |
|
815 |
transaction.Commit(); |
|
816 |
connection.Close(); |
|
817 |
} |
|
818 |
catch (Exception ex) |
|
819 |
{ |
|
820 |
transaction.Rollback(); |
|
821 |
result = false; |
|
822 |
} |
|
823 |
finally |
|
824 |
{ |
|
825 |
transaction.Dispose(); |
|
826 |
} |
|
827 |
} |
|
828 |
} |
|
829 |
catch (Exception ex) |
|
830 |
{ |
|
831 |
System.Windows.Forms.MessageBox.Show(ex.Message); |
|
832 |
result = false; |
|
833 |
} |
|
834 |
finally |
|
835 |
{ |
|
836 |
connection.Dispose(); |
|
837 |
} |
|
838 |
} |
|
839 |
|
|
840 |
return result; |
|
841 |
} |
|
842 |
|
|
843 |
public static bool SaveNozzle(DataTable dt) |
|
844 |
{ |
|
845 |
ID2Info id2Info = ID2Info.GetInstance(); |
|
846 |
|
|
847 |
bool result = true; |
|
848 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
|
849 |
{ |
|
850 |
try |
|
851 |
{ |
|
852 |
connection.Open(); |
|
853 |
|
|
854 |
using (SQLiteTransaction transaction = connection.BeginTransaction()) |
|
855 |
{ |
|
856 |
try |
|
857 |
{ |
|
858 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
859 |
{ |
|
860 |
cmd.CommandText = string.Format("DELETE FROM {0}", PSN_NOZZLE); |
|
861 |
cmd.ExecuteNonQuery(); |
|
862 |
|
|
863 |
foreach (DataRow row in dt.Rows) |
|
864 |
{ |
|
865 |
cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@OID, @ITEMTAG, @XCOORDS, @YCOORDS, @Equipment_OID, @FLUID, @NPD, @ROTATION, @FlowDirection)", PSN_NOZZLE); |
|
866 |
cmd.Parameters.Clear(); |
|
867 |
cmd.Parameters.AddWithValue("@OID", row["OID"].ToString()); |
|
868 |
cmd.Parameters.AddWithValue("@ITEMTAG", row["ITEMTAG"].ToString()); |
|
869 |
cmd.Parameters.AddWithValue("@XCOORDS", row["XCOORDS"].ToString()); |
|
870 |
cmd.Parameters.AddWithValue("@YCOORDS", row["YCOORDS"].ToString()); |
|
871 |
cmd.Parameters.AddWithValue("@Equipment_OID", row["Equipment_OID"].ToString()); |
|
872 |
cmd.Parameters.AddWithValue("@FLUID", row["FLUID"].ToString()); |
|
873 |
cmd.Parameters.AddWithValue("@NPD", row["NPD"].ToString()); |
|
874 |
cmd.Parameters.AddWithValue("@ROTATION", row["ROTATION"].ToString()); |
|
875 |
cmd.Parameters.AddWithValue("@FlowDirection", row["FlowDirection"].ToString()); |
|
876 |
cmd.ExecuteNonQuery(); |
|
877 |
} |
|
878 |
} |
|
879 |
transaction.Commit(); |
|
880 |
connection.Close(); |
|
881 |
} |
|
882 |
catch (Exception ex) |
|
883 |
{ |
|
884 |
transaction.Rollback(); |
|
885 |
result = false; |
|
886 |
} |
|
887 |
finally |
|
888 |
{ |
|
889 |
transaction.Dispose(); |
|
890 |
} |
|
891 |
} |
|
892 |
} |
|
893 |
catch (Exception ex) |
|
894 |
{ |
|
895 |
System.Windows.Forms.MessageBox.Show(ex.Message); |
|
896 |
result = false; |
|
897 |
} |
|
898 |
finally |
|
899 |
{ |
|
900 |
connection.Dispose(); |
|
901 |
} |
|
902 |
} |
|
903 |
|
|
904 |
return result; |
|
905 |
} |
|
12 | 906 |
} |
13 | 907 |
} |
내보내기 Unified diff