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